From a8a63f3f8971f9b0cadeba033cd7affa730f1568 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 25 Aug 2016 14:23:11 +0200 Subject: [PATCH] Please cherry-pick: - first the user instance must become managed, then persist log entry ... - better check for Long, and not != null test (very lazy) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../model/user/JobsAdminUserSessionBean.java | 2 +- .../JobsUserActivityLogMessageBean.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/java/org/mxchange/jusercore/model/user/JobsAdminUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/JobsAdminUserSessionBean.java index ee00ea1..d55610f 100644 --- a/src/java/org/mxchange/jusercore/model/user/JobsAdminUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/JobsAdminUserSessionBean.java @@ -75,7 +75,7 @@ public class JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad if (null == user) { // Abort here throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserId() != null) { + } else if (user.getUserId() instanceof Long) { // Not allowed here throw new IllegalStateException(MessageFormat.format("user.userId must be null, is: {0}", user.getUserId())); //NOI18N } diff --git a/src/java/org/mxchange/jusercore/model/user/activity/JobsUserActivityLogMessageBean.java b/src/java/org/mxchange/jusercore/model/user/activity/JobsUserActivityLogMessageBean.java index 5558717..374a6fb 100644 --- a/src/java/org/mxchange/jusercore/model/user/activity/JobsUserActivityLogMessageBean.java +++ b/src/java/org/mxchange/jusercore/model/user/activity/JobsUserActivityLogMessageBean.java @@ -25,6 +25,7 @@ import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.ObjectMessage; import org.mxchange.jjobs.database.BaseJobsDatabaseBean; +import org.mxchange.jusercore.model.user.User; /** * A message-driven bean for adding user activity log @@ -112,20 +113,32 @@ public class JobsUserActivityLogMessageBean extends BaseJobsDatabaseBean impleme } else if (userActivity.getActivityUser() == null) { // Throw NPE again throw new NullPointerException("userActivity.activityUser is null"); //NOI18N + } else if (userActivity.getActivityUser().getUserId() == null) { + // Throw NPE again + throw new NullPointerException("userActivity.activityUser.userId is null"); //NOI18N + } else if (userActivity.getActivityUser().getUserId() < 1) { + // Throw NPE again + throw new IllegalArgumentException(MessageFormat.format("userActivity.activityUser.userId={0} is not valid", userActivity.getActivityUser().getUserId())); //NOI18N } else if (userActivity.getActivityType() == null) { // Throw again ... throw new NullPointerException("userActivity.activityType is null"); //NOI18N } else if (userActivity.getActivityType().isEmpty()) { // Empty type - throw new NullPointerException("userActivity.activityType is empty"); //NOI18N + throw new IllegalArgumentException("userActivity.activityType is empty"); //NOI18N } else if ((userActivity.getActivityMessage() instanceof String) && (userActivity.getActivityMessage().isEmpty())) { // Set but empty message - throw new NullPointerException("userActivity.activityMessage is empty"); //NOI18N + throw new IllegalArgumentException("userActivity.activityMessage is empty"); //NOI18N } else if (userActivity.getActivityTimestamp() == null) { // Throw NPE again throw new NullPointerException("userActivity.activityTimestamp is null"); //NOI18N } + // Make user instance managed + User managedUser = this.getManagedUser(userActivity.getActivityUser()); + + // Set it back + userActivity.setActivityUser(managedUser); + // All fine, persist it this.getEntityManager().persist(userActivity); -- 2.39.5