From: Roland Haeder Date: Sat, 17 Oct 2015 19:07:30 +0000 (+0200) Subject: addded method afterUserLogin() which is an CDI observer on logged-in user events X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=417de23a10ad955fc99c4b671db97cfe81430825;p=addressbook-war.git addded method afterUserLogin() which is an CDI observer on logged-in user events --- diff --git a/src/java/org/mxchange/addressbook/beans/user/UserWebBean.java b/src/java/org/mxchange/addressbook/beans/user/UserWebBean.java index 3759a66e..8bb0bf65 100644 --- a/src/java/org/mxchange/addressbook/beans/user/UserWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/UserWebBean.java @@ -44,6 +44,7 @@ import org.mxchange.jphone.phonenumbers.fax.FaxNumber; import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; import org.mxchange.jphone.phonenumbers.smsprovider.SmsProvider; +import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.model.user.LoginUser; @@ -237,6 +238,33 @@ public class UserWebBean implements UserWebController { } } + @Override + public void afterUserLogin (final @Observes UserLoggedInEvent event) { + // Trace message + System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N + + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUser() == null) { + // Throw NPE again + throw new NullPointerException("event.user is null"); //NOI18N + } else if (event.getUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.user.userId is null"); //NOI18N + } else if (event.getUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUser(), event.getUser().getUserId())); //NOI18N + } + + // Re-initialize list + this.visibleUserList = this.userBean.allMemberPublicVisibleUsers(); + + // Trace message + System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N + } + @Override public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) { // Trace message diff --git a/src/java/org/mxchange/addressbook/beans/user/UserWebController.java b/src/java/org/mxchange/addressbook/beans/user/UserWebController.java index f9644e2f..e153f8d5 100644 --- a/src/java/org/mxchange/addressbook/beans/user/UserWebController.java +++ b/src/java/org/mxchange/addressbook/beans/user/UserWebController.java @@ -22,6 +22,7 @@ import java.util.List; import org.mxchange.jcontacts.contact.gender.Gender; import org.mxchange.jcountry.data.Country; import org.mxchange.jphone.phonenumbers.smsprovider.SmsProvider; +import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.model.user.User; @@ -53,6 +54,13 @@ public interface UserWebController extends Serializable { */ void afterRegistrationEvent (final UserRegisteredEvent event); + /** + * Event observer for logged-in user + *

+ * @param event Event instance + */ + void afterUserLogin (final UserLoggedInEvent event); + /** * All public user profiles *