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 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

      ResourceHeaders writeResource(ResourceHeaders headers, InputStream content)
      Writes a resource to the session.
      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
      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 read
      versionNumber - 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 read
      versionNumber - the version to read, or null for HEAD
      Returns:
      the resource's content
      Throws:
      NotFoundException - if the resource cannot be found
    • readRange

      ResourceContent readRange(String resourceId, long startPosition, long endPosition)
      Reads a range of bytes of a resource's content.
      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

      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 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

      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 name
      address - the author's address
    • versionMessage

      void versionMessage(String message)
      Sets the OCFL version message.
      Parameters:
      message - the OCFL version message
    • invalidateCache

      void invalidateCache(String resourceId)
      Invalidate the cache for a Fedora resource's headers
      Parameters:
      resourceId - the Fedora resource id to read
    • 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:
      close in interface AutoCloseable