From: Roland Häder Date: Fri, 26 Aug 2016 14:12:07 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fc16d01dd5210bb2e4b4f9494f9542df88cb91cd;p=jjobs-war.git Please cherry-pick: - introduced addUserActivityToCache() which handles adding activity log objects to "cache" --- diff --git a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java index 607ec59c..c6cc8c0b 100644 --- a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java @@ -130,7 +130,7 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple this.userActivityBean.addUserActivityLog(userActivity); // Add to cache, too - this.usersActivity.get(user).add(userActivity); + this.addUserActivityToCache(userActivity); } @Override @@ -166,7 +166,7 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple this.userActivityBean.addUserActivityLog(userActivity); // Add to cache, too - this.usersActivity.get(user).add(userActivity); + this.addUserActivityToCache(userActivity); } @Override @@ -509,4 +509,38 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple } } + /** + * Adds given user activity instance to "cache" (local map) + *

+ * @param userActivity User activity instance + */ + private void addUserActivityToCache (final LogableUserActivity userActivity) { + // Is the instance valid + if (null == userActivity) { + // Throw NPE again + throw new NullPointerException("userActivity is null"); + } else if (userActivity.getActivityId() instanceof Long) { + // Is not null + throw new IllegalArgumentException("userActivity.activityId=" + userActivity.getActivityId() + " is not null"); + } else if (userActivity.getActivityUser() == null) { + // Throw NPE again + throw new NullPointerException("userActivity.activityUser is null"); + } else if (userActivity.getActivityUser().getUserId() == null) { + // Throw it again + throw new NullPointerException("userActivity.activityUser.userId is null"); + } else if (userActivity.getActivityUser().getUserId() < 1) { + // Invalid id number + throw new IllegalArgumentException("userActivity.activityUser.userId=" + userActivity.getActivityUser().getUserId() + " is not valid"); + } + + // Is it there? + if (!this.usersActivity.containsKey(userActivity.getActivityUser())) { + // Init it + this.usersActivity.put(userActivity.getActivityUser(), new LinkedList()); + } + + // Add activity to log + this.usersActivity.get(userActivity.getActivityUser()).add(userActivity); + } + }