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, contextsPolicy, metadataPolicy, and the
MembershipView.
- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether the active-only hierarchical reader channel must be used.protected org.gcube.informationsystem.resourceregistry.api.rest.ContextsPolicyThe contexts inclusion policy.protected booleanWhether hierarchical lookup is enabled.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 MembershipViewThe view that selects the memberships listed by thecontextsmap of each result.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.voidsetContextsPolicy(org.gcube.informationsystem.resourceregistry.api.rest.ContextsPolicy contextsPolicy) Sets the contexts inclusion policy.voidsetHierarchical(boolean hierarchical) Sets whether hierarchical lookup is enabled.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.voidsetMembershipView(MembershipView membershipView) Sets the view that selects the memberships listed by thecontextsmap of each result.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. -
contextsPolicy
protected org.gcube.informationsystem.resourceregistry.api.rest.ContextsPolicy contextsPolicyThe contexts inclusion policy. -
membershipView
The view that selects the memberships listed by thecontextsmap of each result. -
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. -
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
-
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
Sets the view that selects the memberships listed by thecontextsmap 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_emitaliases.- Parameters:
maskMetadata-trueto redact sensitive metadata identity fields
-
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/contextsPolicyentirely - 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
-