@Override
public void validate(Object target, Errors errors) {
DomainRequestForm domainRequestForm = (DomainRequestForm) target;
Domain domain = domainService.getByUUID(domainRequestForm.getDomainUUID());
if (!doesBindingErrorExist(errors, DOMAIN_UUID_FIELD) && domain == null) {
errors.reject(DOMAIN_UUID_FIELD, "domainRequestValidator.domainUUID.invalid");
}
if (!doesBindingErrorExist(errors, FIRST_NAME_FIELD) && !StringUtils.hasText(domainRequestForm.getFirstName())) {
errors.rejectValue(FIRST_NAME_FIELD, "domainRequestValidator.firstName.empty");
}
if (!doesBindingErrorExist(errors, LAST_NAME_FIELD) && !StringUtils.hasText(domainRequestForm.getLastName())) {
errors.rejectValue(LAST_NAME_FIELD, "domainRequestValidator.lastName.empty");
}
if (!doesBindingErrorExist(errors, COMPANY_NAME_FIELD) && !StringUtils.hasText(domainRequestForm.getCompanyName())) {
errors.rejectValue(COMPANY_NAME_FIELD, "domainRequestValidator.companyName.empty");
}
if (!doesBindingErrorExist(errors, ADDRESS_FIELD) && !StringUtils.hasText(domainRequestForm.getAddress())) {
errors.rejectValue(ADDRESS_FIELD, "domainRequestValidator.address.empty");
}
if (!doesBindingErrorExist(errors, PHONE_FIELD) && !StringUtils.hasText(domainRequestForm.getPhoneNumber())) {
errors.rejectValue(PHONE_FIELD, "domainRequestValidator.phoneNumber.empty");
}
if (!doesBindingErrorExist(errors, EMAIL_ADDRESS_FIELD) && !StringUtils.hasText(domainRequestForm.getEmailAddress()) || !doesRegexMatch(domainRequestForm.getEmailAddress(), emailPattern)) {
errors.rejectValue(EMAIL_ADDRESS_FIELD, "domainRequestValidator.emailAddress.invalid");
}
if (!doesBindingErrorExist(errors, DEVICE_TYPE_FIELD) && domainRequestForm.getDeviceType() == null) {
errors.rejectValue(DEVICE_TYPE_FIELD, "domainRequestValidator.deviceType.empty");
}
if (!doesBindingErrorExist(errors, REGION_FIELD)) {
Domain domainForRegion = domainService.getDomainForRegion(domainRequestForm.getRegion());
if (domainForRegion == null || !domainForRegion.equals(domain)) {
errors.rejectValue(REGION_FIELD, "domainRequestValidator.region.invalid");
}
}
if (!doesFieldErrorExist(errors, EMAIL_ADDRESS_FIELD) && !doesFieldErrorExist(errors, DOMAIN_UUID_FIELD) && !doesFieldErrorExist(errors, REGION_FIELD) && domainRequestService.doesDomainRequestExist(domain.getId(), domainRequestForm.getEmailAddress())) {