1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.examoffering.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.courseoffering.infc.CourseOffering;
21 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
22 import org.kuali.student.r2.common.dto.ContextInfo;
23 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
24 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
25 import org.kuali.student.r2.common.exceptions.MissingParameterException;
26 import org.kuali.student.r2.common.exceptions.OperationFailedException;
27 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
28 import org.kuali.student.r2.common.krms.util.KSKRMSExecutionUtil;
29 import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
30 import org.kuali.student.r2.lum.course.infc.Course;
31 import org.kuali.student.r2.lum.course.service.CourseService;
32
33 import java.util.Collections;
34 import java.util.HashSet;
35 import java.util.Map;
36 import java.util.Set;
37
38
39
40
41
42
43
44
45
46 public class MatchingCourseTermResolver implements TermResolver<Boolean> {
47
48 private CourseOfferingService courseOfferingService;
49 private CourseService courseService;
50
51 @Override
52 public Set<String> getPrerequisites() {
53 Set<String> prereqs = new HashSet<String>(2);
54 prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CO_ID);
55 prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
56 return Collections.unmodifiableSet(prereqs);
57 }
58
59 @Override
60 public String getOutput() {
61 return KSKRMSServiceConstants.TERM_RESOLVER_MATCHINGCOURSE;
62 }
63
64 @Override
65 public Set<String> getParameterNames() {
66 Set<String> temp = new HashSet<String>(3);
67 temp.add(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLU_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
80 String courseId = parameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLU_KEY);
81
82 try {
83 CourseOffering co = this.retrieveCourseOffering(resolvedPrereqs, context);
84 Course course = this.getCourseService().getCourse(co.getCourseId(), context);
85
86 if(courseId.equals(course.getVersion().getVersionIndId())){
87 return true;
88 }
89
90 } catch (Exception e) {
91 KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this);
92 }
93
94 return false;
95 }
96
97 private CourseOffering retrieveCourseOffering(Map<String, Object> resolvedPrereqs, ContextInfo context)
98 throws PermissionDeniedException, MissingParameterException, InvalidParameterException, OperationFailedException,
99 DoesNotExistException {
100
101 CourseOffering co = (CourseOffering) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_CO);
102 if(co == null){
103 String coId = (String) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_CO_ID);
104 co = this.getCourseOfferingService().getCourseOffering(coId, context);
105 resolvedPrereqs.put(KSKRMSServiceConstants.TERM_PREREQUISITE_CO, co);
106 }
107
108 return co;
109 }
110
111 public CourseOfferingService getCourseOfferingService() {
112 return courseOfferingService;
113 }
114
115 public void setCourseOfferingService(CourseOfferingService courseOfferingService) {
116 this.courseOfferingService = courseOfferingService;
117 }
118
119 public CourseService getCourseService() {
120 return courseService;
121 }
122
123 public void setCourseService(CourseService courseService) {
124 this.courseService = courseService;
125 }
126 }