| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.enrollment.class2.acal.controller; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.BooleanUtils; |
| 19 | |
import org.apache.commons.lang.StringUtils; |
| 20 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
| 21 | |
import org.kuali.rice.krad.uif.UifParameters; |
| 22 | |
import org.kuali.rice.krad.util.GlobalVariables; |
| 23 | |
import org.kuali.rice.krad.util.KRADConstants; |
| 24 | |
import org.kuali.rice.krad.util.UrlFactory; |
| 25 | |
import org.kuali.rice.krad.web.controller.UifControllerBase; |
| 26 | |
import org.kuali.rice.krad.web.form.UifFormBase; |
| 27 | |
import org.kuali.student.enrollment.acal.constants.AcademicCalendarServiceConstants; |
| 28 | |
import org.kuali.student.enrollment.acal.dto.AcademicCalendarInfo; |
| 29 | |
import org.kuali.student.enrollment.acal.dto.TermInfo; |
| 30 | |
import org.kuali.student.enrollment.acal.service.AcademicCalendarService; |
| 31 | |
import org.kuali.student.enrollment.class2.acal.dto.*; |
| 32 | |
import org.kuali.student.enrollment.class2.acal.form.AcademicCalendarForm; |
| 33 | |
import org.kuali.student.enrollment.class2.acal.util.CalendarConstants; |
| 34 | |
import org.kuali.student.r2.common.util.constants.AtpServiceConstants; |
| 35 | |
import org.springframework.stereotype.Controller; |
| 36 | |
import org.springframework.validation.BindingResult; |
| 37 | |
import org.springframework.web.bind.annotation.ModelAttribute; |
| 38 | |
import org.springframework.web.bind.annotation.RequestMapping; |
| 39 | |
import org.springframework.web.bind.annotation.RequestMethod; |
| 40 | |
import org.springframework.web.servlet.ModelAndView; |
| 41 | |
|
| 42 | |
import javax.servlet.http.HttpServletRequest; |
| 43 | |
import javax.servlet.http.HttpServletResponse; |
| 44 | |
import javax.xml.namespace.QName; |
| 45 | |
import java.util.*; |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
@Controller |
| 54 | |
@RequestMapping(value = "/academicCalendar") |
| 55 | 0 | public class AcademicCalendarController extends UifControllerBase { |
| 56 | |
|
| 57 | |
private AcademicCalendarService acalService; |
| 58 | |
|
| 59 | |
@Override |
| 60 | |
protected UifFormBase createInitialForm(HttpServletRequest request) { |
| 61 | 0 | return new AcademicCalendarForm(); |
| 62 | |
} |
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
@Override |
| 74 | |
@RequestMapping(method = RequestMethod.GET, params = "methodToCall=start") |
| 75 | |
public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 76 | |
HttpServletRequest request, HttpServletResponse response) { |
| 77 | 0 | AcademicCalendarForm acalForm = (AcademicCalendarForm) form; |
| 78 | |
|
| 79 | 0 | String acalId = request.getParameter(CalendarConstants.CALENDAR_ID); |
| 80 | |
|
| 81 | 0 | if (StringUtils.isNotBlank(acalId)){ |
| 82 | |
try { |
| 83 | 0 | loadAcademicCalendar(acalId, acalForm); |
| 84 | 0 | } catch (Exception ex) { |
| 85 | 0 | throw new RuntimeException(ex); |
| 86 | 0 | } |
| 87 | |
} |
| 88 | |
|
| 89 | 0 | String readOnlyView = request.getParameter(CalendarConstants.READ_ONLY_VIEW); |
| 90 | 0 | acalForm.getView().setReadOnly(BooleanUtils.toBoolean(readOnlyView)); |
| 91 | |
|
| 92 | 0 | if (StringUtils.isNotBlank(request.getParameter(CalendarConstants.SELECT_TAB))) { |
| 93 | 0 | acalForm.setDefaultTabToShow(request.getParameter(CalendarConstants.SELECT_TAB)); |
| 94 | |
} |
| 95 | |
|
| 96 | 0 | return super.start(form, result, request, response); |
| 97 | |
} |
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
@RequestMapping(params = "methodToCall=createBlankCalendar") |
| 103 | |
public ModelAndView createBlankCalendar(@ModelAttribute("KualiForm") AcademicCalendarForm acalForm, BindingResult result, |
| 104 | |
HttpServletRequest request, HttpServletResponse response){ |
| 105 | |
|
| 106 | 0 | acalForm.setAcademicCalendarInfo(new AcademicCalendarInfo()); |
| 107 | 0 | acalForm.setEvents(new ArrayList<AcalEventWrapper>()); |
| 108 | 0 | acalForm.setHolidayCalendarList(new ArrayList<HolidayCalendarWrapper>()); |
| 109 | 0 | acalForm.setTermWrapperList(new ArrayList<AcademicTermWrapper>()); |
| 110 | |
|
| 111 | 0 | return getUIFModelAndView(acalForm, CalendarConstants.ACADEMIC_CALENDAR_EDIT_PAGE); |
| 112 | |
} |
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
@RequestMapping(method = RequestMethod.GET, params = "methodToCall=startNew") |
| 123 | |
public ModelAndView startNew( @ModelAttribute("KualiForm") AcademicCalendarForm acalForm, BindingResult result, |
| 124 | |
HttpServletRequest request, HttpServletResponse response) { |
| 125 | |
|
| 126 | 0 | String acalId = request.getParameter(CalendarConstants.CALENDAR_ID); |
| 127 | 0 | String pageId = request.getParameter(CalendarConstants.PAGE_ID); |
| 128 | |
|
| 129 | 0 | if (StringUtils.isNotBlank(acalId)) { |
| 130 | 0 | if (StringUtils.equals(CalendarConstants.ACADEMIC_CALENDAR_COPY_PAGE,pageId)) { |
| 131 | |
try { |
| 132 | 0 | AcademicCalendarInfo acalInfo= getAcalService().getAcademicCalendar(acalId, acalForm.getContextInfo()); |
| 133 | 0 | acalForm.setOrgAcalInfo(acalInfo); |
| 134 | |
|
| 135 | 0 | } catch (Exception ex) { |
| 136 | 0 | throw new RuntimeException(ex); |
| 137 | 0 | } |
| 138 | |
} |
| 139 | |
} |
| 140 | |
else { |
| 141 | |
try { |
| 142 | 0 | AcademicCalendarInfo acalInfo = acalForm.getViewHelperService().getLatestAcademicCalendar(); |
| 143 | 0 | acalForm.setOrgAcalInfo(acalInfo); |
| 144 | |
} |
| 145 | 0 | catch (Exception x) { |
| 146 | 0 | throw new RuntimeException(x); |
| 147 | 0 | } |
| 148 | |
|
| 149 | |
} |
| 150 | |
|
| 151 | 0 | return getUIFModelAndView(acalForm); |
| 152 | |
} |
| 153 | |
|
| 154 | |
@RequestMapping(params = "methodToCall=toEdit") |
| 155 | |
public ModelAndView toEdit(@ModelAttribute("KualiForm") AcademicCalendarForm acalForm, BindingResult result, |
| 156 | |
HttpServletRequest request, HttpServletResponse response){ |
| 157 | 0 | AcademicCalendarInfo acalInfo = acalForm.getAcademicCalendarInfo(); |
| 158 | 0 | AcademicCalendarInfo orgAcalInfo = acalForm.getOrgAcalInfo(); |
| 159 | |
|
| 160 | 0 | if (StringUtils.isBlank(acalInfo.getId()) && StringUtils.isNotBlank(orgAcalInfo.getId())){ |
| 161 | |
try{ |
| 162 | 0 | loadAcademicCalendar(orgAcalInfo.getId(), acalForm); |
| 163 | 0 | } catch (Exception ex) { |
| 164 | 0 | throw new RuntimeException("unable to getAcademicCalendar"); |
| 165 | 0 | } |
| 166 | 0 | acalForm.setOrgAcalInfo(new AcademicCalendarInfo()); |
| 167 | |
} |
| 168 | |
|
| 169 | 0 | acalForm.getView().setReadOnly(false); |
| 170 | |
|
| 171 | 0 | return getUIFModelAndView(acalForm, CalendarConstants.ACADEMIC_CALENDAR_EDIT_PAGE); |
| 172 | |
} |
| 173 | |
|
| 174 | |
@RequestMapping(method = RequestMethod.GET, params = "methodToCall=copyForNew") |
| 175 | |
public ModelAndView copyForNew( @ModelAttribute("KualiForm") AcademicCalendarForm acalForm, BindingResult result, |
| 176 | |
HttpServletRequest request, HttpServletResponse response) { |
| 177 | |
|
| 178 | 0 | AcademicCalendarInfo acalInfo = null; |
| 179 | |
|
| 180 | 0 | String acalId = request.getParameter(CalendarConstants.CALENDAR_ID); |
| 181 | 0 | if (acalId != null && !acalId.trim().isEmpty()) { |
| 182 | 0 | String pageId = request.getParameter(CalendarConstants.PAGE_ID); |
| 183 | 0 | if (CalendarConstants.ACADEMIC_CALENDAR_COPY_PAGE.equals(pageId)) { |
| 184 | |
|
| 185 | |
try { |
| 186 | 0 | acalInfo= getAcalService().getAcademicCalendar(acalId, acalForm.getContextInfo()); |
| 187 | 0 | acalForm.setOrgAcalInfo(acalInfo); |
| 188 | |
|
| 189 | 0 | } catch (Exception ex) { |
| 190 | 0 | throw new RuntimeException(ex); |
| 191 | 0 | } |
| 192 | |
} |
| 193 | 0 | } |
| 194 | |
else { |
| 195 | |
|
| 196 | |
try { |
| 197 | 0 | acalInfo = acalForm.getViewHelperService().getLatestAcademicCalendar(); |
| 198 | 0 | acalForm.setOrgAcalInfo(acalInfo); |
| 199 | |
} |
| 200 | 0 | catch (Exception x) { |
| 201 | 0 | throw new RuntimeException(x); |
| 202 | 0 | } |
| 203 | |
|
| 204 | |
} |
| 205 | 0 | return copy(acalForm, result, request, response); |
| 206 | |
} |
| 207 | |
|
| 208 | |
@RequestMapping(params = "methodToCall=toCopy") |
| 209 | |
public ModelAndView toCopy(@ModelAttribute("KualiForm") AcademicCalendarForm acalForm, BindingResult result, |
| 210 | |
HttpServletRequest request, HttpServletResponse response){ |
| 211 | |
|
| 212 | 0 | AcademicCalendarInfo acalInfo = acalForm.getAcademicCalendarInfo(); |
| 213 | 0 | acalForm.reset(); |
| 214 | 0 | acalForm.setOrgAcalInfo(acalInfo); |
| 215 | |
|
| 216 | 0 | return copy(acalForm, result, request, response); |
| 217 | |
} |
| 218 | |
|
| 219 | |
|
| 220 | |
@RequestMapping(method = RequestMethod.POST, params="methodToCall=copy") |
| 221 | |
public ModelAndView copy( @ModelAttribute("KualiForm") AcademicCalendarForm acalForm, BindingResult result, |
| 222 | |
HttpServletRequest request, HttpServletResponse response) { |
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | 0 | acalForm.setNewCalendar(false); |
| 228 | |
try { |
| 229 | 0 | acalForm.getViewHelperService().copyToCreateAcademicCalendar(acalForm); |
| 230 | 0 | }catch (Exception ex) { |
| 231 | 0 | throw new RuntimeException(ex); |
| 232 | 0 | } |
| 233 | |
|
| 234 | 0 | return getUIFModelAndView(acalForm, CalendarConstants.ACADEMIC_CALENDAR_EDIT_PAGE); |
| 235 | |
|
| 236 | |
} |
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
@RequestMapping(method = RequestMethod.POST, params="methodToCall=editHolidayCalendar") |
| 241 | |
public ModelAndView editHolidayCalendar( @ModelAttribute("KualiForm") AcademicCalendarForm acalForm, BindingResult result, |
| 242 | |
HttpServletRequest request, HttpServletResponse response) { |
| 243 | |
|
| 244 | 0 | String selectedCollectionPath = acalForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH); |
| 245 | 0 | if (StringUtils.isBlank(selectedCollectionPath)) { |
| 246 | 0 | throw new RuntimeException("unable to determine the selected collection path"); |
| 247 | |
} |
| 248 | |
|
| 249 | 0 | int selectedLineIndex = -1; |
| 250 | 0 | String selectedLine = acalForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); |
| 251 | 0 | if (StringUtils.isNotBlank(selectedLine)) { |
| 252 | 0 | selectedLineIndex = Integer.parseInt(selectedLine); |
| 253 | |
} |
| 254 | |
|
| 255 | 0 | if (selectedLineIndex == -1) { |
| 256 | 0 | throw new RuntimeException("unable to determine the selected line index"); |
| 257 | |
} |
| 258 | |
|
| 259 | 0 | Properties hcalURLParam = new Properties(); |
| 260 | 0 | hcalURLParam.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, CalendarConstants.HC_EDIT_METHOD); |
| 261 | 0 | hcalURLParam.put(CalendarConstants.CALENDAR_ID, acalForm.getHolidayCalendarList().get(selectedLineIndex).getId()); |
| 262 | 0 | hcalURLParam.put(UifParameters.VIEW_ID, CalendarConstants.HOLIDAYCALENDAR_FLOWVIEW); |
| 263 | 0 | hcalURLParam.put(UifParameters.PAGE_ID, CalendarConstants.HOLIDAYCALENDAR_EDITPAGE); |
| 264 | 0 | hcalURLParam.put(UifParameters.RETURN_FORM_KEY, acalForm.getFormKey()); |
| 265 | |
|
| 266 | 0 | Properties acalReturnURLParams = new Properties(); |
| 267 | 0 | acalReturnURLParams.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, CalendarConstants.AC_EDIT_METHOD); |
| 268 | 0 | acalReturnURLParams.put(UifParameters.VIEW_ID, CalendarConstants.ACAL_VIEW); |
| 269 | 0 | acalReturnURLParams.put(UifParameters.PAGE_ID, CalendarConstants.ACADEMIC_CALENDAR_EDIT_PAGE); |
| 270 | 0 | String returnUrl = UrlFactory.parameterizeUrl(CalendarConstants.ACAL_CONTROLLER_PATH, acalReturnURLParams); |
| 271 | 0 | hcalURLParam.put(UifParameters.RETURN_LOCATION, returnUrl); |
| 272 | |
|
| 273 | 0 | return super.performRedirect(acalForm,CalendarConstants.HCAL_CONTROLLER_PATH, hcalURLParam); |
| 274 | |
|
| 275 | |
} |
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
@RequestMapping(params = "methodToCall=search") |
| 282 | |
public ModelAndView search(@ModelAttribute("KualiForm") AcademicCalendarForm acalForm, BindingResult result, |
| 283 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 284 | |
|
| 285 | 0 | String controllerPath = CalendarConstants.CALENDAR_SEARCH_CONTROLLER_PATH; |
| 286 | 0 | Properties urlParameters = new Properties(); |
| 287 | 0 | urlParameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.START_METHOD); |
| 288 | 0 | urlParameters.put(UifParameters.VIEW_ID, CalendarConstants.CALENDAR_SEARCH_VIEW); |
| 289 | 0 | return super.performRedirect(acalForm,controllerPath, urlParameters); |
| 290 | |
} |
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
|
| 295 | |
|
| 296 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=save") |
| 297 | |
public ModelAndView save(@ModelAttribute("KualiForm") AcademicCalendarForm academicCalendarForm, BindingResult result, |
| 298 | |
HttpServletRequest request, HttpServletResponse response) throws Exception{ |
| 299 | 0 | return saveAcademicCalendar(academicCalendarForm, CalendarConstants.MSG_INFO_ACADEMIC_CALENDAR_SAVED,false); |
| 300 | |
} |
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=delete") |
| 306 | |
public ModelAndView delete(@ModelAttribute("KualiForm") AcademicCalendarForm acalForm, BindingResult result, |
| 307 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 308 | |
|
| 309 | 0 | acalForm.getViewHelperService().deleteAcademicCalendar(acalForm.getAcademicCalendarInfo().getId()); |
| 310 | |
|
| 311 | 0 | GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_MESSAGES, CalendarConstants.MSG_INFO_SEARCH_DELETE_SUCCESS, acalForm.getAcademicCalendarInfo().getName()); |
| 312 | |
|
| 313 | 0 | Properties urlParameters = new Properties(); |
| 314 | 0 | urlParameters.put("viewId", CalendarConstants.ENROLLMENT_HOME_VIEW); |
| 315 | 0 | urlParameters.put("methodToCall", KRADConstants.START_METHOD); |
| 316 | 0 | return performRedirect(acalForm, request.getRequestURL().toString(), urlParameters); |
| 317 | |
} |
| 318 | |
|
| 319 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=cancelTerm") |
| 320 | |
public ModelAndView cancelTerm(@ModelAttribute("KualiForm") AcademicCalendarForm academicCalendarForm, BindingResult result, |
| 321 | |
HttpServletRequest request, HttpServletResponse response) { |
| 322 | |
|
| 323 | 0 | String selectedCollectionPath = academicCalendarForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH); |
| 324 | 0 | if (StringUtils.isBlank(selectedCollectionPath)) { |
| 325 | 0 | throw new RuntimeException("unable to determine the selected collection path"); |
| 326 | |
} |
| 327 | |
|
| 328 | 0 | int selectedLineIndex = -1; |
| 329 | 0 | String selectedLine = academicCalendarForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); |
| 330 | 0 | if (StringUtils.isNotBlank(selectedLine)) { |
| 331 | 0 | selectedLineIndex = Integer.parseInt(selectedLine); |
| 332 | |
} |
| 333 | |
|
| 334 | 0 | if (selectedLineIndex == -1) { |
| 335 | 0 | throw new RuntimeException("unable to determine the selected line index"); |
| 336 | |
} |
| 337 | |
|
| 338 | 0 | AcademicTermWrapper termWrapper = academicCalendarForm.getTermWrapperList().get(selectedLineIndex); |
| 339 | |
|
| 340 | 0 | if (termWrapper.isNew()){ |
| 341 | 0 | academicCalendarForm.getTermWrapperList().remove(selectedLineIndex); |
| 342 | |
}else{ |
| 343 | |
try { |
| 344 | 0 | TermInfo termInfo = getAcalService().getTerm(termWrapper.getTermInfo().getId(), academicCalendarForm.getContextInfo()); |
| 345 | 0 | AcademicTermWrapper termWrapperFromDB = academicCalendarForm.getViewHelperService().populateTermWrapper(termInfo, false); |
| 346 | 0 | academicCalendarForm.getTermWrapperList().set(selectedLineIndex,termWrapperFromDB); |
| 347 | |
|
| 348 | |
|
| 349 | 0 | if (academicCalendarForm.getHolidayCalendarList() != null && !academicCalendarForm.getHolidayCalendarList().isEmpty()) { |
| 350 | |
try{ |
| 351 | 0 | academicCalendarForm.getViewHelperService().populateInstructionalDays(termWrapperFromDB); |
| 352 | 0 | }catch(Exception e){ |
| 353 | |
|
| 354 | 0 | e.printStackTrace(); |
| 355 | 0 | } |
| 356 | |
} |
| 357 | 0 | } catch (Exception e) { |
| 358 | 0 | throw new RuntimeException(e); |
| 359 | 0 | } |
| 360 | |
} |
| 361 | |
|
| 362 | 0 | return updateComponent(academicCalendarForm, result, request, response); |
| 363 | |
} |
| 364 | |
|
| 365 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=makeTermOfficial") |
| 366 | |
public ModelAndView makeTermOfficial(@ModelAttribute("KualiForm") AcademicCalendarForm academicCalendarForm, BindingResult result, |
| 367 | |
HttpServletRequest request, HttpServletResponse response) { |
| 368 | |
|
| 369 | 0 | String selectedCollectionPath = academicCalendarForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH); |
| 370 | 0 | if (StringUtils.isBlank(selectedCollectionPath)) { |
| 371 | 0 | throw new RuntimeException("unable to determine the selected collection path"); |
| 372 | |
} |
| 373 | |
|
| 374 | 0 | int selectedLineIndex = -1; |
| 375 | 0 | String selectedLine = academicCalendarForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); |
| 376 | 0 | if (StringUtils.isNotBlank(selectedLine)) { |
| 377 | 0 | selectedLineIndex = Integer.parseInt(selectedLine); |
| 378 | |
} |
| 379 | |
|
| 380 | 0 | if (selectedLineIndex == -1) { |
| 381 | 0 | throw new RuntimeException("unable to determine the selected line index"); |
| 382 | |
} |
| 383 | |
|
| 384 | 0 | AcademicTermWrapper termWrapper = academicCalendarForm.getTermWrapperList().get(selectedLineIndex); |
| 385 | |
|
| 386 | 0 | academicCalendarForm.getViewHelperService().validateTerm(academicCalendarForm.getTermWrapperList(),selectedLineIndex,academicCalendarForm.getAcademicCalendarInfo()); |
| 387 | |
|
| 388 | 0 | if (GlobalVariables.getMessageMap().getErrorCount() > 0){ |
| 389 | 0 | return getUIFModelAndView(academicCalendarForm); |
| 390 | |
} |
| 391 | |
|
| 392 | |
try{ |
| 393 | 0 | academicCalendarForm.getViewHelperService().saveTerm(termWrapper, academicCalendarForm.getAcademicCalendarInfo().getId(),true); |
| 394 | 0 | GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_ERRORS,"info.enroll.term.official",termWrapper.getTermNameForUI()); |
| 395 | 0 | }catch (Exception e){ |
| 396 | 0 | throw new RuntimeException(e); |
| 397 | 0 | } |
| 398 | |
|
| 399 | |
|
| 400 | 0 | if (academicCalendarForm.getHolidayCalendarList() != null && !academicCalendarForm.getHolidayCalendarList().isEmpty()) { |
| 401 | |
try{ |
| 402 | 0 | academicCalendarForm.getViewHelperService().populateInstructionalDays(termWrapper); |
| 403 | 0 | }catch(Exception e){ |
| 404 | |
|
| 405 | 0 | e.printStackTrace(); |
| 406 | 0 | } |
| 407 | |
} |
| 408 | |
|
| 409 | 0 | return updateComponent(academicCalendarForm, result, request, response); |
| 410 | |
} |
| 411 | |
|
| 412 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=cancelAddingTerm") |
| 413 | |
public ModelAndView cancelAddingTerm(@ModelAttribute("KualiForm") AcademicCalendarForm academicCalendarForm, BindingResult result, |
| 414 | |
HttpServletRequest request, HttpServletResponse response) { |
| 415 | |
|
| 416 | 0 | ((AcademicTermWrapper)academicCalendarForm.getNewCollectionLines().get("termWrapperList")).clear(); |
| 417 | |
|
| 418 | 0 | return updateComponent(academicCalendarForm, result, request, response); |
| 419 | |
} |
| 420 | |
|
| 421 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=cancelAddingHoliday") |
| 422 | |
public ModelAndView cancelAddingHoliday(@ModelAttribute("KualiForm") AcademicCalendarForm academicCalendarForm, BindingResult result, |
| 423 | |
HttpServletRequest request, HttpServletResponse response) { |
| 424 | |
|
| 425 | 0 | ((HolidayCalendarWrapper)academicCalendarForm.getNewCollectionLines().get("holidayCalendarList")).setId(StringUtils.EMPTY); |
| 426 | |
|
| 427 | 0 | return updateComponent(academicCalendarForm, result, request, response); |
| 428 | |
} |
| 429 | |
|
| 430 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteTerm") |
| 431 | |
public ModelAndView deleteTerm(@ModelAttribute("KualiForm") AcademicCalendarForm academicCalendarForm, BindingResult result, |
| 432 | |
HttpServletRequest request, HttpServletResponse response) { |
| 433 | |
|
| 434 | 0 | String selectedCollectionPath = academicCalendarForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH); |
| 435 | 0 | if (StringUtils.isBlank(selectedCollectionPath)) { |
| 436 | 0 | throw new RuntimeException("unable to determine the selected collection path"); |
| 437 | |
} |
| 438 | |
|
| 439 | 0 | int selectedLineIndex = -1; |
| 440 | 0 | String selectedLine = academicCalendarForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); |
| 441 | 0 | if (StringUtils.isNotBlank(selectedLine)) { |
| 442 | 0 | selectedLineIndex = Integer.parseInt(selectedLine); |
| 443 | |
} |
| 444 | |
|
| 445 | 0 | if (selectedLineIndex == -1) { |
| 446 | 0 | throw new RuntimeException("unable to determine the selected line index"); |
| 447 | |
} |
| 448 | |
|
| 449 | 0 | AcademicTermWrapper termWrapper = academicCalendarForm.getTermWrapperList().get(selectedLineIndex); |
| 450 | |
|
| 451 | 0 | if (!termWrapper.isNew()){ |
| 452 | 0 | academicCalendarForm.getTermsToDeleteOnSave().add(termWrapper); |
| 453 | |
} |
| 454 | |
|
| 455 | 0 | academicCalendarForm.getTermWrapperList().remove(selectedLineIndex); |
| 456 | |
|
| 457 | 0 | return updateComponent(academicCalendarForm, result, request, response); |
| 458 | |
|
| 459 | |
} |
| 460 | |
|
| 461 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteKeyDate") |
| 462 | |
public ModelAndView deleteKeyDate(@ModelAttribute("KualiForm") AcademicCalendarForm academicCalendarForm, BindingResult result, |
| 463 | |
HttpServletRequest request, HttpServletResponse response) { |
| 464 | |
|
| 465 | 0 | String selectedCollectionPath = academicCalendarForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH); |
| 466 | 0 | if (StringUtils.isBlank(selectedCollectionPath)) { |
| 467 | 0 | throw new RuntimeException("unable to determine the selected collection path"); |
| 468 | |
} |
| 469 | |
|
| 470 | 0 | int selectedLineIndex = -1; |
| 471 | 0 | String selectedLine = academicCalendarForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); |
| 472 | 0 | if (StringUtils.isNotBlank(selectedLine)) { |
| 473 | 0 | selectedLineIndex = Integer.parseInt(selectedLine); |
| 474 | |
} |
| 475 | |
|
| 476 | 0 | if (selectedLineIndex == -1) { |
| 477 | 0 | throw new RuntimeException("unable to determine the selected line index"); |
| 478 | |
} |
| 479 | |
|
| 480 | 0 | String selectedTermIndex = StringUtils.substringBetween(selectedCollectionPath,"termWrapperList[","]"); |
| 481 | 0 | String selectedKeyDateGroup = StringUtils.substringBetween(selectedCollectionPath,"keyDatesGroupWrappers[","]"); |
| 482 | |
|
| 483 | 0 | AcademicTermWrapper termWrapper = academicCalendarForm.getTermWrapperList().get(Integer.parseInt(selectedTermIndex)); |
| 484 | 0 | KeyDatesGroupWrapper keydateGroup = termWrapper.getKeyDatesGroupWrappers().get(Integer.parseInt(selectedKeyDateGroup)); |
| 485 | 0 | KeyDateWrapper keyDateWrapper = keydateGroup.getKeydates().get(selectedLineIndex); |
| 486 | |
|
| 487 | 0 | if (StringUtils.isNotBlank(keyDateWrapper.getKeyDateInfo().getId())){ |
| 488 | 0 | termWrapper.getKeyDatesToDeleteOnSave().add(keyDateWrapper); |
| 489 | |
} |
| 490 | |
|
| 491 | 0 | keydateGroup.getKeydates().remove(selectedLineIndex); |
| 492 | |
|
| 493 | 0 | return updateComponent(academicCalendarForm, result, request, response); |
| 494 | |
|
| 495 | |
} |
| 496 | |
|
| 497 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteKeyDateGroup") |
| 498 | |
public ModelAndView deleteKeyDateGroup(@ModelAttribute("KualiForm") AcademicCalendarForm academicCalendarForm, BindingResult result, |
| 499 | |
HttpServletRequest request, HttpServletResponse response) { |
| 500 | |
|
| 501 | 0 | String selectedCollectionPath = academicCalendarForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH); |
| 502 | 0 | if (StringUtils.isBlank(selectedCollectionPath)) { |
| 503 | 0 | throw new RuntimeException("unable to determine the selected collection path"); |
| 504 | |
} |
| 505 | |
|
| 506 | 0 | int selectedLineIndex = -1; |
| 507 | 0 | String selectedLine = academicCalendarForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); |
| 508 | 0 | if (StringUtils.isNotBlank(selectedLine)) { |
| 509 | 0 | selectedLineIndex = Integer.parseInt(selectedLine); |
| 510 | |
} |
| 511 | |
|
| 512 | 0 | if (selectedLineIndex == -1) { |
| 513 | 0 | throw new RuntimeException("unable to determine the selected line index"); |
| 514 | |
} |
| 515 | |
|
| 516 | 0 | String selectedTermIndex = StringUtils.substringBetween(selectedCollectionPath,"termWrapperList[","]"); |
| 517 | |
|
| 518 | 0 | AcademicTermWrapper termWrapper = academicCalendarForm.getTermWrapperList().get(Integer.parseInt(selectedTermIndex)); |
| 519 | 0 | KeyDatesGroupWrapper keydateGroup = termWrapper.getKeyDatesGroupWrappers().get(selectedLineIndex); |
| 520 | 0 | for (KeyDateWrapper keyDateWrapper : keydateGroup.getKeydates()) { |
| 521 | 0 | if (StringUtils.isNotBlank(keyDateWrapper.getKeyDateInfo().getId())){ |
| 522 | 0 | termWrapper.getKeyDatesToDeleteOnSave().add(keyDateWrapper); |
| 523 | |
} |
| 524 | |
} |
| 525 | |
|
| 526 | 0 | termWrapper.getKeyDatesGroupWrappers().remove(keydateGroup); |
| 527 | |
|
| 528 | 0 | return updateComponent(academicCalendarForm, result, request, response); |
| 529 | |
|
| 530 | |
} |
| 531 | |
|
| 532 | |
|
| 533 | |
|
| 534 | |
|
| 535 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=makeAcalOfficial") |
| 536 | |
public ModelAndView makeAcalOfficial(@ModelAttribute("KualiForm") AcademicCalendarForm acalForm, BindingResult result, |
| 537 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 538 | 0 | return saveAcademicCalendar(acalForm, CalendarConstants.MSG_INFO_ACADEMIC_CALENDAR_OFFICIAL, true); |
| 539 | |
} |
| 540 | |
|
| 541 | |
|
| 542 | |
private void loadAcademicCalendar(String acalId, AcademicCalendarForm acalForm) throws Exception { |
| 543 | |
|
| 544 | 0 | AcademicCalendarInfo acalInfo = getAcalService().getAcademicCalendar(acalId,acalForm.getContextInfo()); |
| 545 | |
|
| 546 | 0 | acalForm.setAcademicCalendarInfo(acalInfo); |
| 547 | 0 | acalForm.setAdminOrgName(getAdminOrgNameById(acalInfo.getAdminOrgId())); |
| 548 | 0 | acalForm.setNewCalendar(false); |
| 549 | 0 | acalForm.setOfficialCalendar(StringUtils.equals(acalInfo.getStateKey(),AtpServiceConstants.ATP_OFFICIAL_STATE_KEY)); |
| 550 | |
|
| 551 | 0 | List<AcalEventWrapper> events = acalForm.getViewHelperService().populateEventWrappers(acalForm); |
| 552 | 0 | acalForm.setEvents(events); |
| 553 | |
|
| 554 | 0 | List<AcademicTermWrapper> termWrappers = acalForm.getViewHelperService().populateTermWrappers(acalId, false); |
| 555 | 0 | acalForm.setTermWrapperList(termWrappers); |
| 556 | |
|
| 557 | 0 | List<HolidayCalendarWrapper> holidayCalendarWrapperList = acalForm.getViewHelperService().loadHolidayCalendars(acalInfo); |
| 558 | 0 | acalForm.setHolidayCalendarList(holidayCalendarWrapperList); |
| 559 | |
|
| 560 | |
|
| 561 | 0 | if (acalForm.getHolidayCalendarList() != null && !acalForm.getHolidayCalendarList().isEmpty()) { |
| 562 | |
try{ |
| 563 | 0 | acalForm.getViewHelperService().populateInstructionalDays(acalForm.getTermWrapperList()); |
| 564 | 0 | }catch(Exception e){ |
| 565 | |
|
| 566 | 0 | e.printStackTrace(); |
| 567 | 0 | } |
| 568 | |
} |
| 569 | |
|
| 570 | 0 | } |
| 571 | |
|
| 572 | |
private AcademicCalendarInfo processHolidayCalendars(AcademicCalendarForm academicCalendarForm) { |
| 573 | 0 | AcademicCalendarInfo acalInfo = academicCalendarForm.getAcademicCalendarInfo(); |
| 574 | 0 | List<HolidayCalendarWrapper> holidayCalendarList = academicCalendarForm.getHolidayCalendarList(); |
| 575 | 0 | List<String> holidayCalendarIds = new ArrayList<String>(); |
| 576 | 0 | if (holidayCalendarList!=null && !holidayCalendarList.isEmpty()) { |
| 577 | 0 | for (HolidayCalendarWrapper hcWrapper : holidayCalendarList){ |
| 578 | 0 | holidayCalendarIds.add(hcWrapper.getHolidayCalendarInfo().getId()); |
| 579 | |
} |
| 580 | 0 | acalInfo.setHolidayCalendarIds(holidayCalendarIds); |
| 581 | 0 | academicCalendarForm.setAcademicCalendarInfo(acalInfo); |
| 582 | |
} |
| 583 | 0 | return acalInfo; |
| 584 | |
} |
| 585 | |
|
| 586 | |
private ModelAndView saveAcademicCalendar(AcademicCalendarForm academicCalendarForm, String keyToDisplayOnSave, boolean isOfficial) throws Exception { |
| 587 | |
|
| 588 | 0 | AcademicCalendarInfo academicCalendarInfo = academicCalendarForm.getAcademicCalendarInfo(); |
| 589 | |
|
| 590 | |
|
| 591 | 0 | academicCalendarForm.getViewHelperService().populateAcademicCalendarDefaults(academicCalendarForm); |
| 592 | |
|
| 593 | |
|
| 594 | 0 | academicCalendarForm.getViewHelperService().validateAcademicCalendar(academicCalendarForm); |
| 595 | |
|
| 596 | 0 | if (GlobalVariables.getMessageMap().getErrorCount() > 0){ |
| 597 | 0 | return getUIFModelAndView(academicCalendarForm); |
| 598 | |
} |
| 599 | |
|
| 600 | |
|
| 601 | 0 | if(StringUtils.isNotBlank(academicCalendarInfo.getId())){ |
| 602 | |
|
| 603 | 0 | academicCalendarInfo = processHolidayCalendars(academicCalendarForm); |
| 604 | 0 | if (isOfficial) { |
| 605 | 0 | academicCalendarInfo.setStateKey(AcademicCalendarServiceConstants.ACADEMIC_CALENDAR_OFFICIAL_STATE_KEY); |
| 606 | |
} |
| 607 | 0 | AcademicCalendarInfo acalInfo = getAcalService().updateAcademicCalendar(academicCalendarInfo.getId(), academicCalendarInfo, academicCalendarForm.getContextInfo() ); |
| 608 | 0 | academicCalendarForm.setAcademicCalendarInfo(getAcalService().getAcademicCalendar(acalInfo.getId(), academicCalendarForm.getContextInfo())); |
| 609 | |
|
| 610 | |
|
| 611 | 0 | List<AcalEventWrapper> events = academicCalendarForm.getEvents(); |
| 612 | 0 | processEvents(academicCalendarForm, events, acalInfo.getId()); |
| 613 | 0 | } |
| 614 | |
else { |
| 615 | 0 | AcademicCalendarInfo acalInfo = null; |
| 616 | |
|
| 617 | 0 | processHolidayCalendars(academicCalendarForm); |
| 618 | 0 | acalInfo = academicCalendarForm.getViewHelperService().createAcademicCalendar(academicCalendarForm); |
| 619 | 0 | academicCalendarForm.setAcademicCalendarInfo(getAcalService().getAcademicCalendar(acalInfo.getId(), academicCalendarForm.getContextInfo())); |
| 620 | |
|
| 621 | 0 | createEvents(acalInfo.getId(), academicCalendarForm); |
| 622 | |
} |
| 623 | |
|
| 624 | |
|
| 625 | 0 | for (AcademicTermWrapper termWrapper : academicCalendarForm.getTermsToDeleteOnSave()){ |
| 626 | 0 | getAcalService().deleteTerm(termWrapper.getTermInfo().getId(),academicCalendarForm.getContextInfo()); |
| 627 | |
} |
| 628 | |
|
| 629 | 0 | academicCalendarForm.getTermsToDeleteOnSave().clear(); |
| 630 | |
|
| 631 | |
|
| 632 | 0 | for(AcademicTermWrapper termWrapper : academicCalendarForm.getTermWrapperList()){ |
| 633 | 0 | academicCalendarForm.getViewHelperService().saveTerm(termWrapper, academicCalendarForm.getAcademicCalendarInfo().getId(),false); |
| 634 | |
} |
| 635 | |
|
| 636 | |
|
| 637 | 0 | if (academicCalendarForm.getHolidayCalendarList() != null && !academicCalendarForm.getHolidayCalendarList().isEmpty()) { |
| 638 | |
try{ |
| 639 | 0 | academicCalendarForm.getViewHelperService().populateInstructionalDays(academicCalendarForm.getTermWrapperList()); |
| 640 | 0 | }catch(Exception e){ |
| 641 | |
|
| 642 | 0 | e.printStackTrace(); |
| 643 | 0 | } |
| 644 | |
} |
| 645 | |
|
| 646 | 0 | academicCalendarForm.setNewCalendar(false); |
| 647 | |
|
| 648 | 0 | if (isOfficial) { |
| 649 | 0 | academicCalendarForm.setOfficialCalendar(true); |
| 650 | 0 | academicCalendarForm.getView().setReadOnly(true); |
| 651 | |
} |
| 652 | |
|
| 653 | 0 | GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_MESSAGES, keyToDisplayOnSave, academicCalendarForm.getAcademicCalendarInfo().getName()); |
| 654 | |
|
| 655 | 0 | return getUIFModelAndView(academicCalendarForm); |
| 656 | |
} |
| 657 | |
|
| 658 | |
private String getAdminOrgNameById(String id){ |
| 659 | |
|
| 660 | 0 | String adminOrgName = null; |
| 661 | 0 | Map<String, String> allAcalOrgs = new HashMap<String, String>(); |
| 662 | 0 | allAcalOrgs.put("102", "Registrar's Office"); |
| 663 | 0 | allAcalOrgs.put("34", "Medical School"); |
| 664 | |
|
| 665 | 0 | if(allAcalOrgs.containsKey(id)){ |
| 666 | 0 | adminOrgName = allAcalOrgs.get(id); |
| 667 | |
} |
| 668 | |
|
| 669 | 0 | return adminOrgName; |
| 670 | |
} |
| 671 | |
|
| 672 | |
private void createEvents(String acalId, AcademicCalendarForm acalForm) throws Exception { |
| 673 | 0 | List<AcalEventWrapper> events = acalForm.getEvents(); |
| 674 | |
|
| 675 | 0 | if(events != null && !events.isEmpty()){ |
| 676 | 0 | List<AcalEventWrapper> createdEvents = new ArrayList<AcalEventWrapper>(); |
| 677 | 0 | for (AcalEventWrapper event : events){ |
| 678 | 0 | createdEvents.add(acalForm.getViewHelperService().createEvent(acalId, event)); |
| 679 | |
} |
| 680 | 0 | acalForm.setEvents(createdEvents); |
| 681 | |
} |
| 682 | |
|
| 683 | 0 | } |
| 684 | |
|
| 685 | |
|
| 686 | |
|
| 687 | |
|
| 688 | |
private void processEvents(AcademicCalendarForm acalForm, List<AcalEventWrapper> events, String acalId)throws Exception{ |
| 689 | 0 | List<AcalEventWrapper> updatedEvents = new ArrayList<AcalEventWrapper>(); |
| 690 | 0 | List<String> currentEventIds = getExistingEventIds(acalForm); |
| 691 | 0 | if(events != null && !events.isEmpty()){ |
| 692 | 0 | for(AcalEventWrapper event : events){ |
| 693 | 0 | if(currentEventIds.contains(event.getAcalEventInfo().getId())){ |
| 694 | |
|
| 695 | 0 | AcalEventWrapper updatedEvent = acalForm.getViewHelperService().updateEvent(event.getAcalEventInfo().getId(), event); |
| 696 | 0 | updatedEvents.add(updatedEvent); |
| 697 | 0 | currentEventIds.remove(event.getAcalEventInfo().getId()); |
| 698 | 0 | } |
| 699 | |
else { |
| 700 | |
|
| 701 | 0 | AcalEventWrapper createdEvent = acalForm.getViewHelperService().createEvent(acalId, event); |
| 702 | 0 | updatedEvents.add(createdEvent); |
| 703 | 0 | } |
| 704 | |
} |
| 705 | |
} |
| 706 | 0 | acalForm.setEvents(updatedEvents); |
| 707 | |
|
| 708 | |
|
| 709 | 0 | if (currentEventIds != null && currentEventIds.size() > 0){ |
| 710 | 0 | for(String eventId: currentEventIds){ |
| 711 | |
|
| 712 | 0 | acalForm.getViewHelperService().deleteEvent(eventId); |
| 713 | |
} |
| 714 | |
} |
| 715 | |
|
| 716 | 0 | } |
| 717 | |
|
| 718 | |
private List<String> getExistingEventIds(AcademicCalendarForm acalForm) throws Exception{ |
| 719 | 0 | List<AcalEventWrapper> events = acalForm.getViewHelperService().populateEventWrappers(acalForm); |
| 720 | 0 | List<String> eventIds = new ArrayList<String>(); |
| 721 | |
|
| 722 | 0 | if(events != null && !events.isEmpty()){ |
| 723 | 0 | for(AcalEventWrapper event : events){ |
| 724 | 0 | eventIds.add(event.getAcalEventInfo().getId()); |
| 725 | |
} |
| 726 | |
} |
| 727 | 0 | return eventIds; |
| 728 | |
} |
| 729 | |
|
| 730 | |
|
| 731 | |
public AcademicCalendarService getAcalService() { |
| 732 | 0 | if(acalService == null) { |
| 733 | 0 | acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART)); |
| 734 | |
} |
| 735 | 0 | return this.acalService; |
| 736 | |
} |
| 737 | |
|
| 738 | |
|
| 739 | |
} |