]> git.mxchange.org Git - pizzaservice-war.git/blobdiff - src/java/org/mxchange/pizzaapplication/beans/user/confirmlink/PizzaConfirmationLinkWebRequestBean.java
Please cherry-pick:
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / user / confirmlink / PizzaConfirmationLinkWebRequestBean.java
index 23edfa6d0f174731422cab9ad4f1b4861fdb51b4..ad0a09e37ac17a5c5d975c10f51e8208c420bc79 100644 (file)
@@ -30,14 +30,18 @@ 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.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.juserlogincore.events.confirmation.UserConfirmedAccountEvent;
 import org.mxchange.pizzaapplication.beans.BasePizzaController;
 import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
 import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
@@ -47,7 +51,7 @@ import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-@Named ("confirmationLinkController")
+@Named ("userConfirmationLinkController")
 @RequestScoped
 public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController implements PizzaConfirmationLinkWebRequestController {
 
@@ -62,6 +66,13 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
        @Inject
        private PizzaWebRequestHelperController beanHelper;
 
+       /**
+        * Event being fired when a bean helper should be cleaned
+        */
+       @Inject
+       @Any
+       private Event<ObservableHelperCleanupEvent> cleanHelperEvent;
+
        /**
         * Confirmation key
         */
@@ -85,6 +96,13 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
        @Inject
        private PizzaUserWebSessionController userController;
 
+       /**
+        * Event for when a user instance was created
+        */
+       @Any
+       @Inject
+       private Event<ObservableCreatedUserEvent> userCreatedEvent;
+
        /**
         * Default constructor
         */
@@ -123,6 +141,9 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
 
        @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
@@ -135,6 +156,9 @@ 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
+
                // Get iterator from it
                Iterator<User> iterator = users.iterator();
 
@@ -146,41 +170,49 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
                        // 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
+
                        // 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 {
-                       // Set user ...
-                       this.beanHelper.setUser(user);
-
-                       // ... and copy it to the controller
-                       this.beanHelper.copyUserToController();
-
                        // Try to confirm it
-                       this.confirmUserAccount();
+                       this.confirmUserAccount(user);
                }
+
+               // Trace message
+               System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: EXIT!", this.getClass().getSimpleName())); //NOI18N
        }
 
        /**
         * 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) {
+               // 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
-                       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,6 +228,9 @@ 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
@@ -205,8 +240,14 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
                        // Get base URL
                        String baseUrl = FacesUtils.generateBaseUrl();
 
+                       // Debug message
+                       System.out.println(MessageFormat.format("{0}.confirmUserAccount: baseUrl={1}", this.getClass().getSimpleName(), baseUrl)); //NOI18N
+
                        // 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
@@ -215,8 +256,14 @@ 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);
+               // Debug message
+               System.out.println(MessageFormat.format("{0}.confirmUserAccount: updatedUser={1}", this.getClass().getSimpleName(), updatedUser)); //NOI18N
+
+               // Fire event
+               this.userCreatedEvent.fire(new CreatedUserEvent(updatedUser));
+
+               // Trace message
+               System.out.println(MessageFormat.format("{0}.confirmUserAccount: EXIT!", this.getClass().getSimpleName())); //NOI18N
        }
 
 }