From b4c1510ec1dba41d77b7507cd4447ccd85795027 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 11 May 2020 02:48:27 +0200 Subject: [PATCH] Please cherry-pick: - departments, headquarters and branch offices cannot have a relation to employees as employess have a relation already to them. So if comparison of those entities come, this ends up in an endless loop with a stack overflow. - the fix here is a bit simple and also a bit complex: relate those 3 entities to contacts (jcontacts-core.jar) and look in all employees related to the department, headquarter or branch office who have an equal contact record MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../PizzaAdminBranchOfficeSessionBean.java | 19 +++++++++++++++++++ .../PizzaAdminDepartmentSessionBean.java | 10 +++++----- .../PizzaAdminHeadquarterSessionBean.java | 10 ++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaAdminBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaAdminBranchOfficeSessionBean.java index 1b1d2a5..177d2e7 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaAdminBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaAdminBranchOfficeSessionBean.java @@ -21,6 +21,7 @@ import java.util.Date; import java.util.List; import javax.ejb.EJB; import javax.ejb.Stateless; +import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeAlreadyAddedException; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; @@ -76,6 +77,24 @@ public class PizzaAdminBranchOfficeSessionBean extends BasePizzaEnterpriseBean i // Add created timestamp branchOffice.setBranchEntryCreated(new Date()); + // Is contact employee set? + if (branchOffice.getBranchContactEmployee() instanceof Contact) { + // Get managed lead contact + final Contact managedContact = this.createManaged(branchOffice.getBranchContactEmployee()); + + // Set it back + branchOffice.setBranchContactEmployee(managedContact); + } + + // Is owner employee set? + if (branchOffice.getBranchOwnerEmployee() instanceof Contact) { + // Get managed lead contact + final Contact managedContact = this.createManaged(branchOffice.getBranchOwnerEmployee()); + + // Set it back + branchOffice.setBranchOwnerEmployee(managedContact); + } + // Is user instance set? if (branchOffice.getBranchCompany() instanceof BasicData) { // Get managed instance back diff --git a/src/java/org/mxchange/jcontactsbusiness/model/department/PizzaAdminDepartmentSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/department/PizzaAdminDepartmentSessionBean.java index 28402df..0fbfe5c 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/department/PizzaAdminDepartmentSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/department/PizzaAdminDepartmentSessionBean.java @@ -21,10 +21,10 @@ import java.util.Date; import java.util.List; import javax.ejb.EJB; import javax.ejb.Stateless; +import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentAlreadyAddedException; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jcontactsbusiness.model.employee.Employable; import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; import org.mxchange.jusercore.model.user.User; import org.mxchange.pizzaapplication.enterprise.BasePizzaEnterpriseBean; @@ -116,12 +116,12 @@ public class PizzaAdminDepartmentSessionBean extends BasePizzaEnterpriseBean imp } // Is lead employee set? - if (department.getDepartmentLead()instanceof Employable) { - // Get managed lead employee - final Employable managedEmployee = this.createManaged(department.getDepartmentLead()); + if (department.getDepartmentLead() instanceof Contact) { + // Get managed lead contact + final Contact managedContact = this.createManaged(department.getDepartmentLead()); // Set it back - department.setDepartmentLead(managedEmployee); + department.setDepartmentLead(managedContact); } // Is "owning" user set? diff --git a/src/java/org/mxchange/jcontactsbusiness/model/headquarter/PizzaAdminHeadquarterSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/PizzaAdminHeadquarterSessionBean.java index 79cda54..86d809c 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/headquarter/PizzaAdminHeadquarterSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/PizzaAdminHeadquarterSessionBean.java @@ -21,6 +21,7 @@ import java.util.Date; import java.util.List; import javax.ejb.EJB; import javax.ejb.Stateless; +import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterAlreadyAddedException; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; import org.mxchange.jcountry.model.data.Country; @@ -74,6 +75,15 @@ public class PizzaAdminHeadquarterSessionBean extends BasePizzaEnterpriseBean im // Add created timestamp headquarter.setHeadquarterEntryCreated(new Date()); + // Is contact employee set? + if (headquarter.getHeadquarterContactEmployee() instanceof Contact) { + // Get managed lead contact + final Contact managedContact = this.createManaged(headquarter.getHeadquarterContactEmployee()); + + // Set it back + headquarter.setHeadquarterContactEmployee(managedContact); + } + // Is user instance set? if (headquarter.getHeadquarterUserOwner() instanceof User) { // Get managed instance back -- 2.39.5