SF Patch 1743188 Patch for Request #1145499 - Move Items

git-svn-id: http://scm.dspace.org/svn/repo/trunk@2171 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Stuart Lewis
2007-08-28 15:05:50 +00:00
parent 0ab5d3bad4
commit a4c696de8c
6 changed files with 257 additions and 1 deletions

View File

@@ -1978,6 +1978,66 @@ public class Item extends DSpaceObject
replaceAllBitstreamPolicies(policies);
}
/**
* Moves the item from one collection to another one
*
* @throws SQLException
* @throws AuthorizeException
* @throws IOException
*/
public void move (Collection from, Collection to) throws SQLException, AuthorizeException, IOException
{
if (isOwningCollection(from))
{
setOwningCollection(to);
update();
}
to.addItem(this);
from.removeItem(this);
}
/**
* Get the collections this item is not in.
*
* @return the collections this item is not in, if any.
* @throws SQLException
*/
public Collection[] getCollectionsNotLinked() throws SQLException
{
Collection[] allCollections = Collection.findAll(ourContext);
Collection[] linkedCollections = getCollections();
Collection[] notLinkedCollections = new Collection[allCollections.length - linkedCollections.length];
if ((allCollections.length - linkedCollections.length) == 0)
{
return notLinkedCollections;
}
int i = 0;
for (Collection collection : allCollections)
{
boolean alreadyLinked = false;
for (Collection linkedCommunity : linkedCollections)
{
if (collection.getID() == linkedCommunity.getID())
{
alreadyLinked = true;
break;
}
}
if (!alreadyLinked)
{
notLinkedCollections[i++] = collection;
}
}
return notLinkedCollections;
}
/**
* return TRUE if context's user can edit item, false otherwise