[DS-525] Move item - inherit default policies of destination collection

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5829 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Stuart Lewis
2010-11-11 21:16:20 +00:00
parent a21369bfa0
commit 8377f93202
10 changed files with 96 additions and 19 deletions

View File

@@ -659,9 +659,9 @@ public class Item extends DSpaceObject
* value has no language (for example, a date).
* @param values
* the values to add.
* @param authority
* @param authorities
* the external authority key for this value (or null)
* @param confidence
* @param confidences
* the authority confidence (default 0)
*/
public void addMetadata(String schema, String element, String qualifier, String lang,
@@ -2037,7 +2037,7 @@ public class Item extends DSpaceObject
* Return <code>true</code> if <code>other</code> is the same Item as
* this object, <code>false</code> otherwise
*
* @param other
* @param obj
* object to compare to
* @return <code>true</code> if object passed in represents the same item
* as this object
@@ -2218,7 +2218,7 @@ public class Item extends DSpaceObject
if (policies.size() < 1)
{
throw new java.sql.SQLException("Collection " + c.getID()
+ " has no default item READ policies");
+ " has no default item READ policies");
}
// change the action to just READ
@@ -2246,8 +2246,11 @@ public class Item extends DSpaceObject
}
replaceAllBitstreamPolicies(policies);
log.debug(LogManager.getHeader(ourContext, "item_inheritCollectionDefaultPolicies",
"item_id=" + getID()));
}
/**
* Moves the item from one collection to another one
*
@@ -2256,6 +2259,19 @@ public class Item extends DSpaceObject
* @throws IOException
*/
public void move (Collection from, Collection to) throws SQLException, AuthorizeException, IOException
{
// Use the normal move method, and default to not inherit permissions
this.move(from, to, false);
}
/**
* Moves the item from one collection to another one
*
* @throws SQLException
* @throws AuthorizeException
* @throws IOException
*/
public void move (Collection from, Collection to, boolean inheritDefaultPolicies) throws SQLException, AuthorizeException, IOException
{
// Check authorisation on the item before that the move occur
// otherwise we will need edit permission on the "target collection" to archive our goal
@@ -2272,10 +2288,25 @@ public class Item extends DSpaceObject
// If we are moving from the owning collection, update that too
if (isOwningCollection(from))
{
setOwningCollection(to);
ourContext.turnOffAuthorisationSystem();
update();
ourContext.restoreAuthSystemState();
// Update the owning collection
log.info(LogManager.getHeader(ourContext, "move_item",
"item_id=" + getID() + ", from " +
"collection_id=" + from.getID() + " to " +
"collection_id=" + to.getID()));
setOwningCollection(to);
// If applicable, update the item policies
if (inheritDefaultPolicies)
{
log.info(LogManager.getHeader(ourContext, "move_item",
"Updating item with inherited policies"));
inheritCollectionDefaultPolicies(to);
}
// Update the item
ourContext.turnOffAuthorisationSystem();
update();
ourContext.restoreAuthSystemState();
}
else
{

View File

@@ -1256,6 +1256,7 @@ jsp.tools.move-item.collection.from.msg = Collection to
jsp.tools.move-item.collection.to.msg = Collection to move to
jsp.tools.move-item.item.name.msg = Name of the item to be moved
jsp.tools.move-item.title = Moving an item
jsp.tools.move-item.inheritpolicies = Inherit default policies of destination collection
jsp.tools.upload-bitstream.info = Select the bitstream to upload
jsp.tools.upload-bitstream.title = Upload Bitstream
jsp.tools.upload-bitstream.upload = Upload

View File

@@ -324,13 +324,19 @@ public class EditItemServlet extends DSpaceServlet
{
Collection fromCollection = Collection.find(context, UIUtil.getIntParameter(request, "collection_from_id"));
Collection toCollection = Collection.find(context, UIUtil.getIntParameter(request, "collection_to_id"));
Boolean inheritPolicies = false;
if (request.getParameter("inheritpolicies") != null)
{
inheritPolicies = true;
}
if (fromCollection == null || toCollection == null)
{
throw new ServletException("Missing or incorrect collection IDs for moving item");
}
item.move(fromCollection, toCollection);
item.move(fromCollection, toCollection, inheritPolicies);
showEditForm(context, request, response, item);
@@ -354,7 +360,7 @@ public class EditItemServlet extends DSpaceServlet
/**
* Throw an exception if user isn't authorized to edit this item
*
* @param context
* @param c
* @param item
*/
private void checkEditAuthorization(Context c, Item item)

View File

@@ -106,6 +106,10 @@
%>
</select>
</td>
</tr>
<tr>
<td class="standard"><small><strong><fmt:message key="jsp.tools.move-item.inheritpolicies"/></strong></small></td>
<td class="standard"><input type="checkbox" name="inheritpolicies" /></td>
</tr>
<tr>
<td class="standard"></td>

View File

@@ -80,8 +80,8 @@ public class FlowItemUtils
private static final Message T_metadata_added = new Message("default","New metadata was added.");
private static final Message T_item_withdrawn = new Message("default","The item has been withdrawn.");
private static final Message T_item_reinstated = new Message("default","The item has been reinstated.");
private static final Message T_item_moved = new Message("default","The item has been moved.");
private static final Message T_item_move_destination_not_found = new Message("default","The selected destination collection could not be found.");
private static final Message T_item_moved = new Message("default","The item has been moved.");
private static final Message T_item_move_destination_not_found = new Message("default","The selected destination collection could not be found.");
private static final Message T_bitstream_added = new Message("default","The new bitstream was successfully uploaded.");
private static final Message T_bitstream_failed = new Message("default","Error while uploading file.");
private static final Message T_bitstream_updated = new Message("default","The bitstream has been updated.");
@@ -346,9 +346,10 @@ public class FlowItemUtils
* @param context The DSpace context
* @param itemID The id of the to-be-moved item.
* @param collectionID The id of the destination collection.
* @param inherit Whether to inherit the policies of the destination collection
* @return A result object
*/
public static FlowResult processMoveItem(Context context, int itemID, int collectionID) throws SQLException, AuthorizeException, IOException
public static FlowResult processMoveItem(Context context, int itemID, int collectionID, boolean inherit) throws SQLException, AuthorizeException, IOException
{
FlowResult result = new FlowResult();
result.setContinue(false);
@@ -357,10 +358,13 @@ public class FlowItemUtils
if(AuthorizeManager.isAdmin(context, item))
{
//Add a policy giving this user *explicit* admin permissions on the item itself.
//Add an action giving this user *explicit* admin permissions on the item itself.
//This ensures that the user will be able to call item.update() even if he/she
// moves it to a Collection that he/she doesn't administer.
AuthorizeManager.addPolicy(context, item, Constants.ADMIN, context.getCurrentUser());
if (item.canEdit())
{
AuthorizeManager.authorizeAction(context, item, Constants.WRITE);
}
Collection destination = Collection.find(context, collectionID);
if (destination == null)
@@ -408,6 +412,13 @@ public class FlowItemUtils
}
item.setOwningCollection(destination);
// Inherit policies of destination collection if required
if (inherit)
{
item.inheritCollectionDefaultPolicies(destination);
}
item.update();
context.commit();

View File

@@ -45,6 +45,7 @@ import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.app.xmlui.wing.WingException;
import org.dspace.app.xmlui.wing.element.Body;
import org.dspace.app.xmlui.wing.element.CheckBox;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
@@ -73,6 +74,8 @@ public class MoveItemForm extends AbstractDSpaceTransformer {
private static final Message T_collection_help = message("xmlui.administrative.item.MoveItemForm.collection_help");
private static final Message T_collection_default = message("xmlui.administrative.item.MoveItemForm.collection_default");
private static final Message T_submit_move = message("xmlui.administrative.item.MoveItemForm.submit_move");
private static final Message T_submit_inherit = message("xmlui.administrative.item.MoveItemForm.inherit_policies");
private static final Message T_submit_inherit_help = message("xmlui.administrative.item.MoveItemForm.inherit_policies_help");
public void addPageMeta(PageMeta pageMeta) throws WingException
@@ -114,10 +117,19 @@ public class MoveItemForm extends AbstractDSpaceTransformer {
{
name = name.substring(0, 47) + "...";
}
select.addOption(collection.equals(owningCollection), collection.getID(), name);
// Only add the item if it isn't already the owner
if (!item.isOwningCollection(collection))
{
select.addOption(collection.equals(owningCollection), collection.getID(), name);
}
}
org.dspace.app.xmlui.wing.element.Item actions = list.addItem();
CheckBox inheritPolicies = actions.addCheckBox("inheritPolicies");
inheritPolicies.setLabel(T_submit_inherit);
inheritPolicies.setHelp(T_submit_inherit_help);
inheritPolicies.addOption("inheritPolicies");
actions.addButton("submit_move").setValue(T_submit_move);
actions.addButton("submit_cancel").setValue(T_submit_cancel);

View File

@@ -1707,12 +1707,20 @@ function doMoveItem(itemID)
{
var collectionID = cocoon.request.get("collectionID");
if (!collectionID)
{
continue;
}
var inherit = false;
if (cocoon.request.get("inheritPolicies"))
{
inherit = true;
}
// Actually move the item
assertEditItem(itemID);
result = FlowItemUtils.processMoveItem(getDSContext(),itemID,collectionID);
result = FlowItemUtils.processMoveItem(getDSContext(), itemID, collectionID, inherit);
}
} while (result == null || !result.getContinue());

View File

@@ -630,6 +630,7 @@ to administer DSpace.
<map:transform type="MoveItemForm">
<map:parameter name="itemID" value="{flow-attribute:itemID}"/>
<map:parameter name="collectionID" value="{flow-attribute:collectionID}"/>
<map:parameter name="inheritPolicies" value="{flow-attribute:inheritPolicies}"/>
</map:transform>
</map:match>

View File

@@ -1289,6 +1289,8 @@
<message key="xmlui.administrative.item.MoveItemForm.collection_help">Select the collection you wish to move this item to.</message>
<message key="xmlui.administrative.item.MoveItemForm.collection_default">Select a collection...</message>
<message key="xmlui.administrative.item.MoveItemForm.submit_move">Move</message>
<message key="xmlui.administrative.item.MoveItemForm.inherit_policies">Inherit policies</message>
<message key="xmlui.administrative.item.MoveItemForm.inherit_policies_help">Inherit the default policies of the destination collection</message>
<!-- org.dspace.app.xmlui.administrative.item.EditBitstreamForm -->
<message key="xmlui.administrative.item.EditBitstreamForm.title">Edit Bitstream</message>

View File

@@ -64,6 +64,7 @@
(Stuart Lewis)
- [DS-467] Consider making the JSPUI styles.css.jsp a static file
- [DS-525] Move item - inherit default policies of destination collection
- [DS-550] Upgrade to latest Google Analytics tracking code
- [DS-632] Batch Metadata Import needs to validate metadata fields specified in CSVs
- [DS-646] Remove /bin scripts (replaced by 'dspace' command)