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