if (null == user) {
// Abort here
throw new NullPointerException("user is null"); //NOI18N
+ } else if (user.getUserId() != null) {
+ // Not allowed here
+ throw new IllegalStateException(MessageFormat.format("user.userId must be null, is: {0}", user.getUserId())); //NOI18N
}
// Check if user is registered
}
@Override
- public void updateUserPersonalData (final User user) {
+ public User updateUserData (final User user) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateUserData: user={0} - CALLED!", user)); //NOI18N
+
+ // user should not be null
+ if (null == user) {
+ // Abort here
+ throw new NullPointerException("user is null"); //NOI18N
+ } else if (user.getUserId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (user.getUserId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
+ } else if (user.getUserAccountStatus() == null) {
+ // Throw NPE again
+ throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
+ } else if (!this.ifUserExists(user)) {
+ // User does not exist
+ throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
+ }
+
+ // Remove contact instance as this is not updatedf
+ user.setUserContact(null);
+
+ // Find the instance
+ User foundUser = this.getEntityManager().find(user.getClass(), user.getUserId());
+
+ // Should be found!
+ assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
+
+ // Merge user
+ User detachedUser = this.getEntityManager().merge(foundUser);
+
+ // Should be found!
+ assert (detachedUser instanceof User) : MessageFormat.format("User with id {0} not merged, but should be.", user.getUserId()); //NOI18N
+
+ // Copy all data
+ detachedUser.copyAll(user);
+
+ // Set as updated
+ detachedUser.setUserUpdated(new GregorianCalendar());
+
+ // Return updated instance
+ return detachedUser;
+ }
+
+ @Override
+ public User updateUserPersonalData (final User user) {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateUserPersonalData: user={0} - CALLED!", user)); //NOI18N
// Set it back
detachedContact.setContactLandLineNumber(detachedLandLine);
}
+
+ // Return updated user instance
+ return detachedUser;
}
}