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