From: Roland Häder Date: Thu, 25 Aug 2016 12:23:11 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5e17a6a5d06d29b1d595a895b1fe27758ba00251;p=pizzaservice-ejb.git Please cherry-pick: - first the user instance must become managed, then persist log entry ... - better check for Long, and not != null test (very lazy) Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java index f660c50..b6c0397 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java @@ -75,7 +75,7 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements 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/PizzaUserActivityLogMessageBean.java b/src/java/org/mxchange/jusercore/model/user/activity/PizzaUserActivityLogMessageBean.java index 1be7d32..23f5b78 100644 --- a/src/java/org/mxchange/jusercore/model/user/activity/PizzaUserActivityLogMessageBean.java +++ b/src/java/org/mxchange/jusercore/model/user/activity/PizzaUserActivityLogMessageBean.java @@ -24,6 +24,7 @@ import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.ObjectMessage; +import org.mxchange.jusercore.model.user.User; import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean; /** @@ -112,20 +113,32 @@ public class PizzaUserActivityLogMessageBean extends BasePizzaDatabaseBean imple } 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);