mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
Merge pull request #1210 from kohts/DS-2315
DS-2315: export Simple Archive Format without bitstreams
This commit is contained in:
@@ -71,6 +71,10 @@ public class ItemExportCLITool {
|
||||
options.addOption("z", "zip", true, "export as zip file (specify filename e.g. export.zip)");
|
||||
options.addOption("h", "help", false, "help");
|
||||
|
||||
// as pointed out by Peter Dietz this provides similar functionality to export metadata
|
||||
// but it is needed since it directly exports to Simple Archive Format (SAF)
|
||||
options.addOption("x", "exclude-bitstreams", false, "do not export bitstreams");
|
||||
|
||||
CommandLine line = parser.parse(options, argv);
|
||||
|
||||
String typeString = null;
|
||||
@@ -137,6 +141,12 @@ public class ItemExportCLITool {
|
||||
zipFileName = line.getOptionValue('z');
|
||||
}
|
||||
|
||||
boolean excludeBitstreams = false;
|
||||
if (line.hasOption('x'))
|
||||
{
|
||||
excludeBitstreams = true;
|
||||
}
|
||||
|
||||
// now validate the args
|
||||
if (myType == -1)
|
||||
{
|
||||
@@ -234,14 +244,14 @@ public class ItemExportCLITool {
|
||||
System.out.println("Exporting from collection: " + myIDString);
|
||||
items = itemService.findByCollection(c, mycollection);
|
||||
}
|
||||
itemExportService.exportAsZip(c, items, destDirName, zipFileName, seqStart, migrate);
|
||||
itemExportService.exportAsZip(c, items, destDirName, zipFileName, seqStart, migrate, excludeBitstreams);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (myItem != null)
|
||||
{
|
||||
// it's only a single item
|
||||
itemExportService.exportItem(c, Collections.singletonList(myItem).iterator(), destDirName, seqStart, migrate);
|
||||
itemExportService.exportItem(c, Collections.singletonList(myItem).iterator(), destDirName, seqStart, migrate, excludeBitstreams);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -249,7 +259,7 @@ public class ItemExportCLITool {
|
||||
|
||||
// it's a collection, so do a bunch of items
|
||||
Iterator<Item> i = itemService.findByCollection(c, mycollection);
|
||||
itemExportService.exportItem(c, i, destDirName, seqStart, migrate);
|
||||
itemExportService.exportItem(c, i, destDirName, seqStart, migrate, excludeBitstreams);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -88,7 +88,8 @@ public class ItemExportServiceImpl implements ItemExportService
|
||||
|
||||
@Override
|
||||
public void exportItem(Context c, Iterator<Item> i,
|
||||
String destDirName, int seqStart, boolean migrate) throws Exception
|
||||
String destDirName, int seqStart, boolean migrate,
|
||||
boolean excludeBitstreams) throws Exception
|
||||
{
|
||||
int mySequenceNumber = seqStart;
|
||||
int counter = SUBDIR_LIMIT - 1;
|
||||
@@ -123,13 +124,13 @@ public class ItemExportServiceImpl implements ItemExportService
|
||||
}
|
||||
|
||||
System.out.println("Exporting item to " + mySequenceNumber);
|
||||
exportItem(c, i.next(), fullPath, mySequenceNumber, migrate);
|
||||
exportItem(c, i.next(), fullPath, mySequenceNumber, migrate, excludeBitstreams);
|
||||
mySequenceNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
protected void exportItem(Context c, Item myItem, String destDirName,
|
||||
int seqStart, boolean migrate) throws Exception
|
||||
int seqStart, boolean migrate, boolean excludeBitstreams) throws Exception
|
||||
{
|
||||
File destDir = new File(destDirName);
|
||||
|
||||
@@ -138,8 +139,9 @@ public class ItemExportServiceImpl implements ItemExportService
|
||||
// now create a subdirectory
|
||||
File itemDir = new File(destDir + "/" + seqStart);
|
||||
|
||||
System.out.println("Exporting Item " + myItem.getID() + " to "
|
||||
+ itemDir);
|
||||
System.out.println("Exporting Item " + myItem.getID() +
|
||||
(myItem.getHandle() != null ? ", handle " + myItem.getHandle() : "") +
|
||||
" to " + itemDir);
|
||||
|
||||
if (itemDir.exists())
|
||||
{
|
||||
@@ -151,7 +153,7 @@ public class ItemExportServiceImpl implements ItemExportService
|
||||
{
|
||||
// make it this far, now start exporting
|
||||
writeMetadata(c, myItem, itemDir, migrate);
|
||||
writeBitstreams(c, myItem, itemDir);
|
||||
writeBitstreams(c, myItem, itemDir, excludeBitstreams);
|
||||
if (!migrate)
|
||||
{
|
||||
writeHandle(c, myItem, itemDir);
|
||||
@@ -354,8 +356,8 @@ public class ItemExportServiceImpl implements ItemExportService
|
||||
* @throws Exception
|
||||
* if there is any problem writing to the export directory
|
||||
*/
|
||||
protected void writeBitstreams(Context c, Item i, File destDir)
|
||||
throws Exception
|
||||
protected void writeBitstreams(Context c, Item i, File destDir,
|
||||
boolean excludeBitstreams) throws Exception
|
||||
{
|
||||
File outFile = new File(destDir, "contents");
|
||||
|
||||
@@ -389,12 +391,10 @@ public class ItemExportServiceImpl implements ItemExportService
|
||||
|
||||
int myPrefix = 1; // only used with name conflict
|
||||
|
||||
InputStream is = bitstreamService.retrieve(c, bitstream);
|
||||
|
||||
boolean isDone = false; // done when bitstream is finally
|
||||
// written
|
||||
|
||||
while (!isDone) {
|
||||
while (!excludeBitstreams && !isDone) {
|
||||
if (myName.contains(File.separator)) {
|
||||
String dirs = myName.substring(0, myName
|
||||
.lastIndexOf(File.separator));
|
||||
@@ -408,12 +408,24 @@ public class ItemExportServiceImpl implements ItemExportService
|
||||
File fout = new File(destDir, myName);
|
||||
|
||||
if (fout.createNewFile()) {
|
||||
InputStream is = bitstreamService.retrieve(c, bitstream);
|
||||
FileOutputStream fos = new FileOutputStream(fout);
|
||||
Utils.bufferedCopy(is, fos);
|
||||
// close streams
|
||||
is.close();
|
||||
fos.close();
|
||||
|
||||
isDone = true;
|
||||
} else {
|
||||
myName = myPrefix + "_" + oldName; // keep
|
||||
// appending
|
||||
// numbers to the
|
||||
// filename until
|
||||
// unique
|
||||
myPrefix++;
|
||||
}
|
||||
}
|
||||
|
||||
// write the manifest file entry
|
||||
if (bitstreamService.isRegisteredBitstream(bitstream)) {
|
||||
out.println("-r -s " + bitstream.getStoreNumber()
|
||||
@@ -425,16 +437,6 @@ public class ItemExportServiceImpl implements ItemExportService
|
||||
primary + description);
|
||||
}
|
||||
|
||||
isDone = true;
|
||||
} else {
|
||||
myName = myPrefix + "_" + oldName; // keep
|
||||
// appending
|
||||
// numbers to the
|
||||
// filename until
|
||||
// unique
|
||||
myPrefix++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,7 +452,9 @@ public class ItemExportServiceImpl implements ItemExportService
|
||||
@Override
|
||||
public void exportAsZip(Context context, Iterator<Item> items,
|
||||
String destDirName, String zipFileName,
|
||||
int seqStart, boolean migrate) throws Exception
|
||||
int seqStart, boolean migrate,
|
||||
boolean excludeBitstreams) throws Exception
|
||||
|
||||
{
|
||||
String workDir = getExportWorkDirectory() +
|
||||
System.getProperty("file.separator") +
|
||||
@@ -469,7 +473,7 @@ public class ItemExportServiceImpl implements ItemExportService
|
||||
}
|
||||
|
||||
// export the items using normal export method
|
||||
exportItem(context, items, workDir, seqStart, migrate);
|
||||
exportItem(context, items, workDir, seqStart, migrate, excludeBitstreams);
|
||||
|
||||
// now zip up the export directory created above
|
||||
zip(workDir, destDirName + System.getProperty("file.separator") + zipFileName);
|
||||
@@ -716,7 +720,7 @@ public class ItemExportServiceImpl implements ItemExportService
|
||||
|
||||
|
||||
// export the items using normal export method
|
||||
exportItem(context, iitems, workDir, 1, migrate);
|
||||
exportItem(context, iitems, workDir, 1, migrate, false);
|
||||
}
|
||||
|
||||
// now zip up the export directory created above
|
||||
|
@@ -47,7 +47,8 @@ public interface ItemExportService {
|
||||
public static final String COMPRESSED_EXPORT_MIME_TYPE = "application/zip";
|
||||
|
||||
public void exportItem(Context c, Iterator<Item> i,
|
||||
String destDirName, int seqStart, boolean migrate) throws Exception;
|
||||
String destDirName, int seqStart, boolean migrate,
|
||||
boolean excludeBitstreams) throws Exception;
|
||||
|
||||
/**
|
||||
* Method to perform an export and save it as a zip file.
|
||||
@@ -62,7 +63,8 @@ public interface ItemExportService {
|
||||
*/
|
||||
public void exportAsZip(Context context, Iterator<Item> items,
|
||||
String destDirName, String zipFileName,
|
||||
int seqStart, boolean migrate) throws Exception;
|
||||
int seqStart, boolean migrate,
|
||||
boolean excludeBitstreams) throws Exception;
|
||||
|
||||
/**
|
||||
* Convenience methot to create export a single Community, Collection, or
|
||||
|
Reference in New Issue
Block a user