Coverage Report - org.kuali.rice.kew.actionrequest.service.impl.DocumentRequeuerImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentRequeuerImpl
0%
0/28
0%
0/10
3.333
 
 1  
 /*
 2  
  * Copyright 2005-2008 The Kuali Foundation
 3  
  * 
 4  
  * 
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.opensource.org/licenses/ecl2.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 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  
  * A service which effectively "refreshes" and requeues a document.  It first deletes any
 38  
  * pending action requests on the documents and then requeues the document for standard routing.
 39  
  * Addionally, it adds duplicate notification suppression state to RouteNodeInstanceS for 
 40  
  * which ActionRequestS will be regenerated. 
 41  
  * 
 42  
  * Intended to be called async and wired that way in server/client spring beans.
 43  
  * 
 44  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 45  
  */
 46  0
 public class DocumentRequeuerImpl implements DocumentRequeuerService {
 47  
         
 48  0
         private RouteHelper helper = new RouteHelper();
 49  
     
 50  
         /**
 51  
          * Requeues a document, and sets notification suppression data
 52  
          * 
 53  
          * @see org.kuali.rice.kew.actionrequest.service.DocumentRequeuerService#requeueDocument(java.lang.Long)
 54  
          */
 55  
         @SuppressWarnings("unchecked")
 56  
         public void requeueDocument(String documentId) {
 57  0
                 PerformanceLogger performanceLogger = new PerformanceLogger();
 58  0
         KEWServiceLocator.getRouteHeaderService().lockRouteHeader(documentId, true);
 59  0
         Collection<RouteNodeInstance> activeNodes = getRouteNodeService().getActiveNodeInstances(documentId);
 60  0
         List<ActionRequestValue> requestsToDelete = new ArrayList<ActionRequestValue>();
 61  
         
 62  0
                 NotificationSuppression notificationSuppression = new NotificationSuppression();
 63  
                 
 64  0
         for (RouteNodeInstance nodeInstance : activeNodes) {
 65  
             // only "requeue" if we're dealing with a request activation node
 66  0
             if (helper.isRequestActivationNode(nodeInstance.getRouteNode())) {
 67  0
                     List<ActionRequestValue> deletesForThisNode = 
 68  
                             getActionRequestService().findPendingRootRequestsByDocIdAtRouteNode(documentId, nodeInstance.getRouteNodeInstanceId());
 69  
                     
 70  0
                     for (ActionRequestValue deleteForThisNode : deletesForThisNode) {
 71  
                             // only delete the request if it was generated by a route module (or the rules system)
 72  0
                             if (deleteForThisNode.isRouteModuleRequest()) {
 73  0
                                     requestsToDelete.add(deleteForThisNode);
 74  
 
 75  
                                     // suppress duplicate notifications
 76  0
                                     notificationSuppression.addNotificationSuppression(nodeInstance, deleteForThisNode);
 77  
                             }
 78  
                     }
 79  
                 // this will trigger a regeneration of requests
 80  0
                 nodeInstance.setInitial(true);
 81  0
                 getRouteNodeService().save(nodeInstance);
 82  0
             }
 83  
         }
 84  0
         for (ActionRequestValue requestToDelete : requestsToDelete) {
 85  0
             getActionRequestService().deleteActionRequestGraph(requestToDelete);
 86  
         }
 87  
         try {
 88  0
             OrchestrationConfig config = new OrchestrationConfig(EngineCapability.STANDARD);
 89  0
                 KEWServiceLocator.getWorkflowEngineFactory().newEngine(config).process(documentId, null);
 90  0
         } catch (Exception e) {
 91  0
                 throw new WorkflowRuntimeException(e);
 92  0
         }
 93  0
         performanceLogger.log("Time to run DocumentRequeuer for document " + documentId);        
 94  0
         }
 95  
 
 96  
     private ActionRequestService getActionRequestService() {
 97  0
         return KEWServiceLocator.getActionRequestService();
 98  
     }
 99  
     
 100  
     private RouteNodeService getRouteNodeService() {
 101  0
         return KEWServiceLocator.getRouteNodeService();
 102  
     }
 103  
 }