From: Roland Häder Date: Thu, 25 Aug 2016 07:42:26 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f2eb3e0393592a4aea90ae7579ed91aeeffc754d;p=jjobs-war.git Please cherry-pick: - rewrote list to map with a list per user - initialized this map in post-construct method Signed-off-by: Roland Häder --- 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 55ee3f20..6a6ac6ef 100644 --- a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java @@ -16,8 +16,11 @@ */ 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 activityList; + private UserActivityLogSessionBeanRemote userActivityBean; /** - * EJB for user activity log + * "Cache" for activity log per user */ - private UserActivityLogSessionBeanRemote userActivityBean; + private final Map> 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 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()); + } + + // Add by user instance + boolean added = this.usersActivity.get(userActivity.getActivityUser()).add(userActivity); + + // Should be added + assert(added) : "Activity log not added"; //NOI18N + } } }