existingIds = context.getExistingUserIds();
}
if (!update && StringUtils.isEmpty(user.getId())) {
ValidationMessage message =
new ValidationMessage("userId", "User ID is required.", "User ID is required.");
response.addValidationError(message);
}
if (!update && StringUtils.isNotEmpty(user.getId()) && existingIds.contains(user.getId())) {
ValidationMessage message =
new ValidationMessage("userId", "User ID '" + user.getId() + "' is already in use.", "User ID '"
+ user.getId() + "' is already in use.");
response.addValidationError(message);
}
if (StringUtils.isNotEmpty(user.getId()) && user.getId().contains(" ")) {
ValidationMessage message =
new ValidationMessage("userId", "User ID '" + user.getId() + "' cannot contain spaces.", "User ID '"
+ user.getId() + "' cannot contain spaces.");
response.addValidationError(message);
}
if (StringUtils.isNotEmpty(user.getFirstName())) {
user.setFirstName(user.getFirstName());
}
if (StringUtils.isNotEmpty(user.getLastName())) {
user.setLastName(user.getLastName());
}
if (StringUtils.isEmpty(user.getPassword())) {
ValidationMessage message =
new ValidationMessage("password", "User ID '" + user.getId()
+ "' has no password. This is a required field.", "Password is required.");
response.addValidationError(message);
}
if (StringUtils.isEmpty(user.getEmail())) {
ValidationMessage message =
new ValidationMessage("email", "User ID '" + user.getId() + "' has no email address",
"Email address is required.");
response.addValidationError(message);
}
else {
try {
if (!user.getEmail().matches(".+@.+")) {
ValidationMessage message =
new ValidationMessage("email", "User ID '" + user.getId() + "' has an invalid email address.",
"Email address is invalid.");
response.addValidationError(message);
}
}
catch (PatternSyntaxException e) {
throw new IllegalStateException("Regex did not compile: " + e.getMessage(), e);
}
}
if (!CUser.STATUS_ACTIVE.equals(user.getStatus()) && !CUser.STATUS_DISABLED.equals(user.getStatus())) {
ValidationMessage message =
new ValidationMessage("status", "User ID '" + user.getId() + "' has invalid status '"
+ user.getStatus() + "'. (Allowed values are: " + CUser.STATUS_ACTIVE + " and "
+ CUser.STATUS_DISABLED + ")", "Invalid Status selected.");
response.addValidationError(message);
}
if (context.getExistingRoleIds() != null && context.getExistingUserRoleMap() != null) {
if (roles != null && roles.size() > 0) {
for (String roleId : roles) {
if (!context.getExistingRoleIds().contains(roleId)) {
ValidationMessage message =
new ValidationMessage("roles", "User ID '" + user.getId() + "' Invalid role id '" + roleId
+ "' found.", "User cannot contain invalid role ID '" + roleId + "'.");
response.addValidationError(message);
}
}
}