org.dspace.app.itemexport
Class ItemExport

java.lang.Object
  extended by org.dspace.app.itemexport.ItemExport

public class ItemExport
extends Object

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 Summary
static String COMPRESSED_EXPORT_MIME_TYPE
          used for export download
 
Constructor Summary
ItemExport()
           
 
Method Summary
static String assembleFileName(String type, EPerson eperson, Date date)
          Create a file name based on the date and eperson
static boolean canDownload(Context context, String fileName)
          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
static void createDownloadableExport(DSpaceObject dso, Context context, boolean migrate)
          Convenience methot to create export a single Community, Collection, or Item
static void createDownloadableExport(DSpaceObject dso, Context context, String additionalEmail, boolean migrate)
          Convenience methot to create export a single Community, Collection, or Item
static void createDownloadableExport(List<DSpaceObject> dsObjects, Context context, boolean migrate)
          Convenience method to export a List of dspace objects (Community, Collection or Item)
static void createDownloadableExport(List<DSpaceObject> dsObjects, Context context, String additionalEmail, boolean migrate)
          Convenience method to export a List of dspace objects (Community, Collection or Item)
static void deleteOldExportArchives(int epersonID)
          A clean up method that is ran before a new export archive is created.
static void emailErrorMessage(EPerson eperson, String error)
          Since the archive is created in a new thread we are unable to communicate with calling method about success or failure.
static void emailSuccessMessage(Context context, EPerson eperson, String fileName)
          Since the archive is created in a new thread we are unable to communicate with calling method about success or failure.
static void exportAsZip(Context context, ItemIterator items, String destDirName, String zipFileName, int seqStart, boolean migrate)
          Method to perform an export and save it as a zip file.
static String getExportDownloadDirectory(int ePersonID)
          Use config file entry for org.dspace.app.itemexport.download.dir and id of the eperson to create a download directory name
static InputStream getExportDownloadInputStream(String fileName, EPerson eperson)
          Used to read the export archived.
static long getExportFileLastModified(String fileName)
           
static long getExportFileSize(String fileName)
          Get the file size of the export archive represented by the file name
static List<String> getExportsAvailable(EPerson eperson)
          Reads the download directory for the eperson to see if any export archives are available
static String getExportWorkDirectory()
          Returns config file entry for org.dspace.app.itemexport.work.dir
static void main(String[] argv)
           
static void zip(String strSource, String target)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPRESSED_EXPORT_MIME_TYPE

public static final String COMPRESSED_EXPORT_MIME_TYPE
used for export download

See Also:
Constant Field Values
Constructor Detail

ItemExport

public ItemExport()
Method Detail

main

public static void main(String[] argv)
                 throws Exception
Throws:
Exception

exportAsZip

public static void exportAsZip(Context context,
                               ItemIterator items,
                               String destDirName,
                               String zipFileName,
                               int seqStart,
                               boolean migrate)
                        throws Exception
Method to perform an export and save it as a zip file.

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
Throws:
Exception

createDownloadableExport

public static void createDownloadableExport(DSpaceObject dso,
                                            Context context,
                                            boolean migrate)
                                     throws Exception
Convenience methot to create export a single Community, Collection, or Item

Parameters:
dso - - the dspace object to export
context - - the dspace context
Throws:
Exception

createDownloadableExport

public static void createDownloadableExport(List<DSpaceObject> dsObjects,
                                            Context context,
                                            boolean migrate)
                                     throws Exception
Convenience method to export a List of dspace objects (Community, Collection or Item)

Parameters:
dsObjects - - List containing dspace objects
context - - the dspace context
Throws:
Exception

createDownloadableExport

public static void createDownloadableExport(DSpaceObject dso,
                                            Context context,
                                            String additionalEmail,
                                            boolean migrate)
                                     throws Exception
Convenience methot to create export a single Community, Collection, or Item

Parameters:
dso - - the dspace object to export
context - - the dspace context
additionalEmail - - cc email to use
Throws:
Exception

createDownloadableExport

public static void createDownloadableExport(List<DSpaceObject> dsObjects,
                                            Context context,
                                            String additionalEmail,
                                            boolean migrate)
                                     throws Exception
Convenience method to export a List of dspace objects (Community, Collection or Item)

Parameters:
dsObjects - - List containing dspace objects
context - - the dspace context
additionalEmail - - cc email to use
Throws:
Exception

assembleFileName

public static String assembleFileName(String type,
                                      EPerson eperson,
                                      Date date)
                               throws Exception
Create a file name based on the date and eperson

Parameters:
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

getExportDownloadDirectory

public static String getExportDownloadDirectory(int ePersonID)
                                         throws Exception
Use config file entry for org.dspace.app.itemexport.download.dir and id of the eperson to create a download directory name

Parameters:
ePersonID - - id of the eperson who requested export archive
Returns:
String representing a directory in the form of org.dspace.app.itemexport.download.dir/epersonID
Throws:
Exception

getExportWorkDirectory

public static String getExportWorkDirectory()
                                     throws Exception
Returns config file entry for org.dspace.app.itemexport.work.dir

Returns:
String representing config file entry for org.dspace.app.itemexport.work.dir
Throws:
Exception

getExportDownloadInputStream

public static InputStream getExportDownloadInputStream(String fileName,
                                                       EPerson eperson)
                                                throws Exception
Used to read the export archived. Inteded for download.

Parameters:
fileName - the name of the file to download
eperson - the eperson requesting the download
Returns:
an input stream of the file to be downloaded
Throws:
Exception

getExportFileSize

public static long getExportFileSize(String fileName)
                              throws Exception
Get the file size of the export archive represented by the file name

Parameters:
fileName - name of the file to get the size
Returns:
Throws:
Exception

getExportFileLastModified

public static long getExportFileLastModified(String fileName)
                                      throws Exception
Throws:
Exception

canDownload

public static boolean canDownload(Context context,
                                  String fileName)
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

Parameters:
context - dspace context
fileName - the file name to check auths for
Returns:
true if it is the same person false otherwise

getExportsAvailable

public static List<String> getExportsAvailable(EPerson eperson)
                                        throws Exception
Reads the download directory for the eperson to see if any export archives are available

Parameters:
eperson -
Returns:
a list of file names representing export archives that have been processed
Throws:
Exception

deleteOldExportArchives

public static void deleteOldExportArchives(int epersonID)
                                    throws Exception
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

Parameters:
epersonID - - the id of the eperson to clean up
Throws:
Exception

emailSuccessMessage

public static void emailSuccessMessage(Context context,
                                       EPerson eperson,
                                       String fileName)
                                throws javax.mail.MessagingException
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

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

emailErrorMessage

public static void emailErrorMessage(EPerson eperson,
                                     String error)
                              throws javax.mail.MessagingException
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

Parameters:
eperson - - EPerson to send the error message to
error - - the error message
Throws:
javax.mail.MessagingException

zip

public static void zip(String strSource,
                       String target)
                throws Exception
Throws:
Exception


Copyright © 2010 DuraSpace. All Rights Reserved.