Class QueryTemplateImpl
java.lang.Object
org.gcube.informationsystem.base.impl.ElementImpl
org.gcube.informationsystem.base.impl.entities.EntityElementImpl
org.gcube.informationsystem.queries.templates.impl.entities.QueryTemplateImpl
- All Implemented Interfaces:
Serializable,Element,EntityElement,IdentifiableElement,QueryTemplate
The default implementation of the
QueryTemplate interface.- Author:
- Luca Frosini (ISTI - CNR)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe description of the query template.protected StringThe name of the query template.protected org.gcube.com.fasterxml.jackson.databind.ObjectMapperThe object mapper.protected org.gcube.com.fasterxml.jackson.databind.JsonNodeThe parameters.protected org.gcube.com.fasterxml.jackson.databind.JsonNodeThe template.protected Map<String,TemplateVariable> The template variables.Fields inherited from class org.gcube.informationsystem.base.impl.entities.EntityElementImpl
metadata, uuidFields inherited from interface org.gcube.informationsystem.base.reference.Element
DATETIME_PATTERN, NAME, TYPE_PROPERTYFields inherited from interface org.gcube.informationsystem.base.reference.entities.EntityElement
NAMEFields inherited from interface org.gcube.informationsystem.base.reference.IdentifiableElement
ID_PROPERTY, METADATA_PROPERTYFields inherited from interface org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate
DESCRIPTION_PROPERTY, NAME, NAME_PROPERTY, TEMPLATE_PROPERTY, TEMPLATE_VARIABLES_PROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTemplateVariable(TemplateVariable templateVariable) Adds a variable to the template.Returns the description of the query template.org.gcube.com.fasterxml.jackson.databind.JsonNodeGenerates a runnable query by substituting variables with their default values.org.gcube.com.fasterxml.jackson.databind.JsonNodegetJsonQuery(org.gcube.com.fasterxml.jackson.databind.JsonNode values) Generates a runnable query by substituting variables with the provided values.getName()Returns the name of the query template.org.gcube.com.fasterxml.jackson.databind.node.ObjectNodeCreates anObjectNodecontaining the default values of all template variables.org.gcube.com.fasterxml.jackson.databind.JsonNodeReturns the template body as aJsonNode.Returns the template body as a string.Returns the variables defined in this template.protected org.gcube.com.fasterxml.jackson.databind.JsonNodereplaceVariables(org.gcube.com.fasterxml.jackson.databind.JsonNode jsonNode) Replaces the variables in the given JSON node.voidsetDescription(String description) Sets the description of the query template.voidSets the name of the query template.voidsetTemplate(String template) Sets the template body from a string.voidsetTemplate(org.gcube.com.fasterxml.jackson.databind.JsonNode template) Sets the template body from aJsonNode.Methods inherited from class org.gcube.informationsystem.base.impl.entities.EntityElementImpl
getID, getMetadata, setID, setMetadataMethods inherited from class org.gcube.informationsystem.base.impl.ElementImpl
getTypeName, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.gcube.informationsystem.base.reference.Element
getTypeNameMethods inherited from interface org.gcube.informationsystem.base.reference.entities.EntityElement
getID, getMetadata, setID, setMetadata
-
Field Details
-
name
The name of the query template. -
description
The description of the query template. -
objectMapper
protected org.gcube.com.fasterxml.jackson.databind.ObjectMapper objectMapperThe object mapper. -
template
protected org.gcube.com.fasterxml.jackson.databind.JsonNode templateThe template. -
templateVariables
The template variables. -
params
protected org.gcube.com.fasterxml.jackson.databind.JsonNode paramsThe parameters.
-
-
Constructor Details
-
QueryTemplateImpl
public QueryTemplateImpl()Default constructor.
-
-
Method Details
-
getName
Returns the name of the query template.- Specified by:
getNamein interfaceQueryTemplate- Returns:
- The template name.
-
setName
Sets the name of the query template.- Specified by:
setNamein interfaceQueryTemplate- Parameters:
name- The name to set.
-
getDescription
Returns the description of the query template.- Specified by:
getDescriptionin interfaceQueryTemplate- Returns:
- The template description.
-
setDescription
Sets the description of the query template.- Specified by:
setDescriptionin interfaceQueryTemplate- Parameters:
description- The description to set.
-
getTemplateAsString
public String getTemplateAsString() throws org.gcube.com.fasterxml.jackson.core.JsonProcessingExceptionReturns the template body as a string.- Specified by:
getTemplateAsStringin interfaceQueryTemplate- Returns:
- The template as a string.
- Throws:
org.gcube.com.fasterxml.jackson.core.JsonProcessingException- if an error occurs during serialization.
-
setTemplate
public void setTemplate(String template) throws org.gcube.com.fasterxml.jackson.core.JsonProcessingException, IOException Sets the template body from a string.- Specified by:
setTemplatein interfaceQueryTemplate- Parameters:
template- The template string.- Throws:
org.gcube.com.fasterxml.jackson.core.JsonProcessingException- if an error occurs during JSON processing.IOException- if an error occurs during parsing.
-
getTemplate
public org.gcube.com.fasterxml.jackson.databind.JsonNode getTemplate()Returns the template body as aJsonNode.- Specified by:
getTemplatein interfaceQueryTemplate- Returns:
- The template as a
JsonNode.
-
setTemplate
public void setTemplate(org.gcube.com.fasterxml.jackson.databind.JsonNode template) Sets the template body from aJsonNode.- Specified by:
setTemplatein interfaceQueryTemplate- Parameters:
template- The template as aJsonNode.
-
getTemplateVariables
Returns the variables defined in this template.- Specified by:
getTemplateVariablesin interfaceQueryTemplate- Returns:
- A map of template variables, with variable names as keys.
-
addTemplateVariable
Adds a variable to the template. If a variable with the same name already exists, it will be overridden.- Specified by:
addTemplateVariablein interfaceQueryTemplate- Parameters:
templateVariable- The variable to add.
-
getParamsFromDefaultValues
public org.gcube.com.fasterxml.jackson.databind.node.ObjectNode getParamsFromDefaultValues()Creates anObjectNodecontaining the default values of all template variables.- Specified by:
getParamsFromDefaultValuesin interfaceQueryTemplate- Returns:
- An
ObjectNodewith default parameter values.
-
getJsonQuery
Generates a runnable query by substituting variables with their default values.- Specified by:
getJsonQueryin interfaceQueryTemplate- Returns:
- The generated query as a
JsonNode. - Throws:
Exception- if an error occurs during query generation.
-
replaceVariables
protected org.gcube.com.fasterxml.jackson.databind.JsonNode replaceVariables(org.gcube.com.fasterxml.jackson.databind.JsonNode jsonNode) throws Exception Replaces the variables in the given JSON node.- Parameters:
jsonNode- the JSON node- Returns:
- the JSON node with the variables replaced
- Throws:
Exception- if an error occurs
-
getJsonQuery
public org.gcube.com.fasterxml.jackson.databind.JsonNode getJsonQuery(org.gcube.com.fasterxml.jackson.databind.JsonNode values) throws Exception Generates a runnable query by substituting variables with the provided values.- Specified by:
getJsonQueryin interfaceQueryTemplate- Parameters:
values- AJsonNodecontaining the values to substitute.- Returns:
- The generated query as a
JsonNode. - Throws:
Exception- if an error occurs during query generation.
-