forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AcceptEditRejectAction.java
169 lines (138 loc) · 7.49 KB
/
AcceptEditRejectAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.xmlworkflow.state.actions.processingaction;
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;
import java.sql.SQLException;
/**
* Processing class of an action that allows users to
* edit/accept/reject a workflow item
*
* @author Bram De Schouwer (bram.deschouwer at dot com)
* @author Kevin Van de Velde (kevin at atmire dot com)
* @author Ben Bosman (ben at atmire dot com)
* @author Mark Diggory (markd at atmire dot com)
*/
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
@Override
public void activate(Context c, XmlWorkflowItem wf) throws SQLException {
}
@Override
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request) throws SQLException, AuthorizeException, IOException {
int page = Util.getIntParameter(request, "page");
switch (page){
case MAIN_PAGE:
return processMainPage(c, wfi, step, request);
case REJECT_PAGE:
return processRejectPage(c, wfi, step, request);
case DELETE_PAGE:
return processDeleteItem(c, wfi, step, request);
}
return new ActionResult(ActionResult.TYPE.TYPE_CANCEL);
}
public ActionResult processMainPage(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request) throws SQLException, AuthorizeException {
if(request.getParameter("submit_approve") != null){
//Delete the tasks
addApprovedProvenance(c, wfi);
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
} else if(request.getParameter("submit_reject") != null){
// Make sure we indicate which page we want to process
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);
}
}
public ActionResult processRejectPage(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request) throws SQLException, AuthorizeException, IOException {
if(request.getParameter("submit_reject") != null){
String reason = request.getParameter("reason");
if(reason == null || 0 == reason.trim().length()){
addErrorField(request, "reason");
request.setAttribute("page", REJECT_PAGE);
return new ActionResult(ActionResult.TYPE.TYPE_ERROR);
}
//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);
return new ActionResult(ActionResult.TYPE.TYPE_SUBMISSION_PAGE);
}else{
//Cancel, go back to the main task page
request.setAttribute("page", MAIN_PAGE);
return new ActionResult(ActionResult.TYPE.TYPE_PAGE);
}
}
private void addApprovedProvenance(Context c, XmlWorkflowItem wfi) throws SQLException, AuthorizeException {
//Add the provenance for the accept
String now = DCDate.getCurrent().toString();
// Get user's name + email address
String usersName = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService().getEPersonName(c.getCurrentUser());
String provDescription = getProvenanceStartId() + " Approved for entry into archive by "
+ usersName + " on " + now + " (GMT) ";
// Add to item as a DC field
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);
}
}