mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
Adding another minor option to the AIP Disseminator (DS-466). There's now also an 'updatedAfter' flag, which allows for a very basic form of 'incremental backup'. When this flag is used, an ISO-8601 date must be specified. When used, the AIP Disseminator will only export Item AIPs for items that have changed since that date (it will still always export all Community & Collection AIPs, as there's no last-modified date for them). This new option has also been already documented in the AIP Backup & Restore docs at: https://wiki.duraspace.org/display/DSDOC/AipBackupRestore
git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5696 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -114,73 +114,77 @@ public abstract class AbstractPackageDisseminator
|
||||
//try to disseminate the first object using provided PackageDisseminator
|
||||
disseminate(context, dso, params, pkgFile);
|
||||
|
||||
//add to list of successfully disseminated packages
|
||||
addToPackageList(pkgFile);
|
||||
|
||||
//We can only recursively disseminate non-Items
|
||||
//(NOTE: Items have no children, as Bitstreams/Bundles are created from Item packages)
|
||||
if(dso.getType()!=Constants.ITEM)
|
||||
//check if package was disseminated
|
||||
if(pkgFile.exists())
|
||||
{
|
||||
//Determine where first file package was disseminated to, as all
|
||||
//others will be written to same directory
|
||||
String pkgDirectory = pkgFile.getCanonicalFile().getParent();
|
||||
if(!pkgDirectory.endsWith(File.separator))
|
||||
//add to list of successfully disseminated packages
|
||||
addToPackageList(pkgFile);
|
||||
|
||||
//We can only recursively disseminate non-Items
|
||||
//(NOTE: Items have no children, as Bitstreams/Bundles are created from Item packages)
|
||||
if(dso.getType()!=Constants.ITEM)
|
||||
{
|
||||
pkgDirectory += File.separator;
|
||||
}
|
||||
String fileExtension = PackageUtils.getFileExtension(pkgFile.getName());
|
||||
//Determine where first file package was disseminated to, as all
|
||||
//others will be written to same directory
|
||||
String pkgDirectory = pkgFile.getCanonicalFile().getParent();
|
||||
if(!pkgDirectory.endsWith(File.separator))
|
||||
{
|
||||
pkgDirectory += File.separator;
|
||||
}
|
||||
String fileExtension = PackageUtils.getFileExtension(pkgFile.getName());
|
||||
|
||||
//recursively disseminate content, based on object type
|
||||
switch (dso.getType())
|
||||
{
|
||||
case Constants.COLLECTION :
|
||||
//Also find all Items in this Collection and disseminate
|
||||
Collection collection = (Collection) dso;
|
||||
ItemIterator iterator = collection.getAllItems();
|
||||
while(iterator.hasNext())
|
||||
{
|
||||
Item item = iterator.next();
|
||||
//recursively disseminate content, based on object type
|
||||
switch (dso.getType())
|
||||
{
|
||||
case Constants.COLLECTION :
|
||||
//Also find all Items in this Collection and disseminate
|
||||
Collection collection = (Collection) dso;
|
||||
ItemIterator iterator = collection.getAllItems();
|
||||
while(iterator.hasNext())
|
||||
{
|
||||
Item item = iterator.next();
|
||||
|
||||
//disseminate all items (recursively!)
|
||||
String childFileName = pkgDirectory + PackageUtils.getPackageName(item, fileExtension);
|
||||
disseminateAll(context, item, params, new File(childFileName));
|
||||
}
|
||||
//disseminate all items (recursively!)
|
||||
String childFileName = pkgDirectory + PackageUtils.getPackageName(item, fileExtension);
|
||||
disseminateAll(context, item, params, new File(childFileName));
|
||||
}
|
||||
|
||||
break;
|
||||
case Constants.COMMUNITY :
|
||||
//Also find all SubCommunities in this Community and disseminate
|
||||
Community community = (Community) dso;
|
||||
Community[] subcommunities = community.getSubcommunities();
|
||||
for(int i=0; i<subcommunities.length; i++)
|
||||
{
|
||||
//disseminate all sub-communities (recursively!)
|
||||
String childFileName = pkgDirectory + PackageUtils.getPackageName(subcommunities[i], fileExtension);
|
||||
disseminateAll(context, subcommunities[i], params, new File(childFileName));
|
||||
}
|
||||
break;
|
||||
case Constants.COMMUNITY :
|
||||
//Also find all SubCommunities in this Community and disseminate
|
||||
Community community = (Community) dso;
|
||||
Community[] subcommunities = community.getSubcommunities();
|
||||
for(int i=0; i<subcommunities.length; i++)
|
||||
{
|
||||
//disseminate all sub-communities (recursively!)
|
||||
String childFileName = pkgDirectory + PackageUtils.getPackageName(subcommunities[i], fileExtension);
|
||||
disseminateAll(context, subcommunities[i], params, new File(childFileName));
|
||||
}
|
||||
|
||||
//Also find all Collections in this Community and disseminate
|
||||
Collection[] collections = community.getCollections();
|
||||
for(int i=0; i<collections.length; i++)
|
||||
{
|
||||
//disseminate all collections (recursively!)
|
||||
String childFileName = pkgDirectory + PackageUtils.getPackageName(collections[i], fileExtension);
|
||||
disseminateAll(context, collections[i], params, new File(childFileName));
|
||||
}
|
||||
//Also find all Collections in this Community and disseminate
|
||||
Collection[] collections = community.getCollections();
|
||||
for(int i=0; i<collections.length; i++)
|
||||
{
|
||||
//disseminate all collections (recursively!)
|
||||
String childFileName = pkgDirectory + PackageUtils.getPackageName(collections[i], fileExtension);
|
||||
disseminateAll(context, collections[i], params, new File(childFileName));
|
||||
}
|
||||
|
||||
break;
|
||||
case Constants.SITE :
|
||||
//Also find all top-level Communities and disseminate
|
||||
Community[] topCommunities = Community.findAllTop(context);
|
||||
for(int i=0; i<topCommunities.length; i++)
|
||||
{
|
||||
//disseminate all top-level communities (recursively!)
|
||||
String childFileName = pkgDirectory + PackageUtils.getPackageName(topCommunities[i], fileExtension);
|
||||
disseminateAll(context, topCommunities[i], params, new File(childFileName));
|
||||
}
|
||||
break;
|
||||
case Constants.SITE :
|
||||
//Also find all top-level Communities and disseminate
|
||||
Community[] topCommunities = Community.findAllTop(context);
|
||||
for(int i=0; i<topCommunities.length; i++)
|
||||
{
|
||||
//disseminate all top-level communities (recursively!)
|
||||
String childFileName = pkgDirectory + PackageUtils.getPackageName(topCommunities[i], fileExtension);
|
||||
disseminateAll(context, topCommunities[i], params, new File(childFileName));
|
||||
}
|
||||
|
||||
break;
|
||||
}//end switch
|
||||
}//end if not an Item
|
||||
break;
|
||||
}//end switch
|
||||
}//end if not an Item
|
||||
}//end if pkgFile exists
|
||||
|
||||
//return list of all successfully disseminated packages
|
||||
return getPackageList();
|
||||
|
@@ -76,6 +76,9 @@ import edu.harvard.hul.ois.mets.Type;
|
||||
import edu.harvard.hul.ois.mets.helper.MetsException;
|
||||
import edu.harvard.hul.ois.mets.helper.PCData;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import org.dspace.core.Utils;
|
||||
|
||||
/**
|
||||
* Subclass of the METS packager framework to disseminate a DSpace
|
||||
@@ -155,8 +158,32 @@ public class DSpaceAIPDisseminator extends AbstractMETSDisseminator
|
||||
//Before disseminating anything, save the passed in PackageParameters, so they can be used by all methods
|
||||
disseminateParams = params;
|
||||
|
||||
//just do a normal dissemination as specified by AbstractMETSDisseminator
|
||||
super.disseminate(context, dso, params, pkgFile);
|
||||
boolean disseminate = true; //by default, always disseminate
|
||||
|
||||
//if user specified to only disseminate objects updated *after* a specific date
|
||||
// (Note: this only works for Items right now, as DSpace doesn't store a
|
||||
// last modified date for Collections or Communities)
|
||||
if(disseminateParams.containsKey("updatedAfter") && dso.getType()==Constants.ITEM)
|
||||
{
|
||||
Date afterDate = Utils.parseISO8601Date(disseminateParams.getProperty("updatedAfter"));
|
||||
|
||||
//if null is returned, we couldn't parse the date!
|
||||
if(afterDate==null)
|
||||
throw new IOException("Invalid date passed in via 'updatedAfter' option. Date must be in ISO-8601 format, and include both a day and time (e.g. 2010-01-01T00:00:00).");
|
||||
|
||||
//check when this item was last modified.
|
||||
Item i = (Item) dso;
|
||||
if(i.getLastModified().after(afterDate))
|
||||
disseminate = true;
|
||||
else
|
||||
disseminate = false;
|
||||
}
|
||||
|
||||
if(disseminate)
|
||||
{
|
||||
//just do a normal dissemination as specified by AbstractMETSDisseminator
|
||||
super.disseminate(context, dso, params, pkgFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user