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