]> git.mxchange.org Git - jfinancials-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Wed, 1 Nov 2017 21:35:35 +0000 (22:35 +0100)
committerRoland Häder <roland@mxchange.org>
Wed, 1 Nov 2017 21:35:35 +0000 (22:35 +0100)
- added EJBs for headquarters entity, general and administrative
- added method for updating all "phone created" timestamps in above entity
- renamed entity class name in persistence.xml

Signed-off-by: Roland Häder <roland@mxchange.org>
src/conf/persistence.xml
src/java/org/mxchange/jcontactsbusiness/model/department/FinancialsAdminDepartmentSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/headquarters/FinancialsAdminHeadquartersSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jcontactsbusiness/model/headquarters/FinancialsHeadquartersSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/database/BaseFinancialsDatabaseBean.java

index 4c9afc99c34ff8af78e6417fa1ba29c93e862a3b..61a44e2431e86374f41154091ca74180616f3da9 100644 (file)
@@ -7,7 +7,7 @@
     <class>org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice</class>
     <class>org.mxchange.jcontactsbusiness.model.department.BusinessDepartment</class>
     <class>org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee</class>
-    <class>org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquartersData</class>
+    <class>org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquarters</class>
     <class>org.mxchange.jcontactsbusiness.model.jobposition.EmployeePosition</class>
     <class>org.mxchange.jcontactsbusiness.model.logo.BusinessLogo</class>
     <class>org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime</class>
index 6f2c33a5cfe765c0141c44caa42f5fb905ccc4c0..7e0e1027c7ae462f4c550757f7e67a52bad81376 100644 (file)
@@ -23,11 +23,11 @@ import javax.ejb.EJB;
 import javax.ejb.Stateless;
 import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentAlreadyAddedException;
 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
-import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData;
 import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jcontactsbusiness.model.employee.Employable;
 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
+import org.mxchange.jcontactsbusiness.model.headquarters.Headquarter;
 
 /**
  * A stateless session bean for administrative department purposes
@@ -107,9 +107,9 @@ public class FinancialsAdminDepartmentSessionBean extends BaseFinancialsDatabase
                }
 
                // Is headquarters set?
-               if (department.getDepartmentHeadquarters() instanceof HeadquartersData) {
+               if (department.getDepartmentHeadquarters() instanceof Headquarter) {
                        // Get managed headquarters
-                       final HeadquartersData managedHeadquarters = this.createManaged(department.getDepartmentHeadquarters());
+                       final Headquarter managedHeadquarters = this.createManaged(department.getDepartmentHeadquarters());
 
                        // Set it back
                        department.setDepartmentHeadquarters(managedHeadquarters);
diff --git a/src/java/org/mxchange/jcontactsbusiness/model/headquarters/FinancialsAdminHeadquartersSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarters/FinancialsAdminHeadquartersSessionBean.java
new file mode 100644 (file)
index 0000000..a24ae7d
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.model.headquarters;
+
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.List;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import org.mxchange.jcontactsbusiness.exceptions.headquarters.HeadquartersAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A stateless session bean for administrative branch office purposes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "adminHeadquarter", description = "An administrative statless bean for handling branch office data (all)")
+public class FinancialsAdminHeadquartersSessionBean extends BaseFinancialsDatabaseBean implements AdminHeadquartersSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 58_467_386_571_701L;
+
+       /**
+        * General branch office bean
+        */
+       @EJB (lookup = "java:global/jfinancials-ejb/headquarters!org.mxchange.jcontactsbusiness.model.headquarters.HeadquarterSessionBeanRemote")
+       private HeadquartersSessionBeanRemote headquartersBean;
+
+       /**
+        * Default constructor
+        */
+       public FinancialsAdminHeadquartersSessionBean () {
+               // Call super constructor
+               super();
+       }
+
+       @Override
+       public Headquarter addHeadquarters (final Headquarter headquarter) throws HeadquartersAlreadyAddedException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addHeadquarters(): headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N
+
+               // Validate parameter
+               if (null == headquarter) {
+                       // Throw NPE
+                       throw new NullPointerException("headquarter is null"); //NOI18N
+               } else if (headquarter.getHeadquartersId() instanceof Long) {
+                       // Should not happen
+                       throw new IllegalArgumentException("headquarter.branchId should not be set."); //NOI18N
+               } else if (this.isHeadquarterFound(headquarter)) {
+                       // Already added, abort here
+                       throw new HeadquartersAlreadyAddedException(headquarter);
+               }
+
+               // Add created timestamp
+               headquarter.setHeadquartersCreated(new Date());
+
+               // Is user instance set?
+               if (headquarter.getHeadquartersUserOwner() instanceof User) {
+                       // Get managed instance back
+                       final User managedUser = this.createManaged(headquarter.getHeadquartersUserOwner());
+
+                       // Set it back in branch office
+                       headquarter.setHeadquartersUserOwner(managedUser);
+               }
+
+               // Is user instance set?
+               if (headquarter.getHeadquartersCountry() instanceof Country) {
+                       // Get managed instance back
+                       final Country managedCountry = this.createManaged(headquarter.getHeadquartersCountry());
+
+                       // Set it back in branch office
+                       headquarter.setHeadquartersCountry(managedCountry);
+               }
+
+               // Set "created" timestamp on any number assigned
+               this.setAllPhoneEntriesCreated(headquarter);
+
+               // Get opening times
+               final List<OpeningTime> openingTimes = headquarter.getHeadquartersOpeningTimes();
+
+               // Debugging:
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.addHeadquarters(): headquarter.headquarterOpeningTimes={1}", this.getClass().getSimpleName(), openingTimes));
+
+               // Is opening times set and not empty?
+               if ((openingTimes instanceof List) && (!openingTimes.isEmpty())) {
+                       // Add created timestamp for all times
+                       this.setAllOpeningTimesCreated(openingTimes);
+               } else {
+                       // Set all to null
+                       headquarter.setHeadquartersOpeningTimes(null);
+               }
+
+               // Persist it
+               this.getEntityManager().persist(headquarter);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addHeadquarters(): headquarter.branchId={1} - EXIT!", this.getClass().getSimpleName(), headquarter.getHeadquartersId())); //NOI18N
+
+               // Return updated instance
+               return headquarter;
+       }
+
+       /**
+        * Checks if given branch office's address is already persisted. The whole
+        * (persisted) list is being loaded and each address is being matched
+        * against the given branch office's address.
+        * <p>
+        * @param headquarter Headquarters office being checked
+        * <p>
+        * @return Whether it has been found
+        */
+       private boolean isHeadquarterFound (final Headquarter headquarter) {
+               // Get whole list
+               final List<Headquarter> headquarters = this.headquartersBean.allHeadquarters();
+
+               // Default is not found
+               boolean isFound = false;
+
+               // Check all single addresses
+               for (final Headquarter hq : headquarters) {
+                       // Is the same address found?
+                       if (Headquarters.isSameAddress(hq, headquarter)) {
+                               // Found one
+                               isFound = true;
+                               break;
+                       }
+               }
+
+               // Return flag
+               return isFound;
+       }
+
+}
diff --git a/src/java/org/mxchange/jcontactsbusiness/model/headquarters/FinancialsHeadquartersSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarters/FinancialsHeadquartersSessionBean.java
new file mode 100644 (file)
index 0000000..76e671f
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.model.headquarters;
+
+import java.text.MessageFormat;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.Query;
+import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean;
+
+/**
+ * A stateless session bean for general headquarters purposes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "headquarters", description = "A general statless bean for handling headquarters data (all)")
+public class FinancialsHeadquartersSessionBean extends BaseFinancialsDatabaseBean implements HeadquartersSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 58_467_386_571_701L;
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<Headquarter> allHeadquarters () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allHeadquarters: CALLED!", this.getClass().getSimpleName())); //NOI18N
+
+               // Get query
+               final Query query = this.getEntityManager().createNamedQuery("AllHeadquarters"); //NOI18N
+
+               // Get list from it
+               final List<Headquarter> list = query.getResultList();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allHeadquarters: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
+
+               // Return it
+               return list;
+       }
+
+}
index 9119e1b1f92f530cd87ba0876652cabb8a064672..9e0d2b7114eeb336ddadefa9b000f45729ad3196 100644 (file)
@@ -30,12 +30,14 @@ import javax.mail.internet.InternetAddress;
 import org.mxchange.jcontacts.model.contact.Contact;
 import org.mxchange.jcontacts.model.contact.ContactUtils;
 import org.mxchange.jcontacts.model.contact.UserContact;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
 import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice;
 import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee;
-import org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquartersData;
-import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData;
+import org.mxchange.jcontactsbusiness.model.employee.Employable;
+import org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquarters;
+import org.mxchange.jcontactsbusiness.model.headquarters.Headquarter;
 import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
 import org.mxchange.jcoreee.database.BaseDatabaseBean;
 import org.mxchange.jcountry.model.data.Country;
@@ -52,8 +54,6 @@ import org.mxchange.jphone.utils.PhoneUtils;
 import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserUtils;
-import org.mxchange.jcontactsbusiness.model.employee.Employable;
-import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
 
 /**
  * A helper class for beans that access the database.
@@ -197,28 +197,28 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean {
        /**
         * Get back a managed instance from given branch office
         * <p>
-        * @param branchOffice Unmanaged/detached branch office instance
+        * @param headquarter Unmanaged/detached branch office instance
         * <p>
         * @return Managed basic data instance
         */
-       protected BranchOffice createManaged (final BranchOffice branchOffice) {
+       protected BranchOffice createManaged (final BranchOffice headquarter) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N
 
                // user should not be null
-               if (null == branchOffice) {
+               if (null == headquarter) {
                        // Abort here
-                       throw new NullPointerException("branchOffice is null"); //NOI18N
-               } else if (branchOffice.getBranchId() == null) {
+                       throw new NullPointerException("headquarter is null"); //NOI18N
+               } else if (headquarter.getBranchId() == null) {
                        // Id is set
-                       throw new NullPointerException("branchOffice.branchOfficeId is null"); //NOI18N
-               } else if (branchOffice.getBranchId() < 1) {
+                       throw new NullPointerException("headquarter.headquarterId is null"); //NOI18N
+               } else if (headquarter.getBranchId() < 1) {
                        // Id is set
-                       throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchOfficeId={0} is invalid", branchOffice.getBranchId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("headquarter.headquarterId={0} is invalid", headquarter.getBranchId())); //NOI18N
                }
 
                // Try to find it (should be there)
-               final BranchOffice managedBranchOffice = this.getEntityManager().find(BusinessBranchOffice.class, branchOffice.getBranchId());
+               final BranchOffice managedBranchOffice = this.getEntityManager().find(BusinessBranchOffice.class, headquarter.getBranchId());
 
                // Should be there
                assert (managedBranchOffice instanceof BasicData) : "managedBranchOffice is null"; //NOI18N
@@ -273,24 +273,24 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean {
         * <p>
         * @return Managed basic data instance
         */
-       protected HeadquartersData createManaged (final HeadquartersData headquarters) {
+       protected Headquarter createManaged (final Headquarter headquarters) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: branchOffice={1} - CALLED!", this.getClass().getSimpleName(), headquarters)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarters)); //NOI18N
 
                // user should not be null
                if (null == headquarters) {
                        // Abort here
-                       throw new NullPointerException("branchOffice is null"); //NOI18N
+                       throw new NullPointerException("headquarter is null"); //NOI18N
                } else if (headquarters.getHeadquartersId() == null) {
                        // Id is set
-                       throw new NullPointerException("branchOffice.headquartersId is null"); //NOI18N
+                       throw new NullPointerException("headquarter.headquartersId is null"); //NOI18N
                } else if (headquarters.getHeadquartersId() < 1) {
                        // Id is set
-                       throw new IllegalArgumentException(MessageFormat.format("branchOffice.headquartersId={0} is invalid", headquarters.getHeadquartersId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("headquarter.headquartersId={0} is invalid", headquarters.getHeadquartersId())); //NOI18N
                }
 
                // Try to find it (should be there)
-               final HeadquartersData managedHeadquarters = this.getEntityManager().find(BusinessHeadquartersData.class, headquarters.getHeadquartersId());
+               final Headquarter managedHeadquarters = this.getEntityManager().find(BusinessHeadquarters.class, headquarters.getHeadquartersId());
 
                // Should be there
                assert (managedHeadquarters instanceof BasicData) : "managedHeadquarters is null"; //NOI18N
@@ -483,6 +483,53 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean {
                this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
        }
 
+       /**
+        * Updates all branch office's phone entry's created timestamps
+        * <p>
+        * @param headquarter Headquarters instance to update
+        */
+       protected void setAllPhoneEntriesCreated (final Headquarter headquarter) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: headquarter={0} - CALLED!", headquarter)); //NOI18N
+
+               // The contact instance must be valid
+               if (null == headquarter) {
+                       // Throw NPE again
+                       throw new NullPointerException("headquarter is null"); //NOI18N
+               } else if (headquarter.getHeadquartersId() != null) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("headquarter.branchId={0} is unexpected.", headquarter.getHeadquartersId()));
+               }
+
+               // Get all phone instances
+               final DialableLandLineNumber landLineNumber = headquarter.getHeadquartersLandLineNumber();
+               final DialableFaxNumber faxNumber = headquarter.getHeadquartersFaxNumber();
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N
+
+               // Is a phone number instance set?
+               if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
+
+                       // Set updated timestamp
+                       landLineNumber.setPhoneEntryCreated(new Date());
+               }
+
+               // Is a fax number instance set?
+               if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
+
+                       // Set updated timestamp
+                       faxNumber.setPhoneEntryCreated(new Date());
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
+       }
+
        /**
         * Updates all company's phone entry's created timestamps
         * <p>