]> git.mxchange.org Git - jjobs-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Fri, 26 Aug 2016 14:12:07 +0000 (16:12 +0200)
committerRoland Haeder <roland@mxchange.org>
Sun, 28 Aug 2016 18:48:00 +0000 (20:48 +0200)
- introduced addUserActivityToCache() which handles adding activity log objects to "cache"

src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java

index 607ec59c38e1e272187d18145008564edabd531e..c6cc8c0b98b82c828c553c3bf37f8849c66ed6de 100644 (file)
@@ -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)
+        * <p>
+        * @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<LogableUserActivity>());
+               }
+
+               // Add activity to log
+               this.usersActivity.get(userActivity.getActivityUser()).add(userActivity);
+       }
+
 }