Class InventoryUpdater
- java.lang.Object
-
- edu.wisc.library.ocfl.core.inventory.InventoryUpdater
-
public class InventoryUpdater extends Object
This class is used to record changes to OCFL objects and construct an updated inventory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInventoryUpdater.AddFileResultIndicates the result of an add file operation.static classInventoryUpdater.Builderstatic classInventoryUpdater.RemoveFileResultIndicates that a file was removed from the manifest.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description InventoryUpdater.AddFileResultaddFile(String fileId, String logicalPath, OcflOption... options)Adds a file.voidaddFixity(String logicalPath, DigestAlgorithm algorithm, String digest)Adds an entry to the fixity block.static InventoryUpdater.Builderbuilder()InventorybuildNewInventory(OffsetDateTime createdTimestamp, VersionInfo versionInfo)voidclearFixity()Removes all entries from the fixity block.voidclearState()Removes all of the files from the version's state.StringgetFixityDigest(String logicalPath, DigestAlgorithm algorithm)Gets the fixity digest for the specified file or null.StringinnerContentPath(String logicalPath)Maps the logical path to a content path and returns the part of the content path that's under the content directory.Set<InventoryUpdater.RemoveFileResult>reinstateFile(VersionNum sourceVersion, String srcLogicalPath, String dstLogicalPath, OcflOption... options)Reinstates a file from a previous version to the current version.Set<InventoryUpdater.RemoveFileResult>removeFile(String logicalPath)Removes a file from the current version.Set<InventoryUpdater.RemoveFileResult>renameFile(String srcLogicalPath, String dstLogicalPath, OcflOption... options)Renames a file in the current version to a new logical path.
-
-
-
Method Detail
-
builder
public static InventoryUpdater.Builder builder()
-
buildNewInventory
public Inventory buildNewInventory(OffsetDateTime createdTimestamp, VersionInfo versionInfo)
Constructs a newInventorythat contains a newVersionbased on the changes that were recorded. After calling this method, the InventoryUpdater instance should NOT be used again.- Parameters:
createdTimestamp- when the version was createdversionInfo- information about the version- Returns:
- new inventory
-
addFile
public InventoryUpdater.AddFileResult addFile(String fileId, String logicalPath, OcflOption... options)
Adds a file. If there is already a file with the same digest in the manifest, only the state is updated.- Parameters:
fileId- the file's digestlogicalPath- the logical path to insert the file at within the objectoptions- options- Returns:
- details about the file if it was added to the manifest
-
innerContentPath
public String innerContentPath(String logicalPath)
Maps the logical path to a content path and returns the part of the content path that's under the content directory.- Parameters:
logicalPath- the logical path- Returns:
- content path part that's under the content directory
-
addFixity
public void addFixity(String logicalPath, DigestAlgorithm algorithm, String digest)
Adds an entry to the fixity block. An entry is not added if the algorithm is the same as the inventory's algorithm.- Parameters:
logicalPath- the file's logical pathalgorithm- algorithm used to calculate the digestdigest- the digest value
-
getFixityDigest
public String getFixityDigest(String logicalPath, DigestAlgorithm algorithm)
Gets the fixity digest for the specified file or null.- Parameters:
logicalPath- the logical path to the filealgorithm- the digest algorithm- Returns:
- the digest or null
-
clearFixity
public void clearFixity()
Removes all entries from the fixity block.
-
removeFile
public Set<InventoryUpdater.RemoveFileResult> removeFile(String logicalPath)
Removes a file from the current version. If the file was added in the same version, it is also removed from the manifest.- Parameters:
logicalPath- logical path to the file- Returns:
- files that were removed from the manifest
-
renameFile
public Set<InventoryUpdater.RemoveFileResult> renameFile(String srcLogicalPath, String dstLogicalPath, OcflOption... options)
Renames a file in the current version to a new logical path. If there is an existing file at the new logical path, andOcflOption.OVERWRITEis specified, then the existing file is replaced. If the replaced file was originally added in the current version, then it is also removed from the manifest.- Parameters:
srcLogicalPath- current logical pathdstLogicalPath- new logical pathoptions- options- Returns:
- files that were removed from the manifest
-
reinstateFile
public Set<InventoryUpdater.RemoveFileResult> reinstateFile(VersionNum sourceVersion, String srcLogicalPath, String dstLogicalPath, OcflOption... options)
Reinstates a file from a previous version to the current version. If there is an existing file at the new logical path, andOcflOption.OVERWRITEis specified, then the existing file is replaced. If the replaced file was originally added in the current version, then it is also removed from the manifest.- Parameters:
sourceVersion- the version number the source logical path corresponds tosrcLogicalPath- the source logical path of the file to reinstatedstLogicalPath- the destination logical path to reinstate the file atoptions- options- Returns:
- files that were removed from the manifest
-
clearState
public void clearState()
Removes all of the files from the version's state.
-
-