use of org.springframework.validation.Errors in project alf.io by alfio-event.
the class EventApiController method validateEvent.
@RequestMapping(value = "/events/check", method = POST)
public ValidationResult validateEvent(@RequestBody EventModification eventModification, Errors errors) {
ValidationResult base = validateEventHeader(Optional.empty(), eventModification, errors).or(validateTicketCategories(eventModification, errors)).or(validateEventPrices(Optional.empty(), eventModification, errors)).or(eventModification.getAdditionalServices().stream().map(as -> validateAdditionalService(as, eventModification, errors)).reduce(ValidationResult::or).orElse(ValidationResult.success()));
AtomicInteger counter = new AtomicInteger();
return base.or(eventModification.getTicketCategories().stream().map(c -> validateCategory(c, errors, "ticketCategories[" + counter.getAndIncrement() + "].", eventModification)).reduce(ValidationResult::or).orElse(ValidationResult.success())).or(validateAdditionalTicketFields(eventModification.getTicketFields(), errors));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class LocationValidatorTest method validate_shouldPassValidationIfRetiredLocationIsGivenRetiredReason.
/**
* @see LocationValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfRetiredLocationIsGivenRetiredReason() {
Location location = new Location();
location.setName("County General");
location.setDescription("desc");
location.setRetired(true);
location.setRetireReason("Because I don't like County General");
Errors errors = new BindException(location, "location");
new LocationValidator().validate(location, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class LocationValidatorTest method validate_shouldFailValidationIfNameIsNullOrEmpty.
/**
* @see LocationValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfNameIsNullOrEmpty() {
Location location = new Location();
location.setDescription("desc");
Errors errors = new BindException(location, "location");
new LocationValidator().validate(location, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
Assert.assertFalse(errors.hasFieldErrors("description"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class LocationValidatorTest method validate_shouldPassValidationIfAllFieldsAreCorrect.
/**
* @see LocationValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfAllFieldsAreCorrect() {
Location location = new Location();
location.setName("County General");
location.setDescription("desc");
Errors errors = new BindException(location, "location");
new LocationValidator().validate(location, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class LocationValidatorTest method validate_shouldFailValidationIfRetiredAndRetireReasonIsNullOrEmpty.
/**
* @see LocationValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfRetiredAndRetireReasonIsNullOrEmpty() {
Location location = new Location();
location.setName("County General");
location.setRetired(true);
Errors errors = new BindException(location, "location");
new LocationValidator().validate(location, errors);
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
Aggregations