]> git.mxchange.org Git - jfinancials-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sun, 9 Jul 2017 10:46:02 +0000 (12:46 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 9 Jul 2017 11:31:45 +0000 (13:31 +0200)
- renamed updatedUser -> managedUser, which is more accurate
- always set values in managed instances to have the JPA noticed it

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jusercore/model/user/FinancialsUserSessionBean.java
src/java/org/mxchange/jusercore/model/user/resendlink/FinancialsResendLinkSessionBean.java

index bcb495174a1b0f76b44b4f41326f45d4411f7977..0536ca6282e85d7ab09d28f8a361ddcea3d980d2 100644 (file)
@@ -163,22 +163,22 @@ public class FinancialsUserSessionBean extends BaseFinancialsDatabaseBean implem
                        throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
                }
 
-               // Update user status and remove confirmation key
-               user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
-               user.setUserConfirmKey(null);
-               user.setUserUpdated(new GregorianCalendar());
-
                // Update user account
-               User updatedUser = this.updateUserData(user);
+               User managedUser = this.updateUserData(user);
+
+               // Update user status and remove confirmation key
+               managedUser.setUserAccountStatus(UserAccountStatus.CONFIRMED);
+               managedUser.setUserConfirmKey(null);
+               managedUser.setUserUpdated(new GregorianCalendar());
 
                // Send out email
-               this.sendEmail("User account confirmed", "user_account_confirmed", updatedUser, baseUrl, null); //NOI18N
+               this.sendEmail("User account confirmed", "user_account_confirmed", managedUser, baseUrl, null); //NOI18N
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
 
                // Return updated instance
-               return updatedUser;
+               return managedUser;
        }
 
        @Override
@@ -596,14 +596,20 @@ public class FinancialsUserSessionBean extends BaseFinancialsDatabaseBean implem
 
                // user should not be null
                if (null == user) {
-                       // Abort here
+                       // Throw NPE
                        throw new NullPointerException("user is null"); //NOI18N
                } else if (user.getUserId() == null) {
                        // Throw NPE again
                        throw new NullPointerException("user.userId is null"); //NOI18N
                } else if (user.getUserId() < 1) {
-                       // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
+                       // Not valid number
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
+               } else if (user.getUserName() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("user.userName is null"); //NOI18N
+               } else if (user.getUserName().isEmpty()) {
+                       // Empty string
+                       throw new IllegalArgumentException("user.userName is empty"); //NOI18N
                } else if (user.getUserAccountStatus() == null) {
                        // Throw NPE
                        throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
@@ -623,28 +629,38 @@ public class FinancialsUserSessionBean extends BaseFinancialsDatabaseBean implem
                        // 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
-               User updatedUser = this.updateUserData(user);
+               User managedUser = this.updateUserData(user);
+
+               // Update user account
+               managedUser.setUserUpdated(new GregorianCalendar());
 
                // Create history entry
-               PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), updatedUser);
+               PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), managedUser);
 
                // Set created timestamp
                entry.setUserPasswordHistoryCreated(new GregorianCalendar());
 
+               // Merge user to make sure it is not re-persisted
+               User mergedUser = this.getEntityManager().merge(managedUser);
+               entry.setUserPasswordHistoryUser(mergedUser);
+
                // Persist it
                this.getEntityManager().persist(entry);
 
                // Flush it to get id number back
                this.getEntityManager().flush();
 
+               // Send email to user
+               this.sendEmail("User password change", "user_password_change", managedUser, baseUrl, null); //NOI18N
+
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: entry.userPasswordHistoryId={1} - EXIT!", this.getClass().getSimpleName(), entry.getUserPasswordHistoryId())); //NOI18N
 
index c4c7dcb6d5bbb22d746b520839bc33f3c4ac7240..470237a2166afc5fe4356f3c2fc6320e65c6962f 100644 (file)
@@ -97,6 +97,9 @@ public class FinancialsResendLinkSessionBean extends BaseFinancialsDatabaseBean
                // Get new registration key
                String confirmationKey = this.registerBean.generateConfirmationKey(user);
 
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.resendConfirmationLink: confirmationKey={1}", this.getClass().getSimpleName(), confirmationKey)); //NOI18N
+
                // Get managed instance
                User managedUser = this.getManagedUser(user);
 
@@ -105,7 +108,7 @@ public class FinancialsResendLinkSessionBean extends BaseFinancialsDatabaseBean
 
                // Send email
                // @TODO: Internationlize the subject line somehow
-               this.sendEmail("Resend user confirmation link", "user_resend_confirmation_link",  user, baseUrl, null); //NOI18N
+               this.sendEmail("Resend user confirmation link", "user_resend_confirmation_link",  managedUser, baseUrl, null); //NOI18N
 
                // Log trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.resendConfirmationLink: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N