From 06bbf84932c8e72936fdd6301baf325ac5887f47 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 24 Apr 2020 03:34:34 +0200 Subject: [PATCH] Please cherry-pick: - implemented business method updateBranchOffice() - added protected method mergeBranchOfficeData() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../JobsAdminBranchOfficeSessionBean.java | 39 ++++++++++++++- .../JobsBranchOfficeSessionBean.java | 2 +- .../JobsAdminDepartmentSessionBean.java | 4 +- .../department/JobsDepartmentSessionBean.java | 2 +- .../JobsAdminHeadquarterSessionBean.java | 2 +- .../JobsHeadquarterSessionBean.java | 2 +- .../JobsAdminOpeningTimesSessionBean.java | 10 ++-- .../JobsOpeningTimesSessionBean.java | 2 +- .../enterprise/BaseJobsEnterpriseBean.java | 49 +++++++++++++++++++ 9 files changed, 99 insertions(+), 13 deletions(-) diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsAdminBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsAdminBranchOfficeSessionBean.java index baf8451..93830f7 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsAdminBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsAdminBranchOfficeSessionBean.java @@ -23,6 +23,7 @@ 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.exceptions.branchoffice.BranchOfficeNotFoundException; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; import org.mxchange.jcountry.model.data.Country; @@ -128,7 +129,7 @@ public class JobsAdminBranchOfficeSessionBean extends BaseJobsEnterpriseBean imp final List openingTimes = branchOffice.getBranchOpeningTimes(); // Debugging: - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.addBranchOffice(): branchOffice.branchOfficeOpeningTimes={1}", this.getClass().getSimpleName(), openingTimes)); + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.addBranchOffice(): branchOffice.branchOfficeOpeningTimes={1}", this.getClass().getSimpleName(), openingTimes)); //NOI18N // Is opening times set and not empty? if ((openingTimes instanceof List) && (!openingTimes.isEmpty())) { @@ -149,6 +150,36 @@ public class JobsAdminBranchOfficeSessionBean extends BaseJobsEnterpriseBean imp return branchOffice; } + @Override + public BranchOffice updateBranchOffice (final BranchOffice branchOffice) throws BranchOfficeNotFoundException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateBranchOffice(): branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N + + // Is parameter valid? + if (null == branchOffice) { + // Throw NPE + throw new NullPointerException("branchOffice is null"); //NOI18N + } else if (branchOffice.getBranchId() == null) { + // Throw NPE again + throw new NullPointerException("branchOffice.branchId is null"); //NOI18N + } else if (branchOffice.getBranchId() < 1) { + // Throw IAE again + throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is invalid", branchOffice.getBranchId())); //NOI18N + } else if (!this.isBranchOfficeFound(branchOffice)) { + // Not found + throw new BranchOfficeNotFoundException(branchOffice.getBranchId()); + } + + // Merge data + final BranchOffice updatedBranchOffice = this.mergeBranchOfficeData(branchOffice); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateBranchOffice(): updatedBranchOffice={1} - EXIT!", this.getClass().getSimpleName(), updatedBranchOffice)); + + // Return updated instance + return updatedBranchOffice; + } + /** * Checks if given branch office's address is already persisted. The whole * (persisted) list is being loaded and each address is being matched @@ -159,6 +190,9 @@ public class JobsAdminBranchOfficeSessionBean extends BaseJobsEnterpriseBean imp * @return Whether it has been found */ private boolean isBranchOfficeFound (final BranchOffice branchOffice) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isBranchOfficeFound(): branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N + // Get whole list final List branchOffices = this.branchOfficeBean.fetchAllBranchOffices(); @@ -175,6 +209,9 @@ public class JobsAdminBranchOfficeSessionBean extends BaseJobsEnterpriseBean imp } } + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isBranchOfficeFound(): isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N + // Return flag return isFound; } diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsBranchOfficeSessionBean.java index 76b81c0..8a7fa8c 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsBranchOfficeSessionBean.java @@ -33,7 +33,7 @@ public class JobsBranchOfficeSessionBean extends BaseJobsEnterpriseBean implemen /** * Serial number */ - private static final long serialVersionUID = 58_467_386_571_701L; + private static final long serialVersionUID = 58_467_386_571_702L; @Override @SuppressWarnings ("unchecked") diff --git a/src/java/org/mxchange/jcontactsbusiness/model/department/JobsAdminDepartmentSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/department/JobsAdminDepartmentSessionBean.java index aa3d805..70d2c70 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/department/JobsAdminDepartmentSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/department/JobsAdminDepartmentSessionBean.java @@ -40,7 +40,7 @@ public class JobsAdminDepartmentSessionBean extends BaseJobsEnterpriseBean imple /** * Serial number */ - private static final long serialVersionUID = 58_467_386_571_701L; + private static final long serialVersionUID = 58_467_386_571_703L; /** * General department bean @@ -125,7 +125,7 @@ public class JobsAdminDepartmentSessionBean extends BaseJobsEnterpriseBean imple } // Is "owning" user set? - if (department.getDepartmentUserOwner()instanceof User) { + if (department.getDepartmentUserOwner() instanceof User) { // Get managed user final User managedUser = this.createManaged(department.getDepartmentUserOwner()); diff --git a/src/java/org/mxchange/jcontactsbusiness/model/department/JobsDepartmentSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/department/JobsDepartmentSessionBean.java index 9082de9..f371c94 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/department/JobsDepartmentSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/department/JobsDepartmentSessionBean.java @@ -33,7 +33,7 @@ public class JobsDepartmentSessionBean extends BaseJobsEnterpriseBean implements /** * Serial number */ - private static final long serialVersionUID = 58_467_386_571_701L; + private static final long serialVersionUID = 58_467_386_571_704L; @Override @SuppressWarnings ("unchecked") diff --git a/src/java/org/mxchange/jcontactsbusiness/model/headquarter/JobsAdminHeadquarterSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/JobsAdminHeadquarterSessionBean.java index 4a509c2..f1521d4 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/headquarter/JobsAdminHeadquarterSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/JobsAdminHeadquarterSessionBean.java @@ -39,7 +39,7 @@ public class JobsAdminHeadquarterSessionBean extends BaseJobsEnterpriseBean impl /** * Serial number */ - private static final long serialVersionUID = 58_467_386_571_701L; + private static final long serialVersionUID = 58_467_386_571_706L; /** * General branch office bean diff --git a/src/java/org/mxchange/jcontactsbusiness/model/headquarter/JobsHeadquarterSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/JobsHeadquarterSessionBean.java index 3164719..fa006f8 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/headquarter/JobsHeadquarterSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/JobsHeadquarterSessionBean.java @@ -33,7 +33,7 @@ public class JobsHeadquarterSessionBean extends BaseJobsEnterpriseBean implement /** * Serial number */ - private static final long serialVersionUID = 58_467_386_571_701L; + private static final long serialVersionUID = 58_467_386_571_707L; @Override @SuppressWarnings ("unchecked") diff --git a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/JobsAdminOpeningTimesSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/JobsAdminOpeningTimesSessionBean.java index 37f1e1a..6596b5c 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/JobsAdminOpeningTimesSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/JobsAdminOpeningTimesSessionBean.java @@ -32,7 +32,7 @@ public class JobsAdminOpeningTimesSessionBean extends BaseJobsEnterpriseBean imp /** * Serial number */ - private static final long serialVersionUID = 58_467_386_571_701L; + private static final long serialVersionUID = 58_467_386_571_709L; /** * Default constructor @@ -54,16 +54,16 @@ public class JobsAdminOpeningTimesSessionBean extends BaseJobsEnterpriseBean imp } else if (openingTime.getOpeningTimeId() instanceof Long) { // Should not happen throw new IllegalArgumentException("openingTime.openingId should not be set."); //NOI18N - } else if (openingTime.getOpeningStartDay()== null) { + } else if (openingTime.getOpeningStartDay() == null) { // Throw NPE throw new NullPointerException("openingTime.openingStartDay is null"); //NOI18N - } else if (openingTime.getOpeningStartTime()== null) { + } else if (openingTime.getOpeningStartTime() == null) { // Throw NPE throw new NullPointerException("openingTime.openingStartTime is null"); //NOI18N - } else if (openingTime.getOpeningEndDay()== null) { + } else if (openingTime.getOpeningEndDay() == null) { // Throw NPE throw new NullPointerException("openingTime.openingEndDay is null"); //NOI18N - } else if (openingTime.getOpeningEndTime()== null) { + } else if (openingTime.getOpeningEndTime() == null) { // Throw NPE throw new NullPointerException("openingTime.openingEndTime is null"); //NOI18N } diff --git a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/JobsOpeningTimesSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/JobsOpeningTimesSessionBean.java index eef95bb..e85b93c 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/JobsOpeningTimesSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/JobsOpeningTimesSessionBean.java @@ -33,7 +33,7 @@ public class JobsOpeningTimesSessionBean extends BaseJobsEnterpriseBean implemen /** * Serial number */ - private static final long serialVersionUID = 58_467_386_571_701L; + private static final long serialVersionUID = 58_467_386_571_710L; @Override @SuppressWarnings ("unchecked") diff --git a/src/java/org/mxchange/jjobs/enterprise/BaseJobsEnterpriseBean.java b/src/java/org/mxchange/jjobs/enterprise/BaseJobsEnterpriseBean.java index f956c34..477513c 100644 --- a/src/java/org/mxchange/jjobs/enterprise/BaseJobsEnterpriseBean.java +++ b/src/java/org/mxchange/jjobs/enterprise/BaseJobsEnterpriseBean.java @@ -31,6 +31,7 @@ import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontacts.model.contact.Contacts; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; +import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices; import org.mxchange.jcontactsbusiness.model.department.Department; import org.mxchange.jcontactsbusiness.model.employee.Employable; import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; @@ -816,6 +817,54 @@ public abstract class BaseJobsEnterpriseBean extends BaseEnterpriseBean { return detachedNumber; } + /** + * Merges given branch office's data + *

+ * @param detachedBranchOffice Branch office instance to merge + *

+ * @return Detached contact instance + */ + protected BranchOffice mergeBranchOfficeData (final BranchOffice detachedBranchOffice) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeBranchOfficeData: detachedBranchOffice={0} - CALLED!", detachedBranchOffice)); //NOI18N + + // The contact instance must be valid + if (null == detachedBranchOffice) { + // Throw NPE again + throw new NullPointerException("detachedBranchOffice is null"); //NOI18N + } else if (detachedBranchOffice.getBranchId() == null) { + // Throw NPE again + throw new NullPointerException("detachedBranchOffice.branchId is null"); //NOI18N //NOI18N + } else if (detachedBranchOffice.getBranchId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("detachedBranchOffice.branchId ={0} is not valid.", detachedBranchOffice.getBranchId())); //NOI18N + } + + // Set updated timestamp + detachedBranchOffice.setBranchEntryUpdated(new Date()); + + // Get contact from it and find it + final BranchOffice foundBranchOffice = this.getEntityManager().find(detachedBranchOffice.getClass(), detachedBranchOffice.getBranchId()); + + // Should be found + assert (foundBranchOffice instanceof BranchOffice) : MessageFormat.format("Branch office with id {0} not found, but should be.", detachedBranchOffice.getBranchId()); //NOI18N + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeBranchOfficeData: foundContact.contactId={0}", foundBranchOffice.getBranchId())); //NOI18N + + // Copy all + BranchOffices.copyBranchOfficeData(detachedBranchOffice, foundBranchOffice); + + // Merge contact instance + final BranchOffice managedBranchOffice = this.getEntityManager().merge(foundBranchOffice); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeBranchOfficeData: managedBranchOffice={0} - EXIT!", managedBranchOffice)); //NOI18N + + // Return detached contact + return managedBranchOffice; + } + /** * Merges given contact's data *

-- 2.39.5