Class BitstreamStorageServiceImpl

  • All Implemented Interfaces:
    BitstreamStorageService, org.springframework.beans.factory.InitializingBean

    public class BitstreamStorageServiceImpl
    extends Object
    implements BitstreamStorageService, org.springframework.beans.factory.InitializingBean

    Stores, retrieves and deletes bitstreams.

    Presently, asset stores are specified in dspace.cfg. Since Java does not offer a way of detecting free disk space, the asset store to use for new bitstreams is also specified in a configuration property. The drawbacks to this are that the administrators are responsible for monitoring available space in the asset stores, and DSpace (Tomcat) has to be restarted when the asset store for new ('incoming') bitstreams is changed.

    Mods by David Little, UCSD Libraries 12/21/04 to allow the registration of files (bitstreams) into DSpace.

    Cleanup integration with checker package by Nate Sarr 2006-01. N.B. The dependency on the checker package isn't ideal - a Listener pattern would be better but was considered overkill for the purposes of integrating the checker. It would be worth re-considering a Listener pattern if another package needs to be notified of BitstreamStorageManager actions.

    Author:
    Peter Breton, Robert Tansley, David Little, Nathan Sarr
    • Field Detail

      • bitstreamService

        @Autowired(required=true)
        protected BitstreamService bitstreamService
      • REGISTERED_FLAG

        protected final String REGISTERED_FLAG
        This prefix string marks registered bitstreams in internal_id
        See Also:
        Constant Field Values
    • Constructor Detail

      • BitstreamStorageServiceImpl

        protected BitstreamStorageServiceImpl()
    • Method Detail

      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws Exception
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Throws:
        Exception
      • store

        public UUID store​(Context context,
                          Bitstream bitstream,
                          InputStream is)
                   throws SQLException,
                          IOException
        Description copied from interface: BitstreamStorageService
        Store a stream of bits.

        If this method returns successfully, the bits have been stored, and RDBMS metadata entries are in place (the context still needs to be completed to finalize the transaction).

        If this method returns successfully and the context is aborted, then the bits will be stored in the asset store and the RDBMS metadata entries will exist, but with the deleted flag set.

        If this method throws an exception, then any of the following may be true:
        • Neither bits nor RDBMS metadata entries have been stored.
        • RDBMS metadata entries with the deleted flag set have been stored, but no bits.
        • RDBMS metadata entries with the deleted flag set have been stored, and some or all of the bits have also been stored.
        Specified by:
        store in interface BitstreamStorageService
        Parameters:
        context - The current context
        bitstream - The bitstream to store
        is - The stream of bits to store
        Returns:
        The ID of the stored bitstream
        Throws:
        SQLException - If a problem occurs accessing the RDBMS
        IOException - If a problem occurs while storing the bits
      • register

        public UUID register​(Context context,
                             Bitstream bitstream,
                             int assetstore,
                             String bitstreamPath)
                      throws SQLException,
                             IOException,
                             AuthorizeException
        Register a bitstream already in storage.
        Specified by:
        register in interface BitstreamStorageService
        Parameters:
        context - The current context
        assetstore - The assetstore number for the bitstream to be registered
        bitstreamPath - The relative path of the bitstream to be registered. The path is relative to the path of ths assetstore.
        bitstream - The bitstream to register
        Returns:
        The ID of the registered bitstream
        Throws:
        SQLException - If a problem occurs accessing the RDBMS
        IOException - if IO error
        AuthorizeException - Exception indicating the current user of the context does not have permission to perform a particular action.
      • isRegisteredBitstream

        public boolean isRegisteredBitstream​(String internalId)
        Description copied from interface: BitstreamStorageService
        Does the internal_id column in the bitstream row indicate the bitstream is a registered file
        Specified by:
        isRegisteredBitstream in interface BitstreamStorageService
        Parameters:
        internalId - the value of the internal_id column
        Returns:
        true if the bitstream is a registered file
      • cleanup

        public void cleanup​(boolean deleteDbRecords,
                            boolean verbose)
                     throws SQLException,
                            IOException,
                            AuthorizeException
        Description copied from interface: BitstreamStorageService
        Clean up the bitstream storage area. This method deletes any bitstreams which are more than 1 hour old and marked deleted. The deletions cannot be undone.
        Specified by:
        cleanup in interface BitstreamStorageService
        Parameters:
        deleteDbRecords - if true deletes the database records otherwise it only deletes the files and directories in the assetstore
        verbose - verbosity flag
        Throws:
        SQLException - If a problem occurs accessing the RDBMS
        IOException - If a problem occurs while cleaning up
        AuthorizeException - Exception indicating the current user of the context does not have permission to perform a particular action.
      • clone

        public Bitstream clone​(Context context,
                               Bitstream bitstream)
                        throws SQLException,
                               IOException,
                               AuthorizeException
        Description copied from interface: BitstreamStorageService
        Clone the given bitstream to a new bitstream with a new ID. Metadata of the given bitstream are also copied to the new bitstream.
        Specified by:
        clone in interface BitstreamStorageService
        Parameters:
        context - The relevant DSpace Context.
        bitstream - the bitstream to be cloned
        Returns:
        id of the clone bitstream. A general class of exceptions produced by failed or interrupted I/O operations.
        Throws:
        SQLException - An exception that provides information on a database access error or other errors.
        AuthorizeException - Exception indicating the current user of the context does not have permission to perform a particular action.
        IOException - if IO error
      • migrate

        public void migrate​(Context context,
                            Integer assetstoreSource,
                            Integer assetstoreDestination,
                            boolean deleteOld,
                            Integer batchCommitSize)
                     throws IOException,
                            SQLException,
                            AuthorizeException
        Migrates all assets off of one assetstore to another
        Specified by:
        migrate in interface BitstreamStorageService
        Parameters:
        assetstoreSource - source assetstore
        assetstoreDestination - destination assetstore
        context - The relevant DSpace Context.
        deleteOld - whether to delete files from the source assetstore after migration
        batchCommitSize - batch size
        Throws:
        IOException - A general class of exceptions produced by failed or interrupted I/O operations.
        SQLException - An exception that provides information on a database access error or other errors.
        AuthorizeException - Exception indicating the current user of the context does not have permission to perform a particular action.
      • printStores

        public void printStores​(Context context)
        Description copied from interface: BitstreamStorageService
        Print out (log/out) a listing of the assetstores configured, and how many assets they contain
        Specified by:
        printStores in interface BitstreamStorageService
        Parameters:
        context - The relevant DSpace Context.
      • getIncoming

        public int getIncoming()
      • setIncoming

        public void setIncoming​(int incoming)
      • isRecent

        protected boolean isRecent​(Long lastModified)
        Return true if this file is too recent to be deleted, false otherwise.
        Parameters:
        lastModified - The time asset was last modified
        Returns:
        True if this file is too recent to be deleted