All Implemented Interfaces:
Serializable, Element, EntityElement, IdentifiableElement, QueryTemplate

public class QueryTemplateImpl extends EntityElementImpl implements QueryTemplate
The default implementation of the QueryTemplate interface.
Author:
Luca Frosini (ISTI - CNR)
See Also:
  • Field Details

    • 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.
  • Constructor Details

    • QueryTemplateImpl

      public QueryTemplateImpl()
      Default constructor.
  • Method Details

    • getName

      public String getName()
      Returns the name of the query template.
      Specified by:
      getName in interface QueryTemplate
      Returns:
      The template name.
    • setName

      public void setName(String name)
      Sets the name of the query template.
      Specified by:
      setName in interface QueryTemplate
      Parameters:
      name - The name to set.
    • getDescription

      public String getDescription()
      Returns the description of the query template.
      Specified by:
      getDescription in interface QueryTemplate
      Returns:
      The template description.
    • setDescription

      public void setDescription(String description)
      Sets the description of the query template.
      Specified by:
      setDescription in interface QueryTemplate
      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:
      getTemplateAsString in interface QueryTemplate
      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:
      setTemplate in interface QueryTemplate
      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 a JsonNode.
      Specified by:
      getTemplate in interface QueryTemplate
      Returns:
      The template as a JsonNode.
    • setTemplate

      public void setTemplate(org.gcube.com.fasterxml.jackson.databind.JsonNode template)
      Sets the template body from a JsonNode.
      Specified by:
      setTemplate in interface QueryTemplate
      Parameters:
      template - The template as a JsonNode.
    • getTemplateVariables

      public Map<String,TemplateVariable> getTemplateVariables()
      Returns the variables defined in this template.
      Specified by:
      getTemplateVariables in interface QueryTemplate
      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:
      addTemplateVariable in interface QueryTemplate
      Parameters:
      templateVariable - The variable to add.
    • getParamsFromDefaultValues

      public org.gcube.com.fasterxml.jackson.databind.node.ObjectNode getParamsFromDefaultValues()
      Creates an ObjectNode containing the default values of all template variables.
      Specified by:
      getParamsFromDefaultValues in interface QueryTemplate
      Returns:
      An ObjectNode with default parameter values.
    • getJsonQuery

      public org.gcube.com.fasterxml.jackson.databind.JsonNode getJsonQuery() throws Exception
      Generates a runnable query by substituting variables with their default values.
      Specified by:
      getJsonQuery in interface QueryTemplate
      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:
      getJsonQuery in interface QueryTemplate
      Parameters:
      values - A JsonNode containing the values to substitute.
      Returns:
      The generated query as a JsonNode.
      Throws:
      Exception - if an error occurs during query generation.