Alternate way to restart workflow in case of decline

This commit is contained in:
Marie Verdonck
2023-02-09 11:03:24 +01:00
parent 2516460364
commit 0bafbb60a4
4 changed files with 53 additions and 8 deletions

View File

@@ -18,6 +18,7 @@ import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group;
import org.dspace.xmlworkflow.WorkflowConfigurationException;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
/**
* Service interface class for the WorkflowService framework.
@@ -100,6 +101,9 @@ public interface WorkflowService<T extends WorkflowItem> {
String rejection_message)
throws SQLException, AuthorizeException, IOException;
public void restartWorkflow(Context context, XmlWorkflowItem wi, EPerson decliner, String provenance)
throws SQLException, AuthorizeException, IOException, WorkflowException;
public String getMyDSpaceLink();
public void deleteCollection(Context context, Collection collection)

View File

@@ -1076,6 +1076,49 @@ public class XmlWorkflowServiceImpl implements XmlWorkflowService {
return wsi;
}
@Override
public void restartWorkflow(Context context, XmlWorkflowItem wi, EPerson decliner, String provenance)
throws SQLException, AuthorizeException, IOException, WorkflowException {
if (!authorizeService.isAdmin(context)) {
throw new AuthorizeException("You must be an admin to restart a workflow");
}
context.turnOffAuthorisationSystem();
// rejection provenance
Item myitem = wi.getItem();
// Here's what happened
String provDescription =
provenance + " Declined by " + getEPersonName(decliner) + " on " + DCDate.getCurrent().toString() +
" (GMT) ";
// Add to item as a DC field
itemService
.addMetadata(context, myitem, MetadataSchemaEnum.DC.getName(),
"description", "provenance", "en", provDescription);
//Clear any workflow schema related metadata
itemService
.clearMetadata(context, myitem, WorkflowRequirementsService.WORKFLOW_SCHEMA, Item.ANY, Item.ANY, Item.ANY);
itemService.update(context, myitem);
// remove policy for controller
removeUserItemPolicies(context, myitem, decliner);
revokeReviewerPolicies(context, myitem);
// convert into personal workspace
WorkspaceItem wsi = returnToWorkspace(context, wi);
log.info(LogHelper.getHeader(context, "decline_workflow", "workflow_item_id="
+ wi.getID() + "item_id=" + wi.getItem().getID() + "collection_id=" + wi.getCollection().getID() +
"eperson_id=" + decliner.getID()));
// Restart workflow
this.startWithoutNotify(context, wsi);
context.restoreAuthSystemState();
}
/**
* Return the workflow item to the workspace of the submitter. The workflow
* item is removed, and a workspace item created.

View File

@@ -14,7 +14,7 @@ import javax.servlet.http.HttpServletRequest;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
import org.dspace.xmlworkflow.service.XmlWorkflowService;
import org.dspace.xmlworkflow.state.actions.Action;
import org.dspace.xmlworkflow.state.actions.ActionResult;
import org.dspace.xmlworkflow.storedcomponents.ClaimedTask;
@@ -36,6 +36,8 @@ public abstract class ProcessingAction extends Action {
protected ClaimedTaskService claimedTaskService;
@Autowired(required = true)
protected ItemService itemService;
@Autowired
protected XmlWorkflowService xmlWorkflowService;
public static final String SUBMIT_EDIT_METADATA = "submit_edit_metadata";
public static final String SUBMIT_CANCEL = "submit_cancel";
@@ -73,8 +75,8 @@ public abstract class ProcessingAction extends Action {
// We have pressed reject, so remove the task the user has & put it back
// to a workspace item
XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService().sendWorkflowItemBackSubmission(c, wfi,
c.getCurrentUser(), this.getProvenanceStartId(), reason);
xmlWorkflowService.sendWorkflowItemBackSubmission(c, wfi, c.getCurrentUser(), this.getProvenanceStartId(),
reason);
return new ActionResult(ActionResult.TYPE.TYPE_SUBMISSION_PAGE);
}

View File

@@ -23,7 +23,6 @@ import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.workflow.WorkflowException;
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
import org.dspace.xmlworkflow.service.XmlWorkflowService;
import org.dspace.xmlworkflow.state.Step;
import org.dspace.xmlworkflow.state.actions.ActionResult;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
@@ -120,11 +119,8 @@ public class SingleUserReviewAction extends ProcessingAction {
*/
private ActionResult processDecline(Context c, XmlWorkflowItem wfi)
throws SQLException, IOException, AuthorizeException, WorkflowException {
EPerson user = c.getCurrentUser();
c.turnOffAuthorisationSystem();
XmlWorkflowService xmlWorkflowService = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService();
WorkspaceItem workspaceItem = xmlWorkflowService.abort(c, wfi, user);
xmlWorkflowService.start(c, workspaceItem);
xmlWorkflowService.restartWorkflow(c, wfi, c.getCurrentUser(), this.getProvenanceStartId());
c.restoreAuthSystemState();
return new ActionResult(ActionResult.TYPE.TYPE_SUBMISSION_PAGE);
}