01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.actionrequests;
18:
19: import java.util.ArrayList;
20: import java.util.Collection;
21: import java.util.Iterator;
22: import java.util.List;
23:
24: import edu.iu.uis.eden.KEWServiceLocator;
25: import edu.iu.uis.eden.engine.RouteHelper;
26: import edu.iu.uis.eden.engine.node.RouteNodeInstance;
27: import edu.iu.uis.eden.engine.node.RouteNodeService;
28: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
29: import edu.iu.uis.eden.util.PerformanceLogger;
30:
31: /**
32: * A service which effectively "refreshes" and requeus a document. It first deletes any
33: * pending action requests on the documents and then requeues the document for standard routing.
34: *
35: * Intended to be called async and wired that way in server/client spring beans.
36: *
37: * @author rkirkend
38: * @author ewestfal
39: */
40: public class DocumentRequeuerImpl implements DocumentRequeuerService {
41:
42: private RouteHelper helper = new RouteHelper();
43:
44: public void requeueDocument(Long documentId) {
45: PerformanceLogger performanceLogger = new PerformanceLogger();
46: KEWServiceLocator.getRouteHeaderService().lockRouteHeader(
47: documentId, true);
48: Collection activeNodes = getRouteNodeService()
49: .getActiveNodeInstances(documentId);
50: List<ActionRequestValue> requestsToDelete = new ArrayList<ActionRequestValue>();
51: for (Iterator iterator = activeNodes.iterator(); iterator
52: .hasNext();) {
53: RouteNodeInstance nodeInstance = (RouteNodeInstance) iterator
54: .next();
55: // only "requeue" if we're dealing with a request activation node
56: if (helper.isRequestActivationNode(nodeInstance
57: .getRouteNode())) {
58: requestsToDelete.addAll(getActionRequestService()
59: .findPendingRootRequestsByDocIdAtRouteNode(
60: documentId,
61: nodeInstance.getRouteNodeInstanceId()));
62: // this will trigger a regeneration of requests
63: nodeInstance.setInitial(true);
64: getRouteNodeService().save(nodeInstance);
65: }
66: }
67: for (Iterator iterator = requestsToDelete.iterator(); iterator
68: .hasNext();) {
69: ActionRequestValue actionRequestToDelete = (ActionRequestValue) iterator
70: .next();
71: // only delete the request if it was generated by a route module (or the rules system)
72: if (actionRequestToDelete.isRouteModuleRequest()) {
73: getActionRequestService().deleteActionRequestGraph(
74: actionRequestToDelete);
75: }
76: }
77: try {
78: KEWServiceLocator.getWorkflowEngine().process(documentId,
79: null);
80: } catch (Exception e) {
81: throw new WorkflowRuntimeException(e);
82: }
83: performanceLogger
84: .log("Time to run DocumentRequeuer for document "
85: + documentId);
86: }
87:
88: private ActionRequestService getActionRequestService() {
89: return KEWServiceLocator.getActionRequestService();
90: }
91:
92: private RouteNodeService getRouteNodeService() {
93: return KEWServiceLocator.getRouteNodeService();
94: }
95: }
|