Interface QueryTemplate
-
- All Superinterfaces:
Element,EntityElement,IdentifiableElement,Serializable
- All Known Implementing Classes:
QueryTemplateImpl
@TypeMetadata(name="QueryTemplate", description="The type used to store Query Templates", version="1.0.0") @Change(version="1.0.0", description="First Version") public interface QueryTemplate extends EntityElement
Represents a query template that can be used to generate runnable queries by substituting variables.- Author:
- Luca Frosini (ISTI - CNR)
-
-
Field Summary
Fields Modifier and Type Field Description static StringDESCRIPTION_PROPERTYThe property name for the template's description.static StringNAMEThe name of the QueryTemplate entity type.static StringNAME_PROPERTYThe property name for the template's name.static StringTEMPLATE_PROPERTYThe property name for the template's body.static StringTEMPLATE_VARIABLES_PROPERTYThe property name for the template's variables.-
Fields inherited from interface org.gcube.informationsystem.base.reference.Element
DATETIME_PATTERN, TYPE_PROPERTY
-
Fields inherited from interface org.gcube.informationsystem.base.reference.IdentifiableElement
ID_PROPERTY, METADATA_PROPERTY
-
-
Method Summary
All Methods Instance Methods Abstract 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.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 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
static final String NAME
The name of the QueryTemplate entity type.- See Also:
- Constant Field Values
-
NAME_PROPERTY
static final String NAME_PROPERTY
The property name for the template's name.- See Also:
- Constant Field Values
-
DESCRIPTION_PROPERTY
static final String DESCRIPTION_PROPERTY
The property name for the template's description.- See Also:
- Constant Field Values
-
TEMPLATE_PROPERTY
static final String TEMPLATE_PROPERTY
The property name for the template's body.- See Also:
- Constant Field Values
-
TEMPLATE_VARIABLES_PROPERTY
static final String TEMPLATE_VARIABLES_PROPERTY
The property name for the template's variables.- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
@ISProperty(name="name", description="The name of the Query Template. Among UUID univocally identifiy the Query Template.", readonly=true, mandatory=true, nullable=false) String getName()
Returns the name of the query template.- Returns:
- The template name.
-
setName
void setName(String name)
Sets the name of the query template.- Parameters:
name- The name to set.
-
getDescription
@ISProperty(name="description", description="The description of the Query Template.", readonly=false, mandatory=true, nullable=false) String getDescription()
Returns the description of the query template.- Returns:
- The template description.
-
setDescription
void setDescription(String description)
Sets the description of the query template.- Parameters:
description- The description to set.
-
getTemplateAsString
@ISProperty(name="template", description="The Query Template. It can contains query variables to be replaced to obtain a runnable query.", readonly=false, mandatory=true, nullable=false) String getTemplateAsString() throws org.gcube.com.fasterxml.jackson.core.JsonProcessingException
Returns the template body as a string.- Returns:
- The template as a string.
- Throws:
org.gcube.com.fasterxml.jackson.core.JsonProcessingException- if an error occurs during serialization.
-
setTemplate
void setTemplate(String template) throws org.gcube.com.fasterxml.jackson.core.JsonProcessingException, IOException
Sets the template body from a string.- Parameters:
template- The template string.- Throws:
IOException- if an error occurs during parsing.org.gcube.com.fasterxml.jackson.core.JsonProcessingException- if an error occurs during JSON processing.
-
setTemplate
void setTemplate(org.gcube.com.fasterxml.jackson.databind.JsonNode template)
Sets the template body from aJsonNode.- Parameters:
template- The template as aJsonNode.
-
getTemplate
org.gcube.com.fasterxml.jackson.databind.JsonNode getTemplate()
Returns the template body as aJsonNode.- Returns:
- The template as a
JsonNode.
-
getTemplateVariables
@ISProperty(name="templateVariables", description="The Query Template Variables. It can contains Query Template Variable to be replaced to obtain a runnable query.", readonly=false, mandatory=true, nullable=false) Map<String,TemplateVariable> getTemplateVariables()
Returns the variables defined in this template.- Returns:
- A map of template variables, with variable names as keys.
-
addTemplateVariable
void addTemplateVariable(TemplateVariable templateVariable)
Adds a variable to the template. If a variable with the same name already exists, it will be overridden.- Parameters:
templateVariable- The variable to add.
-
getParamsFromDefaultValues
org.gcube.com.fasterxml.jackson.databind.node.ObjectNode getParamsFromDefaultValues()
Creates anObjectNodecontaining the default values of all template variables.- Returns:
- An
ObjectNodewith default parameter values.
-
getJsonQuery
org.gcube.com.fasterxml.jackson.databind.JsonNode getJsonQuery() throws ExceptionGenerates a runnable query by substituting variables with their default values.- Returns:
- The generated query as a
JsonNode. - Throws:
Exception- if an error occurs during query generation.
-
getJsonQuery
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.- Parameters:
values- AJsonNodecontaining the values to substitute.- Returns:
- The generated query as a
JsonNode. - Throws:
Exception- if an error occurs during query generation.
-
-