1 | |
package org.kuali.student.enrollment.class2.acal.service; |
2 | |
|
3 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
4 | |
import org.kuali.rice.krad.maintenance.MaintainableImpl; |
5 | |
import org.kuali.rice.krad.maintenance.MaintenanceDocument; |
6 | |
import org.kuali.rice.krad.util.KRADConstants; |
7 | |
import org.kuali.student.enrollment.acal.dto.AcademicCalendarInfo; |
8 | |
import org.kuali.student.enrollment.acal.dto.KeyDateInfo; |
9 | |
import org.kuali.student.enrollment.acal.dto.TermInfo; |
10 | |
import org.kuali.student.enrollment.acal.service.AcademicCalendarService; |
11 | |
import org.kuali.student.enrollment.class2.acal.dto.AcademicCalendarWrapper; |
12 | |
import org.kuali.student.enrollment.class2.acal.dto.TermWrapper; |
13 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
14 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
15 | |
import org.kuali.student.r2.common.exceptions.*; |
16 | |
import org.kuali.student.r2.common.util.constants.AtpServiceConstants; |
17 | |
|
18 | |
import javax.xml.namespace.QName; |
19 | |
import java.util.*; |
20 | |
|
21 | |
|
22 | |
@Deprecated |
23 | 0 | public class AcademicCalendarWrapperMaintainableImpl extends MaintainableImpl { |
24 | |
private static final long serialVersionUID = 1L; |
25 | |
|
26 | |
private static final String DEFAULT_DOCUMENT_DESC_FOR_CREATING_ACADEMIC_CALENDAR = |
27 | |
"New academic calendar"; |
28 | |
private static final String DEFAULT_DOCUMENT_DESC_FOR_EDITING_ACADEMIC_CALENDAR = |
29 | |
"Edit academic calendar"; |
30 | |
private static final String DEFAULT_DOCUMENT_DESC_FOR_COPYING_ACADEMIC_CALENDAR = |
31 | |
"Copy academic calendar"; |
32 | |
|
33 | |
public final static String ACADEMIC_CALENDAR_KEY_PREFIX = "kuali.academic.calendar."; |
34 | |
public final static String CREDENTIAL_PROGRAM_TYPE_KEY_PREFIX = "kuali.lu.type.credential."; |
35 | |
|
36 | |
public final static String TERM_KEY_PREFIX = "kuali.term."; |
37 | |
|
38 | |
public final static String TERM_TYPE_KEY_PREFIX = "kuali.atp.type."; |
39 | |
public final static String MILESTONE_TYPE_KEY_PREFIX = "kuali.atp.milestone."; |
40 | |
public final static String KEY_DATE_INFO_KEY_PREFIX = "kuali.milestone."; |
41 | |
|
42 | |
private transient AcademicCalendarService academicCalendarService; |
43 | |
|
44 | |
|
45 | |
@Override |
46 | |
public void saveDataObject() { |
47 | 0 | academicCalendarService = getAcademicCalendarService(); |
48 | 0 | ContextInfo context = new ContextInfo(); |
49 | |
|
50 | 0 | AcademicCalendarWrapper academicCalendarWrapper = (AcademicCalendarWrapper)getDataObject(); |
51 | |
|
52 | |
|
53 | |
try{ |
54 | 0 | if(getMaintenanceAction().equals(KRADConstants.MAINTENANCE_NEW_ACTION) || |
55 | |
getMaintenanceAction().equals(KRADConstants.MAINTENANCE_COPY_ACTION)) { |
56 | |
|
57 | |
|
58 | |
|
59 | 0 | AcademicCalendarInfo academicCalendarInfo = academicCalendarWrapper.getAcademicCalendarInfo(); |
60 | |
|
61 | 0 | if (getMaintenanceAction().equals(KRADConstants.MAINTENANCE_COPY_ACTION)) { |
62 | 0 | List<AttributeInfo> attributes = academicCalendarInfo.getAttributes(); |
63 | 0 | List<AttributeInfo> newAttributes = new ArrayList(); |
64 | 0 | for (AttributeInfo attribute:attributes) { |
65 | 0 | if (attribute.getId().equals("CredentialProgramType")) { |
66 | 0 | attribute.setId(null); |
67 | |
} |
68 | 0 | newAttributes.add(attribute); |
69 | |
} |
70 | 0 | academicCalendarInfo.setAttributes(newAttributes); |
71 | |
} |
72 | |
|
73 | 0 | String academicCalendarKey = getAcademicCalendarKey (academicCalendarInfo); |
74 | 0 | academicCalendarInfo.setId(academicCalendarKey); |
75 | 0 | academicCalendarInfo.setStateKey(AtpServiceConstants.ATP_OFFICIAL_STATE_KEY); |
76 | 0 | academicCalendarService.createAcademicCalendar(academicCalendarKey, academicCalendarInfo, context); |
77 | |
|
78 | |
|
79 | 0 | List<TermWrapper> termWrapperList = academicCalendarWrapper.getTermWrapperList(); |
80 | 0 | for(TermWrapper termWrapper:termWrapperList){ |
81 | |
|
82 | 0 | TermInfo termInfo = termWrapper.getTermInfo(); |
83 | 0 | String termName = getTermInfoName(termInfo); |
84 | 0 | termInfo.setName(termName); |
85 | 0 | termInfo.setStateKey(AtpServiceConstants.ATP_OFFICIAL_STATE_KEY); |
86 | |
|
87 | |
|
88 | 0 | KeyDateInfo classesMeetDates = termWrapper.getClassesMeetDates(); |
89 | 0 | classesMeetDates.setStateKey(AtpServiceConstants.MILESTONE_OFFICIAL_STATE_KEY); |
90 | 0 | classesMeetDates.setTypeKey(AtpServiceConstants.MILESTONE_INSTRUCTIONAL_PERIOD_TYPE_KEY); |
91 | 0 | String classesMeetDatesKey = getKeyDateInfoKey(classesMeetDates); |
92 | 0 | classesMeetDates.setId(classesMeetDatesKey); |
93 | |
|
94 | |
|
95 | 0 | KeyDateInfo registrationPeriod = termWrapper.getRegistrationPeriod(); |
96 | 0 | registrationPeriod.setStateKey(AtpServiceConstants.MILESTONE_OFFICIAL_STATE_KEY); |
97 | 0 | registrationPeriod.setTypeKey(AtpServiceConstants.MILESTONE_REGISTRATION_PERIOD_TYPE_KEY); |
98 | 0 | String registrationPeriodKey = getKeyDateInfoKey(registrationPeriod); |
99 | 0 | registrationPeriod.setId(registrationPeriodKey); |
100 | |
|
101 | |
|
102 | 0 | KeyDateInfo dropPeriodEndsDate = termWrapper.getDropPeriodEndsDate(); |
103 | 0 | dropPeriodEndsDate.setStateKey(AtpServiceConstants.MILESTONE_OFFICIAL_STATE_KEY); |
104 | 0 | dropPeriodEndsDate.setTypeKey(AtpServiceConstants.MILESTONE_DROP_DATE_TYPE_KEY); |
105 | 0 | String dropPeriodEndsDateKey = getKeyDateInfoKey(dropPeriodEndsDate); |
106 | 0 | dropPeriodEndsDate.setId(dropPeriodEndsDateKey); |
107 | |
|
108 | |
|
109 | 0 | KeyDateInfo finalExaminationsDates = termWrapper.getFinalExaminationsDates(); |
110 | 0 | finalExaminationsDates.setStateKey(AtpServiceConstants.MILESTONE_OFFICIAL_STATE_KEY); |
111 | 0 | finalExaminationsDates.setTypeKey(AtpServiceConstants.MILESTONE_FINAL_EXAM_PERIOD_TYPE_KEY); |
112 | 0 | String finalExaminationsDatesKey = getKeyDateInfoKey(finalExaminationsDates); |
113 | 0 | finalExaminationsDates.setId(finalExaminationsDatesKey); |
114 | |
|
115 | |
|
116 | 0 | KeyDateInfo gradesDueDate = termWrapper.getGradesDueDate(); |
117 | 0 | gradesDueDate.setStateKey(AtpServiceConstants.MILESTONE_OFFICIAL_STATE_KEY); |
118 | 0 | gradesDueDate.setTypeKey(AtpServiceConstants.MILESTONE_GRADES_DUE_TYPE_KEY); |
119 | 0 | String gradesDueDateKey = getKeyDateInfoKey(gradesDueDate); |
120 | 0 | gradesDueDate.setId(gradesDueDateKey); |
121 | |
|
122 | |
|
123 | 0 | termInfo = academicCalendarService.createTerm(termInfo.getTypeKey(), termInfo, context); |
124 | 0 | academicCalendarService.createKeyDate(termInfo.getId(), classesMeetDatesKey, classesMeetDates, context); |
125 | 0 | academicCalendarService.createKeyDate(termInfo.getId(), registrationPeriodKey, registrationPeriod, context); |
126 | 0 | academicCalendarService.createKeyDate(termInfo.getId(), dropPeriodEndsDateKey, dropPeriodEndsDate, context); |
127 | 0 | academicCalendarService.createKeyDate(termInfo.getId(), finalExaminationsDatesKey, finalExaminationsDates, context); |
128 | 0 | academicCalendarService.createKeyDate(termInfo.getId(), gradesDueDateKey, gradesDueDate, context); |
129 | |
|
130 | |
|
131 | 0 | academicCalendarService.addTermToAcademicCalendar(academicCalendarKey, termInfo.getId(), context); |
132 | 0 | } |
133 | 0 | } |
134 | |
else { |
135 | |
|
136 | 0 | AcademicCalendarInfo academicCalendarInfo = academicCalendarWrapper.getAcademicCalendarInfo(); |
137 | 0 | academicCalendarService.updateAcademicCalendar(academicCalendarInfo.getId(), academicCalendarInfo, context); |
138 | |
|
139 | 0 | List<TermWrapper> termWrapperList = academicCalendarWrapper.getTermWrapperList(); |
140 | 0 | for(TermWrapper termWrapper:termWrapperList){ |
141 | |
|
142 | 0 | TermInfo termInfo = termWrapper.getTermInfo(); |
143 | 0 | KeyDateInfo classesMeetDates = termWrapper.getClassesMeetDates(); |
144 | 0 | KeyDateInfo registrationPeriod = termWrapper.getRegistrationPeriod(); |
145 | 0 | KeyDateInfo dropPeriodEndsDate = termWrapper.getDropPeriodEndsDate(); |
146 | 0 | KeyDateInfo finalExaminationsDates = termWrapper.getFinalExaminationsDates(); |
147 | 0 | KeyDateInfo gradesDueDate = termWrapper.getGradesDueDate(); |
148 | |
|
149 | |
|
150 | 0 | academicCalendarService.updateTerm(termInfo.getId(), termInfo, context); |
151 | 0 | academicCalendarService.updateKeyDate(classesMeetDates.getId(), classesMeetDates, context); |
152 | 0 | academicCalendarService.updateKeyDate(registrationPeriod.getId(), registrationPeriod, context); |
153 | 0 | academicCalendarService.updateKeyDate(dropPeriodEndsDate.getId(), dropPeriodEndsDate, context); |
154 | 0 | academicCalendarService.updateKeyDate(finalExaminationsDates.getId(), finalExaminationsDates, context); |
155 | 0 | academicCalendarService.updateKeyDate(gradesDueDate.getId(), gradesDueDate, context); |
156 | |
|
157 | |
|
158 | |
|
159 | 0 | } |
160 | |
} |
161 | 0 | }catch (AlreadyExistsException aee){ |
162 | |
|
163 | |
|
164 | 0 | }catch (DataValidationErrorException dvee){ |
165 | |
|
166 | 0 | }catch (InvalidParameterException ipe){ |
167 | |
|
168 | 0 | }catch (MissingParameterException mpe){ |
169 | |
|
170 | 0 | }catch (OperationFailedException ofe){ |
171 | |
|
172 | 0 | }catch (PermissionDeniedException pde){ |
173 | |
|
174 | 0 | }catch (ReadOnlyException roe){ |
175 | |
|
176 | 0 | }catch (DoesNotExistException dee){ |
177 | |
|
178 | 0 | }catch (VersionMismatchException vme){ |
179 | |
|
180 | 0 | } |
181 | |
|
182 | 0 | } |
183 | |
|
184 | |
@Override |
185 | |
public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) { |
186 | 0 | ContextInfo context = new ContextInfo(); |
187 | 0 | academicCalendarService = getAcademicCalendarService(); |
188 | 0 | AcademicCalendarWrapper academicCalendarWrapper = new AcademicCalendarWrapper(); |
189 | |
try{ |
190 | |
|
191 | 0 | AcademicCalendarInfo academicCalendarInfo = academicCalendarService.getAcademicCalendar(dataObjectKeys.get("key"), context); |
192 | 0 | academicCalendarWrapper.setAcademicCalendarInfo(academicCalendarInfo); |
193 | |
|
194 | 0 | List<TermWrapper> termWrapperList = new ArrayList<TermWrapper>(); |
195 | 0 | List<TermInfo> termInfoList = academicCalendarService.getTermsForAcademicCalendar(dataObjectKeys.get("key"), context); |
196 | 0 | for (TermInfo termInfo:termInfoList){ |
197 | 0 | TermWrapper termWrapper = new TermWrapper(); |
198 | 0 | termWrapper.setTermInfo(termInfo); |
199 | 0 | List<KeyDateInfo> keyDateInfoList = academicCalendarService.getKeyDatesForTerm(termInfo.getId(), context); |
200 | 0 | for (KeyDateInfo keyDateInfo : keyDateInfoList){ |
201 | 0 | if(AtpServiceConstants.MILESTONE_INSTRUCTIONAL_PERIOD_TYPE_KEY.equals(keyDateInfo.getTypeKey())){ |
202 | 0 | termWrapper.setClassesMeetDates(keyDateInfo); |
203 | |
} |
204 | 0 | else if(AtpServiceConstants.MILESTONE_REGISTRATION_PERIOD_TYPE_KEY.equals(keyDateInfo.getTypeKey())){ |
205 | 0 | termWrapper.setRegistrationPeriod(keyDateInfo); |
206 | |
} |
207 | 0 | else if(AtpServiceConstants.MILESTONE_DROP_DATE_TYPE_KEY.equals(keyDateInfo.getTypeKey())){ |
208 | 0 | termWrapper.setDropPeriodEndsDate(keyDateInfo); |
209 | |
} |
210 | 0 | else if(AtpServiceConstants.MILESTONE_FINAL_EXAM_PERIOD_TYPE_KEY.equals(keyDateInfo.getTypeKey())){ |
211 | 0 | termWrapper.setFinalExaminationsDates(keyDateInfo); |
212 | |
} |
213 | 0 | else if(AtpServiceConstants.MILESTONE_GRADES_DUE_TYPE_KEY.equals(keyDateInfo.getTypeKey())){ |
214 | 0 | termWrapper.setGradesDueDate(keyDateInfo); |
215 | |
} |
216 | |
|
217 | |
} |
218 | 0 | termWrapperList.add(termWrapper); |
219 | 0 | } |
220 | 0 | academicCalendarWrapper.setTermWrapperList(termWrapperList); |
221 | 0 | return academicCalendarWrapper; |
222 | |
|
223 | 0 | }catch (InvalidParameterException ipe){ |
224 | |
|
225 | 0 | }catch (MissingParameterException mpe){ |
226 | |
|
227 | 0 | }catch (OperationFailedException ofe){ |
228 | |
|
229 | 0 | }catch (PermissionDeniedException pde){ |
230 | |
|
231 | 0 | }catch (DoesNotExistException dee){ |
232 | |
|
233 | 0 | } |
234 | 0 | return null; |
235 | |
|
236 | |
} |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
@Override |
263 | |
public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> requestParameters) { |
264 | |
|
265 | 0 | document.getDocumentHeader().setDocumentDescription(DEFAULT_DOCUMENT_DESC_FOR_COPYING_ACADEMIC_CALENDAR); |
266 | 0 | } |
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
@Override |
272 | |
public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> requestParameters) { |
273 | |
|
274 | 0 | document.getDocumentHeader().setDocumentDescription(DEFAULT_DOCUMENT_DESC_FOR_EDITING_ACADEMIC_CALENDAR); |
275 | |
|
276 | 0 | } |
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
@Override |
282 | |
public void processAfterNew(MaintenanceDocument document, Map<String, String[]> requestParameters) { |
283 | |
|
284 | 0 | document.getDocumentHeader().setDocumentDescription(DEFAULT_DOCUMENT_DESC_FOR_CREATING_ACADEMIC_CALENDAR); |
285 | |
|
286 | 0 | } |
287 | |
|
288 | |
protected AcademicCalendarService getAcademicCalendarService() { |
289 | 0 | if(academicCalendarService == null) { |
290 | 0 | academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/acal","AcademicCalendarService")); |
291 | |
} |
292 | |
|
293 | 0 | return academicCalendarService; |
294 | |
} |
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
private String getAcademicCalendarKey(AcademicCalendarInfo academicCalendarInfo){ |
302 | 0 | String academicCalendarKey = new String (ACADEMIC_CALENDAR_KEY_PREFIX); |
303 | |
String credentialProgram; |
304 | |
|
305 | 0 | String adminOrgId = academicCalendarInfo.getAdminOrgId(); |
306 | |
|
307 | 0 | if (adminOrgId.startsWith(CREDENTIAL_PROGRAM_TYPE_KEY_PREFIX)){ |
308 | 0 | credentialProgram = adminOrgId.substring(25); |
309 | |
} |
310 | |
else { |
311 | 0 | credentialProgram = adminOrgId; |
312 | |
} |
313 | 0 | String yearOfStartDate = getYearFromDate(academicCalendarInfo.getStartDate()); |
314 | 0 | String yearOfEndDate = getYearFromDate(academicCalendarInfo.getEndDate()); |
315 | 0 | academicCalendarKey = academicCalendarKey.concat(credentialProgram+"."+yearOfStartDate+"-"+yearOfEndDate); |
316 | 0 | return academicCalendarKey.toLowerCase(); |
317 | |
|
318 | |
} |
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
private String getKeyDateInfoKey(KeyDateInfo keyDateInfo){ |
328 | 0 | String keyDateInfoKey = new String (KEY_DATE_INFO_KEY_PREFIX); |
329 | |
|
330 | |
String theKeyDateInfoType; |
331 | |
|
332 | 0 | String theKeyDateInfoTypeKey = keyDateInfo.getTypeKey(); |
333 | 0 | if (theKeyDateInfoTypeKey.startsWith(MILESTONE_TYPE_KEY_PREFIX)){ |
334 | 0 | theKeyDateInfoType = theKeyDateInfoTypeKey.substring(MILESTONE_TYPE_KEY_PREFIX.length()); |
335 | |
} |
336 | |
else { |
337 | 0 | theKeyDateInfoType = theKeyDateInfoTypeKey; |
338 | |
} |
339 | |
|
340 | 0 | return keyDateInfoKey.toLowerCase(); |
341 | |
|
342 | |
} |
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | |
private String getTermInfoName(TermInfo termInfo){ |
349 | |
String theType; |
350 | 0 | String theTypeKey = termInfo.getTypeKey(); |
351 | 0 | if (theTypeKey.startsWith(TERM_TYPE_KEY_PREFIX)){ |
352 | 0 | theType = theTypeKey.substring(15); |
353 | |
} |
354 | |
else { |
355 | 0 | theType = theTypeKey; |
356 | |
} |
357 | 0 | String yearOfStartDate = getYearFromDate(termInfo.getStartDate()); |
358 | 0 | String termName = new String (theType+" "+yearOfStartDate); |
359 | 0 | return termName; |
360 | |
} |
361 | |
|
362 | |
|
363 | |
private String getYearFromDate(Date date){ |
364 | 0 | Calendar cal = Calendar.getInstance(); |
365 | 0 | cal.setTime(date); |
366 | 0 | int year = cal.get(Calendar.YEAR); |
367 | 0 | return new Integer(year).toString(); |
368 | |
} |
369 | |
|
370 | |
} |