1 /** 2 * Copyright 2005-2015 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.rule; 17 18 import org.apache.log4j.Logger; 19 import org.kuali.rice.kew.engine.RouteContext; 20 import org.kuali.rice.kew.engine.node.RouteNodeInstance; 21 import org.kuali.rice.kew.engine.node.hierarchyrouting.HierarchyRoutingNode; 22 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; 23 import org.kuali.rice.kew.util.Utilities; 24 25 import java.sql.Timestamp; 26 import java.util.Map; 27 28 29 /** 30 * Derives the rule name to select based on node instance state configured by a governing 31 * HierarchyRoutingNode and the HierarchyRoutingNode name. E.g.: 32 * <pre> 33 * <dynamic name="hierarchy"> 34 * <type>org.kuali.rice.kew.engine.node.hierarchyrouting.HierarchyRoutingNode</type> 35 * <hierarchyProvider>org.kuali.rice.kew.engine.node.hierarchyrouting.SimpleHierarchyProvider</hierarchyProvider> 36 * <ruleSelector>HierarchicalNamed</ruleSelector> 37 * </dynamic> 38 * </pre> 39 * If <code>org.kuali.rice.kew.engine.node.hierarchyrouting.SimpleHierarchyProvider</code> supplied stops named 'a', 'b', and 'c', the rules 40 * selected would be 'hierarchy-a', 'hierarchy-b', and 'hierarchy-c', respectively. 41 * @author Kuali Rice Team (rice.collab@kuali.org) 42 */ 43 public class HierarchicalNamedRuleSelector extends NamedRuleSelector { 44 private static final Logger LOG = Logger.getLogger(HierarchicalNamedRuleSelector.class); 45 @Override 46 protected String getName(RouteContext context, DocumentRouteHeaderValue routeHeader, RouteNodeInstance nodeInstance, 47 String selectionCriterion, Timestamp effectiveDate) { 48 Map<String, String> cfgMap = Utilities.getKeyValueCollectionAsMap(nodeInstance.getState()); 49 String stop_id = cfgMap.get(HierarchyRoutingNode.STOP_ID); 50 if (stop_id == null) { 51 LOG.warn("STOP ID from nodeInstance was NULL: " + nodeInstance); 52 return null; 53 } 54 LOG.info("STOP ID from nodeInstance: " + nodeInstance.getRouteNodeInstanceId() + ": " + stop_id); 55 return nodeInstance.getProcess().getRouteNode().getRouteNodeName() + "-" + stop_id; 56 } 57 }