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.ActivityOffering;
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.core.scheduling.constants.SchedulingServiceConstants;
31 import org.kuali.student.r2.core.scheduling.dto.ScheduleComponentInfo;
32 import org.kuali.student.r2.core.scheduling.dto.ScheduleInfo;
33 import org.kuali.student.r2.core.scheduling.dto.TimeSlotInfo;
34 import org.kuali.student.r2.core.scheduling.service.SchedulingService;
35 import org.kuali.student.r2.core.scheduling.util.SchedulingServiceUtil;
36
37 import java.util.Calendar;
38 import java.util.Collections;
39 import java.util.HashSet;
40 import java.util.List;
41 import java.util.Map;
42 import java.util.Set;
43
44
45
46
47
48
49
50
51
52
53 public class MatchingTimeSlotTermResolver implements TermResolver<Boolean> {
54
55 private CourseOfferingService courseOfferingService;
56 private SchedulingService schedulingService;
57
58 @Override
59 public Set<String> getPrerequisites() {
60 Set<String> prereqs = new HashSet<String>(2);
61 prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_AO_ID);
62 prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
63 return Collections.unmodifiableSet(prereqs);
64 }
65
66 @Override
67 public String getOutput() {
68 return KSKRMSServiceConstants.TERM_RESOLVER_MATCHINGTIMESLOT;
69 }
70
71 @Override
72 public Set<String> getParameterNames() {
73 Set<String> temp = new HashSet<String>(3);
74 temp.add(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_TIMESLOT_WEEKDAY_STRING);
75 temp.add(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_TIMESLOT_START);
76 temp.add(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_TIMESLOT_END);
77 return Collections.unmodifiableSet(temp);
78 }
79
80 @Override
81 public int getCost() {
82 return 5;
83 }
84
85 @Override
86 public Boolean resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
87 ContextInfo context = (ContextInfo) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
88
89 String weekdays = parameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_TIMESLOT_WEEKDAY_STRING);
90 String startTime = parameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_TIMESLOT_START);
91
92 try {
93 ActivityOffering ao = this.retrieveActivityOffering(resolvedPrereqs, context);
94 List<ScheduleInfo> schedules = this.getSchedulingService().getSchedulesByIds(ao.getScheduleIds(), context);
95 for(ScheduleInfo schedule : schedules){
96 for(ScheduleComponentInfo scheduleComponent : schedule.getScheduleComponents()){
97 List<TimeSlotInfo> timeSlots = this.getSchedulingService().getTimeSlotsByIds(scheduleComponent.getTimeSlotIds(), context);
98 for(TimeSlotInfo timeSlot : timeSlots){
99 if(weekdays.equals(SchedulingServiceUtil.weekdaysList2WeekdaysString(timeSlot.getWeekdays()))
100 && Long.valueOf(startTime).equals(timeSlot.getStartTime().getMilliSeconds())){
101 return true;
102 }
103 }
104 }
105 }
106
107
108 } catch (Exception e) {
109 KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this);
110 }
111
112 return false;
113 }
114
115 private ActivityOffering retrieveActivityOffering(Map<String, Object> resolvedPrereqs, ContextInfo context)
116 throws PermissionDeniedException, MissingParameterException, InvalidParameterException, OperationFailedException,
117 DoesNotExistException {
118
119 ActivityOffering ao = (ActivityOffering) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_AO);
120 if(ao == null){
121 String aoId = (String) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_AO_ID);
122 ao = this.getCourseOfferingService().getActivityOffering(aoId, context);
123 resolvedPrereqs.put(KSKRMSServiceConstants.TERM_PREREQUISITE_AO, ao);
124 }
125
126 return ao;
127 }
128
129 public CourseOfferingService getCourseOfferingService() {
130 return courseOfferingService;
131 }
132
133 public void setCourseOfferingService(CourseOfferingService courseOfferingService) {
134 this.courseOfferingService = courseOfferingService;
135 }
136
137 public SchedulingService getSchedulingService() {
138 return schedulingService;
139 }
140
141 public void setSchedulingService(SchedulingService schedulingService) {
142 this.schedulingService = schedulingService;
143 }
144 }