Package org.dspace.app.itemexport
Class ItemExportServiceImpl
java.lang.Object
org.dspace.app.itemexport.ItemExportServiceImpl
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprotected BitstreamServiceprotected CommunityServiceprotected ConfigurationServiceprotected EPersonServiceprotected HandleServiceprotected ItemServiceprotected final intFields inherited from interface org.dspace.app.itemexport.service.ItemExportService
COMPRESSED_EXPORT_MIME_TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionassembleFileName(String type, EPerson eperson, LocalDate date) Create a file name based on the date and epersonbooleancanDownload(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 itvoidcreateDownloadableExport(List<DSpaceObject> dsObjects, Context context, boolean migrate) Convenience method to export a List of dspace objects (Community, Collection or Item)voidcreateDownloadableExport(List<DSpaceObject> dsObjects, Context context, String additionalEmail, boolean migrate) Convenience method to export a List of dspace objects (Community, Collection or Item)voidcreateDownloadableExport(DSpaceObject dso, Context context, boolean migrate) Convenience method to create export a single Community, Collection, or ItemvoidcreateDownloadableExport(DSpaceObject dso, Context context, String additionalEmail, boolean migrate) Convenience method to create export a single Community, Collection, or Itemprotected booleandeleteDirectory(File path) Delete a directoryvoidA clean up method that is ran before a new export archive is created.voiddeleteOldExportArchives(EPerson eperson) A clean up method that is ran before a new export archive is created.voidemailErrorMessage(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.voidemailSuccessMessage(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.voidexportAsZip(Context context, Iterator<Item> items, String destDirName, String zipFileName, int seqStart, boolean migrate, boolean excludeBitstreams) Method to perform an export and save it as a zip file.voidexportItem(Context c, Iterator<Item> i, String destDirName, int seqStart, boolean migrate, boolean excludeBitstreams) protected voidexportItem(Context c, Item myItem, String destDirName, int seqStart, boolean migrate, boolean excludeBitstreams) protected EPersongetEPersonFromString(Context context, String strID) Attempt to find an EPerson based on string IDgetExportDownloadDirectory(EPerson ePerson) Use config file entry for org.dspace.app.itemexport.download.dir and id of the eperson to create a download directory namegetExportDownloadInputStream(String fileName, EPerson eperson) Used to read the export archived.longgetExportFileLastModified(Context context, String fileName) Get the last modified date of the export archive represented by the file name.longgetExportFileSize(Context context, String fileName) Get the file size of the export archive represented by the file name.getExportsAvailable(EPerson eperson) Reads the download directory for the eperson to see if any export archives are availableReturns config file entry for org.dspace.app.itemexport.work.dirprotected voidprocessDownloadableExport(List<DSpaceObject> dsObjects, Context context, String additionalEmail, boolean toMigrate) 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 emailvoidsetHandler(DSpaceRunnableHandler handler) Set the DSpace Runnable Handlerprotected voidwriteBitstreams(Context c, Item i, File destDir, boolean excludeBitstreams) Create both the bitstreams and the contents file.protected voidwriteCollections(Item item, File destDir) Create the 'collections' file.protected voidwriteHandle(Context c, Item i, File destDir) create the file 'handle' which contains the handle assigned to the itemprotected voidwriteMetadata(Context c, String schema, Item i, File destDir, boolean migrate) output the item's dublin core into the item directoryprotected voidwriteMetadata(Context c, Item i, File destDir, boolean migrate) Discover the different schemas in use and output a separate metadata XML file for each schema.voidZip source to targetprotected voidzipFiles(File cpFile, String strSource, String strTarget, ZipOutputStream cpZipOutputStream)
-
Field Details
-
SUBDIR_LIMIT
protected final int SUBDIR_LIMIT- See Also:
-
bitstreamService
-
communityService
-
ePersonService
-
itemService
-
handleService
-
configurationService
-
-
Constructor Details
-
ItemExportServiceImpl
protected ItemExportServiceImpl()
-
-
Method Details
-
exportItem
public void exportItem(Context c, Iterator<Item> i, String destDirName, int seqStart, boolean migrate, boolean excludeBitstreams) throws Exception - Specified by:
exportItemin interfaceItemExportService- Throws:
Exception
-
exportItem
protected void exportItem(Context c, Item myItem, String destDirName, int seqStart, boolean migrate, boolean excludeBitstreams) throws Exception - Throws:
Exception
-
writeMetadata
Discover the different schemas in use and output a separate metadata XML file for each schema.- Parameters:
c- DSpace contexti- DSpace ItemdestDir- destination directorymigrate- 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 contextschema- schemai- DSpace ItemdestDir- destination directorymigrate- Whether to use the migrate option or not- Throws:
Exception- if error
-
writeHandle
create the file 'handle' which contains the handle assigned to the item- Parameters:
c- DSpace Contexti- DSpace ItemdestDir- destination directory- Throws:
Exception- if error
-
writeCollections
Create the 'collections' file. List handles of all Collections which contain this Item. The "owning" Collection is listed first.- Parameters:
item- list collections holding this Item.destDir- write the file here.- Throws:
IOException- if the file cannot be created or written.
-
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 contexti- the item being exporteddestDir- the item's export directoryexcludeBitstreams- 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:ItemExportServiceMethod to perform an export and save it as a zip file.- Specified by:
exportAsZipin interfaceItemExportService- Parameters:
context- The DSpace Contextitems- The items to exportdestDirName- The directory to save the export inzipFileName- The name to save the zip file asseqStart- The first number in the sequencemigrate- Whether to use the migrate option or notexcludeBitstreams- 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:ItemExportServiceConvenience method to create export a single Community, Collection, or Item- Specified by:
createDownloadableExportin interfaceItemExportService- Parameters:
dso- - the dspace object to exportcontext- - the dspace contextmigrate- 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:ItemExportServiceConvenience method to export a List of dspace objects (Community, Collection or Item)- Specified by:
createDownloadableExportin interfaceItemExportService- Parameters:
dsObjects- - List containing dspace objectscontext- - the dspace contextmigrate- 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:ItemExportServiceConvenience method to create export a single Community, Collection, or Item- Specified by:
createDownloadableExportin interfaceItemExportService- Parameters:
dso- - the dspace object to exportcontext- - the dspace contextadditionalEmail- - cc email to usemigrate- 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:ItemExportServiceConvenience method to export a List of dspace objects (Community, Collection or Item)- Specified by:
createDownloadableExportin interfaceItemExportService- Parameters:
dsObjects- - List containing dspace objectscontext- - the dspace contextadditionalEmail- - cc email to usemigrate- 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 processcontext- - the dspace contextadditionalEmail- - email address to cc in addition the the current user emailtoMigrate- Whether to use the migrate option or not- Throws:
Exception- if error
-
assembleFileName
Description copied from interface:ItemExportServiceCreate a file name based on the date and eperson- Specified by:
assembleFileNamein interfaceItemExportService- Parameters:
type- Type of object (as string)eperson- - eperson who requested export and will be able to download itdate- - 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
Description copied from interface:ItemExportServiceUse config file entry for org.dspace.app.itemexport.download.dir and id of the eperson to create a download directory name- Specified by:
getExportDownloadDirectoryin interfaceItemExportService- 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
-
getExportWorkDirectory
Description copied from interface:ItemExportServiceReturns config file entry for org.dspace.app.itemexport.work.dir- Specified by:
getExportWorkDirectoryin interfaceItemExportService- Returns:
- String representing config file entry for org.dspace.app.itemexport.work.dir
- Throws:
Exception- if error
-
getExportDownloadInputStream
Description copied from interface:ItemExportServiceUsed to read the export archived. Intended for download.- Specified by:
getExportDownloadInputStreamin interfaceItemExportService- Parameters:
fileName- the name of the file to downloadeperson- the eperson requesting the download- Returns:
- an input stream of the file to be downloaded
- Throws:
Exception- if error
-
getExportFileSize
Description copied from interface:ItemExportServiceGet the file size of the export archive represented by the file name.- Specified by:
getExportFileSizein interfaceItemExportService- Parameters:
context- DSpace contextfileName- name of the file to get the size.- Returns:
- size as long
- Throws:
Exception- if error
-
getEPersonFromString
Attempt to find an EPerson based on string ID- Parameters:
context- DSpace contextstrID- string identifier- Returns:
- EPerson object (if found)
- Throws:
SQLException- if database error
-
getExportFileLastModified
Description copied from interface:ItemExportServiceGet the last modified date of the export archive represented by the file name.- Specified by:
getExportFileLastModifiedin interfaceItemExportService- Parameters:
context- DSpace contextfileName- name of the file to get the size.- Returns:
- date as long
- Throws:
Exception- if error- See Also:
-
canDownload
Description copied from interface:ItemExportServiceThe 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:
canDownloadin interfaceItemExportService- Parameters:
context- dspace contextfileName- the file name to check auths for- Returns:
- true if it is the same person false otherwise
-
getExportsAvailable
Description copied from interface:ItemExportServiceReads the download directory for the eperson to see if any export archives are available- Specified by:
getExportsAvailablein interfaceItemExportService- Parameters:
eperson- EPerson object- Returns:
- a list of file names representing export archives that have been processed
- Throws:
Exception- if error
-
deleteOldExportArchives
Description copied from interface:ItemExportServiceA 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:
deleteOldExportArchivesin interfaceItemExportService- Parameters:
eperson- - the eperson to clean up- Throws:
Exception- if error
-
deleteOldExportArchives
Description copied from interface:ItemExportServiceA 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:
deleteOldExportArchivesin interfaceItemExportService- Throws:
Exception- if error
-
emailSuccessMessage
public void emailSuccessMessage(Context context, EPerson eperson, String fileName) throws jakarta.mail.MessagingException Description copied from interface:ItemExportServiceSince the archive is created in a new thread we are unable to communicate with calling method about success or failure. We accomplish this communication with email instead. Send a success email once the export archive is complete and ready for download- Specified by:
emailSuccessMessagein interfaceItemExportService- Parameters:
context- - the current Contexteperson- - eperson to send the email tofileName- - the file name to be downloaded. It is added to the url in the email- Throws:
jakarta.mail.MessagingException- if error
-
emailErrorMessage
Description copied from interface:ItemExportServiceSince the archive is created in a new thread we are unable to communicate with calling method about success or failure. We accomplish this communication with email instead. Send an error email if the export archive fails- Specified by:
emailErrorMessagein interfaceItemExportService- Parameters:
eperson- - EPerson to send the error message toerror- - the error message- Throws:
jakarta.mail.MessagingException- if error
-
zip
Description copied from interface:ItemExportServiceZip source to target- Specified by:
zipin interfaceItemExportService- Parameters:
strSource- source filetarget- target file- Throws:
Exception- if error
-
zipFiles
protected void zipFiles(File cpFile, String strSource, String strTarget, ZipOutputStream cpZipOutputStream) throws Exception - Parameters:
cpFile- filestrSource- source locationstrTarget- target locationcpZipOutputStream- current zip outputstream- Throws:
Exception- if error
-
deleteDirectory
Delete a directory- Parameters:
path- directory path- Returns:
- true if successful, false otherwise
-
setHandler
Description copied from interface:ItemExportServiceSet the DSpace Runnable Handler- Specified by:
setHandlerin interfaceItemExportService
-