2 * Copyright (C) 2016 Roland Haeder<rhaeder@cho-time.de>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jjobs.beans.user.activity;
19 import java.util.LinkedHashMap;
20 import java.util.LinkedList;
21 import java.util.List;
23 import javax.annotation.PostConstruct;
24 import javax.enterprise.context.ApplicationScoped;
25 import javax.faces.view.facelets.FaceletException;
26 import javax.inject.Named;
27 import javax.naming.Context;
28 import javax.naming.InitialContext;
29 import javax.naming.NamingException;
30 import org.mxchange.jjobs.beans.BaseJobsController;
31 import org.mxchange.jusercore.model.user.User;
32 import org.mxchange.jusercore.model.user.activity.LogableUserActivity;
33 import org.mxchange.jusercore.model.user.activity.UserActivityLogSessionBeanRemote;
36 * A controller (bean) for user activity log
38 * @author Roland Haeder<rhaeder@cho-time.de>
40 @Named ("userActivityController")
42 public class JobsUserActivityWebApplicationBean extends BaseJobsController implements JobsUserActivityWebApplicationController {
47 private static final long serialVersionUID = 192_586_376_717_856_904L;
50 * EJB for user activity log
52 private UserActivityLogSessionBeanRemote userActivityBean;
55 * "Cache" for activity log per user
57 private final Map<User, List<LogableUserActivity>> usersActivity;
62 @SuppressWarnings ("CollectionWithoutInitialCapacity")
63 public JobsUserActivityWebApplicationBean () {
64 // Try to get EJB instance
66 // Get initial context
67 Context context = new InitialContext();
70 this.userActivityBean = (UserActivityLogSessionBeanRemote) context.lookup("java:global/jlandingpage-ejb/userActivity!org.mxchange.jusercore.model.user.activity.UserActivityLogSessionBeanRemote"); //NOI18N
71 } catch (final NamingException e) {
73 throw new FaceletException(e);
77 this.usersActivity = new LinkedHashMap<>();
81 * Post-constructor method
86 List<LogableUserActivity> list = this.userActivityBean.fetchAllUserActivityLog();
88 // Put all in map, per-user
89 for (final LogableUserActivity userActivity : list) {
91 if (!this.usersActivity.containsKey(userActivity.getActivityUser())) {
93 this.usersActivity.put(userActivity.getActivityUser(), new LinkedList<LogableUserActivity>());
96 // Add by user instance
97 boolean added = this.usersActivity.get(userActivity.getActivityUser()).add(userActivity);
100 assert(added) : "Activity log not added"; //NOI18N