]> git.mxchange.org Git - jjobs-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Thu, 25 Aug 2016 07:42:26 +0000 (09:42 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 25 Aug 2016 18:33:05 +0000 (20:33 +0200)
- rewrote list to map with a list per user
- initialized this map in post-construct method

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

index 55ee3f20830543e2d0a7f2b7894ada04349323eb..6a6ac6ef837fdbd11c3b7443f9d3aabac84fda58 100644 (file)
  */
 package org.mxchange.jjobs.beans.user.activity;
 
+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.faces.view.facelets.FaceletException;
 import javax.inject.Named;
@@ -25,6 +28,7 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.jjobs.beans.BaseJobsController;
+import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.activity.LogableUserActivity;
 import org.mxchange.jusercore.model.user.activity.UserActivityLogSessionBeanRemote;
 
@@ -43,18 +47,19 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple
        private static final long serialVersionUID = 192_586_376_717_856_904L;
 
        /**
-        * "Cache" for activity log per user
+        * EJB for user activity log
         */
-       private final List<LogableUserActivity> activityList;
+       private UserActivityLogSessionBeanRemote userActivityBean;
 
        /**
-        * EJB for user activity log
+        * "Cache" for activity log per user
         */
-       private UserActivityLogSessionBeanRemote userActivityBean;
+       private final Map<User, List<LogableUserActivity>> usersActivity;
 
        /**
         * Default constructor
         */
+       @SuppressWarnings ("CollectionWithoutInitialCapacity")
        public JobsUserActivityWebApplicationBean () {
                // Try to get EJB instance
                try {
@@ -69,7 +74,31 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple
                }
 
                // Init cache
-               this.activityList = new LinkedList<>();
+               this.usersActivity = new LinkedHashMap<>();
+       }
+
+       /**
+        * Post-constructor method
+        */
+       @PostConstruct
+       public void init () {
+               // Get whole list
+               List<LogableUserActivity> list = this.userActivityBean.fetchAllUserActivityLog();
+
+               // Put all in map, per-user
+               for (final LogableUserActivity userActivity : list) {
+                       // Is the list there?
+                       if (!this.usersActivity.containsKey(userActivity.getActivityUser())) {
+                               // Init list
+                               this.usersActivity.put(userActivity.getActivityUser(), new LinkedList<LogableUserActivity>());
+                       }
+
+                       // Add by user instance
+                       boolean added = this.usersActivity.get(userActivity.getActivityUser()).add(userActivity);
+
+                       // Should be added
+                       assert(added) : "Activity log not added"; //NOI18N
+               }
        }
 
 }