Coverage Report - org.kuali.rice.kew.rule.WorkflowAttributeRuleExpression
 
Classes in this File Line Coverage Branch Coverage Complexity
WorkflowAttributeRuleExpression
0%
0/27
0%
0/16
6.5
 
 1  
 /*
 2  
  * Copyright 2007 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.util.ArrayList;
 19  
 import java.util.Iterator;
 20  
 import java.util.List;
 21  
 
 22  
 import org.kuali.rice.kew.engine.RouteContext;
 23  
 import org.kuali.rice.kew.routeheader.DocumentContent;
 24  
 import org.kuali.rice.kew.rule.bo.RuleAttribute;
 25  
 import org.kuali.rice.kew.rule.bo.RuleTemplateAttribute;
 26  
 import org.kuali.rice.kew.rule.xmlrouting.GenericXMLRuleAttribute;
 27  
 import org.kuali.rice.kew.util.KEWConstants;
 28  
 
 29  
 
 30  
 /**
 31  
  * Standard rule expression implementation that evaluates the attributes associated with the rule definition 
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  */
 34  0
 class WorkflowAttributeRuleExpression implements RuleExpression {
 35  
     
 36  
         public RuleExpressionResult evaluate(Rule rule, RouteContext context) {
 37  
         
 38  0
                 RuleBaseValues ruleDefinition = rule.getDefinition();
 39  0
         boolean match = isMatch(ruleDefinition, context.getDocumentContent());
 40  0
         if (match) {
 41  0
             return new RuleExpressionResult(rule, match, ruleDefinition.getResponsibilities());
 42  
         }
 43  0
                 return new RuleExpressionResult(rule, match);
 44  
     }
 45  
 
 46  
     public boolean isMatch(RuleBaseValues ruleDefinition, DocumentContent docContent) {
 47  0
         if (ruleDefinition.getRuleTemplate() == null) {
 48  
             // this can happen if neither rule template nor expression was specified in the rule definition
 49  
             // because WorkflowAttributeRuleExpression is the default expression implementation, we should
 50  
             // handle this here in order to support rules that fire unconditionally (and just return a statically
 51  
             // configured list of responsibilities)
 52  
             // the alternative is to either detect this situation in the rule xml parser or RuleImpl, and either substitute
 53  
             // a different RuleExpression implementation (a "default default" one) in the configuration, or at runtime,
 54  
             // that simply implements the one-liner of returning responsibilities.
 55  
             // doing this in the existing WorkflowAttributeRuleExpression implementation introduces the least change
 56  
             // or compatibilities issues, and avoids pushing compensating logic into RuleImpl
 57  0
             return true;
 58  
         }
 59  0
         for (Iterator iter = ruleDefinition.getRuleTemplate().getActiveRuleTemplateAttributes().iterator(); iter.hasNext();) {
 60  0
             RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter.next();
 61  0
             if (!ruleTemplateAttribute.isWorkflowAttribute()) {
 62  0
                 continue;
 63  
             }
 64  0
             WorkflowAttribute routingAttribute = (WorkflowAttribute) ruleTemplateAttribute.getWorkflowAttribute();
 65  
 
 66  0
             RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute();
 67  0
             if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) {
 68  0
                 ((GenericXMLRuleAttribute) routingAttribute).setRuleAttribute(ruleAttribute);
 69  
             }
 70  0
             String className = ruleAttribute.getClassName();
 71  0
             List editedRuleExtensions = new ArrayList();
 72  0
             for (Iterator iter2 = ruleDefinition.getRuleExtensions().iterator(); iter2.hasNext();) {
 73  0
                 RuleExtension extension = (RuleExtension) iter2.next();
 74  0
                 if (extension.getRuleTemplateAttribute().getRuleAttribute().getClassName().equals(className)) {
 75  0
                     editedRuleExtensions.add(extension);
 76  
                 }
 77  0
             }
 78  0
             if (!routingAttribute.isMatch(docContent, editedRuleExtensions)) {
 79  0
                 return false;
 80  
             }
 81  0
         }
 82  0
         return true;
 83  
     }
 84  
 
 85  
 }