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