Class OperandValidator
java.lang.Object
org.gcube.informationsystem.resourceregistry.queries.operators.OperandValidator
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
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum number of elements of the array operand of_in,_containsAlland_containsAny. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionParses a Date strictly withElement.DATETIME_PATTERN.voidvalidate(ComparisonOperator comparisonOperator, org.gcube.com.fasterxml.jackson.databind.JsonNode operand) Validates the operand of a comparison, presence, collection or map operator.voidvalidate(LogicalOperator logicalOperator, org.gcube.com.fasterxml.jackson.databind.JsonNode operand) Validates the operand of a logical operator:_andtakes an array of condition objects,_ora non-empty array of condition objects,_nota single non-empty condition object.voidvalidateDomain(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.voidvalidateNullTest(String property, PropertyDomain domain) Validates a directnullagainst the domain declared for the tested property.
-
Field Details
-
MAX_ARRAY_OPERAND_SIZE
public static final int MAX_ARRAY_OPERAND_SIZEThe maximum number of elements of the array operand of_in,_containsAlland_containsAny.- See Also:
-
-
Constructor Details
-
OperandValidator
public OperandValidator()Creates a newOperandValidator.
-
-
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:_andtakes an array of condition objects,_ora non-empty array of condition objects,_nota single non-empty condition object.- Parameters:
logicalOperator- the logical operatoroperand- 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 operatoroperand- 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 directnullagainst the domain declared for the tested property.- Parameters:
property- the tested propertydomain- the declared domain of the property,nullif 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 satisfyvalidate(ComparisonOperator, JsonNode).- Parameters:
comparisonOperator- the operatoroperand- the operand of the operatorproperty- the compared propertydomain- the declared domain of the property,nullif 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
Parses a Date strictly withElement.DATETIME_PATTERN.- Parameters:
text- the text to parse- Returns:
- the Date, or
nullif the text is not a Date
-