+ public String lockUserAccount () {
+ // Is the user instance valid and CONFIRMED?
+ if (this.getUser() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.user is null"); //NOI18N
+ } else if (this.getUser().getUserId() == null) {
+ // Throw again
+ throw new NullPointerException("this.user.userId is null"); //NOI18N
+ } else if (this.getUser().getUserId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.user.userId={0} is not valid", this.getUser().getUserId())); //NOI18N
+ } else if (this.getUser().getUserAccountStatus() == UserAccountStatus.LOCKED) {
+ // User account is locked
+ throw new FacesException(new UserStatusLockedException(this.getUser()));
+ } else if (this.getUser().getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) {
+ // User account is locked
+ throw new FaceletException(new UserStatusUnconfirmedException(this.getUser()));
+ } else if (this.getUserLockReason() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.userLockReason is null"); //NOI18N
+ } else if (this.getUserLockReason().isEmpty()) {
+ // Empty lock reason
+ throw new IllegalArgumentException("this.userLockReason is empty"); //NOI18N
+ }
+
+ // Init updated user instance
+ final User updatedUser;
+
+ try {
+ // Get base URL
+ final String baseUrl = FacesUtils.generateBaseUrl();
+
+ // Call EJB to lock account
+ updatedUser = this.adminUserBean.lockUserAccount(this.getUser(), this.getUserLockReason(), baseUrl);
+ } catch (final UserStatusLockedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
+ // Throw again
+ throw new FaceletException(ex);
+ }
+
+ // Fire event
+ this.userLockedEvent.fire(new AdminLockedUserEvent(updatedUser));
+
+ // Clear bean
+ this.clear();
+
+ // Should go fine at this point, redirect to user profile
+ return "admin_show_user"; //NOI18N
+ }
+
+ /**
+ * Unlocks selected user's account. This method makes sure that the account
+ * is locked.
+ * <p>
+ * @return Redirect outcome
+ */
+ public String unlockUserAccount () {
+ // Is the user instance valid and CONFIRMED?
+ if (this.getUser() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.user is null"); //NOI18N
+ } else if (this.getUser().getUserId() == null) {
+ // Throw again
+ throw new NullPointerException("this.user.userId is null"); //NOI18N
+ } else if (this.getUser().getUserId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.user.userId={0} is not valid", this.getUser().getUserId())); //NOI18N
+ } else if (this.getUser().getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
+ // User account is locked
+ throw new FacesException(new UserStatusConfirmedException(this.getUser()));
+ } else if (this.getUser().getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) {
+ // User account is locked
+ throw new FaceletException(new UserStatusUnconfirmedException(this.getUser()));
+ }
+
+ // Init updated user instance
+ final User updatedUser;
+
+ try {
+ // Get base URL
+ final String baseUrl = FacesUtils.generateBaseUrl();
+
+ // Call EJB to unlock account
+ updatedUser = this.adminUserBean.unlockUserAccount(this.getUser(), baseUrl);
+ } catch (final UserStatusConfirmedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
+ // Throw again
+ throw new FaceletException(ex);
+ }
+
+ // Fire event
+ this.userUnlockedEvent.fire(new AdminUnlockedUserEvent(updatedUser));
+
+ // Clear bean
+ this.clear();
+
+ // Should go fine at this point, redirect to user profile
+ return "admin_show_user"; //NOI18N