/*
- * Copyright (C) 2016 Cho-Time GmbH
+ * Copyright (C) 2016, 2017 Roland Häder
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
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
* <p>
- * @author Roland Haeder<rhaeder@cho-time.de>
+ * @author Roland Häder<roland@mxchange.org>
*/
@MessageDriven (
name = "userActivityLog",
activationConfig = {
@ActivationConfigProperty (
propertyName = "destinationLookup",
- propertyValue = "jms/jlanding-user-activity-log"
+ propertyValue = "jms/jjobs-user-activity-log"
),
@ActivationConfigProperty (
propertyName = "destinationType",
* Default constructor
*/
public JobsUserActivityLogMessageBean () {
+ // Call super constructor
+ super();
}
@Override
}
// Securely cast it
- ObjectMessage objectMessage = (ObjectMessage) message;
+ final ObjectMessage objectMessage = (ObjectMessage) message;
// Init variable
- Serializable serializable;
+ final Serializable serializable;
try {
// Get object from message
}
// Securely cast it
- LogableUserActivity userActivity = (LogableUserActivity) serializable;
+ final LogableUserActivity userActivity = (LogableUserActivity) serializable;
// Should be valid
if (null == userActivity) {
} 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
+ final User managedUser = this.createManaged(userActivity.getActivityUser());
+
+ // Set it back
+ userActivity.setActivityUser(managedUser);
+
// All fine, persist it
this.getEntityManager().persist(userActivity);