View Javadoc
1   /**
2    * Copyright 2005-2016 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.RouteHelper;
20  import org.kuali.rice.kew.engine.node.*;
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  
26  /**
27   * Handles transitions into and out of {@link SplitNode} nodes.
28   * 
29   * @see SplitNode
30   *
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public class SplitTransitionEngine extends TransitionEngine {
34  	
35      public ProcessResult isComplete(RouteContext context) throws Exception {
36          SplitNode node = (SplitNode)getNode(context.getNodeInstance().getRouteNode(), SplitNode.class);
37          return node.process(context, getRouteHelper());
38      }
39      
40  	public Transition transitionFrom(RouteContext context, ProcessResult processResult)
41  			throws Exception {
42  		RouteNodeInstance splitInstance = context.getNodeInstance();
43  		List<RouteNodeInstance> nextNodeInstances = new ArrayList<RouteNodeInstance>();
44          SplitResult result = (SplitResult)processResult;
45          for (String branchName : result.getBranchNames())
46          {
47              for (RouteNode routeNode : splitInstance.getRouteNode().getNextNodes())
48              {
49                  if (routeNode.getBranch() != null && routeNode.getBranch().getName().equals(branchName))
50                  {
51                      nextNodeInstances.add(createSplitChild(branchName, routeNode, splitInstance));
52                  }
53              }
54          }
55  		return new Transition(nextNodeInstances);
56  	}
57  	
58  	public static RouteNodeInstance createSplitChild(String branchName, RouteNode routeNode, RouteNodeInstance splitInstance) {
59  	    RouteHelper routeHelper = new RouteHelper();
60  	    RouteNodeInstance nextNodeInstance = routeHelper.getNodeFactory().createRouteNodeInstance(splitInstance.getDocumentId(), routeNode);
61  		Branch branch = routeHelper.getNodeFactory().createBranch(branchName, splitInstance.getBranch(), nextNodeInstance);
62  		branch.setSplitNode(splitInstance);
63  		nextNodeInstance.setBranch(branch);
64  		nextNodeInstance.setProcess(splitInstance.getProcess());
65  		return nextNodeInstance;
66  	}
67  	
68  }