Migrating current AIP Backup/Restore code (DS-466) from 'aip-external-1_6-prototype' Branch into Trunk! See https://wiki.duraspace.org/display/DSPACE/AipBackupRestorePrototype for much more details on this work, and how to export/import AIPs. WARNING -- This changes the PackageIngester and PackageDisseminator interfaces. Any of your local, custom Packagers will require refactoring to support the updated interfaces (obviously all DSpace out-of-the-box Packagers have already been refactored).

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5265 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Tim Donohue
2010-08-13 20:10:32 +00:00
parent d1a93e3510
commit 075a913755
46 changed files with 7733 additions and 1557 deletions

View File

@@ -90,17 +90,104 @@ public class InstallItem
Item item = is.getItem();
String handle;
// if no previous handle supplied, create one
if (suppliedHandle == null)
{
// create a new handle for this item
handle = HandleManager.createHandle(c, item);
}
else
{
// assign the supplied handle to this item
handle = HandleManager.createHandle(c, item, suppliedHandle);
}
populateHandleMetadata(item, handle);
// this is really just to flush out fatal embargo metadata
// problems before we set inArchive.
DCDate liftDate = EmbargoManager.getEmbargoDate(c, item);
populateMetadata(c, item, liftDate);
return finishItem(c, item, is, liftDate);
}
/**
* Turn an InProgressSubmission into a fully-archived Item, for
* a "restore" operation such as ingestion of an AIP to recreate an
* archive. This does NOT add any descriptive metadata (e.g. for
* provenance) to preserve the transparency of the ingest. The
* ingest mechanism is assumed to have set all relevant technical
* and administrative metadata fields.
*
* @param c current context
* @param is
* submission to install
* @param suppliedHandle
* the existing Handle to give the installed item, or null
* to create a new one.
*
* @return the fully archived Item
*/
public static Item restoreItem(Context c, InProgressSubmission is,
String suppliedHandle)
throws SQLException, IOException, AuthorizeException
{
Item item = is.getItem();
String handle;
// if no handle supplied
if (suppliedHandle == null)
{
// create a new handle for this item
handle = HandleManager.createHandle(c, item);
//only populate handle metadata for new handles
// (existing handles should already be in the metadata -- as it was restored by ingest process)
populateHandleMetadata(item, handle);
}
else
{
// assign the supplied handle to this item
handle = HandleManager.createHandle(c, item, suppliedHandle);
}
//NOTE: this method specifically skips over "populateMetadata()"
// As this is a "restore" all the metadata should have already been restored
//@TODO: Do we actually want a "Restored on ..." provenance message? Or perhaps kick off an event?
return finishItem(c, item, is, null);
}
private static void populateHandleMetadata(Item item, String handle)
throws SQLException, IOException, AuthorizeException
{
String handleref = HandleManager.getCanonicalForm(handle);
// Add handle as identifier.uri DC value.
// First check that identifier dosn't already exist.
boolean identifierExists = false;
DCValue[] identifiers = item.getDC("identifier", "uri", Item.ANY);
for (DCValue identifier : identifiers)
if (handleref.equals(identifier.value))
identifierExists = true;
if (!identifierExists)
item.addDC("identifier", "uri", null, handleref);
}
// fill in metadata needed by new Item.
private static void populateMetadata(Context c, Item item, DCDate embargoLiftDate)
throws SQLException, IOException, AuthorizeException
{
// create accession date
DCDate now = DCDate.getCurrent();
item.addDC("date", "accessioned", null, now.toString());
// add date available if not under embargo, otherwise it will
// be set when the embargo is lifted.
if (liftDate == null)
if (embargoLiftDate == null)
item.addDC("date", "available", null, now.toString());
// create issue date if not present
@@ -113,30 +200,7 @@ public class InstallItem
item.addDC("date", "issued", null, issued.toString());
}
// if no previous handle supplied, create one
if (suppliedHandle == null)
{
// create handle
handle = HandleManager.createHandle(c, item);
}
else
{
handle = HandleManager.createHandle(c, item, suppliedHandle);
}
String handleref = HandleManager.getCanonicalForm(handle);
// Add handle as identifier.uri DC value.
// First check that identifier dosn't already exist.
boolean identifierExists = false;
DCValue[] identifiers = item.getDC("identifier", "uri", Item.ANY);
for (DCValue identifier : identifiers)
if (handleref.equals(identifier.value))
identifierExists = true;
if (!identifierExists)
item.addDC("identifier", "uri", null, handleref);
String provDescription = "Made available in DSpace on " + now
String provDescription = "Made available in DSpace on " + now
+ " (GMT). " + getBitstreamProvenanceMessage(item);
if (currentDateIssued.length != 0)
@@ -148,7 +212,13 @@ public class InstallItem
// Add provenance description
item.addDC("description", "provenance", "en", provDescription);
}
// final housekeeping when adding new Item to archive
// common between installing and "restoring" items.
private static Item finishItem(Context c, Item item, InProgressSubmission is, DCDate embargoLiftDate)
throws SQLException, IOException, AuthorizeException
{
// create collection2item mapping
is.getCollection().addItem(item);
@@ -163,7 +233,7 @@ public class InstallItem
// Notify interested parties of newly archived Item
c.addEvent(new Event(Event.INSTALL, Constants.ITEM, item.getID(),
handle));
item.getHandle()));
// remove in-progress submission
is.deleteWrapper();
@@ -171,15 +241,14 @@ public class InstallItem
// remove the item's policies and replace them with
// the defaults from the collection
item.inheritCollectionDefaultPolicies(is.getCollection());
// set embargo lift date and take away read access if indicated.
if (liftDate != null)
EmbargoManager.setEmbargo(c, item, liftDate);
if (embargoLiftDate != null)
EmbargoManager.setEmbargo(c, item, embargoLiftDate);
return item;
}
/**
* Generate provenance-worthy description of the bitstreams contained in an
* item.