Package org.fcrepo.storage.ocfl
Interface OcflObjectSession
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DefaultOcflObjectSession
Session interface over an OCFL object. Changes to the object are accumulated in a staging directory until the
session is committed, at which point all of the changes are written to a new OCFL object version.
- Author:
- pwinckles
-
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Aborts the session, abandoning all changes.voidclose()voidcommit()Commits the session, persisting all changes to a new OCFL version.voidcommitType(CommitType commitType) Sets the commit behavior -- create a new version or update the mutable HEAD.booleancontainsResource(String resourceId) Indicates if the resource exists in the sessionvoiddeleteContentFile(ResourceHeaders headers) Deletes a content file from the session, and updates the associated headers.voiddeleteResource(String resourceId) Deletes all files associated to the specified resource.voidinvalidateCache(String resourceId) Invalidate the cache for a Fedora resource's headersbooleanisOpen()listVersions(String resourceId) List all of the versions associated to the resource in chrolological order.readContent(String resourceId) Reads a resource's content.readContent(String resourceId, String versionNumber) Reads a specific version of a resource's content.readHeaders(String resourceId) Reads a resource's header file.readHeaders(String resourceId, String versionNumber) Reads a specific version of a resource's header file.Reads a range of bytes of a resource's content.Reads a range of bytes from a specific version of a resource's content.voidrollback()Rolls back an already committed session, permanently removing the OCFL object version that was created by the session.Returns the headers for all of the resources contained within an OCFL object.voidversionAuthor(String name, String address) Sets the author the OCFL version is attributed to.voidversionCreationTimestamp(OffsetDateTime timestamp) Sets the timestamp that's stamped on the OCFL version.voidversionMessage(String message) Sets the OCFL version message.voidwriteHeaders(ResourceHeaders headers) Writes the resources headers to the session.writeResource(ResourceHeaders headers, InputStream content) Writes a resource to the session.
-
Method Details
-
sessionId
String sessionId()- Returns:
- the id of the session
-
ocflObjectId
String ocflObjectId()- Returns:
- the OCFL object id of the object the session is on
-
writeResource
Writes a resource to the session.- Parameters:
headers- the resource's headerscontent- the resource's content, may be null if the resource has no content- Returns:
- the resource headers that were written to disk, these may differ from the input headers
- Throws:
InvalidContentException- when the content size in the headers does not match the actual content size
-
writeHeaders
Writes the resources headers to the session.- Parameters:
headers- the headers to write
-
deleteContentFile
Deletes a content file from the session, and updates the associated headers. If the resource was added in the current session, then its headers are also deleted and it is as if the resource never existed.- Parameters:
headers- the updated resource headers
-
deleteResource
Deletes all files associated to the specified resource. If the resource is the root resource of the object, then the object will be deleted.- Parameters:
resourceId- the Fedora resource id of the resource to delete
-
containsResource
Indicates if the resource exists in the session- Parameters:
resourceId- the Fedora resource id- Returns:
- true if the resource exists in the session
-
readHeaders
Reads a resource's header file.- Parameters:
resourceId- the Fedora resource id to read- Returns:
- the resource's headers
- Throws:
NotFoundException- if the resource cannot be found
-
readHeaders
Reads a specific version of a resource's header file.- Parameters:
resourceId- the Fedora resource id to readversionNumber- the version to read, or null for HEAD- Returns:
- the resource's headers
- Throws:
NotFoundException- if the resource cannot be found
-
readContent
Reads a resource's content.- Parameters:
resourceId- the Fedora resource id to read- Returns:
- the resource's content
- Throws:
NotFoundException- if the resource cannot be found
-
readContent
Reads a specific version of a resource's content.- Parameters:
resourceId- the Fedora resource id to readversionNumber- the version to read, or null for HEAD- Returns:
- the resource's content
- Throws:
NotFoundException- if the resource cannot be found
-
readRange
Reads a range of bytes of a resource's content.- Parameters:
resourceId- the Fedora resource id to readstartPosition- the position to start reading from, inclusiveendPosition- the position to stop reading at, inclusive- Returns:
- the range of the resources content
-
readRange
ResourceContent readRange(String resourceId, String versionNumber, long startPosition, long endPosition) Reads a range of bytes from a specific version of a resource's content.- Parameters:
resourceId- the Fedora resource id to readversionNumber- the version to read, or null for HEADstartPosition- the position to start reading from, inclusiveendPosition- the position to stop reading at, inclusive- Returns:
- the range of the resources content
-
listVersions
List all of the versions associated to the resource in chrolological order.- Parameters:
resourceId- the Fedora resource id- Returns:
- list of versions
- Throws:
NotFoundException- if the resource cannot be found
-
streamResourceHeaders
Stream<ResourceHeaders> streamResourceHeaders()Returns the headers for all of the resources contained within an OCFL object. The results are unordered.- Returns:
- resource headers
-
versionCreationTimestamp
Sets the timestamp that's stamped on the OCFL version. If this value is not set, the current system time at the time the version is created is used.- Parameters:
timestamp- version creation timestamp
-
versionAuthor
Sets the author the OCFL version is attributed to.- Parameters:
name- the author's nameaddress- the author's address
-
versionMessage
Sets the OCFL version message.- Parameters:
message- the OCFL version message
-
invalidateCache
Invalidate the cache for a Fedora resource's headers- Parameters:
resourceId- the Fedora resource id to read
-
commitType
Sets the commit behavior -- create a new version or update the mutable HEAD.- Parameters:
commitType- the commit behavior
-
commit
void commit()Commits the session, persisting all changes to a new OCFL version. -
abort
void abort()Aborts the session, abandoning all changes. -
rollback
void rollback()Rolls back an already committed session, permanently removing the OCFL object version that was created by the session. Sessions may only be rolled back when auto-versioning in enabled. Calling this method on a session that has not yet been committed does nothing.- Throws:
IllegalStateException- if the session cannot be rolled back because manual versioning was used
-
isOpen
boolean isOpen()- Returns:
- true if the session is still open
-
close
void close()- Specified by:
closein interfaceAutoCloseable
-