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