Class QueryTemplateDefinitionValidator
java.lang.Object
org.gcube.informationsystem.resourceregistry.queries.templates.QueryTemplateDefinitionValidator
Validates a Query Template definition against the closed definition and
TemplateVariable
contract, and applies its variables: the substitution of defaults at save time and of the
supplied values at execution time. Works on the JSON representation only, so it is independent
of the persistence layer.- Author:
- Luca Frosini (ISTI - CNR)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordValues resolved for one execution of a Query Template. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum length, in UTF-16 code units, of aStringvalue without an explicitmax.static final PatternThe grammar of a Query Template name: lowercase words separated by hyphens.static final PatternThe grammar of a template variable name:$followed by a lowerCamelCase name.static final StringThe prefix of every template variable reference. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.gcube.com.fasterxml.jackson.databind.node.ObjectNodecomparable(org.gcube.com.fasterxml.jackson.databind.JsonNode definition) Returns the comparable content of a Query Template definition, submitted or persisted: the complete definition exceptid,metadata,type, andsupertypes, with each variable complete (absentrequiredisfalse, absentregexpis empty, absent bounds are omitted).defaultValues(org.gcube.com.fasterxml.jackson.databind.JsonNode definition) Returns the default value of every variable of a normalized definition.resolveExecutionValues(org.gcube.com.fasterxml.jackson.databind.JsonNode definition, org.gcube.com.fasterxml.jackson.databind.JsonNode params) Resolves the value of every variable for one execution.booleansameValue(org.gcube.com.fasterxml.jackson.databind.JsonNode first, org.gcube.com.fasterxml.jackson.databind.JsonNode second) Tells whether two JSON values are equal, numbers being compared by numeric value.org.gcube.com.fasterxml.jackson.databind.JsonNodesubstitute(org.gcube.com.fasterxml.jackson.databind.JsonNode template, Map<String, org.gcube.com.fasterxml.jackson.databind.JsonNode> values) Returns a copy of the template in which every string node equal to a variable name is replaced by that variable's value.org.gcube.com.fasterxml.jackson.databind.node.ObjectNodeValidates a submitted Query Template definition (closed members, name grammar, description, version and changelog, variable declarations and reference coverage) and returns its normalized form:typeset toQueryTemplate,supertypesremoved, each variable complete and typedTemplateVariable.
-
Field Details
-
NAME_PATTERN
The grammar of a Query Template name: lowercase words separated by hyphens. -
VARIABLE_NAME_PATTERN
The grammar of a template variable name:$followed by a lowerCamelCase name. -
VARIABLE_PREFIX
The prefix of every template variable reference.- See Also:
-
DEFAULT_STRING_MAX_LENGTH
public static final int DEFAULT_STRING_MAX_LENGTHThe maximum length, in UTF-16 code units, of aStringvalue without an explicitmax.- See Also:
-
-
Constructor Details
-
QueryTemplateDefinitionValidator
public QueryTemplateDefinitionValidator()Creates a newQueryTemplateDefinitionValidator.
-
-
Method Details
-
validate
public org.gcube.com.fasterxml.jackson.databind.node.ObjectNode validate(String pathName, org.gcube.com.fasterxml.jackson.databind.JsonNode definition) throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateException Validates a submitted Query Template definition (closed members, name grammar, description, version and changelog, variable declarations and reference coverage) and returns its normalized form:typeset toQueryTemplate,supertypesremoved, each variable complete and typedTemplateVariable.idandmetadataare kept.- Parameters:
pathName- the name addressed by the request, ornullwhen none is addresseddefinition- the submitted definition- Returns:
- the normalized definition
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateException- if the definition violates the contract
-
comparable
public org.gcube.com.fasterxml.jackson.databind.node.ObjectNode comparable(org.gcube.com.fasterxml.jackson.databind.JsonNode definition) Returns the comparable content of a Query Template definition, submitted or persisted: the complete definition exceptid,metadata,type, andsupertypes, with each variable complete (absentrequiredisfalse, absentregexpis empty, absent bounds are omitted).- Parameters:
definition- the definition- Returns:
- its comparable content
-
sameValue
public boolean sameValue(org.gcube.com.fasterxml.jackson.databind.JsonNode first, org.gcube.com.fasterxml.jackson.databind.JsonNode second) Tells whether two JSON values are equal, numbers being compared by numeric value.- Parameters:
first- the first value, possiblynullsecond- the second value, possiblynull- Returns:
trueif they are equal
-
defaultValues
public Map<String,org.gcube.com.fasterxml.jackson.databind.JsonNode> defaultValues(org.gcube.com.fasterxml.jackson.databind.JsonNode definition) Returns the default value of every variable of a normalized definition.- Parameters:
definition- the normalized definition- Returns:
- the default value of each variable, keyed by variable name
-
resolveExecutionValues
public QueryTemplateDefinitionValidator.ExecutionValues resolveExecutionValues(org.gcube.com.fasterxml.jackson.databind.JsonNode definition, org.gcube.com.fasterxml.jackson.databind.JsonNode params) throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException Resolves the value of every variable for one execution. A supplied value must be valid for the variable; an omitted variable takes its default unless it is required.- Parameters:
definition- the persisted definitionparams- the supplied values, a JSON object, ornullwhen no body was sent- Returns:
- the resolved values and the supplied keys that declare no variable
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException- if a required variable is omitted or a supplied value is invalid
-
substitute
public org.gcube.com.fasterxml.jackson.databind.JsonNode substitute(org.gcube.com.fasterxml.jackson.databind.JsonNode template, Map<String, org.gcube.com.fasterxml.jackson.databind.JsonNode> values) Returns a copy of the template in which every string node equal to a variable name is replaced by that variable's value. Object keys are not substitution targets, strings are never partially interpolated, and inserted values are not scanned again.- Parameters:
template- the templatevalues- the value of each variable- Returns:
- the substituted query
-