]> git.mxchange.org Git - jjobs-war.git/commitdiff
Please cherry-pick: (be careful with project-specific names!)
authorRoland Häder <roland@mxchange.org>
Thu, 25 Aug 2016 10:47:06 +0000 (12:47 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 25 Aug 2016 18:35:04 +0000 (20:35 +0200)
- sorted members
- added call to EJB for adding log entry (will be quickly back as a queue does the real job)

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java
src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationController.java

index 6a6ac6ef837fdbd11c3b7443f9d3aabac84fda58..66958f2cbfdaa7472a1e31aa393ee9bb82a6d76e 100644 (file)
  */
 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
                }
        }
 
index d2e54bfcfc0e642b90f100919cd61f998cf0a1fb..a738ba9bf51d1b1b661e2efb786f57e671fdaec5 100644 (file)
 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
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminAddedUserEvent (final AdminAddedUserEvent event);
+
+       /**
+        * Event observer for linked users with existing contact data
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminLinkedUserEvent (final AdminLinkedUserEvent event);
+
+       /**
+        * Event observer for locked users
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminLockedUserEvent (final AdminLockedUserEvent event);
+
+       /**
+        * Event observer for unlocked users
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminUnlockedUserEvent (final AdminUnlockedUserEvent event);
+
+       /**
+        * Event observer for updated user data by administrator
+        * <p>
+        * @param event Event being updated
+        */
+       void afterAdminUpdatedUserDataEvent (final AdminUpdatedUserDataEvent event);
+
+       /**
+        * Event observer when user confirmed account.
+        * <p>
+        * @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).
+        * <p>
+        * @param event Event being observed
+        */
+       void afterUserUpdatedPasswordEvent (final UpdatedUserPasswordEvent event);
+
+       /**
+        * Listens to fired event when user updated personal data
+        * <p>
+        * @param event Event being fired
+        */
+       void afterUserUpdatedPersonalDataEvent (final UpdatedUserPersonalDataEvent event);
+
+       /**
+        * Event observer for new user registrations
+        * <p>
+        * @param event Event being fired
+        */
+       void afterRegistrationEvent (final UserRegisteredEvent event);
+
+       /**
+        * Event observer for logged-in user
+        * <p>
+        * @param event Event being fired
+        */
+       void afterUserLoginEvent (final UserLoggedInEvent event);
+
+       /**
+        * Event observer for users resending their confirmation link
+        * <p>
+        * @param event Event being fired
+        */
+       void afterUserResendConfirmationLinkEvent (final UserResendLinkAccountEvent event);
+
+       /**
+        * Adds user activity entry with given type
+        * <p>
+        * @param user User instance
+        * @param activityType Activity type
+        */
+       void addUserActivity (final User user, final String activityType);
+
+       /**
+        * Adds user activity log with type and message
+        * <p>
+        * @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
+        * <p>
+        * @return List of user's activity log
+        */
+       List<LogableUserActivity> allCurrentUsersActivityLog();
+
 }