Class ItemExportServiceImpl

  • All Implemented Interfaces:
    ItemExportService

    public class ItemExportServiceImpl
    extends Object
    implements ItemExportService
    Item exporter to create simple AIPs for DSpace content. Currently exports individual items, or entire collections. For instructions on use, see printUsage() method.

    ItemExport creates the simple AIP package that the importer also uses. It consists of:

    /exportdir/42/ (one directory per item) / dublin_core.xml - qualified dublin core in RDF schema / contents - text file, listing one file per line / file1 - files contained in the item / file2 / ...

    issues -doesn't handle special characters in metadata (needs to turn &'s into &, etc.)

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

    Author:
    David Little, Jay Paz
    • Field Detail

      • bitstreamService

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

        @Autowired(required=true)
        protected CommunityService communityService
      • ePersonService

        @Autowired(required=true)
        protected EPersonService ePersonService
      • itemService

        @Autowired(required=true)
        protected ItemService itemService
      • handleService

        @Autowired(required=true)
        protected HandleService handleService
    • Constructor Detail

      • ItemExportServiceImpl

        protected ItemExportServiceImpl()
    • Method Detail

      • exportItem

        protected void exportItem​(Context c,
                                  Item myItem,
                                  String destDirName,
                                  int seqStart,
                                  boolean migrate,
                                  boolean excludeBitstreams)
                           throws Exception
        Throws:
        Exception
      • writeMetadata

        protected void writeMetadata​(Context c,
                                     Item i,
                                     File destDir,
                                     boolean migrate)
                              throws Exception
        Discover the different schemas in use and output a separate metadata XML file for each schema.
        Parameters:
        c - DSpace context
        i - DSpace Item
        destDir - destination directory
        migrate - Whether to use the migrate option or not
        Throws:
        Exception - if error
      • writeMetadata

        protected void writeMetadata​(Context c,
                                     String schema,
                                     Item i,
                                     File destDir,
                                     boolean migrate)
                              throws Exception
        output the item's dublin core into the item directory
        Parameters:
        c - DSpace context
        schema - schema
        i - DSpace Item
        destDir - destination directory
        migrate - Whether to use the migrate option or not
        Throws:
        Exception - if error
      • writeHandle

        protected void writeHandle​(Context c,
                                   Item i,
                                   File destDir)
                            throws Exception
        create the file 'handle' which contains the handle assigned to the item
        Parameters:
        c - DSpace Context
        i - DSpace Item
        destDir - destination directory
        Throws:
        Exception - if error
      • writeBitstreams

        protected void writeBitstreams​(Context c,
                                       Item i,
                                       File destDir,
                                       boolean excludeBitstreams)
                                throws Exception
        Create both the bitstreams and the contents file. Any bitstreams that were originally registered will be marked in the contents file as such. However, the export directory will contain actual copies of the content files being exported.
        Parameters:
        c - the DSpace context
        i - the item being exported
        destDir - the item's export directory
        excludeBitstreams - whether to exclude bitstreams
        Throws:
        Exception - if error if there is any problem writing to the export directory
      • exportAsZip

        public void exportAsZip​(Context context,
                                Iterator<Item> items,
                                String destDirName,
                                String zipFileName,
                                int seqStart,
                                boolean migrate,
                                boolean excludeBitstreams)
                         throws Exception
        Description copied from interface: ItemExportService
        Method to perform an export and save it as a zip file.
        Specified by:
        exportAsZip in interface ItemExportService
        Parameters:
        context - The DSpace Context
        items - The items to export
        destDirName - The directory to save the export in
        zipFileName - The name to save the zip file as
        seqStart - The first number in the sequence
        migrate - Whether to use the migrate option or not
        excludeBitstreams - Whether to exclude bitstreams or not
        Throws:
        Exception - if error
      • createDownloadableExport

        public void createDownloadableExport​(DSpaceObject dso,
                                             Context context,
                                             boolean migrate)
                                      throws Exception
        Description copied from interface: ItemExportService
        Convenience methot to create export a single Community, Collection, or Item
        Specified by:
        createDownloadableExport in interface ItemExportService
        Parameters:
        dso - - the dspace object to export
        context - - the dspace context
        migrate - Whether to use the migrate option or not
        Throws:
        Exception - if error
      • createDownloadableExport

        public void createDownloadableExport​(List<DSpaceObject> dsObjects,
                                             Context context,
                                             boolean migrate)
                                      throws Exception
        Description copied from interface: ItemExportService
        Convenience method to export a List of dspace objects (Community, Collection or Item)
        Specified by:
        createDownloadableExport in interface ItemExportService
        Parameters:
        dsObjects - - List containing dspace objects
        context - - the dspace context
        migrate - Whether to use the migrate option or not
        Throws:
        Exception - if error
      • createDownloadableExport

        public void createDownloadableExport​(DSpaceObject dso,
                                             Context context,
                                             String additionalEmail,
                                             boolean migrate)
                                      throws Exception
        Description copied from interface: ItemExportService
        Convenience methot to create export a single Community, Collection, or Item
        Specified by:
        createDownloadableExport in interface ItemExportService
        Parameters:
        dso - - the dspace object to export
        context - - the dspace context
        additionalEmail - - cc email to use
        migrate - Whether to use the migrate option or not
        Throws:
        Exception - if error
      • createDownloadableExport

        public void createDownloadableExport​(List<DSpaceObject> dsObjects,
                                             Context context,
                                             String additionalEmail,
                                             boolean migrate)
                                      throws Exception
        Description copied from interface: ItemExportService
        Convenience method to export a List of dspace objects (Community, Collection or Item)
        Specified by:
        createDownloadableExport in interface ItemExportService
        Parameters:
        dsObjects - - List containing dspace objects
        context - - the dspace context
        additionalEmail - - cc email to use
        migrate - Whether to use the migrate option or not
        Throws:
        Exception - if error
      • processDownloadableExport

        protected void processDownloadableExport​(List<DSpaceObject> dsObjects,
                                                 Context context,
                                                 String additionalEmail,
                                                 boolean toMigrate)
                                          throws Exception
        Does the work creating a List with all the Items in the Community or Collection It then kicks off a new Thread to export the items, zip the export directory and send confirmation email
        Parameters:
        dsObjects - - List of dspace objects to process
        context - - the dspace context
        additionalEmail - - email address to cc in addition the the current user email
        toMigrate - Whether to use the migrate option or not
        Throws:
        Exception - if error
      • assembleFileName

        public String assembleFileName​(String type,
                                       EPerson eperson,
                                       Date date)
                                throws Exception
        Description copied from interface: ItemExportService
        Create a file name based on the date and eperson
        Specified by:
        assembleFileName in interface ItemExportService
        Parameters:
        type - Type of object (as string)
        eperson - - eperson who requested export and will be able to download it
        date - - the date the export process was created
        Returns:
        String representing the file name in the form of 'export_yyy_MMM_dd_count_epersonID'
        Throws:
        Exception - if error
      • getExportDownloadDirectory

        public String getExportDownloadDirectory​(EPerson ePerson)
                                          throws Exception
        Description copied from interface: ItemExportService
        Use config file entry for org.dspace.app.itemexport.download.dir and id of the eperson to create a download directory name
        Specified by:
        getExportDownloadDirectory in interface ItemExportService
        Parameters:
        ePerson - - the eperson who requested export archive
        Returns:
        String representing a directory in the form of org.dspace.app.itemexport.download.dir/epersonID
        Throws:
        Exception - if error
      • getExportFileSize

        public long getExportFileSize​(Context context,
                                      String fileName)
                               throws Exception
        Description copied from interface: ItemExportService
        Get the file size of the export archive represented by the file name.
        Specified by:
        getExportFileSize in interface ItemExportService
        Parameters:
        context - DSpace context
        fileName - name of the file to get the size.
        Returns:
        size as long
        Throws:
        Exception - if error
      • getEPersonFromString

        protected EPerson getEPersonFromString​(Context context,
                                               String strID)
                                        throws SQLException
        Attempt to find an EPerson based on string ID
        Parameters:
        context - DSpace context
        strID - string identifier
        Returns:
        EPerson object (if found)
        Throws:
        SQLException - if database error
      • canDownload

        public boolean canDownload​(Context context,
                                   String fileName)
        Description copied from interface: ItemExportService
        The file name of the export archive contains the eperson id of the person who created it When requested for download this method can check if the person requesting it is the same one that created it
        Specified by:
        canDownload in interface ItemExportService
        Parameters:
        context - dspace context
        fileName - the file name to check auths for
        Returns:
        true if it is the same person false otherwise
      • getExportsAvailable

        public List<String> getExportsAvailable​(EPerson eperson)
                                         throws Exception
        Description copied from interface: ItemExportService
        Reads the download directory for the eperson to see if any export archives are available
        Specified by:
        getExportsAvailable in interface ItemExportService
        Parameters:
        eperson - EPerson object
        Returns:
        a list of file names representing export archives that have been processed
        Throws:
        Exception - if error
      • deleteOldExportArchives

        public void deleteOldExportArchives​(EPerson eperson)
                                     throws Exception
        Description copied from interface: ItemExportService
        A clean up method that is ran before a new export archive is created. It uses the config file entry 'org.dspace.app.itemexport.life.span.hours' to determine if the current exports are too old and need pruging
        Specified by:
        deleteOldExportArchives in interface ItemExportService
        Parameters:
        eperson - - the eperson to clean up
        Throws:
        Exception - if error
      • deleteOldExportArchives

        public void deleteOldExportArchives()
                                     throws Exception
        Description copied from interface: ItemExportService
        A clean up method that is ran before a new export archive is created. It uses the config file entry 'org.dspace.app.itemexport.life.span.hours' to determine if the current exports are too old and need purgeing Removes all old exports, not just those for the person doing the export.
        Specified by:
        deleteOldExportArchives in interface ItemExportService
        Throws:
        Exception - if error
      • emailSuccessMessage

        public void emailSuccessMessage​(Context context,
                                        EPerson eperson,
                                        String fileName)
                                 throws javax.mail.MessagingException
        Description copied from interface: ItemExportService
        Since the archive is created in a new thread we are unable to communicate with calling method about success or failure. We accomplis this communication with email instead. Send a success email once the export archive is complete and ready for download
        Specified by:
        emailSuccessMessage in interface ItemExportService
        Parameters:
        context - - the current Context
        eperson - - eperson to send the email to
        fileName - - the file name to be downloaded. It is added to the url in the email
        Throws:
        javax.mail.MessagingException - if error
      • emailErrorMessage

        public void emailErrorMessage​(EPerson eperson,
                                      String error)
                               throws javax.mail.MessagingException
        Description copied from interface: ItemExportService
        Since the archive is created in a new thread we are unable to communicate with calling method about success or failure. We accomplis this communication with email instead. Send an error email if the export archive fails
        Specified by:
        emailErrorMessage in interface ItemExportService
        Parameters:
        eperson - - EPerson to send the error message to
        error - - the error message
        Throws:
        javax.mail.MessagingException - if error
      • zipFiles

        protected void zipFiles​(File cpFile,
                                String strSource,
                                String strTarget,
                                ZipOutputStream cpZipOutputStream)
                         throws Exception
        Parameters:
        cpFile - file
        strSource - source location
        strTarget - target location
        cpZipOutputStream - current zip outputstream
        Throws:
        Exception - if error
      • deleteDirectory

        protected boolean deleteDirectory​(File path)
        Delete a directory
        Parameters:
        path - directory path
        Returns:
        true if successful, false otherwise