1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.courseoffering.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.enrollment.academicrecord.dto.StudentCourseRecordInfo;
21 import org.kuali.student.r2.common.dto.ContextInfo;
22 import org.kuali.student.r2.common.krms.util.KSKRMSExecutionUtil;
23 import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
24 import org.kuali.student.r2.lum.lrc.dto.ResultValueInfo;
25 import org.kuali.student.r2.lum.lrc.service.LRCService;
26
27 import java.util.Collections;
28 import java.util.HashSet;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Set;
32
33
34
35
36
37
38
39
40
41
42
43 public class CourseWithGradeTermResolver implements TermResolver<Boolean> {
44
45 private LRCService lrcService;
46
47 private TermResolver<List<StudentCourseRecordInfo>> courseRecordsForCourseIdTermResolver;
48
49 @Override
50 public Set<String> getPrerequisites() {
51 Set<String> prereqs = new HashSet<String>(2);
52 prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID);
53 prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
54 return Collections.unmodifiableSet(prereqs);
55 }
56
57 @Override
58 public String getOutput() {
59 return KSKRMSServiceConstants.TERM_RESOLVER_COURSEWITHGRADE;
60 }
61
62 @Override
63 public Set<String> getParameterNames() {
64 Set<String> temp = new HashSet<String>(3);
65 temp.add(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLU_KEY);
66 temp.add(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_GRADE_KEY);
67 temp.add(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_GRADE_TYPE_KEY);
68 return Collections.unmodifiableSet(temp);
69 }
70
71 @Override
72 public int getCost() {
73 return 5;
74 }
75
76 @Override
77 public Boolean resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
78 ContextInfo context = (ContextInfo) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
79 String gradeType = parameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_GRADE_TYPE_KEY);
80 String grade = parameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_GRADE_KEY);
81
82 try {
83
84 ResultValueInfo gradeValue = this.getLrcService().getResultValue(grade, context);
85 Integer gradeNumericValue = Integer.valueOf(gradeValue.getNumericValue());
86
87
88 List<StudentCourseRecordInfo> courseRecords = this.getCourseRecordsForCourseIdTermResolver().resolve(resolvedPrereqs, parameters);
89 for (StudentCourseRecordInfo courseRecord : courseRecords) {
90 if (gradeType.equals(courseRecord.getAssignedGradeScaleKey())) {
91 ResultValueInfo resultValue = this.getLrcService().getResultValue(courseRecord.getAssignedGradeValue(), context);
92 Integer resultNumericValue = Integer.valueOf(resultValue.getNumericValue());
93 if(resultNumericValue>=gradeNumericValue){
94 return true;
95 }
96 }
97 }
98
99 } catch (Exception e) {
100 KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this);
101 }
102
103 return false;
104 }
105
106 public LRCService getLrcService() {
107 return lrcService;
108 }
109
110 public void setLrcService(LRCService lrcService) {
111 this.lrcService = lrcService;
112 }
113
114 public TermResolver<List<StudentCourseRecordInfo>> getCourseRecordsForCourseIdTermResolver() {
115 return courseRecordsForCourseIdTermResolver;
116 }
117
118 public void setCourseRecordsForCourseIdTermResolver(TermResolver<List<StudentCourseRecordInfo>> courseRecordsForCourseIdTermResolver) {
119 this.courseRecordsForCourseIdTermResolver = courseRecordsForCourseIdTermResolver;
120 }
121
122 }