Class AbstractRequestValidator<SELF extends AbstractRequestValidator<SELF>>

java.lang.Object
io.github.belgif.rest.problem.validation.AbstractRequestValidator<SELF>
Type Parameters:
SELF - self-referencing AbstractRequestValidator type (for extensible fluent builder pattern)
Direct Known Subclasses:
RequestValidator

public abstract class AbstractRequestValidator<SELF extends AbstractRequestValidator<SELF>> extends Object
Abstract base class for RequestValidator (for extensible fluent builder pattern).

Performs validation on input parameters of an API request.

This validation does not stop on the first invalid input. It performs all configured validations and if any of them failed, a BadRequestProblem is thrown, containing each encountered InputValidationIssue.

See Also:
  • Constructor Details

    • AbstractRequestValidator

      public AbstractRequestValidator()
  • Method Details

    • validate

      public void validate() throws BadRequestProblem
      Perform all configured validations.
      Throws:
      BadRequestProblem - if the validation fails, containing each encountered InputValidationIssue
    • ssin

      public SELF ssin(Input<String> ssin)
      Validate the structure of a Belgif openapi-person-identifier SSIN.
      Parameters:
      ssin - the SSIN to validate
      Returns:
      this request validator
      See Also:
    • ssins

      public SELF ssins(Input<List<String>> ssins)
      Validate the structure of a list of Belgif openapi-person-identifier SSIN.
      Parameters:
      ssins - the SSINs to validate
      Returns:
      this request validator
      See Also:
    • enterpriseNumber

      public SELF enterpriseNumber(Input<String> enterpriseNumber)
      Validate the structure of a Belgif openapi-organization-identifier EnterpriseNumber.
      Parameters:
      enterpriseNumber - the enterprise number to validate
      Returns:
      this request validator
      See Also:
    • establishmentUnitNumber

      public SELF establishmentUnitNumber(Input<String> establishmentUnitNumber)
      Validate the structure of a Belgif openapi-organization-identifier EstablishmentUnitNumber.
      Parameters:
      establishmentUnitNumber - the establishment unit number to validate
      Returns:
      this request validator
      See Also:
    • period

      public SELF period(Input<?> period)
      Validate the structure of a Belgif openapi-time Period or PeriodOptionalEnd.
      Parameters:
      period - the Period or PeriodOptionalEnd to validate
      Returns:
      this request validator
      See Also:
    • period

      public <T extends Temporal & Comparable<? super T>> SELF period(Input<T> start, Input<T> end)
      Validate that two comparable temporal inputs make a valid period.

      This can be used with types like LocalDate, LocalDateTime, OffsetDateTime, Year, YearMonth, ...

      Type Parameters:
      T - the comparable temporal type
      Parameters:
      start - the input with the start
      end - the input with the end
      Returns:
      this request validator
    • incompleteDate

      public SELF incompleteDate(Input<String> incompleteDate)
      Validate the structure of a Belgif openapi-time IncompleteDate.
      Parameters:
      incompleteDate - the IncompleteDate to validate
      Returns:
      this request validator
      See Also:
    • yearMonth

      public SELF yearMonth(Input<String> yearMonth)
      Validate the structure of a Belgif openapi-time YearMonth.
      Parameters:
      yearMonth - the YearMonth to validate
      Returns:
      this request validator
      See Also:
    • exactlyOneOf

      public SELF exactlyOneOf(Input<?>... inputs)
      Validate that exactly one of the given inputs is present.
      Parameters:
      inputs - the inputs to validate
      Returns:
      this request validator
    • anyOf

      public SELF anyOf(Input<?>... inputs)
      Validate that any of the given inputs is present.
      Parameters:
      inputs - the inputs to validate
      Returns:
      this request validator
    • zeroOrAllOf

      public SELF zeroOrAllOf(Input<?>... inputs)
      Validate that all or none of the given inputs are present.
      Parameters:
      inputs - the inputs to validate
      Returns:
      this request validator
    • zeroOrExactlyOneOf

      public SELF zeroOrExactlyOneOf(Input<?>... inputs)
      Validate that exactly one or none of the given inputs are present.
      Parameters:
      inputs - the inputs to validate
      Returns:
      this request validator
    • equal

      public SELF equal(Input<?>... inputs)
      Validate that the given inputs are equal (according to Object.equals(Object)).
      Parameters:
      inputs - the inputs to validate
      Returns:
      this request validator
    • nullOrEqual

      public SELF nullOrEqual(Input<?> nullableInput, Input<?> mustMatch)
      Validate that the given input is either null, or equal to another given input if present.
      Parameters:
      nullableInput - the input that can be null or equal
      mustMatch - the reference input that must be matched against
      Returns:
      this request validator
    • refData

      public <T> SELF refData(Input<T> input, Collection<T> allowedRefData)
      Validate that the given input is in the allowed reference data.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      allowedRefData - the allowed reference data
      Returns:
      this request validator
    • refData

      public <T> SELF refData(Input<T> input, Supplier<Collection<T>> allowedRefDataSupplier)
      Validate that the given input is in the allowed reference data.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      allowedRefDataSupplier - the supplier of the allowed reference data
      Returns:
      this request validator
    • refData

      public <T> SELF refData(Input<T> input, Predicate<T> allowedRefDataPredicate)
      Validate that the given input is in the allowed reference data.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      allowedRefDataPredicate - the predicate for verifying the reference data
      Returns:
      this request validator
    • refDatas

      public <T> SELF refDatas(Input<List<T>> input, Collection<T> allowedRefData)
      Validate that the given input is in the allowed reference data.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      allowedRefData - the allowed reference data
      Returns:
      this request validator
    • refDatas

      public <T> SELF refDatas(Input<List<T>> input, Supplier<Collection<T>> allowedRefDataSupplier)
      Validate that the given input is in the allowed reference data.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      allowedRefDataSupplier - the supplier of the allowed reference data
      Returns:
      this request validator
    • refDatas

      public <T> SELF refDatas(Input<List<T>> input, Predicate<T> allowedRefDataPredicate)
      Validate that the given input is in the allowed reference data.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      allowedRefDataPredicate - the predicate for verifying the reference data
      Returns:
      this request validator
    • reject

      public <T> SELF reject(Input<T> input)
      Validate that the given input is not present.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      Returns:
      this request validator
    • require

      public <T> SELF require(Input<T> input)
      Validate that the given input is present.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      Returns:
      this request validator
    • requireIfPresent

      public SELF requireIfPresent(Input<?> target, Input<?>... inputs)
      Validate that all the given inputs are present when the given target input is present.
      Parameters:
      target - the target input
      inputs - the inputs that are required when the target input is present
      Returns:
      this request validator
    • when

      public SELF when(boolean condition, Consumer<SELF> requestValidatorConsumer)
      Conditionally register input validators.
      Parameters:
      condition - the condition
      requestValidatorConsumer - the request validator consumer that will only be called if condition is true
      Returns:
      this request validator
    • range

      public <T extends Comparable<T>> SELF range(Input<T> input, T min, T max)
      Validate that the given input value is in the given [min, max] range.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      min - the minimum (inclusive)
      max - the maximum (inclusive)
      Returns:
      this request validator
    • minimum

      public <T extends Comparable<T>> SELF minimum(Input<T> input, T min)
      Validate that the given input value is not less than the given minimum.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      min - the minimum (inclusive)
      Returns:
      this request validator
    • maximum

      public <T extends Comparable<T>> SELF maximum(Input<T> input, T max)
      Validate that the given input value does not exceed the given maximum.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      max - the maximum (inclusive)
      Returns:
      this request validator
    • custom

      public SELF custom(InputValidator validator)
      Register a custom InputValidator.
      Parameters:
      validator - the custom validator
      Returns:
      this request validator
    • addValidator

      protected SELF addValidator(InputValidator validator)
      Parameters:
      validator - the validator
      Returns:
      this request validator
    • getThis

      protected SELF getThis()
      Get a self-reference to return from validator methods (for extensible fluent builder pattern)
      Returns:
      a self-reference