]> git.mxchange.org Git - pizzaservice-war.git/blobdiff - src/java/org/mxchange/pizzaapplication/beans/user/confirmlink/PizzaConfirmationLinkWebRequestBean.java
Updated copyright year
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / user / confirmlink / PizzaConfirmationLinkWebRequestBean.java
index ad0a09e37ac17a5c5d975c10f51e8208c420bc79..b13677cf47bc4360a6d8f7fdd73433a8cd8ec252 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2024 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -20,16 +20,13 @@ 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;
@@ -42,9 +39,8 @@ 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;
+import org.mxchange.pizzaapplication.beans.BasePizzaBean;
+import org.mxchange.pizzaapplication.beans.user.PizzaUserWebRequestController;
 
 /**
  * A web request bean for confirmation link handling
@@ -53,19 +49,13 @@ 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
         */
        private static final long serialVersionUID = 57_637_182_796_370L;
 
-       /**
-        * Bean helper instance
-        */
-       @Inject
-       private PizzaWebRequestHelperController beanHelper;
-
        /**
         * Event being fired when a bean helper should be cleaned
         */
@@ -81,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;
 
        /**
@@ -94,7 +85,7 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
         * User controller
         */
        @Inject
-       private PizzaUserWebSessionController userController;
+       private PizzaUserWebRequestController userController;
 
        /**
         * Event for when a user instance was created
@@ -121,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
@@ -154,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;
@@ -168,25 +135,16 @@ 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
@@ -195,9 +153,6 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
                        // Try to confirm it
                        this.confirmUserAccount(user);
                }
-
-               // Trace message
-               System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: EXIT!", this.getClass().getSimpleName())); //NOI18N
        }
 
        /**
@@ -206,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
@@ -234,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
@@ -256,14 +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
-
                // Fire event
                this.userCreatedEvent.fire(new CreatedUserEvent(updatedUser));
-
-               // Trace message
-               System.out.println(MessageFormat.format("{0}.confirmUserAccount: EXIT!", this.getClass().getSimpleName())); //NOI18N
        }
 
 }