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.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 | |
|
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 | |
} |