]> git.mxchange.org Git - jfinancials-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:52:47 +0000 (18:52 +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

src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebViewHelperBean.java
src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebViewHelperController.java
src/java/org/mxchange/jfinancials/beans/user/FinancialsAdminUserWebRequestBean.java
web/admin/user/admin_user_lock.xhtml

index 5ec0b949867721a0851e7ab6612990ee635b3b60..52b5ba986d0a50e38c133c6bc15b43cabb942bd0 100644 (file)
@@ -147,6 +147,7 @@ public class FinancialsWebViewHelperBean extends BaseFinancialsBean implements F
         * <p>
         * @return Contact instance
         */
+       @Override
        public Contact getContact () {
                return this.contact;
        }
@@ -199,6 +200,7 @@ public class FinancialsWebViewHelperBean extends BaseFinancialsBean implements F
         * <p>
         * @return Dialable fax number
         */
+       @Override
        public DialableFaxNumber getFaxNumber () {
                return this.faxNumber;
        }
@@ -217,6 +219,7 @@ public class FinancialsWebViewHelperBean extends BaseFinancialsBean implements F
         * <p>
         * @return Dialable land-line number
         */
+       @Override
        public DialableLandLineNumber getLandLineNumber () {
                return this.landLineNumber;
        }
@@ -235,6 +238,7 @@ public class FinancialsWebViewHelperBean extends BaseFinancialsBean implements F
         * <p>
         * @return Dialable mobile number
         */
+       @Override
        public DialableMobileNumber getMobileNumber () {
                return this.mobileNumber;
        }
@@ -253,6 +257,7 @@ public class FinancialsWebViewHelperBean extends BaseFinancialsBean implements F
         * <p>
         * @return User instance
         */
+       @Override
        public User getUser () {
                return this.user;
        }
index 649e49097985f56fd9557c7d582be0f88b9885fd..0c45168d83c4e5617cfe62dd1cba4f039c68076c 100644 (file)
 package org.mxchange.jfinancials.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 FinancialsWebViewHelperController 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 4f51d1a01e89407bf1b0c10bff6e5bd04aae00f7..e5c9260e2083a006cad37bd88d63df5253ba5854 100644 (file)
@@ -35,10 +35,10 @@ import org.mxchange.jfinancials.beans.BaseFinancialsBean;
 import org.mxchange.jfinancials.beans.contact.FinancialsAdminContactWebRequestController;
 import org.mxchange.jfinancials.beans.contact.FinancialsContactWebRequestController;
 import org.mxchange.jfinancials.beans.features.FinancialsFeaturesWebApplicationController;
+import org.mxchange.jfinancials.beans.helper.FinancialsWebViewHelperController;
 import org.mxchange.jfinancials.beans.user.list.FinancialsUserListWebViewController;
 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;
@@ -99,6 +99,12 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
        @EJB (lookup = "java:global/jfinancials-ejb/adminUser!org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote")
        private AdminUserSessionBeanRemote adminUserBean;
 
+       /**
+        * Bean helper
+        */
+       @Inject
+       private FinancialsWebViewHelperController beanHelper;
+
        /**
         * Contact instance
         */
@@ -130,11 +136,6 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
        @Any
        private Event<ObservableAdminPostUserDataUpdatedEvent> updatedUserDataEvent;
 
-       /**
-        * User instance
-        */
-       private User user;
-
        /**
         * General user EJB
         */
@@ -236,7 +237,7 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
 
                // Is the user name or email address used already?
                // @TODO Add password length check
-               if ((this.featureController.isFeatureEnabled("user_login_require_user_name")) && (this.userListController.isUserNameRegistered(newUser))) {
+               if ((this.featureController.isFeatureEnabled("user_login_require_user_name")) && (userListController.isUserNameRegistered(newUser))) {
                        // User name is already used
                        throw new FacesException(new UserNameAlreadyRegisteredException(newUser));
                } else if ((this.getContact() == null) && (this.contactController.isEmailAddressRegistered(newUser.getUserContact()))) {
@@ -271,7 +272,7 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
                // Now, that all is set, call EJB
                if (this.getContact() instanceof Contact) {
                        // Fire event
-                       this.userLinkedEvent.fire(new AdminLinkedUserEvent(updatedUser));
+                       userLinkedEvent.fire(new AdminLinkedUserEvent(updatedUser));
                } else {
                        // Fire event
                        this.addedUserEvent.fire(new AdminAddedUserEvent(updatedUser));
@@ -283,33 +284,6 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
                this.clear();
        }
 
-       /**
-        * 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>
@@ -343,53 +317,59 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
         * Deletes given user account
         */
        public void 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 FacesException(ex);
                }
 
                // Fire event
-               this.deleteUserEvent.fire(new AdminDeletedUserEvent(this.getUser(), this.getUserDeleteReason()));
+               this.deleteUserEvent.fire(new AdminDeletedUserEvent(user, this.getUserDeleteReason()));
        }
 
        /**
         * Edits currently loaded user's data in database.
         */
        public void 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);
@@ -398,7 +378,7 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
                        // Not same password entered
                        this.showFacesMessage("form_edit_user:userPassword", "ADMIN_USER_PASSWORD_REPEAT_DIFFERENT", FacesMessage.SEVERITY_INFO); //NOI18N
                        return;
-               } else if ((!Objects.equals(this.getUser().getUserName(), this.getUserName())) && (this.userBean.ifUserNameExists(this.getUserName()))) {
+               } else if ((!Objects.equals(user.getUserName(), this.getUserName())) && (userBean.ifUserNameExists(this.getUserName()))) {
                        // Clear all fields
                        this.clear();
 
@@ -407,7 +387,7 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
                        return;
                } 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);
@@ -422,13 +402,13 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
                }
 
                // 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);
                }
 
                // Init updated User instance
@@ -436,7 +416,7 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
 
                try {
                        // Call EJB for updating user data
-                       updatedUser = this.userBean.updateUserData(this.getUser());
+                       updatedUser = this.userBean.updateUserData(user);
                } catch (final UserNotFoundException ex) {
                        // Throw as cause
                        throw new FacesException(ex);
@@ -464,24 +444,6 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
                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>
@@ -615,28 +577,31 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
         * @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 FacesException(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
@@ -647,7 +612,7 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
                        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 FacesException(ex);
@@ -670,22 +635,25 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
         * @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 FacesException(new UserStatusUnconfirmedException(this.getUser()));
+                       throw new FacesException(new UserStatusUnconfirmedException(user));
                }
 
                // Init updated user instance
@@ -696,7 +664,7 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
                        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 FacesException(ex);
@@ -719,7 +687,6 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsBean implem
                // Clear all data
                this.setContact(null);
                this.setUserDeleteReason(null);
-               this.setUser(null);
                this.setUserLockReason(null);
                this.setUserMustChangePassword(null);
                this.setUserName(null);
index 93a7cb4a780b04aa539ebc3196b92d936dceb7fe..a0f535f3efb504bb79a7d6c4bca106f6e8a9c543 100644 (file)
@@ -90,7 +90,9 @@
                                                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>