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