Package edu.wisc.library.ocfl.core.model
Class Inventory
- java.lang.Object
-
- edu.wisc.library.ocfl.core.model.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/
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInventory.JacksonBuilderThis builder is only intended to be used by Jackson for deserializing inventory files.
-
Constructor Summary
Constructors Constructor Description 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)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static InventoryBuilderbuilder()static InventoryBuilderbuilderFromStub(String id, OcflConfig config, String objectRootPath)Creates an inventory builder with values populated from a stub inventoryInventoryBuilderbuildFrom()Creates an inventory builder that copies all of the properties of this inventory.InventoryBuilderbuildNextVersionFrom()Same as buildFrom except it moves the current digest to the previous digest and nulls the current digest.StringensureContentPath(String fileId)Returns the first contentPath associated to a fileId.VersionensureVersion(VersionNum versionNum)Returns the Version that corresponds to the version number.booleanequals(Object o)StringgetContentDirectory()UseresolveContentDirectory()insteadStringgetContentPath(String fileId)Returns the first path to a file that maps to the given digestSet<String>getContentPaths(String fileId)Returns the set of paths that are identified by the given digest if they exist.DigestAlgorithmgetDigestAlgorithm()StringgetFileId(String path)Returns the digest that is used to identify the given path if it exists.StringgetFileId(Path path)Returns the digest that is used to identify the given path if it exists.Set<String>getFileIdsForMatchingFiles(String path)Returns the set of file ids of files that have content paths that begin with the given prefix.Set<String>getFileIdsForMatchingFiles(Path path)Returns the set of file ids of files that have content paths that begin with the given prefix.Map<DigestAlgorithm,Map<String,Set<String>>>getFixity()Map<DigestAlgorithm,String>getFixityForContentPath(String contentPath)Returns the fixity information for a contentPath.VersionNumgetHead()VersiongetHeadVersion()StringgetId()StringgetInventoryDigest()Returns the digest of this inventory or null if it's not known.Map<String,Set<String>>getManifest()A map of all of the files that are part of the object across all versions of the object.StringgetObjectRootPath()StringgetPreviousDigest()Returns the digest in the previous version's sidecar file or nullRevisionNumgetRevisionNum()If there's an active mutable HEAD, its revision number is returned.InventoryTypegetType()VersiongetVersion(VersionNum versionNum)Map<VersionNum,Version>getVersions()A map of version number to the object that describes the state of the object at that version.inthashCode()booleanhasMutableHead()Indicates if there's an active mutable HEADbooleanmanifestContainsFileId(String fileId)Helper method for checking if an object contains a file with the given digest id.RevisionNumnextRevisionNum()Returns the next revision number.VersionNumnextVersionNum()Returns the next version number after the current HEAD version.StringresolveContentDirectory()The name of the directory within a version directory that contains the object content.StringstoragePath(String fileId)Returns the path from the storage root to a file within an object.static InventorystubInventory(String id, OcflConfig config, String objectRootPath)Creates a stub inventory that is useful when creating new objects.StringtoString()
-
-
-
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 idtype- OCFL inventory typedigestAlgorithm- digest algorithmhead- head version numbercontentDirectory- content directory namefixity- fixity blockmanifest- manifest blockversions- versions blockmutableHead- if there is a mutable headrevisionNum- current revision numberobjectRootPath- object root pathpreviousDigest- digest of previous inventoryinventoryDigest- 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 idconfig- ocfl defaults configobjectRootPath- path to object root- Returns:
- stub inventory
-
builder
public static InventoryBuilder builder()
- Returns:
- new
InventoryBuilderthat is not based on an existing 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 idconfig- ocfl defaults configobjectRootPath- 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.
-
getFixity
public Map<DigestAlgorithm,Map<String,Set<String>>> getFixity()
- Returns:
- fixity information for all of the files that are part of the object.
-
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()
UseresolveContentDirectory()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
-
-