this.userActivityBean.addUserActivityLog(userActivity);
// Add to cache, too
- this.usersActivity.get(user).add(userActivity);
+ this.addUserActivityToCache(userActivity);
}
@Override
this.userActivityBean.addUserActivityLog(userActivity);
// Add to cache, too
- this.usersActivity.get(user).add(userActivity);
+ this.addUserActivityToCache(userActivity);
}
@Override
}
}
+ /**
+ * 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);
+ }
+
}