return BatchInvitationForm.class.isAssignableFrom(clazz);
}
@Override
public void validate(Object target, Errors errors) {
BatchInvitationForm form = (BatchInvitationForm) target;
User user = userService.getUserFromSecurityContext();
if (user == null || user.getActiveOrganization() == null) {
errors.reject("batchInvitationValidator.error.generic");
return;
}
// Check if User Roles are valid
if (form.getOrganizationUserRole() == null || !UserRole.getAllSelectableForDomainType(DomainType.ORGANIZATION).contains(form.getOrganizationUserRole())) {
errors.rejectValue(ORGANIZATION_USER_ROLE_FIELD, "batchInvitationValidator.userRole.organization.invalid");
return;
} else if (UserRole.ROLE_ORG_GUEST.equals(form.getOrganizationUserRole()) && CollectionUtils.isEmpty(form.getGroupIds())) {
errors.rejectValue(GROUP_IDS_FIELD, "batchInvitationValidator.orgGuest.groupIds.empty");
}
// Validate security
validateSecurity(errors, form, user);
if (errors.hasErrors()) {
return;
}
List<Contact> validContacts = new ArrayList<Contact>(); /*List of valid contacts*/
List<Contact> invalidContacts = new ArrayList<Contact>(); /*List of invalid contacts*/
for (int index = 0; index < form.getContacts().size(); index++) {
Contact contact = form.getContacts().get(index);
Errors contactErrors = new BeanPropertyBindingResult(form, "batchInvitationForm");
contact.setEmail(trimWhitespace(contact.getEmail()));
// Validate email