]> git.mxchange.org Git - jjobs-ejb.git/blob - src/java/org/mxchange/jusercore/model/user/activity/JobsUserActivityLogMessageBean.java
Don't cherry-pick:
[jjobs-ejb.git] / src / java / org / mxchange / jusercore / model / user / activity / JobsUserActivityLogMessageBean.java
1 /*
2  * Copyright (C) 2017, 2018 Free Software Foundation
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jusercore.model.user.activity;
18
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;
28
29 /**
30  * A stateless, session-scoped EJB for user-activity
31  * <p>
32  * @author Roland Häder<roland@mxchange.org>
33  */
34 @Stateless (name = "userActivity", description = "A stateless, session-scored user-activity bean.")
35 public class JobsUserActivityLogMessageBean extends BaseJobsEnterpriseBean implements UserActivityLogSessionBeanRemote {
36
37         /**
38          * Serial number
39          */
40         private static final long serialVersionUID = 1_268_376_401_659L;
41
42         /**
43          * Default constructor
44          */
45         public JobsUserActivityLogMessageBean () {
46                 // Invoke super constructor
47                 super("jms/jjobs-queue-factory", "jms/jjobs-user-activity-log"); //NOI18N
48         }
49
50         @Override
51         public void addUserActivityLog (final LogableUserActivity userActivity) {
52                 // Trace message
53                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUserActivityLog: userActivity={1} - CALLED!", this.getClass().getSimpleName(), userActivity)); //NOI18N
54
55                 // Validate parameter
56                 if (null == userActivity) {
57                         // Throw NPE
58                         throw new NullPointerException("userActivity is null"); //NOI18N
59                 } else if (userActivity.getActivityContactFamilyName() == null) {
60                         // Throw it again
61                         throw new NullPointerException("userActivity.activityContactFamilyName is null"); //NOI18N
62                 } else if (userActivity.getActivityContactFamilyName().isEmpty()) {
63                         // Throw IAE
64                         throw new IllegalArgumentException("userActivity.activityContactFamilyName is empty"); //NOI18N
65                 } else if (userActivity.getActivityContactFirstName() == null) {
66                         // Throw NPE
67                         throw new NullPointerException("userActivity.activityContactFirstName is null"); //NOI18N
68                 } else if (userActivity.getActivityContactFirstName().isEmpty()) {
69                         // Throw IAE
70                         throw new IllegalArgumentException("userActivity.activityContactFirstName is empty"); //NOI18N
71                 } else if (userActivity.getActivityContactPersonalTitle() == null) {
72                         // Throw NPE
73                         throw new NullPointerException("userActivity.activityContactPersonalTitle is null"); //NOI18N
74                 } else if ((userActivity.getActivityMessage() != null) && (userActivity.getActivityMessage().isEmpty())) {
75                         // Throw IAE
76                         throw new IllegalArgumentException("userActivity.activityMessage is empty"); //NOI18N
77                 } else if (userActivity.getActivityType() == null) {
78                         // Throw NPE
79                         throw new NullPointerException("userActivity.activityType is null"); //NOI18N
80                 } else if (userActivity.getActivityType().isEmpty()) {
81                         // Throw IAE
82                         throw new IllegalArgumentException("userActivity.activityType is empty"); //NOI18N
83                 } else if (userActivity.getActivityUserName() == null) {
84                         // Throw NPE
85                         throw new NullPointerException("userActivity.activityUserName is null"); //NOI18N
86                 } else if (userActivity.getActivityUserName().isEmpty()) {
87                         // Throw IAE
88                         throw new IllegalArgumentException("userActivity.activityUserName is empty"); //NOI18N
89                 } else if (userActivity.getActivityId() != null) {
90                         // Throw it again
91                         throw new IllegalArgumentException("userActivity.activityId should never be set."); //NOI18N
92                 }
93
94                 try {
95                         // Send out email change
96                         final ObjectMessage message = this.getSession().createObjectMessage();
97                         message.setObject(userActivity);
98
99                         // Send message
100                         this.sendMessage(message);
101                 } catch (final JMSException ex) {
102                         // Throw again
103                         throw new EJBException(ex);
104                 }
105
106                 // Trace message
107                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUserActivityLog: EXIT!", this.getClass().getSimpleName())); //NOI18N
108         }
109
110         @Override
111         @SuppressWarnings ("unchecked")
112         public List<LogableUserActivity> fetchAllUserActivityLog () {
113                 // Trace message
114                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUserActivityLog: CALLED!", this.getClass().getSimpleName())); //NOI18N
115
116                 // Get named query
117                 final Query query = this.getEntityManager().createNamedQuery("AllUserActivityLog"); //NOI18N
118
119                 // Get list from it
120                 List<LogableUserActivity> list = query.getResultList();
121
122                 // Trace message
123                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUserActivityLog: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
124
125                 // Return it
126                 return list;
127         }
128
129         @Override
130         @SuppressWarnings ("unchecked")
131         public List<LogableUserActivity> fetchAllUsersActivityLog (final User user) {
132                 // Trace message
133                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLog: CALLED!", this.getClass().getSimpleName())); //NOI18N
134
135                 // Validate parameters
136                 if (null == user) {
137                         // Abort here
138                         throw new NullPointerException("user is null"); //NOI18N
139                 } else if (user.getUserId() == null) {
140                         // Id is set
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
145                 }
146
147                 // Get named query
148                 final Query query = this.getEntityManager().createNamedQuery("SearchAllUsersActivity"); //NOI18N
149
150                 // Set parameter
151                 query.setParameter("activityUser", user); //NOI18N
152
153                 // Get list from it
154                 List<LogableUserActivity> list = query.getResultList();
155
156                 // Trace message
157                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLog: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
158
159                 // Return it
160                 return list;
161         }
162
163 }