View Javadoc

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