import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices;
import org.mxchange.jcontactsbusiness.model.department.Department;
+import org.mxchange.jcontactsbusiness.model.department.Departments;
import org.mxchange.jcontactsbusiness.model.employee.Employable;
import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
import org.mxchange.jcontactsbusiness.model.jobposition.HireableJobPosition;
this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
}
- /**
- * Returns a detached instance from given mobile instance
- * <p>
- * @param mobileNumber Mobile instance
- * @param fetchedNumber Found mobile number in database
- * <p>
- * @return Detached instance
- */
- protected DialableMobileNumber getDetached (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: mobileNumber={0},fetchedNumber={1} - CALLED!", mobileNumber, fetchedNumber)); //NOI18N
-
- // Should be valid
- if (null == mobileNumber) {
- // Throw NPE
- throw new NullPointerException("mobileNumber is null"); //NOI18N
- } else if (fetchedNumber.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
- * <p>
- * @param landLineNumber Land-line instance
- * @param fetchedNumber Found land-line number in database
- * <p>
- * @return Detached instance
- */
- protected DialableLandLineNumber getDetached (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: landLineNumber={0},fetchedNumber={1} - CALLED!", landLineNumber, fetchedNumber)); //NOI18N
-
- // Should be valid
- if (null == landLineNumber) {
- // Throw NPE
- throw new NullPointerException("landLineNumber is null"); //NOI18N
- } else if (fetchedNumber.getPhoneId() == null) {
- // ..and again
- throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
- }
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
-
- // Init query instance
- final DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
-
- // Default is null
- DialableLandLineNumber detachedNumber = null;
-
- // Is there a difference?
- if (!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
- * <p>
- * @param faxNumber Fax instance
- * @param fetchedNumber Found fax number in database
- * <p>
- * @return Detached instance
- */
- protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber)); //NOI18N
-
- // Should be valid
- if (null == faxNumber) {
- // Throw NPE
- throw new NullPointerException("faxNumber is null"); //NOI18N
- } else if (fetchedNumber.getPhoneId() == null) {
- // ..and again
- throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
- }
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
-
- // Init query instance
- final DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
-
- // Default is null
- DialableFaxNumber detachedNumber = null;
-
- // Is there a difference?
- if (!FaxNumbers.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;
- }
-
/**
* Merges given branch office's data
* <p>
throw new NullPointerException("detachedBranchOffice is null"); //NOI18N
} else if (detachedBranchOffice.getBranchId() == null) {
// Throw NPE again
- throw new NullPointerException("detachedBranchOffice.branchId is null"); //NOI18N //NOI18N
+ 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
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
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
this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
}
+ /**
+ * Merges given department's data
+ * <p>
+ * @param detachedDepartment Department instance to merge
+ * <p>
+ * @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
+ }
+
+ // Set updated timestamp
+ detachedDepartment.setDepartmentEntryUpdated(new Date());
+
+ // Get contact from it and find it
+ final Department foundDepartment = this.getEntityManager().find(detachedDepartment.getClass(), detachedDepartment.getDepartmentId());
+
+ // Should be found
+ assert (foundDepartment instanceof Department) : MessageFormat.format("Department with id {0} not found, but should be.", detachedDepartment.getDepartmentId()); //NOI18N
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeDepartmentData: foundContact.contactId={0}", foundDepartment.getDepartmentId())); //NOI18N
+
+ // Copy all
+ Departments.copyDepartmentData(detachedDepartment, foundDepartment);
+
+ // Merge contact instance
+ final Department managedDepartment = this.getEntityManager().merge(foundDepartment);
+
+ // 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.
+ * <p>
+ * @param faxNumber Fax instance
+ * @param fetchedNumber Found fax number in database
+ * <p>
+ * @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 (!FaxNumbers.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.
+ * <p>
+ * @param landLineNumber Land-line instance
+ * @param fetchedNumber Found land-line number in database
+ * <p>
+ * @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 (!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 mobile instance merged with
+ * current.
+ * <p>
+ * @param mobileNumber Mobile instance
+ * @param fetchedNumber Found mobile number in database
+ * <p>
+ * @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 (!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;
+ }
+
/**
* Sends an email with given subject line, template name to given recipient
* and user data
// 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);
// 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);
// 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);
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