+ /**
+ * 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
+ }
+
+ /**
+ * Getter for contact instance
+ * <p>
+ * @return Contact instance
+ */
+ public Contact getContact () {
+ return this.contact;
+ }
+
+ /**
+ * Setter for contact instance
+ * <p>
+ * @param contact Contact instance
+ */
+ public void setContact (final Contact contact) {
+ this.contact = contact;
+ }
+
+ /**
+ * Getter for user instance
+ * <p>
+ * @return User instance
+ */
+ public User getUser () {
+ return this.user;
+ }
+
+ /**
+ * Setter for user instance
+ * <p>
+ * @param user User instance
+ */
+ public void setUser (final User user) {
+ this.user = user;