]> 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 98b46a9a3afc89b008ad186e067244941bcc97dd..c665071157bd35de2b8e6d21c30feaf23f180aae 100644 (file)
@@ -20,27 +20,27 @@ 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
@@ -49,7 +49,7 @@ import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
  */
 @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,29 +112,8 @@ 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 () {
-               // Trace message
-               System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
                // Is the confirmation key set?
                if (this.getConfirmationKey() == null) {
                        // May be null if not set
@@ -136,13 +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();
-
-               // Debug message
-               System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: users.size()={1}", this.getClass().getSimpleName(), users.size())); //NOI18N
+               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;
@@ -150,36 +135,24 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
                // Then loop through all
                while (iterator.hasNext()) {
                        // Get next user
-                       User next = iterator.next();
-
-                       // Debug message
-                       System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: this.confirmationKey={1},next.confirmationKey={2}", this.getClass().getSimpleName(), this.getConfirmationKey(), next.getUserConfirmKey())); //NOI18N
+                       final User next = iterator.next();
 
                        // Same confirmation key?
                        if (Objects.equals(this.getConfirmationKey(), next.getUserConfirmKey())) {
-                               // Debug message
-                               System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: next={1} - Aborting ...", this.getClass().getSimpleName(), next)); //NOI18N
-
                                // Found it, then set it and abort loop
                                user = next;
                                break;
                        }
                }
 
-               // Debug message
-               System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: user={1}", this.getClass().getSimpleName(), user)); //NOI18N
-
                // 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 {
                        // Try to confirm it
                        this.confirmUserAccount(user);
                }
-
-               // Trace message
-               System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: EXIT!", this.getClass().getSimpleName())); //NOI18N
        }
 
        /**
@@ -188,9 +161,6 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
         * @param user User instance
         */
        private void confirmUserAccount (final User user) {
-               // Trace message
-               System.out.println(MessageFormat.format("{0}.confirmUserAccount: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
-
                // Should be set
                if (null == user) {
                        // Throw NPE
@@ -216,20 +186,14 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
                }
 
                // Updated user instance
-               User updatedUser;
+               final User updatedUser;
 
                try {
                        // Get base URL
-                       String baseUrl = FacesUtils.generateBaseUrl();
-
-                       // Debug message
-                       System.out.println(MessageFormat.format("{0}.confirmUserAccount: baseUrl={1}", this.getClass().getSimpleName(), baseUrl)); //NOI18N
+                       final String baseUrl = FacesUtils.generateBaseUrl();
 
                        // Confirm account
                        updatedUser = this.userBean.confirmAccount(user, baseUrl);
-
-                       // Debug message
-                       System.out.println(MessageFormat.format("{0}.confirmUserAccount: updatedUser={1} - Returned from EJB", this.getClass().getSimpleName(), updatedUser)); //NOI18N
                } catch (final UserStatusConfirmedException | UserStatusLockedException ex) {
                        // Something unexpected happened
                        throw new FaceletException(MessageFormat.format("Cannot confirm user account {0}", user.getUserName()), ex); //NOI18N
@@ -238,17 +202,8 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
                // Fire event that the user has confirmed account
                this.userConfirmedEvent.fire(new UserConfirmedAccountEvent(updatedUser));
 
-               // Debug message
-               System.out.println(MessageFormat.format("{0}.confirmUserAccount: updatedUser={1}", this.getClass().getSimpleName(), updatedUser)); //NOI18N
-
-               // Set it again in helper
-               this.beanHelper.setUser(updatedUser);
-
-               // ... and copy it to the controller
-               this.beanHelper.copyUserToController();
-
-               // Trace message
-               System.out.println(MessageFormat.format("{0}.confirmUserAccount: EXIT!", this.getClass().getSimpleName())); //NOI18N
+               // Fire event
+               this.userCreatedEvent.fire(new CreatedUserEvent(updatedUser));
        }
 
 }