Package org.fcrepo.storage.ocfl
Class DefaultOcflObjectSession
- java.lang.Object
-
- org.fcrepo.storage.ocfl.DefaultOcflObjectSession
-
- All Implemented Interfaces:
AutoCloseable,OcflObjectSession
public class DefaultOcflObjectSession extends Object implements OcflObjectSession
Default OcflObjectSession implementation.- Author:
- pwinckles
-
-
Constructor Summary
Constructors Constructor Description DefaultOcflObjectSession(String sessionId, edu.wisc.library.ocfl.api.MutableOcflRepository ocflRepo, String ocflObjectId, Path objectStaging, com.fasterxml.jackson.databind.ObjectReader headerReader, com.fasterxml.jackson.databind.ObjectWriter headerWriter, CommitType commitType, Cache<String,ResourceHeaders> headersCache)
-
Method Summary
All Methods Instance Methods Concrete 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()This method is NOT currently using the ResourceHeader cache.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.
-
-
-
Constructor Detail
-
DefaultOcflObjectSession
public DefaultOcflObjectSession(String sessionId, edu.wisc.library.ocfl.api.MutableOcflRepository ocflRepo, String ocflObjectId, Path objectStaging, com.fasterxml.jackson.databind.ObjectReader headerReader, com.fasterxml.jackson.databind.ObjectWriter headerWriter, CommitType commitType, Cache<String,ResourceHeaders> headersCache)
-
-
Method Detail
-
sessionId
public String sessionId()
- Specified by:
sessionIdin interfaceOcflObjectSession- Returns:
- the id of the session
-
ocflObjectId
public String ocflObjectId()
- Specified by:
ocflObjectIdin interfaceOcflObjectSession- Returns:
- the OCFL object id of the object the session is on
-
writeResource
public ResourceHeaders writeResource(ResourceHeaders headers, InputStream content)
Description copied from interface:OcflObjectSessionWrites a resource to the session.- Specified by:
writeResourcein interfaceOcflObjectSession- 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
-
writeHeaders
public void writeHeaders(ResourceHeaders headers)
Description copied from interface:OcflObjectSessionWrites the resources headers to the session.- Specified by:
writeHeadersin interfaceOcflObjectSession- Parameters:
headers- the headers to write
-
deleteContentFile
public void deleteContentFile(ResourceHeaders headers)
Description copied from interface:OcflObjectSessionDeletes 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.- Specified by:
deleteContentFilein interfaceOcflObjectSession- Parameters:
headers- the updated resource headers
-
deleteResource
public void deleteResource(String resourceId)
Description copied from interface:OcflObjectSessionDeletes all files associated to the specified resource. If the resource is the root resource of the object, then the object will be deleted.- Specified by:
deleteResourcein interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id of the resource to delete
-
containsResource
public boolean containsResource(String resourceId)
Description copied from interface:OcflObjectSessionIndicates if the resource exists in the session- Specified by:
containsResourcein interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id- Returns:
- true if the resource exists in the session
-
readHeaders
public ResourceHeaders readHeaders(String resourceId)
Description copied from interface:OcflObjectSessionReads a resource's header file.- Specified by:
readHeadersin interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id to read- Returns:
- the resource's headers
-
readHeaders
public ResourceHeaders readHeaders(String resourceId, String versionNumber)
Description copied from interface:OcflObjectSessionReads a specific version of a resource's header file.- Specified by:
readHeadersin interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id to readversionNumber- the version to read, or null for HEAD- Returns:
- the resource's headers
-
readContent
public ResourceContent readContent(String resourceId)
Description copied from interface:OcflObjectSessionReads a resource's content.- Specified by:
readContentin interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id to read- Returns:
- the resource's content
-
readContent
public ResourceContent readContent(String resourceId, String versionNumber)
Description copied from interface:OcflObjectSessionReads a specific version of a resource's content.- Specified by:
readContentin interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id to readversionNumber- the version to read, or null for HEAD- Returns:
- the resource's content
-
listVersions
public List<OcflVersionInfo> listVersions(String resourceId)
Description copied from interface:OcflObjectSessionList all of the versions associated to the resource in chrolological order.- Specified by:
listVersionsin interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id- Returns:
- list of versions
-
streamResourceHeaders
public Stream<ResourceHeaders> streamResourceHeaders()
This method is NOT currently using the ResourceHeader cache. It should not matter because this method is currently only used when reindexing. If it is ever used anywhere else, we may want to figure out how to get it to use the cache.- Specified by:
streamResourceHeadersin interfaceOcflObjectSession- Returns:
- ResourceHeader stream
-
versionCreationTimestamp
public void versionCreationTimestamp(OffsetDateTime timestamp)
Description copied from interface:OcflObjectSessionSets 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.- Specified by:
versionCreationTimestampin interfaceOcflObjectSession- Parameters:
timestamp- version creation timestamp
-
versionAuthor
public void versionAuthor(String name, String address)
Description copied from interface:OcflObjectSessionSets the author the OCFL version is attributed to.- Specified by:
versionAuthorin interfaceOcflObjectSession- Parameters:
name- the author's nameaddress- the author's address
-
versionMessage
public void versionMessage(String message)
Description copied from interface:OcflObjectSessionSets the OCFL version message.- Specified by:
versionMessagein interfaceOcflObjectSession- Parameters:
message- the OCFL version message
-
commitType
public void commitType(CommitType commitType)
Description copied from interface:OcflObjectSessionSets the commit behavior -- create a new version or update the mutable HEAD.- Specified by:
commitTypein interfaceOcflObjectSession- Parameters:
commitType- the commit behavior
-
commit
public void commit()
Description copied from interface:OcflObjectSessionCommits the session, persisting all changes to a new OCFL version.- Specified by:
commitin interfaceOcflObjectSession
-
abort
public void abort()
Description copied from interface:OcflObjectSessionAborts the session, abandoning all changes.- Specified by:
abortin interfaceOcflObjectSession
-
rollback
public void rollback()
Description copied from interface:OcflObjectSessionRolls 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.- Specified by:
rollbackin interfaceOcflObjectSession
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceOcflObjectSession
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfaceOcflObjectSession- Returns:
- true if the session is still open
-
-