1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.student.r2.core.class1.scheduling.service.impl; |
18 | |
|
19 | |
import org.kuali.student.r2.common.constants.CommonServiceConstants; |
20 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
21 | |
import org.kuali.student.r2.common.dto.TimeOfDayInfo; |
22 | |
import org.kuali.student.r2.common.exceptions.*; |
23 | |
import org.kuali.student.r2.core.scheduling.constants.SchedulingServiceConstants; |
24 | |
import org.kuali.student.r2.core.scheduling.dto.TimeSlotInfo; |
25 | |
import org.kuali.student.r2.core.scheduling.infc.TimeSlot; |
26 | |
import org.kuali.student.r2.core.scheduling.service.SchedulingService; |
27 | |
|
28 | |
import java.util.ArrayList; |
29 | |
import java.util.Calendar; |
30 | |
import java.util.Date; |
31 | |
import java.util.List; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class SchedulingServiceDataLoader { |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public final static Long START_TIME_MILLIS_8_00_AM = new Long(8 * 60 * 60 * 1000); |
45 | 0 | public final static Long START_TIME_MILLIS_10_00_AM = new Long(10 * 60 * 60 * 1000); |
46 | 0 | public final static Long START_TIME_MILLIS_1_00_PM = new Long(13 * 60 * 60 * 1000); |
47 | 0 | public final static Long START_TIME_MILLIS_3_00_PM = new Long(15 * 60 * 60 * 1000); |
48 | |
|
49 | 0 | public final static Long END_TIME_MILLIS_8_50_AM = new Long(8 * 60 * 60 * 1000 + 50 * 60 * 1000); |
50 | 0 | public final static Long END_TIME_MILLIS_9_10_AM = new Long(8 * 60 * 60 * 1000 + 70 * 60 * 1000); |
51 | 0 | public final static Long END_TIME_MILLIS_10_50_AM = new Long(10 * 60 * 60 * 1000 + 50 * 60 * 1000); |
52 | 0 | public final static Long END_TIME_MILLIS_11_10_AM = new Long(10 * 60 * 60 * 1000 + 70 * 60 * 1000); |
53 | 0 | public final static Long END_TIME_MILLIS_1_50_PM = new Long(13 * 60 * 60 * 1000 + 50 * 60 * 1000); |
54 | 0 | public final static Long END_TIME_MILLIS_2_10_PM = new Long(13 * 60 * 60 * 1000 + 70 * 60 * 1000); |
55 | 0 | public final static Long END_TIME_MILLIS_3_50_PM = new Long(15 * 60 * 60 * 1000 + 50 * 60 * 1000); |
56 | 0 | public final static Long END_TIME_MILLIS_4_10_PM = new Long(15 * 60 * 60 * 1000 + 70 * 60 * 1000); |
57 | |
|
58 | 0 | public SchedulingServiceDataLoader() { |
59 | 0 | } |
60 | |
|
61 | 0 | public SchedulingServiceDataLoader (SchedulingService schedulingService) { |
62 | 0 | this.schedulingService = schedulingService; |
63 | 0 | } |
64 | |
|
65 | |
public SchedulingService getSchedulingService() { |
66 | 0 | return schedulingService; |
67 | |
} |
68 | |
|
69 | |
public void setSchedulingService(SchedulingService schedulingService) { |
70 | 0 | this.schedulingService = schedulingService; |
71 | 0 | } |
72 | |
private SchedulingService schedulingService; |
73 | 0 | private static String principalId = SchedulingServiceDataLoader.class.getSimpleName(); |
74 | |
|
75 | |
public void loadData () |
76 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, |
77 | |
OperationFailedException, PermissionDeniedException, ReadOnlyException { |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | 0 | List<Integer> DOW_M_W_F= new ArrayList<Integer>(); |
84 | 0 | DOW_M_W_F.add(Calendar.MONDAY); |
85 | 0 | DOW_M_W_F.add(Calendar.WEDNESDAY); |
86 | 0 | DOW_M_W_F.add(Calendar.FRIDAY); |
87 | |
|
88 | 0 | List<Integer> DOW_T_TH = new ArrayList<Integer>(); |
89 | 0 | DOW_T_TH.add(Calendar.TUESDAY); |
90 | 0 | DOW_T_TH.add(Calendar.THURSDAY); |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | 0 | loadTimeSlotInfo("1", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_M_W_F, START_TIME_MILLIS_8_00_AM, END_TIME_MILLIS_8_50_AM); |
96 | 0 | loadTimeSlotInfo("2", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_M_W_F, START_TIME_MILLIS_8_00_AM, END_TIME_MILLIS_9_10_AM); |
97 | 0 | loadTimeSlotInfo("3", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_T_TH, START_TIME_MILLIS_8_00_AM, END_TIME_MILLIS_8_50_AM); |
98 | 0 | loadTimeSlotInfo("4", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_T_TH, START_TIME_MILLIS_8_00_AM, END_TIME_MILLIS_9_10_AM); |
99 | 0 | loadTimeSlotInfo("5", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_M_W_F, START_TIME_MILLIS_10_00_AM, END_TIME_MILLIS_10_50_AM); |
100 | 0 | loadTimeSlotInfo("6", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_M_W_F, START_TIME_MILLIS_10_00_AM, END_TIME_MILLIS_11_10_AM); |
101 | 0 | loadTimeSlotInfo("7", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_T_TH, START_TIME_MILLIS_10_00_AM, END_TIME_MILLIS_10_50_AM); |
102 | 0 | loadTimeSlotInfo("8", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_T_TH, START_TIME_MILLIS_10_00_AM, END_TIME_MILLIS_11_10_AM); |
103 | 0 | loadTimeSlotInfo("9", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_M_W_F, START_TIME_MILLIS_1_00_PM, END_TIME_MILLIS_1_50_PM); |
104 | 0 | loadTimeSlotInfo("10", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_M_W_F, START_TIME_MILLIS_1_00_PM, END_TIME_MILLIS_2_10_PM); |
105 | 0 | loadTimeSlotInfo("11", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_T_TH, START_TIME_MILLIS_1_00_PM, END_TIME_MILLIS_1_50_PM); |
106 | 0 | loadTimeSlotInfo("12", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_T_TH, START_TIME_MILLIS_1_00_PM, END_TIME_MILLIS_2_10_PM); |
107 | 0 | loadTimeSlotInfo("13", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_M_W_F, START_TIME_MILLIS_3_00_PM, END_TIME_MILLIS_3_50_PM); |
108 | 0 | loadTimeSlotInfo("14", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_M_W_F, START_TIME_MILLIS_3_00_PM, END_TIME_MILLIS_4_10_PM); |
109 | 0 | loadTimeSlotInfo("15", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_T_TH, START_TIME_MILLIS_3_00_PM, END_TIME_MILLIS_3_50_PM); |
110 | 0 | loadTimeSlotInfo("16", SchedulingServiceConstants.TIME_SLOT_STATE_STANDARD_KEY, SchedulingServiceConstants.TIME_SLOT_TYPE_ACTIVITY_OFFERING_KEY, DOW_T_TH, START_TIME_MILLIS_3_00_PM, END_TIME_MILLIS_4_10_PM); |
111 | 0 | } |
112 | |
|
113 | |
private void loadTimeSlotInfo (String ts_id, String stateKey, String typeKey, List<Integer> weekdays, Long startTimeInMillisecs, Long endTimeInMillisecs) |
114 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, |
115 | |
OperationFailedException, PermissionDeniedException, ReadOnlyException { |
116 | 0 | TimeSlotInfo ts = new TimeSlotInfo(); |
117 | 0 | ts.setId(ts_id); |
118 | 0 | ts.setWeekdays(weekdays); |
119 | 0 | TimeOfDayInfo startTime = new TimeOfDayInfo(); |
120 | 0 | startTime.setMilliSeconds(startTimeInMillisecs); |
121 | 0 | ts.setStartTime(startTime); |
122 | 0 | TimeOfDayInfo endTime = new TimeOfDayInfo(); |
123 | 0 | endTime.setMilliSeconds(endTimeInMillisecs); |
124 | 0 | ts.setEndTime(endTime); |
125 | 0 | ts.setStateKey(stateKey); |
126 | 0 | ts.setTypeKey(typeKey); |
127 | 0 | ContextInfo contextInfo = new ContextInfo(); |
128 | 0 | contextInfo.setPrincipalId(principalId); |
129 | 0 | contextInfo.setCurrentDate(new Date()); |
130 | 0 | CommonServiceConstants.setIsIdAllowedOnCreate(contextInfo, true); |
131 | 0 | schedulingService.createTimeSlot(typeKey, ts, contextInfo); |
132 | 0 | } |
133 | |
|
134 | |
public static String ts2Str (TimeSlot ts) { |
135 | 0 | String toRet = ts.getId() + ", "; |
136 | 0 | for (Integer day : ts.getWeekdays()) { |
137 | 0 | switch (day) { |
138 | |
case Calendar.MONDAY: |
139 | 0 | toRet += "M"; |
140 | 0 | break; |
141 | |
case Calendar.TUESDAY: |
142 | 0 | toRet += "T"; |
143 | 0 | break; |
144 | |
case Calendar.WEDNESDAY: |
145 | 0 | toRet += "W"; |
146 | 0 | break; |
147 | |
case Calendar.THURSDAY: |
148 | 0 | toRet += "TH"; |
149 | 0 | break; |
150 | |
case Calendar.FRIDAY: |
151 | 0 | toRet += "F"; |
152 | 0 | break; |
153 | |
case Calendar.SATURDAY: |
154 | 0 | toRet += "SA"; |
155 | 0 | break; |
156 | |
case Calendar.SUNDAY: |
157 | 0 | toRet += "SU"; |
158 | 0 | break; |
159 | |
default: |
160 | |
} |
161 | 0 | toRet += " "; |
162 | |
} |
163 | 0 | toRet += ", " + ts.getStartTime().getMilliSeconds() + ", " + ts.getEndTime().getMilliSeconds(); |
164 | 0 | return toRet; |
165 | |
} |
166 | |
} |