Example usage for org.springframework.validation Errors hasErrors

List of usage examples for org.springframework.validation Errors hasErrors

Introduction

In this page you can find the example usage for org.springframework.validation Errors hasErrors.

Prototype

boolean hasErrors();

Source Link

Document

Return if there were any errors.

Usage

From source file:org.openmrs.module.kenyaemr.validator.TelephoneNumberValidatorTest.java

/**
 * Validates the input string/* ww w  . j a va2 s .c o m*/
 * @param input the input
 * @return whether input is valid
 */
private static boolean invokeValidator(String input) {
    Validator validator = new TelephoneNumberValidator();
    Errors errors = new BeanPropertyBindingResult("test", "test");
    validator.validate(input, errors);
    return !errors.hasErrors();
}

From source file:org.openmrs.module.kenyaemr.validator.EmailAddressValidatorTest.java

/**
 * Validates the input string//from ww  w. j  a va  2 s.c om
 * @param input the input
 * @return whether input is valid
 */
private static boolean invokeValidator(String input) {
    Validator validator = new EmailAddressValidator();
    Errors errors = new BeanPropertyBindingResult("test", "test");
    validator.validate(input, errors);
    return !errors.hasErrors();
}

From source file:org.ng200.openolympus.validation.SolutionDtoValidator.java

public void validate(final SolutionDto solutionDto, final Errors errors) {
    if (errors.hasErrors()) {
        return;//w  ww.j av a 2  s . c o m
    }
    if (solutionDto.getTaskFile().getOriginalFilename().replaceAll("[^a-zA-Z0-9-\\._]", "").isEmpty()) {
        errors.rejectValue("taskFile", "", "solution.form.errors.badFilename");
    }
    if (solutionDto.getTaskFile().isEmpty()) {
        errors.rejectValue("taskFile", "", "solution.form.errors.emptyFile");
    }
}

From source file:com.juliuskrah.multipart.web.UserController.java

@PostMapping("/profile")
public String index(@ModelAttribute Account account, @RequestParam("file") MultipartFile file, Errors errors) {
    if (errors.hasErrors()) {
        return "profile";
    }/*from   w  w w. j a  va2  s.  c  o m*/
    log.debug("Filename is {}", file.getOriginalFilename());

    return "redirect:/u/profile";
}

From source file:org.ng200.openolympus.validation.PasswordChangeDtoValidator.java

public void validate(final PasswordChangeDto passwordChangeDto, User user, final Errors errors) {
    if (errors.hasErrors()) {
        return;/*from w w w . j a v a  2  s.co m*/
    }
    if (passwordChangeDto.getExistingPassword() == null) {
        errors.rejectValue("existingPassword", "", "empty");
    } else if (!this.passwordEncoder.matches(passwordChangeDto.getExistingPassword(), user.getPassword())) {
        errors.rejectValue("existingPassword", "", "passwordDoesntMatch");
    }
}

From source file:org.ng200.openolympus.validation.UserDtoValidator.java

public void validate(final UserDto user, final Errors errors) {
    if (errors.hasErrors()) {
        return;//from   w  w  w.  java  2 s . co  m
    }
    if (this.userRepository.findByUsername(user.getUsername()) != null) {
        errors.rejectValue("username", "", "register.form.errors.username.exists");
    }
    if (user.getPassword() != null && !user.getPassword().equals(user.getPasswordConfirmation())) {
        errors.rejectValue("passwordConfirmation", "", "register.form.errors.password.confirmationDoesntMatch");
    }
}

From source file:org.ng200.openolympus.validation.ContestDtoValidator.java

public void validate(final ContestDto contest, final Errors errors) {
    if (errors.hasErrors()) {
        return;//from  www  .j  a  v a2s . c o  m
    }
    final Date start = contest.getStartTime();
    final Date end = Date
            .from(contest.getStartTime().toInstant().plusMillis(contest.getDuration() * 1000 * 60));
    if (this.contestService.intersects(start, end) != null) {
        errors.rejectValue("startTime", "", "contest.add.form.errors.contestIntersects");
    }
}

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

private void doFurtherValidations(Object target, Errors errors) {
    if (errors.hasErrors()) {
        return;//from   ww w .  jav a 2  s .c om
    }

    EducationModel education = (EducationModel) target;
    if (!education.isCurrent()) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "endYear", FIELD_MANDATORY);
        if (!errors.hasErrors()) {
            checkPeriodCorrectness(education, errors);
        }
    }
}

From source file:org.ng200.openolympus.validation.ContestTaskAdditionDtoValidator.java

public void validate(final Contest contest, final ContestTaskAdditionDto contestTaskAddition,
        final Errors errors) {
    if (errors.hasErrors()) {
        return;//from  w  w  w.  j av a2  s  .c  o  m
    }
    final Task task = this.taskRepository.findByName(contestTaskAddition.getTaskName());
    if (task == null) {
        errors.rejectValue("taskName", "", "contest.addTask.form.errors.taskNull");
        return;
    }
    if (contest.getTasks().contains(task)) {
        errors.rejectValue("taskName", "", "contest.addTask.form.errors.taskAlreadyInContest");
        return;
    }
}

From source file:org.ng200.openolympus.validation.ContestUserTimeAdditionDtoValidator.java

public void validate(final Contest contest, final ContestUserTimeAdditionDto contestTimeAddition,
        final Errors errors) {
    if (errors.hasErrors()) {
        return;//  w  ww.  java 2  s .c  o  m
    }
    final User user = this.userRepository.findByUsername(contestTimeAddition.getUsername());
    if (user == null) {
        errors.rejectValue("username", "", "contest.addUserTime.form.errors.userDoesntExist");
        return;
    }
    if (this.contestParticipationRepository.findOneByContestAndUser(contest, user) == null) {
        errors.rejectValue("username", "", "contest.addUserTime.form.errors.userNotInContest");
        return;
    }

}