]> git.mxchange.org Git - jfinancials-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Fri, 24 Apr 2020 01:34:34 +0000 (03:34 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 24 Apr 2020 01:35:33 +0000 (03:35 +0200)
- implemented business method updateBranchOffice()
- added protected method mergeBranchOfficeData()

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jcontactsbusiness/model/branchoffice/FinancialsAdminBranchOfficeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/branchoffice/FinancialsBranchOfficeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/department/FinancialsAdminDepartmentSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/department/FinancialsDepartmentSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/headquarter/FinancialsAdminHeadquarterSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/headquarter/FinancialsHeadquarterSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/opening_time/FinancialsAdminOpeningTimesSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/opening_time/FinancialsOpeningTimesSessionBean.java
src/java/org/mxchange/jfinancials/enterprise/BaseFinancialsEnterpriseBean.java

index 41584c2276a61f770c1adb8569c49e07199feed2..8be5c1de593322c180094455a72695a34fc244fe 100644 (file)
@@ -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<OpeningTime> 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<BranchOffice> 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;
        }
index ae95ba61f5347e1bf3b16d2106d3a9c67318cc00..4c93b443cf11e3c0ddc46cc9118e376263f1b893 100644 (file)
@@ -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")
index f23f267dc16e4590aab0547365b89e3130254f78..5370044f95e31fbd488c4793a9226ac710bd40aa 100644 (file)
@@ -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());
 
index d64b7619bcfddcb34eb9d2f746f51d01fb82cad3..1dbeb09fbda36b2c22144c281efd1b4f0693b5f9 100644 (file)
@@ -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")
index 307ca3754f1fa559962a949a013d205c07d4b00c..d860f20b0aef354dfa8e09228013d8ccf800bb39 100644 (file)
@@ -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
index 37094d7254a71f2cd8ef9674b0566d211e63a6f0..3d28effc0b1a41a0acfd418bf0707533a3f68304 100644 (file)
  */
 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")
index ea9749bd3ef9e9b7d6016d190f096f3677d1f081..3a4b99df9828733d57f174a6e205175c8d6889e3 100644 (file)
@@ -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
                }
index c87d2ea0e1905828b772203fc7216344fec086d7..ff04b6efaf774e5b0354f42b6ca0bcdd02467df3 100644 (file)
@@ -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")
index ffb1e83197da491f4801033b4c503c2a36d761aa..c86456e76d0b9b34635c8bd92ff19b41c78bf502 100644 (file)
@@ -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
+        * <p>
+        * @param detachedBranchOffice Branch office instance to merge
+        * <p>
+        * @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
         * <p>