Class InstancesJsonQueryExecutor
java.lang.Object
org.gcube.informationsystem.resourceregistry.queries.json.InstancesJsonQueryExecutor
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, includeContexts, metadataPolicy, and
ContextVisibilityPolicy.
- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether the active-only hierarchical reader channel must be used.protected ContextVisibilityPolicyThe Context visibility policy applied to thecontextsmap of each result, whenincludeContextsis set.protected StringThe caller's own Context path, required byContextVisibilityPolicy.DESCENDANTSfiltering.protected booleanWhether descendant Contexts with a non-ACTIVEeffectiveStateare additionally filtered out of thecontextsmap.protected booleanWhether hierarchical lookup is enabled.protected booleanWhether to include context availability information in results.protected final JsonQueryThe underlying query-text builder.protected IntegerThe pagination limit for the query.protected booleanWhether privacy-sensitive metadata identity fields must be masked.protected org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicyThe metadata inclusion policy.protected com.orientechnologies.orient.core.db.document.ODatabaseDocumentThe active OrientDB database session.protected IntegerThe pagination offset for the query.protected booleanWhether the query results should include subtypes (polymorphic).protected boolean -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newInstancesJsonQueryExecutorinstance with default configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcollectSensitiveEmitAliases(org.gcube.com.fasterxml.jackson.databind.JsonNode node, Set<String> sensitiveAliases) Recursively scans the query JSON for all_emitblocks and collects the result-column aliases that correspond to privacy-sensitive metadata fields (metadata.createdByandmetadata.lastUpdateBy).booleanReports whether the query executed by the lastquery()call was projection-based (i.e. contained an_emitblock anywhere in its tree).query()Executes the JSON query, enforcing role-based and context-scoped security rules.voidsetActiveOnlyHierarchical(boolean activeOnlyHierarchical) Sets whether the active-only hierarchical reader channel must be used instead of the unrestricted one.voidsetContextVisibilityPolicy(ContextVisibilityPolicy contextVisibilityPolicy) Sets the Context visibility policy applied to thecontextsmap of each result, whenincludeContextsis set.voidsetCurrentContextPath(String currentContextPath) Sets the caller's own Context path, required byContextVisibilityPolicy.DESCENDANTSfiltering.voidsetFilterNonActiveDescendants(boolean filterNonActiveDescendants) Sets whether descendant Contexts with a non-ACTIVEeffectiveStatemust additionally be filtered out of thecontextsmap, on top of whateversetContextVisibilityPolicy(ContextVisibilityPolicy)already applies.voidsetHierarchical(boolean hierarchical) Sets whether hierarchical lookup is enabled.voidsetIncludeContexts(boolean includeContexts) Sets whether to include contexts in results.voidsetJsonQuery(String jsonQuery) Parses and sets the input JSON query string.voidsetJsonQuery(org.gcube.com.fasterxml.jackson.databind.JsonNode jsonQuery) Sets the input JSON query tree node.voidSets the pagination limit.voidsetMaskMetadata(boolean maskMetadata) Configures privacy masking for full representations and_emitaliases.voidsetMetadataPolicy(org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy) Sets the metadata policy.voidSets the pagination offset.voidsetPolymorphic(boolean polymorphic) Sets whether polymorphic query is enabled.
-
Field Details
-
jsonQueryBuilder
The underlying query-text builder. -
oDatabaseDocument
protected com.orientechnologies.orient.core.db.document.ODatabaseDocument oDatabaseDocumentThe active OrientDB database session. -
limit
The pagination limit for the query. -
offset
The pagination offset for the query. -
polymorphic
protected boolean polymorphicWhether the query results should include subtypes (polymorphic). -
hierarchical
protected boolean hierarchicalWhether hierarchical lookup is enabled. -
activeOnlyHierarchical
protected boolean activeOnlyHierarchicalWhether the active-only hierarchical reader channel must be used. -
includeContexts
protected boolean includeContextsWhether to include context availability information in results. -
metadataPolicy
protected org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicyThe metadata inclusion policy. -
maskMetadata
protected boolean maskMetadataWhether privacy-sensitive metadata identity fields must be masked. -
contextVisibilityPolicy
The Context visibility policy applied to thecontextsmap of each result, whenincludeContextsis set. -
currentContextPath
The caller's own Context path, required byContextVisibilityPolicy.DESCENDANTSfiltering. -
filterNonActiveDescendants
protected boolean filterNonActiveDescendantsWhether descendant Contexts with a non-ACTIVEeffectiveStateare additionally filtered out of thecontextsmap. -
projection
protected boolean projection
-
-
Constructor Details
-
InstancesJsonQueryExecutor
public InstancesJsonQueryExecutor()Creates a newInstancesJsonQueryExecutorinstance 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
Sets the pagination limit.- Parameters:
limit- the limit to set
-
setOffset
Sets the pagination offset.- Parameters:
offset- the offset to set
-
setPolymorphic
public void setPolymorphic(boolean polymorphic) Sets whether polymorphic query is enabled.- Parameters:
polymorphic-trueto enable polymorphic results,falseotherwise
-
setHierarchical
public void setHierarchical(boolean hierarchical) Sets whether hierarchical lookup is enabled.- Parameters:
hierarchical-trueto enable hierarchical,falseotherwise
-
setActiveOnlyHierarchical
public void setActiveOnlyHierarchical(boolean activeOnlyHierarchical) Sets whether the active-only hierarchical reader channel must be used instead of the unrestricted one. Meaningless unlesssetHierarchical(boolean)is alsotrue.- Parameters:
activeOnlyHierarchical-trueto use the active-only channel
-
setIncludeContexts
public void setIncludeContexts(boolean includeContexts) Sets whether to include contexts in results.- Parameters:
includeContexts-trueto enable includeContexts,falseotherwise
-
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_emitaliases.- Parameters:
maskMetadata-trueto redact sensitive metadata identity fields
-
setContextVisibilityPolicy
Sets the Context visibility policy applied to thecontextsmap of each result, whenincludeContextsis set. Must be resolved and set by the caller (PEP or Management class) based on the current caller's role; defaults to unfilteredContextVisibilityPolicy.ALLif never called.- Parameters:
contextVisibilityPolicy- the ContextVisibilityPolicy to apply
-
setCurrentContextPath
Sets the caller's own Context path, required byContextVisibilityPolicy.DESCENDANTSfiltering.- Parameters:
currentContextPath- the current context path to apply
-
setFilterNonActiveDescendants
public void setFilterNonActiveDescendants(boolean filterNonActiveDescendants) Sets whether descendant Contexts with a non-ACTIVEeffectiveStatemust additionally be filtered out of thecontextsmap, on top of whateversetContextVisibilityPolicy(ContextVisibilityPolicy)already applies.- Parameters:
filterNonActiveDescendants-trueto filter non-ACTIVEdescendants
-
isProjection
public boolean isProjection()Reports whether the query executed by the lastquery()call was projection-based (i.e. contained an_emitblock anywhere in its tree). Per the Canonical_emitPrecedence Rules, a projecting query ignoresmetadataPolicy/includeContextsentirely - callers use this to report that fact back to the client via aQueryParameterWarning.- Returns:
trueif the last executed query was projection-based,falseotherwise (including before the firstquery()call)
-
collectSensitiveEmitAliases
protected void collectSensitiveEmitAliases(org.gcube.com.fasterxml.jackson.databind.JsonNode node, Set<String> sensitiveAliases) Recursively scans the query JSON for all_emitblocks and collects the result-column aliases that correspond to privacy-sensitive metadata fields (metadata.createdByandmetadata.lastUpdateBy).In an
_emitblock the JSON structure is"<fieldPath>": "<alias>", so the alias (value) is what OrientDB returns as the column name in the result set.- Parameters:
node- the JSON node to scan (call with the root query node)sensitiveAliases- the set to populate
-
query
public String query() throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryExceptionExecutes 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 incorrectorg.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- on database error
-