001 /**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.actions;
017
018 import java.util.ArrayList;
019 import java.util.List;
020
021 import org.kuali.rice.kew.engine.RouteContext;
022 import org.kuali.rice.kew.engine.RouteHelper;
023 import org.kuali.rice.kew.engine.node.SplitNode;
024 import org.kuali.rice.kew.engine.node.SplitResult;
025
026
027 public class CustomCycleSplit implements SplitNode {
028
029 private static int timesToCycle = 0;
030 private static String cycleBranchName = null;
031 private static String nonCycleBranchName = null;
032 private static int timesCycled = 0;
033
034 public SplitResult process(RouteContext context, RouteHelper helper) throws Exception {
035 List<String> branchNames = new ArrayList<String>();
036 if (org.apache.commons.lang.StringUtils.isEmpty(cycleBranchName) || org.apache.commons.lang.StringUtils.isEmpty(nonCycleBranchName)) {
037 throw new Exception("Must specify cycle and non-cycle branch names.");
038 }
039 if (timesCycled++ == timesToCycle) {
040 branchNames.add(nonCycleBranchName);
041 } else {
042 branchNames.add(cycleBranchName);
043 }
044 return new SplitResult(branchNames);
045 }
046
047 public static void configureCycle(String cycleBranchName, String nonCycleBranchName, int timesToCycle) {
048 CustomCycleSplit.cycleBranchName = cycleBranchName;
049 CustomCycleSplit.nonCycleBranchName = nonCycleBranchName;
050 CustomCycleSplit.timesToCycle = timesToCycle;
051 CustomCycleSplit.timesCycled = 0;
052 }
053
054 public static int getTimesCycled() {
055 return timesCycled;
056 }
057
058 }