Coverage Report - org.kuali.student.common.util.krms.proposition.MaxCourseCompletionProposition
 
Classes in this File Line Coverage Branch Coverage Complexity
MaxCourseCompletionProposition
0%
0/19
0%
0/4
1.333
 
 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.common.util.krms.proposition;
 17  
 
 18  
 import org.apache.commons.collections.CollectionUtils;
 19  
 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
 20  
 import org.kuali.rice.krms.api.engine.ResultEvent;
 21  
 import org.kuali.rice.krms.api.engine.Term;
 22  
 import org.kuali.rice.krms.framework.engine.PropositionResult;
 23  
 import org.kuali.rice.krms.framework.engine.result.BasicResult;
 24  
 import org.kuali.student.common.util.krms.RulesExecutionConstants;
 25  
 
 26  
 import java.util.Collection;
 27  
 import java.util.Collections;
 28  
 
 29  
 /**
 30  
  * Proposition class that checks for completion of no more than N of the given courses
 31  
  */
 32  
 public class MaxCourseCompletionProposition extends AbstractLeafProposition {
 33  
 
 34  
     private final String courseSetId;
 35  
 
 36  
     private final String singleCourseId;
 37  
 
 38  
     private final Integer maxCoursesCompleted;
 39  
 
 40  0
     public MaxCourseCompletionProposition(String singleCourseId) {
 41  0
         this.courseSetId = null;
 42  0
         this.singleCourseId = singleCourseId;
 43  0
         this.maxCoursesCompleted = 0;
 44  0
     }
 45  
 
 46  0
     public MaxCourseCompletionProposition(String courseSetId, Integer maxCourses) {
 47  0
         this.courseSetId = courseSetId;
 48  0
         this.singleCourseId = null;
 49  0
         this.maxCoursesCompleted = maxCourses;
 50  0
     }
 51  
 
 52  
     @Override
 53  
     public PropositionResult evaluate(ExecutionEnvironment environment) {
 54  0
         Collection<String> completedCourses = environment.resolveTerm(RulesExecutionConstants.completedCourseIdsTerm, this);
 55  
         Collection<String> coursesToCheck;
 56  
 
 57  0
         if(singleCourseId == null) {
 58  0
             Term term = new Term(RulesExecutionConstants.COURSE_SET_TERM_NAME, Collections.singletonMap(RulesExecutionConstants.COURSE_SET_ID_TERM_PROPERTY, courseSetId));
 59  0
             coursesToCheck = environment.resolveTerm(term, this);
 60  0
         }
 61  
         else {
 62  0
             coursesToCheck = Collections.singleton(singleCourseId);
 63  
         }
 64  
 
 65  
 
 66  0
         PropositionResult result = new PropositionResult(CollectionUtils.intersection(completedCourses, coursesToCheck).size() <= maxCoursesCompleted);
 67  
 
 68  0
         environment.getEngineResults().addResult(new BasicResult(ResultEvent.PROPOSITION_EVALUATED, this, environment, result.getResult()));
 69  
 
 70  0
         return result;
 71  
     }
 72  
 }