]> git.mxchange.org Git - pizzaservice-war.git/blobdiff - src/java/org/mxchange/pizzaapplication/beans/user/confirmlink/PizzaConfirmationLinkWebRequestBean.java
Pre-commit:
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / user / confirmlink / PizzaConfirmationLinkWebRequestBean.java
index 23edfa6d0f174731422cab9ad4f1b4861fdb51b4..c665071157bd35de2b8e6d21c30feaf23f180aae 100644 (file)
@@ -20,36 +20,36 @@ import java.text.MessageFormat;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Objects;
-import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Event;
 import javax.enterprise.inject.Any;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
 import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
+import org.mxchange.jcoreee.events.helper.clear.HelperCleanupEvent;
+import org.mxchange.jcoreee.events.helper.clear.ObservableHelperCleanupEvent;
 import org.mxchange.jcoreee.utils.FacesUtils;
-import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
-import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
+import org.mxchange.jusercore.events.user.created.CreatedUserEvent;
+import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
 import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
 import org.mxchange.jusercore.exceptions.UserStatusLockedException;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
-import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
+import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.juserlogincore.events.confirmation.UserConfirmedAccountEvent;
+import org.mxchange.pizzaapplication.beans.BasePizzaBean;
+import org.mxchange.pizzaapplication.beans.user.PizzaUserWebRequestController;
 
 /**
  * A web request bean for confirmation link handling
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-@Named ("confirmationLinkController")
+@Named ("userConfirmationLinkController")
 @RequestScoped
-public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController implements PizzaConfirmationLinkWebRequestController {
+public class PizzaConfirmationLinkWebRequestBean extends BasePizzaBean implements PizzaConfirmationLinkWebRequestController {
 
        /**
         * Serial number
@@ -57,10 +57,11 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
        private static final long serialVersionUID = 57_637_182_796_370L;
 
        /**
-        * Bean helper instance
+        * Event being fired when a bean helper should be cleaned
         */
        @Inject
-       private PizzaWebRequestHelperController beanHelper;
+       @Any
+       private Event<ObservableHelperCleanupEvent> cleanHelperEvent;
 
        /**
         * Confirmation key
@@ -70,6 +71,7 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
        /**
         * Remote user bean
         */
+       @EJB (lookup = "java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote")
        private UserSessionBeanRemote userBean;
 
        /**
@@ -83,7 +85,14 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
         * User controller
         */
        @Inject
-       private PizzaUserWebSessionController userController;
+       private PizzaUserWebRequestController userController;
+
+       /**
+        * Event for when a user instance was created
+        */
+       @Any
+       @Inject
+       private Event<ObservableCreatedUserEvent> userCreatedEvent;
 
        /**
         * Default constructor
@@ -103,24 +112,6 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
                this.confirmationKey = confirmationKey;
        }
 
-       /**
-        * Post-construction method
-        */
-       @PostConstruct
-       public void init () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
-       }
-
        @Override
        public void maybeConfirmUserAccount () {
                // Is the confirmation key set?
@@ -133,10 +124,10 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
                }
 
                // Now try to find the user in user list, first get the whole list
-               List<User> users = this.userController.allUsers();
+               final List<User> users = this.userController.allUsers();
 
                // Get iterator from it
-               Iterator<User> iterator = users.iterator();
+               final Iterator<User> iterator = users.iterator();
 
                // Init instance
                User user = null;
@@ -144,7 +135,7 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
                // Then loop through all
                while (iterator.hasNext()) {
                        // Get next user
-                       User next = iterator.next();
+                       final User next = iterator.next();
 
                        // Same confirmation key?
                        if (Objects.equals(this.getConfirmationKey(), next.getUserConfirmKey())) {
@@ -157,30 +148,23 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
                // Is the user instance null?
                if ((null == user) || (user.getUserAccountStatus() != UserAccountStatus.UNCONFIRMED)) {
                        // Then clear this bean and the helper
-                       this.beanHelper.setUser(null);
+                       this.cleanHelperEvent.fire(new HelperCleanupEvent());
                } else {
-                       // Set user ...
-                       this.beanHelper.setUser(user);
-
-                       // ... and copy it to the controller
-                       this.beanHelper.copyUserToController();
-
                        // Try to confirm it
-                       this.confirmUserAccount();
+                       this.confirmUserAccount(user);
                }
        }
 
        /**
         * Tries to confirm the currently set user instance (in helper).
+        * <p>
+        * @param user User instance
         */
-       private void confirmUserAccount () {
-               // Get user instance
-               User user = this.beanHelper.getUser();
-
+       private void confirmUserAccount (final User user) {
                // Should be set
                if (null == user) {
                        // Throw NPE
-                       throw new NullPointerException("user is null");
+                       throw new NullPointerException("user is null"); //NOI18N
                } else if (user.getUserId() == null) {
                        // Abort here
                        throw new NullPointerException("user.userId is null"); //NOI18N
@@ -196,14 +180,17 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
                } else if (user.getUserConfirmKey() == null) {
                        // Throw NPE
                        throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
+               } else if (user.getUserConfirmKey().isEmpty()) {
+                       // Is empty string
+                       throw new IllegalArgumentException("user.userConfirmKey is empty"); //NOI18N
                }
 
                // Updated user instance
-               User updatedUser;
+               final User updatedUser;
 
                try {
                        // Get base URL
-                       String baseUrl = FacesUtils.generateBaseUrl();
+                       final String baseUrl = FacesUtils.generateBaseUrl();
 
                        // Confirm account
                        updatedUser = this.userBean.confirmAccount(user, baseUrl);
@@ -215,8 +202,8 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
                // Fire event that the user has confirmed account
                this.userConfirmedEvent.fire(new UserConfirmedAccountEvent(updatedUser));
 
-               // Set it again in helper
-               this.beanHelper.setUser(updatedUser);
+               // Fire event
+               this.userCreatedEvent.fire(new CreatedUserEvent(updatedUser));
        }
 
 }