001package org.kuali.ole.deliver.calendar.controller; 002 003import org.apache.log4j.Logger; 004import org.kuali.ole.OLEConstants; 005import org.kuali.ole.deliver.calendar.bo.*; 006import org.kuali.ole.deliver.calendar.service.DateUtil; 007import org.kuali.ole.deliver.calendar.service.impl.OleCalendarDocumentServiceImpl; 008import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; 009import org.kuali.rice.krad.maintenance.MaintenanceDocument; 010import org.kuali.rice.krad.maintenance.MaintenanceUtils; 011import org.kuali.rice.krad.service.MaintenanceDocumentService; 012import org.kuali.rice.krad.util.GlobalVariables; 013import org.kuali.rice.krad.util.KRADConstants; 014import org.kuali.rice.krad.web.controller.MaintenanceDocumentController; 015import org.kuali.rice.krad.web.form.DocumentFormBase; 016import org.kuali.rice.krad.web.form.MaintenanceDocumentForm; 017import org.springframework.stereotype.Controller; 018import org.springframework.validation.BindingResult; 019import org.springframework.web.bind.annotation.ModelAttribute; 020import org.springframework.web.bind.annotation.RequestMapping; 021import org.springframework.web.servlet.ModelAndView; 022 023import javax.servlet.http.HttpServletRequest; 024import javax.servlet.http.HttpServletResponse; 025import java.sql.Timestamp; 026import java.util.*; 027 028/** 029 * Created with IntelliJ IDEA. 030 * User: arjuns 031 * Date: 7/21/13 032 * Time: 1:32 PM 033 * To change this template use File | Settings | File Templates. 034 */ 035@Controller 036@RequestMapping(value = "/OleCalendarController") 037public class OleCalendarController extends MaintenanceDocumentController { 038 039 private static final Logger LOG = Logger.getLogger(OleCalendarController.class); 040 041 042 /** 043 * Setups a new <code>MaintenanceDocumentView</code> with the edit maintenance 044 * action 045 */ 046 @RequestMapping(params = "methodToCall=" + KRADConstants.Maintenance.METHOD_TO_CALL_EDIT) 047 public ModelAndView maintenanceEdit(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result, 048 HttpServletRequest request, HttpServletResponse response) throws Exception { 049 050 051 return super.maintenanceEdit(form,result,request,response); 052 } 053 054 055 056 @RequestMapping(params = "methodToCall=" + "maintenanceDelete") 057 public ModelAndView maintenanceDelete(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result, 058 HttpServletRequest request, HttpServletResponse response) throws Exception { 059 LOG.debug(" Inside maintenanceDelete "); 060 setupMaintenanceForDelete(form, request, OLEConstants.OlePatron.OLE_PATRON_DELETE); 061 return getUIFModelAndView(form); 062 } 063 064 /** 065 * This method returns the instance of olePatronMaintenanceDocumentService 066 * 067 * @return olePatronMaintenanceDocumentService(MaintenanceDocumentService) 068 */ 069 @Override 070 protected MaintenanceDocumentService getMaintenanceDocumentService() { 071 return GlobalResourceLoader.getService(OLEConstants.OLE_CALENDAR_DOC_SERVICE); 072 } 073 074 /** 075 * This method populates confirmation to delete the document. 076 * 077 * @param form 078 * @param request 079 * @param maintenanceAction 080 */ 081 protected void setupMaintenanceForDelete(MaintenanceDocumentForm form, HttpServletRequest request, String maintenanceAction) { 082 LOG.debug(" Inside setupMaintenanceForDelete "); 083 MaintenanceDocument document = form.getDocument(); 084 if (document == null) { 085 document = getMaintenanceDocumentService() 086 .setupNewMaintenanceDocument(form.getDataObjectClassName(), form.getDocTypeName(), 087 maintenanceAction); 088 089 form.setDocument(document); 090 form.setDocTypeName(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName()); 091 } 092 093 form.setMaintenanceAction(maintenanceAction); 094 OleCalendarDocumentServiceImpl oleCalendarDocumentService = (OleCalendarDocumentServiceImpl) getMaintenanceDocumentService(); 095 oleCalendarDocumentService.setupMaintenanceObjectForDelete(document, maintenanceAction, request.getParameterMap()); 096 MaintenanceUtils.checkForLockingDocument(document, false); 097 } 098 099 /** 100 * Performs the blanket approve workflow action on the form document instance 101 * 102 * @param form - document form base containing the document instance that will be blanket approved 103 * @return ModelAndView 104 */ 105 @RequestMapping(params = "methodToCall=blanketApprove") 106 public ModelAndView blanketApprove(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, 107 HttpServletRequest request, HttpServletResponse response) throws Exception { 108 109 LOG.debug(" Inside route method of patron maintenance controller "); 110 ModelAndView modelAndView; 111 MaintenanceDocumentForm mainForm = (MaintenanceDocumentForm) form; 112 MaintenanceDocument document = (MaintenanceDocument) form.getDocument(); 113 OleCalendar oleCalendar = (OleCalendar) document.getNewMaintainableObject().getDataObject(); 114 boolean isNew = document.isNew(); 115 generalInfoValidation(oleCalendar, isNew); 116 ModelAndView modelAndView1 = super.blanketApprove(mainForm, result, request, response);//changed 117 assignEndDate(oleCalendar); 118 convert12HrsFormat(document); 119 120 121 return modelAndView1; 122 } 123 124 125 @RequestMapping(params = "methodToCall=calendarPopUp") 126 public ModelAndView calendarPopUp(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, 127 HttpServletRequest request, HttpServletResponse response) { 128 MaintenanceDocumentForm mainForm = (MaintenanceDocumentForm) form; 129 MaintenanceDocument document = (MaintenanceDocument) form.getDocument(); 130 OleCalendar oleCalendar = (OleCalendar) document.getNewMaintainableObject().getDataObject(); 131 oleCalendar.setEndDateNoMessage(null); 132 oleCalendar.setEndDateYesMessage(null); 133 oleCalendar.setEndDateYesFlag(false); 134 oleCalendar.setEndDateNoFlag(false); 135 oleCalendar.setMessage(""); 136 OleCalendar calendar = null; 137 String groupId = oleCalendar.getCalendarGroupId(); 138 Map map = new HashMap(); 139 map.put("calendarGroupId", groupId); 140 Collection<OleCalendar> calendars = getBusinessObjectService().findMatching(OleCalendar.class, map); 141 int cseq = 0; 142 for (OleCalendar oleCalendar1 : calendars) { 143 if (cseq < Integer.parseInt(oleCalendar1.getChronologicalSequence())) { 144 cseq = Integer.parseInt(oleCalendar1.getChronologicalSequence()); 145 } 146 } 147 if (oleCalendar.getCalendarId() != null && !oleCalendar.getCalendarId().equals("") && oleCalendar.getChronologicalSequence() != null && !oleCalendar.getChronologicalSequence().equals("")) { //for edit 148 Map calMap = new HashMap(); 149 calMap.put("calendarId", oleCalendar.getCalendarId()); 150 //map.put("calendarGroupId", groupId); 151 calendar = getBusinessObjectService().findByPrimaryKey(OleCalendar.class, calMap); 152 String beginDate = null; 153 String beginDateDataBase = null; 154 String endDate = null; 155 String endDateDataBase = null; 156 if (cseq != Integer.parseInt(oleCalendar.getChronologicalSequence())) { 157 if (oleCalendar.getEndDate() != null && oleCalendar.getEndDate().toString().contains(" ")) { 158 endDate = oleCalendar.getEndDate().toString().split(" ")[0]; 159 } 160 if (oleCalendar.getBeginDate() != null && oleCalendar.getBeginDate().toString().contains(" ")) { 161 beginDate = oleCalendar.getBeginDate().toString().split(" ")[0]; 162 } 163 if (calendar.getEndDate() != null && calendar.getEndDate().toString().contains(" ")) { 164 endDateDataBase = calendar.getEndDate().toString().split(" ")[0]; 165 } 166 if (calendar.getBeginDate() != null && calendar.getBeginDate().toString().contains(" ")) { 167 beginDateDataBase = calendar.getBeginDate().toString().split(" ")[0]; 168 } 169 if (beginDate != null && beginDateDataBase != null && !beginDate.equals(beginDateDataBase)) { 170 oleCalendar.setMessage("This Calendar End-Date cannot be edited"); 171 } 172 if (endDate != null && endDateDataBase != null && !endDate.equals(endDateDataBase)) { 173 oleCalendar.setMessage("This Calendar End-Date cannot be edited"); 174 } 175 } 176 if (oleCalendar.getMessage().equals("This Calendar End-Date cannot be edited")) { 177 178 oleCalendar.setBeginDate(calendar.getBeginDate()); 179 oleCalendar.setEndDate(calendar.getEndDate()); 180 181 } 182 } 183 184 if (oleCalendar.getChronologicalSequence() != null && !oleCalendar.getChronologicalSequence().equals("") && oleCalendar.getEndDate()!=null) { 185 if (cseq == 0 || cseq == Integer.parseInt(oleCalendar.getChronologicalSequence())) { 186 oleCalendar.setEndDateYesMessage("By entering an End Date this calendar will become inactive and there is no future calendar."); 187 oleCalendar.setEndDateYesFlag(true); 188 } 189 } 190 if (oleCalendar.getChronologicalSequence().equals("")&& oleCalendar.getEndDate()!=null) { 191 oleCalendar.setEndDateYesMessage("By entering an End Date this calendar will become inactive and there is no future calendar."); 192 oleCalendar.setEndDateYesFlag(true); 193 } 194 195 if (calendars.size() >= 1 && (oleCalendar.getCalendarId() == null || oleCalendar.getCalendarId().equals(""))) { 196 oleCalendar.setEndDateNoMessage("The Previous calendars End-Date will be changed to ensure no gaps are created."); 197 oleCalendar.setEndDateNoFlag(true); 198 } 199 MaintenanceUtils.checkForLockingDocument(document, false); 200 return getUIFModelAndView(mainForm); 201 } 202 203 @RequestMapping(params = "methodToCall=cancelOperation") 204 public ModelAndView cancelOperation(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, 205 HttpServletRequest request, HttpServletResponse response) { 206 MaintenanceDocumentForm mainForm = (MaintenanceDocumentForm) form; 207 MaintenanceDocument maintenanceDocument = (MaintenanceDocument)mainForm.getDocument(); 208 OleCalendar oleCalendar = (OleCalendar)maintenanceDocument.getNewMaintainableObject().getDataObject(); 209 oleCalendar.setCancelOperationFlag(true); 210 oleCalendar.setCancelOperationEndDateFlag(true); 211 return getUIFModelAndView(mainForm); 212 } 213 214 /** 215 * This method returns the instance of olePatronMaintenanceDocumentService 216 * 217 * @return olePatronMaintenanceDocumentService(MaintenanceDocumentService) 218 */ 219 @Override 220 @RequestMapping(params = "methodToCall=route") 221 public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, 222 HttpServletRequest request, HttpServletResponse response) { 223 LOG.debug(" Inside route method of patron maintenance controller "); 224 ModelAndView modelAndView; 225 MaintenanceDocumentForm mainForm = (MaintenanceDocumentForm) form; 226 MaintenanceDocument document = (MaintenanceDocument) form.getDocument(); 227 OleCalendar oleCalendar = (OleCalendar) document.getNewMaintainableObject().getDataObject(); 228 oleCalendar.setCancelOperationFlag(true); 229// Concat of 23:59:59 to EndDate while setting endDate manually 230 if( oleCalendar.getEndDate()!= null && !oleCalendar.getEndDate().toString().equals("")){ 231 String endDateString = oleCalendar.getEndDate().toString(); 232 String endDateSplit[] = endDateString.split(" "); 233 oleCalendar.setEndDate(Timestamp.valueOf(endDateSplit[0]+" "+"23:59:59")); 234 } 235// Concat of 23:59:59 to EndDate while setting endDate manually 236 237 boolean isNew = document.isNew(); 238 generalInfoValidation(oleCalendar, isNew); 239 ModelAndView modelAndView1 = super.route(mainForm, result, request, response);//changed 240 assignEndDate(oleCalendar); 241 convert12HrsFormat(document); 242 243 244 return modelAndView1; 245 } 246 247 public void assignEndDate(OleCalendar oleCalendar) { 248 249 if (GlobalVariables.getMessageMap().getErrorMessages().isEmpty()) { 250 251 //*-*-*-Setting End-Date of a calendar while adding a new Calendar*-*-*- 252 Date endDate = DateUtil.addDays(oleCalendar.getBeginDate(), -1); 253 String groupId = oleCalendar.getCalendarGroupId(); 254 Map map = new HashMap(); 255 map.put("calendarGroupId", groupId); 256// OleCalendarGroup oleCalendarGroup = getBusinessObjectService().findByPrimaryKey(OleCalendarGroup.class,map); 257 Collection<OleCalendar> calendars = getBusinessObjectService().findMatching(OleCalendar.class, map); 258 Integer latestCalChrSeqNo = 0; 259 Integer maxChrSeqNo = 0; 260 261 for (OleCalendar calendar1 : calendars) { 262 if (calendar1.getChronologicalSequence() != null) { 263 latestCalChrSeqNo = Integer.parseInt(calendar1.getChronologicalSequence()); 264 maxChrSeqNo = Math.max(maxChrSeqNo, latestCalChrSeqNo); 265 } 266 } 267 268// Integer latestCalChrSeqNo=0; 269// Integer maxChrSeqNo = 0; 270 for (OleCalendar calendar : calendars) { 271// if(calendar.getChronologicalSequence()!=null){ 272// latestCalChrSeqNo = Integer.parseInt(calendar.getChronologicalSequence()); 273// maxChrSeqNo = Math.max(maxChrSeqNo,latestCalChrSeqNo); 274// } 275 if (oleCalendar.getCalendarId() != null && oleCalendar.getCalendarId().equals(calendar.getCalendarId())) { 276 break; 277 } 278 if ((oleCalendar.getCalendarId() == null || !oleCalendar.getCalendarId().equals(calendar.getCalendarId())) 279 && calendar.getCalendarGroupId().equalsIgnoreCase(groupId) && (maxChrSeqNo==0 || maxChrSeqNo==Integer.parseInt(calendar.getChronologicalSequence()))) { 280 String endDateSplit = null; 281 if (endDate != null) { 282 if (endDate.toString().contains(" ")) { 283 284 endDateSplit = endDate.toString().split(" ")[0]; 285 } 286 287 288 } 289 calendar.setEndDate(Timestamp.valueOf(endDateSplit +" "+ "23:59:59")); 290 getBusinessObjectService().save(calendar); 291 } 292 // getBusinessObjectService().save(calendar); 293 } 294 } 295 } 296 297 public void generalInfoValidation(OleCalendar oleCalendar, boolean isNew) { 298 List<OleCalendarWeek> oleCalendarWeekList = oleCalendar.getOleCalendarWeekList(); 299 300 //millitary format conversion 301 302 DateUtil dateUtil = new DateUtil(); 303 304 if (oleCalendar.getCalendarGroupId().equals("")) { 305 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "temp.group.name");//"oleCalendarGroupId" 306 } 307 308 309 if (oleCalendar.getOleCalendarWeekList().size() > 0) { 310 311 for (OleCalendarWeek oleCalendarWeek : oleCalendarWeekList) { 312 if (oleCalendarWeek.getOpenTime().equals("")) { 313 GlobalVariables.getMessageMap().putErrorForSectionId("GeneralInfo", "temp.week.open.time"); 314 } 315 if (oleCalendarWeek.getCloseTime().equals("")) { 316 GlobalVariables.getMessageMap().putErrorForSectionId("GeneralInfo", "temp.week.close.time"); 317 } 318 } 319 320 boolean repeat = false; 321 322 List<Integer> dest = new ArrayList<Integer>(); 323 for (int i = 0; i < oleCalendarWeekList.size(); i++) { 324 for (int x = new Integer(oleCalendarWeekList.get(i).getStartDay()); x <= new Integer(oleCalendarWeekList.get(i).getEndDay()); x++) { 325 if (dest.size() > 0) { 326 if (dest.contains(x)) { 327 repeat = true; 328 break; 329 } else { 330 dest.add(x); 331 } 332 } else { 333 dest.add(x); 334 } 335 336 } 337 338 339 } 340 if (repeat) { 341 GlobalVariables.getMessageMap().putErrorForSectionId("GeneralInfo", "temp.weak.days.overlap"); 342 343 } 344 345// To set exception period end date (concat with 23:59:59) 346 String excptEndDateSplit = null; 347 for (OleCalendarExceptionPeriod oleCalendarExceptionPeriod : oleCalendar.getOleCalendarExceptionPeriodList()) { 348 if (oleCalendarExceptionPeriod.getEndDate().toString().contains(" ")) { 349 excptEndDateSplit = oleCalendarExceptionPeriod.getEndDate().toString().split(" ")[0]; 350 oleCalendarExceptionPeriod.setEndDate(Timestamp.valueOf(excptEndDateSplit + " " + "23:59:59")); 351 } 352 } 353// To set exception period end date (concat with 23:59:59) 354 355 356 String openTimePeriodWeek = ""; 357 String closeTimePeriodWeek = ""; 358 String openTimeConvExceptionDate = ""; 359 String closeTimeConvExceptionDate = ""; 360 361 // if (!oleCalendar.getOleCalendarWeekList().get(0).getStartDay().equals(oleCalendar.getOleCalendarWeekList().get(0).getEndDay())) { //for validations 362 // OleCalendar oleCalendar = (OleCalendar) document; 363 for (OleCalendarWeek oleCalendarWeek : oleCalendar.getOleCalendarWeekList()) { 364 if (oleCalendarWeek.getOpenTime().equals("") || oleCalendarWeek.getCloseTime().equals("")) { 365 break; 366 } 367 String openTimeWeek = oleCalendarWeek.getOpenTime() + oleCalendarWeek.getOpenTimeSession(); 368 String closeTimeWeek = oleCalendarWeek.getCloseTime() + oleCalendarWeek.getCloseTimeSession(); 369 String openTime = ""; 370 String closeTime = ""; 371// String openTimePeriodWeek = ""; 372// String closeTimePeriodWeek = ""; 373// String openTimeConvExceptionDate = ""; 374// String closeTimeConvExceptionDate = ""; 375 376 try { 377 openTime = dateUtil.convertTo24HoursFormat(openTimeWeek); 378 closeTime = dateUtil.convertTo24HoursFormat(closeTimeWeek); 379 } catch (java.text.ParseException e) { 380 LOG.error(e, e); //To change body of catch statement use File | Settings | File Templates. 381 } 382 /*if (new Float(openTime.split(":")[0] + openTime.split(":")[1]) >= new Float(closeTime.split(":")[0] + closeTime.split(":")[1])) { //validation for open time should less than close time 383 GlobalVariables.getMessageMap().putErrorForSectionId("GeneralInfo", "temp.strt.end.time"); 384 }*/ 385 386 387 oleCalendarWeek.setOpenTime(openTime); 388 oleCalendarWeek.setCloseTime(closeTime); 389 } 390 391 for (OleCalendarExceptionPeriod oleCalendarExceptionPeriod : oleCalendar.getOleCalendarExceptionPeriodList()) { 392 for (OleCalendarExceptionPeriodWeek oleCalendarExceptionPeriodWeek : oleCalendarExceptionPeriod.getOleCalendarExceptionPeriodWeekList()) { 393 if(!oleCalendarExceptionPeriodWeek.getOpenTime().equals("")&& oleCalendarExceptionPeriodWeek.getOpenTime()!=null && !oleCalendarExceptionPeriodWeek.getCloseTime().equals("") && oleCalendarExceptionPeriodWeek.getCloseTime()!=null){ 394 String openTimeExceptionPeriodWeek = oleCalendarExceptionPeriodWeek.getOpenTime() + oleCalendarExceptionPeriodWeek.getOpenTimeSession(); 395 String closeTimeExceptionPeriodWeek = oleCalendarExceptionPeriodWeek.getCloseTime() + oleCalendarExceptionPeriodWeek.getCloseTimeSession(); 396 try { 397 openTimePeriodWeek = dateUtil.convertTo24HoursFormat(openTimeExceptionPeriodWeek); 398 closeTimePeriodWeek = dateUtil.convertTo24HoursFormat(closeTimeExceptionPeriodWeek); 399 } catch (java.text.ParseException e) { 400 LOG.error(e, e); //To change body of catch statement use File | Settings | File Templates. 401 } 402 oleCalendarExceptionPeriodWeek.setOpenTime(openTimePeriodWeek); 403 oleCalendarExceptionPeriodWeek.setCloseTime(closeTimePeriodWeek); 404 } 405 406 } 407 } 408 409 for (OleCalendarExceptionDate oleCalendarExceptionDate : oleCalendar.getOleCalendarExceptionDateList()) { 410 411 if ((!oleCalendarExceptionDate.getOpenTime().equals("")) && (!oleCalendarExceptionDate.getCloseTime().equals(""))) { 412 String openTimeExceptionDate = oleCalendarExceptionDate.getOpenTime() + oleCalendarExceptionDate.getOpenTimeSession(); 413 String closeTimeExceptionDate = oleCalendarExceptionDate.getCloseTime() + oleCalendarExceptionDate.getCloseTimeSession(); 414 try { 415 openTimeConvExceptionDate = dateUtil.convertTo24HoursFormat(openTimeExceptionDate); 416 closeTimeConvExceptionDate = dateUtil.convertTo24HoursFormat(closeTimeExceptionDate); 417 } catch (java.text.ParseException e) { 418 LOG.error(e, e); //To change body of catch statement use File | Settings | File Templates. 419 } 420 if (!oleCalendarExceptionDate.getExceptionType().equals("Holiday")) { //changed 421 oleCalendarExceptionDate.setOpenTime(openTimeConvExceptionDate); 422 oleCalendarExceptionDate.setCloseTime(closeTimeConvExceptionDate); 423 424 } 425 } 426 427 } 428 /*if(oleCalendarWeek.getOpenTimeSession().equalsIgnoreCase("PM")){ 429 430 String[] openTimeSplit = oleCalendarWeek.getOpenTime().split(":"); 431 int openTime = Integer.parseInt(openTimeSplit[0]); 432 int finalOpenTime = openTime+12; 433 String finalTime = finalOpenTime+":"+openTimeSplit[1]; 434 }*/ 435// } 436 437 438 //ModelAndView modelAndView1= super.route(mainForm, result, request, response); 439 //MaintenanceDocument oleDocument = (MaintenanceDocument) mainForm.getDocument(); 440 441 442 if (isNew) { 443 String groupId1 = oleCalendar.getCalendarGroupId(); 444 Map map1 = new HashMap(); 445 map1.put("calendarGroupId", groupId1); 446 Collection<OleCalendar> calendars1 = getBusinessObjectService().findMatching(OleCalendar.class, map1); 447 Integer latestCalChrSeqNo = 0; 448 Integer maxChrSeqNo = 0; 449 for (OleCalendar calendar1 : calendars1) { 450 if (calendar1.getChronologicalSequence() != null) { 451 latestCalChrSeqNo = Integer.parseInt(calendar1.getChronologicalSequence()); 452 maxChrSeqNo = Math.max(maxChrSeqNo, latestCalChrSeqNo); 453 } 454 } 455 456 map1.put("chronologicalSequence", maxChrSeqNo.toString()); 457 List<OleCalendar> calendars2 = (List<OleCalendar>) getBusinessObjectService().findMatching(OleCalendar.class, map1); 458 OleCalendar lastCalendar = calendars2 != null && calendars2.size() > 0 ? calendars2.get(0) : null; 459 if (oleCalendar != null && oleCalendar.getBeginDate() != null && lastCalendar != null && lastCalendar.getBeginDate() != null && 460 oleCalendar.getBeginDate().compareTo(lastCalendar.getBeginDate()) <= 0) { 461 GlobalVariables.getMessageMap().putErrorForSectionId("GeneralInfo", "temp.strt.end.date.new.cal"); 462 } 463 } 464 465/* 466 } else { 467 String openTime = "", closeTime = ""; 468 try { 469 470 openTime = dateUtil.convertTo24HoursFormat(oleCalendar.getOleCalendarWeekList().get(0).getOpenTime() + oleCalendar.getOleCalendarWeekList().get(0).getOpenTimeSession()); 471 closeTime = dateUtil.convertTo24HoursFormat(oleCalendar.getOleCalendarWeekList().get(0).getCloseTime() + oleCalendar.getOleCalendarWeekList().get(0).getCloseTimeSession()); 472 } catch (java.text.ParseException e) { 473 LOG.error(e, e); //To change body of catch statement use File | Settings | File Templates. 474 } 475 if (new Float(openTime.split(":")[0] + openTime.split(":")[1]) >= new Float(closeTime.split(":")[0] + closeTime.split(":")[1])) { //validation for open time should less than close time 476 GlobalVariables.getMessageMap().putErrorForSectionId("GeneralInfo", "temp.strt.end.time"); 477 } 478 GlobalVariables.getMessageMap().putErrorForSectionId("GeneralInfo", "temp.strt.end.date"); 479 //oleCalendar.getOleCalendarWeekList().get(0).setEndDay(OLEConstants.STRT_END_DAY); 480 481 //end of if condition for validation 482 }*/ 483 } 484 /*chronologicalSequence strt*/ 485 Map<String, String> criteria = new HashMap<String, String>(); 486 int seq = 0; 487 488 criteria.put("calendarGroupId", oleCalendar.getCalendarGroupId()); 489 List<OleCalendar> oleCalendarGroups = (List<OleCalendar>) getBusinessObjectService().findMatching(OleCalendar.class, criteria); 490 if (oleCalendarGroups.size() > 0) { 491 //int high=0; 492 for (int i = 0; i < oleCalendarGroups.size(); i++) { 493 if (seq == 0) { 494 seq = new Integer(oleCalendarGroups.get(i).getChronologicalSequence()); 495 } else { 496 if (seq < new Integer(oleCalendarGroups.get(i).getChronologicalSequence())) { 497 seq = new Integer(oleCalendarGroups.get(i).getChronologicalSequence()); 498 } 499 } 500 } 501 if(oleCalendar.getChronologicalSequence()== null || oleCalendar.getChronologicalSequence().equals("")){ 502 oleCalendar.setChronologicalSequence(new StringBuilder().append(seq + 1).toString()); 503 } 504 505 } else { 506 507 oleCalendar.setChronologicalSequence(new StringBuilder().append(seq + 1).toString()); 508 } 509 /*chronologicalSequence end*/ 510 } 511 512 513 public void convert12HrsFormat(MaintenanceDocument document) { 514 DateUtil dateUtil = new DateUtil(); 515 516 OleCalendar oldCalendar = (OleCalendar) document.getNewMaintainableObject().getDataObject(); 517 518 for (OleCalendarWeek oldCalendarWeek : oldCalendar.getOleCalendarWeekList()) { 519 520 if (oldCalendarWeek.getOpenTime().equals("") || oldCalendarWeek.getCloseTime().equals("")) { 521 break; 522 } 523 String convertedOpenTime = ""; 524 String convertCloseTime = ""; 525 String oleOpenTime = oldCalendarWeek.getOpenTime(); 526 String oleCloseTime = oldCalendarWeek.getCloseTime(); 527 try { 528 convertedOpenTime = dateUtil.convertTo12HoursFormat(oleOpenTime); 529 convertCloseTime = dateUtil.convertTo12HoursFormat(oleCloseTime); 530 } catch (java.text.ParseException e) { 531 LOG.error(e, e); //To change body of catch statement use File | Settings | File Templates. 532 } 533 534 if (convertedOpenTime != null) { 535 oldCalendarWeek.setOpenTime(convertedOpenTime.substring(0, convertedOpenTime.length() - 2)); 536 //oldCalendarWeek.setOpenTimeSession(convertedOpenTime.substring(convertedOpenTime.length() - 2, convertedOpenTime.length())); 537 } 538 if (convertCloseTime != null) { 539 // oldCalendarWeek.setCloseTimeSession(convertCloseTime.substring(convertCloseTime.length() - 2, convertCloseTime.length())); 540 oldCalendarWeek.setCloseTime(convertCloseTime.substring(0, convertCloseTime.length() - 2)); 541 } 542 } 543 544 545 for (OleCalendarExceptionPeriod oleCalendarExceptionPeriod : oldCalendar.getOleCalendarExceptionPeriodList()) { 546 //changed 547 for (OleCalendarExceptionPeriodWeek oleCalendarExceptionPeriodWeek : oleCalendarExceptionPeriod.getOleCalendarExceptionPeriodWeekList()) { 548 if(!oleCalendarExceptionPeriodWeek.getOpenTime().equals("")&& oleCalendarExceptionPeriodWeek.getOpenTime()!=null && !oleCalendarExceptionPeriodWeek.getCloseTime().equals("") && oleCalendarExceptionPeriodWeek.getCloseTime()!=null){ 549 String convOpenTimeExcptPrdWk = ""; 550 String convCloseTimeExcptPrdWk = ""; 551 String oleOpenTimeExcptPrdWk = oleCalendarExceptionPeriodWeek.getOpenTime(); 552 String oleCloseTimeExcptPrdWk = oleCalendarExceptionPeriodWeek.getCloseTime(); 553 try { 554 convOpenTimeExcptPrdWk = dateUtil.convertTo12HoursFormat(oleOpenTimeExcptPrdWk); 555 convCloseTimeExcptPrdWk = dateUtil.convertTo12HoursFormat(oleCloseTimeExcptPrdWk); 556 } catch (java.text.ParseException e) { 557 LOG.error(e, e); //To change body of catch statement use File | Settings | File Templates. 558 } 559 560 if (convOpenTimeExcptPrdWk != null) { 561 oleCalendarExceptionPeriodWeek.setOpenTime(convOpenTimeExcptPrdWk.substring(0, convOpenTimeExcptPrdWk.length() - 2)); 562 //oleCalendarExceptionPeriodWeek.setOpenTimeSession(convOpenTimeExcptPrdWk.substring(convOpenTimeExcptPrdWk.length() - 2, convOpenTimeExcptPrdWk.length())); 563 } 564 if (convCloseTimeExcptPrdWk != null) { 565 // oleCalendarExceptionPeriodWeek.setCloseTimeSession(convCloseTimeExcptPrdWk.substring(convCloseTimeExcptPrdWk.length() - 2, convCloseTimeExcptPrdWk.length())); 566 oleCalendarExceptionPeriodWeek.setCloseTime(convCloseTimeExcptPrdWk.substring(0, convCloseTimeExcptPrdWk.length() - 2)); 567 } 568 } 569 570 } 571 } 572 573 574 for (OleCalendarExceptionDate oleCalendarExceptionDate : oldCalendar.getOleCalendarExceptionDateList()) { 575 String convertedOpenTimeExcptDate = ""; 576 String convertedCloseTimeExcptDate = ""; 577 String oleOpenTimeExcptDate = oleCalendarExceptionDate.getOpenTime(); 578 String oleCloseTimeExcptDate = oleCalendarExceptionDate.getCloseTime(); 579 if ((!oleCalendarExceptionDate.getOpenTime().equals("")) && (!oleCalendarExceptionDate.getCloseTime().equals(""))) { //changed 580 try { 581 convertedOpenTimeExcptDate = dateUtil.convertTo12HoursFormat(oleOpenTimeExcptDate); 582 convertedCloseTimeExcptDate = dateUtil.convertTo12HoursFormat(oleCloseTimeExcptDate); 583 } catch (java.text.ParseException e) { 584 LOG.error(e, e); //To change body of catch statement use File | Settings | File Templates. 585 } 586 587 if (convertedOpenTimeExcptDate != null) { 588 oleCalendarExceptionDate.setOpenTime(convertedOpenTimeExcptDate.substring(0, convertedOpenTimeExcptDate.length() - 2)); 589 // oleCalendarExceptionDate.setOpenTimeSession(convertedOpenTimeExcptDate.substring(convertedOpenTimeExcptDate.length() - 2, convertedOpenTimeExcptDate.length())); 590 } 591 if (convertedCloseTimeExcptDate != null) { 592 // oleCalendarExceptionDate.setCloseTimeSession(convertedCloseTimeExcptDate.substring(convertedCloseTimeExcptDate.length() - 2, convertedCloseTimeExcptDate.length())); 593 oleCalendarExceptionDate.setCloseTime(convertedCloseTimeExcptDate.substring(0, convertedCloseTimeExcptDate.length() - 2)); 594 } 595 } 596 } 597 } 598 599 600 @RequestMapping(params = "methodToCall=exceptionDateMethod") 601 public ModelAndView exceptionDateMethod(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, 602 HttpServletRequest request, HttpServletResponse response) { 603 604 MaintenanceDocumentForm mainForm = (MaintenanceDocumentForm) form; 605 //oleCalendarForm.isTemp() 606 MaintenanceDocument document = (MaintenanceDocument) form.getDocument(); 607 OleCalendar oleCalendar = (OleCalendar) document.getNewMaintainableObject().getDataObject(); 608 609 610 /*List<OleCalendarExceptionDate> oleCalendarExceptionDateList =oleCalendar.getOleCalendarExceptionDateList(); 611 if(oleCalendarExceptionDateList.size()>0){ 612 if(oleCalendarExceptionDateList.get(0).getExceptionType().equals("Holiday")){ 613 oleCalendar.setHideTime(false); 614 } 615 else{ 616 oleCalendar.setHideTime(true); 617 } 618 619 }*/ 620 621 if (oleCalendar.getExceptionDayChecking().equals("Holiday")) { 622 oleCalendar.setHideTime(false); 623 } else { 624 oleCalendar.setHideTime(true); 625 } 626 return getUIFModelAndView(mainForm); 627 } 628 629 630 @RequestMapping(params = "methodToCall=" + "deleteDocument") 631 public ModelAndView deleteDocument(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result, 632 HttpServletRequest request, HttpServletResponse response) throws Exception { 633 634 LOG.debug(" Inside deleteDocument "); 635 MaintenanceDocument document = form.getDocument(); 636 OleCalendar oleCalendar = new OleCalendar(); 637 OleCalendar prevCalendar = null; 638 OleCalendar nextCalendar = null; 639 try { 640 if (document.getDocumentDataObject() != null) { 641 oleCalendar = (OleCalendar) document.getDocumentDataObject(); 642 if (oleCalendar != null && oleCalendar.getCalendarId() != null) { 643 Map map = new HashMap<>(); 644 map.put("calendarGroupId", oleCalendar.getCalendarGroupId()); 645 List<OleCalendar> calendars = (List<OleCalendar>) getBusinessObjectService().findMatchingOrderBy(OleCalendar.class, map, "CL_SEQ", true); 646 for (int i = 0; i < calendars.size(); i++) { 647 OleCalendar calendar = calendars.get(i); 648 if (calendar.getChronologicalSequence().equalsIgnoreCase(oleCalendar.getChronologicalSequence())) { 649 650 prevCalendar = (i - 1) >= 0 ? calendars.get(i - 1) : null; 651 nextCalendar = (i + 1) < calendars.size() ? calendars.get(i + 1) : null; 652 if (nextCalendar == null && prevCalendar != null) { 653 prevCalendar.setEndDate(null); 654 getBusinessObjectService().save(prevCalendar); 655 } else if (nextCalendar != null && prevCalendar != null) { 656 Timestamp prevCalNewEndDate = DateUtil.addDays(nextCalendar.getBeginDate(),-1); 657 prevCalendar.setEndDate(prevCalNewEndDate); 658 getBusinessObjectService().save(prevCalendar); 659 } 660 661 } 662 } 663 getBusinessObjectService().delete(oleCalendar); 664 } else { 665 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_MESSAGES, OLEConstants.OlePatron.ERROR_PATRON_NOT_FOUND); 666 return getUIFModelAndView(form); 667 } 668 } 669 } catch (Exception ex) { 670 LOG.error(ex.getMessage(), ex); 671 throw new RuntimeException(); 672 } 673 return close(form, result, request, response); 674 } 675}