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 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.framework.engine.PropositionResult;
22 import org.kuali.rice.krms.framework.engine.result.BasicResult;
23 import org.kuali.student.common.util.krms.RulesExecutionConstants;
24
25 import java.util.Collection;
26
27
28
29
30
31
32 public abstract class CourseEnrollmentProposition extends AbstractLeafProposition {
33
34 protected final boolean checkForAllEnrolled;
35
36 protected Integer minToEnroll;
37
38 public CourseEnrollmentProposition(Integer minToEnroll) {
39 this.checkForAllEnrolled = false;
40 this.minToEnroll = minToEnroll;
41 }
42
43 public CourseEnrollmentProposition() {
44 checkForAllEnrolled = true;
45 }
46
47
48 @Override
49 public PropositionResult evaluate(ExecutionEnvironment environment) {
50
51 Collection<String> enrolledCourses = environment.resolveTerm(RulesExecutionConstants.enrolledCourseIdsTerm, this);
52
53 Collection<String> requiredCourseIds = getRequiredCourseIds(environment);
54
55 PropositionResult result = null;
56
57 if(checkForAllEnrolled) {
58 result = new PropositionResult(enrolledCourses.containsAll(requiredCourseIds));
59 }
60
61 else {
62 result = new PropositionResult(CollectionUtils.intersection(enrolledCourses, requiredCourseIds).size() >= minToEnroll);
63 }
64
65 environment.getEngineResults().addResult(new BasicResult(ResultEvent.PROPOSITION_EVALUATED, this, environment, result.getResult()));
66
67 return result;
68
69 }
70
71 protected abstract Collection<String> getRequiredCourseIds(ExecutionEnvironment environment);
72 }