| 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 | |
|
| 19 | |
import org.apache.commons.lang.StringUtils; |
| 20 | |
import org.kuali.rice.core.api.util.RiceKeyConstants; |
| 21 | |
import org.kuali.rice.krad.uif.UifConstants; |
| 22 | |
import org.kuali.rice.krad.uif.UifParameters; |
| 23 | |
import org.kuali.rice.krad.util.GlobalVariables; |
| 24 | |
import org.kuali.rice.krad.util.KRADConstants; |
| 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.HolidayCalendarInfo; |
| 29 | |
import org.kuali.student.enrollment.class2.acal.dto.HolidayWrapper; |
| 30 | |
import org.kuali.student.enrollment.class2.acal.form.HolidayCalendarForm; |
| 31 | |
import org.kuali.student.enrollment.class2.acal.service.AcademicCalendarViewHelperService; |
| 32 | |
import org.kuali.student.enrollment.class2.acal.util.CalendarConstants; |
| 33 | |
import org.kuali.student.enrollment.class2.acal.util.CommonUtils; |
| 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 java.util.*; |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
@Controller |
| 54 | |
@RequestMapping(value = "/holidayCalendar") |
| 55 | 0 | public class HolidayCalendarController extends UifControllerBase { |
| 56 | |
|
| 57 | |
@Override |
| 58 | |
protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) { |
| 59 | 0 | return new HolidayCalendarForm(); |
| 60 | |
} |
| 61 | |
|
| 62 | |
@Override |
| 63 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=addLine") |
| 64 | |
public ModelAndView addLine(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 65 | |
HttpServletRequest request, HttpServletResponse response) { |
| 66 | 0 | HolidayCalendarForm hcForm = (HolidayCalendarForm) form; |
| 67 | 0 | List<HolidayWrapper> holidays = hcForm.getHolidays(); |
| 68 | 0 | Map<String, Object> newCollectionLines = form.getNewCollectionLines(); |
| 69 | |
|
| 70 | 0 | if(newCollectionLines != null && !newCollectionLines.isEmpty()){ |
| 71 | 0 | for (Map.Entry<String, Object> entry : newCollectionLines.entrySet()){ |
| 72 | 0 | HolidayWrapper newHoliday = (HolidayWrapper)entry.getValue(); |
| 73 | 0 | if(checkHoliday(newHoliday)){ |
| 74 | 0 | if(holidays != null && !holidays.isEmpty()){ |
| 75 | 0 | for(HolidayWrapper holiday : holidays){ |
| 76 | 0 | boolean duplicated = isDuplicateHoliday(newHoliday, holiday); |
| 77 | 0 | if(duplicated){ |
| 78 | 0 | GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, "ERROR: The holiday being added is already in the collection."); |
| 79 | 0 | return updateComponent(form, result, request, response); |
| 80 | |
} |
| 81 | 0 | } |
| 82 | |
} |
| 83 | |
} |
| 84 | |
else { |
| 85 | 0 | return updateComponent(form, result, request, response); |
| 86 | |
} |
| 87 | 0 | } |
| 88 | |
} |
| 89 | |
|
| 90 | 0 | return super.addLine(form, result, request, response); |
| 91 | |
} |
| 92 | |
|
| 93 | |
private boolean checkHoliday(HolidayWrapper holiday) { |
| 94 | 0 | boolean valid = true; |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | 0 | return valid; |
| 128 | |
} |
| 129 | |
|
| 130 | |
private boolean isDuplicateHoliday(HolidayWrapper newHoliday, HolidayWrapper sourceHoliday){ |
| 131 | 0 | return (newHoliday.getTypeKey().equals(sourceHoliday.getTypeKey())); |
| 132 | |
} |
| 133 | |
|
| 134 | |
@Override |
| 135 | |
@RequestMapping(method = RequestMethod.GET, params = "methodToCall=start") |
| 136 | |
public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 137 | |
HttpServletRequest request, HttpServletResponse response) { |
| 138 | 0 | HolidayCalendarForm hcForm = (HolidayCalendarForm) form; |
| 139 | |
|
| 140 | 0 | String hcId = request.getParameter(CalendarConstants.CALENDAR_ID); |
| 141 | |
|
| 142 | 0 | if ((hcId != null) && !hcId.trim().isEmpty()) { |
| 143 | 0 | String pageId = request.getParameter("pageId"); |
| 144 | 0 | if (CalendarConstants.HOLIDAYCALENDAR_VIEWPAGE.equals(pageId)) { |
| 145 | 0 | hcForm.setViewTypeName(UifConstants.ViewType.INQUIRY); |
| 146 | |
} |
| 147 | |
|
| 148 | |
try { |
| 149 | 0 | getHolidayCalendar(hcId, hcForm); |
| 150 | 0 | } catch (Exception ex) { |
| 151 | 0 | throw new RuntimeException("unable to getHolidayCalendar "); |
| 152 | 0 | } |
| 153 | |
} |
| 154 | |
|
| 155 | 0 | return super.start(form, result, request, response); |
| 156 | |
} |
| 157 | |
|
| 158 | |
@RequestMapping(method = RequestMethod.GET, params = "methodToCall=startNew") |
| 159 | |
public ModelAndView startNew( @ModelAttribute("KualiForm") HolidayCalendarForm form, BindingResult result, |
| 160 | |
HttpServletRequest request, HttpServletResponse response) { |
| 161 | 0 | HolidayCalendarInfo hcInfo = null; |
| 162 | |
|
| 163 | |
try { |
| 164 | 0 | String calendarId = request.getParameter(CalendarConstants.CALENDAR_ID); |
| 165 | 0 | if (calendarId == null || calendarId.trim().isEmpty()) { |
| 166 | 0 | hcInfo = getHolidayCalendarFormHelper(form).getNewestHolidayCalendar(); |
| 167 | |
} |
| 168 | |
else { |
| 169 | 0 | hcInfo = getHolidayCalendarFormHelper(form).getHolidayCalendar(calendarId); |
| 170 | |
} |
| 171 | |
} |
| 172 | 0 | catch (Exception e) { |
| 173 | 0 | GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, "Unexpected error; could not get holiday to copy: " + e.getMessage()); |
| 174 | 0 | } |
| 175 | |
|
| 176 | 0 | form.setHolidayCalendarInfo(hcInfo); |
| 177 | |
|
| 178 | 0 | if (null != hcInfo) { |
| 179 | |
|
| 180 | 0 | Calendar cal = Calendar.getInstance(); |
| 181 | 0 | int currentYear = cal.get(Calendar.YEAR); |
| 182 | 0 | cal.setTime(hcInfo.getEndDate()); |
| 183 | 0 | int endYear = cal.get(Calendar.YEAR); |
| 184 | 0 | if (endYear == currentYear) { |
| 185 | 0 | cal.setTime(hcInfo.getStartDate()); |
| 186 | 0 | int startYear = cal.get(Calendar.YEAR); |
| 187 | 0 | StringBuilder calName = new StringBuilder(); |
| 188 | 0 | if (startYear < endYear) { |
| 189 | 0 | calName.append(++startYear); |
| 190 | 0 | calName.append("-"); |
| 191 | |
} |
| 192 | 0 | calName.append(++endYear); |
| 193 | 0 | calName.append(" Holiday Calendar"); |
| 194 | 0 | form.setNewCalendarName(calName.toString()); |
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
} |
| 203 | |
} |
| 204 | |
|
| 205 | 0 | return super.start(form, result, request, response); |
| 206 | |
} |
| 207 | |
|
| 208 | |
@RequestMapping(method = RequestMethod.GET, params = "methodToCall=copyForNew") |
| 209 | |
public ModelAndView copyForNew( @ModelAttribute("KualiForm") HolidayCalendarForm form, BindingResult result, |
| 210 | |
HttpServletRequest request, HttpServletResponse response) { |
| 211 | 0 | HolidayCalendarInfo hcInfo = null; |
| 212 | |
|
| 213 | |
try { |
| 214 | 0 | String calendarId = request.getParameter(CalendarConstants.CALENDAR_ID); |
| 215 | 0 | if (calendarId == null || calendarId.trim().isEmpty()) { |
| 216 | 0 | hcInfo = getHolidayCalendarFormHelper(form).getNewestHolidayCalendar(); |
| 217 | |
} |
| 218 | |
else { |
| 219 | 0 | hcInfo = getHolidayCalendarFormHelper(form).getHolidayCalendar(calendarId); |
| 220 | |
} |
| 221 | |
} |
| 222 | 0 | catch (Exception e) { |
| 223 | 0 | GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, "Unexpected error; could not get holiday to copy: " + e.getMessage()); |
| 224 | 0 | } |
| 225 | |
|
| 226 | 0 | form.setHolidayCalendarInfo(hcInfo); |
| 227 | |
|
| 228 | 0 | return toCopy(form, result, request, response); |
| 229 | |
} |
| 230 | |
|
| 231 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=copy") |
| 232 | |
public ModelAndView copy( @ModelAttribute("KualiForm") HolidayCalendarForm form, BindingResult result, |
| 233 | |
HttpServletRequest request, HttpServletResponse response) { |
| 234 | 0 | restoreForm(form); |
| 235 | 0 | if ((null == form.getHolidayCalendarInfo()) || (null == form.getHolidayCalendarInfo().getId())) { |
| 236 | |
|
| 237 | 0 | GlobalVariables.getMessageMap().putError( KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, |
| 238 | |
"Unexpected error; the holiday to copy has been misplaced."); |
| 239 | 0 | return getUIFModelAndView(form); |
| 240 | |
} |
| 241 | |
|
| 242 | |
List<HolidayWrapper> newHolidays; |
| 243 | |
try { |
| 244 | 0 | newHolidays = getHolidayCalendarFormHelper(form).getHolidayWrappersForHolidayCalendar( |
| 245 | |
form.getHolidayCalendarInfo().getId()); |
| 246 | |
} |
| 247 | 0 | catch (Exception x) { |
| 248 | 0 | throw new RuntimeException(x); |
| 249 | 0 | } |
| 250 | |
|
| 251 | 0 | for (HolidayWrapper holidayWrapper : newHolidays) { |
| 252 | |
|
| 253 | 0 | holidayWrapper.getHolidayInfo().setId(null); |
| 254 | |
} |
| 255 | |
|
| 256 | 0 | form.setOrgHcId(form.getHolidayCalendarInfo().getId()); |
| 257 | 0 | form.getHolidayCalendarInfo().setId(null); |
| 258 | 0 | form.getHolidayCalendarInfo().setName(form.getNewCalendarName()); |
| 259 | 0 | form.getHolidayCalendarInfo().setStartDate(form.getNewCalendarStartDate()); |
| 260 | 0 | form.getHolidayCalendarInfo().setEndDate(form.getNewCalendarEndDate()); |
| 261 | 0 | form.getHolidayCalendarInfo().setStateKey(AtpServiceConstants.ATP_DRAFT_STATE_KEY); |
| 262 | 0 | form.getHolidayCalendarInfo().setDescr(CommonUtils.buildDesc(form.getNewCalendarName())); |
| 263 | 0 | form.setHolidays(newHolidays); |
| 264 | 0 | form.setHcId(null); |
| 265 | |
|
| 266 | 0 | return getUIFModelAndView(form, CalendarConstants.HOLIDAYCALENDAR_EDITPAGE); |
| 267 | |
} |
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
@RequestMapping(params = "methodToCall=search") |
| 273 | |
public ModelAndView search(@ModelAttribute("KualiForm") HolidayCalendarForm form, BindingResult result, |
| 274 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 275 | |
|
| 276 | 0 | String controllerPath = CalendarConstants.CALENDAR_SEARCH_CONTROLLER_PATH; |
| 277 | 0 | Properties urlParameters = new Properties(); |
| 278 | 0 | urlParameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.START_METHOD); |
| 279 | 0 | urlParameters.put(UifParameters.VIEW_ID, CalendarConstants.CALENDAR_SEARCH_VIEW); |
| 280 | 0 | urlParameters.put(CalendarConstants.CALENDAR_SEARCH_TYPE, CalendarConstants.HOLIDAYCALENDER); |
| 281 | 0 | return super.performRedirect(form,controllerPath, urlParameters); |
| 282 | |
} |
| 283 | |
|
| 284 | |
@RequestMapping(params = "methodToCall=toCreate") |
| 285 | |
public ModelAndView toCreate(@ModelAttribute("KualiForm") HolidayCalendarForm hcForm, BindingResult result, |
| 286 | |
HttpServletRequest request, HttpServletResponse response){ |
| 287 | 0 | hcForm.setHcId(null); |
| 288 | 0 | hcForm.setHolidayCalendarInfo( new HolidayCalendarInfo()); |
| 289 | 0 | hcForm.setHolidays(new ArrayList<HolidayWrapper>()); |
| 290 | 0 | return getUIFModelAndView(hcForm, CalendarConstants.HOLIDAYCALENDAR_EDITPAGE); |
| 291 | |
} |
| 292 | |
|
| 293 | |
private void restoreForm(HolidayCalendarForm hcForm){ |
| 294 | 0 | HolidayCalendarInfo hcalInfo = hcForm.getHolidayCalendarInfo(); |
| 295 | |
|
| 296 | 0 | if (StringUtils.isBlank(hcalInfo.getId()) && StringUtils.isNotBlank(hcForm.getOrgHcId())){ |
| 297 | |
try{ |
| 298 | 0 | getHolidayCalendar(hcForm.getOrgHcId(), hcForm); |
| 299 | 0 | hcForm.setHcId(hcForm.getOrgHcId()); |
| 300 | 0 | hcForm.setOrgHcId(null); |
| 301 | 0 | } catch (Exception ex) { |
| 302 | 0 | throw new RuntimeException("unable to getHolidayCalendar"); |
| 303 | 0 | } |
| 304 | |
} |
| 305 | 0 | } |
| 306 | |
|
| 307 | |
@RequestMapping(params = "methodToCall=toEdit") |
| 308 | |
public ModelAndView toEdit(@ModelAttribute("KualiForm") HolidayCalendarForm hcForm, BindingResult result, |
| 309 | |
HttpServletRequest request, HttpServletResponse response){ |
| 310 | 0 | restoreForm(hcForm); |
| 311 | 0 | return getUIFModelAndView(hcForm, CalendarConstants.HOLIDAYCALENDAR_EDITPAGE); |
| 312 | |
} |
| 313 | |
|
| 314 | |
@RequestMapping(params = "methodToCall=toCopy") |
| 315 | |
public ModelAndView toCopy(@ModelAttribute("KualiForm") HolidayCalendarForm hcForm, BindingResult result, |
| 316 | |
HttpServletRequest request, HttpServletResponse response){ |
| 317 | 0 | hcForm.setNewCalendarName(null); |
| 318 | 0 | hcForm.setNewCalendarStartDate(null); |
| 319 | 0 | hcForm.setNewCalendarEndDate(null); |
| 320 | 0 | return copy(hcForm, result, request, response); |
| 321 | |
} |
| 322 | |
|
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
@RequestMapping(params = "methodToCall=save") |
| 327 | |
public ModelAndView save(@ModelAttribute("KualiForm") HolidayCalendarForm hcForm, BindingResult result, |
| 328 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 329 | 0 | return updateHolidayCalendarForm(hcForm, CalendarConstants.MSG_INFO_HOLIDAY_CALENDAR_SAVED, |
| 330 | |
CalendarConstants.UPDATE_SAVE); |
| 331 | |
} |
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
@RequestMapping(params = "methodToCall=delete") |
| 337 | |
public ModelAndView delete(@ModelAttribute("KualiForm") HolidayCalendarForm hcForm, BindingResult result, |
| 338 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 339 | 0 | getHolidayCalendarFormHelper(hcForm).deleteHolidayCalendar(hcForm.getHolidayCalendarInfo().getId()); |
| 340 | 0 | Properties urlParameters = new Properties(); |
| 341 | 0 | urlParameters.put("viewId", CalendarConstants.ENROLLMENT_HOME_VIEW); |
| 342 | 0 | urlParameters.put("methodToCall", "start"); |
| 343 | 0 | return performRedirect(hcForm, request.getRequestURL().toString(), urlParameters); |
| 344 | |
} |
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
@RequestMapping(params = "methodToCall=makeOfficial") |
| 350 | |
public ModelAndView makeOfficial(@ModelAttribute("KualiForm") HolidayCalendarForm hcForm, BindingResult result, |
| 351 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 352 | 0 | hcForm.getHolidayCalendarInfo().setStateKey(AtpServiceConstants.ATP_OFFICIAL_STATE_KEY); |
| 353 | 0 | return updateHolidayCalendarForm(hcForm, CalendarConstants.MSG_INFO_HOLIDAY_CALENDAR_OFFICIAL, |
| 354 | |
CalendarConstants.UPDATE_MAKEOFFICIAL); |
| 355 | |
} |
| 356 | |
|
| 357 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteHoliday") |
| 358 | |
public ModelAndView deleteHoliday(@ModelAttribute("KualiForm") HolidayCalendarForm hcForm, BindingResult result, |
| 359 | |
HttpServletRequest request, HttpServletResponse response) { |
| 360 | |
|
| 361 | 0 | String selectedCollectionPath = hcForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH); |
| 362 | 0 | if (StringUtils.isBlank(selectedCollectionPath)) { |
| 363 | 0 | throw new RuntimeException("unable to determine the selected collection path"); |
| 364 | |
} |
| 365 | |
|
| 366 | 0 | int selectedLineIndex = -1; |
| 367 | 0 | String selectedLine = hcForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); |
| 368 | 0 | if (StringUtils.isNotBlank(selectedLine)) { |
| 369 | 0 | selectedLineIndex = Integer.parseInt(selectedLine); |
| 370 | |
} |
| 371 | |
|
| 372 | 0 | if (selectedLineIndex == -1) { |
| 373 | 0 | throw new RuntimeException("unable to determine the selected line index"); |
| 374 | |
} |
| 375 | |
|
| 376 | |
try{ |
| 377 | 0 | getHolidayCalendarFormHelper(hcForm).deleteHoliday(selectedLineIndex,hcForm); |
| 378 | 0 | }catch (Exception e){ |
| 379 | 0 | GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, "Error deleting holiday - " + e.getMessage()); |
| 380 | 0 | e.printStackTrace(); |
| 381 | 0 | } |
| 382 | |
|
| 383 | 0 | return updateComponent(hcForm, result, request, response); |
| 384 | |
} |
| 385 | |
|
| 386 | |
private ModelAndView updateHolidayCalendarForm(HolidayCalendarForm hcForm, String updateMsg, String from) throws Exception { |
| 387 | |
|
| 388 | 0 | getHolidayCalendarFormHelper(hcForm).validateHolidayCalendar(hcForm); |
| 389 | 0 | getHolidayCalendarFormHelper(hcForm).populateHolidayCalendarDefaults(hcForm); |
| 390 | |
|
| 391 | 0 | if (GlobalVariables.getMessageMap().getErrorCount() > 0){ |
| 392 | 0 | return getUIFModelAndView(hcForm, CalendarConstants.HOLIDAYCALENDAR_EDITPAGE); |
| 393 | |
} |
| 394 | |
|
| 395 | 0 | if (!isValidHolidayCalendar(hcForm.getHolidayCalendarInfo())) { |
| 396 | 0 | return getUIFModelAndView(hcForm, CalendarConstants.HOLIDAYCALENDAR_EDITPAGE); |
| 397 | |
} |
| 398 | |
|
| 399 | |
|
| 400 | 0 | getHolidayCalendarFormHelper(hcForm).saveHolidayCalendar(hcForm); |
| 401 | |
|
| 402 | 0 | HolidayCalendarInfo hCalInfo = hcForm.getHolidayCalendarInfo(); |
| 403 | 0 | hcForm.setAdminOrgName(getAdminOrgNameById(hCalInfo.getAdminOrgId())); |
| 404 | 0 | hcForm.setStateName(getHolidayCalendarFormHelper(hcForm).getHolidayCalendarState(hCalInfo.getStateKey())); |
| 405 | 0 | hcForm.setNewCalendar(false); |
| 406 | 0 | hcForm.setOfficialCalendar(hCalInfo.getStateKey().equals(AcademicCalendarServiceConstants.ACADEMIC_CALENDAR_OFFICIAL_STATE_KEY)); |
| 407 | 0 | hcForm.setHcId(hCalInfo.getId()); |
| 408 | |
|
| 409 | |
|
| 410 | 0 | Collections.sort(hcForm.getHolidays()); |
| 411 | |
|
| 412 | 0 | GlobalVariables.getMessageMap().putInfo("holidayCalendarInfo.name", updateMsg, hCalInfo.getName()); |
| 413 | |
|
| 414 | 0 | if (from.equals(CalendarConstants.UPDATE_MAKEOFFICIAL)) { |
| 415 | 0 | return getUIFModelAndView(hcForm, CalendarConstants.HOLIDAYCALENDAR_VIEWPAGE); |
| 416 | |
} |
| 417 | |
else { |
| 418 | 0 | return getUIFModelAndView(hcForm, CalendarConstants.HOLIDAYCALENDAR_EDITPAGE); |
| 419 | |
} |
| 420 | |
} |
| 421 | |
|
| 422 | |
private boolean isValidHolidayCalendar(HolidayCalendarInfo hc)throws Exception { |
| 423 | 0 | boolean valid = true; |
| 424 | 0 | Date startDate = hc.getStartDate(); |
| 425 | 0 | Date endDate = hc.getEndDate(); |
| 426 | |
|
| 427 | 0 | if(startDate.after(endDate)) { |
| 428 | 0 | GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, "ERROR: " + hc.getName() + "start date should not be later than the end date."); |
| 429 | 0 | valid = false; |
| 430 | |
} |
| 431 | |
|
| 432 | 0 | return valid; |
| 433 | |
} |
| 434 | |
|
| 435 | |
private void getHolidayCalendar(String hcId, HolidayCalendarForm hcForm) throws Exception { |
| 436 | 0 | HolidayCalendarInfo hcInfo = getHolidayCalendarFormHelper(hcForm).getHolidayCalendar(hcId); |
| 437 | 0 | hcForm.setHolidayCalendarInfo(hcInfo); |
| 438 | 0 | hcForm.setAdminOrgName(getAdminOrgNameById(hcInfo.getAdminOrgId())); |
| 439 | 0 | hcForm.setStateName(getHolidayCalendarFormHelper(hcForm).getHolidayCalendarState(hcInfo.getStateKey())); |
| 440 | 0 | hcForm.setNewCalendar(false); |
| 441 | 0 | hcForm.setOfficialCalendar(hcInfo.getStateKey().equals(AcademicCalendarServiceConstants.ACADEMIC_CALENDAR_OFFICIAL_STATE_KEY)); |
| 442 | |
|
| 443 | 0 | List<HolidayWrapper> holidays = |
| 444 | |
getHolidayCalendarFormHelper(hcForm).getHolidayWrappersForHolidayCalendar(hcInfo.getId()); |
| 445 | 0 | Collections.sort(holidays); |
| 446 | 0 | hcForm.setHolidays(holidays); |
| 447 | 0 | } |
| 448 | |
|
| 449 | |
|
| 450 | |
|
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
|
| 457 | |
|
| 458 | |
|
| 459 | |
private List<String> getHolidayIds(HolidayCalendarForm hcForm) throws Exception{ |
| 460 | |
|
| 461 | 0 | String hcId = hcForm.getHolidayCalendarInfo().getId(); |
| 462 | 0 | List<HolidayWrapper> holidays = getHolidayCalendarFormHelper(hcForm).getHolidayWrappersForHolidayCalendar(hcId); |
| 463 | 0 | List<String> holidayIds = new ArrayList<String>(); |
| 464 | |
|
| 465 | 0 | if(holidays != null && !holidays.isEmpty()){ |
| 466 | 0 | for(HolidayWrapper holiday : holidays){ |
| 467 | 0 | holidayIds.add(holiday.getHolidayInfo().getId()); |
| 468 | |
} |
| 469 | |
} |
| 470 | |
|
| 471 | 0 | return holidayIds; |
| 472 | |
} |
| 473 | |
|
| 474 | |
|
| 475 | |
|
| 476 | |
|
| 477 | |
|
| 478 | |
|
| 479 | |
|
| 480 | |
|
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | |
|
| 487 | |
|
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | |
|
| 492 | |
|
| 493 | |
|
| 494 | |
|
| 495 | |
|
| 496 | |
|
| 497 | |
|
| 498 | |
|
| 499 | |
|
| 500 | |
|
| 501 | |
|
| 502 | |
|
| 503 | |
|
| 504 | |
private String getAdminOrgNameById(String id){ |
| 505 | |
|
| 506 | 0 | String adminOrgName = null; |
| 507 | 0 | Map<String, String> allHcOrgs = new HashMap<String, String>(); |
| 508 | 0 | allHcOrgs.put("102", "Registrar's Office"); |
| 509 | |
|
| 510 | 0 | if(allHcOrgs.containsKey(id)){ |
| 511 | 0 | adminOrgName = allHcOrgs.get(id); |
| 512 | |
} |
| 513 | |
|
| 514 | 0 | return adminOrgName; |
| 515 | |
} |
| 516 | |
|
| 517 | |
private AcademicCalendarViewHelperService getHolidayCalendarFormHelper(HolidayCalendarForm hcForm) { |
| 518 | 0 | if (hcForm.getView() != null && hcForm.getView().getViewHelperServiceClassName() != null){ |
| 519 | 0 | return (AcademicCalendarViewHelperService)hcForm.getView().getViewHelperService(); |
| 520 | |
} else { |
| 521 | 0 | return (AcademicCalendarViewHelperService)hcForm.getPostedView().getViewHelperService(); |
| 522 | |
} |
| 523 | |
} |
| 524 | |
|
| 525 | |
} |