return GroupForm.class.isAssignableFrom(aClass);
}
@Override
public void validate(Object o, Errors errors) {
GroupForm groupForm = (GroupForm) o;
if (groupForm.getName() == null || "".equals(groupForm.getName())) {
errors.rejectValue(NAME_FIELD, "groupValidator.emptyName");
}
if (!errors.hasFieldErrors(NAME_FIELD)) {
User user = userService.getUserFromSecurityContext();
if (user == null) {
errors.reject("groupValidator.generic");
return;
}
Organization organization = user.getActiveOrganization();
if (organization == null) {
errors.reject("groupValidator.generic");
}
Group group = groupService.get(groupForm.getName(), organization.getId());
if (group != null) {
errors.rejectValue(NAME_FIELD, "groupValidator.groupNameExistsInOrganization");
}
}
}