From e914dcb8b302bbd0cdfa0231e363e9700d83d066 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 3 Aug 2016 16:34:22 +0200 Subject: [PATCH] Please cherry-pick: - implemented business method updateUserPassword() --- .../model/user/JobsUserSessionBean.java | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java index e358d95..cd0737b 100644 --- a/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java @@ -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 -- 2.39.5