]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Thu, 15 Oct 2015 09:58:37 +0000 (11:58 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 15 Oct 2015 09:58:37 +0000 (11:58 +0200)
- rewrote user registration to event-driven (CDI event/observer) pattern
- updated jar(s)
Signed-off-by:Roland Häder <roland@mxchange.org>

lib/juser-core.jar
lib/juser-lib.jar
src/java/org/mxchange/addressbook/beans/register/UserRegisterWebBean.java
src/java/org/mxchange/addressbook/beans/user/UserWebBean.java
src/java/org/mxchange/addressbook/beans/user/UserWebController.java

index 404aa57a64c762198ae62f54693ad7854a9566bf..320f3709346dffe09dcb4c35042014ef71c3e1d6 100644 (file)
Binary files a/lib/juser-core.jar and b/lib/juser-core.jar differ
index c961a9711a4b53bc9c0db1a64cd39a5aecfc85ee..2dfb221c85a49cc1143983593069ce16f2170f98 100644 (file)
Binary files a/lib/juser-lib.jar and b/lib/juser-lib.jar differ
index 71995c64ddaccbbdefeed5c1d9ab43bb18a5a32b..d1ec119be92f6fc39b842b19022b67da23f6b638 100644 (file)
@@ -18,6 +18,8 @@ package org.mxchange.addressbook.beans.register;
 
 import java.text.MessageFormat;
 import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -25,6 +27,8 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.user.UserWebController;
+import org.mxchange.jusercore.events.registration.RegisteredUserEvent;
+import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
 import org.mxchange.jusercore.exceptions.DataRepeatMismatchException;
 import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
 import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
@@ -58,6 +62,13 @@ public class UserRegisterWebBean implements UserRegisterWebController {
        @Inject
        private UserWebController userController;
 
+       /**
+        * An en event fireable when a new user has registered
+        */
+       @Inject
+       @Any
+       private Event<UserRegisteredEvent> registeredEvent;
+
        /**
         * Default constructor
         */
@@ -113,17 +124,8 @@ public class UserRegisterWebBean implements UserRegisterWebController {
                        // Call bean
                        User registeredUser = this.registerBean.registerUser(user);
 
-                       // Copy all data from registered->user
-                       this.userController.copyUser(registeredUser);
-
-                       // Add user name and email address
-                       this.userController.addUserNameEmailAddress(registeredUser);
-
-                       // Clear all data
-                       this.userController.clearData();
-
-                       // Set user id again
-                       this.userController.setUserId(registeredUser.getUserId());
+                       // Fire event
+                       this.registeredEvent.fire(new RegisteredUserEvent(registeredUser));
 
                        // All fine, redirect to proper page
                        return "register_done"; //NOI18N
index 0b04027da8fcfa202bf13f25b78493e1fa67b3df..7c9c5f64b9dfaaaa48103df76d2d42320f8b3bec 100644 (file)
@@ -24,6 +24,7 @@ import java.util.List;
 import java.util.Objects;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Observes;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Named;
 import javax.naming.Context;
@@ -40,6 +41,7 @@ import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
 import org.mxchange.jphone.phonenumbers.smsprovider.SmsProvider;
+import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
 import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
@@ -194,7 +196,6 @@ public class UserWebBean implements UserWebController {
         */
        private String userPasswordRepeat;
 
-
        /**
         * Whether the user wants a public profile
         */
@@ -225,8 +226,14 @@ public class UserWebBean implements UserWebController {
                }
        }
 
-       @Override
-       public void addUserNameEmailAddress (final User user) {
+       /**
+        * Adds user's name and email address to bean's internal list. It also
+        * updates the public user list if the user has decided to have a public
+        * profile on registration.
+        * <p>
+        * @param user User instance
+        */
+       private void addUserNameEmailAddress (final User user) {
                // Make sure the entry is not added yet
                if (this.userNameList.contains(user.getUserName())) {
                        // Abort here
@@ -249,8 +256,10 @@ public class UserWebBean implements UserWebController {
                return Collections.unmodifiableList(this.publicUserList);
        }
 
-       @Override
-       public void clearData () {
+       /**
+        * Clears all data in this bean
+        */
+       private void clearData () {
                // Clear all data
                // - personal data
                this.setUserId(null);
@@ -279,8 +288,12 @@ public class UserWebBean implements UserWebController {
                this.setUserPasswordRepeat(null);
        }
 
-       @Override
-       public void copyUser (final User user) {
+       /**
+        * Copies given user into the controller
+        * <p>
+        * @param user User instance
+        */
+       private void copyUser (final User user) {
                // Copy all fields:
                // - base data
                this.setUserId(user.getUserId());
@@ -422,6 +435,39 @@ public class UserWebBean implements UserWebController {
                return user;
        }
 
+       @Override
+       public void afterRegistration (final @Observes UserRegisteredEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null");
+               } else if (event.getUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.user is null");
+               } else if (event.getUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.user.userId is null");
+               } else if (event.getUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUser(), event.getUser().getUserId()));
+               }
+
+               // Get user instance
+               User registeredUser = event.getUser();
+
+               // Copy all data from registered->user
+               this.copyUser(registeredUser);
+
+               // Add user name and email address
+               this.addUserNameEmailAddress(registeredUser);
+
+               // Clear all data
+               this.clearData();
+
+               // Set user id again
+               this.setUserId(registeredUser.getUserId());
+       }
+
        @Override
        public Date getBirthday () {
                return this.birthday;
index 92cc995f24888c2032d29b12b45cae592a8c195b..e887607e02427c36b91ad2a79ae26ec9f2180f95 100644 (file)
@@ -22,6 +22,7 @@ import java.util.List;
 import org.mxchange.jcontacts.contact.gender.Gender;
 import org.mxchange.jcountry.data.Country;
 import org.mxchange.jphone.phonenumbers.smsprovider.SmsProvider;
+import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
 import org.mxchange.jusercore.model.user.User;
 
 /**
@@ -31,15 +32,6 @@ import org.mxchange.jusercore.model.user.User;
  */
 public interface UserWebController extends Serializable {
 
-       /**
-        * Adds user's name and email address to bean's internal list. It also
-        * updates the public user list if the user has decided to have a public
-        * profile on registration.
-        * <p>
-        * @param user User instance
-        */
-       void addUserNameEmailAddress (final User user);
-
        /**
         * All public user profiles
         * <p>
@@ -47,18 +39,6 @@ public interface UserWebController extends Serializable {
         */
        List<User> allPublicUsers ();
 
-       /**
-        * Clears all data in this bean
-        */
-       void clearData ();
-
-       /**
-        * Copies given user into the controller
-        * <p>
-        * @param user User instance
-        */
-       void copyUser (final User user);
-
        /**
         * Creates an instance from all properties
         * <p>
@@ -462,4 +442,11 @@ public interface UserWebController extends Serializable {
         * @return Whether at least one user has a public profile
         */
        boolean isPublicUserRegistered ();
+
+       /**
+        * Event observer for new user registrations
+        * <p>
+        * @param event User registration event
+        */
+       void afterRegistration (final UserRegisteredEvent event);
 }