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-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kew.engine.transition;
 17  
 
 18  
 import org.kuali.rice.kew.engine.RouteContext;
 19  
 import org.kuali.rice.kew.engine.node.ProcessDefinitionBo;
 20  
 import org.kuali.rice.kew.engine.node.ProcessResult;
 21  
 import org.kuali.rice.kew.engine.node.RouteNode;
 22  
 import org.kuali.rice.kew.engine.node.RouteNodeInstance;
 23  
 import org.kuali.rice.kew.engine.node.SubProcessNode;
 24  
 import org.kuali.rice.kew.engine.node.SubProcessResult;
 25  
 import org.kuali.rice.kew.api.exception.WorkflowException;
 26  
 
 27  
 import java.util.ArrayList;
 28  
 import java.util.List;
 29  
 
 30  
 
 31  
 /**
 32  
  * Handles transitions into and out of {@link SubProcessNode} nodes.
 33  
  * 
 34  
  * @see SubProcessNode
 35  
  *
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 37  
  */
 38  0
 public class SubProcessTransitionEngine extends TransitionEngine {
 39  
     
 40  
     public RouteNodeInstance transitionTo(RouteNodeInstance nextNodeInstance, RouteContext context) throws Exception {
 41  0
         String processName = nextNodeInstance.getRouteNode().getRouteNodeName();
 42  0
         ProcessDefinitionBo process = context.getDocument().getDocumentType().getNamedProcess(processName);
 43  0
         if (process == null) {
 44  0
             throw new WorkflowException("Could not locate named sub process: " + processName);
 45  
         }
 46  0
         RouteNodeInstance subProcessNodeInstance = nextNodeInstance;
 47  0
         subProcessNodeInstance.setInitial(false);
 48  0
         subProcessNodeInstance.setActive(false);
 49  0
         nextNodeInstance = getRouteHelper().getNodeFactory().createRouteNodeInstance(subProcessNodeInstance.getDocumentId(), process.getInitialRouteNode());
 50  0
         nextNodeInstance.setBranch(subProcessNodeInstance.getBranch());
 51  0
         nextNodeInstance.setProcess(subProcessNodeInstance);
 52  0
             return nextNodeInstance;
 53  
         }
 54  
 
 55  
         public ProcessResult isComplete(RouteContext context) throws Exception {
 56  0
         throw new UnsupportedOperationException("isComplete() should not be invoked on a SubProcess!");
 57  
     }
 58  
 
 59  
     public Transition transitionFrom(RouteContext context, ProcessResult processResult) throws Exception {
 60  0
                 RouteNodeInstance processInstance = context.getNodeInstance().getProcess();
 61  0
         processInstance.setComplete(true);
 62  0
                 SubProcessNode node = (SubProcessNode)getNode(processInstance.getRouteNode(), SubProcessNode.class);
 63  0
                 SubProcessResult result = node.process(context);
 64  0
                 List<RouteNodeInstance> nextNodeInstances = new ArrayList<RouteNodeInstance>();
 65  0
                 if (result.isComplete()) {
 66  0
                         List<RouteNode> nextNodes = processInstance.getRouteNode().getNextNodes();
 67  0
             for (RouteNode nextNode : nextNodes)
 68  
             {
 69  0
                 RouteNodeInstance nextNodeInstance = getRouteHelper().getNodeFactory().createRouteNodeInstance(processInstance.getDocumentId(), nextNode);
 70  0
                 nextNodeInstance.setBranch(processInstance.getBranch());
 71  0
                 nextNodeInstance.setProcess(processInstance.getProcess());
 72  0
                 nextNodeInstances.add(nextNodeInstance);
 73  0
             }
 74  
                 }
 75  0
                 return new Transition(nextNodeInstances);
 76  
         }
 77  
 
 78  
 }