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 | 0 | public CourseEnrollmentProposition(Integer minToEnroll) { |
39 | 0 | this.checkForAllEnrolled = false; |
40 | 0 | this.minToEnroll = minToEnroll; |
41 | 0 | } |
42 | |
|
43 | 0 | public CourseEnrollmentProposition() { |
44 | 0 | checkForAllEnrolled = true; |
45 | 0 | } |
46 | |
|
47 | |
|
48 | |
@Override |
49 | |
public PropositionResult evaluate(ExecutionEnvironment environment) { |
50 | |
|
51 | 0 | Collection<String> enrolledCourses = environment.resolveTerm(RulesExecutionConstants.enrolledCourseIdsTerm, this); |
52 | |
|
53 | 0 | Collection<String> requiredCourseIds = getRequiredCourseIds(environment); |
54 | |
|
55 | 0 | PropositionResult result = null; |
56 | |
|
57 | 0 | if(checkForAllEnrolled) { |
58 | 0 | result = new PropositionResult(enrolledCourses.containsAll(requiredCourseIds)); |
59 | |
} |
60 | |
|
61 | |
else { |
62 | 0 | result = new PropositionResult(CollectionUtils.intersection(enrolledCourses, requiredCourseIds).size() >= minToEnroll); |
63 | |
} |
64 | |
|
65 | 0 | environment.getEngineResults().addResult(new BasicResult(ResultEvent.PROPOSITION_EVALUATED, this, environment, result.getResult())); |
66 | |
|
67 | 0 | return result; |
68 | |
|
69 | |
} |
70 | |
|
71 | |
protected abstract Collection<String> getRequiredCourseIds(ExecutionEnvironment environment); |
72 | |
} |