]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java
Please cherry-pick:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / user / JobsAdminUserWebRequestBean.java
index b25488b59a727b5ecd95743be8e96515c9896254..5c4486e512229f54297913b699bbe6aa3bf56cce 100644 (file)
@@ -27,7 +27,6 @@ import javax.enterprise.inject.Any;
 import javax.faces.FacesException;
 import javax.faces.application.FacesMessage;
 import javax.faces.context.FacesContext;
-import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
 import javax.inject.Named;
 import org.mxchange.jcontacts.model.contact.Contact;
@@ -36,6 +35,7 @@ import org.mxchange.jjobs.beans.BaseJobsBean;
 import org.mxchange.jjobs.beans.contact.JobsAdminContactWebRequestController;
 import org.mxchange.jjobs.beans.contact.JobsContactWebRequestController;
 import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController;
+import org.mxchange.jjobs.beans.user.list.JobsUserListWebViewController;
 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
 import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
@@ -47,8 +47,8 @@ import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
 import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent;
 import org.mxchange.jusercore.events.user.unlocked.AdminUnlockedUserEvent;
 import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent;
-import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent;
-import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
+import org.mxchange.jusercore.events.user.update.post.AdminPostUserDataUpdatedEvent;
+import org.mxchange.jusercore.events.user.update.post.ObservableAdminPostUserDataUpdatedEvent;
 import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
 import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
 import org.mxchange.jusercore.exceptions.UserNotFoundException;
@@ -128,7 +128,7 @@ public class JobsAdminUserWebRequestBean extends BaseJobsBean implements JobsAdm
         */
        @Inject
        @Any
-       private Event<ObservableAdminUpdatedUserDataEvent> updatedUserDataEvent;
+       private Event<ObservableAdminPostUserDataUpdatedEvent> updatedUserDataEvent;
 
        /**
         * User instance
@@ -160,6 +160,12 @@ public class JobsAdminUserWebRequestBean extends BaseJobsBean implements JobsAdm
        @Any
        private Event<ObservableAdminLinkedUserEvent> userLinkedEvent;
 
+       /**
+        * Regular user controller
+        */
+       @Inject
+       private JobsUserListWebViewController userListController;
+
        /**
         * User lock reason
         */
@@ -236,9 +242,9 @@ public class JobsAdminUserWebRequestBean extends BaseJobsBean implements JobsAdm
 
                // Is the user name or email address used already?
                // @TODO Add password length check
-               if ((this.featureController.isFeatureEnabled("user_login_require_user_name")) && (this.userController.isUserNameRegistered(newUser))) {
+               if ((this.featureController.isFeatureEnabled("user_login_require_user_name")) && (this.userListController.isUserNameRegistered(newUser))) {
                        // User name is already used
-                       throw new FaceletException(new UserNameAlreadyRegisteredException(newUser));
+                       throw new FacesException(new UserNameAlreadyRegisteredException(newUser));
                } else if ((this.getContact() == null) && (this.contactController.isEmailAddressRegistered(newUser.getUserContact()))) {
                        // Email address is already used
                        this.showFacesMessage("admin_add_user:emailAddress", "ERROR_EMAIL_ADDRESS_ALREADY_USED", FacesMessage.SEVERITY_WARN); //NOI18N
@@ -251,26 +257,31 @@ public class JobsAdminUserWebRequestBean extends BaseJobsBean implements JobsAdm
                        return;
                }
 
+               // Init variable
+               final User updatedUser;
+
                try {
                        // Now, that all is set, call EJB
                        if (this.getContact() instanceof Contact) {
                                // Link contact with this user
-                               final User updatedUser = this.adminUserBean.linkUser(newUser);
-
-                               // Fire event
-                               this.userLinkedEvent.fire(new AdminLinkedUserEvent(updatedUser));
+                               updatedUser = this.adminUserBean.linkUser(newUser);
                        } else {
                                // Add new user
-                               final User updatedUser = this.adminUserBean.addUser(newUser);
-
-                               // Fire event
-                               this.addedUserEvent.fire(new AdminAddedUserEvent(updatedUser));
+                               updatedUser = this.adminUserBean.addUser(newUser);
                        }
                } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) {
                        // Throw again
-                       throw new FaceletException(ex);
+                       throw new FacesException(ex);
                }
 
+               // Now, that all is set, call EJB
+               if (this.getContact() instanceof Contact) {
+                       // Fire event
+                       this.userLinkedEvent.fire(new AdminLinkedUserEvent(updatedUser));
+               } else {
+                       // Fire event
+                       this.addedUserEvent.fire(new AdminAddedUserEvent(updatedUser));
+               }
                // Clear helper
                this.setContact(null);
 
@@ -311,7 +322,7 @@ public class JobsAdminUserWebRequestBean extends BaseJobsBean implements JobsAdm
         * @param event User registration event
         */
        public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
-               // event should not be null
+               // Event and contained entity instance should not be null
                if (null == event) {
                        // Throw NPE
                        throw new NullPointerException("event is null"); //NOI18N
@@ -355,7 +366,7 @@ public class JobsAdminUserWebRequestBean extends BaseJobsBean implements JobsAdm
                        this.adminUserBean.deleteUser(this.getUser(), this.getUserDeleteReason());
                } catch (final UserNotFoundException ex) {
                        // Should not happen, so throw again
-                       throw new FaceletException(ex);
+                       throw new FacesException(ex);
                }
 
                // Fire event
@@ -430,7 +441,7 @@ public class JobsAdminUserWebRequestBean extends BaseJobsBean implements JobsAdm
                final User updatedUser = this.userBean.updateUserData(this.getUser());
 
                // Fire event
-               this.updatedUserDataEvent.fire(new AdminUpdatedUserDataEvent(updatedUser));
+               this.updatedUserDataEvent.fire(new AdminPostUserDataUpdatedEvent(updatedUser));
        }
 
        /**
@@ -617,7 +628,7 @@ public class JobsAdminUserWebRequestBean extends BaseJobsBean implements JobsAdm
                        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()));
+                       throw new FacesException(new UserStatusUnconfirmedException(this.getUser()));
                } else if (this.getUserLockReason() == null) {
                        // Throw NPE again
                        throw new NullPointerException("this.userLockReason is null"); //NOI18N
@@ -637,7 +648,7 @@ public class JobsAdminUserWebRequestBean extends BaseJobsBean implements JobsAdm
                        updatedUser = this.adminUserBean.lockUserAccount(this.getUser(), this.getUserLockReason(), baseUrl);
                } catch (final UserStatusLockedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
                        // Throw again
-                       throw new FaceletException(ex);
+                       throw new FacesException(ex);
                }
 
                // Fire event
@@ -672,7 +683,7 @@ public class JobsAdminUserWebRequestBean extends BaseJobsBean implements JobsAdm
                        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()));
+                       throw new FacesException(new UserStatusUnconfirmedException(this.getUser()));
                }
 
                // Init updated user instance
@@ -686,7 +697,7 @@ public class JobsAdminUserWebRequestBean extends BaseJobsBean implements JobsAdm
                        updatedUser = this.adminUserBean.unlockUserAccount(this.getUser(), baseUrl);
                } catch (final UserStatusConfirmedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
                        // Throw again
-                       throw new FaceletException(ex);
+                       throw new FacesException(ex);
                }
 
                // Fire event
@@ -734,7 +745,7 @@ public class JobsAdminUserWebRequestBean extends BaseJobsBean implements JobsAdm
                        password = UserLoginUtils.createRandomPassword(JobsUserWebRequestController.MINIMUM_PASSWORD_LENGTH);
                } else if (!this.isSamePasswordEntered()) {
                        // Both passwords don't match
-                       throw new FaceletException(new UserPasswordRepeatMismatchException());
+                       throw new FacesException(new UserPasswordRepeatMismatchException());
                } else {
                        // Both match, so get it from this bean
                        password = this.getUserPassword();
@@ -754,7 +765,14 @@ public class JobsAdminUserWebRequestBean extends BaseJobsBean implements JobsAdm
                }
 
                // Create new instance
-               final User newUser = new LoginUser(this.getUserName(), this.getUserProfileMode(), this.getUserMustChangePassword(), UserLoginUtils.encryptPassword(password), UserAccountStatus.CONFIRMED, userContact);
+               final User newUser = new LoginUser(
+                                  this.getUserName(),
+                                  this.getUserProfileMode(),
+                                  this.getUserMustChangePassword(),
+                                  UserLoginUtils.encryptPassword(password),
+                                  UserAccountStatus.CONFIRMED,
+                                  userContact
+                  );
 
                // Get locale from view-root
                final Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();