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 Map<Version,String>changelogThe changelog of the query template.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.protected VersionversionThe version of the query template.-
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, REDACTED, TYPE_PROPERTY, UNKNOWN_USER
-
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
CHANGELOG_PROPERTY, DESCRIPTION_PROPERTY, NAME, NAME_PROPERTY, TEMPLATE_PROPERTY, TEMPLATE_VARIABLES_PROPERTY, VERSION_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.Map<Version,String>getChangelog()Returns the changelog of the query template.Map<String,String>getChangelogWithVersionAsString()Returns the changelog with versions represented as strings.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.VersiongetVersion()Returns the version of the query template.StringgetVersionAsString()Returns the version of the query template as a string.protected org.gcube.com.fasterxml.jackson.databind.JsonNodereplaceVariables(org.gcube.com.fasterxml.jackson.databind.JsonNode jsonNode)Replaces the variables in the given JSON node.voidsetChangelog(Map<String,String> changelog)Sets the changelog of the query 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.voidsetVersion(String version)Sets the version of the query template.-
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.
-
version
protected Version version
The version 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.
-
getVersion
public Version getVersion()
Returns the version of the query template.- Specified by:
getVersionin interfaceQueryTemplate- Returns:
- The template version, or
nullwhen not set.
-
getVersionAsString
public String getVersionAsString()
Returns the version of the query template as a string.- Specified by:
getVersionAsStringin interfaceQueryTemplate- Returns:
- The version string, or
nullwhen not set.
-
setVersion
public void setVersion(String version)
Sets the version of the query template.- Specified by:
setVersionin interfaceQueryTemplate- Parameters:
version- The version string, in the form major.minor.patch.
-
getChangelog
public Map<Version,String> getChangelog()
Returns the changelog of the query template.- Specified by:
getChangelogin interfaceQueryTemplate- Returns:
- A map of versions to change descriptions, or
nullwhen not set.
-
getChangelogWithVersionAsString
public Map<String,String> getChangelogWithVersionAsString()
Returns the changelog with versions represented as strings.- Specified by:
getChangelogWithVersionAsStringin interfaceQueryTemplate- Returns:
- A map of version strings to change descriptions, or
nullwhen not set.
-
setChangelog
public void setChangelog(Map<String,String> changelog)
Sets the changelog of the query template.- Specified by:
setChangelogin interfaceQueryTemplate- Parameters:
changelog- A map of version strings to change descriptions.
-
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. Every string node whose entire value equals a declared variable name, as an object value or as an array element at any depth, is replaced by the variable's value node. Object keys are not substitution targets, strings are never partially interpolated, and inserted values are not scanned again.- Parameters:
jsonNode- the JSON node- Returns:
- the JSON node with the variables replaced
- Throws:
Exception- if a variable has neither a provided value nor a default value
-
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.
-
-