import javax.persistence.Query;
import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.contact.ContactUtils;
import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.fax.FaxNumbers;
import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.landline.LandLineNumbers;
import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.phonenumbers.mobile.MobileNumbers;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
import org.mxchange.jusercore.exceptions.UserStatusLockedException;
import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
-import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
import org.mxchange.jusercore.model.user.password_history.UserPasswordHistory;
import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
+import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
/**
* Default constructor
*/
public AddressbookUserSessionBean () {
+ // Call super constructor
+ super("jms/addressbook-queue-factory", "jms/addressbook-email-queue"); //NOI18N
}
@Override
} else if (user.getUserConfirmKey() == null) {
// Throw NPE
throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
+ } else if (null == baseUrl) {
+ // Throw it again
+ throw new NullPointerException("baseUrl is null"); //NOI18N
+ } else if (baseUrl.isEmpty()) {
+ // Invalid parameter
+ throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
}
// Update user status and remove confirmation key
}
// Send out email
- this.sendEmail("Account confirmed", "account_confirmed", emailAddress, updatedUser, baseUrl); //NOI18N
+ this.sendEmail("User account confirmed", "user_account_confirmed", emailAddress, updatedUser, baseUrl, null); //NOI18N
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N
assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
// Copy all data
- managedUser.copyAll(user);
+ UserUtils.copyAll(user, managedUser);
// Set as updated
managedUser.setUserUpdated(new GregorianCalendar());
// Not valid
throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
} else if (user.getUserAccountStatus() == null) {
- // Throw NPE again
+ // Throw NPE
throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
+ } else if (user.getUserContact() == null) {
+ // Throw it again
+ throw new NullPointerException("user.userContact is null"); //NOI18N
+ } else if (user.getUserContact().getContactId() == null) {
+ // .. and again
+ throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
+ } else if (user.getUserContact().getContactId() < 1) {
+ // Invalid id
+ throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
+ } else if (user.getUserContact().getContactPersonalTitle() == null) {
+ // Throw NPE again
+ throw new NullPointerException("user.userContact.contactPersonalTitle is null"); //NOI18N
} else if (!this.ifUserExists(user)) {
// User does not exist
throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
} else if (null == baseUrl) {
- // Abort here
- throw new NullPointerException("password is null"); //NOI18N
+ // Throw it again
+ throw new NullPointerException("baseUrl is null"); //NOI18N
} else if (baseUrl.isEmpty()) {
- // Abort here
- throw new IllegalArgumentException("password is empty"); //NOI18N
+ // Invalid parameter
+ throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
}
// Call other method
// Flush it to get id number back
this.getEntityManager().flush();
+ // Init variable
+ Address emailAddress;
+
+ try {
+ // Create email address and set
+ emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress());
+ } catch (final AddressException ex) {
+ // Throw again
+ throw new EJBException(ex);
+ }
+
+ // Send email to user
+ this.sendEmail("User password change", "user_password_change", emailAddress, user, baseUrl, null); //NOI18N
+
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: entry.userPasswordHistoryId={1} - EXIT!", this.getClass().getSimpleName(), entry.getUserPasswordHistoryId())); //NOI18N
assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
// Copy all data
- managedUser.copyAll(user);
+ UserUtils.copyAll(user, managedUser);
// Set as updated
managedUser.setUserUpdated(new GregorianCalendar());
this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: managedContact.contactId={0}", managedContact.getContactId())); //NOI18N
// Copy all
- managedContact.copyAll(user.getUserContact());
+ ContactUtils.copyAll(user.getUserContact(), managedContact);
// Set it back in user
user.setUserContact(managedContact);
// Is there a mobile instance set?
if (mobileNumber instanceof DialableMobileNumber) {
// Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: mobileNumber.phoneId={0} is being updated ...", mobileNumber.getPhoneId())); //NOI18N
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: mobile.phoneId={0} is being updated ...", mobileNumber.getPhoneId())); //NOI18N
+
+ // Then find it, too
+ DialableMobileNumber foundMobile = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getPhoneId());
+
+ // Should be there
+ assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
+
+ // Then merge it, too
+ 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));
// Debug message
this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: faxNumber.phoneId={0} is being updated ...", faxNumber.getPhoneId())); //NOI18N
+ // Then find it, too
+ 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
+
+ // Then merge it, too
+ 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(this.getManaged(faxNumber, faxNumber));
+ managedContact.setContactFaxNumber(managedFax);
}
// Get mobile instance
// Debug message
this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLineNumber.phoneId={0} is being updated ...", landLineNumber.getPhoneId())); //NOI18N
+ // Then find it, too
+ 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
+
+ // Then merge it, too
+ 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(this.getManaged(landLineNumber, landLineNumber));
+ managedContact.setContactLandLineNumber(managedLandLine);
}
// Trace message