/*
- * Copyright (C) 2016 - 2018 Free Software Foundation
+ * Copyright (C) 2017, 2018 Free Software Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
package org.mxchange.jusercore.model.user.activity;
import java.text.MessageFormat;
-import java.util.Arrays;
import java.util.List;
import javax.ejb.EJBException;
import javax.ejb.Stateless;
import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.persistence.Query;
-import org.mxchange.jcoreee.database.BaseEnterpriseBean;
+import org.mxchange.jcoreee.enterprise.BaseEnterpriseBean;
import org.mxchange.jusercore.model.user.User;
/**
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-@Stateless (name = "userActivity", description = "A bean handling the user data")
-public class PizzaUserActivitySessionBean extends BaseEnterpriseBean implements UserActivityLogSessionBeanRemote {
+@Stateless (name = "userActivity", description = "A stateless, session-scored user-activity bean.")
+public class PizzaUserActivitySessionBean extends BaseEnterpiseBean implements UserActivityLogSessionBeanRemote {
/**
* Serial number
*/
- private static final long serialVersionUID = 219_568_677_671_054L;
+ private static final long serialVersionUID = 1_268_376_401_659L;
/**
* Default constructor
*/
public PizzaUserActivitySessionBean () {
- // Call super constructor
- super("jms/pizzaservice-queue-factory", "jms/pizzaservice-user-activity-log"); //NOI18N
+ // Invoke super constructor
+ super("jms/pizzaapplication-queue-factory", "jms/pizzaapplication-user-activity-log"); //NOI18N
}
@Override
public void addUserActivityLog (final LogableUserActivity userActivity) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUserActivityLog: userActivity={1} CALLED!", this.getClass().getSimpleName(), userActivity)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUserActivityLog: userActivity={1} - CALLED!", this.getClass().getSimpleName(), userActivity)); //NOI18N
- // Should be valid
+ // Validate parameter
if (null == userActivity) {
// Throw NPE
throw new NullPointerException("userActivity is null"); //NOI18N
// Id number should not be set
throw new IllegalArgumentException(MessageFormat.format("userActivity.activityId={0} should be null", userActivity.getActivityId())); //NOI18N
} else if (userActivity.getActivityUser() == null) {
- // Throw NPE again
+` // Throw NPE again
throw new NullPointerException("userActivity.activityUser is null"); //NOI18N
+ } else if (userActivity.getActivityContactFamilyName() == null) {
+ // Throw it again
+ throw new NullPointerException("userActivity.activityContactFamilyName is null"); //NOI18N
+ } else if (userActivity.getActivityContactFamilyName().isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("userActivity.activityContactFamilyName is empty"); //NOI18N
+ } else if (userActivity.getActivityContactFirstName() == null) {
+ // Throw NPE
+ throw new NullPointerException("userActivity.activityContactFirstName is null"); //NOI18N
+ } else if (userActivity.getActivityContactFirstName().isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("userActivity.activityContactFirstName is empty"); //NOI18N
+ } else if (userActivity.getActivityContactPersonalTitle() == null) {
+ // Throw NPE
+ throw new NullPointerException("userActivity.activityContactPersonalTitle is null"); //NOI18N
+ } else if ((userActivity.getActivityMessage() != null) && (userActivity.getActivityMessage().isEmpty())) {
+ // Throw IAE
+ throw new IllegalArgumentException("userActivity.activityMessage is empty"); //NOI18N
} else if (userActivity.getActivityType() == null) {
- // Throw again ...
+ // Throw NPE
throw new NullPointerException("userActivity.activityType is null"); //NOI18N
} else if (userActivity.getActivityType().isEmpty()) {
- // Empty type
- throw new NullPointerException("userActivity.activityType is empty"); //NOI18N
- } else if ((userActivity.getActivityMessage() instanceof String) && (userActivity.getActivityMessage().isEmpty())) {
- // Set but empty message
- throw new NullPointerException("userActivity.activityMessage is empty"); //NOI18N
- } else if (userActivity.getActivityTimestamp() == null) {
- // Throw NPE again
- throw new NullPointerException("userActivity.activityTimestamp is null"); //NOI18N
+ // Throw IAE
+ throw new IllegalArgumentException("userActivity.activityType is empty"); //NOI18N
+ } else if (userActivity.getActivityUserName() == null) {
+ // Throw NPE
+ throw new NullPointerException("userActivity.activityUserName is null"); //NOI18N
+ } else if (userActivity.getActivityUserName().isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("userActivity.activityUserName is empty"); //NOI18N
+ } else if (userActivity.getActivityId() != null) {
+ // Throw it again
+ throw new IllegalArgumentException("userActivity.activityId should never be set."); //NOI18N
}
try {
// Send out email change
- ObjectMessage message = this.getSession().createObjectMessage();
+ final ObjectMessage message = this.getSession().createObjectMessage();
message.setObject(userActivity);
// Send message
// Throw again
throw new EJBException(ex);
}
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUserActivityLog: EXIT!", this.getClass().getSimpleName())); //NOI18N
}
@Override
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUserActivityLog: CALLED!", this.getClass().getSimpleName())); //NOI18N
- // Search for user's activity
- Query query = this.getEntityManager().createNamedQuery("AllUserActivityLog", UserActivityLog.class); //NOI18N
+ // Get named query
+ final Query query = this.getEntityManager().createNamedQuery("AllUserActivityLog"); //NOI18N
- // Get list
+ // Get list from it
List<LogableUserActivity> list = query.getResultList();
// Trace message
@SuppressWarnings ("unchecked")
public List<LogableUserActivity> fetchAllUsersActivityLog (final User user) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLog: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLog: CALLED!", this.getClass().getSimpleName())); //NOI18N
- // Is user valid?
+ // Validate parameters
if (null == user) {
// Throw NPE
throw new NullPointerException("user is null"); //NOI18N
// Throw again
throw new NullPointerException("user.userId is null"); //NOI18N
} else if (user.getUserId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("user.userId{0} is not valid", user.getUserId())); //NOI18N
+ // Not valid id number
+ throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
}
- // Search for user's activity
- Query query = this.getEntityManager().createNamedQuery("FindAllUsersActivity", UserActivityLog.class); //NOI18N
+ // Get named query
+ final Query query = this.getEntityManager().createNamedQuery("SearchAllUsersActivity"); //NOI18N
// Set parameter
query.setParameter("activityUser", user); //NOI18N
- // Get list
+ // Get list from it
List<LogableUserActivity> list = query.getResultList();
// Trace message
return list;
}
- @Override
- @SuppressWarnings ("unchecked")
- public List<LogableUserActivity> fetchAllUsersActivityLogByMultipleType (final User user, final String[] activityTypes) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLogByType: user={1},activityTypes={2} - CALLED!", this.getClass().getSimpleName(), user, Arrays.toString(activityTypes))); //NOI18N
-
- // Is user valid?
- if (null == user) {
- // Throw NPE
- throw new NullPointerException("user is null"); //NOI18N
- } else if (user.getUserId() == null) {
- // Throw again
- throw new NullPointerException("user.userId is null"); //NOI18N
- } else if (user.getUserId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("user.userId{0} is not valid", user.getUserId())); //NOI18N
- } else if (null == activityTypes) {
- // Throw NPE again
- throw new NullPointerException("activityTypes is null"); //NOI18N
- } else if (activityTypes.length == 0) {
- // Should not be empty
- throw new IllegalArgumentException("activityTypes is empty"); //NOI18N
- }
-
- // Search for user's activity
- Query query = this.getEntityManager().createNamedQuery("FindUsersActivityByMultipleTypes", UserActivityLog.class); //NOI18N
-
- // Set parameters
- query.setParameter("activityUser", user); //NOI18N
- query.setParameter("activityTypes", Arrays.asList(activityTypes)); //NOI18N
-
- // Get list
- List<LogableUserActivity> list = query.getResultList();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLogByType: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
-
- // Return it
- return list;
- }
-
- @Override
- @SuppressWarnings ("unchecked")
- public List<LogableUserActivity> fetchAllUsersActivityLogByType (final User user, final String activityType) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLogByType: user={1},activityType={2} - CALLED!", this.getClass().getSimpleName(), user, activityType)); //NOI18N
-
- // Is user valid?
- if (null == user) {
- // Throw NPE
- throw new NullPointerException("user is null"); //NOI18N
- } else if (user.getUserId() == null) {
- // Throw again
- throw new NullPointerException("user.userId is null"); //NOI18N
- } else if (user.getUserId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("user.userId{0} is not valid", user.getUserId())); //NOI18N
- } else if (null == activityType) {
- // Throw NPE again
- throw new NullPointerException("activityType is null"); //NOI18N
- } else if (activityType.isEmpty()) {
- // Should not be empty
- throw new IllegalArgumentException("activityType is empty"); //NOI18N
- }
-
- // Search for user's activity
- Query query = this.getEntityManager().createNamedQuery("FindUsersActivityByType", UserActivityLog.class); //NOI18N
-
- // Set parameters
- query.setParameter("activityUser", user); //NOI18N
- query.setParameter("activityType", activityType); //NOI18N
-
- // Get list
- List<LogableUserActivity> list = query.getResultList();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLogByType: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
-
- // Return it
- return list;
- }
-
}