1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.actions; |
17 | |
|
18 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
19 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
20 | |
import org.kuali.rice.kew.api.exception.InvalidActionTakenException; |
21 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
22 | |
import org.kuali.rice.kew.api.exception.WorkflowException; |
23 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorException; |
24 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl; |
25 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
26 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
27 | |
import org.kuali.rice.kim.api.identity.principal.PrincipalContract; |
28 | |
|
29 | |
|
30 | |
import java.util.ArrayList; |
31 | |
import java.util.List; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public abstract class SuperUserActionTakenEvent extends ActionTakenEvent { |
40 | |
|
41 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SuperUserActionTakenEvent.class); |
42 | |
|
43 | |
protected String superUserAction; |
44 | |
|
45 | |
private ActionRequestValue actionRequest; |
46 | 0 | public static String AUTHORIZATION = "general.routing.superuser.notAuthorized"; |
47 | |
|
48 | |
public SuperUserActionTakenEvent(String actionTakenCode, DocumentRouteHeaderValue routeHeader, PrincipalContract principal) { |
49 | 0 | super(actionTakenCode, routeHeader, principal); |
50 | 0 | } |
51 | |
|
52 | |
public SuperUserActionTakenEvent(String actionTakenCode, DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, boolean runPostProcessor) { |
53 | 0 | super(actionTakenCode, routeHeader, principal, annotation, runPostProcessor); |
54 | 0 | } |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
@Override |
60 | |
public String validateActionRules() { |
61 | 0 | DocumentType docType = getRouteHeader().getDocumentType(); |
62 | 0 | if (!KEWServiceLocator.getDocumentTypePermissionService().canAdministerRouting(getPrincipal().getPrincipalId(), docType)) { |
63 | 0 | return "User not authorized for super user action"; |
64 | |
} |
65 | 0 | return ""; |
66 | |
} |
67 | |
|
68 | |
@Override |
69 | |
public String validateActionRules(List<ActionRequestValue> actionRequests) { |
70 | 0 | return validateActionRules(); |
71 | |
} |
72 | |
|
73 | |
public void recordAction() throws InvalidActionTakenException { |
74 | |
|
75 | 0 | String errorMessage = validateActionRules(); |
76 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) { |
77 | 0 | LOG.info("User not authorized"); |
78 | 0 | List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>(); |
79 | 0 | errors.add(new WorkflowServiceErrorImpl(errorMessage, AUTHORIZATION)); |
80 | 0 | throw new WorkflowServiceErrorException(errorMessage, errors); |
81 | |
} |
82 | |
|
83 | 0 | processActionRequests(); |
84 | |
|
85 | |
try { |
86 | 0 | String oldStatus = getRouteHeader().getDocRouteStatus(); |
87 | |
|
88 | 0 | if (getRouteHeader().isStateInitiated()) { |
89 | 0 | getRouteHeader().markDocumentEnroute(); |
90 | 0 | notifyStatusChange(getRouteHeader().getDocRouteStatus(), oldStatus); |
91 | |
} |
92 | 0 | markDocument(); |
93 | 0 | String newStatus = getRouteHeader().getDocRouteStatus(); |
94 | 0 | notifyStatusChange(newStatus, oldStatus); |
95 | 0 | } catch (Exception ex) { |
96 | 0 | LOG.error("Caught Exception talking to post processor", ex); |
97 | 0 | throw new RuntimeException(ex.getMessage()); |
98 | 0 | } |
99 | |
|
100 | 0 | } |
101 | |
|
102 | |
protected abstract void markDocument() throws WorkflowException; |
103 | |
|
104 | |
protected void processActionRequests() throws InvalidActionTakenException { |
105 | 0 | LOG.debug("Processing pending action requests"); |
106 | |
|
107 | 0 | ActionTakenValue actionTaken = saveActionTaken(); |
108 | |
|
109 | 0 | List<ActionRequestValue> actionRequests = getActionRequestService().findPendingByDoc(getDocumentId()); |
110 | |
|
111 | 0 | for (ActionRequestValue actionRequest : actionRequests) |
112 | |
{ |
113 | 0 | getActionRequestService().deactivateRequest(actionTaken, actionRequest); |
114 | |
} |
115 | |
|
116 | 0 | notifyActionTaken(actionTaken); |
117 | 0 | } |
118 | |
|
119 | |
public ActionRequestValue getActionRequest() { |
120 | 0 | return actionRequest; |
121 | |
} |
122 | |
|
123 | |
public void setActionRequest(ActionRequestValue actionRequest) { |
124 | 0 | this.actionRequest = actionRequest; |
125 | 0 | } |
126 | |
|
127 | |
} |