Class TypeRepository
java.lang.Object
org.gcube.informationsystem.resourceregistry.types.TypeRepository
Orchestrator and repository layer for managing resource and facet Schema Types.
Coordinates database access via
TypeManagement and passive key-value
caching via RedisTypeCache, adhering strictly to the All-or-Nothing
cache consistency strategy.- Author:
- Luca Frosini (ISTI - CNR)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult payload and shape produced by a Type JSON query. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreate(String json, org.gcube.informationsystem.types.reference.Type type, boolean preservePassedMetadata) Registers a new type, optionally preserving themetadataobject already present in the submitted JSON instead of autofilling it from the current caller and clock.create(String json, org.gcube.informationsystem.types.reference.Type type, boolean preservePassedMetadata, boolean allowUnresolvedResourceReferences) Registers a new type, optionally allowing aResourceSchema's own forward-declaredconsistsOf/isRelatedTorelation-type reference (and, forisRelatedToonly, its target Resource type) to not exist yet.create(String json, org.gcube.informationsystem.types.reference.Type type, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy) Registers a new Type definition in the database and adds it to the cache.booleanDeletes the specified type schema and its definition from the database.booleanReturns whether the Redis cache is currently bypassed.Loads every Type definition from the database as an immutable, version-stampedSchemaSnapshot.intpopulateCacheFrom(SchemaSnapshot snapshot) Repopulates the Redis type cache from a snapshot, in a single pipelined batch.query(String jsonQuery, int limit, int offset, int depth, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy) Executes a JSON query against the Types collection (schema definitions), returning matching Type definitions.queryWithDetails(String jsonQuery, int limit, int offset, int depth, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy, boolean maskMetadata) Executes a Type JSON query and reports whether its result is projection-based.read(String typeName, int depth, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy) Reads the serialized JSON representation of a Type and optionally all of its subtypes down to a specified depth.read(String typeName, int depth, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy, boolean maskMetadata) Reads a Type by name while applying metadata inclusion and identity masking.voidsetCacheBypass(boolean bypass) Configures whether the Redis cache should be completely bypassed.update(String typeName, String json, org.gcube.informationsystem.types.reference.Type type, boolean skipVersionCheckOnUpdate) Updates an existing Type definition in the database;TypeManagementempties the cache.voidLoads a snapshot and repopulates the Redis type cache from it.
-
Constructor Details
-
TypeRepository
public TypeRepository()Constructor to instantiate TypeRepository.
-
-
Method Details
-
setCacheBypass
public void setCacheBypass(boolean bypass) Configures whether the Redis cache should be completely bypassed.- Parameters:
bypass-trueto force direct OrientDB database queries,falseotherwise
-
isCacheBypass
public boolean isCacheBypass()Returns whether the Redis cache is currently bypassed.- Returns:
trueif cache is bypassed,falseotherwise
-
read
public String read(String typeName, int depth, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Reads the serialized JSON representation of a Type and optionally all of its subtypes down to a specified depth.- Parameters:
typeName- the case-sensitive type name to look updepth- the depth of subclasses to include (0 = none, N = N levels, -1 = all recursively)metadataPolicy- the metadata inclusion policy to apply- Returns:
- serialized JSON array representing the type schema(s)
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- if the lookup fails
-
read
public String read(String typeName, int depth, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy, boolean maskMetadata) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Reads a Type by name while applying metadata inclusion and identity masking.- Parameters:
typeName- the case-sensitive type name to look updepth- the depth of subclasses to include (0 = none, N = N levels, -1 = all recursively)metadataPolicy- the metadata inclusion policy to applymaskMetadata- whether sensitive metadata identity fields must be redacted- Returns:
- serialized JSON array representing the type schema(s)
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- if the lookup fails
-
query
public String query(String jsonQuery, int limit, int offset, int depth, 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 Types collection (schema definitions), returning matching Type definitions.- Parameters:
jsonQuery- the JSON query payload describing the Type definition search criterialimit- the maximum number of results to returnoffset- the number of results to skipdepth- the descendant-closure depth for Type-name matching (0 = exact name only, N = N levels of descendants, -1 = all descendants recursively)metadataPolicy- the metadata inclusion policy to apply- Returns:
- JSON array string of matching Type 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 TypeRepository.TypeQueryResult queryWithDetails(String jsonQuery, int limit, int offset, int depth, 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 Type JSON query and reports whether its result is projection-based.- Parameters:
jsonQuery- the JSON query payload describing the Type definition search criterialimit- the maximum number of results to returnoffset- the number of results to skipdepth- the descendant-closure depth for Type-name matchingmetadataPolicy- 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
-
create
public TypeCreationResult create(String json, org.gcube.informationsystem.types.reference.Type type, org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Registers a new Type definition in the database and adds it to the cache. If the type name already exists, the repository performs an exact congruency check. If the existing schema is identical to the provided one, it returns aTypeCreationResultwithcreated = false(no-op). If the schemas differ, it throws aSchemaAlreadyPresentException(409 Conflict).- Parameters:
json- the raw type JSON definitiontype- the deserialized Type model instancemetadataPolicy- the metadata inclusion policy applied to the returned representation- Returns:
- the
TypeCreationResultwrapping the schema representation and creation outcome - Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- if the creation fails or schema mismatch occurs
-
create
public TypeCreationResult create(String json, org.gcube.informationsystem.types.reference.Type type, boolean preservePassedMetadata) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Registers a new type, optionally preserving themetadataobject already present in the submitted JSON instead of autofilling it from the current caller and clock. Used exclusively by System Restore to reproduce the original audit trail of a dumped type.- Parameters:
json- the raw type JSON definitiontype- the deserialized Type model instancepreservePassedMetadata-trueto preserve submitted metadata,falseto autofill- Returns:
- the
TypeCreationResultwrapping the schema representation and creation outcome - Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- if the creation fails or schema mismatch occurs
-
create
public TypeCreationResult create(String json, org.gcube.informationsystem.types.reference.Type type, boolean preservePassedMetadata, boolean allowUnresolvedResourceReferences) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Registers a new type, optionally allowing aResourceSchema's own forward-declaredconsistsOf/isRelatedTorelation-type reference (and, forisRelatedToonly, its target Resource type) to not exist yet. Used exclusively by System Restore, whose dump is a flat snapshot of an already-consistent historical state that a live system could only have reached incrementally (e.g. a Resource created first, then updated later to declare a relation that did not exist until afterwards) — replaying it as a single unordered batch of creations otherwise hits an unresolvable ordering cycle between a Resource and a relation type that in turn requires that same Resource to exist as its ownsource/target(seetype-update-and-deprecation/decision-log.md, 2026-08-24). The bypass is deliberately narrow: aconsistsOfentry's target (always a Facet) and aRelationSchema's ownsource/targetremain always strictly checked, in both modes — only the two ends of the genuine ordering cycle are relaxed here, never validated dangling.- Parameters:
json- the raw type JSON definitiontype- the deserialized Type model instancepreservePassedMetadata-trueto preserve submitted metadata,falseto autofillallowUnresolvedResourceReferences-trueto skip existence checks for aResourceSchema's ownconsistsOf/isRelatedTorelation-type reference andisRelatedTotarget Resource type;falsefor the ordinary strict behavior- Returns:
- the
TypeCreationResultwrapping the schema representation and creation outcome - Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- if the creation fails or schema mismatch occurs
-
update
public String update(String typeName, String json, org.gcube.informationsystem.types.reference.Type type, boolean skipVersionCheckOnUpdate) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Updates an existing Type definition in the database;TypeManagementempties the cache.- Parameters:
typeName- the name of the type to updatejson- the raw updated type JSON definitiontype- the deserialized updated Type model instanceskipVersionCheckOnUpdate-trueto skip version increment checks,falseto enforce them- Returns:
- the serialized JSON representation of the updated type
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- if the update fails
-
delete
public boolean delete(String typeName) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Deletes the specified type schema and its definition from the database.- Parameters:
typeName- the case-sensitive name of the type to delete- Returns:
trueif deletion succeeded- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException- if no type with the specified name existsorg.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException- if the type has concrete instances, subtypes, or references from another type definition or from the template of a Query Templateorg.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- if deletion fails
-
loadSchemaSnapshot
public SchemaSnapshot loadSchemaSnapshot() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryExceptionLoads every Type definition from the database as an immutable, version-stampedSchemaSnapshot.This is the expensive operation the whole caching design exists to avoid repeating: it walks the type graph and reassembles every definition. It is therefore performed only in the background, by the schema projection worker, and never on a request path.
The version is read before loading, so that a change landing mid-load produces a snapshot stamped with the older version, which is then rebuilt — rather than a partially stale snapshot stamped as current.
- Returns:
- the loaded snapshot
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- if the database load fails
-
populateCacheFrom
Repopulates the Redis type cache from a snapshot, in a single pipelined batch.- Parameters:
snapshot- the snapshot to write- Returns:
- the number of types written, or
0if nothing was written
-
warmUpCache
public void warmUpCache() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryExceptionLoads a snapshot and repopulates the Redis type cache from it.- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- if the database load fails
-