Coverage Report - org.kuali.rice.krms.framework.engine.BasicRule
 
Classes in this File Line Coverage Branch Coverage Complexity
BasicRule
76%
16/21
80%
8/10
2
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.krms.framework.engine;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
 21  
 import org.kuali.rice.krms.api.engine.ResultEvent;
 22  
 import org.kuali.rice.krms.framework.engine.result.BasicResult;
 23  
 
 24  
 public class BasicRule implements Rule {
 25  1
         private static final ResultLogger LOG = ResultLogger.getInstance();
 26  
 
 27  
         private String name;
 28  
         private Proposition proposition;
 29  
         private List<Action> actions;
 30  
         
 31  34
         public BasicRule(String name, Proposition proposition, List<Action> actions) {
 32  34
                 if (proposition == null) {
 33  0
                         throw new IllegalArgumentException("Proposition cannot be null.");
 34  
                 }
 35  34
                 this.name = name;
 36  34
                 this.proposition = proposition;
 37  34
                 this.actions = actions;
 38  34
         }
 39  
         
 40  
         public BasicRule(Proposition proposition, List<Action> actions) {
 41  0
                 this(null, proposition, actions);
 42  0
         }
 43  
         
 44  
         @Override
 45  
         public boolean evaluate(ExecutionEnvironment environment) {
 46  35
                 boolean result = proposition.evaluate(environment).getResult();
 47  35
                 if (actions != null) {
 48  34
                         for (Action action : actions) {
 49  34
                                 if (shouldExecuteAction(result)) {
 50  19
                                         action.execute(environment);
 51  
                                 }
 52  
                         }
 53  
                 }
 54  35
                 if (LOG.isEnabled(environment)){
 55  35
                         LOG.logResult(new BasicResult(ResultEvent.RuleEvaluated, this, environment, result));
 56  
                 }
 57  35
                 return result;
 58  
         }
 59  
         
 60  
         protected boolean shouldExecuteAction(boolean ruleExecutionResult) {
 61  34
                 return ruleExecutionResult;
 62  
         }
 63  
 
 64  
         public String getName() {
 65  0
                 return name;
 66  
         }
 67  
         
 68  
         public String toString(){
 69  0
                 return name;
 70  
         }
 71  
 }