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