Class S3BitStoreService

java.lang.Object
org.dspace.storage.bitstore.BaseBitStoreService
org.dspace.storage.bitstore.S3BitStoreService
All Implemented Interfaces:
BitStoreService

public class S3BitStoreService extends BaseBitStoreService
Asset store using Amazon's Simple Storage Service (S3). S3 is a commercial, web-service accessible, remote storage facility. NB: you must have obtained an account with Amazon to use this store
Author:
Richard Rodgers, Peter Dietz, Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
  • Field Details

  • Constructor Details

    • S3BitStoreService

      public S3BitStoreService()
    • S3BitStoreService

      protected S3BitStoreService(com.amazonaws.services.s3.AmazonS3 s3Service)
      This constructor is used for test purpose.
      Parameters:
      s3Service - AmazonS3 service
  • Method Details

    • amazonClientBuilderBy

      protected static Supplier<com.amazonaws.services.s3.AmazonS3> amazonClientBuilderBy(@NotNull @NotNull com.amazonaws.regions.Regions regions, @NotNull @NotNull com.amazonaws.auth.AWSCredentials awsCredentials)
      Utility method for generate AmazonS3 builder
      Parameters:
      regions - wanted regions in client
      awsCredentials - credentials of the client
      Returns:
      builder with the specified parameters
    • isEnabled

      public boolean isEnabled()
      Description copied from interface: BitStoreService
      Determines if a store is enabled, by default is enabled
      Returns:
      boolean true if enabled, false otherwise
    • init

      public void init() throws IOException
      Initialize the asset store S3 Requires: - access key - secret key - bucket name
      Throws:
      IOException - A general class of exceptions produced by failed or interrupted I/O operations.
    • generateId

      public String generateId()
      Return an identifier unique to this asset store instance
      Returns:
      a unique ID
    • get

      public InputStream get(Bitstream bitstream) throws IOException
      Retrieve the bits for the asset with ID. If the asset does not exist, returns null.
      Parameters:
      bitstream - The ID of the asset to retrieve
      Returns:
      The stream of bits, or null
      Throws:
      IOException - If a problem occurs while retrieving the bits
    • put

      public void put(Bitstream bitstream, InputStream in) throws IOException
      Store a stream of bits.

      If this method returns successfully, the bits have been stored. If an exception is thrown, the bits have not been stored.

      Parameters:
      in - The stream of bits to store
      bitstream - The bitstream object
      Throws:
      IOException - If a problem occurs while storing the bits
    • about

      public Map<String,Object> about(Bitstream bitstream, List<String> attrs) throws IOException
      Obtain technical metadata about an asset in the asset store. Checksum used is (ETag) hex encoded 128-bit MD5 digest of an object's content as calculated by Amazon S3 (Does not use getContentMD5, as that is 128-bit MD5 digest calculated on caller's side)
      Parameters:
      bitstream - The asset to describe
      attrs - A List of desired metadata fields
      Returns:
      attrs A Map with key/value pairs of desired metadata If file not found, then return null
      Throws:
      IOException - If a problem occurs while obtaining metadata
    • remove

      public void remove(Bitstream bitstream) throws IOException
      Remove an asset from the asset store. An irreversible operation.
      Parameters:
      bitstream - The asset to delete
      Throws:
      IOException - If a problem occurs while removing the asset
    • getFullKey

      public String getFullKey(String id)
      Utility Method: Prefix the key with a subfolder, if this instance assets are stored within subfolder
      Parameters:
      id - DSpace bitstream internal ID
      Returns:
      full key prefixed with a subfolder, if applicable
    • getRelativePath

      public String getRelativePath(String sInternalId)
      there are 2 cases: - conventional bitstream, conventional storage - registered bitstream, conventional storage conventional bitstream: dspace ingested, dspace random name/path registered bitstream: registered to dspace, any name/path
      Parameters:
      sInternalId -
      Returns:
      Computed Relative path
    • setEnabled

      public void setEnabled(boolean enabled)
    • getAwsAccessKey

      public String getAwsAccessKey()
    • setAwsAccessKey

      @Autowired(required=true) public void setAwsAccessKey(String awsAccessKey)
    • getAwsSecretKey

      public String getAwsSecretKey()
    • setAwsSecretKey

      @Autowired(required=true) public void setAwsSecretKey(String awsSecretKey)
    • getAwsRegionName

      public String getAwsRegionName()
    • setAwsRegionName

      public void setAwsRegionName(String awsRegionName)
    • getBucketName

      @Autowired(required=true) public String getBucketName()
    • setBucketName

      public void setBucketName(String bucketName)
    • getSubfolder

      public String getSubfolder()
    • setSubfolder

      public void setSubfolder(String subfolder)
    • isUseRelativePath

      public boolean isUseRelativePath()
    • setUseRelativePath

      public void setUseRelativePath(boolean useRelativePath)
    • main

      public static void main(String[] args) throws Exception
      Contains a command-line testing tool. Expects arguments: -a accessKey -s secretKey -f assetFileName
      Parameters:
      args - the command line arguments given
      Throws:
      Exception - generic exception
    • isRegisteredBitstream

      public boolean isRegisteredBitstream(String internalId)
      Is this a registered bitstream? (not stored via this service originally)
      Parameters:
      internalId -
      Returns:
    • setBufferSize

      public void setBufferSize(long bufferSize)