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.kuali.rice.kew.actiontaken.ActionTakenValue; |
20 | |
import org.kuali.rice.kew.api.WorkflowRuntimeException; |
21 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
22 | |
import org.kuali.rice.kew.engine.BlanketApproveEngine; |
23 | |
import org.kuali.rice.kew.engine.OrchestrationConfig; |
24 | |
import org.kuali.rice.kew.exception.*; |
25 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
26 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
27 | |
import org.kuali.rice.kew.util.KEWConstants; |
28 | |
import org.kuali.rice.kim.api.identity.principal.PrincipalContract; |
29 | |
|
30 | |
|
31 | |
import java.util.ArrayList; |
32 | |
import java.util.Collections; |
33 | |
import java.util.List; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public class SuperUserNodeApproveEvent extends SuperUserActionTakenEvent { |
44 | |
|
45 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SuperUserNodeApproveEvent.class); |
46 | |
private String nodeName; |
47 | |
|
48 | |
public SuperUserNodeApproveEvent(DocumentRouteHeaderValue routeHeader, PrincipalContract principal) { |
49 | 0 | super(KEWConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED_CD, routeHeader, principal); |
50 | 0 | this.superUserAction = KEWConstants.SUPER_USER_ROUTE_LEVEL_APPROVE; |
51 | 0 | } |
52 | |
|
53 | |
public SuperUserNodeApproveEvent(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, boolean runPostProcessor, String nodeName) { |
54 | 0 | super(KEWConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED_CD, routeHeader, principal, annotation, runPostProcessor); |
55 | 0 | this.superUserAction = KEWConstants.SUPER_USER_ROUTE_LEVEL_APPROVE; |
56 | 0 | this.nodeName = nodeName; |
57 | 0 | } |
58 | |
|
59 | |
public void recordAction() throws InvalidActionTakenException { |
60 | |
|
61 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(nodeName)) { |
62 | 0 | throw new InvalidActionTakenException("No approval node name set"); |
63 | |
} |
64 | |
|
65 | 0 | DocumentType docType = getRouteHeader().getDocumentType(); |
66 | |
|
67 | 0 | String errorMessage = super.validateActionRules(); |
68 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) { |
69 | 0 | LOG.info("User not authorized"); |
70 | 0 | List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>(); |
71 | 0 | errors.add(new WorkflowServiceErrorImpl(errorMessage, SuperUserActionTakenEvent.AUTHORIZATION)); |
72 | 0 | throw new WorkflowServiceErrorException(errorMessage, errors); |
73 | |
} |
74 | |
|
75 | 0 | ActionTakenValue actionTaken = saveActionTaken(); |
76 | |
|
77 | 0 | notifyActionTaken(actionTaken); |
78 | |
|
79 | 0 | if (getRouteHeader().isInException()) { |
80 | 0 | LOG.debug("Moving document back to Enroute from Exception"); |
81 | 0 | String oldStatus = getRouteHeader().getDocRouteStatus(); |
82 | 0 | getRouteHeader().markDocumentEnroute(); |
83 | 0 | String newStatus = getRouteHeader().getDocRouteStatus(); |
84 | 0 | notifyStatusChange(newStatus, oldStatus); |
85 | 0 | KEWServiceLocator.getRouteHeaderService().saveRouteHeader(getRouteHeader()); |
86 | |
} |
87 | |
|
88 | 0 | OrchestrationConfig config = new OrchestrationConfig(); |
89 | 0 | config.setCause(actionTaken); |
90 | 0 | config.setDestinationNodeNames(Collections.singleton(nodeName)); |
91 | 0 | config.setSendNotifications(docType.getSuperUserApproveNotificationPolicy().getPolicyValue()); |
92 | |
try { |
93 | 0 | BlanketApproveEngine blanketApproveEngine = KEWServiceLocator.getBlanketApproveEngineFactory().newEngine(config, isRunPostProcessorLogic()); |
94 | 0 | blanketApproveEngine.process(getRouteHeader().getDocumentId(), null); |
95 | 0 | } catch (Exception e) { |
96 | 0 | if (e instanceof RuntimeException) { |
97 | 0 | throw (RuntimeException)e; |
98 | |
} else { |
99 | 0 | throw new WorkflowRuntimeException(e.toString(), e); |
100 | |
} |
101 | 0 | } |
102 | |
|
103 | |
|
104 | 0 | } |
105 | |
|
106 | |
protected void markDocument() throws WorkflowException { |
107 | |
|
108 | 0 | } |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
} |