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=33d0bdfda3bb0ba43eecbca28953db8a283db20b;p=jjobs-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/JobsAdminUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/JobsAdminUserSessionBean.java index 4cbf2d5..315b5a7 100644 --- a/src/java/org/mxchange/jusercore/model/user/JobsAdminUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/JobsAdminUserSessionBean.java @@ -263,7 +263,6 @@ public class JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad // 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/JobsUserActivitySessionBean.java b/src/java/org/mxchange/jusercore/model/user/activity/JobsUserActivitySessionBean.java index e3cd0fe..b974ffb 100644 --- a/src/java/org/mxchange/jusercore/model/user/activity/JobsUserActivitySessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/activity/JobsUserActivitySessionBean.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; @@ -196,4 +197,86 @@ public class JobsUserActivitySessionBean extends BaseDatabaseBean implements Use 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; + } + }