From f2eb3e0393592a4aea90ae7579ed91aeeffc754d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 25 Aug 2016 09:42:26 +0200 Subject: [PATCH] Please cherry-pick: - rewrote list to map with a list per user - initialized this map in post-construct method MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../JobsUserActivityWebApplicationBean.java | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) 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 + } } } -- 2.39.5