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
public class QueryTemplateImpl extends EntityElementImpl implements QueryTemplate
The default implementation of theQueryTemplateinterface.- Author:
- Luca Frosini (ISTI - CNR)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected StringdescriptionThe description of the query template.protected StringnameThe name of the query template.protected org.gcube.com.fasterxml.jackson.databind.ObjectMapperobjectMapperThe object mapper.protected org.gcube.com.fasterxml.jackson.databind.JsonNodeparamsThe parameters.protected org.gcube.com.fasterxml.jackson.databind.JsonNodetemplateThe template.protected Map<String,TemplateVariable>templateVariablesThe template variables.-
Fields inherited from class org.gcube.informationsystem.base.impl.entities.EntityElementImpl
metadata, uuid
-
Fields inherited from interface org.gcube.informationsystem.base.reference.Element
DATETIME_PATTERN, NAME, TYPE_PROPERTY
-
Fields inherited from interface org.gcube.informationsystem.base.reference.entities.EntityElement
NAME
-
Fields inherited from interface org.gcube.informationsystem.base.reference.IdentifiableElement
ID_PROPERTY, METADATA_PROPERTY
-
Fields inherited from interface org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate
DESCRIPTION_PROPERTY, NAME, NAME_PROPERTY, TEMPLATE_PROPERTY, TEMPLATE_VARIABLES_PROPERTY
-
-
Constructor Summary
Constructors Constructor Description QueryTemplateImpl()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTemplateVariable(TemplateVariable templateVariable)Adds a variable to the template.StringgetDescription()Returns the description of the query template.org.gcube.com.fasterxml.jackson.databind.JsonNodegetJsonQuery()Generates 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.StringgetName()Returns the name of the query template.org.gcube.com.fasterxml.jackson.databind.node.ObjectNodegetParamsFromDefaultValues()Creates anObjectNodecontaining the default values of all template variables.org.gcube.com.fasterxml.jackson.databind.JsonNodegetTemplate()Returns the template body as aJsonNode.StringgetTemplateAsString()Returns the template body as a string.Map<String,TemplateVariable>getTemplateVariables()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.voidsetName(String name)Sets 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, setMetadata
-
Methods inherited from class org.gcube.informationsystem.base.impl.ElementImpl
getTypeName, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.gcube.informationsystem.base.reference.Element
getTypeName
-
Methods inherited from interface org.gcube.informationsystem.base.reference.entities.EntityElement
getID, getMetadata, setID, setMetadata
-
-
-
-
Field Detail
-
name
protected String name
The name of the query template.
-
description
protected String description
The description of the query template.
-
objectMapper
protected org.gcube.com.fasterxml.jackson.databind.ObjectMapper objectMapper
The object mapper.
-
template
protected org.gcube.com.fasterxml.jackson.databind.JsonNode template
The template.
-
templateVariables
protected Map<String,TemplateVariable> templateVariables
The template variables.
-
params
protected org.gcube.com.fasterxml.jackson.databind.JsonNode params
The parameters.
-
-
Method Detail
-
getName
public String getName()
Returns the name of the query template.- Specified by:
getNamein interfaceQueryTemplate- Returns:
- The template name.
-
setName
public void setName(String name)
Sets the name of the query template.- Specified by:
setNamein interfaceQueryTemplate- Parameters:
name- The name to set.
-
getDescription
public String getDescription()
Returns the description of the query template.- Specified by:
getDescriptionin interfaceQueryTemplate- Returns:
- The template description.
-
setDescription
public void setDescription(String description)
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.JsonProcessingException
Returns 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
public Map<String,TemplateVariable> getTemplateVariables()
Returns the variables defined in this template.- Specified by:
getTemplateVariablesin interfaceQueryTemplate- Returns:
- A map of template variables, with variable names as keys.
-
addTemplateVariable
public void addTemplateVariable(TemplateVariable templateVariable)
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
public org.gcube.com.fasterxml.jackson.databind.JsonNode getJsonQuery() throws ExceptionGenerates 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 ExceptionReplaces 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 ExceptionGenerates 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.
-
-