java.lang.Object
org.gcube.informationsystem.resourceregistry.queries.operators.OperandValidator

public class OperandValidator extends Object
Validates the operand of every JSON query operator against its formal schema.

The checks of validate(ComparisonOperator, JsonNode) depend only on the operand: native JSON type, null policy, array cardinality, homogeneous array elements, bound ordering, regular-expression validity and the maximum size of array operands. The checks of validateDomain(ComparisonOperator, JsonNode, String, PropertyDomain) compare the operator and its operand with the domain the Type definition declares for the compared property. Operands are never coerced.

Author:
Luca Frosini (ISTI - CNR)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The maximum number of elements of the array operand of _in, _containsAll and _containsAny.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new OperandValidator.
  • Method Summary

    Modifier and Type
    Method
    Description
    toDate(String text)
    Parses a Date strictly with Element.DATETIME_PATTERN.
    void
    validate(ComparisonOperator comparisonOperator, org.gcube.com.fasterxml.jackson.databind.JsonNode operand)
    Validates the operand of a comparison, presence, collection or map operator.
    void
    validate(LogicalOperator logicalOperator, org.gcube.com.fasterxml.jackson.databind.JsonNode operand)
    Validates the operand of a logical operator: _and takes an array of condition objects, _or a non-empty array of condition objects, _not a single non-empty condition object.
    void
    validateDomain(ComparisonOperator comparisonOperator, org.gcube.com.fasterxml.jackson.databind.JsonNode operand, String property, PropertyDomain domain)
    Validates an operator and its operand against the domain declared for the compared property.
    void
    Validates a direct null against the domain declared for the tested property.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_ARRAY_OPERAND_SIZE

      public static final int MAX_ARRAY_OPERAND_SIZE
      The maximum number of elements of the array operand of _in, _containsAll and _containsAny.
      See Also:
  • Constructor Details

  • Method Details

    • validate

      public void validate(LogicalOperator logicalOperator, org.gcube.com.fasterxml.jackson.databind.JsonNode operand) throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException
      Validates the operand of a logical operator: _and takes an array of condition objects, _or a non-empty array of condition objects, _not a single non-empty condition object.
      Parameters:
      logicalOperator - the logical operator
      operand - the operand of the logical operator
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if the operand does not have the shape required by the operator
    • validate

      public void validate(ComparisonOperator comparisonOperator, org.gcube.com.fasterxml.jackson.databind.JsonNode operand) throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException
      Validates the operand of a comparison, presence, collection or map operator.
      Parameters:
      comparisonOperator - the operator
      operand - the operand of the operator
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if the operand violates the schema of the operator
    • validateNullTest

      public void validateNullTest(String property, PropertyDomain domain) throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException
      Validates a direct null against the domain declared for the tested property.
      Parameters:
      property - the tested property
      domain - the declared domain of the property, null if the Type definition does not declare it
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if the property cannot be used in a predicate
    • validateDomain

      public void validateDomain(ComparisonOperator comparisonOperator, org.gcube.com.fasterxml.jackson.databind.JsonNode operand, String property, PropertyDomain domain) throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException
      Validates an operator and its operand against the domain declared for the compared property. The operand must already satisfy validate(ComparisonOperator, JsonNode).
      Parameters:
      comparisonOperator - the operator
      operand - the operand of the operator
      property - the compared property
      domain - the declared domain of the property, null if the Type definition does not declare it
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if the operator does not apply to the domain or the operand is not compatible with it
    • toDate

      public Date toDate(String text)
      Parses a Date strictly with Element.DATETIME_PATTERN.
      Parameters:
      text - the text to parse
      Returns:
      the Date, or null if the text is not a Date