1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.krms.termresolver;
17
18 import org.kuali.rice.krms.api.engine.TermResolutionException;
19 import org.kuali.rice.krms.api.engine.TermResolver;
20 import org.kuali.student.krms.util.KSKRMSExecutionUtil;
21 import org.kuali.student.r2.common.dto.ContextInfo;
22 import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
23
24 import java.util.Collections;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
29
30
31
32
33
34
35
36
37
38
39
40 public class NumberOfCompletedCoursesTermResolver implements TermResolver<Integer> {
41
42 private TermResolver<List<String>> cluIdsInCluSetTermResolver;
43 private TermResolver<Boolean> completedCourseTermResolver;
44
45 @Override
46 public Set<String> getPrerequisites() {
47 Set<String> temp = new HashSet<String>(2);
48 temp.add(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID);
49 temp.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
50 return Collections.unmodifiableSet(temp);
51 }
52
53 @Override
54 public String getOutput() {
55 return KSKRMSServiceConstants.TERM_RESOLVER_NUMBEROFCOMPLETEDCOURSES;
56 }
57
58 @Override
59 public Set<String> getParameterNames() {
60 return Collections.singleton(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLUSET_KEY);
61 }
62
63 @Override
64 public int getCost() {
65 return 5;
66 }
67
68 @Override
69 public Integer resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
70
71 int clusCompleted = 0;
72 ContextInfo context = (ContextInfo) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
73 String personId = (String) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID);
74 try {
75
76 List<String> versionIndIds = this.getCluIdsInCluSetTermResolver().resolve(resolvedPrereqs, parameters);
77 for(String versionIndId : versionIndIds){
78 parameters.put(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLU_KEY, versionIndId);
79 if(this.getCompletedCourseTermResolver().resolve(resolvedPrereqs, parameters)){
80 clusCompleted++;
81 }
82 }
83 } catch (Exception e) {
84 KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this);
85 }
86
87 return clusCompleted;
88 }
89
90 public TermResolver<List<String>> getCluIdsInCluSetTermResolver() {
91 return cluIdsInCluSetTermResolver;
92 }
93
94 public void setCluIdsInCluSetTermResolver(TermResolver<List<String>> cluIdsInCluSetTermResolver) {
95 this.cluIdsInCluSetTermResolver = cluIdsInCluSetTermResolver;
96 }
97
98 public TermResolver<Boolean> getCompletedCourseTermResolver() {
99 return completedCourseTermResolver;
100 }
101
102 public void setCompletedCourseTermResolver(TermResolver<Boolean> completedCourseTermResolver) {
103 this.completedCourseTermResolver = completedCourseTermResolver;
104 }
105 }