Coverage Report - org.kuali.student.r2.core.class1.process.krms.proposition.SubProcessProposition
 
Classes in this File Line Coverage Branch Coverage Complexity
SubProcessProposition
0%
0/21
0%
0/4
3
 
 1  
 /**
 2  
  * Copyright 2011 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.r2.core.class1.process.krms.proposition;
 17  
 
 18  
 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
 19  
 import org.kuali.rice.krms.api.engine.ResultEvent;
 20  
 import org.kuali.rice.krms.api.engine.Term;
 21  
 import org.kuali.rice.krms.framework.engine.PropositionResult;
 22  
 import org.kuali.rice.krms.framework.engine.result.BasicResult;
 23  
 import org.kuali.student.common.util.krms.RulesExecutionConstants;
 24  
 import org.kuali.student.common.util.krms.proposition.AbstractLeafProposition;
 25  
 import org.kuali.student.r2.common.dto.ContextInfo;
 26  
 import org.kuali.student.r2.common.dto.ValidationResultInfo;
 27  
 import org.kuali.student.r2.common.exceptions.OperationFailedException;
 28  
 import org.kuali.student.r2.core.class1.process.context.CourseRegistrationProcessContextInfo;
 29  
 import org.kuali.student.r2.core.class1.process.evaluator.ProcessEvaluator;
 30  
 
 31  
 import java.util.HashMap;
 32  
 import java.util.List;
 33  
 import java.util.Map;
 34  
 
 35  
 /**
 36  
  * This class evaluates a sub process
 37  
  *
 38  
  * @author alubbers
 39  
  */
 40  
 public class SubProcessProposition extends AbstractLeafProposition {
 41  
 
 42  
     private CourseRegistrationProcessContextInfo checkContext;
 43  
     private ProcessEvaluator<CourseRegistrationProcessContextInfo> processEvaluator;
 44  
 
 45  0
     public SubProcessProposition(CourseRegistrationProcessContextInfo checkContext, ProcessEvaluator<CourseRegistrationProcessContextInfo> processEvaluator) {
 46  0
         this.checkContext = checkContext;
 47  0
         this.processEvaluator = processEvaluator;
 48  0
     }
 49  
 
 50  
     @Override
 51  
     public PropositionResult evaluate(ExecutionEnvironment environment) {
 52  
 
 53  0
         ContextInfo context = environment.resolveTerm(new Term(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME), this);
 54  0
         List<ValidationResultInfo> results = null;
 55  
 
 56  0
         Map<String, Object> resultDetails = new HashMap<String, Object>();
 57  
 
 58  
         try {
 59  0
             results = processEvaluator.evaluate(checkContext, context);
 60  0
         } catch (OperationFailedException e) {
 61  
 
 62  
             // on an evaluation exception, report the details of the exception to the KRMS environment
 63  0
             resultDetails.put(RulesExecutionConstants.SUBPROCESS_EVALUATION_EXCEPTION, e);
 64  0
             environment.getEngineResults().addResult(new BasicResult(resultDetails, ResultEvent.PROPOSITION_EVALUATED, this, environment, false));
 65  0
             return new PropositionResult(false);
 66  
 
 67  0
         }
 68  
 
 69  
         // add all the validation results into the map
 70  0
         resultDetails.put(RulesExecutionConstants.SUBPROCESS_EVALUATION_RESULTS, results);
 71  
 
 72  0
         boolean propositionResult = true;
 73  0
         for (ValidationResultInfo evalResult : results) {
 74  
             // if any result is an error, the entire proposition evaluation is false
 75  0
             if(evalResult.isError()) {
 76  0
                 propositionResult = false;
 77  0
                 break;
 78  
             }
 79  
         }
 80  
 
 81  
         // add a result in the environment that can be analyzed by callers of the KRMS engine
 82  0
         environment.getEngineResults().addResult(new BasicResult(resultDetails, ResultEvent.PROPOSITION_EVALUATED, this, environment, propositionResult));
 83  
 
 84  0
         return new PropositionResult(propositionResult);
 85  
     }
 86  
 
 87  
 }