Coverage Report - org.kuali.rice.kew.engine.transition.SubProcessTransitionEngine
 
Classes in this File Line Coverage Branch Coverage Complexity
SubProcessTransitionEngine
0%
0/27
0%
0/6
2.667
 
 1  
 /*
 2  
  * Copyright 2005-2007 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.engine.transition;
 18  
 
 19  
 import org.kuali.rice.kew.engine.RouteContext;
 20  
 import org.kuali.rice.kew.engine.node.Process;
 21  
 import org.kuali.rice.kew.engine.node.*;
 22  
 import org.kuali.rice.kew.exception.WorkflowException;
 23  
 
 24  
 import java.util.ArrayList;
 25  
 import java.util.List;
 26  
 
 27  
 
 28  
 /**
 29  
  * Handles transitions into and out of {@link SubProcessNode} nodes.
 30  
  * 
 31  
  * @see SubProcessNode
 32  
  *
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  */
 35  0
 public class SubProcessTransitionEngine extends TransitionEngine {
 36  
     
 37  
     public RouteNodeInstance transitionTo(RouteNodeInstance nextNodeInstance, RouteContext context) throws Exception {
 38  0
         String processName = nextNodeInstance.getRouteNode().getRouteNodeName();
 39  0
         Process process = context.getDocument().getDocumentType().getNamedProcess(processName);
 40  0
         if (process == null) {
 41  0
             throw new WorkflowException("Could not locate named sub process: " + processName);
 42  
         }
 43  0
         RouteNodeInstance subProcessNodeInstance = nextNodeInstance;
 44  0
         subProcessNodeInstance.setInitial(false);
 45  0
         subProcessNodeInstance.setActive(false);
 46  0
         nextNodeInstance = getRouteHelper().getNodeFactory().createRouteNodeInstance(subProcessNodeInstance.getDocumentId(), process.getInitialRouteNode());
 47  0
         nextNodeInstance.setBranch(subProcessNodeInstance.getBranch());
 48  0
         nextNodeInstance.setProcess(subProcessNodeInstance);
 49  0
             return nextNodeInstance;
 50  
         }
 51  
 
 52  
         public ProcessResult isComplete(RouteContext context) throws Exception {
 53  0
         throw new UnsupportedOperationException("isComplete() should not be invoked on a SubProcess!");
 54  
     }
 55  
 
 56  
     public Transition transitionFrom(RouteContext context, ProcessResult processResult) throws Exception {
 57  0
                 RouteNodeInstance processInstance = context.getNodeInstance().getProcess();
 58  0
         processInstance.setComplete(true);
 59  0
                 SubProcessNode node = (SubProcessNode)getNode(processInstance.getRouteNode(), SubProcessNode.class);
 60  0
                 SubProcessResult result = node.process(context);
 61  0
                 List<RouteNodeInstance> nextNodeInstances = new ArrayList<RouteNodeInstance>();
 62  0
                 if (result.isComplete()) {
 63  0
                         List<RouteNode> nextNodes = processInstance.getRouteNode().getNextNodes();
 64  0
             for (RouteNode nextNode : nextNodes)
 65  
             {
 66  0
                 RouteNodeInstance nextNodeInstance = getRouteHelper().getNodeFactory().createRouteNodeInstance(processInstance.getDocumentId(), nextNode);
 67  0
                 nextNodeInstance.setBranch(processInstance.getBranch());
 68  0
                 nextNodeInstance.setProcess(processInstance.getProcess());
 69  0
                 nextNodeInstances.add(nextNodeInstance);
 70  0
             }
 71  
                 }
 72  0
                 return new Transition(nextNodeInstances);
 73  
         }
 74  
 
 75  
 }