Example usage for org.springframework.validation ValidationUtils invokeValidator

List of usage examples for org.springframework.validation ValidationUtils invokeValidator

Introduction

In this page you can find the example usage for org.springframework.validation ValidationUtils invokeValidator.

Prototype

public static void invokeValidator(Validator validator, Object target, Errors errors) 

Source Link

Document

Invoke the given Validator for the supplied object and Errors instance.

Usage

From source file:it.f2informatica.core.validator.AbstractValidator.java

protected void invokeValidator(Validator validator, Object target, String nestedPath, Errors errors) {
    try {/*w  w  w.  j  a  va2 s  . c  o  m*/
        errors.pushNestedPath(nestedPath);
        ValidationUtils.invokeValidator(validator, target, errors);
    } finally {
        errors.popNestedPath();
    }
}

From source file:com.baidu.gcrm.customer.web.validator.CustomerSubmitValidator.java

@Override
public void validate(Object target, Errors errors) {
    CustomerBean customerBean = (CustomerBean) target;

    Customer customer = ServiceBeanFactory.getCustomerService().findById(customerBean.getCustomer().getId());
    customerBean.setCustomer(customer);/*w  w w.  j a  v a2 s.  c  om*/

    ValidationUtils.invokeValidator(new CustomerValidator(), customer, errors);
    ValidationUtils.invokeValidator(new CustomerTypeChangeValidator(), customer, errors);
    if (customer.getCompanyStatus() == CustomerState.disabled.ordinal()) {
        errors.rejectValue("customer.approvalStatus", "customer.disabled.submit.forbidden");
    }
    // ???? add by cch
    if (errors.hasErrors()) {
        return;
    }
    validatorNameAndLicense(customer, errors);

    Long customerNumber = customer.getId();
    List<ContactPerson> contacts = ServiceBeanFactory.getContactService()
            .findContactsByCustomerNumber(customerNumber);
    if (contacts != null && contacts.size() > CONTACT_LIMIT) {
        errors.rejectValue("", "contact.size.invalid");
    }

    if (CollectionUtils.isNotEmpty(contacts)) {
        int i = 0;
        for (ContactPerson temContactPerson : contacts) {
            ContactPersonValidator.validateSingleContactPerson(errors,
                    new StringBuilder("contacts[").append(i).append("].").toString(), temContactPerson, true);
            i++;
        }
    }

    Opportunity opportunity = ServiceBeanFactory.getOpportunityService()
            .findOpportunityByCustomerNumber(customerNumber);
    if (opportunity != null) {
        Double budget = opportunity.getBudget();
        if (budget != null && budget.doubleValue() < 0) {
            errors.rejectValue("opportunity.budget", "opportunity.budget.number");
        }
    }

    Qualification qualification = ServiceBeanFactory.getQualificationService()
            .findByCustomerNumber(customerNumber);
    if (qualification != null) {
        ValidationUtils.invokeValidator(new QualificationValidator(), qualification, errors);
    }
}

From source file:com.acc.validator.ProductDataValidator.java

@Override
public void validate(final Object target, final Errors errors) {
    final ProductData product = (ProductData) target;

    ValidationUtils.rejectIfEmpty(errors, "code", "field.required");

    try {//from w  w  w  . ja  v a 2 s  .co  m
        errors.pushNestedPath("reviews");
        if (product.getReviews() != null) {
            for (final ReviewData review : product.getReviews()) {
                ValidationUtils.invokeValidator(this.reviewValidator, review, errors);
            }
        }
    } finally {
        errors.popNestedPath();
    }
}

From source file:com.baidu.gcrm.customer.web.validator.CustomerAddValidator.java

@Override
public void validate(Object target, Errors errors) {
    CustomerBean customerBean = (CustomerBean) target;

    ValidationUtils.invokeValidator(new CustomerValidator(), customerBean.getCustomer(), errors);
    // ???????/*from  ww  w.  ja v  a  2s .c om*/
    if (errors.hasErrors()) {
        return;
    }

    Customer customer = customerBean.getCustomer();
    // ???? add by cch
    validatorNameAndLicense(customer, errors);
    //???
    validatorAgentTypeAndAgentCountry(customer, errors);
    List<ContactPerson> contacts = customerBean.getContacts();
    if (contacts != null && contacts.size() > CONTACT_LIMIT) {
        errors.rejectValue("", "contact.size.invalid");
    }

    if (CollectionUtils.isNotEmpty(contacts)) {
        int i = 0;
        for (ContactPerson temContactPerson : contacts) {
            ContactPersonValidator.validateSingleContactPerson(errors,
                    new StringBuilder("contacts[").append(i).append("].").toString(), temContactPerson, true);
            i++;
        }
    }

    Opportunity opportunity = customerBean.getOpportunity();
    if (opportunity != null) {
        Double budget = opportunity.getBudget();
        if (budget != null && budget.doubleValue() < 0) {
            errors.rejectValue("opportunity.budget", "opportunity.budget.number");
        }
    }
    // weichengke add
    Qualification qualification = customerBean.getQualification();

    if (qualification != null) {

        if (StringUtils.isNotBlank(qualification.getParterTop1())
                && qualification.getParterTop1().length() > 128) {
            errors.rejectValue("qualification.parterTop1", "qualification.parterTop.length.toolong");
        }
        if (StringUtils.isNotBlank(qualification.getParterTop2())
                && qualification.getParterTop2().length() > 128) {
            errors.rejectValue("qualification.parterTop2", "qualification.parterTop.length.toolong");
        }
        if (StringUtils.isNotBlank(qualification.getParterTop3())
                && qualification.getParterTop3().length() > 128) {
            errors.rejectValue("qualification.parterTop3", "qualification.parterTop.length.toolong");
        }
        if (StringUtils.isNotBlank(qualification.getPerformanceHighlights())
                && qualification.getPerformanceHighlights().length() > 512) {
            errors.rejectValue("qualification.performanceHighlights",
                    "qualification.performanceHighlights.length.toolong");
        }

        List<CustomerResource> resources = qualification.getCustomerResources();
        if (resources == null || resources.size() == 0) {
            return;
        }

        int index = 0;
        for (CustomerResource resource : qualification.getCustomerResources()) {
            if (StringUtils.isNotBlank(resource.getAdvertisersCompany1())
                    && resource.getAdvertisersCompany1().length() > 128) {
                errors.rejectValue("qualification.customerResources[" + index + "].advertisersCompany1",
                        "costomerResource.advertisersCompany.length.toolong");
            }
            if (StringUtils.isNotBlank(resource.getAdvertisersCompany2())
                    && resource.getAdvertisersCompany2().length() > 128) {
                errors.rejectValue("qualification.customerResources[" + index + "].advertisersCompany2",
                        "costomerResource.advertisersCompany.length.toolong");
            }
            if (StringUtils.isNotBlank(resource.getAdvertisersCompany3())
                    && resource.getAdvertisersCompany3().length() > 128) {
                errors.rejectValue("qualification.customerResources[" + index + "].advertisersCompany3",
                        "costomerResource.advertisersCompany.length.toolong");
            }
            if (StringUtils.isNotBlank(resource.getIndustry()) && resource.getIndustry().length() > 128) {
                errors.rejectValue("qualification.customerResources[" + index + "].industry",
                        "costomerResource.industry.length.toolong");
            }
            index++;
        }
    }
}

From source file:csns.web.validator.SurveyResponseValidator.java

@Override
public void validate(Object target, Errors errors) {
    SurveyResponse response = (SurveyResponse) target;
    errors.pushNestedPath("answerSheet");
    ValidationUtils.invokeValidator(answerSheetValidator, response.getAnswerSheet(), errors);
}

From source file:csns.web.validator.ItemValidator.java

@Override
public void validate(Object target, Errors errors) {
    Item item = (Item) target;/*from  w  w  w . j a  va2s  .  com*/

    errors.pushNestedPath("resource");
    ValidationUtils.invokeValidator(resourceValidator, item.getResource(), errors);
    errors.popNestedPath();
}

From source file:net.maritimecloud.identityregistry.validators.VesselValidator.java

@Override
public void validate(Object target, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "mrn", "mrn.empty", "mrn  is required.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "name.empty", "name is required.");
    Vessel vessel = (Vessel) target;//from ww w  .  j  a v a 2  s . co m
    if (vessel.getAttributes() != null) {
        for (int i = 0; i < vessel.getAttributes().size(); ++i) {
            try {
                errors.pushNestedPath("attributes[" + i + "]");
                ValidationUtils.invokeValidator(this.vesselAttributeValidator, vessel.getAttributes().get(i),
                        errors);
            } finally {
                errors.popNestedPath();
            }
        }
    }
}

From source file:csns.web.validator.AssignmentValidator.java

@Override
public void validate(Object target, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.field.required");

    Assignment assignment = (Assignment) target;
    if (!StringUtils.hasText(assignment.getAlias()))
        assignment.setAlias(assignment.getName());

    if (!assignment.isOnline()) {
        errors.pushNestedPath("description");
        ValidationUtils.invokeValidator(resourceValidator, assignment.getDescription(), errors);
        errors.popNestedPath();//w ww .j a v  a  2s  .c  o m
    }
}

From source file:org.openmrs.module.metadatasharing.model.validator.SubscriptionHeaderValidator.java

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should reject invalid package header
 * @should reject empty content URI//  w ww .  ja  va2  s.  c o  m
 */
@Override
public void validate(Object target, Errors errors) {
    SubscriptionHeader header = (SubscriptionHeader) target;
    errors.pushNestedPath("packageHeader");
    ValidationUtils.invokeValidator(packageValidator, header.getPackageHeader(), errors);
    errors.popNestedPath();

    ValidationUtils.rejectIfEmpty(errors, "contentUri",
            "metadatasharing.error.subscriptionHeader.contentUri.empty", "The contentUri cannot be empty");
}

From source file:org.codeqinvest.web.project.ProjectConnectionsValidator.java

/**
 * {@inheritDoc}//from  www  .  j  a  v a 2  s.c  om
 */
@Override
public void validate(Object target, Errors errors) {
    ValidationUtils.invokeValidator(projectValidator, target, errors);
    Project project = (Project) target;
    if (!sonarConnectionCheckerService.isReachable(project.getSonarConnectionSettings())) {
        errors.rejectValue("sonarConnectionSettings", "sonar.not.reachable");
    }

    try {
        if (!scmAvailabilityCheckerServiceFactory.create(project.getScmSettings())
                .isAvailable(project.getScmSettings())) {
            scmSystemNotAvailable(errors);
        }
    } catch (UnsupportedScmSystem e) {
        scmSystemNotAvailable(errors);
    }
}