java.lang.Object
org.gcube.informationsystem.resourceregistry.queries.json.JsonQuery

public class JsonQuery extends Object
Translates a JSON Query-By-Example payload into the equivalent SQL/MATCH query text.

Purely a query-text builder: it holds no database connection and no collection-specific execution configuration (pagination, hierarchical scoping, metadata policy, ...). Execution is collection-specific and lives elsewhere — e.g. InstancesJsonQueryExecutor for the Instances collection, QueryTemplateManagement.query(String) for Query Templates, ContextManagement.query(String) for Contexts — each opens its own environment/connection and serializes results its own way, since these differ too much across collections (different environments, different visibility/serialization concerns) to be meaningfully unified under one execution method.

Author:
Luca Frosini (ISTI - CNR)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The parsed root query element helper.
    protected org.gcube.com.fasterxml.jackson.databind.JsonNode
    The input JSON query structure tree node.
    protected boolean
    Whether the caller reads the sensitive metadata identity fields redacted.
    protected org.gcube.com.fasterxml.jackson.databind.ObjectMapper
    In-use Jackson object mapper.
    protected boolean
    Whether the entry-point match may include registered subtypes.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new JsonQuery instance with default ObjectMapper.
  • Method Summary

    Modifier and Type
    Method
    Description
    Builds and returns the SQL MATCH query string buffer equivalent to this JSON query representation.
    Builds and returns the SQL query string buffer equivalent to this JSON query representation.
    Returns the parsed root query element helper resolved by the last createQuery()/ createMatchQuery() call.
    org.gcube.com.fasterxml.jackson.databind.JsonNode
    Returns the input JSON query tree node.
    getJsonQueryElement(org.gcube.com.fasterxml.jackson.databind.JsonNode jsonQuery)
    Factory helper to instantiate the appropriate JsonQueryElement subclass for the specified JSON query root node.
    Returns the named parameters generated for the current query text.
    void
    setJsonQuery(String jsonQuery)
    Parses and sets the input JSON query string.
    void
    setJsonQuery(org.gcube.com.fasterxml.jackson.databind.JsonNode jsonQuery)
    Sets the input JSON query tree node.
    void
    setMaskMetadata(boolean maskMetadata)
    Configures the representation the query is evaluated on: the sensitive metadata identity fields are read as stored, or as the redacted constant the caller is shown.
    void
    setPolymorphic(boolean polymorphic)
    Configures whether the entry-point match includes registered subtypes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • objectMapper

      protected org.gcube.com.fasterxml.jackson.databind.ObjectMapper objectMapper
      In-use Jackson object mapper.
    • jsonQuery

      protected org.gcube.com.fasterxml.jackson.databind.JsonNode jsonQuery
      The input JSON query structure tree node.
    • entryPoint

      protected JsonQueryElement entryPoint
      The parsed root query element helper.
    • polymorphic

      protected boolean polymorphic
      Whether the entry-point match may include registered subtypes.
    • maskMetadata

      protected boolean maskMetadata
      Whether the caller reads the sensitive metadata identity fields redacted.
  • Constructor Details

    • JsonQuery

      public JsonQuery()
      Creates a new JsonQuery instance with default ObjectMapper.
  • Method Details

    • setPolymorphic

      public void setPolymorphic(boolean polymorphic)
      Configures whether the entry-point match includes registered subtypes.
      Parameters:
      polymorphic - true for polymorphic matching; false for the exact Type
    • setMaskMetadata

      public void setMaskMetadata(boolean maskMetadata)
      Configures the representation the query is evaluated on: the sensitive metadata identity fields are read as stored, or as the redacted constant the caller is shown.
      Parameters:
      maskMetadata - true if the caller reads the sensitive metadata identity fields redacted
    • getJsonQuery

      public org.gcube.com.fasterxml.jackson.databind.JsonNode getJsonQuery()
      Returns the input JSON query tree node.
      Returns:
      the JSON query node
    • setJsonQuery

      public void setJsonQuery(org.gcube.com.fasterxml.jackson.databind.JsonNode jsonQuery)
      Sets the input JSON query tree node.
      Parameters:
      jsonQuery - the JSON query node
    • setJsonQuery

      public void setJsonQuery(String jsonQuery) throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException
      Parses and sets the input JSON query string.
      Parameters:
      jsonQuery - the JSON query string
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if the JSON string is invalid
    • getEntryPoint

      public JsonQueryElement getEntryPoint()
      Returns the parsed root query element helper resolved by the last createQuery()/ createMatchQuery() call.
      Returns:
      the entry-point query element, or null if no query has been built yet
    • getQueryParameters

      public Map<String,Object> getQueryParameters()
      Returns the named parameters generated for the current query text.
      Returns:
      generated OrientDB named parameters
    • getJsonQueryElement

      public static JsonQueryElement getJsonQueryElement(org.gcube.com.fasterxml.jackson.databind.JsonNode jsonQuery) throws org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Factory helper to instantiate the appropriate JsonQueryElement subclass for the specified JSON query root node.
      Parameters:
      jsonQuery - the JSON query node
      Returns:
      the corresponding JsonQueryElement subclass helper
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if the query root does not declare a string type
      org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException - if the query target type is not registered
      org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException - if the schema type definition is invalid
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database or lookup error
    • createQuery

      public StringBuffer createQuery() throws org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException, org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Builds and returns the SQL query string buffer equivalent to this JSON query representation.
      Returns:
      SQL query string buffer
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException - if schema traversal fails
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if query syntax or constraints are violated
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database error
    • createMatchQuery

      public StringBuffer createMatchQuery() throws org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException, org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Builds and returns the SQL MATCH query string buffer equivalent to this JSON query representation.
      Returns:
      SQL MATCH query string buffer
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException - if schema traversal fails
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if query syntax or constraints are violated
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database error