2 * Copyright (C) 2017, 2018 Free Software Foundation
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.jusercore.model.user.activity;
19 import java.text.MessageFormat;
20 import java.util.List;
21 import javax.ejb.EJBException;
22 import javax.ejb.Stateless;
23 import javax.jms.JMSException;
24 import javax.jms.ObjectMessage;
25 import javax.persistence.Query;
26 import org.mxchange.jjobs.beans.ejb.BaseJobsEnterpriseBean;
27 import org.mxchange.jusercore.model.user.User;
30 * A stateless, session-scoped EJB for user-activity
32 * @author Roland Häder<roland@mxchange.org>
34 @Stateless (name = "userActivity", description = "A stateless, session-scored user-activity bean.")
35 public class JobsUserActivityLogMessageBean extends BaseJobsEnterpriseBean implements UserActivityLogSessionBeanRemote {
40 private static final long serialVersionUID = 1_268_376_401_659L;
45 public JobsUserActivityLogMessageBean () {
46 // Invoke super constructor
47 super("jms/jjobs-queue-factory", "jms/jjobs-user-activity-log"); //NOI18N
51 public void addUserActivityLog (final LogableUserActivity userActivity) {
53 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUserActivityLog: userActivity={1} - CALLED!", this.getClass().getSimpleName(), userActivity)); //NOI18N
56 if (null == userActivity) {
58 throw new NullPointerException("userActivity is null"); //NOI18N
59 } else if (userActivity.getActivityContactFamilyName() == null) {
61 throw new NullPointerException("userActivity.activityContactFamilyName is null"); //NOI18N
62 } else if (userActivity.getActivityContactFamilyName().isEmpty()) {
64 throw new IllegalArgumentException("userActivity.activityContactFamilyName is empty"); //NOI18N
65 } else if (userActivity.getActivityContactFirstName() == null) {
67 throw new NullPointerException("userActivity.activityContactFirstName is null"); //NOI18N
68 } else if (userActivity.getActivityContactFirstName().isEmpty()) {
70 throw new IllegalArgumentException("userActivity.activityContactFirstName is empty"); //NOI18N
71 } else if (userActivity.getActivityContactPersonalTitle() == null) {
73 throw new NullPointerException("userActivity.activityContactPersonalTitle is null"); //NOI18N
74 } else if ((userActivity.getActivityMessage() != null) && (userActivity.getActivityMessage().isEmpty())) {
76 throw new IllegalArgumentException("userActivity.activityMessage is empty"); //NOI18N
77 } else if (userActivity.getActivityType() == null) {
79 throw new NullPointerException("userActivity.activityType is null"); //NOI18N
80 } else if (userActivity.getActivityType().isEmpty()) {
82 throw new IllegalArgumentException("userActivity.activityType is empty"); //NOI18N
83 } else if (userActivity.getActivityUserName() == null) {
85 throw new NullPointerException("userActivity.activityUserName is null"); //NOI18N
86 } else if (userActivity.getActivityUserName().isEmpty()) {
88 throw new IllegalArgumentException("userActivity.activityUserName is empty"); //NOI18N
89 } else if (userActivity.getActivityId() != null) {
91 throw new IllegalArgumentException("userActivity.activityId should never be set."); //NOI18N
95 // Send out email change
96 final ObjectMessage message = this.getSession().createObjectMessage();
97 message.setObject(userActivity);
100 this.sendMessage(message);
101 } catch (final JMSException ex) {
103 throw new EJBException(ex);
107 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUserActivityLog: EXIT!", this.getClass().getSimpleName())); //NOI18N
111 @SuppressWarnings ("unchecked")
112 public List<LogableUserActivity> fetchAllUserActivityLog () {
114 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUserActivityLog: CALLED!", this.getClass().getSimpleName())); //NOI18N
117 final Query query = this.getEntityManager().createNamedQuery("AllUserActivityLog"); //NOI18N
120 List<LogableUserActivity> list = query.getResultList();
123 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUserActivityLog: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
130 @SuppressWarnings ("unchecked")
131 public List<LogableUserActivity> fetchAllUsersActivityLog (final User user) {
133 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLog: CALLED!", this.getClass().getSimpleName())); //NOI18N
135 // Validate parameters
138 throw new NullPointerException("user is null"); //NOI18N
139 } else if (user.getUserId() == null) {
141 throw new NullPointerException("user.userId is null"); //NOI18N
142 } else if (user.getUserId() < 1) {
143 // Not valid id number
144 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
148 final Query query = this.getEntityManager().createNamedQuery("SearchAllUsersActivity"); //NOI18N
151 query.setParameter("activityUser", user); //NOI18N
154 List<LogableUserActivity> list = query.getResultList();
157 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLog: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N