]> git.mxchange.org Git - addressbook-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Thu, 20 Oct 2022 16:42:21 +0000 (18:42 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 20 Oct 2022 16:46:17 +0000 (18:46 +0200)
- renamed copyUser() to copyToUser() because that method "copies" (read: sets)
  all required class fields except "entry-created" in given user instance
- also used UserContact's parameterized constructor instead of default one and
  then setting all on my own
- removed @PostConstruct method

src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebRequestBean.java
src/java/org/mxchange/addressbook/beans/features/AddressbookFeatureWebApplicationBean.java
src/java/org/mxchange/addressbook/beans/user/login/AddressbookUserLoginWebSessionBean.java

index 671af5371d8709172fdc5cbebf7271556d50a956..6c63aee1f530cc18ab05cc9cdf4760b666406f51 100644 (file)
@@ -107,7 +107,7 @@ public class AddressbookAdminCountryWebRequestBean extends BaseAddressbookBean i
 
        /**
         * Adds country to all relevant beans and sends it to the EJB. A redirect
-        * should happen after successfull creation.
+        * should happen after successful creation.
         * <p>
         * @return Redirect outcome
         * <p>
@@ -115,15 +115,14 @@ public class AddressbookAdminCountryWebRequestBean extends BaseAddressbookBean i
         */
        public String addCountry () {
                // Create new country object
-               final Country country = new CountryData();
-
-               // Add all data
-               country.setCountryAbroadDialPrefix(this.getCountryAbroadDialPrefix());
-               country.setCountryCode(this.getCountryCode());
-               country.setCountryExternalDialPrefix(this.getCountryExternalDialPrefix());
-               country.setCountryI18nKey(this.getCountryI18nKey());
-               country.setCountryIsLocalPrefixRequired(this.getCountryIsLocalPrefixRequired());
-               country.setCountryPhoneCode(this.getCountryPhoneCode());
+               final Country country = new CountryData(
+                                         this.getCountryAbroadDialPrefix(),
+                                         this.getCountryCode(),
+                                         this.getCountryExternalDialPrefix(),
+                                         this.getCountryI18nKey(),
+                                         this.getCountryIsLocalPrefixRequired(),
+                                         this.getCountryPhoneCode()
+                         );
 
                // Does it already exist?
                if (this.isCountryAdded(country)) {
index 07be03ef75f85ec386851023ef9ab9826f0edd5a..a0212aa2e035ece23c6ff71d90048afdb4b1a313 100644 (file)
@@ -16,7 +16,6 @@
  */
 package org.mxchange.addressbook.beans.features;
 
-import javax.annotation.PostConstruct;
 import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Named;
 import org.mxchange.addressbook.beans.BaseAddressbookBean;
@@ -43,13 +42,6 @@ public class AddressbookFeatureWebApplicationBean extends BaseAddressbookBean im
                super();
        }
 
-       /**
-        * Post-construction method
-        */
-       @PostConstruct
-       public void init () {
-       }
-
        @Override
        public boolean isFeatureEnabled (final String feature) {
                // The parameter must be set
index 4b5230b1cf66cb28650e6e46efbd99bd6fbb1e41..c308d41e43828b6d858dd0158522f728377d3990 100644 (file)
@@ -164,10 +164,122 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookBean impl
                        throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
                }
 
-               // All fine, so update list
+               // Set user id again
+               this.setUserId(event.getLinkedUser().getUserId());
+       }
+
+       /**
+        * 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
+               }
+
+               // Get user instance
+               final User user = event.getCreatedUser();
+
+               // Set all fields here
+               this.copyToUser(user);
+       }
+
+       /**
+        * Event observer for logged-in user
+        * <p>
+        * @param event Event instance
+        */
+       public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
+               // Event and contained entity instance should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLoggedInUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.registeredUser is null"); //NOI18N
+               } else if (event.getLoggedInUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
+               } else if (event.getLoggedInUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
+               }
+
+               // "Cache" user instance
+               final User user = event.getLoggedInUser();
+
+               // Copy all data to this bean
+               this.copyToUser(user);
+       }
+
+       /**
+        * Event observer for user password changes
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterUserPasswordChangedEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
+               // Is it valid?
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUserPassword() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("event.userPassword is null"); //NOI18N
+               } else if (event.getUserPassword().isEmpty()) {
+                       // Throw NPE
+                       throw new IllegalArgumentException("event.userPassword is empty"); //NOI18N
+               }
+
+               // Set it here
+               this.setUserPassword(event.getUserPassword());
                this.updatePasswordHistory(event.getPasswordHistory());
        }
 
+       /**
+        * Event observer for new user registrations
+        * <p>
+        * @param event User registration event
+        */
+       public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
+               // Event and contained entity instance should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getRegisteredUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.registeredUser is null"); //NOI18N
+               } else if (event.getRegisteredUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
+               } else if (event.getRegisteredUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+               }
+
+               // Get user instance
+               final User registeredUser = event.getRegisteredUser();
+
+               // Copy all data from registered->user
+               this.copyToUser(registeredUser);
+
+               // Set user id again
+               this.setUserId(registeredUser.getUserId());
+       }
+
        /**
         * Logout for administrator area. If a logged-in user instance exists, it is
         * being logged-out, too.
@@ -395,6 +507,20 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookBean impl
        private void clear () {
                // Clear all fields
                this.setUserCurrentPassword(null);
+               this.setUserProfileMode(null);
+       }
+
+       /**
+        * Copies given user into the controller
+        * <p>
+        * @param user User instance
+        */
+       private void copyToUser (final User user) {
+               // Copy all fields:
+               // - base data
+               this.setUserId(user.getUserId());
+               this.setUserName(user.getUserName());
+               this.setUserProfileMode(user.getUserProfileMode());
        }
 
        /**