]> git.mxchange.org Git - addressbook-mailer-ejb.git/blobdiff - src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java
Don't cherry-pick:
[addressbook-mailer-ejb.git] / src / java / org / mxchange / jusercore / model / user / AddressbookUserSessionBean.java
index c3609277c97bacc8fe113ec276b60e2d03831979..c8db69dd18797bcb21307084c3196cc44ac5df61 100644 (file)
@@ -30,17 +30,21 @@ import javax.persistence.PersistenceException;
 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;
 
 /**
@@ -66,6 +70,8 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
         * Default constructor
         */
        public AddressbookUserSessionBean () {
+               // Call super constructor
+               super("jms/addressbook-queue-factory", "jms/addressbook-email-queue"); //NOI18N
        }
 
        @Override
@@ -158,6 +164,12 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                } 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
@@ -180,7 +192,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                }
 
                // 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
@@ -579,7 +591,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                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());
@@ -607,17 +619,29 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                        // 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
@@ -635,6 +659,20 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                // 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
 
@@ -672,7 +710,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                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());
@@ -688,7 +726,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                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);
@@ -702,7 +740,22 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                // 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));
@@ -716,8 +769,23 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                        // 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
@@ -728,8 +796,23 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                        // 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