]> git.mxchange.org Git - addressbook-war.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Thu, 15 Oct 2015 17:22:48 +0000 (19:22 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 15 Oct 2015 17:22:48 +0000 (19:22 +0200)
- implemented observer that will update user's address book list
- updated jar(s)

lib/juser-core.jar
src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java
src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java
src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java

index 0a7e08ccd541827054c107c421cc7fa41f2604cd..94920473f0bd2dcfee1d99e5be9f16c81e3bd70d 100644 (file)
Binary files a/lib/juser-core.jar and b/lib/juser-core.jar differ
index b4353f38bdba4f1f4fc18a93d3b3cb70ea216560..143fdd390b9ab75745e391e4ff972de5332e57d2 100644 (file)
@@ -34,7 +34,7 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.login.UserLoginWebController;
-import org.mxchange.addressbook.events.AddressbookLoadedEvent;
+import org.mxchange.addressbook.events.addressbook.AddressbookLoadedEvent;
 import org.mxchange.addressbook.exceptions.AddressbookNameAlreadyUsedException;
 import org.mxchange.addressbook.model.addressbook.Addressbook;
 import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote;
@@ -42,6 +42,7 @@ import org.mxchange.addressbook.model.addressbook.UserAddressbook;
 import org.mxchange.addressbook.model.addressbook.entry.AddressbookEntry;
 import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook;
 import org.mxchange.addressbook.model.addressbook.status.AddressbokStatus;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
 import org.mxchange.jusercore.model.user.User;
 
 /**
@@ -314,8 +315,8 @@ public class AddressbookWebBean implements AddressbookWebController {
 
                // Is the user logged-in?
                if (this.loginController.isUserLoggedIn()) {
-                       // Fill list with entries
-                       this.usersAddressbooks = this.addressbookBean.getUsersList(this.loginController.getLoggedInUser());
+                       // Initialize list
+                       this.initAddressbookList();
                }
 
                // TODO Initialize list from bean with just one call
@@ -349,4 +350,33 @@ public class AddressbookWebBean implements AddressbookWebController {
                // Return status
                return isFound;
        }
+
+       @Override
+       public void afterLoginEvent (final @Observes UserLoggedInEvent event) {
+               // Is the user logged in?
+               if (null == event) {
+                       // Is null
+                       throw new NullPointerException("event is null");
+               } else if (event.getUser() == null) {
+                       // user is null
+                       throw new NullPointerException("event.user is null");
+               } else if (!event.getUser().equals(this.loginController.getLoggedInUser())) {
+                       // Not matching
+                       throw new IllegalStateException("event.user and loginController.loggedInUser don't match.");
+               } else if (!this.loginController.isUserLoggedIn()) {
+                       // Not logged in
+                       throw new FaceletException("This method can only be called as logged-in user."); //NOI18N
+               }
+
+               // Init user's address book list
+               this.initAddressbookList();
+       }
+
+       /**
+        * Initializes the user user's address book list
+        */
+       private void initAddressbookList () {
+               // Fill list with entries
+               this.usersAddressbooks = this.addressbookBean.getUsersList(this.loginController.getLoggedInUser());
+       }
 }
index f1cf0c450cbe9290070a227b56a079e2bcadc7d7..457462d04ac3910d982d70d0ef1aed7eafd2b0ad 100644 (file)
@@ -19,10 +19,11 @@ package org.mxchange.addressbook.beans.addressbook;
 import java.io.Serializable;
 import java.util.Calendar;
 import java.util.List;
-import org.mxchange.addressbook.events.AddressbookLoadedEvent;
+import org.mxchange.addressbook.events.addressbook.AddressbookLoadedEvent;
 import org.mxchange.addressbook.model.addressbook.Addressbook;
 import org.mxchange.addressbook.model.addressbook.entry.AddressbookEntry;
 import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
 import org.mxchange.jusercore.model.user.User;
 
 /**
@@ -162,4 +163,12 @@ public interface AddressbookWebController extends Serializable {
         * @return Count of user's shared address books
         */
        Integer countAllUserSharedAddressbooks (final User user);
+
+       /**
+        * This method is called when a user has successfully logged in his/her
+        * account.
+        * <p>
+        * @param event
+        */
+       void afterLoginEvent (final UserLoggedInEvent event);
 }
index c90b8b7fdf6ddab00f315fd9ce5c83024bf8fffa..a6c7832780d4df5f6ebec9488f4ae6826308d81e 100644 (file)
@@ -18,6 +18,8 @@ package org.mxchange.addressbook.beans.login;
 
 import java.util.Objects;
 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;
@@ -27,6 +29,8 @@ import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.user.UserWebController;
 import org.mxchange.jusercore.container.login.LoginContainer;
 import org.mxchange.jusercore.container.login.UserLoginContainer;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
+import org.mxchange.jusercore.events.login.UserLoginEvent;
 import org.mxchange.jusercore.exceptions.UserNotFoundException;
 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
 import org.mxchange.jusercore.exceptions.UserStatusLockedException;
@@ -59,6 +63,13 @@ public class UserLoginWebBean implements UserLoginWebController {
         */
        private UserLoginSessionBeanRemote loginBean;
 
+       /**
+        * Event fired when user has logged in
+        */
+       @Inject
+       @Any
+       private Event<UserLoggedInEvent> loginEvent;
+
        /**
         * Template type for pages that might be displayed in guest area and login
         * area. Default is guest area.
@@ -110,6 +121,9 @@ public class UserLoginWebBean implements UserLoginWebController {
                        // Set template to "login"
                        this.setTemplateType("login"); //NOI18N
 
+                       // Fire event away. Keep this last before return statement.
+                       this.loginEvent.fire(new UserLoginEvent(confirmedUser));
+
                        // All fine
                        return "login"; //NOI18N
                } catch (final UserNotFoundException | UserStatusLockedException | UserStatusUnconfirmedException | UserPasswordMismatchException ex) {
@@ -153,7 +167,6 @@ public class UserLoginWebBean implements UserLoginWebController {
 
                // Trace message
                // NOISY: System.out.println(MessageFormat.format("UserLoginWebBean:isUserLoggedIn: this.userLoggedIn={0} - EXIT!", this.userLoggedIn));
-
                // Return it
                return this.userLoggedIn;
        }