]> git.mxchange.org Git - jjobs-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 21:51:34 +0000 (23:51 +0200)
- implemented business method updateUserPassword()

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

index e358d9524adf127984709df4f39ecdb6cdfe123a..cd0737b25b2fdc93440f48f5df8cc382f239f4df 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;
 
@@ -656,7 +659,7 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                        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
@@ -681,6 +684,51 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                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