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 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 public static String AUTHORIZATION = "general.routing.superuser.notAuthorized";
49
50 public SuperUserActionTakenEvent(String actionTakenCode, DocumentRouteHeaderValue routeHeader, KimPrincipal principal) {
51 super(actionTakenCode, routeHeader, principal);
52 }
53
54 public SuperUserActionTakenEvent(String actionTakenCode, DocumentRouteHeaderValue routeHeader, KimPrincipal principal, String annotation, boolean runPostProcessor) {
55 super(actionTakenCode, routeHeader, principal, annotation, runPostProcessor);
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 (!Utilities.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 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 }
103
104 protected abstract void markDocument() throws WorkflowException;
105
106 protected void processActionRequests() throws InvalidActionTakenException {
107 LOG.debug("Processing pending action requests");
108
109 ActionTakenValue actionTaken = saveActionTaken();
110
111 List<ActionRequestValue> actionRequests = getActionRequestService().findPendingByDoc(getRouteHeaderId());
112
113 for (ActionRequestValue actionRequest : actionRequests)
114 {
115 getActionRequestService().deactivateRequest(actionTaken, actionRequest);
116 }
117
118 notifyActionTaken(actionTaken);
119 }
120
121 public ActionRequestValue getActionRequest() {
122 return actionRequest;
123 }
124
125 public void setActionRequest(ActionRequestValue actionRequest) {
126 this.actionRequest = actionRequest;
127 }
128
129 }