]> git.mxchange.org Git - jjobs-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>
Wed, 10 Jun 2020 18:29:56 +0000 (20:29 +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/JobsAdminBranchOfficeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsBranchOfficeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/department/JobsAdminDepartmentSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/department/JobsDepartmentSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/headquarter/JobsAdminHeadquarterSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/headquarter/JobsHeadquarterSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/opening_time/JobsAdminOpeningTimesSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/opening_time/JobsOpeningTimesSessionBean.java
src/java/org/mxchange/jjobs/enterprise/BaseJobsEnterpriseBean.java

index baf8451494cdb8b2c4695d60013481f7d0423075..93830f79485d5840f2f7bb7b57e3c3e493d01a80 100644 (file)
@@ -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<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())) {
@@ -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<BranchOffice> 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;
        }
index 76b81c09c6ee77caca8a36385beb2b10f73b47c3..8a7fa8cc5c52b5044592390527a5212c48f3aa19 100644 (file)
@@ -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")
index aa3d8058b5843320015d7d0fc907721c6902a996..70d2c7064d2248f1cc91c88a20094b81732e0279 100644 (file)
@@ -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());
 
index 9082de97ee0c3d75d29df15637bc8a641854fc1d..f371c944c8f98cf9d1211e97c11cecd5997f693a 100644 (file)
@@ -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")
index 4a509c25a898b311933b19687a15269a63064b80..f1521d4a09fcdcfcd827efc473a078e31f7bdecb 100644 (file)
@@ -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
index 3164719e826c6fa0a748670ddf9e705099c8e053..fa006f8fee2bdff0a075f10763dfb8cc707e295a 100644 (file)
@@ -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")
index 37f1e1aaa6ab4cf27f12b1d1265f3df69c25ffc5..6596b5cf8d3a48779f9b1418a992b8e9d7e472f6 100644 (file)
@@ -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
                }
index eef95bb6a36fdcab3b75c46754900ce1ddb339a4..e85b93c7dfa2f8cb102a2e453faf5a9f82594ea0 100644 (file)
@@ -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")
index f956c349fee1ef1491803c3b8fdac78e1d190ecf..477513cb849c6bf585be05b95ce5c682dafe7fd3 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;
@@ -816,6 +817,54 @@ public abstract class BaseJobsEnterpriseBean 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>