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 org.apache.log4j.Logger; |
20 | |
import org.kuali.rice.kew.actionrequest.ActionRequestFactory; |
21 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
22 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
23 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
24 | |
import org.kuali.rice.kew.engine.BlanketApproveEngine; |
25 | |
import org.kuali.rice.kew.engine.OrchestrationConfig; |
26 | |
import org.kuali.rice.kew.engine.RouteContext; |
27 | |
import org.kuali.rice.kew.engine.node.RequestsNode; |
28 | |
import org.kuali.rice.kew.exception.InvalidActionTakenException; |
29 | |
import org.kuali.rice.kew.exception.WorkflowException; |
30 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorException; |
31 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl; |
32 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
33 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
34 | |
import org.kuali.rice.kew.util.KEWConstants; |
35 | |
import org.kuali.rice.kim.api.entity.principal.PrincipalContract; |
36 | |
|
37 | |
|
38 | |
import java.util.ArrayList; |
39 | |
import java.util.HashSet; |
40 | |
import java.util.List; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
public class SuperUserApproveEvent extends SuperUserActionTakenEvent { |
50 | |
|
51 | 0 | private static final Logger LOG = Logger.getLogger(SuperUserApproveEvent.class); |
52 | |
|
53 | |
public SuperUserApproveEvent(DocumentRouteHeaderValue routeHeader, PrincipalContract principal) { |
54 | 0 | super(KEWConstants.ACTION_TAKEN_SU_APPROVED_CD, routeHeader, principal); |
55 | 0 | this.superUserAction = KEWConstants.SUPER_USER_APPROVE; |
56 | 0 | } |
57 | |
|
58 | |
public SuperUserApproveEvent(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, boolean runPostProcessor) { |
59 | 0 | super(KEWConstants.ACTION_TAKEN_SU_APPROVED_CD, routeHeader, principal, annotation, runPostProcessor); |
60 | 0 | this.superUserAction = KEWConstants.SUPER_USER_APPROVE; |
61 | 0 | } |
62 | |
|
63 | |
public void recordAction() throws InvalidActionTakenException { |
64 | |
|
65 | |
|
66 | 0 | setRouteHeader(KEWServiceLocator.getRouteHeaderService().getRouteHeader(getDocumentId(), true)); |
67 | |
|
68 | 0 | DocumentType docType = getRouteHeader().getDocumentType(); |
69 | |
|
70 | 0 | String errorMessage = super.validateActionRules(); |
71 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) { |
72 | 0 | LOG.info("User not authorized"); |
73 | 0 | List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>(); |
74 | 0 | errors.add(new WorkflowServiceErrorImpl(errorMessage, AUTHORIZATION)); |
75 | 0 | throw new WorkflowServiceErrorException(errorMessage, errors); |
76 | |
} |
77 | |
|
78 | 0 | ActionTakenValue actionTaken = saveActionTaken(); |
79 | |
|
80 | 0 | notifyActionTaken(actionTaken); |
81 | |
|
82 | 0 | if (getRouteHeader().isInException() || getRouteHeader().isStateInitiated()) { |
83 | 0 | LOG.debug("Moving document back to Enroute"); |
84 | 0 | String oldStatus = getRouteHeader().getDocRouteStatus(); |
85 | 0 | getRouteHeader().markDocumentEnroute(); |
86 | 0 | String newStatus = getRouteHeader().getDocRouteStatus(); |
87 | 0 | notifyStatusChange(newStatus, oldStatus); |
88 | 0 | KEWServiceLocator.getRouteHeaderService().saveRouteHeader(getRouteHeader()); |
89 | |
} |
90 | |
|
91 | 0 | OrchestrationConfig config = new OrchestrationConfig(); |
92 | 0 | config.setCause(actionTaken); |
93 | 0 | config.setDestinationNodeNames(new HashSet<String>()); |
94 | 0 | config.setSendNotifications(docType.getSuperUserApproveNotificationPolicy().getPolicyValue()); |
95 | 0 | RequestsNode.setSupressPolicyErrors(RouteContext.getCurrentRouteContext()); |
96 | |
try { |
97 | 0 | completeAnyOutstandingCompleteApproveRequests(actionTaken, docType.getSuperUserApproveNotificationPolicy().getPolicyValue()); |
98 | 0 | BlanketApproveEngine blanketApproveEngine = KEWServiceLocator.getBlanketApproveEngineFactory().newEngine(config, isRunPostProcessorLogic()); |
99 | 0 | blanketApproveEngine.process(getRouteHeader().getDocumentId(), null); |
100 | 0 | } catch (Exception e) { |
101 | 0 | LOG.error("Failed to orchestrate the document to SuperUserApproved.", e); |
102 | 0 | throw new InvalidActionTakenException("Failed to orchestrate the document to SuperUserApproved.", e); |
103 | 0 | } |
104 | |
|
105 | 0 | } |
106 | |
|
107 | |
@SuppressWarnings("unchecked") |
108 | |
protected void completeAnyOutstandingCompleteApproveRequests(ActionTakenValue actionTaken, boolean sendNotifications) throws Exception { |
109 | 0 | List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findPendingByActionRequestedAndDocId(KEWConstants.ACTION_REQUEST_APPROVE_REQ, getDocumentId()); |
110 | 0 | actionRequests.addAll(KEWServiceLocator.getActionRequestService().findPendingByActionRequestedAndDocId(KEWConstants.ACTION_REQUEST_COMPLETE_REQ, getDocumentId())); |
111 | 0 | for (ActionRequestValue actionRequest : actionRequests) { |
112 | 0 | KEWServiceLocator.getActionRequestService().deactivateRequest(actionTaken, actionRequest); |
113 | |
} |
114 | 0 | if (sendNotifications) { |
115 | 0 | new ActionRequestFactory(this.getRouteHeader()).generateNotifications(actionRequests, getPrincipal(), this.findDelegatorForActionRequests(actionRequests), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KEWConstants.ACTION_TAKEN_SU_APPROVED_CD); |
116 | |
} |
117 | 0 | } |
118 | |
|
119 | |
protected void markDocument() throws WorkflowException { |
120 | |
|
121 | 0 | } |
122 | |
} |