Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable workflow: Enable workflow item deletion without publishing it (DS-3926) #2076

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -9,13 +9,23 @@

import org.dspace.app.util.Util;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.factory.AuthorizeServiceFactory;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.DCDate;
import org.dspace.content.MetadataSchema;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.ItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
import org.dspace.xmlworkflow.service.WorkflowRequirementsService;
import org.dspace.xmlworkflow.service.XmlWorkflowService;
import org.dspace.xmlworkflow.state.Step;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
import org.dspace.xmlworkflow.storedcomponents.service.WorkflowItemRoleService;
import org.dspace.xmlworkflow.storedcomponents.service.XmlWorkflowItemService;
import org.dspace.xmlworkflow.state.actions.ActionResult;
import org.dspace.content.Item;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
Expand All @@ -34,6 +44,7 @@ public class AcceptEditRejectAction extends ProcessingAction {

public static final int MAIN_PAGE = 0;
public static final int REJECT_PAGE = 1;
public static final int DELETE_PAGE = 2;

//TODO: rename to AcceptAndEditMetadataAction

Expand All @@ -51,6 +62,8 @@ public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServl
return processMainPage(c, wfi, step, request);
case REJECT_PAGE:
return processRejectPage(c, wfi, step, request);
case DELETE_PAGE:
return processDeleteItem(c, wfi, step, request);

}

Expand All @@ -68,6 +81,10 @@ public ActionResult processMainPage(Context c, XmlWorkflowItem wfi, Step step, H
request.setAttribute("page", REJECT_PAGE);
// We have pressed reject item, so take the user to a page where he can reject
return new ActionResult(ActionResult.TYPE.TYPE_PAGE);
} else if(request.getParameter("submit_delete") != null){
request.setAttribute("page", DELETE_PAGE);
// We have pressed delete item
return new ActionResult(ActionResult.TYPE.TYPE_PAGE);
} else {
//We pressed the leave button so return to our submissions page
return new ActionResult(ActionResult.TYPE.TYPE_SUBMISSION_PAGE);
Expand Down Expand Up @@ -110,4 +127,43 @@ private void addApprovedProvenance(Context c, XmlWorkflowItem wfi) throws SQLExc
itemService.addMetadata(c, wfi.getItem(), MetadataSchema.DC_SCHEMA, "description", "provenance", "en", provDescription);
itemService.update(c, wfi.getItem());
}

public ActionResult processDeleteItem(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request) throws SQLException, AuthorizeException, IOException {
if(request.getParameter("submit_delete") != null){
AuthorizeService authorizeService= AuthorizeServiceFactory.getInstance().getAuthorizeService();
XmlWorkflowService xmlWorkflowService = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService();
WorkflowRequirementsService workflowRequirementsService=XmlWorkflowServiceFactory.getInstance().getWorkflowRequirementsService();
WorkflowItemRoleService workflowItemRoleService=XmlWorkflowServiceFactory.getInstance().getWorkflowItemRoleService();
XmlWorkflowItemService xmlWorkflowItemService=XmlWorkflowServiceFactory.getInstance().getXmlWorkflowItemService();
ItemService itemService= ContentServiceFactory.getInstance().getItemService();

Item item =wfi.getItem();
//Check for permission
authorizeService.authorizeAction(c, item, Constants.DELETE);

//Remove references from 'cwf_in_progress_user' and 'cwf_claimtask' tables
workflowRequirementsService.clearInProgressUsers(c, wfi);
xmlWorkflowService.deleteAllTasks(c,wfi);

//Remove (if any) the workflowItemroles for this item
workflowItemRoleService.deleteForWorkflowItem(c, wfi);

//Remove the workflowItem
xmlWorkflowItemService.deleteWrapper(c, wfi);

//Shut down authorization system
c.turnOffAuthorisationSystem();
//Remove item
itemService.delete(c,item);
c.restoreAuthSystemState();

c.commit();
return new ActionResult(ActionResult.TYPE.TYPE_SUBMISSION_PAGE);
}

//Cancel, go back to the main task page
request.setAttribute("page", MAIN_PAGE);
return new ActionResult(ActionResult.TYPE.TYPE_PAGE);
}

}
Expand Up @@ -14,8 +14,11 @@
import org.dspace.app.xmlui.wing.WingException;
import org.dspace.app.xmlui.wing.element.*;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.factory.AuthorizeServiceFactory;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.core.Constants;
import org.dspace.xmlworkflow.state.actions.Action;
import org.dspace.xmlworkflow.state.actions.processingaction.ReviewAction;
import org.xml.sax.SAXException;
Expand All @@ -40,6 +43,9 @@ public class AcceptEditRejectAction extends AbstractXMLUIAction {
protected static final Message T_info2=
message("xmlui.Submission.workflow.RejectTaskStep.info1");

protected static final Message T_info3=
message("xmlui.XMLWorkflow.workflow.DeleteItemAction.info3");


private static final Message T_HEAD = message("xmlui.XMLWorkflow.workflow.EditMetadataAction.head");

Expand Down Expand Up @@ -76,7 +82,10 @@ public class AcceptEditRejectAction extends AbstractXMLUIAction {
protected static final Message T_cancel_submit =
message("xmlui.general.cancel");


protected static final Message T_delete_help =
message("xmlui.XMLWorkflow.workflow.EditMetadataAction.delete_help");
protected static final Message T_delete_submit =
message("xmlui.general.delete");;
@Override
public void addBody(Body body) throws SAXException, WingException, SQLException, IOException, AuthorizeException {
Item item = workflowItem.getItem();
Expand Down Expand Up @@ -105,12 +114,16 @@ public void addBody(Body body) throws SAXException, WingException, SQLException,
case ReviewAction.REJECT_PAGE:
renderRejectPage(div);
break;
case org.dspace.xmlworkflow.state.actions.processingaction.AcceptEditRejectAction.DELETE_PAGE:
renderDeletePage(div);

}

div.addHidden("submission-continue").setValue(knot.getId());
}

private void renderMainPage(Division div) throws WingException {
private void renderMainPage(Division div) throws WingException, SQLException {
AuthorizeService authorizeService= AuthorizeServiceFactory.getInstance().getAuthorizeService();
Table table = div.addTable("workflow-actions", 1, 1);
table.setHead(T_info1);

Expand All @@ -123,8 +136,13 @@ private void renderMainPage(Division div) throws WingException {
row = table.addRow();
row.addCellContent(T_reject_help);
row.addCell().addButton("submit_reject").setValue(T_reject_submit);



//Delete item
if (authorizeService.authorizeActionBoolean(context, workflowItem.getItem(), Constants.DELETE)) {
row = table.addRow();
row.addCellContent(T_delete_help);
row.addCell().addButton("submit_delete").setValue(T_delete_submit);
}
// Edit metadata
row = table.addRow();
row.addCellContent(T_edit_help);
Expand All @@ -140,7 +158,6 @@ private void renderMainPage(Division div) throws WingException {

private void renderRejectPage(Division div) throws WingException {
Request request = ObjectModelHelper.getRequest(objectModel);

List form = div.addList("reject-workflow",List.TYPE_FORM);

form.addItem(T_info2);
Expand All @@ -161,4 +178,17 @@ private void renderRejectPage(Division div) throws WingException {
actions.addButton("submit_cancel").setValue(T_submit_cancel);

}

private void renderDeletePage(Division div) throws WingException {
Division divNotice = div.addDivision("general-message","notice failure");
divNotice.addPara(T_info3);

List form = div.addList("delete-workflow",List.TYPE_FORM);

div.addHidden("page").setValue(org.dspace.xmlworkflow.state.actions.processingaction.AcceptEditRejectAction.DELETE_PAGE);

org.dspace.app.xmlui.wing.element.Item actions = form.addItem();
actions.addButton("submit_delete").setValue(T_delete_submit);
actions.addButton("submit_cancel").setValue(T_submit_cancel);
}
}
Expand Up @@ -46,6 +46,7 @@
<message key="xmlui.XMLWorkflow.workflow.EditMetadataAction.approve_submit">Approve item</message>
<message key="xmlui.XMLWorkflow.workflow.EditMetadataAction.edit_help">Select this option to change the item's metadata.</message>
<message key="xmlui.XMLWorkflow.workflow.EditMetadataAction.edit_submit">Edit metadata</message>
<message key="xmlui.XMLWorkflow.workflow.EditMetadataAction.delete_help">Delete workflow item</message>

<message key="xmlui.XMLWorkflow.step.unknown">Unknown state</message>

Expand Down Expand Up @@ -102,5 +103,7 @@
<message key="xmlui.XMLWorkflow.scoreReview.scoreReviewStep.claimaction">Score review</message>
<message key="xmlui.XMLWorkflow.scoreReview.scoreReviewStep.scorereviewaction">Score review</message>
<message key="xmlui.XMLWorkflow.scoreReview.scoreReviewStep">Score review</message>

<message key="xmlui.XMLWorkflow.workflow.DeleteItemAction.info3">Are you sure do you want to delete the item?</message>

</catalogue>