Class InstancesJsonQueryExecutor

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

public class InstancesJsonQueryExecutor extends Object
Executes a JSON Query-By-Example against the Instances collection, enforcing role-based and context-scoped security rules.

Wraps a JsonQuery builder to obtain the SQL query text (query-text generation is generic across collections; execution is not), then opens the current request's InstanceEnvironment, runs the query, and serializes each matched element via ERManagementUtility/ERManagement, honouring polymorphic, hierarchical, contextsPolicy, metadataPolicy, and the MembershipView.

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

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    Whether the active-only hierarchical reader channel must be used.
    protected org.gcube.informationsystem.resourceregistry.api.rest.ContextsPolicy
    The contexts inclusion policy.
    protected boolean
    Whether hierarchical lookup is enabled.
    protected final JsonQuery
    The underlying query-text builder.
    protected Integer
    The pagination limit for the query.
    protected boolean
    Whether privacy-sensitive metadata identity fields must be masked.
    protected MembershipView
    The view that selects the memberships listed by the contexts map of each result.
    protected org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy
    The metadata inclusion policy.
    protected com.orientechnologies.orient.core.db.document.ODatabaseDocument
    The active OrientDB database session.
    protected Integer
    The pagination offset for the query.
    protected boolean
    Whether the query results should include subtypes (polymorphic).
    protected boolean
    Whether the last query() was projection-based (an _emit block was present), set only after query() runs.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new InstancesJsonQueryExecutor instance with default configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Reports whether the query executed by the last query() call was projection-based (i.e. contained an _emit block anywhere in its tree).
    Executes the JSON query, enforcing role-based and context-scoped security rules.
    void
    setActiveOnlyHierarchical(boolean activeOnlyHierarchical)
    Sets whether the active-only hierarchical reader channel must be used instead of the unrestricted one.
    void
    setContextsPolicy(org.gcube.informationsystem.resourceregistry.api.rest.ContextsPolicy contextsPolicy)
    Sets the contexts inclusion policy.
    void
    setHierarchical(boolean hierarchical)
    Sets whether hierarchical lookup is enabled.
    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
    Sets the pagination limit.
    void
    setMaskMetadata(boolean maskMetadata)
    Configures privacy masking for full representations and _emit aliases.
    void
    Sets the view that selects the memberships listed by the contexts map of each result.
    void
    setMetadataPolicy(org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy)
    Sets the metadata policy.
    void
    Sets the pagination offset.
    void
    setPolymorphic(boolean polymorphic)
    Sets whether polymorphic query is enabled.

    Methods inherited from class java.lang.Object

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

    • jsonQueryBuilder

      protected final JsonQuery jsonQueryBuilder
      The underlying query-text builder.
    • oDatabaseDocument

      protected com.orientechnologies.orient.core.db.document.ODatabaseDocument oDatabaseDocument
      The active OrientDB database session.
    • limit

      protected Integer limit
      The pagination limit for the query.
    • offset

      protected Integer offset
      The pagination offset for the query.
    • polymorphic

      protected boolean polymorphic
      Whether the query results should include subtypes (polymorphic).
    • hierarchical

      protected boolean hierarchical
      Whether hierarchical lookup is enabled.
    • activeOnlyHierarchical

      protected boolean activeOnlyHierarchical
      Whether the active-only hierarchical reader channel must be used.
    • contextsPolicy

      protected org.gcube.informationsystem.resourceregistry.api.rest.ContextsPolicy contextsPolicy
      The contexts inclusion policy.
    • membershipView

      protected MembershipView membershipView
      The view that selects the memberships listed by the contexts map of each result.
    • metadataPolicy

      protected org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy
      The metadata inclusion policy.
    • maskMetadata

      protected boolean maskMetadata
      Whether privacy-sensitive metadata identity fields must be masked.
    • projection

      protected boolean projection
      Whether the last query() was projection-based (an _emit block was present), set only after query() runs.
  • Constructor Details

    • InstancesJsonQueryExecutor

      public InstancesJsonQueryExecutor()
      Creates a new InstancesJsonQueryExecutor instance with default configuration.
  • Method Details

    • 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
    • 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
    • setLimit

      public void setLimit(Integer limit)
      Sets the pagination limit.
      Parameters:
      limit - the limit to set
    • setOffset

      public void setOffset(Integer offset)
      Sets the pagination offset.
      Parameters:
      offset - the offset to set
    • setPolymorphic

      public void setPolymorphic(boolean polymorphic)
      Sets whether polymorphic query is enabled.
      Parameters:
      polymorphic - true to enable polymorphic results, false otherwise
    • setHierarchical

      public void setHierarchical(boolean hierarchical)
      Sets whether hierarchical lookup is enabled.
      Parameters:
      hierarchical - true to enable hierarchical, false otherwise
    • setActiveOnlyHierarchical

      public void setActiveOnlyHierarchical(boolean activeOnlyHierarchical)
      Sets whether the active-only hierarchical reader channel must be used instead of the unrestricted one. Meaningless unless setHierarchical(boolean) is also true.
      Parameters:
      activeOnlyHierarchical - true to use the active-only channel
    • setContextsPolicy

      public void setContextsPolicy(org.gcube.informationsystem.resourceregistry.api.rest.ContextsPolicy contextsPolicy)
      Sets the contexts inclusion policy.
      Parameters:
      contextsPolicy - the contexts policy to set
    • setMembershipView

      public void setMembershipView(MembershipView membershipView)
      Sets the view that selects the memberships listed by the contexts map of each result. Defaults to the unrestricted view if never called.
      Parameters:
      membershipView - the membership view to apply
    • setMetadataPolicy

      public void setMetadataPolicy(org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy)
      Sets the metadata policy.
      Parameters:
      metadataPolicy - the metadata policy to set
    • setMaskMetadata

      public void setMaskMetadata(boolean maskMetadata)
      Configures privacy masking for full representations and _emit aliases.
      Parameters:
      maskMetadata - true to redact sensitive metadata identity fields
    • isProjection

      public boolean isProjection()
      Reports whether the query executed by the last query() call was projection-based (i.e. contained an _emit block anywhere in its tree). Per the Canonical _emit Precedence Rules, a projecting query ignores metadataPolicy/contextsPolicy entirely - callers use this to report that fact back to the client via a QueryParameterWarning.
      Returns:
      true if the last executed query was projection-based, false otherwise (including before the first query() call)
    • query

      public String query() throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Executes the JSON query, enforcing role-based and context-scoped security rules.
      Returns:
      JSON array string of query results
      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 error