View Javadoc
1   /**
2    * Copyright 2005-2014 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.actions;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.rice.kew.engine.RouteContext;
22  import org.kuali.rice.kew.engine.RouteHelper;
23  import org.kuali.rice.kew.engine.node.SplitNode;
24  import org.kuali.rice.kew.engine.node.SplitResult;
25  
26  
27  public class CustomCycleSplit implements SplitNode {
28  
29      private static int timesToCycle = 0;
30      private static String cycleBranchName = null;
31      private static String nonCycleBranchName = null;
32      private static int timesCycled = 0;
33      
34      public SplitResult process(RouteContext context, RouteHelper helper) throws Exception {
35          List<String> branchNames = new ArrayList<String>();
36          if (org.apache.commons.lang.StringUtils.isEmpty(cycleBranchName) || org.apache.commons.lang.StringUtils.isEmpty(nonCycleBranchName)) {
37              throw new Exception("Must specify cycle and non-cycle branch names.");
38          }
39          if (timesCycled++ == timesToCycle) {
40              branchNames.add(nonCycleBranchName); 
41          } else {
42              branchNames.add(cycleBranchName);
43          }
44          return new SplitResult(branchNames);
45      }
46      
47      public static void configureCycle(String cycleBranchName, String nonCycleBranchName, int timesToCycle) {
48          CustomCycleSplit.cycleBranchName = cycleBranchName;
49          CustomCycleSplit.nonCycleBranchName = nonCycleBranchName;
50          CustomCycleSplit.timesToCycle = timesToCycle;
51          CustomCycleSplit.timesCycled = 0;
52      }
53      
54      public static int getTimesCycled() {
55          return timesCycled;
56      }
57  
58  }