1 package org.kuali.student.enrollment.class2.courseregistration.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.common.util.krms.RulesExecutionConstants;
6 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
7 import org.kuali.student.enrollment.courseregistration.dto.CourseRegistrationInfo;
8 import org.kuali.student.enrollment.courseregistration.service.CourseRegistrationService;
9 import org.kuali.student.r2.common.dto.ContextInfo;
10 import org.kuali.student.r2.common.exceptions.DisabledIdentifierException;
11 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
12 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
13 import org.kuali.student.r2.common.exceptions.MissingParameterException;
14 import org.kuali.student.r2.common.exceptions.OperationFailedException;
15 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
16
17 import java.util.ArrayList;
18 import java.util.Collection;
19 import java.util.Collections;
20 import java.util.HashSet;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.Set;
24
25 public class EnrolledCoursesResolver implements TermResolver<Collection<String>> {
26
27 private CourseRegistrationService courseRegService;
28
29 private final static Set<String> prerequisites = new HashSet<String>(2);
30
31 static {
32 prerequisites.add(RulesExecutionConstants.STUDENT_ID_TERM_NAME);
33 prerequisites.add(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME);
34 }
35
36 @Override
37 public Set<String> getPrerequisites() {
38 return prerequisites;
39 }
40
41 @Override
42 public String getOutput() {
43 return RulesExecutionConstants.STUDENT_ENROLLED_COURSE_IDS_TERM_NAME;
44 }
45
46 @Override
47 public Set<String> getParameterNames() {
48 return Collections.emptySet();
49 }
50
51 @Override
52 public int getCost() {
53
54 return 0;
55 }
56
57 @Override
58 public Collection<String> resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
59 String studentId = resolvedPrereqs.get(RulesExecutionConstants.STUDENT_ID_TERM_NAME).toString();
60 ContextInfo context = (ContextInfo) resolvedPrereqs.get(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME);
61
62 Collection<String> results = null;
63
64 try {
65 List<CourseRegistrationInfo> registrations = courseRegService.getCourseRegistrationsByStudent(studentId, context);
66
67 results = new ArrayList<String>(registrations.size());
68
69 for (CourseRegistrationInfo courseRegInfo : registrations) {
70 if (courseRegInfo.getCourseOfferingId() != null) {
71 results.add(courseRegInfo.getCourseOfferingId());
72 }
73 }
74 } catch (InvalidParameterException e) {
75 throw new TermResolutionException(e.getMessage(), this, parameters, e);
76 } catch (MissingParameterException e) {
77 throw new TermResolutionException(e.getMessage(), this, parameters, e);
78 } catch (OperationFailedException e) {
79 throw new TermResolutionException(e.getMessage(), this, parameters, e);
80 } catch (PermissionDeniedException e) {
81 throw new TermResolutionException(e.getMessage(), this, parameters, e);
82 }
83
84 return results;
85 }
86 }