]> git.mxchange.org Git - addressbook-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sun, 18 Mar 2018 21:25:50 +0000 (22:25 +0100)
committerRoland Häder <roland@mxchange.org>
Sat, 1 Feb 2020 03:31:35 +0000 (04:31 +0100)
- ContactUtils was renamed to Contacts to follow naming-convention
- fixed copy-paste mistake for headquarters instance, was BasicData
- also employeePosition was renamed to employeeJobPosition

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java
src/java/org/mxchange/jcontacts/model/contact/AddressbookContactSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookAdminEmployeeSessionBean.java
src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java

index fe45cf34de54ddd4e64a782d1919ff48b8de4898..4774ad3c4c2abac605b2849d1895d29f70f04389 100644 (file)
@@ -28,8 +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.ContactUtils;
-import org.mxchange.jcontacts.model.contact.UserContact;
+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;
@@ -488,7 +487,79 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                if (null == headquarters) {
                        // Abort here
                        throw new NullPointerException("headquarter is null"); //NOI18N
-               } else if (headquarters.getHeadquartersId() == null) {
+               } else if (headquarter.getHeadquarterId() == null) {
+                       // Id is set
+                       throw new NullPointerException("headquarter.headquarterId is null"); //NOI18N
+               } else if (headquarter.getHeadquarterId() < 1) {
+                       // Id is set
+                       throw new IllegalArgumentException(MessageFormat.format("headquarter.headquarterId={0} is invalid", headquarter.getHeadquarterId())); //NOI18N
+               }
+
+               // Try to find it (should be there)
+               final Headquarter managedHeadquarter = this.getEntityManager().find(headquarter.getClass(), headquarter.getHeadquarterId());
+
+               // Should be there
+               assert (managedHeadquarter instanceof Headquarter) : "managedHeadquarter is null"; //NOI18N
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedHeadquarter={1} - EXIT!", this.getClass().getSimpleName(), managedHeadquarter)); //NOI18N
+
+               // Return it
+               return managedHeadquarter;
+       }
+
+       /**
+        * Get back a managed instance from given job position
+        * <p>
+        * @param jobPosition Unmanaged/detached job position instance
+        * <p>
+        * @return Managed job position instance
+        */
+       protected JobPosition createManaged (final JobPosition 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 JobPosition managedJobPosition = this.getEntityManager().find(jobPosition.getClass(), jobPosition.getJobPositionId());
+
+               // Should be there
+               assert (managedJobPosition instanceof JobPosition) : "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 mobile provider
+        * <p>
+        * @param mobileProvider Unmanaged/detached mobile provider instance
+        * <p>
+        * @return Managed mobile provider instance
+        */
+       protected MobileProvider createManaged (final MobileProvider mobileProvider) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: mobileProvider={1} - CALLED!", this.getClass().getSimpleName(), mobileProvider)); //NOI18N
+
+               // user should not be null
+               if (null == mobileProvider) {
+                       // Abort here
+                       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) {
@@ -991,7 +1062,7 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                final Contact managedContact = this.getEntityManager().merge(foundContact);
 
                // Copy all
-               ContactUtils.copyAll(detachedContact, managedContact);
+               Contacts.copyAll(detachedContact, managedContact);
 
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
index cdf4b3cad25c32c9f8c397a19c735c31a66b932d..583b1fce676717fcd57566456aed8cc4eeb86067 100644 (file)
@@ -107,7 +107,7 @@ public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean i
                        final Contact next = iterator.next();
 
                        // Is same contact?
-                       if ((Objects.equals(contact, next)) || (ContactUtils.isSameContact(contact, next))) {
+                       if ((Objects.equals(contact, next)) || (Contacts.isSameContact(contact, next))) {
                                // Debug message
                                this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isContactFound: Found same contact: contactId={1}", this.getClass().getSimpleName(), next.getContactId())); //NOI18N
 
index 00361667a8545388a5924d40340488747c4fe2a1..15ab7362c66452b2401a48bf3a952cf786e533db 100644 (file)
@@ -69,15 +69,15 @@ public class AddressbookAdminEmployeeSessionBean extends BaseAddressbookDatabase
                } else if (employee.getEmployeeId() != null) {
                        // Throw IAE
                        throw new IllegalArgumentException(MessageFormat.format("employee.employeeId={0} is unexpected.", employee.getEmployeeId())); //NOI18N
-               } else if (employee.getEmployeeCompany() == null) {
+               } else if (employee.getEmployeeBasicData() == null) {
                        // Throw NPE
                        throw new NullPointerException("employee.employeeCompany is null"); //NOI18N
-               } else if (employee.getEmployeeCompany().getBasicDataId() == null) {
+               } else if (employee.getEmployeeBasicData().getBasicDataId() == null) {
                        // Throw it again
                        throw new NullPointerException("employee.employeeCompany.basicDataId is null"); //NOI18N
-               } else if (employee.getEmployeeCompany().getBasicDataId() < 1) {
+               } else if (employee.getEmployeeBasicData().getBasicDataId() < 1) {
                        // Throw IAE
-                       throw new IllegalArgumentException(MessageFormat.format("employee.employeeCompany.basicDataId={0} is invalid.", employee.getEmployeeCompany().getBasicDataId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("employee.employeeCompany.basicDataId={0} is invalid.", employee.getEmployeeBasicData().getBasicDataId())); //NOI18N
                } else if (employee.getEmployeeBranchOffice() == null && employee.getEmployeeDepartment() == null && employee.getEmployeeHeadquarter() == null) {
                        // At least one must be set
                        throw new NullPointerException("employee.employeeBranchOffice, employee.employeeDepartment and employee.employeeHeadquarter is null"); //NOI18N
@@ -120,12 +120,12 @@ public class AddressbookAdminEmployeeSessionBean extends BaseAddressbookDatabase
                } else if ((employee.getEmployeePersonalData() != null) && (employee.getEmployeePersonalData().getContactId() < 1)) {
                        // Throw IAE
                        throw new IllegalArgumentException(MessageFormat.format("employee.employeePersonalData.contactId={0} is unexpected.", employee.getEmployeePersonalData().getContactId())); //NOI18N
-               } else if ((employee.getEmployeePosition() != null) && (employee.getEmployeePosition().getJobPositionId() == null)) {
+               } else if ((employee.getEmployeeJobPosition() != null) && (employee.getEmployeeJobPosition().getJobPositionId() == null)) {
                        // Throw NPE
                        throw new NullPointerException("employee.employeePosition.jobPositionId is null"); //NOI18N
-               } else if ((employee.getEmployeePosition() != null) && (employee.getEmployeePosition().getJobPositionId() < 1)) {
+               } else if ((employee.getEmployeeJobPosition() != null) && (employee.getEmployeeJobPosition().getJobPositionId() < 1)) {
                        // Throw IAE
-                       throw new IllegalArgumentException(MessageFormat.format("employee.employeePosition.jobPositionId={0} is unexpected.", employee.getEmployeePosition().getJobPositionId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("employee.employeePosition.jobPositionId={0} is unexpected.", employee.getEmployeeJobPosition().getJobPositionId())); //NOI18N
                } else if ((employee.getEmployeeUserOwner() != null) && (employee.getEmployeeUserOwner().getUserId() == null)) {
                        // Throw NPE
                        throw new NullPointerException("employee.employeeUserOwner.userId is null"); //NOI18N
@@ -138,7 +138,7 @@ public class AddressbookAdminEmployeeSessionBean extends BaseAddressbookDatabase
                }
 
                // Make company (basic data) managed
-               employee.setEmployeeCompany(this.createManaged(employee.getEmployeeCompany()));
+               employee.setEmployeeBasicData(this.createManaged(employee.getEmployeeBasicData()));
 
                // Is branch office set?
                if (employee.getEmployeeBranchOffice() instanceof BranchOffice) {
@@ -177,12 +177,12 @@ public class AddressbookAdminEmployeeSessionBean extends BaseAddressbookDatabase
                }
 
                // Is headquarter set?
-               if (employee.getEmployeePosition() instanceof JobPosition) {
+               if (employee.getEmployeeJobPosition() instanceof JobPosition) {
                        // Then make it managed
-                       final JobPosition jobPosition = this.createManaged(employee.getEmployeePosition());
+                       final JobPosition jobPosition = this.createManaged(employee.getEmployeeJobPosition());
 
                        // Set it back
-                       employee.setEmployeePosition(jobPosition);
+                       employee.setEmployeeJobPosition(jobPosition);
                }
 
                // Is headquarter set?
index c9d2558055e260cfa761901be2fe415a140fc378..a836ff53036a7bf2887f72778ed507b3c0cbb96a 100644 (file)
@@ -27,7 +27,7 @@ import javax.persistence.PersistenceException;
 import javax.persistence.Query;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
 import org.mxchange.jcontacts.model.contact.Contact;
-import org.mxchange.jcontacts.model.contact.ContactUtils;
+import org.mxchange.jcontacts.model.contact.Contacts;
 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumbers;
 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
@@ -585,7 +585,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                final Contact managedContact = this.getEntityManager().merge(foundContact);
 
                // Copy all
-               ContactUtils.copyAll(managedUser.getUserContact(), managedContact);
+               Contacts.copyAll(managedUser.getUserContact(), managedContact);
 
                // Set it back in user
                managedUser.setUserContact(managedContact);