mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-08 02:24:18 +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("z", "zip", true, "export as zip file (specify filename e.g. export.zip)");
|
||||||
options.addOption("h", "help", false, "help");
|
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);
|
CommandLine line = parser.parse(options, argv);
|
||||||
|
|
||||||
String typeString = null;
|
String typeString = null;
|
||||||
@@ -137,6 +141,12 @@ public class ItemExportCLITool {
|
|||||||
zipFileName = line.getOptionValue('z');
|
zipFileName = line.getOptionValue('z');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean excludeBitstreams = false;
|
||||||
|
if (line.hasOption('x'))
|
||||||
|
{
|
||||||
|
excludeBitstreams = true;
|
||||||
|
}
|
||||||
|
|
||||||
// now validate the args
|
// now validate the args
|
||||||
if (myType == -1)
|
if (myType == -1)
|
||||||
{
|
{
|
||||||
@@ -234,14 +244,14 @@ public class ItemExportCLITool {
|
|||||||
System.out.println("Exporting from collection: " + myIDString);
|
System.out.println("Exporting from collection: " + myIDString);
|
||||||
items = itemService.findByCollection(c, mycollection);
|
items = itemService.findByCollection(c, mycollection);
|
||||||
}
|
}
|
||||||
itemExportService.exportAsZip(c, items, destDirName, zipFileName, seqStart, migrate);
|
itemExportService.exportAsZip(c, items, destDirName, zipFileName, seqStart, migrate, excludeBitstreams);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (myItem != null)
|
if (myItem != null)
|
||||||
{
|
{
|
||||||
// it's only a single item
|
// 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
|
else
|
||||||
{
|
{
|
||||||
@@ -249,7 +259,7 @@ public class ItemExportCLITool {
|
|||||||
|
|
||||||
// it's a collection, so do a bunch of items
|
// it's a collection, so do a bunch of items
|
||||||
Iterator<Item> i = itemService.findByCollection(c, mycollection);
|
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
|
@Override
|
||||||
public void exportItem(Context c, Iterator<Item> i,
|
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 mySequenceNumber = seqStart;
|
||||||
int counter = SUBDIR_LIMIT - 1;
|
int counter = SUBDIR_LIMIT - 1;
|
||||||
@@ -123,13 +124,13 @@ public class ItemExportServiceImpl implements ItemExportService
|
|||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Exporting item to " + mySequenceNumber);
|
System.out.println("Exporting item to " + mySequenceNumber);
|
||||||
exportItem(c, i.next(), fullPath, mySequenceNumber, migrate);
|
exportItem(c, i.next(), fullPath, mySequenceNumber, migrate, excludeBitstreams);
|
||||||
mySequenceNumber++;
|
mySequenceNumber++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void exportItem(Context c, Item myItem, String destDirName,
|
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);
|
File destDir = new File(destDirName);
|
||||||
|
|
||||||
@@ -138,8 +139,9 @@ public class ItemExportServiceImpl implements ItemExportService
|
|||||||
// now create a subdirectory
|
// now create a subdirectory
|
||||||
File itemDir = new File(destDir + "/" + seqStart);
|
File itemDir = new File(destDir + "/" + seqStart);
|
||||||
|
|
||||||
System.out.println("Exporting Item " + myItem.getID() + " to "
|
System.out.println("Exporting Item " + myItem.getID() +
|
||||||
+ itemDir);
|
(myItem.getHandle() != null ? ", handle " + myItem.getHandle() : "") +
|
||||||
|
" to " + itemDir);
|
||||||
|
|
||||||
if (itemDir.exists())
|
if (itemDir.exists())
|
||||||
{
|
{
|
||||||
@@ -151,7 +153,7 @@ public class ItemExportServiceImpl implements ItemExportService
|
|||||||
{
|
{
|
||||||
// make it this far, now start exporting
|
// make it this far, now start exporting
|
||||||
writeMetadata(c, myItem, itemDir, migrate);
|
writeMetadata(c, myItem, itemDir, migrate);
|
||||||
writeBitstreams(c, myItem, itemDir);
|
writeBitstreams(c, myItem, itemDir, excludeBitstreams);
|
||||||
if (!migrate)
|
if (!migrate)
|
||||||
{
|
{
|
||||||
writeHandle(c, myItem, itemDir);
|
writeHandle(c, myItem, itemDir);
|
||||||
@@ -354,8 +356,8 @@ public class ItemExportServiceImpl implements ItemExportService
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
* if there is any problem writing to the export directory
|
* if there is any problem writing to the export directory
|
||||||
*/
|
*/
|
||||||
protected void writeBitstreams(Context c, Item i, File destDir)
|
protected void writeBitstreams(Context c, Item i, File destDir,
|
||||||
throws Exception
|
boolean excludeBitstreams) throws Exception
|
||||||
{
|
{
|
||||||
File outFile = new File(destDir, "contents");
|
File outFile = new File(destDir, "contents");
|
||||||
|
|
||||||
@@ -389,12 +391,10 @@ public class ItemExportServiceImpl implements ItemExportService
|
|||||||
|
|
||||||
int myPrefix = 1; // only used with name conflict
|
int myPrefix = 1; // only used with name conflict
|
||||||
|
|
||||||
InputStream is = bitstreamService.retrieve(c, bitstream);
|
|
||||||
|
|
||||||
boolean isDone = false; // done when bitstream is finally
|
boolean isDone = false; // done when bitstream is finally
|
||||||
// written
|
// written
|
||||||
|
|
||||||
while (!isDone) {
|
while (!excludeBitstreams && !isDone) {
|
||||||
if (myName.contains(File.separator)) {
|
if (myName.contains(File.separator)) {
|
||||||
String dirs = myName.substring(0, myName
|
String dirs = myName.substring(0, myName
|
||||||
.lastIndexOf(File.separator));
|
.lastIndexOf(File.separator));
|
||||||
@@ -408,23 +408,13 @@ public class ItemExportServiceImpl implements ItemExportService
|
|||||||
File fout = new File(destDir, myName);
|
File fout = new File(destDir, myName);
|
||||||
|
|
||||||
if (fout.createNewFile()) {
|
if (fout.createNewFile()) {
|
||||||
|
InputStream is = bitstreamService.retrieve(c, bitstream);
|
||||||
FileOutputStream fos = new FileOutputStream(fout);
|
FileOutputStream fos = new FileOutputStream(fout);
|
||||||
Utils.bufferedCopy(is, fos);
|
Utils.bufferedCopy(is, fos);
|
||||||
// close streams
|
// close streams
|
||||||
is.close();
|
is.close();
|
||||||
fos.close();
|
fos.close();
|
||||||
|
|
||||||
// write the manifest file entry
|
|
||||||
if (bitstreamService.isRegisteredBitstream(bitstream)) {
|
|
||||||
out.println("-r -s " + bitstream.getStoreNumber()
|
|
||||||
+ " -f " + myName +
|
|
||||||
"\tbundle:" + bundleName +
|
|
||||||
primary + description);
|
|
||||||
} else {
|
|
||||||
out.println(myName + "\tbundle:" + bundleName +
|
|
||||||
primary + description);
|
|
||||||
}
|
|
||||||
|
|
||||||
isDone = true;
|
isDone = true;
|
||||||
} else {
|
} else {
|
||||||
myName = myPrefix + "_" + oldName; // keep
|
myName = myPrefix + "_" + oldName; // keep
|
||||||
@@ -435,6 +425,18 @@ public class ItemExportServiceImpl implements ItemExportService
|
|||||||
myPrefix++;
|
myPrefix++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// write the manifest file entry
|
||||||
|
if (bitstreamService.isRegisteredBitstream(bitstream)) {
|
||||||
|
out.println("-r -s " + bitstream.getStoreNumber()
|
||||||
|
+ " -f " + myName +
|
||||||
|
"\tbundle:" + bundleName +
|
||||||
|
primary + description);
|
||||||
|
} else {
|
||||||
|
out.println(myName + "\tbundle:" + bundleName +
|
||||||
|
primary + description);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,7 +452,9 @@ public class ItemExportServiceImpl implements ItemExportService
|
|||||||
@Override
|
@Override
|
||||||
public void exportAsZip(Context context, Iterator<Item> items,
|
public void exportAsZip(Context context, Iterator<Item> items,
|
||||||
String destDirName, String zipFileName,
|
String destDirName, String zipFileName,
|
||||||
int seqStart, boolean migrate) throws Exception
|
int seqStart, boolean migrate,
|
||||||
|
boolean excludeBitstreams) throws Exception
|
||||||
|
|
||||||
{
|
{
|
||||||
String workDir = getExportWorkDirectory() +
|
String workDir = getExportWorkDirectory() +
|
||||||
System.getProperty("file.separator") +
|
System.getProperty("file.separator") +
|
||||||
@@ -469,7 +473,7 @@ public class ItemExportServiceImpl implements ItemExportService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// export the items using normal export method
|
// 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
|
// now zip up the export directory created above
|
||||||
zip(workDir, destDirName + System.getProperty("file.separator") + zipFileName);
|
zip(workDir, destDirName + System.getProperty("file.separator") + zipFileName);
|
||||||
@@ -716,7 +720,7 @@ public class ItemExportServiceImpl implements ItemExportService
|
|||||||
|
|
||||||
|
|
||||||
// export the items using normal export method
|
// 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
|
// 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 static final String COMPRESSED_EXPORT_MIME_TYPE = "application/zip";
|
||||||
|
|
||||||
public void exportItem(Context c, Iterator<Item> i,
|
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.
|
* 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,
|
public void exportAsZip(Context context, Iterator<Item> items,
|
||||||
String destDirName, String zipFileName,
|
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
|
* Convenience methot to create export a single Community, Collection, or
|
||||||
|
Reference in New Issue
Block a user