1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.actionrequest.service.impl;
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.List;
22
23 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
24 import org.kuali.rice.kew.actionrequest.service.ActionRequestService;
25 import org.kuali.rice.kew.actionrequest.service.DocumentRequeuerService;
26 import org.kuali.rice.kew.api.WorkflowRuntimeException;
27 import org.kuali.rice.kew.engine.OrchestrationConfig;
28 import org.kuali.rice.kew.engine.OrchestrationConfig.EngineCapability;
29 import org.kuali.rice.kew.engine.RouteHelper;
30 import org.kuali.rice.kew.engine.node.RouteNodeInstance;
31 import org.kuali.rice.kew.engine.node.service.RouteNodeService;
32 import org.kuali.rice.kew.service.KEWServiceLocator;
33 import org.kuali.rice.kew.util.PerformanceLogger;
34
35
36
37
38
39
40
41
42
43
44
45
46 public class DocumentRequeuerImpl implements DocumentRequeuerService {
47
48 private RouteHelper helper = new RouteHelper();
49
50
51
52
53
54
55 @SuppressWarnings("unchecked")
56 public void requeueDocument(String documentId) {
57 PerformanceLogger performanceLogger = new PerformanceLogger();
58 KEWServiceLocator.getRouteHeaderService().lockRouteHeader(documentId, true);
59 Collection<RouteNodeInstance> activeNodes = getRouteNodeService().getActiveNodeInstances(documentId);
60 List<ActionRequestValue> requestsToDelete = new ArrayList<ActionRequestValue>();
61
62 NotificationSuppression notificationSuppression = new NotificationSuppression();
63
64 for (RouteNodeInstance nodeInstance : activeNodes) {
65
66 if (helper.isRequestActivationNode(nodeInstance.getRouteNode())) {
67 List<ActionRequestValue> deletesForThisNode =
68 getActionRequestService().findPendingRootRequestsByDocIdAtRouteNode(documentId, nodeInstance.getRouteNodeInstanceId());
69
70 for (ActionRequestValue deleteForThisNode : deletesForThisNode) {
71
72 if (deleteForThisNode.isRouteModuleRequest()) {
73 requestsToDelete.add(deleteForThisNode);
74
75
76 notificationSuppression.addNotificationSuppression(nodeInstance, deleteForThisNode);
77 }
78 }
79
80 nodeInstance.setInitial(true);
81 getRouteNodeService().save(nodeInstance);
82 }
83 }
84 for (ActionRequestValue requestToDelete : requestsToDelete) {
85 getActionRequestService().deleteActionRequestGraph(requestToDelete);
86 }
87 try {
88 OrchestrationConfig config = new OrchestrationConfig(EngineCapability.STANDARD);
89 KEWServiceLocator.getWorkflowEngineFactory().newEngine(config).process(documentId, null);
90 } catch (Exception e) {
91 throw new WorkflowRuntimeException(e);
92 }
93 performanceLogger.log("Time to run DocumentRequeuer for document " + documentId);
94 }
95
96 private ActionRequestService getActionRequestService() {
97 return KEWServiceLocator.getActionRequestService();
98 }
99
100 private RouteNodeService getRouteNodeService() {
101 return KEWServiceLocator.getRouteNodeService();
102 }
103 }