Coverage Report - org.kuali.rice.krms.framework.engine.BasicRule
 
Classes in this File Line Coverage Branch Coverage Complexity
BasicRule
80%
17/21
80%
8/10
2
 
 1  
 package org.kuali.rice.krms.framework.engine;
 2  
 
 3  
 import java.util.List;
 4  
 
 5  
 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
 6  
 import org.kuali.rice.krms.api.engine.ResultEvent;
 7  
 import org.kuali.rice.krms.framework.engine.result.BasicResult;
 8  
 
 9  
 public class BasicRule implements Rule {
 10  1
         private static final ResultLogger LOG = ResultLogger.getInstance();
 11  
 
 12  
         private String name;
 13  
         private Proposition proposition;
 14  
         private List<Action> actions;
 15  
         
 16  34
         public BasicRule(String name, Proposition proposition, List<Action> actions) {
 17  34
                 if (proposition == null) {
 18  0
                         throw new IllegalArgumentException("Propsition cannot be null.");
 19  
                 }
 20  34
                 this.name = name;
 21  34
                 this.proposition = proposition;
 22  34
                 this.actions = actions;
 23  34
         }
 24  
         
 25  
         public BasicRule(Proposition proposition, List<Action> actions) {
 26  0
                 this(null, proposition, actions);
 27  0
         }
 28  
         
 29  
         @Override
 30  
         public boolean evaluate(ExecutionEnvironment environment) {
 31  35
                 boolean result = proposition.evaluate(environment);
 32  35
                 if (actions != null) {
 33  34
                         for (Action action : actions) {
 34  34
                                 if (shouldExecuteAction(result)) {
 35  19
                                         action.execute(environment);
 36  
                                 }
 37  
                         }
 38  
                 }
 39  35
                 if (LOG.isEnabled(environment)){
 40  35
                         LOG.logResult(new BasicResult(ResultEvent.RuleEvaluated, this, environment, result));
 41  
                 }
 42  35
                 return result;
 43  
         }
 44  
         
 45  
         protected boolean shouldExecuteAction(boolean ruleExecutionResult) {
 46  34
                 return ruleExecutionResult;
 47  
         }
 48  
 
 49  
         public String getName() {
 50  0
                 return name;
 51  
         }
 52  
         
 53  
         public String toString(){
 54  463
                 return name;
 55  
         }
 56  
 }