From d9296f1998a8f726c9cb71690bde58cba5decb70 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 --- ...inancialsAdminBranchOfficeSessionBean.java | 39 ++++++++++++++- .../FinancialsBranchOfficeSessionBean.java | 2 +- .../FinancialsAdminDepartmentSessionBean.java | 6 +-- .../FinancialsDepartmentSessionBean.java | 2 +- ...FinancialsAdminHeadquarterSessionBean.java | 2 +- .../FinancialsHeadquarterSessionBean.java | 4 +- ...inancialsAdminOpeningTimesSessionBean.java | 10 ++-- .../FinancialsOpeningTimesSessionBean.java | 2 +- .../BaseFinancialsEnterpriseBean.java | 49 +++++++++++++++++++ 9 files changed, 100 insertions(+), 16 deletions(-) diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/FinancialsAdminBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/FinancialsAdminBranchOfficeSessionBean.java index 41584c2..8be5c1d 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/FinancialsAdminBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/FinancialsAdminBranchOfficeSessionBean.java @@ -22,6 +22,7 @@ import java.util.List; import javax.ejb.EJB; import javax.ejb.Stateless; 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; @@ -109,7 +110,7 @@ public class FinancialsAdminBranchOfficeSessionBean extends BaseFinancialsEnterp 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())) { @@ -130,6 +131,36 @@ public class FinancialsAdminBranchOfficeSessionBean extends BaseFinancialsEnterp 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 @@ -140,6 +171,9 @@ public class FinancialsAdminBranchOfficeSessionBean extends BaseFinancialsEnterp * @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(); @@ -156,6 +190,9 @@ public class FinancialsAdminBranchOfficeSessionBean extends BaseFinancialsEnterp } } + // 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/FinancialsBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/FinancialsBranchOfficeSessionBean.java index ae95ba6..4c93b44 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/FinancialsBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/FinancialsBranchOfficeSessionBean.java @@ -33,7 +33,7 @@ public class FinancialsBranchOfficeSessionBean extends BaseFinancialsEnterpriseB /** * 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/FinancialsAdminDepartmentSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/department/FinancialsAdminDepartmentSessionBean.java index f23f267..5370044 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/department/FinancialsAdminDepartmentSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/department/FinancialsAdminDepartmentSessionBean.java @@ -40,7 +40,7 @@ public class FinancialsAdminDepartmentSessionBean extends BaseFinancialsEnterpri /** * 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 @@ -116,7 +116,7 @@ public class FinancialsAdminDepartmentSessionBean extends BaseFinancialsEnterpri } // Is lead employee set? - if (department.getDepartmentLead()instanceof Employable) { + if (department.getDepartmentLead() instanceof Employable) { // Get managed lead employee final Employable managedEmployee = this.createManaged(department.getDepartmentLead()); @@ -125,7 +125,7 @@ public class FinancialsAdminDepartmentSessionBean extends BaseFinancialsEnterpri } // 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/FinancialsDepartmentSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/department/FinancialsDepartmentSessionBean.java index d64b761..1dbeb09 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/department/FinancialsDepartmentSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/department/FinancialsDepartmentSessionBean.java @@ -33,7 +33,7 @@ public class FinancialsDepartmentSessionBean extends BaseFinancialsEnterpriseBea /** * 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/FinancialsAdminHeadquarterSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/FinancialsAdminHeadquarterSessionBean.java index 307ca37..d860f20 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/headquarter/FinancialsAdminHeadquarterSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/FinancialsAdminHeadquarterSessionBean.java @@ -38,7 +38,7 @@ public class FinancialsAdminHeadquarterSessionBean extends BaseFinancialsEnterpr /** * 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/FinancialsHeadquarterSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/FinancialsHeadquarterSessionBean.java index 37094d7..3d28eff 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/headquarter/FinancialsHeadquarterSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/FinancialsHeadquarterSessionBean.java @@ -16,13 +16,11 @@ */ package org.mxchange.jcontactsbusiness.model.headquarter; -import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; import java.text.MessageFormat; import java.util.List; import javax.ejb.Stateless; import javax.persistence.Query; import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean; -import org.mxchange.jcontactsbusiness.model.headquarter.HeadquarterSessionBeanRemote; /** * A stateless session bean for general headquarter purposes @@ -35,7 +33,7 @@ public class FinancialsHeadquarterSessionBean extends BaseFinancialsEnterpriseBe /** * 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/FinancialsAdminOpeningTimesSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/FinancialsAdminOpeningTimesSessionBean.java index ea9749b..3a4b99d 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/FinancialsAdminOpeningTimesSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/FinancialsAdminOpeningTimesSessionBean.java @@ -32,7 +32,7 @@ public class FinancialsAdminOpeningTimesSessionBean extends BaseFinancialsEnterp /** * 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 FinancialsAdminOpeningTimesSessionBean extends BaseFinancialsEnterp } 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/FinancialsOpeningTimesSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/FinancialsOpeningTimesSessionBean.java index c87d2ea..ff04b6e 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/FinancialsOpeningTimesSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/FinancialsOpeningTimesSessionBean.java @@ -33,7 +33,7 @@ public class FinancialsOpeningTimesSessionBean extends BaseFinancialsEnterpriseB /** * 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/jfinancials/enterprise/BaseFinancialsEnterpriseBean.java b/src/java/org/mxchange/jfinancials/enterprise/BaseFinancialsEnterpriseBean.java index ffb1e83..c86456e 100644 --- a/src/java/org/mxchange/jfinancials/enterprise/BaseFinancialsEnterpriseBean.java +++ b/src/java/org/mxchange/jfinancials/enterprise/BaseFinancialsEnterpriseBean.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; @@ -876,6 +877,54 @@ public abstract class BaseFinancialsEnterpriseBean 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