Class S3BitStoreService

  • All Implemented Interfaces:
    BitStoreService

    public class S3BitStoreService
    extends Object
    implements BitStoreService
    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
    • Constructor Detail

      • S3BitStoreService

        public S3BitStoreService()
    • Method Detail

      • init

        public void init()
                  throws IOException
        Initialize the asset store S3 Requires: - access key - secret key - bucket name
        Specified by:
        init in interface BitStoreService
        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
        Specified by:
        generateId in interface BitStoreService
        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.
        Specified by:
        get in interface BitStoreService
        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.

        Specified by:
        put in interface BitStoreService
        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 about​(Bitstream bitstream,
                         Map 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)
        Specified by:
        about in interface BitStoreService
        Parameters:
        bitstream - The asset to describe
        attrs - A Map whose keys consist 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.
        Specified by:
        remove in interface BitStoreService
        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
      • 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)
      • 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