// 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
// 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
// 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
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("updateUserPersonalData: foundContact.contactId={0}", foundContact.getContactId())); //NOI18N
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeContactData: foundContact.contactId={0}", foundContact.getContactId())); //NOI18N
+
+ // 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("mergeContactData: detachedContact={0} - EXIT!", managedContact)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: managedContact={0} - EXIT!", managedContact)); //NOI18N
// Return detached contact
return managedContact;
// 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);
}
// 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);
}
// 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);
}
}
@Override
- public User updateUserData (final User user) {
+ public User updateUserData (final User detachedUser) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: detachedUser={1} - CALLED!", this.getClass().getSimpleName(), detachedUser)); //NOI18N
// user should not be null
- if (null == user) {
+ if (null == detachedUser) {
// Abort here
- throw new NullPointerException("user is null"); //NOI18N
- } else if (user.getUserId() == null) {
+ throw new NullPointerException("detachedUser is null"); //NOI18N
+ } else if (detachedUser.getUserId() == null) {
// Throw NPE again
- throw new NullPointerException("user.userId is null"); //NOI18N
- } else if (user.getUserId() < 1) {
+ throw new NullPointerException("detachedUser.userId is null"); //NOI18N
+ } else if (detachedUser.getUserId() < 1) {
// Not valid
- throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
- } else if (user.getUserAccountStatus() == null) {
+ throw new IllegalArgumentException(MessageFormat.format("detachedUser.userId={0} is not valid.", detachedUser.getUserId())); //NOI18N
+ } else if (detachedUser.getUserAccountStatus() == null) {
// Throw NPE again
- throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
- } else if (!this.ifUserExists(user)) {
+ throw new NullPointerException("detachedUser.userAccountStatus is null"); //NOI18N
+ } else if (!this.ifUserExists(detachedUser)) {
// User does not exist
- throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
+ throw new EJBException(MessageFormat.format("User with id {0} does not exist.", detachedUser.getUserId())); //NOI18N
}
// Remove contact instance as this is not updated
- user.setUserContact(null);
+ detachedUser.setUserContact(null);
// Find the instance
- final User foundUser = this.getEntityManager().find(user.getClass(), user.getUserId());
+ final User foundUser = this.getEntityManager().find(detachedUser.getClass(), detachedUser.getUserId());
// Should be found!
- assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
+ assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", detachedUser.getUserId()); //NOI18N
+
+ // Copy all data
+ Users.copyAll(detachedUser, foundUser);
// Merge user
final User managedUser = this.getEntityManager().merge(foundUser);
// Should be found!
assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not merged, but should be.", managedUser.getUserId()); //NOI18N
- // Copy all data
- Users.copyAll(managedUser, managedUser);
-
// Set as updated
managedUser.setUserUpdated(new Date());
// 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.", managedUser.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
managedUser.setUserContact(managedContact);
// 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(managedMobile);
}
// 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);
}
// 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);
}