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
FieldsModifier and TypeFieldDescriptionstatic final StringThe property name for the template's description.static final StringThe name of the QueryTemplate entity type.static final StringThe property name for the template's name.static final StringThe property name for the template's body.static final StringThe property name for the template's variables.Fields inherited from interface org.gcube.informationsystem.base.reference.Element
DATETIME_PATTERN, TYPE_PROPERTYFields inherited from interface org.gcube.informationsystem.base.reference.IdentifiableElement
ID_PROPERTY, METADATA_PROPERTY -
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.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 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 QueryTemplate entity type.- See Also:
-
NAME_PROPERTY
The property name for the template's name.- See Also:
-
DESCRIPTION_PROPERTY
The property name for the template's description.- See Also:
-
TEMPLATE_PROPERTY
The property name for the template's body.- See Also:
-
TEMPLATE_VARIABLES_PROPERTY
The property name for the template's variables.- See Also:
-
-
Method Details
-
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
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
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.JsonProcessingExceptionReturns 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
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
Generates 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 Exception Generates 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.
-