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