return DomainRegionForm.class.isAssignableFrom(clazz);
}
@Override
public void validate(Object target, Errors errors) {
DomainRegionForm form = (DomainRegionForm) target;
boolean isEdit = form.getId() != null && form.getId() > 0;
if (!ValidationUtils.doesBindingErrorExist(errors, NAME_FIELD) && !StringUtils.hasText(form.getName())) {
errors.rejectValue(NAME_FIELD, "domainRegionValidator.name.empty");
}
boolean domainRegionNameExists = domainService.doesDomainContainRegionWithName(form.getDomainId(), form.getName());
if (isEdit && domainRegionNameExists) {
Region region = regionService.get(form.getId());
if (!region.getName().equals(form.getName())) {
errors.rejectValue(NAME_FIELD, "domainRegionValidator.name.exists");
}
} else if (!ValidationUtils.doesFieldErrorExist(errors, NAME_FIELD) && domainRegionNameExists) {
errors.rejectValue(NAME_FIELD, "domainRegionValidator.name.exists");
}
if (!ValidationUtils.doesBindingErrorExist(errors, EMAILS_FIELD)) {
for (String email : form.getEmails()) {
if (!ValidationUtils.doesRegexMatch(email, emailPattern)) {
errors.rejectValue(NAME_FIELD, "domainRegionValidator.emails.invalid");
break;
}
}