]> git.mxchange.org Git - addressbook-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Fri, 23 Sep 2022 16:52:47 +0000 (18:52 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 23 Sep 2022 16:57:42 +0000 (18:57 +0200)
- cannot copy whole user instance to RequestScoped bean as this is being
  forgotten on next request, SessionScoped will be a little overdose + it can
  be solved by taking the user instance already set in beanHelper bean

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelperBean.java
src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelperController.java
src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java
web/admin/user/admin_user_lock.xhtml

index d36a3629d68eda5736fca8cab5fce04f099fc0ae..d349c65a279b0dcbf432cc56670b7983a27b3150 100644 (file)
@@ -161,6 +161,7 @@ public class AddressbookWebRequestHelperBean implements AddressbookWebRequestHel
         * <p>
         * @return Contact instance
         */
+       @Override
        public Contact getContact () {
                return this.contact;
        }
@@ -215,6 +216,7 @@ public class AddressbookWebRequestHelperBean implements AddressbookWebRequestHel
         * <p>
         * @return Dialable fax number
         */
+       @Override
        public DialableFaxNumber getFaxNumber () {
                return this.faxNumber;
        }
@@ -233,6 +235,7 @@ public class AddressbookWebRequestHelperBean implements AddressbookWebRequestHel
         * <p>
         * @return Dialable land-line number
         */
+       @Override
        public DialableLandLineNumber getLandLineNumber () {
                return this.landLineNumber;
        }
@@ -251,6 +254,7 @@ public class AddressbookWebRequestHelperBean implements AddressbookWebRequestHel
         * <p>
         * @return Dialable mobile number
         */
+       @Override
        public DialableMobileNumber getMobileNumber () {
                return this.mobileNumber;
        }
@@ -269,6 +273,7 @@ public class AddressbookWebRequestHelperBean implements AddressbookWebRequestHel
         * <p>
         * @return User instance
         */
+       @Override
        public User getUser () {
                return this.user;
        }
index 072375ad0a02afbcb1edb1a09a59cedb0b3c2b2b..a043f84b6c90852aa2ed64e5e3e1ce4ca7cfe5bd 100644 (file)
 package org.mxchange.addressbook.beans.helper;
 
 import java.io.Serializable;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jusercore.model.user.User;
 
 /**
  * An interface for general bean helper
@@ -25,4 +30,39 @@ import java.io.Serializable;
  */
 public interface AddressbookWebRequestHelperController extends Serializable {
 
+       /**
+        * Getter for contact instance
+        * <p>
+        * @return Contact instance
+        */
+       Contact getContact ();
+
+       /**
+        * Getter for dialable fax number
+        * <p>
+        * @return Dialable fax number
+        */
+       DialableFaxNumber getFaxNumber ();
+
+       /**
+        * Getter for dialable land-line number
+        * <p>
+        * @return Dialable land-line number
+        */
+       DialableLandLineNumber getLandLineNumber ();
+
+       /**
+        * Getter for dialable mobile number
+        * <p>
+        * @return Dialable mobile number
+        */
+       DialableMobileNumber getMobileNumber ();
+
+       /**
+        * Getter for user instance
+        * <p>
+        * @return User instance
+        */
+       User getUser ();
+
 }
index 00080eb5f843cf6631ca4ac8525f57219b64f8c3..ec35e555fd36b7b804f3098ee4f407ee06108c5f 100644 (file)
@@ -32,12 +32,12 @@ import javax.inject.Named;
 import org.mxchange.addressbook.beans.BaseAddressbookBean;
 import org.mxchange.addressbook.beans.contact.AddressbookAdminContactWebRequestController;
 import org.mxchange.addressbook.beans.contact.AddressbookContactWebRequestController;
+import org.mxchange.addressbook.beans.helper.FinancialsWebViewHelperController;
 import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController;
 import org.mxchange.jcontacts.model.contact.Contact;
 import org.mxchange.jcoreee.utils.FacesUtils;
 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
-import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
 import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent;
 import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent;
 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
@@ -98,6 +98,12 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
        @EJB (lookup = "java:global/addressbook-ejb/adminUser!org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote")
        private AdminUserSessionBeanRemote adminUserBean;
 
+       /**
+        * Bean helper
+        */
+       @Inject
+       private FinancialsWebViewHelperController beanHelper;
+
        /**
         * Contact instance
         */
@@ -129,11 +135,6 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
        @Any
        private Event<ObservableAdminUpdatedUserDataEvent> updatedUserDataEvent;
 
-       /**
-        * User instance
-        */
-       private User user;
-
        /**
         * General user EJB
         */
@@ -261,7 +262,7 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
 
                // Is the user name or email address used already?
                // @TODO Add password length check
-               if (this.userController.isUserNameRegistered(newUser)) {
+               if ((this.featureController.isFeatureEnabled("user_login_require_user_name")) && (userListController.isUserNameRegistered(newUser))) {
                        // User name is already used
                        throw new FaceletException(new UserNameAlreadyRegisteredException(newUser));
                } else if ((this.getContact() == null) && (this.contactController.isEmailAddressRegistered(newUser.getUserContact()))) {
@@ -312,6 +313,15 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
                        throw new FaceletException(ex);
                }
 
+               // Now, that all is set, call EJB
+               if (this.getContact() instanceof Contact) {
+                       // Fire event
+                       userLinkedEvent.fire(new AdminLinkedUserEvent(updatedUser));
+               } else {
+                       // Fire event
+                       this.addedUserEvent.fire(new AdminAddedUserEvent(updatedUser));
+               }
+
                // Clear helper
                this.setContact(null);
 
@@ -322,33 +332,6 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
                return "admin_list_user"; //NOI18N
        }
 
-       /**
-        * Event observer for when a bean helper has successfully created a user
-        * instance, means the user exists. If the user does not exist, this event
-        * should not fire but instead a proper exception must be thrown.
-        * <p>
-        * @param event User created event
-        */
-       public void afterCreatedUserEvent (@Observes final ObservableCreatedUserEvent event) {
-               // Is the instance valid?
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getCreatedUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.createdUser is null"); //NOI18N
-               } else if (event.getCreatedUser().getUserId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.createdUser.userId is null"); //NOI18N
-               } else if (event.getCreatedUser().getUserId() < 1) {
-                       // Throw NPE again
-                       throw new NullPointerException(MessageFormat.format("event.createdUser.userId={0} is not valid", event.getCreatedUser().getUserId())); //NOI18N
-               }
-
-               // Set whole user
-               this.setUser(event.getCreatedUser());
-       }
-
        /**
         * Event observer for new user registrations
         * <p>
@@ -384,21 +367,24 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
         * @return Redirect outcome
         */
        public String deleteUserData () {
+               // Get user instance
+               final User user = this.beanHelper.getUser();
+
                // Is the user instance valid and CONFIRMED?
-               if (this.getUser() == null) {
+               if (null == user) {
                        // Throw NPE
                        throw new NullPointerException("user is null"); //NOI18N
-               } else if (this.getUser().getUserId() == null) {
+               } else if (user.getUserId() == null) {
                        // Throw again
                        throw new NullPointerException("user.userId is null"); //NOI18N
-               } else if (this.getUser().getUserId() < 1) {
+               } else if (user.getUserId() < 1) {
                        // Invalid id number
-                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", this.getUser().getUserId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
                }
 
                try {
                        // All fine, delete it
-                       this.adminUserBean.deleteUser(this.getUser(), this.getUserDeleteReason());
+                       this.adminUserBean.deleteUser(user, this.getUserDeleteReason());
                } catch (final UserNotFoundException ex) {
                        // Should not happen, so throw again
                        throw new FaceletException(ex);
@@ -417,25 +403,28 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
         * @return Redirect outcome
         */
        public String editUserData () {
+               // Get user instance
+               final User user = this.beanHelper.getUser();
+
                // Null password means not setting it
                String encryptedPassword = null;
 
                // Check if user instance is in helper and valid
-               if (this.getUser() == null) {
+               if (null == user) {
                        // Throw NPE
                        throw new NullPointerException("beanHelper.user is null"); //NOI18N
-               } else if (this.getUser().getUserId() == null) {
+               } else if (user.getUserId() == null) {
                        // Throw NPE again
                        throw new NullPointerException("beanHelper.user.userId is null"); //NOI18N
-               } else if (this.getUser().getUserId() < 1) {
+               } else if (user.getUserId() < 1) {
                        // Invalid id
-                       throw new IllegalStateException(MessageFormat.format("beanHelper.user.userId={0} is invalid", this.getUser().getUserId())); //NOI18N
+                       throw new IllegalStateException(MessageFormat.format("beanHelper.user.userId={0} is invalid", user.getUserId())); //NOI18N
                } else if (this.getUserName() == null) {
                        // Not all required fields are set
-                       throw new NullPointerException("this.userName is null"); //NOI18N
+                       throw new NullPointerException("userName is null"); //NOI18N
                } else if (this.getUserName().isEmpty()) {
                        // Not all required fields are set
-                       throw new IllegalArgumentException("this.userName is empty"); //NOI18N
+                       throw new IllegalArgumentException("userName is empty"); //NOI18N
                } else if (((!this.getUserPassword().isEmpty()) || (!this.getUserPasswordRepeat().isEmpty())) && (!this.isSamePasswordEntered())) {
                        // Clear password fields
                        this.setUserPassword(null);
@@ -453,7 +442,7 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
                        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())))) {
+                       if ((Objects.equals(user.getUserMustChangePassword(), this.getUserMustChangePassword())) && (UserLoginUtils.ifPasswordMatches(new UserLoginContainer(user, this.getUserPassword())))) {
                                // Clear password fields
                                this.setUserPassword(null);
                                this.setUserPasswordRepeat(null);
@@ -468,17 +457,25 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
                }
 
                // Set user name and flag
-               this.getUser().setUserName(this.getUserName());
-               this.getUser().setUserMustChangePassword(this.getUserMustChangePassword());
+               user.setUserName(this.getUserName());
+               user.setUserMustChangePassword(this.getUserMustChangePassword());
 
                // Is a password set?
                if (encryptedPassword != null) {
                        // Set it as well
-                       this.getUser().setUserEncryptedPassword(encryptedPassword);
+                       user.setUserEncryptedPassword(encryptedPassword);
                }
 
-               // Call EJB for updating user data
-               final User updatedUser = this.userBean.updateUserData(this.getUser());
+               // Init updated User instance
+               final User updatedUser;
+
+               try {
+                       // Call EJB for updating user data
+                       updatedUser = this.userBean.updateUserData(user);
+               } catch (final UserNotFoundException ex) {
+                       // Throw as cause
+                       throw new FacesException(ex);
+               }
 
                // Fire event
                this.updatedUserDataEvent.fire(new AdminUpdatedUserDataEvent(updatedUser));
@@ -505,24 +502,6 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
                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;
-       }
-
        /**
         * Getter for user delete reason
         * <p>
@@ -638,28 +617,31 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
         * @return Redirect outcome
         */
        public String lockUserAccount () {
+               // Get user instance
+               final User user = this.beanHelper.getUser();
+
                // Is the user instance valid and CONFIRMED?
-               if (this.getUser() == null) {
+               if (null == user) {
                        // Throw NPE
-                       throw new NullPointerException("this.user is null"); //NOI18N
-               } else if (this.getUser().getUserId() == null) {
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
                        // Throw again
-                       throw new NullPointerException("this.user.userId is null"); //NOI18N
-               } else if (this.getUser().getUserId() < 1) {
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.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) {
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
+               } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
                        // User account is locked
-                       throw new FacesException(new UserStatusLockedException(this.getUser()));
-               } else if (this.getUser().getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) {
+                       throw new FacesException(new UserStatusLockedException(user));
+               } else if (user.getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) {
                        // User account is locked
-                       throw new FaceletException(new UserStatusUnconfirmedException(this.getUser()));
+                       throw new FacesException(new UserStatusUnconfirmedException(user));
                } else if (this.getUserLockReason() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("this.userLockReason is null"); //NOI18N
+                       throw new NullPointerException("userLockReason is null"); //NOI18N
                } else if (this.getUserLockReason().isEmpty()) {
                        // Empty lock reason
-                       throw new IllegalArgumentException("this.userLockReason is empty"); //NOI18N
+                       throw new IllegalArgumentException("userLockReason is empty"); //NOI18N
                }
 
                // Init updated user instance
@@ -670,7 +652,7 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
                        final String baseUrl = FacesUtils.generateBaseUrl();
 
                        // Call EJB to lock account
-                       updatedUser = this.adminUserBean.lockUserAccount(this.getUser(), this.getUserLockReason(), baseUrl);
+                       updatedUser = this.adminUserBean.lockUserAccount(user, this.getUserLockReason(), baseUrl);
                } catch (final UserStatusLockedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
                        // Throw again
                        throw new FaceletException(ex);
@@ -693,22 +675,25 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
         * @return Redirect outcome
         */
        public String unlockUserAccount () {
+               // Get user instance
+               final User user = this.beanHelper.getUser();
+
                // Is the user instance valid and CONFIRMED?
-               if (this.getUser() == null) {
+               if (null == user) {
                        // Throw NPE
-                       throw new NullPointerException("this.user is null"); //NOI18N
-               } else if (this.getUser().getUserId() == null) {
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
                        // Throw again
-                       throw new NullPointerException("this.user.userId is null"); //NOI18N
-               } else if (this.getUser().getUserId() < 1) {
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.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) {
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
+               } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
                        // User account is locked
-                       throw new FacesException(new UserStatusConfirmedException(this.getUser()));
-               } else if (this.getUser().getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) {
+                       throw new FacesException(new UserStatusConfirmedException(user));
+               } else if (user.getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) {
                        // User account is locked
-                       throw new FaceletException(new UserStatusUnconfirmedException(this.getUser()));
+                       throw new FacesException(new UserStatusUnconfirmedException(user));
                }
 
                // Init updated user instance
@@ -719,7 +704,7 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
                        final String baseUrl = FacesUtils.generateBaseUrl();
 
                        // Call EJB to unlock account
-                       updatedUser = this.adminUserBean.unlockUserAccount(this.getUser(), baseUrl);
+                       updatedUser = this.adminUserBean.unlockUserAccount(user, baseUrl);
                } catch (final UserStatusConfirmedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
                        // Throw again
                        throw new FaceletException(ex);
@@ -741,6 +726,7 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
        private void clear () {
                // Clear all data
                this.setContact(null);
+               this.setUserDeleteReason(null);
                this.setUserLockReason(null);
                this.setUserMustChangePassword(null);
                this.setUserName(null);
index b488e4f73965dcb1084ab9d2efa4d1ccd9a2a515..03bfc251328d146b9a5b30fab0750b70a65c9856 100644 (file)
                                        </div>
                                </h:panelGroup>
 
-                               <div class="table-footer">
-                                       <p:commandButton styleClass="reset divider-right" type="reset" value="#{msg.BUTTON_RESET_FORM}" />
-
-                                       <p:commandButton styleClass="submit" type="submit" action="#{adminUserController.lockUserAccount()}" value="#{msg.BUTTON_ADMIN_LOCK_USER_ACCOUNT}" />
-                               </div>
+                               <p:panelGrid columns="2" layout="grid">
+                                       <p:commandButton
+                                               type="reset"
+                                               value="#{msg.BUTTON_RESET_FORM}"
+                                               />
+
+                                       <p:commandButton
+                                               type="submit"
+                                               action="#{adminUserController.lockUserAccount()}"
+                                               value="#{msg.BUTTON_ADMIN_LOCK_USER_ACCOUNT}"
+                                               >
+                                               <f:param name="userId" value="${beanHelper.user.userId}" />
+                                       </p:commandButton>
+                               </p:panelGrid>
                        </h:panelGroup>
                </h:form>