From 1f01e4e321ffcb2deee95014c8a354ae4b762b88 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 24 Nov 2019 05:37:31 +0100 Subject: [PATCH] Please cherry-pick/repeat: - renamed/moved file MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../BaseAddressbookEnterpriseBean.java | 483 ++++++------------ 1 file changed, 164 insertions(+), 319 deletions(-) diff --git a/src/java/org/mxchange/addressbook/enterprise/BaseAddressbookEnterpriseBean.java b/src/java/org/mxchange/addressbook/enterprise/BaseAddressbookEnterpriseBean.java index 95a1c17..73f8fe7 100644 --- a/src/java/org/mxchange/addressbook/enterprise/BaseAddressbookEnterpriseBean.java +++ b/src/java/org/mxchange/addressbook/enterprise/BaseAddressbookEnterpriseBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 - 2020 Free Software Foundation + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mxchange.addressbook.database; +package org.mxchange.addressbook.enterprise; import java.text.MessageFormat; import java.util.Date; @@ -30,17 +30,15 @@ import javax.mail.internet.InternetAddress; 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.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.department.Department; 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.headquarter.Headquarter; +import org.mxchange.jcontactsbusiness.model.jobposition.HireableJobPosition; +import org.mxchange.jcontactsbusiness.model.jobposition.JobPosition; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; -import org.mxchange.jcoreee.database.BaseDatabaseBean; +import org.mxchange.jcoreee.bean.ejb.BaseEnterpriseBean; import org.mxchange.jcountry.model.data.Country; -import org.mxchange.jcountry.model.data.CountryData; import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper; import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; @@ -49,8 +47,8 @@ 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.utils.PhoneUtils; -import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.Users; @@ -59,7 +57,7 @@ import org.mxchange.jusercore.model.user.Users; *

* @author Roland Häder */ -public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { +public abstract class BaseAddressbookEnterpriseBean extends BaseEnterpriseBean { /** * Serial number @@ -70,7 +68,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { * Protected constructor */ protected BaseAddressbookEnterpriseBean () { - // Call super constructor + // Call super contructor super(); } @@ -85,213 +83,6 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { super(factoryJndi, queueJndi); } - /** - * Updates all contact's phone entry's created timestamps - *

- * @param contact Contact instance to update - */ - protected void setAllContactPhoneEntriesCreated (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N - - // The contact instance must be valid - if (null == contact) { - // Throw NPE again - throw new NullPointerException("contact is null"); //NOI18N - } - - // 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("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N - - // Is a phone number instance set? - if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //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(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //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(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for mobile number ...", this.getClass().getSimpleName())); //NOI18N - - // Set updated timestamp - mobileNumber.setPhoneEntryCreated(new Date()); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N - } - - /** - * Returns a managed instance from given mobile number - *

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

- * @return Managed instance - */ - protected DialableMobileNumber getManaged (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N - - // Should be valid - if (null == mobileNumber) { - // Throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (null == fetchedNumber) { - // Throw NPE again - throw new NullPointerException("fetchedNumber 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 managedNumber = null; - - // Is there a difference? - if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) { - // Merge this entry - managedNumber = this.getEntityManager().merge(foundNumber); - - // @TODO Copy all - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N - - // Return it - return managedNumber; - } - - /** - * Returns a managed instance from given land-line number - *

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

- * @return Managed instance - */ - protected DialableLandLineNumber getManaged (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: landLineNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), landLineNumber, fetchedNumber)); //NOI18N - - // Should be valid - if (null == landLineNumber) { - // Throw NPE - throw new NullPointerException("landLineNumber is null"); //NOI18N - } else if (null == fetchedNumber) { - // Throw NPE again - throw new NullPointerException("fetchedNumber 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 managedNumber = null; - - // Is there a difference? - if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) { - // Merge this entry - managedNumber = this.getEntityManager().merge(foundNumber); - - // @TODO Copy all - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N - - // Return it - return managedNumber; - } - - /** - * Returns a managed instance from given fax number - *

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

- * @return Managed instance - */ - protected DialableFaxNumber getManaged (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: faxNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), faxNumber, fetchedNumber)); //NOI18N - - // Should be valid - if (null == faxNumber) { - // Throw NPE - throw new NullPointerException("faxNumber is null"); //NOI18N - } else if (null == fetchedNumber) { - // Throw NPE again - throw new NullPointerException("fetchedNumber 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 managedNumber = null; - - // Is there a difference? - if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) { - // Merge this entry - managedNumber = this.getEntityManager().merge(foundNumber); - - // @TODO Copy all - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N - - // Return it - return managedNumber; - } - /** * Get back a managed instance from given contact *

@@ -309,14 +100,14 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { throw new NullPointerException("contact is null"); //NOI18N } else if (contact.getContactId() == null) { // Id is set - throw new NullPointerException("contact.contactId is null"); //NOI18N + throw new NullPointerException("contact.branchId is null"); //NOI18N } else if (contact.getContactId() < 1) { // Id is set - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("contact.branchId={0} is invalid", contact.getContactId())); //NOI18N } // Try to find it (should be there) - final Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId()); + final Contact managedContact = this.getEntityManager().find(contact.getClass(), contact.getContactId()); // Should be there assert (managedContact instanceof Contact) : "managedContact is null"; //NOI18N @@ -352,7 +143,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { } // Try to find it (should be there) - final Country managedCountry = this.getEntityManager().find(CountryData.class, country.getCountryId()); + final Country managedCountry = this.getEntityManager().find(country.getClass(), country.getCountryId()); // Should be there assert (managedCountry instanceof Country) : "managedCountry is null"; //NOI18N @@ -388,7 +179,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { } // Try to find it (should be there) - final BasicData managedBasicData = this.getEntityManager().find(BusinessBasicData.class, basicData.getBasicDataId()); + final BasicData managedBasicData = this.getEntityManager().find(basicData.getClass(), basicData.getBasicDataId()); // Should be there assert (managedBasicData instanceof BasicData) : "managedBasicData is null"; //NOI18N @@ -403,31 +194,31 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { /** * Get back a managed instance from given branch office *

- * @param headquarter Unmanaged/detached branch office instance + * @param branchOffice Unmanaged/detached branch office instance *

- * @return Managed basic data instance + * @return Managed branch office instance */ - protected BranchOffice createManaged (final BranchOffice headquarter) { + protected BranchOffice createManaged (final BranchOffice branchOffice) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N // user should not be null - if (null == headquarter) { + if (null == branchOffice) { // Abort here - throw new NullPointerException("headquarter is null"); //NOI18N - } else if (headquarter.getBranchId() == null) { + throw new NullPointerException("branchOffice is null"); //NOI18N + } else if (branchOffice.getBranchId() == null) { // Id is set - throw new NullPointerException("headquarter.headquarterId is null"); //NOI18N - } else if (headquarter.getBranchId() < 1) { + throw new NullPointerException("branchOffice.branchId is null"); //NOI18N + } else if (branchOffice.getBranchId() < 1) { // Id is set - throw new IllegalArgumentException(MessageFormat.format("headquarter.headquarterId={0} is invalid", headquarter.getBranchId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is invalid", branchOffice.getBranchId())); //NOI18N } // Try to find it (should be there) - final BranchOffice managedBranchOffice = this.getEntityManager().find(BusinessBranchOffice.class, headquarter.getBranchId()); + final BranchOffice managedBranchOffice = this.getEntityManager().find(branchOffice.getClass(), branchOffice.getBranchId()); // Should be there - assert (managedBranchOffice instanceof BasicData) : "managedBranchOffice is null"; //NOI18N + assert (managedBranchOffice instanceof BranchOffice) : "managedBranchOffice is null"; //NOI18N // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBranchOffice={1} - EXIT!", this.getClass().getSimpleName(), managedBranchOffice)); //NOI18N @@ -436,6 +227,42 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { return managedBranchOffice; } + /** + * Get back a managed instance from given department + *

+ * @param department Unmanaged/detached department instance + *

+ * @return Managed department instance + */ + protected Department createManaged (final Department department) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: department={1} - CALLED!", this.getClass().getSimpleName(), department)); //NOI18N + + // user should not be null + if (null == department) { + // Abort here + throw new NullPointerException("department is null"); //NOI18N + } else if (department.getDepartmentId() == null) { + // Id is set + throw new NullPointerException("department.departmentId is null"); //NOI18N + } else if (department.getDepartmentId() < 1) { + // Id is set + throw new IllegalArgumentException(MessageFormat.format("department.departmentId={0} is invalid", department.getDepartmentId())); //NOI18N + } + + // Try to find it (should be there) + final Department managedDepartment = this.getEntityManager().find(department.getClass(), department.getDepartmentId()); + + // Should be there + assert (managedDepartment instanceof Department) : "managedDepartment is null"; //NOI18N + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedDepartment={1} - EXIT!", this.getClass().getSimpleName(), managedDepartment)); //NOI18N + + // Return it + return managedDepartment; + } + /** * Get back a managed instance from given employee *

@@ -460,7 +287,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { } // Try to find it (should be there) - final Employable managedEmployee = this.getEntityManager().find(BusinessEmployee.class, employee.getEmployeeId()); + final Employable managedEmployee = this.getEntityManager().find(employee.getClass(), employee.getEmployeeId()); // Should be there assert (managedEmployee instanceof Employable) : "managedEmployee is null"; //NOI18N @@ -473,18 +300,54 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { } /** - * Get back a managed instance from given headquarters + * Get back a managed instance from given jobPosition + *

+ * @param jobPosition Unmanaged/detached job position instance + *

+ * @return Managed job position instance + */ + protected HireableJobPosition createManaged (final HireableJobPosition jobPosition) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: jobPosition={1} - CALLED!", this.getClass().getSimpleName(), jobPosition)); //NOI18N + + // user should not be null + if (null == jobPosition) { + // Abort here + throw new NullPointerException("jobPosition is null"); //NOI18N + } else if (jobPosition.getJobPositionId() == null) { + // Id is set + throw new NullPointerException("jobPosition.jobPositionId is null"); //NOI18N + } else if (jobPosition.getJobPositionId() < 1) { + // Id is set + throw new IllegalArgumentException(MessageFormat.format("jobPosition.jobPositionId={0} is invalid", jobPosition.getJobPositionId())); //NOI18N + } + + // Try to find it (should be there) + final HireableJobPosition managedJobPosition = this.getEntityManager().find(jobPosition.getClass(), jobPosition.getJobPositionId()); + + // Should be there + assert (managedJobPosition instanceof HireableJobPosition) : "managedJobPosition is null"; //NOI18N + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedJobPosition={1} - EXIT!", this.getClass().getSimpleName(), managedJobPosition)); //NOI18N + + // Return it + return managedJobPosition; + } + + /** + * Get back a managed instance from given headquarter *

- * @param headquarters Unmanaged/detached headquarters instance + * @param headquarter Unmanaged/detached headquarter instance *

* @return Managed basic data instance */ - protected Headquarter createManaged (final Headquarter headquarters) { + protected Headquarter createManaged (final Headquarter headquarter) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarters)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N // user should not be null - if (null == headquarters) { + if (null == headquarter) { // Abort here throw new NullPointerException("headquarter is null"); //NOI18N } else if (headquarter.getHeadquarterId() == null) { @@ -561,23 +424,23 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { throw new NullPointerException("mobileProvider is null"); //NOI18N } else if (mobileProvider.getProviderId() == null) { // Id is set - throw new NullPointerException("headquarter.headquartersId is null"); //NOI18N - } else if (headquarters.getHeadquartersId() < 1) { + throw new NullPointerException("mobileProvider.providerId is null"); //NOI18N + } else if (mobileProvider.getProviderId() < 1) { // Id is set - throw new IllegalArgumentException(MessageFormat.format("headquarter.headquartersId={0} is invalid", headquarters.getHeadquartersId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("mobileProvider.providerId={0} is invalid", mobileProvider.getProviderId())); //NOI18N } // Try to find it (should be there) - final Headquarter managedHeadquarters = this.getEntityManager().find(BusinessHeadquarters.class, headquarters.getHeadquartersId()); + final MobileProvider managedMobileProvider = this.getEntityManager().find(mobileProvider.getClass(), mobileProvider.getProviderId()); // Should be there - assert (managedHeadquarters instanceof BasicData) : "managedHeadquarters is null"; //NOI18N + assert (managedMobileProvider instanceof MobileProvider) : "managedMobileProvider is null"; //NOI18N // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedHeadquarters={1} - EXIT!", this.getClass().getSimpleName(), managedHeadquarters)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedMobileProvider={1} - EXIT!", this.getClass().getSimpleName(), managedMobileProvider)); //NOI18N // Return it - return managedHeadquarters; + return managedMobileProvider; } /** @@ -613,7 +476,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { } // Try to find it (should be there) - final User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId()); + final User managedUser = this.getEntityManager().find(user.getClass(), user.getUserId()); // Should be there assert (managedUser instanceof User) : "managedUser is null"; //NOI18N @@ -638,10 +501,10 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { // Validate parameter if (null == openingTimes) { // Throw NPE - throw new NullPointerException("openingTimes is null"); + throw new NullPointerException("openingTimes is null"); //NOI18N } else if (openingTimes.isEmpty()) { // Throw IAE - throw new IllegalArgumentException("openingTimes is empty"); + throw new IllegalArgumentException("openingTimes is empty"); //NOI18N } // Walk through whole list @@ -649,7 +512,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { // Id should not be set if (openingTime.getOpeningId() != null) { // Abort here - throw new IllegalStateException("openingTime.openingId is not null"); + throw new IllegalStateException("openingTime.openingId is not null"); //NOI18N } // Set created timestamp @@ -672,7 +535,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { 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())); + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is unexpected.", contact.getContactId())); //NOI18N } // Get all phone instances @@ -729,7 +592,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { 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())); + throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is unexpected.", branchOffice.getBranchId())); //NOI18N } // Get all phone instances @@ -764,7 +627,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { /** * Updates all branch office's phone entry's created timestamps *

- * @param headquarter Headquarters instance to update + * @param headquarter Headquarter instance to update */ protected void setAllPhoneEntriesCreated (final Headquarter headquarter) { // Trace message @@ -774,14 +637,14 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { if (null == headquarter) { // Throw NPE again throw new NullPointerException("headquarter is null"); //NOI18N - } else if (headquarter.getHeadquartersId() != null) { + } else if (headquarter.getHeadquarterId() != null) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("headquarter.branchId={0} is unexpected.", headquarter.getHeadquartersId())); + throw new IllegalArgumentException(MessageFormat.format("headquarter.branchId={0} is unexpected.", headquarter.getHeadquarterId())); //NOI18N } // Get all phone instances - final DialableLandLineNumber landLineNumber = headquarter.getHeadquartersLandLineNumber(); - final DialableFaxNumber faxNumber = headquarter.getHeadquartersFaxNumber(); + final DialableLandLineNumber landLineNumber = headquarter.getHeadquarterLandLineNumber(); + final DialableFaxNumber faxNumber = headquarter.getHeadquarterFaxNumber(); // Debug message this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N @@ -823,7 +686,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { 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())); + throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is unexpected.", basicData.getBasicDataId())); //NOI18N } // Get all phone instances @@ -896,10 +759,10 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { // Is there a difference? if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) { + // @TODO Copy all to foundNumber, then merge + // Merge this entry detachedNumber = this.getEntityManager().merge(foundNumber); - - // @TODO Copy all } // Trace message @@ -944,10 +807,10 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { // Is there a difference? if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) { + // @TODO Copy all to foundNumber, then merge + // Merge this entry detachedNumber = this.getEntityManager().merge(foundNumber); - - // @TODO Copy all } // Trace message @@ -992,10 +855,10 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { // Is there a difference? if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) { + // @TODO Copy all to foundNumber, then merge + // Merge this entry detachedNumber = this.getEntityManager().merge(foundNumber); - - // @TODO Copy all } // Trace message @@ -1014,7 +877,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { */ protected Contact mergeContactData (final Contact detachedContact) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: detachedContact={0} - CALLED!", detachedContact)); //NOI18N // The contact instance must be valid if (null == detachedContact) { @@ -1025,7 +888,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N } else if (detachedContact.getContactId() < 1) { // Not valid - throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N + throw new IllegalStateException(MessageFormat.format("detachedContact.contactId={0} is not valid.", detachedContact.getContactId())); //NOI18N } // Set updated timestamp @@ -1038,34 +901,16 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: foundContact.contactId={1}", this.getClass().getSimpleName(), foundContact.getContactId())); //NOI18N - - // Is a fax number set? - if (detachedContact.getContactFaxNumber() instanceof DialableFaxNumber) { - // Make fax numbers managed - foundContact.setContactFaxNumber(this.getManaged(detachedContact.getContactFaxNumber(), detachedContact.getContactFaxNumber())); - } - - // Is a land-line number set? - if (detachedContact.getContactLandLineNumber() instanceof DialableLandLineNumber) { - // Make land-line numbers managed - foundContact.setContactLandLineNumber(this.getManaged(detachedContact.getContactLandLineNumber(), detachedContact.getContactLandLineNumber())); - } + this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeContactData: foundContact.contactId={0}", foundContact.getContactId())); //NOI18N - // Is a mobile number set? - if (detachedContact.getContactMobileNumber() instanceof DialableMobileNumber) { - // Make mobile numbers managed - foundContact.setContactMobileNumber(this.getManaged(detachedContact.getContactMobileNumber(), detachedContact.getContactMobileNumber())); - } + // Copy all + Contacts.copyAll(detachedContact, foundContact); // Merge contact instance final Contact managedContact = this.getEntityManager().merge(foundContact); - // Copy all - Contacts.copyAll(detachedContact, managedContact); - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: managedContact={0} - EXIT!", managedContact)); //NOI18N // Return detached contact return managedContact; @@ -1078,7 +923,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { */ protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactsMobileLandLineFaxNumbers: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactsMobileLandLineFaxNumbers: detachedContact={0} - CALLED!", detachedContact)); //NOI18N // The contact instance must be valid if (null == detachedContact) { @@ -1089,7 +934,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N } else if (detachedContact.getContactId() < 1) { // Not valid - throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N + throw new IllegalStateException(MessageFormat.format("detachedContact.contactId={0} is not valid.", detachedContact.getContactId())); //NOI18N } // Get all instances @@ -1108,15 +953,15 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { // Should be there assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N + // Copy all + MobileNumbers.copyAll(detachedContact.getContactMobileNumber(), foundMobile); + // Then merge it, too final DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile); // Should be there assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N - // Copy all - MobileNumbers.copyAll(detachedContact.getContactMobileNumber(), managedMobile); - // Set it back detachedContact.setContactMobileNumber(managedMobile); } @@ -1132,15 +977,15 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { // Should be there assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N + // Copy all + FaxNumbers.copyAll(detachedContact.getContactFaxNumber(), foundFax); + // Then merge it, too final DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax); // Should be there assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N - // Copy all - FaxNumbers.copyAll(detachedContact.getContactFaxNumber(), managedFax); - // Set it back detachedContact.setContactFaxNumber(managedFax); } @@ -1156,15 +1001,15 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { // Should be there assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N + // Copy all + LandLineNumbers.copyAll(detachedContact.getContactLandLineNumber(), foundLandLine); + // Then merge it, too final DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine); // Should be there assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N - // Copy all - LandLineNumbers.copyAll(detachedContact.getContactLandLineNumber(), managedLandLine); - // Set it back detachedContact.setContactLandLineNumber(managedLandLine); } @@ -1291,7 +1136,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { */ protected void setAllContactPhoneEntries (final Contact contact, final Contact other) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: contact={1},other={2} - CALLED!", this.getClass().getSimpleName(), contact, other)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntries: contact={0},other={1} - CALLED!", contact, other)); //NOI18N // Both must be the same and not null if (null == contact) { @@ -1302,21 +1147,21 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { throw new NullPointerException("other is null"); //NOI18N } else if (!Objects.equals(contact, other)) { // Not same instances - throw new IllegalArgumentException(MessageFormat.format("{0}.setAllContactPhoneEntries: contact={1} and other={2} are not equal!", this.getClass().getSimpleName(), contact, other)); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N } // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N + this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N // Is other mobile not set? if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) { // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying mobile entry ...", this.getClass().getSimpleName())); //NOI18N + this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying mobile entry ..."); //NOI18N // Is the fax number set? if (other.getContactMobileNumber() instanceof DialableMobileNumber) { // Copy mobile number - contact.setContactMobileNumber(this.getManaged(other.getContactMobileNumber(), contact.getContactMobileNumber())); + contact.setContactMobileNumber(this.getDetached(other.getContactMobileNumber(), contact.getContactMobileNumber())); } else { // Null it contact.setContactMobileNumber(null); @@ -1324,17 +1169,17 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { } // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N + this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N // Is other mobile not set? if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) { // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying land-line entry ...", this.getClass().getSimpleName())); //NOI18N + 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.getManaged(other.getContactLandLineNumber(), contact.getContactLandLineNumber())); + contact.setContactLandLineNumber(this.getDetached(other.getContactLandLineNumber(), contact.getContactLandLineNumber())); } else { // Null it contact.setContactLandLineNumber(null); @@ -1342,17 +1187,17 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { } // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactFaxNumber={1}", this.getClass().getSimpleName(), other.getContactFaxNumber())); //NOI18N + this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactFaxNumber={0}", other.getContactFaxNumber())); //NOI18N // Is other mobile not set? if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) { // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying fax entry ...", this.getClass().getSimpleName())); //NOI18N + this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying fax entry ..."); //NOI18N // Is the fax number set? if (other.getContactFaxNumber() instanceof DialableFaxNumber) { // Copy fax number - contact.setContactFaxNumber(this.getManaged(other.getContactFaxNumber(), contact.getContactFaxNumber())); + contact.setContactFaxNumber(this.getDetached(other.getContactFaxNumber(), contact.getContactFaxNumber())); } else { // Null it contact.setContactFaxNumber(null); @@ -1360,7 +1205,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { } // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N + this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntries: EXIT!"); //NOI18N } /** @@ -1376,7 +1221,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { */ protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntriesUpdated: contact={0},isMobileUnlinked={1},isLandlineUnlinked={2},isFaxUnlinked={3} - CALLED", contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N // The contact instance must be valid if (null == contact) { @@ -1410,7 +1255,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { // Is a phone number instance set? if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) { // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N + this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ..."); //NOI18N // Set updated timestamp landLineNumber.setPhoneEntryUpdated(new Date()); @@ -1419,7 +1264,7 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { // Is a fax number instance set? if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) { // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N + this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ..."); //NOI18N // Set updated timestamp faxNumber.setPhoneEntryUpdated(new Date()); @@ -1428,14 +1273,14 @@ public abstract class BaseAddressbookEnterpriseBean extends BaseDatabaseBean { // Is a mobile number instance set? if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() instanceof Long) && (mobileNumber.getPhoneId() > 0)) { // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for mobile number ...", this.getClass().getSimpleName())); //NOI18N + this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for mobile number ..."); //NOI18N // Set updated timestamp mobileNumber.setPhoneEntryUpdated(new Date()); } // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: EXIT!", this.getClass().getSimpleName())); //NOI18N + this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntriesUpdated: EXIT!"); //NOI18N } } -- 2.39.5