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 | 0 | public class EnrolledCoursesResolver implements TermResolver<Collection<String>> { |
26 | |
|
27 | |
private CourseRegistrationService courseRegService; |
28 | |
|
29 | 0 | private final static Set<String> prerequisites = new HashSet<String>(2); |
30 | |
|
31 | |
static { |
32 | 0 | prerequisites.add(RulesExecutionConstants.STUDENT_ID_TERM_NAME); |
33 | 0 | prerequisites.add(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME); |
34 | 0 | } |
35 | |
|
36 | |
@Override |
37 | |
public Set<String> getPrerequisites() { |
38 | 0 | return prerequisites; |
39 | |
} |
40 | |
|
41 | |
@Override |
42 | |
public String getOutput() { |
43 | 0 | return RulesExecutionConstants.STUDENT_ENROLLED_COURSE_IDS_TERM_NAME; |
44 | |
} |
45 | |
|
46 | |
@Override |
47 | |
public Set<String> getParameterNames() { |
48 | 0 | return Collections.emptySet(); |
49 | |
} |
50 | |
|
51 | |
@Override |
52 | |
public int getCost() { |
53 | |
|
54 | 0 | return 0; |
55 | |
} |
56 | |
|
57 | |
@Override |
58 | |
public Collection<String> resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException { |
59 | 0 | String studentId = resolvedPrereqs.get(RulesExecutionConstants.STUDENT_ID_TERM_NAME).toString(); |
60 | 0 | ContextInfo context = (ContextInfo) resolvedPrereqs.get(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME); |
61 | |
|
62 | 0 | Collection<String> results = null; |
63 | |
|
64 | |
try { |
65 | 0 | List<CourseRegistrationInfo> registrations = courseRegService.getCourseRegistrationsByStudent(studentId, context); |
66 | |
|
67 | 0 | results = new ArrayList<String>(registrations.size()); |
68 | |
|
69 | 0 | for (CourseRegistrationInfo courseRegInfo : registrations) { |
70 | 0 | if (courseRegInfo.getCourseOfferingId() != null) { |
71 | 0 | results.add(courseRegInfo.getCourseOfferingId()); |
72 | |
} |
73 | |
} |
74 | 0 | } catch (InvalidParameterException e) { |
75 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters, e); |
76 | 0 | } catch (MissingParameterException e) { |
77 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters, e); |
78 | 0 | } catch (OperationFailedException e) { |
79 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters, e); |
80 | 0 | } catch (PermissionDeniedException e) { |
81 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters, e); |
82 | 0 | } |
83 | |
|
84 | 0 | return results; |
85 | |
} |
86 | |
} |