Class QueryTemplateRepository
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 ClassesModifier and TypeClassDescriptionstatic final recordResult payload and shape produced by a Query Template JSON query. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateOrUpdate(String queryTemplateName, String json, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy) Creates or updates a Query Template.voidDeletes 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, org.gcube.informationsystem.resourceregistry.api.rest.ContextsPolicy contextsPolicy, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy, boolean maskMetadata, MembershipView membershipView) Executes the Query Template with the specified name and parameters.
-
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 returnoffset- the number of results to skipmetadataPolicy- 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 returnoffset- the number of results to skipmetadataPolicy- the metadata inclusion policy to applymaskMetadata- 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 criterialimit- the maximum number of results to returnoffset- the number of results to skipmetadataPolicy- 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 incorrectorg.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 criterialimit- the maximum number of results to returnoffset- the number of results to skipmetadataPolicy- the metadata inclusion policy to apply to full representationsmaskMetadata- 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 incorrectorg.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 readmetadataPolicy- 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 existorg.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 readmetadataPolicy- the metadata inclusion policy to applymaskMetadata- 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 existorg.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, org.gcube.informationsystem.resourceregistry.api.rest.ContextsPolicy contextsPolicy, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy, boolean maskMetadata, MembershipView membershipView) 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 executeparams- JSON object containing parameter values for template substitutionlimit- the maximum number of results to return (peek-adjusted by the caller for pagination)offset- the number of results to skippolymorphic- whether to include instances of subtypes in the resultshierarchical- whether to expand the search boundary to descendant ContextsactiveOnlyHierarchical- whether hierarchical execution must hide non-active descendant ContextscontextsPolicy- the contexts inclusion policy to applymetadataPolicy- the metadata inclusion policy to applymaskMetadata- whether to redact sensitive metadata identity fieldsmembershipView- the view that selects the memberships listed by eachcontextsmap- 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 existorg.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException- if the query execution failsorg.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 updatejson- the raw Query Template JSON definitionmetadataPolicy- 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 foundorg.gcube.informationsystem.resourceregistry.api.exceptions.instances.AvailableInAnotherContextException- if the Query Template is available in another contextorg.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 existorg.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- if deletion fails
-