Class SystemRepository

java.lang.Object
org.gcube.informationsystem.resourceregistry.system.SystemRepository

public class SystemRepository extends Object
Orchestrates database-agnostic System Dump and Restore operations for the complete logical Resource Registry state.

Dump reads every collection unfiltered with full metadata (MetadataPolicy.ALL); Restore validates the closed archive format before recreating that state.

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

    Fields
    Modifier and Type
    Field
    Description
    static final String
    ZIP entry name for the Context hierarchy (live and cemetery).
    static final int
    Format version of the produced dump archive, recorded in manifest.json.
    static final String
    ZIP entry name for the dump manifest.
    static final String
    ZIP entry name for the Query Template collection.
    static final String
    ZIP entry name for the RegistryMetadata singleton.
    static final String
    ZIP entry name for the IsRelatedTo relation instance collection.
    static final String
    ZIP entry name for the Resource instance collection.
    static final String
    ZIP entry name for the Type schema dictionary.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    dump(OutputStream outputStream)
    Writes a complete System Dump ZIP archive to the given output stream.
    Returns every Context, live and cemetery alike, unfiltered and unpaginated.
    Returns the dump manifest: DUMP_FORMAT_VERSION and the creation timestamp (formatted per Element.DATETIME_PATTERN, matching every other date field in the dumped collections).
    Returns every Query Template, unfiltered and unpaginated.
    Returns the RegistryMetadata singleton.
    Returns every IsRelatedTo relation instance, with full metadata and embedded Context membership.
    Returns every Resource instance, with embedded ConsistsOf/Facets, full metadata, and embedded Context membership.
    Returns every registered Type schema across the five dump root categories: Resource, Facet, IsRelatedTo, ConsistsOf, and every custom domain Property descendant, since a Facet's structure can reference a domain-specific Property type — e.g. gcube-model's EnumStringProperty or AttributeProperty — that a target must have registered before that Facet can be recreated), merged into a single JSON array.
    void
    restore(InputStream inputStream)
    Ingests a System Dump ZIP archive (as produced by dump(OutputStream)), recreating the entire Resource Registry state in strict topological order: Types, Contexts, Query Templates, Resources, then IsRelatedTo relations.

    Methods inherited from class java.lang.Object

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

    • DUMP_FORMAT_VERSION

      public static final int DUMP_FORMAT_VERSION
      Format version of the produced dump archive, recorded in manifest.json.
      See Also:
    • MANIFEST_ENTRY

      public static final String MANIFEST_ENTRY
      ZIP entry name for the dump manifest.
      See Also:
    • REGISTRY_METADATA_ENTRY

      public static final String REGISTRY_METADATA_ENTRY
      ZIP entry name for the RegistryMetadata singleton.
      See Also:
    • TYPES_ENTRY

      public static final String TYPES_ENTRY
      ZIP entry name for the Type schema dictionary.
      See Also:
    • CONTEXTS_ENTRY

      public static final String CONTEXTS_ENTRY
      ZIP entry name for the Context hierarchy (live and cemetery).
      See Also:
    • QUERY_TEMPLATES_ENTRY

      public static final String QUERY_TEMPLATES_ENTRY
      ZIP entry name for the Query Template collection.
      See Also:
    • RESOURCES_ENTRY

      public static final String RESOURCES_ENTRY
      ZIP entry name for the Resource instance collection.
      See Also:
    • RELATIONS_ENTRY

      public static final String RELATIONS_ENTRY
      ZIP entry name for the IsRelatedTo relation instance collection.
      See Also:
  • Constructor Details

    • SystemRepository

      public SystemRepository()
  • Method Details

    • dump

      public void dump(OutputStream outputStream) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Writes a complete System Dump ZIP archive to the given output stream.
      Parameters:
      outputStream - the destination stream; not closed by this method's caller — the ZIP wrapper created here owns and closes it
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if any collection cannot be read
    • dumpManifest

      public String dumpManifest() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Returns the dump manifest: DUMP_FORMAT_VERSION and the creation timestamp (formatted per Element.DATETIME_PATTERN, matching every other date field in the dumped collections). The model the dump conforms to is stated by the dumped RegistryMetadata.
      Returns:
      the manifest as a JSON object string
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the manifest cannot be serialized
    • dumpRegistryMetadata

      public String dumpRegistryMetadata() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Returns the RegistryMetadata singleton.
      Returns:
      the RegistryMetadata as a JSON object string
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the record cannot be read, or the system has none
    • dumpTypes

      public String dumpTypes() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Returns every registered Type schema across the five dump root categories: Resource, Facet, IsRelatedTo, ConsistsOf, and every custom domain Property descendant, since a Facet's structure can reference a domain-specific Property type — e.g. gcube-model's EnumStringProperty or AttributeProperty — that a target must have registered before that Facet can be recreated), merged into a single JSON array.
      Returns:
      JSON array of every Type schema
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if a root category cannot be read
    • dumpContexts

      public String dumpContexts() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Returns every Context, live and cemetery alike, unfiltered and unpaginated.
      Returns:
      JSON array of every Context
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if Contexts cannot be read
    • dumpQueryTemplates

      public String dumpQueryTemplates() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Returns every Query Template, unfiltered and unpaginated.
      Returns:
      JSON array of every Query Template
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if Query Templates cannot be read
    • dumpResources

      public String dumpResources() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Returns every Resource instance, with embedded ConsistsOf/Facets, full metadata, and embedded Context membership.
      Returns:
      JSON array of every Resource
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if instances cannot be read
    • dumpRelations

      public String dumpRelations() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Returns every IsRelatedTo relation instance, with full metadata and embedded Context membership.
      Returns:
      JSON array of every IsRelatedTo relation
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if instances cannot be read
    • restore

      public void restore(InputStream inputStream) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Ingests a System Dump ZIP archive (as produced by dump(OutputStream)), recreating the entire Resource Registry state in strict topological order: Types, Contexts, Query Templates, Resources, then IsRelatedTo relations. A restore reproduces the dumped state exactly: every original UUID and every original metadata object (creator, creation/last-update timestamps) is preserved verbatim, every Context comes back among the live Contexts or in the cemetery with its state, paths and history, and every instance, the ConsistsOf and Facet instances nested in a Resource included, comes back in the Contexts the archive records for it. The RegistryMetadata is written last, as dumped, except revisionCount, which stays the target's: the restored Types counted as runtime creates, and the counter never goes backwards at runtime.

      Assumes the target system is empty: no attempt is made to merge with, or skip conflicts against, pre-existing data.

      Parameters:
      inputStream - the ZIP archive stream
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the archive is malformed, of an unsupported format version, or any collection cannot be restored