From: Roland Häder Date: Thu, 1 Sep 2016 15:34:20 +0000 (+0200) Subject: Continued a bit: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=71077000c7d20d6bc0aa48edc4eb257b2c69f428;p=pizzaservice-ejb.git Continued a bit: - close internal TODO as the user-actiity-log can be used for this - for this making easily to work, 2 new business methods have been added - fetchAllUsersActivityLogByType() for a single type per user - fetchAllUsersActivityLogByMultipleType() for multiple types per user --- diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java index 937fea9..526edd8 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java @@ -263,7 +263,6 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements // Update user User managedUser = this.userBean.updateUserData(user); - // @TODO Create user lock history entry // Init variable Address emailAddress; diff --git a/src/java/org/mxchange/jusercore/model/user/activity/PizzaUserActivitySessionBean.java b/src/java/org/mxchange/jusercore/model/user/activity/PizzaUserActivitySessionBean.java index f977e4f..1e44846 100644 --- a/src/java/org/mxchange/jusercore/model/user/activity/PizzaUserActivitySessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/activity/PizzaUserActivitySessionBean.java @@ -17,6 +17,7 @@ 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; @@ -197,4 +198,86 @@ public class PizzaUserActivitySessionBean extends BaseDatabaseBean implements Us return list; } + @Override + @SuppressWarnings ("unchecked") + public List 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, 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 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 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 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; + } + }