Coverage Report - org.kuali.student.enrollment.class2.acal.controller.HolidayCalendarController
 
Classes in this File Line Coverage Branch Coverage Complexity
HolidayCalendarController
0%
0/182
0%
0/66
3.318
 
 1  
 /**
 2  
  * Copyright 2012 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 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  
  * This class implement controller for HolidayCalendar
 49  
  *
 50  
  * @author Kuali Student Team
 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 getUIFModelAndView(form);
 80  
                             }
 81  0
                         }
 82  
                     }
 83  
                 }
 84  
                 else {
 85  0
                     return getUIFModelAndView(form);
 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  
 //        Date startDate = holiday.getStartDate();
 96  
 //        Date endDate = holiday.getEndDate();
 97  
 //        String startTime = holiday.getStartTime();
 98  
 //        String endTime = holiday.getEndTime();
 99  
 //        HolidayInfo holidayInfo = holiday.getHolidayInfo();
 100  
 //
 101  
 //        if (endDate == null)  {
 102  
 //            holidayInfo.setIsDateRange(false);
 103  
 //
 104  
 //            if(StringUtils.isBlank(startTime)){
 105  
 //                holidayInfo.setIsAllDay(true);
 106  
 //            }
 107  
 //        }
 108  
 //        else {
 109  
 //            int timeDiff = startDate.compareTo(endDate);
 110  
 //            if(timeDiff > 0) {
 111  
 //                //TODO:change to  putError, when error reload fixed
 112  
 //                GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, "ERROR: The adding holiday start date should not be later than the end date.");
 113  
 //                return false;
 114  
 //            }else if (timeDiff == 0 ) {
 115  
 //                holidayInfo.setIsDateRange(false);
 116  
 //            }else {
 117  
 //                holidayInfo.setIsDateRange(true);
 118  
 //            }
 119  
 //
 120  
 //            if (StringUtils.isBlank(startTime) & StringUtils.isBlank(endTime)) {
 121  
 //                holidayInfo.setIsAllDay(true);
 122  
 //            }else if(StringUtils.isNotEmpty(startTime)){
 123  
 //                holidayInfo.setIsAllDay(false);
 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  
             // do some calculations on probable values for the new calendar
 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  
                 /* force user to enter dates
 196  
                 cal.add(Calendar.YEAR, 1);
 197  
                 form.setNewCalendarEndDate(cal.getTime());
 198  
                 cal.setTime(hcInfo.getStartDate());
 199  
                 cal.add(Calendar.YEAR, 1);
 200  
                 form.setNewCalendarStartDate(cal.getTime());
 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  
             // this should never happen
 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  
             // decision #14, copy over all information (types, dates, times, flags, etc) for Holidays from the source calendar
 253  0
             holidayWrapper.getHolidayInfo().setId(null); // else the old rcd will be updated
 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  
         // after changing the state in the info back to the default, reset the isOfficialCalendar flag on the form
 263  0
         form.setOfficialCalendar(false);
 264  0
         form.getHolidayCalendarInfo().setDescr(CommonUtils.buildDesc(form.getNewCalendarName()));
 265  0
         form.setHolidays(newHolidays);
 266  0
         form.setHcId(null);
 267  
 
 268  0
         return getUIFModelAndView(form, CalendarConstants.HOLIDAYCALENDAR_EDITPAGE);
 269  
     }
 270  
 
 271  
     /**
 272  
      * redirect to search Calendar page
 273  
      */
 274  
     @RequestMapping(params = "methodToCall=search")
 275  
     public ModelAndView search(@ModelAttribute("KualiForm") HolidayCalendarForm form, BindingResult result,
 276  
                                HttpServletRequest request, HttpServletResponse response) throws Exception {
 277  
 
 278  0
         String controllerPath = CalendarConstants.CALENDAR_SEARCH_CONTROLLER_PATH;
 279  0
         Properties urlParameters = new Properties();
 280  0
         urlParameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.START_METHOD);
 281  0
         urlParameters.put(UifParameters.VIEW_ID, CalendarConstants.CALENDAR_SEARCH_VIEW);
 282  0
         urlParameters.put(CalendarConstants.CALENDAR_SEARCH_TYPE, CalendarConstants.HOLIDAYCALENDER);
 283  0
         return super.performRedirect(form,controllerPath, urlParameters);
 284  
     }
 285  
 
 286  
     @RequestMapping(params = "methodToCall=toCreate")
 287  
     public ModelAndView toCreate(@ModelAttribute("KualiForm") HolidayCalendarForm hcForm, BindingResult result,
 288  
                                               HttpServletRequest request, HttpServletResponse response){
 289  0
         hcForm.setHcId(null);
 290  0
         hcForm.setHolidayCalendarInfo( new HolidayCalendarInfo());
 291  0
         hcForm.setHolidays(new ArrayList<HolidayWrapper>());
 292  0
         return getUIFModelAndView(hcForm, CalendarConstants.HOLIDAYCALENDAR_EDITPAGE);
 293  
     }
 294  
 
 295  
     private void restoreForm(HolidayCalendarForm hcForm){
 296  0
         HolidayCalendarInfo hcalInfo = hcForm.getHolidayCalendarInfo();
 297  
 
 298  0
         if (StringUtils.isBlank(hcalInfo.getId()) && StringUtils.isNotBlank(hcForm.getOrgHcId())){
 299  
             try{
 300  0
                 getHolidayCalendar(hcForm.getOrgHcId(), hcForm);
 301  0
                 hcForm.setHcId(hcForm.getOrgHcId());
 302  0
                 hcForm.setOrgHcId(null);
 303  0
             } catch (Exception ex) {
 304  0
                  throw new RuntimeException("unable to getHolidayCalendar");
 305  0
             }
 306  
         }
 307  0
     }
 308  
 
 309  
     @RequestMapping(params = "methodToCall=toEdit")
 310  
     public ModelAndView toEdit(@ModelAttribute("KualiForm") HolidayCalendarForm hcForm, BindingResult result,
 311  
                                               HttpServletRequest request, HttpServletResponse response){
 312  0
         restoreForm(hcForm);
 313  0
         return getUIFModelAndView(hcForm, CalendarConstants.HOLIDAYCALENDAR_EDITPAGE);
 314  
     }
 315  
 
 316  
     @RequestMapping(params = "methodToCall=toCopy")
 317  
     public ModelAndView toCopy(@ModelAttribute("KualiForm") HolidayCalendarForm hcForm, BindingResult result,
 318  
                                               HttpServletRequest request, HttpServletResponse response){
 319  0
         hcForm.setNewCalendarName(null);
 320  0
         hcForm.setNewCalendarStartDate(null);
 321  0
         hcForm.setNewCalendarEndDate(null);
 322  0
         hcForm.setNewCalendar(true);
 323  0
         return copy(hcForm, result, request, response);
 324  
     }
 325  
 
 326  
      /**
 327  
      * Method used to save HC
 328  
      */
 329  
     @RequestMapping(params = "methodToCall=save")
 330  
     public ModelAndView save(@ModelAttribute("KualiForm") HolidayCalendarForm hcForm, BindingResult result,
 331  
                                               HttpServletRequest request, HttpServletResponse response) throws Exception {
 332  0
         return updateHolidayCalendarForm(hcForm, CalendarConstants.MSG_INFO_HOLIDAY_CALENDAR_SAVED,
 333  
                 CalendarConstants.UPDATE_SAVE);
 334  
     }
 335  
 
 336  
      /**
 337  
      * Method used to delete HC
 338  
      */
 339  
     @RequestMapping(params = "methodToCall=delete")
 340  
     public ModelAndView delete(@ModelAttribute("KualiForm") HolidayCalendarForm hcForm, BindingResult result,
 341  
                                               HttpServletRequest request, HttpServletResponse response) throws Exception {
 342  0
         getHolidayCalendarFormHelper(hcForm).deleteHolidayCalendar(hcForm.getHolidayCalendarInfo().getId());
 343  0
         Properties urlParameters = new  Properties();
 344  0
         urlParameters.put("viewId", CalendarConstants.ENROLLMENT_HOME_VIEW);
 345  0
         urlParameters.put("methodToCall", "start");
 346  0
         return performRedirect(hcForm, request.getRequestURL().toString(), urlParameters);
 347  
     }
 348  
 
 349  
     /**
 350  
      * Method used to set HC official
 351  
      */
 352  
      @RequestMapping(params = "methodToCall=makeOfficial")
 353  
      public ModelAndView makeOfficial(@ModelAttribute("KualiForm") HolidayCalendarForm hcForm, BindingResult result,
 354  
                                                HttpServletRequest request, HttpServletResponse response) throws Exception {
 355  0
          hcForm.getHolidayCalendarInfo().setStateKey(AtpServiceConstants.ATP_OFFICIAL_STATE_KEY);
 356  0
          return updateHolidayCalendarForm(hcForm, CalendarConstants.MSG_INFO_HOLIDAY_CALENDAR_OFFICIAL,
 357  
                  CalendarConstants.UPDATE_MAKEOFFICIAL);
 358  
      }
 359  
 
 360  
     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteHoliday")
 361  
     public ModelAndView deleteHoliday(@ModelAttribute("KualiForm") HolidayCalendarForm hcForm, BindingResult result,
 362  
                                         HttpServletRequest request, HttpServletResponse response) {
 363  
 
 364  0
         String selectedCollectionPath = hcForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
 365  0
         if (StringUtils.isBlank(selectedCollectionPath)) {
 366  0
             throw new RuntimeException("unable to determine the selected collection path");
 367  
         }
 368  
 
 369  0
         int selectedLineIndex = -1;
 370  0
         String selectedLine = hcForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
 371  0
         if (StringUtils.isNotBlank(selectedLine)) {
 372  0
             selectedLineIndex = Integer.parseInt(selectedLine);
 373  
         }
 374  
 
 375  0
         if (selectedLineIndex == -1) {
 376  0
             throw new RuntimeException("unable to determine the selected line index");
 377  
         }
 378  
 
 379  
         try{
 380  0
           getHolidayCalendarFormHelper(hcForm).deleteHoliday(selectedLineIndex,hcForm);
 381  0
         }catch (Exception e){
 382  0
             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, "Error deleting holiday - " + e.getMessage());
 383  0
             e.printStackTrace();
 384  0
         }
 385  
 
 386  0
         return getUIFModelAndView(hcForm);
 387  
     }
 388  
 
 389  
     private ModelAndView updateHolidayCalendarForm(HolidayCalendarForm hcForm, String updateMsg, String from) throws Exception {
 390  
 
 391  0
         getHolidayCalendarFormHelper(hcForm).validateHolidayCalendar(hcForm);
 392  0
         getHolidayCalendarFormHelper(hcForm).populateHolidayCalendarDefaults(hcForm);
 393  
 
 394  0
         if (GlobalVariables.getMessageMap().getErrorCount() > 0){
 395  0
            return getUIFModelAndView(hcForm, CalendarConstants.HOLIDAYCALENDAR_EDITPAGE);
 396  
         }
 397  
 
 398  0
         if (!isValidHolidayCalendar(hcForm.getHolidayCalendarInfo())) {
 399  0
            return getUIFModelAndView(hcForm, CalendarConstants.HOLIDAYCALENDAR_EDITPAGE);
 400  
         }
 401  
 
 402  
         // passed edits, so update the holiday calendar
 403  0
         getHolidayCalendarFormHelper(hcForm).saveHolidayCalendar(hcForm);
 404  
 
 405  0
         HolidayCalendarInfo hCalInfo = hcForm.getHolidayCalendarInfo();
 406  0
         hcForm.setAdminOrgName(getAdminOrgNameById(hCalInfo.getAdminOrgId()));
 407  0
         hcForm.setStateName(getHolidayCalendarFormHelper(hcForm).getHolidayCalendarState(hCalInfo.getStateKey()));
 408  0
         hcForm.setNewCalendar(false);
 409  0
         hcForm.setOfficialCalendar(hCalInfo.getStateKey().equals(AcademicCalendarServiceConstants.ACADEMIC_CALENDAR_OFFICIAL_STATE_KEY));
 410  0
         hcForm.setHcId(hCalInfo.getId());
 411  
 
 412  
         // sort holidays again, in case any were added
 413  0
         Collections.sort(hcForm.getHolidays());
 414  
 
 415  0
         GlobalVariables.getMessageMap().putInfo("holidayCalendarInfo.name", updateMsg, hCalInfo.getName());
 416  
 
 417  0
         if (from.equals(CalendarConstants.UPDATE_MAKEOFFICIAL)) {
 418  0
             return getUIFModelAndView(hcForm, CalendarConstants.HOLIDAYCALENDAR_VIEWPAGE);
 419  
         }
 420  
         else {
 421  0
             return getUIFModelAndView(hcForm, CalendarConstants.HOLIDAYCALENDAR_EDITPAGE);
 422  
         }
 423  
     }
 424  
 
 425  
     private boolean isValidHolidayCalendar(HolidayCalendarInfo hc)throws Exception {
 426  0
         boolean valid = true; //CommonUtils.isValidDateRange(hc.getStartDate(),hc.getEndDate());
 427  0
         Date startDate = hc.getStartDate();
 428  0
         Date endDate = hc.getEndDate();
 429  
 
 430  0
         if(startDate.after(endDate)) {
 431  0
             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, "ERROR: " +  hc.getName() + "start date should not be later than the end date.");
 432  0
             valid = false;
 433  
         }
 434  
 
 435  0
         return valid;
 436  
     }
 437  
 
 438  
     private void getHolidayCalendar(String hcId, HolidayCalendarForm hcForm) throws Exception {
 439  0
         HolidayCalendarInfo hcInfo = getHolidayCalendarFormHelper(hcForm).getHolidayCalendar(hcId);
 440  0
         hcForm.setHolidayCalendarInfo(hcInfo);
 441  0
         hcForm.setAdminOrgName(getAdminOrgNameById(hcInfo.getAdminOrgId()));
 442  0
         hcForm.setStateName(getHolidayCalendarFormHelper(hcForm).getHolidayCalendarState(hcInfo.getStateKey()));
 443  0
         hcForm.setNewCalendar(false);
 444  0
         hcForm.setOfficialCalendar(hcInfo.getStateKey().equals(AcademicCalendarServiceConstants.ACADEMIC_CALENDAR_OFFICIAL_STATE_KEY));
 445  
         //List<HolidayWrapper> holidays = getHolidayCalendarFormHelper(hcForm).getHolidaysForHolidayCalendar(hcForm);
 446  0
         List<HolidayWrapper> holidays =
 447  
                 getHolidayCalendarFormHelper(hcForm).getHolidayWrappersForHolidayCalendar(hcInfo.getId());
 448  0
         Collections.sort(holidays);
 449  0
         hcForm.setHolidays(holidays);
 450  0
     }
 451  
 
 452  
     private String getAdminOrgNameById(String id){
 453  
         //TODO: hard-coded for now, going to call OrgService
 454  0
         String adminOrgName = null;
 455  0
         Map<String, String> allHcOrgs = new HashMap<String, String>();
 456  0
         allHcOrgs.put("102", "Registrar's Office");
 457  
 
 458  0
         if(allHcOrgs.containsKey(id)){
 459  0
             adminOrgName = allHcOrgs.get(id);
 460  
         }
 461  
 
 462  0
         return adminOrgName;
 463  
     }
 464  
 
 465  
     private AcademicCalendarViewHelperService getHolidayCalendarFormHelper(HolidayCalendarForm hcForm) {
 466  0
         if (hcForm.getView() != null && hcForm.getView().getViewHelperServiceClass() != null){
 467  0
             return (AcademicCalendarViewHelperService)hcForm.getView().getViewHelperService();
 468  
         } else {
 469  0
             return (AcademicCalendarViewHelperService)hcForm.getPostedView().getViewHelperService();
 470  
         }
 471  
     }
 472  
 
 473  
 }