java.lang.Object
org.gcube.informationsystem.resourceregistry.queries.templates.QueryTemplateRepository

public class QueryTemplateRepository extends Object
Single data-access layer for QueryTemplate entities.

This is the sole point of contact between QueryTemplatePolicyEnforcementPoint (DB-agnostic by design) and QueryTemplateManagement (the OrientDB-specific implementation, isolated under persistence.orientdb). Mirrors the same layering already established for the Context collection (ContextRepository / ContextManagement): when the persistence backend changes (e.g. to PostgreSQL), only this class needs to be rewritten against the new backend's management/DAO class — QueryTemplatePolicyEnforcementPoint and every REST-facing caller remain untouched.

This class has zero auth logic: role/visibility decisions are made exclusively by QueryTemplatePolicyEnforcementPoint and passed in as plain parameters (already-resolved limit/offset/MetadataPolicy).

Author:
Luca Frosini (ISTI - CNR)
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    Result payload and shape produced by a Query Template JSON query.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    createOrUpdate(String queryTemplateName, String json, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy)
    Creates or updates a Query Template.
    void
    delete(String queryTemplateName)
    Deletes the Query Template with the specified name.
    list(int limit, int offset, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy)
    Lists all Query Templates.
    list(int limit, int offset, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy, boolean maskMetadata)
    Lists all Query Templates with the requested metadata identity policy.
    query(String jsonQuery, int limit, int offset, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy)
    Executes a JSON query against the Query Template collection, returning matching Query Template definitions (not their execution results).
    queryWithDetails(String jsonQuery, int limit, int offset, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy, boolean maskMetadata)
    Executes a Query Template JSON query and reports whether its result is projection-based.
    read(String queryTemplateName, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy)
    Reads a single Query Template by name.
    read(String queryTemplateName, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy, boolean maskMetadata)
    Reads a single Query Template with the requested metadata identity policy.
    run(String queryTemplateName, String params, int limit, int offset, boolean polymorphic, boolean hierarchical, boolean activeOnlyHierarchical, boolean includeContexts, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy, boolean maskMetadata, ContextVisibilityPolicy contextVisibilityPolicy, String currentContextPath, boolean filterNonActiveDescendants)
    Executes the Query Template with the specified name and parameters.

    Methods inherited from class java.lang.Object

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

    • QueryTemplateRepository

      public QueryTemplateRepository()
  • Method Details

    • list

      public String list(int limit, int offset, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Lists all Query Templates.
      Parameters:
      limit - the maximum number of results to return
      offset - the number of results to skip
      metadataPolicy - the metadata inclusion policy to apply
      Returns:
      JSON array string of Query Template definitions
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database or read failure
    • list

      public String list(int limit, int offset, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy, boolean maskMetadata) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Lists all Query Templates with the requested metadata identity policy.
      Parameters:
      limit - the maximum number of results to return
      offset - the number of results to skip
      metadataPolicy - the metadata inclusion policy to apply
      maskMetadata - whether to redact sensitive metadata identity fields
      Returns:
      JSON array string of Query Template definitions
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database or read failure
    • query

      public String query(String jsonQuery, int limit, int offset, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy) throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Executes a JSON query against the Query Template collection, returning matching Query Template definitions (not their execution results).
      Parameters:
      jsonQuery - the JSON query payload describing the Query Template search criteria
      limit - the maximum number of results to return
      offset - the number of results to skip
      metadataPolicy - the metadata inclusion policy to apply
      Returns:
      JSON array string of matching Query Template definitions
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if the query is invalid or syntactically incorrect
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database or processing failure
    • queryWithDetails

      public QueryTemplateRepository.QueryTemplateQueryResult queryWithDetails(String jsonQuery, int limit, int offset, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy, boolean maskMetadata) throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Executes a Query Template JSON query and reports whether its result is projection-based.
      Parameters:
      jsonQuery - the JSON query payload describing the Query Template search criteria
      limit - the maximum number of results to return
      offset - the number of results to skip
      metadataPolicy - the metadata inclusion policy to apply to full representations
      maskMetadata - whether sensitive metadata identity fields must be redacted
      Returns:
      the serialized result and its projection flag
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if the query is invalid or syntactically incorrect
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database or processing failure
    • read

      public String read(String queryTemplateName, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy) throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Reads a single Query Template by name.
      Parameters:
      queryTemplateName - the name of the Query Template to read
      metadataPolicy - the metadata inclusion policy to apply
      Returns:
      the serialized JSON representation of the Query Template
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the Query Template does not exist
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the lookup fails
    • read

      public String read(String queryTemplateName, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy, boolean maskMetadata) throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Reads a single Query Template with the requested metadata identity policy.
      Parameters:
      queryTemplateName - the name of the Query Template to read
      metadataPolicy - the metadata inclusion policy to apply
      maskMetadata - whether to redact sensitive metadata identity fields
      Returns:
      the serialized JSON representation of the Query Template
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the Query Template does not exist
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the lookup fails
    • run

      public TemplateExecutionResult run(String queryTemplateName, String params, int limit, int offset, boolean polymorphic, boolean hierarchical, boolean activeOnlyHierarchical, boolean includeContexts, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy, boolean maskMetadata, ContextVisibilityPolicy contextVisibilityPolicy, String currentContextPath, boolean filterNonActiveDescendants) throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Executes the Query Template with the specified name and parameters.
      Parameters:
      queryTemplateName - the name of the Query Template to execute
      params - JSON object containing parameter values for template substitution
      limit - the maximum number of results to return (peek-adjusted by the caller for pagination)
      offset - the number of results to skip
      polymorphic - whether to include instances of subtypes in the results
      hierarchical - whether to expand the search boundary to descendant Contexts
      activeOnlyHierarchical - whether hierarchical execution must hide non-active descendant Contexts
      includeContexts - whether to include the list of contexts where each result is available
      metadataPolicy - the metadata inclusion policy to apply
      maskMetadata - whether to redact sensitive metadata identity fields
      contextVisibilityPolicy - the context visibility policy to apply to results
      currentContextPath - the caller's current Context path (used when contextVisibilityPolicy is not ContextVisibilityPolicy.ALL)
      filterNonActiveDescendants - whether non-active descendant memberships must be omitted
      Returns:
      the JSON array string of query results together with whether the query was projection-based (see TemplateExecutionResult)
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the Query Template does not exist
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if the query execution fails
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database or processing failure
    • createOrUpdate

      public QueryTemplateCreationResult createOrUpdate(String queryTemplateName, String json, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy) throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.instances.AvailableInAnotherContextException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Creates or updates a Query Template.
      Parameters:
      queryTemplateName - the name of the Query Template to create or update
      json - the raw Query Template JSON definition
      metadataPolicy - the metadata inclusion policy to apply
      Returns:
      the outcome, carrying the serialized JSON representation of the created/updated Query Template and a created/updated flag
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if referenced dependencies are not found
      org.gcube.informationsystem.resourceregistry.api.exceptions.instances.AvailableInAnotherContextException - if the Query Template is available in another context
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the creation or update fails
    • delete

      public void delete(String queryTemplateName) throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Deletes the Query Template with the specified name.
      Parameters:
      queryTemplateName - the name of the Query Template to delete
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the Query Template does not exist
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if deletion fails