import javax.persistence.PersistenceException;
import javax.persistence.Query;
import org.mxchange.jcontacts.model.contact.Contact;
-import org.mxchange.jcontacts.model.contact.Contacts;
import org.mxchange.jjobs.enterprise.BaseJobsEnterpriseBean;
import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
import org.mxchange.jphone.model.phonenumbers.fax.FaxNumbers;
// Set as updated
managedUser.setUserUpdated(new Date());
- managedUser.getUserContact().setContactUpdated(new Date());
- // Get contact from it and find it
- final Contact foundContact = this.getEntityManager().find(managedUser.getUserContact().getClass(), managedUser.getUserContact().getContactId());
-
- // Should be found
- assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", user.getUserContact().getContactId()); //NOI18N
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: contact.contactId={0}", foundContact.getContactId())); //NOI18N
-
- // Merge contact instance
- final Contact managedContact = this.getEntityManager().merge(foundContact);
-
- // Copy all
- Contacts.copyAll(managedUser.getUserContact(), managedContact);
+ // Update user data
+ final Contact managedContact = this.mergeContactData(managedUser.getUserContact());
// Set it back in user
- user.setUserContact(managedContact);
+ managedUser.setUserContact(managedContact);
// Should be found!
- assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not merged, but should be.", user.getUserContact().getContactId()); //NOI18N
+ assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not merged, but should be.", managedUser.getUserContact().getContactId()); //NOI18N
// Get mobile instance
final DialableMobileNumber mobileNumber = managedContact.getContactMobileNumber();
// 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(managedUser.getUserContact().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(managedUser.getUserContact().getContactMobileNumber(), managedMobile);
-
// Set it back
- managedContact.setContactMobileNumber(this.getManaged(mobileNumber, mobileNumber));
+ managedContact.setContactMobileNumber(managedMobile);
}
// Get mobile instance
// Is there a fax instance set?
if (faxNumber instanceof DialableFaxNumber) {
// Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: faxNumber.phoneId={0} is being updated ...", faxNumber.getPhoneId())); //NOI18N
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", faxNumber.getPhoneId())); //NOI18N
// Then find it, too
final DialableFaxNumber foundFax = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId());
// 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(managedUser.getUserContact().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(managedUser.getUserContact().getContactFaxNumber(), managedFax);
-
// Set it back
managedContact.setContactFaxNumber(managedFax);
}
// Is there a fax instance set?
if (landLineNumber instanceof DialableLandLineNumber) {
// Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLineNumber.phoneId={0} is being updated ...", landLineNumber.getPhoneId())); //NOI18N
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLineNumber.getPhoneId())); //NOI18N
// Then find it, too
final DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId());
// 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(managedUser.getUserContact().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(managedUser.getUserContact().getContactLandLineNumber(), managedLandLine);
-
// Set it back
managedContact.setContactLandLineNumber(managedLandLine);
}