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;
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
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