From: Roland Häder Date: Wed, 23 Nov 2022 20:29:14 +0000 (+0100) Subject: Don't cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2055cec2e2c020e762aa54183b17c24c14b8ec9d;p=addressbook-ejb.git Don't cherry-pick: - fixed a lot of stuff - upgraded project files to Apache NetBeans IDE 15 - updated jar(s) --- diff --git a/lib/jaddressbook-lib.jar b/lib/jaddressbook-lib.jar index 80e5a8e..5f4ba09 100644 Binary files a/lib/jaddressbook-lib.jar and b/lib/jaddressbook-lib.jar differ diff --git a/nbproject/ant-deploy.xml b/nbproject/ant-deploy.xml index 2d5f877..fdc06d5 100644 --- a/nbproject/ant-deploy.xml +++ b/nbproject/ant-deploy.xml @@ -1,4 +1,24 @@ + @@ -8,7 +28,7 @@ - + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index 722344d..7dd637f 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -522,8 +522,7 @@ or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties f - - + @@ -555,8 +554,7 @@ or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties f - - + @@ -707,18 +705,6 @@ or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties f - - - - - - - - - - - - @@ -734,8 +720,7 @@ or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties f - - + @@ -847,10 +832,6 @@ exists or setup the property manually. For example like this: - - - - @@ -858,6 +839,10 @@ exists or setup the property manually. For example like this: + + + + @@ -873,10 +858,6 @@ exists or setup the property manually. For example like this: - - - - @@ -884,6 +865,10 @@ exists or setup the property manually. For example like this: + + + + @@ -899,17 +884,17 @@ exists or setup the property manually. For example like this: - - - - - - - - - - - + + + + + + + + + + + @@ -926,10 +911,6 @@ exists or setup the property manually. For example like this: - - - - @@ -937,6 +918,10 @@ exists or setup the property manually. For example like this: + + + + @@ -1316,6 +1301,7 @@ exists or setup the property manually. For example like this: + diff --git a/nbproject/project.properties b/nbproject/project.properties index 0918318..cdd6ad0 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -48,7 +48,7 @@ includes=** j2ee.compile.on.save=true j2ee.deploy.on.save=true j2ee.platform=1.7 -j2ee.platform.classpath=${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/cdi-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar +j2ee.platform.classpath=${j2ee.server.home}/modules/cdi-api.jar:${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.security.enterprise-api.jar:${j2ee.server.home}/modules/javax.security.enterprise.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar diff --git a/src/java/org/mxchange/addressbook/enterprise/BaseAddressbookEnterpriseBean.java b/src/java/org/mxchange/addressbook/enterprise/BaseAddressbookEnterpriseBean.java index 57d7c9e..ec95022 100644 --- a/src/java/org/mxchange/addressbook/enterprise/BaseAddressbookEnterpriseBean.java +++ b/src/java/org/mxchange/addressbook/enterprise/BaseAddressbookEnterpriseBean.java @@ -28,7 +28,7 @@ import javax.mail.Address; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import org.mxchange.jcontacts.model.contact.Contact; -import org.mxchange.jcontacts.model.contact.Contacts; +import org.mxchange.jcontacts.model.utils.ContactUtils; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; import org.mxchange.jcontactsbusiness.model.department.Department; @@ -36,19 +36,21 @@ import org.mxchange.jcontactsbusiness.model.employee.Employable; import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; import org.mxchange.jcontactsbusiness.model.jobposition.HireableJobPosition; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; +import org.mxchange.jcontactsbusiness.model.utils.BranchOfficeUtils; +import org.mxchange.jcontactsbusiness.model.utils.DepartmentUtils; import org.mxchange.jcoreee.bean.ejb.BaseEnterpriseBean; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper; import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.model.phonenumbers.fax.FaxNumbers; import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumbers; import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumbers; import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; +import org.mxchange.jphone.model.utils.FaxNumberUtils; +import org.mxchange.jphone.model.utils.LandLineNumberUtils; +import org.mxchange.jphone.model.utils.MobileNumberUtils; import org.mxchange.jusercore.model.user.User; -import org.mxchange.jusercore.model.user.Users; +import org.mxchange.jusercore.model.utils.UserUtils; /** * A helper class for beans that access the database. @@ -369,7 +371,6 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseEnterpriseBean { return managedHeadquarter; } - /** * Get back a managed instance from given mobile provider *

@@ -688,147 +689,51 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseEnterpriseBean { } /** - * Returns a detached instance from given mobile instance - *

- * @param mobileNumber Mobile instance - * @param fetchedNumber Found mobile number in database - *

- * @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.getMobileId() == null) { - // ..and again - throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getMobileId())); //NOI18N - - // Init query instance - final DialableMobileNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getMobileId()); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N - - // Default is null - DialableMobileNumber detachedNumber = null; - - // Is there a difference? - if (!MobileNumbers.isSameMobileNumber(mobileNumber, fetchedNumber)) { - // @TODO Copy all to foundNumber, then merge - - // Merge this entry - detachedNumber = this.getEntityManager().merge(foundNumber); - } - - // 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 - *

- * @param landLineNumber Land-line instance - * @param fetchedNumber Found land-line number in database - *

- * @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 (!LandLineNumbers.isSameLandLineNumber(landLineNumber, fetchedNumber)) { - // @TODO Copy all to foundNumber, then merge - - // Merge this entry - detachedNumber = this.getEntityManager().merge(foundNumber); - } - - // 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 + * Merges given branch office's data *

- * @param faxNumber Fax instance - * @param fetchedNumber Found fax number in database + * @param detachedBranchOffice Branch office instance to merge *

- * @return Detached instance + * @return Detached contact instance */ - protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) { + protected BranchOffice mergeBranchOfficeData (final BranchOffice detachedBranchOffice) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeBranchOfficeData: detachedBranchOffice={0} - CALLED!", detachedBranchOffice)); //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 + // 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 + } else if (detachedBranchOffice.getBranchId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("detachedBranchOffice.branchId ={0} is not valid.", detachedBranchOffice.getBranchId())); //NOI18N } - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N + // Get contact from it and find it + final BranchOffice foundBranchOffice = this.getEntityManager().find(detachedBranchOffice.getClass(), detachedBranchOffice.getBranchId()); - // Init query instance - final DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId()); + // 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("getDetached: foundNumber={0}", foundNumber)); //NOI18N + this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeBranchOfficeData: foundContact.contactId={0}", foundBranchOffice.getBranchId())); //NOI18N - // Default is null - DialableFaxNumber detachedNumber = null; + // Copy all + BranchOfficeUtils.copyBranchOfficeData(detachedBranchOffice, foundBranchOffice); - // Is there a difference? - if (!FaxNumbers.isSameFaxNumber(faxNumber, fetchedNumber)) { - // @TODO Copy all to foundNumber, then merge + // Merge contact instance + final BranchOffice managedBranchOffice = this.getEntityManager().merge(foundBranchOffice); - // Merge this entry - detachedNumber = this.getEntityManager().merge(foundNumber); - } + // Set updated timestamp + managedBranchOffice.setBranchEntryUpdated(new Date()); // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeBranchOfficeData: managedBranchOffice={0} - EXIT!", managedBranchOffice)); //NOI18N - // Return it - return detachedNumber; + // Return detached contact + return managedBranchOffice; } /** @@ -848,30 +753,27 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseEnterpriseBean { throw new NullPointerException("detachedContact is null"); //NOI18N } else if (detachedContact.getContactId() == null) { // Throw NPE again - throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N + throw new NullPointerException("detachedContact.contactId is null"); //NOI18N } else if (detachedContact.getContactId() < 1) { // Not valid throw new IllegalStateException(MessageFormat.format("detachedContact.contactId={0} is not valid.", detachedContact.getContactId())); //NOI18N } - // Set updated timestamp - detachedContact.setContactEntryUpdated(new Date()); - // Get contact from it and find it - final Contact foundContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId()); - - // Should be found - assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N + final Contact foundContact = this.createManaged(detachedContact); // Debug message this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeContactData: foundContact.contactId={0}", foundContact.getContactId())); //NOI18N // Copy all - Contacts.copyContactData(detachedContact, foundContact); + ContactUtils.copyContactData(detachedContact, foundContact); // Merge contact instance final Contact managedContact = this.getEntityManager().merge(foundContact); + // Set updated timestamp + managedContact.setContactEntryUpdated(new Date()); + // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: managedContact={0} - EXIT!", managedContact)); //NOI18N @@ -894,7 +796,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseEnterpriseBean { throw new NullPointerException("detachedContact is null"); //NOI18N } else if (detachedContact.getContactId() == null) { // Throw NPE again - throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N + throw new NullPointerException("detachedContact.contactId is null"); //NOI18N } else if (detachedContact.getContactId() < 1) { // Not valid throw new IllegalStateException(MessageFormat.format("detachedContact.contactId={0} is not valid.", detachedContact.getContactId())); //NOI18N @@ -917,7 +819,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseEnterpriseBean { assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getMobileId()); //NOI18N // Copy all - MobileNumbers.copyMobileNumberData(detachedContact.getContactMobileNumber(), foundMobile); + MobileNumberUtils.copyMobileNumberData(detachedContact.getContactMobileNumber(), foundMobile); // Then merge it, too final DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile); @@ -941,7 +843,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseEnterpriseBean { assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N // Copy all - FaxNumbers.copyFaxNumberData(detachedContact.getContactFaxNumber(), foundFax); + FaxNumberUtils.copyFaxNumberData(detachedContact.getContactFaxNumber(), foundFax); // Then merge it, too final DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax); @@ -965,7 +867,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseEnterpriseBean { assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N // Copy all - LandLineNumbers.copyLandLineNumberData(detachedContact.getContactLandLineNumber(), foundLandLine); + LandLineNumberUtils.copyLandLineNumberData(detachedContact.getContactLandLineNumber(), foundLandLine); // Then merge it, too final DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine); @@ -981,6 +883,197 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseEnterpriseBean { this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N } + /** + * Merges given department's data + *

+ * @param detachedDepartment Department instance to merge + *

+ * @return Detached contact instance + */ + protected Department mergeDepartmentData (final Department detachedDepartment) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeDepartmentData: detachedDepartment={0} - CALLED!", detachedDepartment)); //NOI18N + + // The contact instance must be valid + if (null == detachedDepartment) { + // Throw NPE again + throw new NullPointerException("detachedDepartment is null"); //NOI18N + } else if (detachedDepartment.getDepartmentId() == null) { + // Throw NPE again + throw new NullPointerException("detachedDepartment.departmentId is null"); //NOI18N + } else if (detachedDepartment.getDepartmentId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("detachedDepartment.departmentId ={0} is not valid.", detachedDepartment.getDepartmentId())); //NOI18N + } + + // Get contact from it and find it + final Department foundDepartment = this.createManaged(detachedDepartment); + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeDepartmentData: foundContact.contactId={0}", foundDepartment.getDepartmentId())); //NOI18N + + // Copy all + DepartmentUtils.copyDepartmentData(detachedDepartment, foundDepartment); + + // Merge contact instance + final Department managedDepartment = this.getEntityManager().merge(foundDepartment); + + // Set updated timestamp + managedDepartment.setDepartmentEntryUpdated(new Date()); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeDepartmentData: managedDepartment={0} - EXIT!", managedDepartment)); //NOI18N + + // Return detached contact + return managedDepartment; + } + + /** + * Returns a detached instance from given fax instance merged into current. + *

+ * @param faxNumber Fax instance + * @param fetchedNumber Found fax number in database + *

+ * @return Detached instance + */ + protected DialableFaxNumber mergeFaxNumberData (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 (!FaxNumberUtils.isSameFaxNumber(faxNumber, fetchedNumber)) { + // @TODO Copy all to foundNumber, then merge + + // Merge this entry + detachedNumber = this.getEntityManager().merge(foundNumber); + } + + // 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 merged with + * current. + *

+ * @param landLineNumber Land-line instance + * @param fetchedNumber Found land-line number in database + *

+ * @return Detached instance + */ + protected DialableLandLineNumber mergeLandLineNumberData (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 (!LandLineNumberUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) { + // @TODO Copy all to foundNumber, then merge + + // Merge this entry + detachedNumber = this.getEntityManager().merge(foundNumber); + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N + + // Return it + return detachedNumber; + } + + /** + * Returns a detached instance from given mobile instance merged with + * current. + *

+ * @param mobileNumber Mobile instance + * @param fetchedNumber Found mobile number in database + *

+ * @return Detached instance + */ + protected DialableMobileNumber mergeMobileNumberData (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.getMobileId() == null) { + // ..and again + throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N + } + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getMobileId())); //NOI18N + + // Init query instance + final DialableMobileNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getMobileId()); + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N + + // Default is null + DialableMobileNumber detachedNumber = null; + + // Is there a difference? + if (!MobileNumberUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) { + // @TODO Copy all to foundNumber, then merge + + // Merge this entry + detachedNumber = this.getEntityManager().merge(foundNumber); + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N + + // Return it + return detachedNumber; + } + /** * Sends an email with given subject line, template name to given recipient * and user data @@ -1054,7 +1147,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseEnterpriseBean { } // Set all values - final Properties variables = Users.getAllUserFields(user); + final Properties variables = UserUtils.getAllUserFields(user); // Set base URL and random password variables.put("baseUrl", baseUrl); //NOI18N @@ -1123,14 +1216,14 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseEnterpriseBean { this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N // Is other mobile not set? - if ((other.getContactMobileNumber() == null) || (MobileNumbers.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) { + if ((other.getContactMobileNumber() == null) || (MobileNumberUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) { // Debug message this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying mobile entry ..."); //NOI18N // Is the fax number set? if (other.getContactMobileNumber() instanceof DialableMobileNumber) { // Copy mobile number - contact.setContactMobileNumber(this.getDetached(other.getContactMobileNumber(), contact.getContactMobileNumber())); + contact.setContactMobileNumber(this.mergeMobileNumberData(other.getContactMobileNumber(), contact.getContactMobileNumber())); } else { // Null it contact.setContactMobileNumber(null); @@ -1141,14 +1234,14 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseEnterpriseBean { this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N // Is other mobile not set? - if ((other.getContactLandLineNumber() == null) || (LandLineNumbers.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) { + if ((other.getContactLandLineNumber() == null) || (LandLineNumberUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) { // Debug message this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying land-line entry ..."); //NOI18N // Is the land-line number set? if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) { // Copy land-line number - contact.setContactLandLineNumber(this.getDetached(other.getContactLandLineNumber(), contact.getContactLandLineNumber())); + contact.setContactLandLineNumber(this.mergeLandLineNumberData(other.getContactLandLineNumber(), contact.getContactLandLineNumber())); } else { // Null it contact.setContactLandLineNumber(null); @@ -1159,14 +1252,14 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseEnterpriseBean { this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactFaxNumber={0}", other.getContactFaxNumber())); //NOI18N // Is other mobile not set? - if ((other.getContactFaxNumber() == null) || (FaxNumbers.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) { + if ((other.getContactFaxNumber() == null) || (FaxNumberUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) { // Debug message this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying fax entry ..."); //NOI18N // Is the fax number set? if (other.getContactFaxNumber() instanceof DialableFaxNumber) { // Copy fax number - contact.setContactFaxNumber(this.getDetached(other.getContactFaxNumber(), contact.getContactFaxNumber())); + contact.setContactFaxNumber(this.mergeFaxNumberData(other.getContactFaxNumber(), contact.getContactFaxNumber())); } else { // Null it contact.setContactFaxNumber(null); @@ -1198,7 +1291,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseEnterpriseBean { throw new NullPointerException("contact is null"); //NOI18N } else if (contact.getContactId() == null) { // Throw NPE again - throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N + throw new NullPointerException("contact.contactId is null"); //NOI18N } else if (contact.getContactId() < 1) { // Not valid throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N diff --git a/src/java/org/mxchange/jaddressbook/model/addressbook/AddressbookSessionBean.java b/src/java/org/mxchange/jaddressbook/model/addressbook/AddressbookSessionBean.java index b9cb0ec..cea5564 100644 --- a/src/java/org/mxchange/jaddressbook/model/addressbook/AddressbookSessionBean.java +++ b/src/java/org/mxchange/jaddressbook/model/addressbook/AddressbookSessionBean.java @@ -25,7 +25,6 @@ import javax.persistence.Query; import org.mxchange.addressbook.enterprise.BaseAddressbookEnterpriseBean; import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote; import org.mxchange.jaddressbook.exceptions.AddressbookNameAlreadyUsedException; -import org.mxchange.jaddressbook.exceptions.AddressbookNotFoundException; import org.mxchange.jaddressbook.model.addressbook.entry.AddressbookEntry; import org.mxchange.jusercore.model.user.User; @@ -42,44 +41,6 @@ public class AddressbookSessionBean extends BaseAddressbookEnterpriseBean implem */ private static final long serialVersionUID = 129_857_871_287_691L; - @Override - @SuppressWarnings ("unchecked") - public List allEntries (final Addressbook addressbook) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("allEntries: addressbook={0} - CALLED!", addressbook)); //NOI18N - - // Validate parameter - if (null == addressbook) { - // Throw NPE - throw new NullPointerException("addressbook is null"); - } else if (addressbook.getAddressbookId() == null) { - // Throw NPE again - throw new NullPointerException("addressbook.addressbookId is null"); - } else if (addressbook.getAddressbookId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookId={0} is invalid.", addressbook.getAddressbookId())); - } else if (addressbook.getAddressbookUser() == null) { - // Throw again NPE - throw new NullPointerException("addressbook.addressbookUser is null"); - } else if (addressbook.getAddressbookUser().getUserId() == null) { - // Throw again NPE - throw new NullPointerException("addressbook.addressbookUser.userId is null"); - } else if (addressbook.getAddressbookUser().getUserId() < 1) { - // Invalid id number again - throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookUser.userId={0} is invalid", addressbook.getAddressbookUser().getUserId())); - } - - // Generate query - Query query = this.getEntityManager().createNamedQuery("SearchUsersAddressbookEntries", List.class); //NOI18N - - // Set parameters - query.setParameter("addressbook", addressbook); //NOI18N - query.setParameter("owner", addressbook.getAddressbookUser()); //NOI18N - - // Return it - return query.getResultList(); - } - @Override public Addressbook createAddressbook (final Addressbook addressbook) throws AddressbookNameAlreadyUsedException { // Is it not null? @@ -113,36 +74,9 @@ public class AddressbookSessionBean extends BaseAddressbookEnterpriseBean implem return addressbook; } - @Override - public Addressbook getAddressbookById (final Long addressbookId) throws AddressbookNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAddressbookById: addressbookId={0} - CALLED!", addressbookId)); //NOI18N - - // addressbookId should not be null or below 1 - if (null == addressbookId) { - // Throw NPE - throw new NullPointerException("addressbookId is null"); //NOI18N - } else if (addressbookId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("addressbookId is not valid: {0}", addressbookId)); //NOI18N - } else if (!this.isAddressbookIdUsed(addressbookId)) { - // No address book found - throw new AddressbookNotFoundException(addressbookId); - } - - // Get named query instance - Query query = this.getEntityManager().createNamedQuery("SearchAddressbookById", UserAddressbook.class); //NOI18N - - // Set parameter - query.setParameter("id", addressbookId); //NOI18N - - // Return it - return (Addressbook) query.getSingleResult(); - } - @Override @SuppressWarnings ("unchecked") - public List getUsersAddressbookList (final User loggedInUser) { + public List fetchAddressbooksByUser (final User loggedInUser) { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("getUsersList: loggedInUser={0} - CALLED!", loggedInUser)); //NOI18N @@ -153,18 +87,56 @@ public class AddressbookSessionBean extends BaseAddressbookEnterpriseBean implem } // Get query instance - Query query = this.getEntityManager().createNamedQuery("AllUsersAddressbooks", List.class); //NOI18N + final Query query = this.getEntityManager().createNamedQuery("AllUsersAddressbooks", List.class); //NOI18N // Set parameter query.setParameter("param", loggedInUser); //NOI18N // Get full list from JPA - List addressbooks = query.getResultList(); + final List addressbooks = query.getResultList(); // Return it return addressbooks; } + @Override + @SuppressWarnings ("unchecked") + public List fetchAllAddressbookEntries (final Addressbook addressbook) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("allEntries: addressbook={0} - CALLED!", addressbook)); //NOI18N + + // Validate parameter + if (null == addressbook) { + // Throw NPE + throw new NullPointerException("addressbook is null"); + } else if (addressbook.getAddressbookId() == null) { + // Throw NPE again + throw new NullPointerException("addressbook.addressbookId is null"); + } else if (addressbook.getAddressbookId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookId={0} is invalid.", addressbook.getAddressbookId())); + } else if (addressbook.getAddressbookUser() == null) { + // Throw again NPE + throw new NullPointerException("addressbook.addressbookUser is null"); + } else if (addressbook.getAddressbookUser().getUserId() == null) { + // Throw again NPE + throw new NullPointerException("addressbook.addressbookUser.userId is null"); + } else if (addressbook.getAddressbookUser().getUserId() < 1) { + // Invalid id number again + throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookUser.userId={0} is invalid", addressbook.getAddressbookUser().getUserId())); + } + + // Generate query + Query query = this.getEntityManager().createNamedQuery("SearchUsersAddressbookEntries", List.class); //NOI18N + + // Set parameters + query.setParameter("addressbook", addressbook); //NOI18N + query.setParameter("owner", addressbook.getAddressbookUser()); //NOI18N + + // Return it + return query.getResultList(); + } + @Override public boolean isAddressbookIdUsed (final Long addressbookId) { // Trace message @@ -180,7 +152,7 @@ public class AddressbookSessionBean extends BaseAddressbookEnterpriseBean implem } // Get query instance - Query query = this.getEntityManager().createNamedQuery("SearchAddressbookById", UserAddressbook.class); //NOI18N + final Query query = this.getEntityManager().createNamedQuery("SearchAddressbookById", UserAddressbook.class); //NOI18N // Set parameter query.setParameter("id", addressbookId); //NOI18N @@ -191,7 +163,7 @@ public class AddressbookSessionBean extends BaseAddressbookEnterpriseBean implem // Try it again, yes no other way try { // Get single result - Addressbook addressbook = (Addressbook) query.getSingleResult(); + final Addressbook addressbook = (Addressbook) query.getSingleResult(); // Debug message this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookIdUsed: addressbook={0} - FOUND!", addressbook)); //NOI18N @@ -212,6 +184,9 @@ public class AddressbookSessionBean extends BaseAddressbookEnterpriseBean implem @Override public boolean isAddressbookNameUsed (final Addressbook addressbook) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("isAddressbookNameUsed: addressbook={0} - CALLED!", addressbook)); + // Is it not null? if (null == addressbook) { // Abort here @@ -234,7 +209,7 @@ public class AddressbookSessionBean extends BaseAddressbookEnterpriseBean implem } // Get query instance - Query query = this.getEntityManager().createNamedQuery("SearchUserAddressbookName", Addressbook.class); //NOI18N + final Query query = this.getEntityManager().createNamedQuery("SearchUserAddressbookName", Addressbook.class); //NOI18N // Set parameter query.setParameter("user", addressbook.getAddressbookUser()); //NOI18N @@ -246,7 +221,7 @@ public class AddressbookSessionBean extends BaseAddressbookEnterpriseBean implem // Try it try { // Get a single result - Addressbook dummy = (Addressbook) query.getSingleResult(); + final Addressbook dummy = (Addressbook) query.getSingleResult(); // Log it this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookNameUsed: Found an address book: {0}", dummy)); //NOI18N diff --git a/src/java/org/mxchange/jcontacts/model/phone/AddressbookAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/model/phone/AddressbookAdminContactPhoneSessionBean.java index 1fee313..d8722a6 100644 --- a/src/java/org/mxchange/jcontacts/model/phone/AddressbookAdminContactPhoneSessionBean.java +++ b/src/java/org/mxchange/jcontacts/model/phone/AddressbookAdminContactPhoneSessionBean.java @@ -22,6 +22,7 @@ import java.util.Objects; import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.addressbook.enterprise.BaseAddressbookEnterpriseBean; +import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote; import org.mxchange.jphone.exceptions.phone.PhoneNumberAlreadyLinkedException; @@ -58,7 +59,7 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookEnte } @Override - public Contact linkExistingFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException { + public Contact linkExistingFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException, ContactNotFoundException { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingFaxNumberWithContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N @@ -115,7 +116,7 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookEnte } @Override - public Contact linkExistingLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException { + public Contact linkExistingLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException, ContactNotFoundException { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingLandLineNumberWithContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java index 05a7fd1..e158137 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java @@ -23,9 +23,12 @@ import java.util.Objects; import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.addressbook.enterprise.BaseAddressbookEnterpriseBean; +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.jcontactsbusiness.model.utils.BranchOfficeUtils; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jusercore.model.user.User; @@ -45,7 +48,7 @@ public class AddressbookAdminBranchOfficeSessionBean extends BaseAddressbookEnte /** * General branch office bean */ - @EJB (lookup = "java:global/addressbook-ejb/branchOffice!org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote") + @EJB (lookup = "java:global/jfinancials-ejb/branchOffice!org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote") private BranchOfficeSessionBeanRemote branchOfficeBean; /** @@ -76,6 +79,24 @@ public class AddressbookAdminBranchOfficeSessionBean extends BaseAddressbookEnte // Add created timestamp branchOffice.setBranchEntryCreated(new Date()); + // Is contact employee set? + if (branchOffice.getBranchContactEmployee() instanceof Contact) { + // Get managed lead contact + final Contact managedContact = this.createManaged(branchOffice.getBranchContactEmployee()); + + // Set it back + branchOffice.setBranchContactEmployee(managedContact); + } + + // Is owner employee set? + if (branchOffice.getBranchOwnerEmployee() instanceof Contact) { + // Get managed lead contact + final Contact managedContact = this.createManaged(branchOffice.getBranchOwnerEmployee()); + + // Set it back + branchOffice.setBranchOwnerEmployee(managedContact); + } + // Is user instance set? if (branchOffice.getBranchCompany() instanceof BasicData) { // Get managed instance back @@ -110,7 +131,7 @@ public class AddressbookAdminBranchOfficeSessionBean extends BaseAddressbookEnte 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())) { @@ -131,6 +152,36 @@ public class AddressbookAdminBranchOfficeSessionBean extends BaseAddressbookEnte 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 @@ -141,6 +192,9 @@ public class AddressbookAdminBranchOfficeSessionBean extends BaseAddressbookEnte * @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(); @@ -150,13 +204,16 @@ public class AddressbookAdminBranchOfficeSessionBean extends BaseAddressbookEnte // Check all single addresses for (final BranchOffice bo : branchOffices) { // Is the same address found? - if (Objects.equals(bo.getBranchId(), branchOffice.getBranchId()) || BranchOffices.isSameAddress(bo, branchOffice)) { + if (Objects.equals(bo.getBranchId(), branchOffice.getBranchId()) || BranchOfficeUtils.isSameAddress(bo, branchOffice)) { // Found one isFound = true; break; } } + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isBranchOfficeFound(): isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N + // Return flag return isFound; }