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.List;
36 import java.util.Map;
37 import java.util.Set;
38
39
40
41
42
43
44
45
46
47
48 public class MatchingCourseSetTermResolver implements TermResolver<Boolean> {
49
50 private CourseOfferingService courseOfferingService;
51 private CourseService courseService;
52 private TermResolver<List<String>> cluIdsInCluSetTermResolver;
53
54 @Override
55 public Set<String> getPrerequisites() {
56 Set<String> prereqs = new HashSet<String>(2);
57 prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CO_ID);
58 prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
59 return Collections.unmodifiableSet(prereqs);
60 }
61
62 @Override
63 public String getOutput() {
64 return KSKRMSServiceConstants.TERM_RESOLVER_MATCHINGCOURSESET;
65 }
66
67 @Override
68 public Set<String> getParameterNames() {
69 Set<String> temp = new HashSet<String>(3);
70 temp.add(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLUSET_KEY);
71 return Collections.unmodifiableSet(temp);
72 }
73
74 @Override
75 public int getCost() {
76 return 5;
77 }
78
79 @Override
80 public Boolean resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
81 ContextInfo context = (ContextInfo) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
82
83 try {
84 CourseOffering co = this.retrieveCourseOffering(resolvedPrereqs, context);
85 Course course = this.getCourseService().getCourse(co.getCourseId(), context);
86
87 List<String> versionIndIds = this.getCluIdsInCluSetTermResolver().resolve(resolvedPrereqs, parameters);
88 if(versionIndIds.contains(course.getVersion().getVersionIndId())){
89 return true;
90 }
91
92 } catch (Exception e) {
93 KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this);
94 }
95
96 return false;
97 }
98
99 private CourseOffering retrieveCourseOffering(Map<String, Object> resolvedPrereqs, ContextInfo context)
100 throws PermissionDeniedException, MissingParameterException, InvalidParameterException, OperationFailedException,
101 DoesNotExistException {
102
103 CourseOffering co = (CourseOffering) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_CO);
104 if(co == null){
105 String coId = (String) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_CO_ID);
106 co = this.getCourseOfferingService().getCourseOffering(coId, context);
107 resolvedPrereqs.put(KSKRMSServiceConstants.TERM_PREREQUISITE_CO, co);
108 }
109
110 return co;
111 }
112
113 public CourseOfferingService getCourseOfferingService() {
114 return courseOfferingService;
115 }
116
117 public void setCourseOfferingService(CourseOfferingService courseOfferingService) {
118 this.courseOfferingService = courseOfferingService;
119 }
120
121 public CourseService getCourseService() {
122 return courseService;
123 }
124
125 public void setCourseService(CourseService courseService) {
126 this.courseService = courseService;
127 }
128
129 public TermResolver<List<String>> getCluIdsInCluSetTermResolver() {
130 return cluIdsInCluSetTermResolver;
131 }
132
133 public void setCluIdsInCluSetTermResolver(TermResolver<List<String>> cluIdsInCluSetTermResolver) {
134 this.cluIdsInCluSetTermResolver = cluIdsInCluSetTermResolver;
135 }
136
137 }