Merge pull request #2468 from mwoodiupui/DS-4289

[DS-4289] SAF exporter does not write the 'collections' file
This commit is contained in:
Tim Donohue
2022-08-01 13:43:40 -05:00
committed by GitHub

View File

@@ -64,17 +64,21 @@ import org.springframework.beans.factory.annotation.Autowired;
* Item exporter to create simple AIPs for DSpace content. Currently exports * Item exporter to create simple AIPs for DSpace content. Currently exports
* individual items, or entire collections. For instructions on use, see * individual items, or entire collections. For instructions on use, see
* printUsage() method. * printUsage() method.
* <P> * <p>
* ItemExport creates the simple AIP package that the importer also uses. It * ItemExport creates the simple AIP package that the importer also uses. It
* consists of: * consists of:
* <P> * <pre>{@code
* /exportdir/42/ (one directory per item) / dublin_core.xml - qualified dublin * /exportdir/42/ (one directory per item)
* core in RDF schema / contents - text file, listing one file per line / file1 * / dublin_core.xml - qualified dublin core in RDF schema
* - files contained in the item / file2 / ... * / contents - text file, listing one file per line
* <P> * / file1 - files contained in the item
* / file2
* / ...
* }</pre>
* <p>
* issues -doesn't handle special characters in metadata (needs to turn {@code &'s} into * issues -doesn't handle special characters in metadata (needs to turn {@code &'s} into
* {@code &amp;}, etc.) * {@code &amp;}, etc.)
* <P> * <p>
* Modified by David Little, UCSD Libraries 12/21/04 to allow the registration * Modified by David Little, UCSD Libraries 12/21/04 to allow the registration
* of files (bitstreams) into DSpace. * of files (bitstreams) into DSpace.
* *
@@ -101,7 +105,7 @@ public class ItemExportServiceImpl implements ItemExportService {
/** /**
* log4j logger * log4j logger
*/ */
private final Logger log = org.apache.logging.log4j.LogManager.getLogger(ItemExportServiceImpl.class); private final Logger log = org.apache.logging.log4j.LogManager.getLogger();
protected ItemExportServiceImpl() { protected ItemExportServiceImpl() {
@@ -168,6 +172,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, excludeBitstreams); writeBitstreams(c, myItem, itemDir, excludeBitstreams);
writeCollections(myItem, itemDir);
if (!migrate) { if (!migrate) {
writeHandle(c, myItem, itemDir); writeHandle(c, myItem, itemDir);
} }
@@ -343,6 +348,33 @@ public class ItemExportServiceImpl implements ItemExportService {
} }
} }
/**
* Create the 'collections' file. List handles of all Collections which
* contain this Item. The "owning" Collection is listed first.
*
* @param item list collections holding this Item.
* @param destDir write the file here.
* @throws IOException if the file cannot be created or written.
*/
protected void writeCollections(Item item, File destDir)
throws IOException {
File outFile = new File(destDir, "collections");
if (outFile.createNewFile()) {
try (PrintWriter out = new PrintWriter(new FileWriter(outFile))) {
String ownerHandle = item.getOwningCollection().getHandle();
out.println(ownerHandle);
for (Collection collection : item.getCollections()) {
String collectionHandle = collection.getHandle();
if (!collectionHandle.equals(ownerHandle)) {
out.println(collectionHandle);
}
}
}
} else {
throw new IOException("Cannot create 'collections' in " + destDir);
}
}
/** /**
* Create both the bitstreams and the contents file. Any bitstreams that * Create both the bitstreams and the contents file. Any bitstreams that
* were originally registered will be marked in the contents file as such. * were originally registered will be marked in the contents file as such.