+ }
+
+ /**
+ * Deletes given user account
+ * <p>
+ * @return Redirect outcome
+ */
+ public String deleteUserData () {
+ // Is the user instance valid and CONFIRMED?
+ if (this.getUser() == null) {
+ // Throw NPE
+ throw new NullPointerException("user is null"); //NOI18N
+ } else if (this.getUser().getUserId() == null) {
+ // Throw again
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (this.getUser().getUserId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", this.getUser().getUserId())); //NOI18N
+ }
+
+ try {
+ // All fine, delete it
+ this.adminUserBean.deleteUser(this.getUser(), this.getUserDeleteReason());
+ } catch (final UserNotFoundException ex) {
+ // Should not happen, so throw again
+ throw new FaceletException(ex);
+ }
+
+ // Fire event
+ this.deleteUserEvent.fire(new AdminDeletedUserEvent(this.getUser(), this.getUserDeleteReason()));
+
+ // Redirect
+ return "admin_list_user"; //NOI18N
+ }
+
+ /**
+ * Edits currently loaded user's data in database.
+ * <p>
+ * @return Redirect outcome
+ */
+ public String editUserData () {
+ // Null password means not setting it
+ String encryptedPassword = null;
+
+ // Check if user instance is in helper and valid
+ if (this.getUser() == null) {
+ // Throw NPE
+ throw new NullPointerException("beanHelper.user is null"); //NOI18N
+ } else if (this.getUser().getUserId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("beanHelper.user.userId is null"); //NOI18N
+ } else if (this.getUser().getUserId() < 1) {
+ // Invalid id
+ throw new IllegalStateException(MessageFormat.format("beanHelper.user.userId={0} is invalid", this.getUser().getUserId())); //NOI18N
+ } else if (this.getUserName() == null) {
+ // Not all required fields are set
+ throw new NullPointerException("this.userName is null"); //NOI18N
+ } else if (this.getUserName().isEmpty()) {
+ // Not all required fields are set
+ throw new IllegalArgumentException("this.userName is empty"); //NOI18N
+ } else if (((!this.getUserPassword().isEmpty()) || (!this.getUserPasswordRepeat().isEmpty())) && (!this.isSamePasswordEntered())) {
+ // Clear password fields
+ this.setUserPassword(null);
+ this.setUserPasswordRepeat(null);
+
+ // Not same password entered
+ this.showFacesMessage("form_edit_user:userPassword", "ADMIN_USER_PASSWORD_REPEAT_DIFFERENT"); //NOI18N
+ return ""; //NOI18N
+ } else if ((!Objects.equals(this.getUser().getUserName(), this.getUserName())) && (this.userBean.ifUserNameExists(this.getUserName()))) {
+ // Clear all fields
+ this.clear();
+
+ // User name already exists
+ this.showFacesMessage("form_edit_user:userName", "ADMIN_USER_NAME_ALREADY_EXISTS"); //NOI18N
+ return ""; //NOI18N
+ } else if (this.isSamePasswordEntered()) {
+ // Same password entered, create container
+ if ((Objects.equals(this.getUser().getUserMustChangePassword(), this.getUserMustChangePassword())) && (UserLoginUtils.ifPasswordMatches(new UserLoginContainer(this.getUser(), this.getUserPassword())))) {
+ // Clear password fields
+ this.setUserPassword(null);
+ this.setUserPasswordRepeat(null);
+
+ // Same password entered
+ this.showFacesMessage("form_edit_user:userPassword", "ADMIN_USER_ENTERED_SAME_AS_OLD_PASSWORD"); //NOI18N
+ return ""; //NOI18N
+ }
+
+ // Encrypt password
+ encryptedPassword = UserLoginUtils.encryptPassword(this.getUserPassword());
+ }
+
+ // Set user name and flag
+ this.getUser().setUserName(this.getUserName());
+ this.getUser().setUserMustChangePassword(this.getUserMustChangePassword());
+
+ // Is a password set?
+ if (encryptedPassword != null) {
+ // Set it as well
+ this.getUser().setUserEncryptedPassword(encryptedPassword);
+ }
+
+ // Call EJB for updating user data
+ final User updatedUser = this.userBean.updateUserData(this.getUser());
+
+ // Fire event
+ this.updatedUserDataEvent.fire(new AdminUpdatedUserDataEvent(updatedUser));
+
+ // Return to user list (for now)
+ return "admin_list_user"; //NOI18N
+ }