]> git.mxchange.org Git - addressbook-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sun, 24 Sep 2017 13:34:12 +0000 (15:34 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 1 Feb 2020 03:05:21 +0000 (04:05 +0100)
- renamed setAllContactPhoneEntriesCreated() -> setAllPhoneEntriesCreated()
- added similar methods for company basic data and branch offices
- also their phone number's created timestamps must be set prior persisting

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java
src/java/org/mxchange/jcontacts/model/contact/AddressbookAdminContactSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java
src/java/org/mxchange/jusercore/model/user/AddressbookAdminUserSessionBean.java

index b42824cfb65120a9bc29aa0189da822738974eca..3748fcd2c574f727a5f6532fad0c7ed24fde23df 100644 (file)
@@ -31,6 +31,7 @@ import org.mxchange.jcontacts.model.contact.ContactUtils;
 import org.mxchange.jcontacts.model.contact.UserContact;
 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
 import org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
 import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployee;
 import org.mxchange.jcontactsbusiness.model.employee.Employee;
 import org.mxchange.jcoreee.database.BaseDatabaseBean;
@@ -477,7 +478,308 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
        }
 
        /**
-        * Merges given (detached) contact's data
+        * Updates all contact's phone entry's created timestamps
+        * <p>
+        * @param contact Contact instance to update
+        */
+       protected void setAllPhoneEntriesCreated (final Contact contact) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: contact={0} - CALLED!", contact)); //NOI18N
+
+               // The contact instance must be valid
+               if (null == contact) {
+                       // Throw NPE
+                       throw new NullPointerException("contact is null"); //NOI18N
+               } else if (contact.getContactId() != null) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is unexpected.", contact.getContactId()));
+               }
+
+               // Get all phone instances
+               final DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
+               final DialableFaxNumber faxNumber = contact.getContactFaxNumber();
+               final DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1},mobileNumber={2}", landLineNumber, faxNumber, mobileNumber)); //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());
+               }
+
+               // Is a mobile number instance set?
+               if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for mobile number ..."); //NOI18N
+
+                       // Set updated timestamp
+                       mobileNumber.setPhoneEntryCreated(new Date());
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
+       }
+
+       /**
+        * Updates all branch office's phone entry's created timestamps
+        * <p>
+        * @param branchOffice Branch office instance to update
+        */
+       protected void setAllPhoneEntriesCreated (final BranchOffice branchOffice) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: branchOffice={0} - CALLED!", branchOffice)); //NOI18N
+
+               // The contact instance must be valid
+               if (null == branchOffice) {
+                       // Throw NPE again
+                       throw new NullPointerException("branchOffice is null"); //NOI18N
+               } else if (branchOffice.getBranchId() != null) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is unexpected.", branchOffice.getBranchId()));
+               }
+
+               // Get all phone instances
+               final DialableLandLineNumber landLineNumber = branchOffice.getBranchLandLineNumber();
+               final DialableFaxNumber faxNumber = branchOffice.getBranchFaxNumber();
+
+               // 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>
+        * @param basicData Company basic data instance to update
+        */
+       protected void setAllPhoneEntriesCreated (final BusinessBasicData basicData) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: basicData={0} - CALLED!", basicData)); //NOI18N
+
+               // The contact instance must be valid
+               if (null == basicData) {
+                       // Throw NPE again
+                       throw new NullPointerException("basicData is null"); //NOI18N
+               } else if (basicData.getBasicDataId() != null) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is unexpected.", basicData.getBasicDataId()));
+               }
+
+               // Get all phone instances
+               final DialableLandLineNumber landLineNumber = basicData.getCompanyLandLineNumber();
+               final DialableFaxNumber faxNumber = basicData.getCompanyFaxNumber();
+
+               // 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());
+
+                       // Set it back in basic data
+                       basicData.setCompanyLandLineNumber(landLineNumber);
+               }
+
+               // 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());
+
+                       // Set it back in basic data
+                       basicData.setCompanyFaxNumber(faxNumber);
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
+       }
+
+       /**
+        * Returns a detached instance from given mobile instance
+        * <p>
+        * @param mobileNumber  Mobile instance
+        * @param fetchedNumber Found mobile number in database
+        * <p>
+        * @return Detached instance
+        */
+       protected DialableMobileNumber getDetached (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: mobileNumber={0},fetchedNumber={1} - CALLED!", mobileNumber, fetchedNumber)); //NOI18N
+
+               // Should be valid
+               if (null == mobileNumber) {
+                       // Throw NPE
+                       throw new NullPointerException("mobileNumber is null"); //NOI18N
+               } else if (fetchedNumber.getPhoneId() == null) {
+                       // ..and again
+                       throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
+               }
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
+
+               // Init query instance
+               final DialableMobileNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
+
+               // Default is null
+               DialableMobileNumber detachedNumber = null;
+
+               // Is there a difference?
+               if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
+                       // Merge this entry
+                       detachedNumber = this.getEntityManager().merge(foundNumber);
+
+                       // @TODO Copy all
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
+
+               // Return it
+               return detachedNumber;
+       }
+
+       /**
+        * Returns a detached instance from given land-line instance
+        * <p>
+        * @param landLineNumber Land-line instance
+        * @param fetchedNumber  Found land-line number in database
+        * <p>
+        * @return Detached instance
+        */
+       protected DialableLandLineNumber getDetached (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: landLineNumber={0},fetchedNumber={1} - CALLED!", landLineNumber, fetchedNumber)); //NOI18N
+
+               // Should be valid
+               if (null == landLineNumber) {
+                       // Throw NPE
+                       throw new NullPointerException("landLineNumber is null"); //NOI18N
+               } else if (fetchedNumber.getPhoneId() == null) {
+                       // ..and again
+                       throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
+               }
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
+
+               // Init query instance
+               final DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
+
+               // Default is null
+               DialableLandLineNumber detachedNumber = null;
+
+               // Is there a difference?
+               if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
+                       // Merge this entry
+                       detachedNumber = this.getEntityManager().merge(foundNumber);
+
+                       // @TODO Copy all
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
+
+               // Return it
+               return detachedNumber;
+       }
+
+       /**
+        * Returns a detached instance from given fax instance
+        * <p>
+        * @param faxNumber     Fax instance
+        * @param fetchedNumber Found fax number in database
+        * <p>
+        * @return Detached instance
+        */
+       protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber)); //NOI18N
+
+               // Should be valid
+               if (null == faxNumber) {
+                       // Throw NPE
+                       throw new NullPointerException("faxNumber is null"); //NOI18N
+               } else if (fetchedNumber.getPhoneId() == null) {
+                       // ..and again
+                       throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
+               }
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
+
+               // Init query instance
+               final DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
+
+               // Default is null
+               DialableFaxNumber detachedNumber = null;
+
+               // Is there a difference?
+               if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
+                       // Merge this entry
+                       detachedNumber = this.getEntityManager().merge(foundNumber);
+
+                       // @TODO Copy all
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
+
+               // Return it
+               return detachedNumber;
+       }
+
+       /**
+        * Merges given contact's data
         * <p>
         * @param detachedContact Contact instance to merge
         * <p>
index d70e55d5dfe6a1b174edacfacac64e05d85d0b3d..27a86a7c8ad37cf7c175afab09cd7f77ff965a7f 100644 (file)
@@ -67,7 +67,7 @@ public class AddressbookAdminContactSessionBean extends BaseAddressbookDatabaseB
                contact.setContactCreated(new Date());
 
                // Set all created timestamps, if instance is there
-               this.setAllContactPhoneEntriesCreated(contact);
+               this.setAllPhoneEntriesCreated(contact);
 
                // Persist it
                this.getEntityManager().persist(contact);
index d056511c8a8ccc57739f63ff15b0365abe491c35..8be82ff83c5b1eaf72d251b9dc96e39178a0393d 100644 (file)
@@ -101,6 +101,9 @@ public class AddressbookAdminBusinessDataSessionBean extends BaseAddressbookData
                        basicData.setCompanyContactEmployee(managedEmployee);
                }
 
+               // Set created timestamps for any assigned numbers
+               this.setAllPhoneEntriesCreated(basicData);
+
                // Persist it
                this.getEntityManager().persist(basicData);
 
index 0d44c9988aa39f8521c37cc20e23988d9708d5b3..6456896b85e1558c9d78ad8aafcb05fb240cf131 100644 (file)
@@ -101,6 +101,9 @@ public class AddressbookAdminBranchOfficeSessionBean extends BaseAddressbookData
                        branchOffice.setBranchCountry(managedCountry);
                }
 
+               // Set "created" timestamp on any number assigned
+               this.setAllPhoneEntriesCreated(branchOffice);
+
                // Persist it
                this.getEntityManager().persist(branchOffice);
 
index 6836963ba9b2adec2c70d0f59cb698219d4fb95a..368d1d2bef7f3ad799d2f073242c093239ce9378 100644 (file)
@@ -91,8 +91,8 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean
                user.setUserCreated(new Date());
                user.getUserContact().setContactCreated(new Date());
 
-               // Update cellphone, land-line and fax instance
-               this.setAllContactPhoneEntriesCreated(user.getUserContact());
+               // Update mobile, land-line and fax instance
+               this.setAllPhoneEntriesCreated(user.getUserContact());
 
                // Persist it
                this.getEntityManager().persist(user);