1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }