From: Roland Häder Date: Wed, 3 Aug 2016 14:34:22 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ba4c8d6bf2fdf2e9d237ccc510b83c4d2b2af90b;p=addressbook-ejb.git Please cherry-pick: - implemented business method updateUserPassword() --- diff --git a/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java index 059d530..eb3b28d 100644 --- a/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.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; @@ -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