]> git.mxchange.org Git - addressbook-mailer-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Wed, 3 Aug 2016 14:34:22 +0000 (16:34 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 6 Aug 2016 20:50:50 +0000 (22:50 +0200)
- implemented business method updateUserPassword()

src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java

index 059d530b2676f8db7d828542728318409ab58c3b..eb3b28dd5780e0ddadb1e71e8b04d2f1bf027e67 100644 (file)
@@ -38,7 +38,10 @@ import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
 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.status.UserAccountStatus;
 
@@ -647,7 +650,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                        throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
                }
 
-               // Remove contact instance as this is not updatedf
+               // Remove contact instance as this is not updated
                user.setUserContact(null);
 
                // Find the instance
@@ -672,6 +675,51 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                return detachedUser;
        }
 
+       @Override
+       public PasswordHistory updateUserPassword (final User user) throws UserNotFoundException, UserStatusUnconfirmedException, UserStatusLockedException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateUserPassword: user={0} - CALLED!", user)); //NOI18N
+
+               // user should not be null
+               if (null == user) {
+                       // Abort here
+                       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
+               } else if (user.getUserAccountStatus() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("user.userAccountStatus 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
+               }
+
+               // Call other method
+               User updatedUser = this.updateUserData(user);
+
+               // Create history entry
+               PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), updatedUser);
+
+               // Set created timestamp
+               entry.setUserPasswordHistoryCreated(new GregorianCalendar());
+
+               // Persist it
+               this.getEntityManager().persist(entry);
+
+               // Flush it to get id number back
+               this.getEntityManager().flush();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateUserPassword: entry.userPasswordHistoryId={0} - EXIT!", entry.getUserPasswordHistoryId())); //NOI18N
+
+               // Return it
+               return entry;
+       }
+
        @Override
        public User updateUserPersonalData (final User user) {
                // Trace message