Make Packager restore item mappings to non-owning Collections

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5397 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Mark Wood
2010-10-06 14:46:30 +00:00
parent 99c1f44c68
commit ba50e4fa87
2 changed files with 47 additions and 1 deletions

View File

@@ -1034,6 +1034,22 @@ public class Item extends DSpaceObject
modified = true;
}
/**
* See whether this Item is contained by a given Collection.
* @param collection
* @return true if {@code collection} contains this Item.
* @throws SQLException
*/
public boolean isIn(Collection collection) throws SQLException
{
TableRow tr = DatabaseManager.querySingle(ourContext,
"SELECT COUNT(*) AS count" +
" FROM collection2item" +
" WHERE collection_id = ? AND item_id = ?",
collection.getID(), itemRow.getIntColumn("item_id"));
return tr.getLongColumn("count") > 0;
}
/**
* Get the collections this item is in. The order is indeterminate.
*

View File

@@ -49,7 +49,9 @@ import java.util.Map;
import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.content.crosswalk.CrosswalkException;
import org.dspace.core.Constants;
import org.dspace.core.Context;
@@ -178,11 +180,25 @@ public abstract class AbstractPackageIngester
//Recursively ingest each child package, using this current object as the parent DSpace Object
for(String childPkgRef : childPkgRefs)
{
// Remember where the additions start
int oldSize = dsoIngestedList.size();
//Assume package reference is relative to current package location
File childPkg = new File(pkgFile.getAbsoluteFile().getParent(), childPkgRef);
//fun, it's recursive! -- ingested referenced package as a child of current object
ingestAll(context, dso, childPkg, params, license);
// A Collection can map to Items that it does not "own".
// If a Collection package has an Item as a child, it
// should be mapped regardless of ownership.
if (Constants.COLLECTION == dso.getType())
{
Item childItem = (Item)dsoIngestedList.get(oldSize);
Collection collection = (Collection)dso;
if (!childItem.isIn(collection))
collection.addItem(childItem);
}
}
}//end if child pkgs
}//end if not an Item
@@ -260,12 +276,26 @@ public abstract class AbstractPackageIngester
//Recursively replace each child package
for(String childPkgRef : childPkgRefs)
{
// Remember where the additions start
int oldSize = dsoIngestedList.size();
//Assume package reference is relative to current package location
File childPkg = new File(pkgFile.getAbsoluteFile().getParent(), childPkgRef);
//fun, it's recursive! -- replaced referenced package as a child of current object
// Pass object to replace as 'null', as we don't know which object to replace.
replaceAll(context, null, childPkg, params);
// A Collection can map to Items that it does not "own".
// If a Collection package has an Item as a child, it
// should be mapped regardless of ownership.
if (Constants.COLLECTION == replacedDso.getType())
{
Item childItem = (Item)dsoIngestedList.get(oldSize);
Collection collection = (Collection)replacedDso;
if (!childItem.isIn(collection))
collection.addItem(childItem);
}
}
}//end if child pkgs
}//end if not an Item