From: Roland Haeder Date: Thu, 15 Oct 2015 17:22:48 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ccecb6c9bc26e900062848923f50360396216274;p=addressbook-war.git Continued: - implemented observer that will update user's address book list - updated jar(s) --- diff --git a/lib/juser-core.jar b/lib/juser-core.jar index 0a7e08cc..94920473 100644 Binary files a/lib/juser-core.jar and b/lib/juser-core.jar differ diff --git a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java index b4353f38..143fdd39 100644 --- a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java @@ -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()); + } } diff --git a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java index f1cf0c45..457462d0 100644 --- a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java +++ b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java @@ -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. + *

+ * @param event + */ + void afterLoginEvent (final UserLoggedInEvent event); } diff --git a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java index c90b8b7f..a6c78327 100644 --- a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java @@ -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 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; }