2 * Copyright (C) 2016 Cho-Time GmbH
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.io.Serializable;
20 import java.text.MessageFormat;
21 import javax.ejb.ActivationConfigProperty;
22 import javax.ejb.MessageDriven;
23 import javax.jms.JMSException;
24 import javax.jms.Message;
25 import javax.jms.MessageListener;
26 import javax.jms.ObjectMessage;
27 import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
30 * A message-driven bean for adding user activity log
32 * @author Roland Haeder<rhaeder@cho-time.de>
35 name = "userActivityLog",
36 description = "A message-driven bean for adding user activity log",
38 @ActivationConfigProperty (
39 propertyName = "destinationLookup",
40 propertyValue = "jms/jlanding-user-activity-log"
42 @ActivationConfigProperty (
43 propertyName = "destinationType",
44 propertyValue = "javax.jms.Queue"
48 public class JobsUserActivityLogMessageBean extends BaseJobsDatabaseBean implements MessageListener {
53 private static final long serialVersionUID = 14_920_686_785_732_054L;
58 public JobsUserActivityLogMessageBean () {
62 public void onMessage (final Message message) {
64 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage: message={1} - CALLED!", this.getClass().getSimpleName(), message)); //NOI18N
66 // The parameter should be valid
67 if (null == message) {
69 throw new NullPointerException("message is null"); //NOI18N
70 } else if (!(message instanceof ObjectMessage)) {
71 // Not implementing right interface
72 throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N
76 ObjectMessage objectMessage = (ObjectMessage) message;
79 Serializable serializable;
82 // Get object from message
83 serializable = objectMessage.getObject();
84 } catch (final JMSException ex) {
85 // Log it and don't continue any further
86 this.getLoggerBeanLocal().logException(ex);
91 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.onMessage: serializable={1}", this.getClass().getSimpleName(), serializable)); //NOI18N
93 // Okay, is it the right interface?
94 if (null == serializable) {
96 throw new NullPointerException("serializable is null"); //NOI18N
97 } else if (!(serializable instanceof LogableUserActivity)) {
98 // Not correct object send
99 throw new IllegalArgumentException(MessageFormat.format("serializable={0} does not implement LogableUserActivity", serializable)); //NOI18N
103 LogableUserActivity userActivity = (LogableUserActivity) serializable;
106 if (null == userActivity) {
108 throw new NullPointerException("userActivity is null"); //NOI18N
109 } else if (userActivity.getActivityId() instanceof Long) {
110 // Id number should not be set
111 throw new IllegalArgumentException(MessageFormat.format("userActivity.activityId={0} should be null", userActivity.getActivityId())); //NOI18N
112 } else if (userActivity.getActivityUser() == null) {
114 throw new NullPointerException("userActivity.activityUser is null"); //NOI18N
115 } else if (userActivity.getActivityType() == null) {
117 throw new NullPointerException("userActivity.activityType is null"); //NOI18N
118 } else if (userActivity.getActivityType().isEmpty()) {
120 throw new NullPointerException("userActivity.activityType is empty"); //NOI18N
121 } else if ((userActivity.getActivityMessage() instanceof String) && (userActivity.getActivityMessage().isEmpty())) {
122 // Set but empty message
123 throw new NullPointerException("userActivity.activityMessage is empty"); //NOI18N
124 } else if (userActivity.getActivityTimestamp() == null) {
126 throw new NullPointerException("userActivity.activityTimestamp is null"); //NOI18N
129 // All fine, persist it
130 this.getEntityManager().persist(userActivity);
133 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage: EXIT!", this.getClass().getSimpleName())); //NOI18N