Interface OcflStorage
-
- All Known Implementing Classes:
AbstractOcflStorage,CachingOcflStorage,CloudOcflStorage,FileSystemOcflStorage,ObjectDetailsDbOcflStorage
public interface OcflStorageExtension point that allows the OCFL repository to use any number of storage implementations so long as they conform to this interface.initializeStorage(edu.wisc.library.ocfl.api.model.OcflVersion, edu.wisc.library.ocfl.core.extension.OcflExtensionConfig, edu.wisc.library.ocfl.core.inventory.InventoryMapper, edu.wisc.library.ocfl.core.extension.ExtensionSupportEvaluator)MUST be called before the object may be used.- See Also:
FileSystemOcflStorage
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()Shutsdown any resources the OclfStorage may have open, such as ExecutorServices.voidcommitMutableHead(Inventory oldInventory, Inventory newInventory, Path stagingDir)Moves the mutable HEAD of any object into the object root and into an immutable version.booleancontainsObject(String objectId)Returns true if an object with the specified id exists in the repository.voidexportObject(String objectId, Path outputPath)Copies a raw OCFL object to the specified directory.voidexportVersion(ObjectVersionId objectVersionId, Path outputPath)Copies a raw OCFL object version to the specified directory.byte[]getInventoryBytes(String objectId, VersionNum versionNum)Returns the raw inventory bytes for the specified object versionMap<String,OcflFileRetriever>getObjectStreams(Inventory inventory, VersionNum versionNum)Returns a map ofOcflFileRetrieverobjects that are used to lazy-load object files.voidimportObject(String objectId, Path objectPath)Moves an entire OCFL object into the repository.voidinitializeStorage(OcflVersion ocflVersion, OcflExtensionConfig layoutConfig, InventoryMapper inventoryMapper, ExtensionSupportEvaluator supportEvaluator)Initializes the OCFL root.voidinvalidateCache()If the OcflStorage is using an inventory cache, then this method invalidates all entries in the cache.voidinvalidateCache(String objectId)If the OcflStorage is using an inventory cache, then this method invalidates the cache entry for the specified object.Stream<String>listObjectIds()Returns a stream of object ids for all of the OCFL objects stored in a repository.InventoryloadInventory(String objectId)Returns a verified copy of the most recent object inventory.StringobjectRootPath(String objectId)Returns the path from the storage root to the object root.voidpurgeMutableHead(String objectId)Permanently removes the mutable HEAD of an object.voidpurgeObject(String objectId)Permanently removes an object from the repository.voidreconstructObjectVersion(Inventory inventory, VersionNum versionNum, Path stagingDir)Reconstructs a complete object at the specified version in the stagingDir.voidrollbackToVersion(Inventory inventory, VersionNum versionNum)Sets the head object version to the specified version by reinstating that version's inventory into the object root, and purging all intermediary versions.voidstoreNewVersion(Inventory inventory, Path stagingDir)Persists a fully composed object version.ValidationResultsvalidateObject(String objectId, boolean contentFixityCheck)Validates the specified object against the OCFL 1.0 spec.
-
-
-
Method Detail
-
initializeStorage
void initializeStorage(OcflVersion ocflVersion, OcflExtensionConfig layoutConfig, InventoryMapper inventoryMapper, ExtensionSupportEvaluator supportEvaluator)
Initializes the OCFL root. If it is an existing OCFL repository and the root has already been initialized, then this method should do nothing. This method must be called before the object may be used.layoutConfig may be null if the OCFL repository already exists, in which case the existing configuration is used. If layoutConfig is specified for an existing repository, initialization will fail if the configurations do not match.
- Parameters:
ocflVersion- the OCFL versionlayoutConfig- the storage layout configuration, may be null to auto-detect existing configurationinventoryMapper- the mapper to use for inventory serializationsupportEvaluator- the evaluator that determines what to do when unsupported extensions are encountered
-
loadInventory
Inventory loadInventory(String objectId)
Returns a verified copy of the most recent object inventory. Null is returned if the object is not found.DefaultOcflRepository calls this method within a read lock and caches the result.
- Parameters:
objectId- the id of the object to load- Returns:
- the deserialized inventory or null if the object was not found
- Throws:
FixityCheckException- if the inventory fails its fixity check
-
getInventoryBytes
byte[] getInventoryBytes(String objectId, VersionNum versionNum)
Returns the raw inventory bytes for the specified object version- Parameters:
objectId- the id of the objectversionNum- the version number- Returns:
- the raw inventory bytes
- Throws:
NotFoundException- if object or version cannot be found
-
storeNewVersion
void storeNewVersion(Inventory inventory, Path stagingDir)
Persists a fully composed object version. The contents of the stagingDir are the contents of the new version, including a serialized copy of the updated inventory. It is safe to move the entire stagingDir to object-root/version.DefaultOcflRepository calls this method from a write lock.
This method MUST ensure that the version to be persisted is not out of sync with the current object state, and reject the request if it is.
After persisting the new version directory, the new inventory file is installed in the object root.
- Parameters:
inventory- the updated object inventorystagingDir- the directory that contains the composed contents of the new object version- Throws:
ObjectOutOfSyncException- if the version cannot be created because it already existsFixityCheckException- if one of the files in the version fails its fixity check
-
getObjectStreams
Map<String,OcflFileRetriever> getObjectStreams(Inventory inventory, VersionNum versionNum)
Returns a map ofOcflFileRetrieverobjects that are used to lazy-load object files. The map keys are the object relative file paths of all of the files in the specified version of the object.- Parameters:
inventory- the object's inventoryversionNum- the id of the version to load- Returns:
- a map of
OcflFileRetrieverobjects keyed off the object relative file paths of all of the files in the object
-
reconstructObjectVersion
void reconstructObjectVersion(Inventory inventory, VersionNum versionNum, Path stagingDir)
Reconstructs a complete object at the specified version in the stagingDir.The fixity of every file must be checked after copying it to the stagingDir.
- Parameters:
inventory- the deserialized object inventoryversionNum- the id of the version to reconstructstagingDir- the location the reconstructed object should be assembled in- Throws:
FixityCheckException- if one of the files fails its fixity check
-
purgeObject
void purgeObject(String objectId)
Permanently removes an object from the repository. Objects that have been purged are NOT recoverable. If an object with the specified id cannot be found it is considered purged and no exception is thrown.DefaultOcflRepository calls this method from a write lock.
- Parameters:
objectId- the id of the object to purge
-
commitMutableHead
void commitMutableHead(Inventory oldInventory, Inventory newInventory, Path stagingDir)
Moves the mutable HEAD of any object into the object root and into an immutable version. The mutable HEAD does not exist at the end of the operation.DefaultOcflRepository calls this method from a write lock.
- Parameters:
oldInventory- the deserialized inventory of the object BEFORE it was rewritten for the commitnewInventory- the deserialized inventory of the object AFTER it was rewritten for the commitstagingDir- the path to the staging directory that contains the inventory files
-
purgeMutableHead
void purgeMutableHead(String objectId)
Permanently removes the mutable HEAD of an object. If the object does not have a mutable HEAD nothing happens.DefaultOcflRepository calls this method from a write lock.
- Parameters:
objectId- the id of the object to purge the mutable HEAD of
-
rollbackToVersion
void rollbackToVersion(Inventory inventory, VersionNum versionNum)
Sets the head object version to the specified version by reinstating that version's inventory into the object root, and purging all intermediary versions.- Parameters:
inventory- the deserialized object inventoryversionNum- the id of the version to rollback to
-
containsObject
boolean containsObject(String objectId)
Returns true if an object with the specified id exists in the repository.- Parameters:
objectId- the id of the object- Returns:
- true if the object exists and false otherwise
-
objectRootPath
String objectRootPath(String objectId)
Returns the path from the storage root to the object root.- Parameters:
objectId- the id of the object- Returns:
- the relative path from the storage root to the object root
-
listObjectIds
Stream<String> listObjectIds()
Returns a stream of object ids for all of the OCFL objects stored in a repository. This stream is populated on demand, and it may be quite slow. Remember to close the stream when you are done with it.- Returns:
- stream of object ids
-
exportVersion
void exportVersion(ObjectVersionId objectVersionId, Path outputPath)
Copies a raw OCFL object version to the specified directory. For example, if you export version 2 of an object, then the entire contents of the object's v2 directory will be exported the output directory. This is primarily useful for backing up OCFL versions, as an isolated OCFL object version is not usable in and of itself.The outputPath MUST NOT exist, but its parent MUST exist.
Mutable HEAD versions cannot be exported
- Parameters:
objectVersionId- the id of the object and version to exportoutputPath- the directory to write the exported version to, must NOT exist- Throws:
NotFoundException- when no object can be found for the specified objectVersionId
-
exportObject
void exportObject(String objectId, Path outputPath)
Copies a raw OCFL object to the specified directory. The output is a complete copy of everything that's contained in the object's root directory.The outputPath MUST NOT exist, but its parent MUST exist.
- Parameters:
objectId- the id of the object to exportoutputPath- the directory to write the exported object to, must NOT exist- Throws:
NotFoundException- when no object can be found for the specified objectId
-
importObject
void importObject(String objectId, Path objectPath)
Moves an entire OCFL object into the repository. This object cannot already exist.- Parameters:
objectId- the id of the object to importobjectPath- the directory that contains the object to import
-
close
void close()
Shutsdown any resources the OclfStorage may have open, such as ExecutorServices. Once closed, additional requests will be rejected. Calling this method is optional, and it is more efficient to just let the shutdown hooks take care of closing the resources.
-
validateObject
ValidationResults validateObject(String objectId, boolean contentFixityCheck)
Validates the specified object against the OCFL 1.0 spec.- Parameters:
objectId- the id of the object to validatecontentFixityCheck- true if the fixity of the content files should be verified- Returns:
- the validation results
- Throws:
NotFoundException- if the object does not exist.
-
invalidateCache
void invalidateCache(String objectId)
If the OcflStorage is using an inventory cache, then this method invalidates the cache entry for the specified object. Otherwise, nothing happens.- Parameters:
objectId- the ID of the object to invalidate in the cache
-
invalidateCache
void invalidateCache()
If the OcflStorage is using an inventory cache, then this method invalidates all entries in the cache. Otherwise, nothing happens.
-
-