Class ContentStoreImpl

java.lang.Object
org.duracloud.client.ContentStoreImpl
All Implemented Interfaces:
ContentStore
Direct Known Subclasses:
CachingContentStoreImpl

public class ContentStoreImpl extends Object implements ContentStore
Provides access to a content store
Author:
Bill Branan
  • Constructor Details

    • ContentStoreImpl

      public ContentStoreImpl(String baseURL, StorageProviderType type, String storeId, boolean writable, RestHttpHelper restHelper)
      Creates a ContentStore. This ContentStore uses the default number of retries when a failure occurs (3).
      Parameters:
      baseURL - a String object.
      type - a StorageProviderType object.
      storeId - a String object.
      writable - flag that indicates whether the content store is writable by non-root users (value can be toggled in the Management Console)
      restHelper - a RestHttpHelper object
    • ContentStoreImpl

      public ContentStoreImpl(String baseURL, StorageProviderType type, String storeId, boolean writable, RestHttpHelper restHelper, int maxRetries)
      Creates a ContentStore with a specific number of retries.
  • Method Details

    • setRetryExceptionHandler

      public void setRetryExceptionHandler(ExceptionHandler retryExceptionHandler)
      Sets the Exception Handler which will be used to process any Exceptions that are thrown when an action fails but will be retried. The default Exception handler logs the exception messages at the WARN level.
      Specified by:
      setRetryExceptionHandler in interface ContentStore
    • getBaseURL

      public String getBaseURL()
      Description copied from interface: ContentStore
      Gets the base URL pointing to the DuraCloud DuraStore REST API
      Specified by:
      getBaseURL in interface ContentStore
    • getStoreId

      public String getStoreId()
      Gets the ID of this content store
      Specified by:
      getStoreId in interface ContentStore
    • isWritable

      public boolean isWritable()
      Indicates whether or not the content store is writable by non root users.
      Specified by:
      isWritable in interface ContentStore
      Returns:
    • getStorageProviderType

      public String getStorageProviderType()
      Gets the storage provider type StorageProviderType
      Specified by:
      getStorageProviderType in interface ContentStore
    • execute

      protected <T> T execute(Retriable retriable) throws ContentStoreException
      Throws:
      ContentStoreException
    • getSpaces

      public List<String> getSpaces() throws ContentStoreException
      Provides a listing of all spaces IDs.
      Specified by:
      getSpaces in interface ContentStore
      Returns:
      Iterator listing spaceIds
      Throws:
      ContentStoreException - if an error occurs
    • getSpaceContents

      public Iterator<String> getSpaceContents(String spaceId) throws ContentStoreException
      Retrieves the complete list of content items within a space. For spaces with many content items, the list is paged and updated automatically in order to retrieve the entire list. This method is equivalent to getSpaceContents(spaceId, null)
      Specified by:
      getSpaceContents in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      Returns:
      Iterator for content IDs
      Throws:
      NotFoundException - if the space does not exist
      ContentStoreException - if an error occurs
    • getSpaceContents

      public Iterator<String> getSpaceContents(String spaceId, String prefix) throws ContentStoreException
      Retrieves the complete list of content items within a space. For spaces with many content items, the list is paged and updated automatically in order to retrieve the entire list. Allows for limiting the content id list to items which start with a given prefix.
      Specified by:
      getSpaceContents in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      prefix - only retrieve content ids with this prefix (null for all content ids)
      Returns:
      Iterator for content IDs
      Throws:
      NotFoundException - if the space does not exist
      ContentStoreException - if an error occurs
    • getSpace

      public Space getSpace(String spaceId, String prefix, long maxResults, String marker) throws ContentStoreException
      Provides a space, including the id and properties of the space as well as a limited list of the content items within a space. This call allows for manual paging of content IDs using the maxResults and marker parameters.
      Specified by:
      getSpace in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      prefix - only retrieve content ids with this prefix (null for all content ids)
      maxResults - the maximum number of content ids to return in the list (0 indicates default - which is 1000)
      marker - the content id marking the last item in the previous set (null to specify first set of ids)
      Returns:
      Space
      Throws:
      NotFoundException - if the space does not exist
      ContentStoreException - if an error occurs
    • createSpace

      public void createSpace(String spaceId) throws ContentStoreException
      Creates a new space. Depending on the storage implementation, the spaceId may be changed somewhat to comply with the naming rules of the underlying storage provider. The same spaceId value used here can be used in all other methods, as the conversion will be applied internally, however a call to getSpaces() may not include a space with exactly this same name.
      Specified by:
      createSpace in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      Throws:
      InvalidIdException - if the space ID is not valid
      ContentStoreException - if the space already exists or cannot be created
    • deleteSpace

      public void deleteSpace(String spaceId) throws ContentStoreException
      Deletes a space.
      Specified by:
      deleteSpace in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      Throws:
      NotFoundException - if the space does not exist
      ContentStoreException - if an error occurs
    • getSpaceProperties

      public Map<String,String> getSpaceProperties(String spaceId) throws ContentStoreException
      Retrieves the properties associated with a space.
      Specified by:
      getSpaceProperties in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      Returns:
      Map of space properties or empty map if no properties exists
      Throws:
      NotFoundException - if the space does not exist
      ContentStoreException - if an error occurs
    • getSpaceACLs

      public Map<String,AclType> getSpaceACLs(String spaceId) throws ContentStoreException
      Retrieves the ACLs associated with a space.
      Specified by:
      getSpaceACLs in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      Returns:
      Map of space ACLs or empty map if no properties exists
      Throws:
      NotFoundException - if the space does not exist
      ContentStoreException - if an error occurs
    • setSpaceACLs

      public void setSpaceACLs(String spaceId, Map<String,AclType> spaceACLs) throws ContentStoreException
      Sets the ACLs associated with a space. Only values included in the ACLs map will be saved, others will be removed.
      Specified by:
      setSpaceACLs in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      spaceACLs - a map of ACL entries for the space (user|group -> right)
      Throws:
      NotFoundException - if the space does not exist
      ContentStoreException - if an error occurs
    • spaceExists

      public boolean spaceExists(String spaceId) throws ContentStoreException
      Determines if a space exists
      Specified by:
      spaceExists in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space to check
      Returns:
      true if the space exists, false otherwise
      Throws:
      ContentStoreException - if an error occurs
    • addContent

      public String addContent(String spaceId, String contentId, InputStream content, long contentSize, String contentMimeType, String contentChecksum, Map<String,String> contentProperties) throws ContentStoreException
      Adds content to a space. The contentId of the new content item can include "/" symbols to indicate a folder heirarchy. Returns the checksum of the content as computed by the underlying storage provider to facilitate comparison
      Specified by:
      addContent in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      contentId - the identifier of the new content item
      content - the new content as a stream
      contentSize - the size of the content
      contentMimeType - the MIME type of the content
      contentChecksum - the MD5 checksum of the content, or null if the checksum is not known
      contentProperties - a map of properties values to be linked to this content
      Returns:
      content checksum
      Throws:
      InvalidIdException - if the content ID is not valid
      NotFoundException - if the space does not exist
      ContentStoreException - if an error occurs
    • copyContent

      public String copyContent(String srcSpaceId, String srcContentId, String destStoreId, String destSpaceId, String destContentId) throws ContentStoreException
      This method provides a way to copy a content item to another content provider.
      Specified by:
      copyContent in interface ContentStore
      Parameters:
      srcSpaceId - of content to copy
      srcContentId - of content to copy
      destStoreId - where the copied content will end up
      destSpaceId - where copied content will end up
      destContentId - given to copied content
      Returns:
      MD5 checksum of destination content item
      Throws:
      ContentStoreException - on error
    • copyContent

      public String copyContent(String srcSpaceId, String srcContentId, String destSpaceId, String destContentId) throws ContentStoreException
      This method copies the content item found in source-space with the id of source-content-id into the dest-space, naming it to dest-content-id.
      Specified by:
      copyContent in interface ContentStore
      Parameters:
      srcSpaceId - of content to copy
      srcContentId - of content to copy
      destSpaceId - where copied content will end up
      destContentId - given to copied content
      Returns:
      MD5 checksum of destination content item
      Throws:
      ContentStoreException - on error
    • moveContent

      public String moveContent(String srcSpaceId, String srcContentId, String destSpaceId, String destContentId) throws ContentStoreException
      This method moves the content item found in source-space with the id of source-content-id into the dest-space, naming it to dest-content-id.
      Specified by:
      moveContent in interface ContentStore
      Parameters:
      srcSpaceId - of content to move
      srcContentId - of content to move
      destSpaceId - where moved content will end up
      destContentId - given to moved content
      Returns:
      MD5 checksum of destination content item
      Throws:
      ContentStoreException - on error
    • moveContent

      public String moveContent(String srcSpaceId, String srcContentId, String destStoreId, String destSpaceId, String destContentId) throws ContentStoreException
      This method moves the content item found in source-space with the id of source-content-id into the dest-space, naming it to dest-content-id.
      Specified by:
      moveContent in interface ContentStore
      Parameters:
      srcSpaceId - of content to move
      srcContentId - of content to move
      destStoreId - where moved content will end up
      destSpaceId - where moved content will end up
      destContentId - given to moved content
      Returns:
      MD5 checksum of destination content item
      Throws:
      ContentStoreException - on error
    • getContent

      public Content getContent(String spaceId, String contentId, Long startByte, Long endByte) throws ContentStoreException
      Gets a byte range of a content item from a space. The startByte must be greater than or equal to 0 and less than the content length. The endByte can be null which indicates you would like all bytes beginning with the specified start byte. Otherwise the endByte must be less than the content length and greater than the startByte.
      Specified by:
      getContent in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      contentId - the identifier of the content item
      startByte - the starting byte of the range.
      endByte - The end byte of the range.
      Returns:
      the content stream
      Throws:
      NotFoundException - if the space or content does not exist
      ContentStoreException - if an error occurs
    • getContent

      public Content getContent(String spaceId, String contentId) throws ContentStoreException
      Gets content from a space.
      Specified by:
      getContent in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      contentId - the identifier of the content item
      Returns:
      the content stream
      Throws:
      NotFoundException - if the space or content does not exist
      ContentStoreException - if an error occurs
    • doGetContent

      protected RestHttpHelper.HttpResponse doGetContent(String spaceId, String contentId, Long startByte, Long endByte) throws ContentStoreException
      Throws:
      ContentStoreException
    • deleteContent

      public void deleteContent(String spaceId, String contentId) throws ContentStoreException
      Removes content from a space.
      Specified by:
      deleteContent in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      contentId - the identifier of the content item
      Throws:
      NotFoundException - if the space or content does not exist
      ContentStoreException - if an error occurs
    • setContentProperties

      public void setContentProperties(String spaceId, String contentId, Map<String,String> contentProperties) throws ContentStoreException
      Sets the properties associated with content. This effectively removes all of the current content properties and adds a new set of properties. Some properties, such as system properties provided by the underlying storage system, cannot be updated or removed. Some of the values which cannot be updated or removed: content-checksum, content-modified, content-size
      Specified by:
      setContentProperties in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      contentId - the identifier of the content item
      contentProperties - a map of properties values to be linked to this content
      Throws:
      NotFoundException - if the space or content does not exist
      ContentStoreException - if an error occurs
    • getContentProperties

      public Map<String,String> getContentProperties(String spaceId, String contentId) throws ContentStoreException
      Retrieves the properties associated with content. This includes both properties generated by the underlying storage system and user defined properties
      Specified by:
      getContentProperties in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      contentId - the identifier of the content item
      Returns:
      the map of properties values linked to the given contentId
      Throws:
      NotFoundException - if the space or content does not exist
      ContentStoreException - if an error occurs
    • contentExists

      public boolean contentExists(String spaceId, String contentId) throws ContentStoreException
      Determines if a content item exists in a given space
      Specified by:
      contentExists in interface ContentStore
      Parameters:
      spaceId - the identifier of the DuraCloud Space
      contentId - the identifier of the content item to check
      Returns:
      true if the content item exists, false otherwise
      Throws:
      ContentStoreException - if an error occurs
    • validateStoreId

      public void validateStoreId(String storeId) throws InvalidIdException
      Throws:
      InvalidIdException
    • validateSpaceId

      public void validateSpaceId(String spaceId) throws InvalidIdException
      Checks a space ID to ensure that it conforms to all restrictions
      Specified by:
      validateSpaceId in interface ContentStore
      Parameters:
      spaceId - ID to validate
      Throws:
      InvalidIdException - if the space ID is invalid
    • validateContentId

      public void validateContentId(String contentId) throws InvalidIdException
      Checks a content ID to ensure that it conforms to all restrictions
      Specified by:
      validateContentId in interface ContentStore
      Parameters:
      contentId - ID to validate
      Throws:
      InvalidIdException - if the content ID is invalid
    • getSupportedTasks

      public List<String> getSupportedTasks() throws ContentStoreException
      Gets a listing of the supported tasks. A task is an activity which is outside of the standard set of storage activites but is available through one or more storage providers.
      Specified by:
      getSupportedTasks in interface ContentStore
      Returns:
      the return value of the task
      Throws:
      ContentStoreException
    • performTask

      public String performTask(String taskName, String taskParameters) throws ContentStoreException
      Perform a task (with retries on failure) which is outside of the standard set of storage activities but is available through one or more storage providers.
      Specified by:
      performTask in interface ContentStore
      Parameters:
      taskName - the name of the task to be performed
      taskParameters - the parameters of the task, what is included here and how the information is formatted is task-specific
      Returns:
      the return value of the task
      Throws:
      ContentStoreException
    • performTaskWithNoRetries

      public String performTaskWithNoRetries(String taskName, String taskParameters) throws ContentStoreException
      Perform a task (without retrying on failure) which is outside of the standard set of storage activities but is available through one or more storage providers.
      Specified by:
      performTaskWithNoRetries in interface ContentStore
      Parameters:
      taskName - the name of the task to be performed
      taskParameters - the parameters of the task, what is included here and how the information is formatted is task-specific
      Returns:
      the return value of the task
      Throws:
      ContentStoreException
    • getManifest

      public InputStream getManifest(String spaceId, ManifestFormat format) throws ContentStoreException
      Description copied from interface: ContentStore
      Gets a manifest for the specific space if one exists. If the space does not exist or the manifest is empty, an exception will be thrown.
      Specified by:
      getManifest in interface ContentStore
      Parameters:
      spaceId - the space id of the desired manifest
      Returns:
      Throws:
      ContentStoreException
    • getAuditLog

      public InputStream getAuditLog(String spaceId) throws ContentStoreException
      Description copied from interface: ContentStore
      Gets an audit log for the specific space if one exists. If the space does not exist or the audit is empty, an exception will be thrown.
      Specified by:
      getAuditLog in interface ContentStore
      Parameters:
      spaceId - the space id
      Returns:
      Throws:
      ContentStoreException
    • getBitIntegrityReport

      public BitIntegrityReport getBitIntegrityReport(String spaceId) throws ContentStoreException
      Description copied from interface: ContentStore
      Returns the most recent bit integrity report. If no bit integrity reports exist for this space, a null value is returned.
      Specified by:
      getBitIntegrityReport in interface ContentStore
      Returns:
      Throws:
      ContentStoreException
    • getBitIntegrityReportProperties

      public BitIntegrityReportProperties getBitIntegrityReportProperties(String spaceId) throws ContentStoreException
      Description copied from interface: ContentStore
      Returns the properties associated with the most recent bit integrity report. If no bit integrity reports exist for this space, a null value is returned.
      Specified by:
      getBitIntegrityReportProperties in interface ContentStore
      Returns:
      Throws:
      ContentStoreException
    • getSpaceStats

      public SpaceStatsDTOList getSpaceStats(String spaceId, Date start, Date end) throws ContentStoreException
      Description copied from interface: ContentStore
      Returns a space stats time series for presenting in a graph.
      Specified by:
      getSpaceStats in interface ContentStore
      Returns:
      Throws:
      ContentStoreException
    • getStorageProviderStats

      public SpaceStatsDTOList getStorageProviderStats(Date start, Date end) throws ContentStoreException
      Description copied from interface: ContentStore
      Returns a base based series of stats for all spaces within a storage provider for the specified time range.
      Specified by:
      getStorageProviderStats in interface ContentStore
      Returns:
      Throws:
      ContentStoreException
    • getStorageProviderStatsByDay

      public SpaceStatsDTOList getStorageProviderStatsByDay(Date date) throws ContentStoreException
      Description copied from interface: ContentStore
      Returns stats for all spaces within a storage provider for a particular day, averaging bit and object counts between 0:00:00 and 23:59:59 UTC.
      Specified by:
      getStorageProviderStatsByDay in interface ContentStore
      Returns:
      Throws:
      ContentStoreException
    • toString

      public String toString()
      Overrides:
      toString in class Object