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 Details

    • DefaultOcflObjectSession

      public DefaultOcflObjectSession(String sessionId, io.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, Cache<String,String> rootIdCache, HeadersValidator headersValidator, boolean useUnsafeWrite)
  • Method Details

    • sessionId

      public String sessionId()
      Specified by:
      sessionId in interface OcflObjectSession
      Returns:
      the id of the session
    • ocflObjectId

      public String ocflObjectId()
      Specified by:
      ocflObjectId in interface OcflObjectSession
      Returns:
      the OCFL object id of the object the session is on
    • writeResource

      public ResourceHeaders writeResource(ResourceHeaders headers, InputStream content)
      Description copied from interface: OcflObjectSession
      Writes a resource to the session.
      Specified by:
      writeResource in interface OcflObjectSession
      Parameters:
      headers - the resource's headers
      content - 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: OcflObjectSession
      Writes the resources headers to the session.
      Specified by:
      writeHeaders in interface OcflObjectSession
      Parameters:
      headers - the headers to write
    • deleteContentFile

      public void deleteContentFile(ResourceHeaders headers)
      Description copied from interface: OcflObjectSession
      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.
      Specified by:
      deleteContentFile in interface OcflObjectSession
      Parameters:
      headers - the updated resource headers
    • deleteResource

      public void deleteResource(String resourceId)
      Description copied from interface: OcflObjectSession
      Deletes 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:
      deleteResource in interface OcflObjectSession
      Parameters:
      resourceId - the Fedora resource id of the resource to delete
    • containsResource

      public boolean containsResource(String resourceId)
      Description copied from interface: OcflObjectSession
      Indicates if the resource exists in the session
      Specified by:
      containsResource in interface OcflObjectSession
      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: OcflObjectSession
      Reads a resource's header file.
      Specified by:
      readHeaders in interface OcflObjectSession
      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: OcflObjectSession
      Reads a specific version of a resource's header file.
      Specified by:
      readHeaders in interface OcflObjectSession
      Parameters:
      resourceId - the Fedora resource id to read
      versionNumber - the version to read, or null for HEAD
      Returns:
      the resource's headers
    • readContent

      public ResourceContent readContent(String resourceId)
      Description copied from interface: OcflObjectSession
      Reads a resource's content.
      Specified by:
      readContent in interface OcflObjectSession
      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: OcflObjectSession
      Reads a specific version of a resource's content.
      Specified by:
      readContent in interface OcflObjectSession
      Parameters:
      resourceId - the Fedora resource id to read
      versionNumber - the version to read, or null for HEAD
      Returns:
      the resource's content
    • readRange

      public ResourceContent readRange(String resourceId, long startPosition, long endPosition)
      Description copied from interface: OcflObjectSession
      Reads a range of bytes of a resource's content.
      Specified by:
      readRange in interface OcflObjectSession
      Parameters:
      resourceId - the Fedora resource id to read
      startPosition - the position to start reading from, inclusive
      endPosition - the position to stop reading at, inclusive
      Returns:
      the range of the resources content
    • readRange

      public ResourceContent readRange(String resourceId, String versionNumber, long startPosition, long endPosition)
      Description copied from interface: OcflObjectSession
      Reads a range of bytes from a specific version of a resource's content.
      Specified by:
      readRange in interface OcflObjectSession
      Parameters:
      resourceId - the Fedora resource id to read
      versionNumber - the version to read, or null for HEAD
      startPosition - the position to start reading from, inclusive
      endPosition - the position to stop reading at, inclusive
      Returns:
      the range of the resources content
    • listVersions

      public List<OcflVersionInfo> listVersions(String resourceId)
      Description copied from interface: OcflObjectSession
      List all of the versions associated to the resource in chrolological order.
      Specified by:
      listVersions in interface OcflObjectSession
      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:
      streamResourceHeaders in interface OcflObjectSession
      Returns:
      ResourceHeader stream
    • versionCreationTimestamp

      public void versionCreationTimestamp(OffsetDateTime timestamp)
      Description copied from interface: OcflObjectSession
      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.
      Specified by:
      versionCreationTimestamp in interface OcflObjectSession
      Parameters:
      timestamp - version creation timestamp
    • versionAuthor

      public void versionAuthor(String name, String address)
      Description copied from interface: OcflObjectSession
      Sets the author the OCFL version is attributed to.
      Specified by:
      versionAuthor in interface OcflObjectSession
      Parameters:
      name - the author's name
      address - the author's address
    • versionMessage

      public void versionMessage(String message)
      Description copied from interface: OcflObjectSession
      Sets the OCFL version message.
      Specified by:
      versionMessage in interface OcflObjectSession
      Parameters:
      message - the OCFL version message
    • invalidateCache

      public void invalidateCache(String resourceId)
      Description copied from interface: OcflObjectSession
      Invalidate the cache for a Fedora resource's headers
      Specified by:
      invalidateCache in interface OcflObjectSession
      Parameters:
      resourceId - the Fedora resource id to read
    • commitType

      public void commitType(CommitType commitType)
      Description copied from interface: OcflObjectSession
      Sets the commit behavior -- create a new version or update the mutable HEAD.
      Specified by:
      commitType in interface OcflObjectSession
      Parameters:
      commitType - the commit behavior
    • commit

      public void commit()
      Description copied from interface: OcflObjectSession
      Commits the session, persisting all changes to a new OCFL version.
      Specified by:
      commit in interface OcflObjectSession
    • abort

      public void abort()
      Description copied from interface: OcflObjectSession
      Aborts the session, abandoning all changes.
      Specified by:
      abort in interface OcflObjectSession
    • rollback

      public void rollback()
      Description copied from interface: OcflObjectSession
      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.
      Specified by:
      rollback in interface OcflObjectSession
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface OcflObjectSession
    • isOpen

      public boolean isOpen()
      Specified by:
      isOpen in interface OcflObjectSession
      Returns:
      true if the session is still open