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 abstract class SuperUserActionTakenEvent extends ActionTakenEvent {
40
41 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SuperUserActionTakenEvent.class);
42
43 protected final String superUserAction;
44
45 private ActionRequestValue actionRequest;
46 public static String AUTHORIZATION = "general.routing.superuser.notAuthorized";
47
48 protected SuperUserActionTakenEvent(String actionTakenCode, String superUserAction, DocumentRouteHeaderValue routeHeader, PrincipalContract principal) {
49 super(actionTakenCode, routeHeader, principal);
50 this.superUserAction = superUserAction;
51 }
52
53 protected SuperUserActionTakenEvent(String actionTakenCode, String superUserAction, DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, boolean runPostProcessor) {
54 super(actionTakenCode, routeHeader, principal, annotation, runPostProcessor);
55 this.superUserAction = superUserAction;
56 }
57
58
59
60
61 @Override
62 public String validateActionRules() {
63 DocumentType docType = getRouteHeader().getDocumentType();
64 if (!KEWServiceLocator.getDocumentTypePermissionService().canAdministerRouting(getPrincipal().getPrincipalId(), docType)) {
65 return "User not authorized for super user action";
66 }
67 return "";
68 }
69
70 @Override
71 public String validateActionRules(List<ActionRequestValue> actionRequests) {
72 return validateActionRules();
73 }
74
75 public void recordAction() throws InvalidActionTakenException {
76
77 String errorMessage = validateActionRules();
78 if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) {
79 LOG.info("User not authorized");
80 List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>();
81 errors.add(new WorkflowServiceErrorImpl(errorMessage, AUTHORIZATION));
82 throw new WorkflowServiceErrorException(errorMessage, errors);
83 }
84
85 ActionTakenValue actionTaken = processActionRequests();
86
87 try {
88 String oldStatus = getRouteHeader().getDocRouteStatus();
89
90 if (getRouteHeader().isStateInitiated()) {
91 getRouteHeader().markDocumentEnroute();
92 notifyStatusChange(getRouteHeader().getDocRouteStatus(), oldStatus);
93 }
94 markDocument();
95 String newStatus = getRouteHeader().getDocRouteStatus();
96 notifyStatusChange(newStatus, oldStatus);
97 } catch (Exception ex) {
98 LOG.error("Caught Exception talking to post processor", ex);
99 throw new RuntimeException(ex.getMessage());
100 }
101
102 processActionTaken(actionTaken);
103 }
104
105 protected abstract void markDocument() throws WorkflowException;
106
107 protected ActionTakenValue processActionRequests() throws InvalidActionTakenException {
108 LOG.debug("Processing pending action requests");
109
110 ActionTakenValue actionTaken = saveActionTaken();
111
112 List<ActionRequestValue> actionRequests = getActionRequestService().findPendingByDoc(getDocumentId());
113
114 for (ActionRequestValue actionRequest : actionRequests)
115 {
116 getActionRequestService().deactivateRequest(actionTaken, actionRequest);
117 }
118
119 notifyActionTaken(actionTaken);
120
121 return actionTaken;
122 }
123
124
125
126
127 protected void processActionTaken(ActionTakenValue actionTaken) {
128
129 }
130
131 public ActionRequestValue getActionRequest() {
132 return actionRequest;
133 }
134
135 public void setActionRequest(ActionRequestValue actionRequest) {
136 this.actionRequest = actionRequest;
137 }
138
139 }