Class Inventory


  • public class Inventory
    extends Object
    OCFL inventory object. It is intended to be used to encode and decode inventories. Inventories are immutable. Creating a new version of an object requires creating a new inventory.
    See Also:
    InventoryBuilder, https://ocfl.io/
    • Constructor Detail

      • Inventory

        public Inventory​(String id,
                         InventoryType type,
                         DigestAlgorithm digestAlgorithm,
                         VersionNum head,
                         String contentDirectory,
                         Map<DigestAlgorithm,​Map<String,​Set<String>>> fixity,
                         Map<String,​Set<String>> manifest,
                         Map<VersionNum,​Version> versions,
                         boolean mutableHead,
                         RevisionNum revisionNum,
                         String objectRootPath,
                         String previousDigest,
                         String inventoryDigest)
        Parameters:
        id - object id
        type - OCFL inventory type
        digestAlgorithm - digest algorithm
        head - head version number
        contentDirectory - content directory name
        fixity - fixity block
        manifest - manifest block
        versions - versions block
        mutableHead - if there is a mutable head
        revisionNum - current revision number
        objectRootPath - object root path
        previousDigest - digest of previous inventory
        inventoryDigest - digest of this inventory
        See Also:
        InventoryBuilder
    • Method Detail

      • stubInventory

        public static Inventory stubInventory​(String id,
                                              OcflConfig config,
                                              String objectRootPath)
        Creates a stub inventory that is useful when creating new objects. It should NOT be persisted.
        Parameters:
        id - object id
        config - ocfl defaults config
        objectRootPath - path to object root
        Returns:
        stub inventory
      • builderFromStub

        public static InventoryBuilder builderFromStub​(String id,
                                                       OcflConfig config,
                                                       String objectRootPath)
        Creates an inventory builder with values populated from a stub inventory
        Parameters:
        id - object id
        config - ocfl defaults config
        objectRootPath - path to object root
        Returns:
        inventory builder
      • buildFrom

        public InventoryBuilder buildFrom()
        Creates an inventory builder that copies all of the properties of this inventory.
        Returns:
        inventory builder
      • buildNextVersionFrom

        public InventoryBuilder buildNextVersionFrom()
        Same as buildFrom except it moves the current digest to the previous digest and nulls the current digest.
        Returns:
        inventory builder
      • getDigestAlgorithm

        public DigestAlgorithm getDigestAlgorithm()
        Returns:
        the algorithm used to compute the digests that are used as file identifiers. sha512 be default.
      • getId

        public String getId()
        Returns:
        the object's id
      • getHead

        public VersionNum getHead()
        Returns:
        the version of the most recent version of the object. This is in the format of "vX" where "X" is a positive integer.
      • getType

        public InventoryType getType()
        Returns:
        the inventory's type and version.
      • getManifest

        public Map<String,​Set<String>> getManifest()
        A map of all of the files that are part of the object across all versions of the object. The map is keyed off file digest and the value is the location of the file relative to the OCFL object root.
        Returns:
        manifest map
      • getVersions

        public Map<VersionNum,​Version> getVersions()
        A map of version number to the object that describes the state of the object at that version. All versions of the object are represented here.
        Returns:
        version states
      • getContentDirectory

        public String getContentDirectory()
        Use resolveContentDirectory() instead
        Returns:
        the content directory
      • resolveContentDirectory

        public String resolveContentDirectory()
        The name of the directory within a version directory that contains the object content. 'content' by default.
        Returns:
        the content directory
      • getHeadVersion

        public Version getHeadVersion()
        Returns:
        the head version
      • getVersion

        public Version getVersion​(VersionNum versionNum)
        Parameters:
        versionNum - version number to get
        Returns:
        the version or null if it doesn't exist
      • ensureVersion

        public Version ensureVersion​(VersionNum versionNum)
        Returns the Version that corresponds to the version number. Throws an exception if the version does not exist.
        Parameters:
        versionNum - version number of the version to retrieve
        Returns:
        the version
        Throws:
        NotFoundException - if the version does not exist
      • manifestContainsFileId

        public boolean manifestContainsFileId​(String fileId)
        Helper method for checking if an object contains a file with the given digest id.
        Parameters:
        fileId - the file id
        Returns:
        true if the file is in the manfiest
      • getFileId

        public String getFileId​(String path)
        Returns the digest that is used to identify the given path if it exists.
        Parameters:
        path - the content path
        Returns:
        the file id associated to the path or null
      • getFileId

        public String getFileId​(Path path)
        Returns the digest that is used to identify the given path if it exists.
        Parameters:
        path - the content path
        Returns:
        the file id associated to the path or null
      • getContentPaths

        public Set<String> getContentPaths​(String fileId)
        Returns the set of paths that are identified by the given digest if they exist.
        Parameters:
        fileId - the file id
        Returns:
        the paths associated to the file id or an empty set
      • getContentPath

        public String getContentPath​(String fileId)
        Returns the first path to a file that maps to the given digest
        Parameters:
        fileId - the file id
        Returns:
        path associated to the file id or null
      • ensureContentPath

        public String ensureContentPath​(String fileId)
        Returns the first contentPath associated to a fileId. Throws an exception if there is no mapping.
        Parameters:
        fileId - the fileId to lookup
        Returns:
        the mapped content path
        Throws:
        NotFoundException - if there is no mapping
      • storagePath

        public String storagePath​(String fileId)
        Returns the path from the storage root to a file within an object.
        Parameters:
        fileId - the fileId of the file to lookup
        Returns:
        the path from the storage root to the file
      • getFileIdsForMatchingFiles

        public Set<String> getFileIdsForMatchingFiles​(Path path)
        Returns the set of file ids of files that have content paths that begin with the given prefix.
        Parameters:
        path - content path prefix
        Returns:
        file ids that begin with the given path
      • getFileIdsForMatchingFiles

        public Set<String> getFileIdsForMatchingFiles​(String path)
        Returns the set of file ids of files that have content paths that begin with the given prefix.
        Parameters:
        path - content path prefix
        Returns:
        file ids that begin with the given path
      • getRevisionNum

        public RevisionNum getRevisionNum()
        If there's an active mutable HEAD, its revision number is returned. Otherwise, null is returned.
        Returns:
        the current revision number or null
      • hasMutableHead

        public boolean hasMutableHead()
        Indicates if there's an active mutable HEAD
        Returns:
        true if there is a mutable HEAD
      • getObjectRootPath

        public String getObjectRootPath()
        Returns:
        the relative path from the storage root to the OCFL object directory
      • getPreviousDigest

        public String getPreviousDigest()
        Returns the digest in the previous version's sidecar file or null
        Returns:
        the digest of the previous version or null
      • getInventoryDigest

        public String getInventoryDigest()
        Returns the digest of this inventory or null if it's not known.
        Returns:
        the digest of this inventory or null
      • nextVersionNum

        public VersionNum nextVersionNum()
        Returns the next version number after the current HEAD version. If the object has a mutable HEAD, the current version is returned.
        Returns:
        the next version number
      • nextRevisionNum

        public RevisionNum nextRevisionNum()
        Returns the next revision number. If the object doest not have a revision number, then a new revision is created.
        Returns:
        the next revision number
      • getFixityForContentPath

        public Map<DigestAlgorithm,​String> getFixityForContentPath​(String contentPath)
        Returns the fixity information for a contentPath.
        Parameters:
        contentPath - the content path
        Returns:
        fixity information or empty map
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object