1 package org.kuali.student.krms.termresolver;
2
3 import org.kuali.rice.krms.api.engine.TermResolutionException;
4 import org.kuali.rice.krms.api.engine.TermResolver;
5 import org.kuali.student.enrollment.academicrecord.dto.StudentCourseRecordInfo;
6 import org.kuali.student.enrollment.academicrecord.service.AcademicRecordService;
7 import org.kuali.student.enrollment.courseoffering.infc.CourseOffering;
8 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
9 import org.kuali.student.krms.util.KSKRMSExecutionUtil;
10 import org.kuali.student.r2.common.dto.ContextInfo;
11 import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
12
13 import java.util.Collections;
14 import java.util.HashSet;
15 import java.util.List;
16 import java.util.Map;
17 import java.util.Set;
18
19
20
21
22 public class CompletedCourseForTermTermResolver implements TermResolver<Boolean> {
23
24 private AcademicRecordService academicRecordService;
25 private CourseOfferingService courseOfferingService;
26
27 private TermResolver<List<String>> cluIdsTermResolver;
28
29 @Override
30 public Set<String> getPrerequisites() {
31 Set<String> prereqs = new HashSet<String>(2);
32 prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID);
33 prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
34 return Collections.unmodifiableSet(prereqs);
35 }
36
37 @Override
38 public String getOutput() {
39 return KSKRMSServiceConstants.TERM_RESOLVER_COMPLETEDCOURSEFORTERM;
40 }
41
42 @Override
43 public Set<String> getParameterNames() {
44 Set<String> parameters = new HashSet<String>(2);
45 parameters.add(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLU_KEY);
46 parameters.add(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_TERM_KEY);
47 return Collections.unmodifiableSet(parameters);
48 }
49
50 @Override
51 public int getCost() {
52 return 0;
53 }
54
55 @Override
56 public Boolean resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
57 ContextInfo context = (ContextInfo) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
58 String personId = (String) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID);
59
60 try {
61
62 String termId = parameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_TERM_KEY);
63
64
65 List<String> courseIds = this.getCluIdsTermResolver().resolve(resolvedPrereqs, parameters);
66 for(String courseId : courseIds){
67
68 List<StudentCourseRecordInfo> courseRecords = this.getAcademicRecordService().getCompletedCourseRecordsForCourse(personId, courseId, context);
69 for (StudentCourseRecordInfo courseRecord : courseRecords){
70 CourseOffering courseOffering = this.getCourseOfferingService().getCourseOffering(courseRecord.getCourseOfferingId(), context);
71 if(termId.equals(courseOffering.getTermId())){
72 return true;
73 }
74 }
75 }
76 } catch (Exception e) {
77 KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this);
78 }
79
80 return false;
81 }
82
83 public AcademicRecordService getAcademicRecordService() {
84 return academicRecordService;
85 }
86
87 public void setAcademicRecordService(AcademicRecordService academicRecordService) {
88 this.academicRecordService = academicRecordService;
89 }
90
91 public CourseOfferingService getCourseOfferingService() {
92 return courseOfferingService;
93 }
94
95 public void setCourseOfferingService(CourseOfferingService courseOfferingService) {
96 this.courseOfferingService = courseOfferingService;
97 }
98
99 public TermResolver<List<String>> getCluIdsTermResolver() {
100 return cluIdsTermResolver;
101 }
102
103 public void setCluIdsTermResolver(TermResolver<List<String>> cluIdsTermResolver) {
104 this.cluIdsTermResolver = cluIdsTermResolver;
105 }
106 }