Package org.fcrepo.storage.ocfl
Interface OcflObjectSession
-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DefaultOcflObjectSession
public interface OcflObjectSession extends AutoCloseable
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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidabort()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.booleanisOpen()List<OcflVersionInfo>listVersions(String resourceId)List all of the versions associated to the resource in chrolological order.StringocflObjectId()ResourceContentreadContent(String resourceId)Reads a resource's content.ResourceContentreadContent(String resourceId, String versionNumber)Reads a specific version of a resource's content.ResourceHeadersreadHeaders(String resourceId)Reads a resource's header file.ResourceHeadersreadHeaders(String resourceId, String versionNumber)Reads a specific version of a resource's header file.voidrollback()Rolls back an already committed session, permanently removing the OCFL object version that was created by the session.StringsessionId()Stream<ResourceHeaders>streamResourceHeaders()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.ResourceHeaderswriteResource(ResourceHeaders headers, InputStream content)Writes a resource to the session.
-
-
-
Method Detail
-
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
ResourceHeaders writeResource(ResourceHeaders headers, InputStream content)
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
void writeHeaders(ResourceHeaders headers)
Writes the resources headers to the session.- Parameters:
headers- the headers to write
-
deleteContentFile
void deleteContentFile(ResourceHeaders headers)
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
void deleteResource(String resourceId)
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
boolean containsResource(String resourceId)
Indicates if the resource exists in the session- Parameters:
resourceId- the Fedora resource id- Returns:
- true if the resource exists in the session
-
readHeaders
ResourceHeaders readHeaders(String resourceId)
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
ResourceHeaders readHeaders(String resourceId, String versionNumber)
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
ResourceContent readContent(String resourceId)
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
ResourceContent readContent(String resourceId, String versionNumber)
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
-
listVersions
List<OcflVersionInfo> listVersions(String resourceId)
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
void versionCreationTimestamp(OffsetDateTime timestamp)
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
void versionAuthor(String name, String address)
Sets the author the OCFL version is attributed to.- Parameters:
name- the author's nameaddress- the author's address
-
versionMessage
void versionMessage(String message)
Sets the OCFL version message.- Parameters:
message- the OCFL version message
-
commitType
void commitType(CommitType 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
-
-