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