Search in sources :

Example 21 with Errors

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));
}
Also used : alfio.manager(alfio.manager) TemplateProcessor(alfio.controller.support.TemplateProcessor) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) Json(alfio.util.Json) Model(org.springframework.ui.Model) Pair(org.apache.commons.lang3.tuple.Pair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SponsorScanRepository(alfio.repository.SponsorScanRepository) ParseException(java.text.ParseException) Triple(org.apache.commons.lang3.tuple.Triple) ZipEntry(java.util.zip.ZipEntry) DateFormat(java.text.DateFormat) PageAndContent(alfio.controller.api.support.PageAndContent) TicketCategoryDescriptionRepository(alfio.repository.TicketCategoryDescriptionRepository) Organization(alfio.model.user.Organization) Predicate(java.util.function.Predicate) TemplateManager(alfio.util.TemplateManager) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) DynamicFieldTemplateRepository(alfio.repository.DynamicFieldTemplateRepository) Role(alfio.model.user.Role) Principal(java.security.Principal) alfio.model(alfio.model) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) alfio.model.modification(alfio.model.modification) OptionalWrapper.optionally(alfio.util.OptionalWrapper.optionally) ValidationResult(alfio.model.result.ValidationResult) ZipOutputStream(java.util.zip.ZipOutputStream) DataAccessException(org.springframework.dao.DataAccessException) Errors(org.springframework.validation.Errors) java.util(java.util) TicketHelper(alfio.controller.api.support.TicketHelper) Getter(lombok.Getter) EventListItem(alfio.controller.api.support.EventListItem) CSVReader(com.opencsv.CSVReader) SimpleDateFormat(java.text.SimpleDateFormat) Function(java.util.function.Function) TicketFieldRepository(alfio.repository.TicketFieldRepository) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletOutputStream(javax.servlet.ServletOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) StreamUtils(org.springframework.util.StreamUtils) OutputStream(java.io.OutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) CSVWriter(com.opencsv.CSVWriter) IOException(java.io.IOException) Validator(alfio.util.Validator) InputStreamReader(java.io.InputStreamReader) DateUtils(org.apache.commons.lang3.time.DateUtils) HttpStatus(org.springframework.http.HttpStatus) Collectors.toList(java.util.stream.Collectors.toList) Validate(org.apache.commons.lang3.Validate) MonetaryUtil(alfio.util.MonetaryUtil) UserManager(alfio.manager.user.UserManager) Log4j2(lombok.extern.log4j.Log4j2) ResponseEntity(org.springframework.http.ResponseEntity) I18nManager(alfio.manager.i18n.I18nManager) DescriptionsLoader(alfio.controller.api.support.DescriptionsLoader) AllArgsConstructor(lombok.AllArgsConstructor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ValidationResult(alfio.model.result.ValidationResult)

Example 22 with 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());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Location(org.openmrs.Location) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 23 with Errors

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"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Location(org.openmrs.Location) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 24 with Errors

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());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Location(org.openmrs.Location) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 25 with Errors

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"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Location(org.openmrs.Location) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Errors (org.springframework.validation.Errors)468 BindException (org.springframework.validation.BindException)387 Test (org.junit.Test)376 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)356 OrderUtilTest (org.openmrs.order.OrderUtilTest)58 DrugOrder (org.openmrs.DrugOrder)56 Date (java.util.Date)53 Test (org.junit.jupiter.api.Test)36 Patient (org.openmrs.Patient)36 TestBean (org.springframework.beans.testfixture.beans.TestBean)33 Calendar (java.util.Calendar)28 Concept (org.openmrs.Concept)25 TestOrder (org.openmrs.TestOrder)23 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)23 OrderType (org.openmrs.OrderType)22 Encounter (org.openmrs.Encounter)21 Obs (org.openmrs.Obs)20 Order (org.openmrs.Order)20 ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)19 PageContext (jakarta.servlet.jsp.PageContext)17