From 2f5ecf4e0064ecfc4dd38562ce3cc3dc152f6c0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 25 Aug 2016 12:47:06 +0200 Subject: [PATCH] Please cherry-pick: (be careful with project-specific names!) - sorted members - added call to EJB for adding log entry (will be quickly back as a queue does the real job) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../JobsUserActivityWebApplicationBean.java | 286 +++++++++++++++++- ...sUserActivityWebApplicationController.java | 115 +++++++ 2 files changed, 400 insertions(+), 1 deletion(-) diff --git a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java index 6a6ac6ef..66958f2c 100644 --- a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java @@ -16,20 +16,34 @@ */ package org.mxchange.jjobs.beans.user.activity; +import java.text.MessageFormat; +import java.util.GregorianCalendar; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import javax.annotation.PostConstruct; import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; import javax.faces.view.facelets.FaceletException; import javax.inject.Named; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jjobs.beans.BaseJobsController; +import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent; +import org.mxchange.jusercore.events.login.UserLoggedInEvent; +import org.mxchange.jusercore.events.registration.UserRegisteredEvent; +import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; +import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent; +import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent; +import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent; +import org.mxchange.jusercore.events.user.unlocked.AdminUnlockedUserEvent; +import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent; +import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.activity.LogableUserActivity; +import org.mxchange.jusercore.model.user.activity.UserActivityLog; import org.mxchange.jusercore.model.user.activity.UserActivityLogSessionBeanRemote; /** @@ -77,6 +91,276 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple this.usersActivity = new LinkedHashMap<>(); } + @Override + public void addUserActivity (final User user, final String activityType) { + // Better re-validate + if (null == user) { + // Throw NPE + throw new NullPointerException("user is null"); //NOI18N + } else if (user.getUserId() == null) { + // Throw again + throw new NullPointerException("user.userId is null"); //NOI18N + } else if (user.getUserId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N + } else if (null == activityType) { + // Throw NPE again + throw new NullPointerException("activityType is null"); //NOI18N + } else if (activityType.isEmpty()) { + // Is empty + throw new IllegalArgumentException("activityType is empty"); //NOI18N + } + + // Create new activity object + LogableUserActivity userActivity = new UserActivityLog(activityType, user, new GregorianCalendar()); + + // Call bean to add it + this.userActivityBean.addUserActivityLog(userActivity); + } + + @Override + public void addUserActivity (final User user, final String activityType, final String message) { + // Better re-validate + if (null == user) { + // Throw NPE + throw new NullPointerException("user is null"); //NOI18N + } else if (user.getUserId() == null) { + // Throw again + throw new NullPointerException("user.userId is null"); //NOI18N + } else if (user.getUserId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N + } else if (null == activityType) { + // Throw NPE again + throw new NullPointerException("activityType is null"); //NOI18N + } else if (activityType.isEmpty()) { + // Is empty + throw new IllegalArgumentException("activityType is empty"); //NOI18N + } else if (null == message) { + // Throw NPE again + throw new NullPointerException("message is null"); //NOI18N + } else if (message.isEmpty()) { + // Is empty + throw new IllegalArgumentException("message is empty"); //NOI18N + } + + // Create new activity object + LogableUserActivity userActivity = new UserActivityLog(message, activityType, user, new GregorianCalendar()); + + // Call bean to add it + this.userActivityBean.addUserActivityLog(userActivity); + } + + @Override + public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.addedUser is null"); //NOI18N + } else if (event.getAddedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.addedUser.userId is null"); //NOI18N + } else if (event.getAddedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N + } + + // Update user list + this.addUserActivity(event.getAddedUser(), "ADMIN_ADDED_USER_ACCOUNT"); //NOI18N + } + + @Override + public void afterAdminLinkedUserEvent (@Observes final AdminLinkedUserEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getLinkedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.linkedUser is null"); //NOI18N + } else if (event.getLinkedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.linkedUser.userId is null"); //NOI18N + } else if (event.getLinkedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N + } + + // Update user list + this.addUserActivity(event.getLinkedUser(), "ADMIN_LINKED_USER_ACCOUNT"); //NOI18N + } + + @Override + public void afterAdminLockedUserEvent (@Observes final AdminLockedUserEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getLockedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.lockedUser is null"); //NOI18N + } else if (event.getLockedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.lockedUser.userId is null"); //NOI18N + } else if (event.getLockedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLockedUser(), event.getLockedUser().getUserId())); //NOI18N + } + + // Update user list + this.addUserActivity(event.getLockedUser(), "ADMIN_LOCKED_USER_ACCOUNT", event.getLockedUser().getUserLastLockedReason()); //NOI18N + } + + @Override + public void afterAdminUnlockedUserEvent (@Observes final AdminUnlockedUserEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUnlockedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.unlockedUser is null"); //NOI18N + } else if (event.getUnlockedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.unlockedUser.userId is null"); //NOI18N + } else if (event.getUnlockedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUnlockedUser(), event.getUnlockedUser().getUserId())); //NOI18N + } + + // Update user list + this.addUserActivity(event.getUnlockedUser(), "ADMIN_UNLOCKED_USER_ACCOUNT"); //NOI18N + } + + @Override + public void afterAdminUpdatedUserDataEvent (@Observes final AdminUpdatedUserDataEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.updatedUser is null"); //NOI18N + } else if (event.getUpdatedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N + } else if (event.getUpdatedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N + } + + // Update user list + this.addUserActivity(event.getUpdatedUser(), "ADMIN_UPDATED_USER_PERSONAL_DATA"); //NOI18N + } + + @Override + public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getRegisteredUser() == null) { + // Throw NPE again + throw new NullPointerException("event.registeredUser is null"); //NOI18N + } else if (event.getRegisteredUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N + } else if (event.getRegisteredUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N + } + + // Update user list + this.addUserActivity(event.getRegisteredUser(), "USER_REGISTERED_NEW_ACCOUNT"); //NOI18N + } + + @Override + public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getConfirmedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.confirmedUser is null"); //NOI18N + } else if (event.getConfirmedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N + } else if (event.getConfirmedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N + } + + // Update user list + this.addUserActivity(event.getConfirmedUser(), "USER_CONFIRMED_ACCOUNT"); //NOI18N + } + + @Override + public void afterUserLogin (@Observes final UserLoggedInEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getLoggedInUser() == null) { + // Throw NPE again + throw new NullPointerException("event.registeredUser is null"); //NOI18N + } else if (event.getLoggedInUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N + } else if (event.getLoggedInUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N + } + + // Copy all data to this bean + this.addUserActivity(event.getLoggedInUser(), "USER_LOGGED_IN"); //NOI18N + } + + @Override + public void afterUserUpdatedPasswordEvent (@Observes final UpdatedUserPasswordEvent event) { + // Check parameter + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getPasswordHistory() == null) { + // Throw NPE again + throw new NullPointerException("event.passwordHistory is null"); //NOI18N + } else if (event.getPasswordHistory().getUserPasswordHistoryId() == null) { + // ... and again + throw new NullPointerException("event.passwordHistory.userPasswordHistoryId is null"); //NOI18N + } else if (event.getPasswordHistory().getUserPasswordHistoryId() < 1) { + // Invalid value + throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N + } + + // Update user list + this.addUserActivity(event.getPasswordHistory().getUserPasswordHistoryUser(), "USER_UPDATED_PASSWORD"); //NOI18N + } + + @Override + public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) { + // Check parameter + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.updatedUser is null"); //NOI18N + } else if (event.getUpdatedUser().getUserId() == null) { + // ... and again + throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N + } else if (event.getUpdatedUser().getUserId() < 1) { + // Invalid value + throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N + } + + // Update user list + this.addUserActivity(event.getUpdatedUser(), "USER_UPDATED_PERSONAL_DATA"); //NOI18N + } + /** * Post-constructor method */ @@ -97,7 +381,7 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple boolean added = this.usersActivity.get(userActivity.getActivityUser()).add(userActivity); // Should be added - assert(added) : "Activity log not added"; //NOI18N + assert (added) : "Activity log not added"; //NOI18N } } diff --git a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationController.java b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationController.java index d2e54bfc..a738ba9b 100644 --- a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationController.java +++ b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationController.java @@ -17,7 +17,20 @@ package org.mxchange.jjobs.beans.user.activity; import java.io.Serializable; +import java.util.List; import javax.ejb.Local; +import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent; +import org.mxchange.jusercore.events.login.UserLoggedInEvent; +import org.mxchange.jusercore.events.registration.UserRegisteredEvent; +import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; +import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent; +import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent; +import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent; +import org.mxchange.jusercore.events.user.unlocked.AdminUnlockedUserEvent; +import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent; +import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent; +import org.mxchange.jusercore.model.user.User; +import org.mxchange.jusercore.model.user.activity.LogableUserActivity; /** * A controller (bean) interface for user activity log @@ -27,4 +40,106 @@ import javax.ejb.Local; @Local public interface JobsUserActivityWebApplicationController extends Serializable { + /** + * Event observer for newly added users by adminstrator + *

+ * @param event Event being fired + */ + void afterAdminAddedUserEvent (final AdminAddedUserEvent event); + + /** + * Event observer for linked users with existing contact data + *

+ * @param event Event being fired + */ + void afterAdminLinkedUserEvent (final AdminLinkedUserEvent event); + + /** + * Event observer for locked users + *

+ * @param event Event being fired + */ + void afterAdminLockedUserEvent (final AdminLockedUserEvent event); + + /** + * Event observer for unlocked users + *

+ * @param event Event being fired + */ + void afterAdminUnlockedUserEvent (final AdminUnlockedUserEvent event); + + /** + * Event observer for updated user data by administrator + *

+ * @param event Event being updated + */ + void afterAdminUpdatedUserDataEvent (final AdminUpdatedUserDataEvent event); + + /** + * Event observer when user confirmed account. + *

+ * @param event Event being fired + */ + void afterUserConfirmedAccountEvent (final UserConfirmedAccountEvent event); + + /** + * Method being call after user's password has been updated (and history + * entry has been created). + *

+ * @param event Event being observed + */ + void afterUserUpdatedPasswordEvent (final UpdatedUserPasswordEvent event); + + /** + * Listens to fired event when user updated personal data + *

+ * @param event Event being fired + */ + void afterUserUpdatedPersonalDataEvent (final UpdatedUserPersonalDataEvent event); + + /** + * Event observer for new user registrations + *

+ * @param event Event being fired + */ + void afterRegistrationEvent (final UserRegisteredEvent event); + + /** + * Event observer for logged-in user + *

+ * @param event Event being fired + */ + void afterUserLoginEvent (final UserLoggedInEvent event); + + /** + * Event observer for users resending their confirmation link + *

+ * @param event Event being fired + */ + void afterUserResendConfirmationLinkEvent (final UserResendLinkAccountEvent event); + + /** + * Adds user activity entry with given type + *

+ * @param user User instance + * @param activityType Activity type + */ + void addUserActivity (final User user, final String activityType); + + /** + * Adds user activity log with type and message + *

+ * @param user User instance + * @param activityType Activity type + * @param message Activity message + */ + void addUserActivity (final User user, final String activityType, final String message); + + /** + * Returns a list of in beanHelper set user instance's activity log + *

+ * @return List of user's activity log + */ + List allCurrentUsersActivityLog(); + } -- 2.39.5