*/
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;
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;
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 {
}
// 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
+ }
}
}