| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.common.util.krms.proposition; |
| 17 | |
|
| 18 | |
import java.util.Collection; |
| 19 | |
|
| 20 | |
import org.apache.commons.collections.CollectionUtils; |
| 21 | |
import org.kuali.rice.krms.api.engine.ExecutionEnvironment; |
| 22 | |
import org.kuali.rice.krms.api.engine.ResultEvent; |
| 23 | |
import org.kuali.rice.krms.api.engine.TermResolutionException; |
| 24 | |
import org.kuali.rice.krms.framework.engine.Proposition; |
| 25 | |
import org.kuali.rice.krms.framework.engine.PropositionResult; |
| 26 | |
import org.kuali.rice.krms.framework.engine.result.BasicResult; |
| 27 | |
import org.kuali.student.common.util.krms.RulesExecutionConstants; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
public abstract class CourseCompletionProposition extends AbstractLeafProposition implements Proposition { |
| 35 | |
|
| 36 | |
protected final boolean checkForAllCompleted; |
| 37 | |
|
| 38 | |
protected Integer minToComplete; |
| 39 | |
|
| 40 | 0 | public CourseCompletionProposition(Integer minToComplete) { |
| 41 | 0 | this.checkForAllCompleted = false; |
| 42 | 0 | this.minToComplete = minToComplete; |
| 43 | 0 | } |
| 44 | |
|
| 45 | 0 | public CourseCompletionProposition() { |
| 46 | 0 | checkForAllCompleted = true; |
| 47 | 0 | } |
| 48 | |
|
| 49 | |
|
| 50 | |
@Override |
| 51 | |
public PropositionResult evaluate(ExecutionEnvironment environment) { |
| 52 | |
|
| 53 | 0 | Collection<String> completedCourses = environment.resolveTerm(RulesExecutionConstants.completedCourseIdsTerm, this); |
| 54 | |
|
| 55 | 0 | Collection<String> termCourses = getTermCourseIds(environment); |
| 56 | |
|
| 57 | 0 | PropositionResult result = null; |
| 58 | |
|
| 59 | 0 | if(checkForAllCompleted) { |
| 60 | 0 | result = new PropositionResult(completedCourses.containsAll(termCourses)); |
| 61 | |
} |
| 62 | |
|
| 63 | |
else { |
| 64 | 0 | result = new PropositionResult(CollectionUtils.intersection(completedCourses, termCourses).size() >= minToComplete); |
| 65 | |
} |
| 66 | |
|
| 67 | 0 | environment.getEngineResults().addResult(new BasicResult(ResultEvent.PROPOSITION_EVALUATED, this, environment, result.getResult())); |
| 68 | |
|
| 69 | 0 | return result; |
| 70 | |
|
| 71 | |
} |
| 72 | |
|
| 73 | |
protected abstract Collection<String> getTermCourseIds(ExecutionEnvironment environment); |
| 74 | |
|
| 75 | |
} |