1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.acal.service.impl;
18
19 import org.apache.commons.lang.BooleanUtils;
20 import org.apache.commons.lang.StringUtils;
21 import org.apache.commons.lang.time.DateFormatUtils;
22 import org.kuali.rice.core.api.criteria.Predicate;
23 import org.kuali.rice.core.api.criteria.QueryByCriteria;
24 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
25 import org.kuali.rice.core.api.util.ConcreteKeyValue;
26 import org.kuali.rice.core.api.util.KeyValue;
27 import org.kuali.rice.core.api.util.RiceKeyConstants;
28 import org.kuali.rice.krad.uif.UifConstants;
29 import org.kuali.rice.krad.uif.container.CollectionGroup;
30 import org.kuali.rice.krad.uif.control.SelectControl;
31 import org.kuali.rice.krad.uif.field.InputField;
32 import org.kuali.rice.krad.uif.view.View;
33 import org.kuali.rice.krad.util.GlobalVariables;
34 import org.kuali.rice.krad.util.KRADConstants;
35 import org.kuali.student.enrollment.class2.acal.dto.HolidayCalendarWrapper;
36 import org.kuali.student.enrollment.class2.acal.dto.HolidayWrapper;
37 import org.kuali.student.enrollment.class2.acal.service.HolidayCalendarViewHelperService;
38 import org.kuali.student.enrollment.class2.acal.util.AcalCommonUtils;
39 import org.kuali.student.r2.common.dto.StatusInfo;
40 import org.kuali.student.r2.common.util.date.DateFormatters;
41 import org.kuali.student.r2.core.acal.dto.HolidayCalendarInfo;
42 import org.kuali.student.r2.core.acal.dto.HolidayInfo;
43 import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
44 import org.kuali.student.enrollment.class2.acal.dto.TimeSetWrapper;
45 import org.kuali.student.enrollment.class2.acal.form.HolidayCalendarForm;
46 import org.kuali.student.enrollment.class2.acal.util.CalendarConstants;
47 import org.kuali.student.common.uif.service.impl.KSViewHelperServiceImpl;
48 import org.kuali.student.r2.common.dto.ContextInfo;
49 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
50 import org.kuali.student.r2.common.exceptions.MissingParameterException;
51 import org.kuali.student.r2.common.exceptions.OperationFailedException;
52 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
53 import org.kuali.student.r2.core.constants.AcademicCalendarServiceConstants;
54 import org.kuali.student.r2.core.class1.state.dto.StateInfo;
55 import org.kuali.student.r2.core.class1.type.dto.TypeInfo;
56 import org.kuali.student.r2.core.constants.AtpServiceConstants;
57
58 import javax.xml.namespace.QName;
59 import java.util.*;
60
61 import static org.kuali.rice.core.api.criteria.PredicateFactory.*;
62
63
64
65
66
67
68 public class HolidayCalendarViewHelperServiceImpl extends KSViewHelperServiceImpl implements HolidayCalendarViewHelperService {
69
70 private AcademicCalendarService acalService;
71 private List<TypeInfo> holidayTypes;
72
73
74 public void saveHolidayCalendar(HolidayCalendarForm hcForm,boolean isSetOfficial) throws Exception{
75
76 ContextInfo contextInfo = createContextInfo();
77
78 HolidayCalendarInfo hcInfo = hcForm.getHolidayCalendarInfo();
79 if (StringUtils.isBlank(hcInfo.getStateKey())){
80 hcInfo.setStateKey(AtpServiceConstants.ATP_DRAFT_STATE_KEY);
81 }
82 hcInfo.setTypeKey(AcademicCalendarServiceConstants.HOLIDAY_CALENDAR_TYPE_KEY);
83 hcInfo.setDescr(AcalCommonUtils.buildDesc("no description"));
84
85 if (StringUtils.isBlank(hcInfo.getId())){
86 HolidayCalendarInfo createdHCal = getAcalService().createHolidayCalendar(AcademicCalendarServiceConstants.HOLIDAY_CALENDAR_TYPE_KEY, hcInfo, contextInfo);
87 hcForm.setHolidayCalendarInfo(createdHCal);
88 }else{
89 HolidayCalendarInfo updatedHCal = getAcalService().updateHolidayCalendar(hcInfo.getId(), hcInfo, contextInfo);
90 hcForm.setHolidayCalendarInfo(updatedHCal);
91 }
92
93
94 List<HolidayWrapper> holidays = hcForm.getHolidays();
95
96 List<String> newHolidayIdList = new ArrayList<String>(holidays.size());
97
98 HolidayInfo holidayInfo, storedHolidayInfo;
99 for (HolidayWrapper holidayWrapper : holidays){
100
101 holidayInfo = holidayWrapper.getHolidayInfo();
102 holidayWrapper.setTypeName(getHolidayTypeName(holidayWrapper.getTypeKey()));
103 holidayInfo.setDescr(AcalCommonUtils.buildDesc("no description"));
104 holidayInfo.setIsAllDay(holidayWrapper.isAllDay());
105 holidayInfo.setIsInstructionalDay(holidayWrapper.isInstructional());
106 holidayInfo.setStartDate(holidayWrapper.getStartDate());
107 holidayInfo.setName(holidayWrapper.getTypeName());
108 holidayInfo.setStartDate(getStartDateWithUpdatedTime(holidayWrapper,true));
109 holidayInfo.setTypeKey(holidayWrapper.getTypeKey());
110 setHolidayEndDate(holidayWrapper);
111
112 if (StringUtils.isBlank(holidayInfo.getId())){
113 if (StringUtils.equals(hcForm.getHolidayCalendarInfo().getStateKey(),AtpServiceConstants.ATP_OFFICIAL_STATE_KEY)){
114 holidayInfo.setStateKey(AtpServiceConstants.MILESTONE_OFFICIAL_STATE_KEY);
115 } else {
116 holidayInfo.setStateKey(AtpServiceConstants.MILESTONE_DRAFT_STATE_KEY);
117 }
118 storedHolidayInfo = getAcalService().createHoliday(hcForm.getHolidayCalendarInfo().getId(), holidayWrapper.getTypeKey(), holidayInfo, contextInfo);
119 }else{
120 storedHolidayInfo = getAcalService().updateHoliday(holidayInfo.getId(),holidayInfo, contextInfo);
121 }
122 holidayWrapper.setHolidayInfo(storedHolidayInfo);
123 newHolidayIdList.add(storedHolidayInfo.getId());
124 hcForm.setMeta(hcInfo.getMeta());
125 }
126
127 if ( ! StringUtils.isBlank(hcInfo.getId())) {
128
129 List<HolidayInfo> oldHolidayList =
130 getAcalService().getHolidaysForHolidayCalendar(hcInfo.getId(), contextInfo);
131 for (HolidayInfo oldHoliday : oldHolidayList) {
132 if ( ! newHolidayIdList.contains(oldHoliday.getId())) {
133 getAcalService().deleteHoliday(oldHoliday.getId(), contextInfo);
134 }
135 }
136 }
137
138 if (isSetOfficial){
139 StatusInfo statusInfo = null;
140 try {
141 statusInfo = getAcalService().changeHolidayCalendarState(hcForm.getHolidayCalendarInfo().getId(), AcademicCalendarServiceConstants.ACADEMIC_CALENDAR_OFFICIAL_STATE_KEY,createContextInfo());
142 if (!statusInfo.getIsSuccess()){
143 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_MESSAGES, RiceKeyConstants.ERROR_CUSTOM, statusInfo.getMessage());
144 } else{
145 hcForm.setHolidayCalendarInfo(getAcalService().getHolidayCalendar(hcForm.getHolidayCalendarInfo().getId(),createContextInfo()));
146 for (HolidayWrapper holidayWrapper : hcForm.getHolidays()) {
147 holidayWrapper.setHolidayInfo(getAcalService().getHoliday(holidayWrapper.getHolidayInfo().getId(),createContextInfo()));
148 }
149 }
150 } catch (Exception e) {
151 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_MESSAGES, CalendarConstants.MessageKeys.ERROR_ACAL_SAVE_FAILED + " - " + e.getMessage());
152 }
153 }
154 }
155
156 public HolidayCalendarInfo getHolidayCalendar(String hcId) throws Exception{
157 HolidayCalendarInfo retrievedHc = getAcalService().getHolidayCalendar(hcId, createContextInfo());
158 return retrievedHc;
159 }
160
161
162
163
164
165
166
167 public HolidayCalendarInfo getNewestHolidayCalendar() throws Exception {
168 int currentYear = Calendar.getInstance().get(Calendar.YEAR);
169
170
171 List<HolidayCalendarInfo> holidayCalendarInfoList =
172 getAcalService().getHolidayCalendarsByStartYear(currentYear, createContextInfo());
173
174
175 if ((null == holidayCalendarInfoList) || holidayCalendarInfoList.isEmpty()) {
176 holidayCalendarInfoList =
177 getAcalService().getHolidayCalendarsByStartYear((currentYear - 1), createContextInfo());
178 }
179
180 if ((null == holidayCalendarInfoList) || (holidayCalendarInfoList.size() == 0)) {
181
182
183 return null;
184 }
185 else {
186
187
188 HolidayCalendarInfo newestCalendar = holidayCalendarInfoList.get(0);
189 for(HolidayCalendarInfo calendarTemp: holidayCalendarInfoList){
190
191 if(calendarTemp.getMeta().getCreateTime().compareTo(newestCalendar.getMeta().getCreateTime())>0){
192 newestCalendar = calendarTemp;
193 }
194 }
195
196 return newestCalendar;
197 }
198 }
199
200 public List<HolidayWrapper> getHolidayWrappersForHolidayCalendar(String holidayCalendarId) throws Exception {
201 List<HolidayInfo> holidayInfos =
202 getAcalService().getHolidaysForHolidayCalendar(holidayCalendarId, createContextInfo());
203 return assembleHolidays(holidayInfos);
204 }
205
206 private List<HolidayWrapper> assembleHolidays (List<HolidayInfo> holidayInfos) throws Exception{
207 List<HolidayWrapper> holidays = new ArrayList<HolidayWrapper>();
208 if (holidayInfos != null && !holidayInfos.isEmpty()){
209 for (HolidayInfo holidayInfo : holidayInfos) {
210 HolidayWrapper holiday = assembleHoliday(holidayInfo);
211 holidays.add(holiday);
212 }
213 }
214
215 return holidays;
216 }
217
218 private HolidayWrapper assembleHoliday(HolidayInfo holidayInfo) throws Exception{
219 HolidayWrapper holiday = new HolidayWrapper(holidayInfo);
220
221 holiday.setTypeName(getHolidayTypeName(holidayInfo.getTypeKey()));
222
223
224 return holiday;
225 }
226
227 public String getHolidayTypeName(String holidayTypeKey) throws Exception {
228 TypeInfo typeInfo = getAcalService().getHolidayType(holidayTypeKey, createContextInfo());
229 return typeInfo.getName();
230 }
231
232 public void deleteHoliday(int selectedIndex,HolidayCalendarForm hcForm) throws Exception{
233 hcForm.getHolidays().remove(selectedIndex);
234 }
235
236 public String getHolidayCalendarState(String holidayCalendarStateKey) throws Exception{
237 StateInfo hcState = getAcalService().getHolidayCalendarState(holidayCalendarStateKey, createContextInfo());
238 return hcState.getName();
239 }
240
241 public void deleteHolidayCalendar(String holidayCalendarId) throws Exception{
242
243 getAcalService().deleteHolidayCalendar(holidayCalendarId, createContextInfo());
244 }
245
246
247
248
249
250
251
252
253 @SuppressWarnings("unused")
254 public void populateHolidayTypes(InputField field, HolidayCalendarForm hcForm){
255
256 boolean isAddLine = BooleanUtils.toBoolean((Boolean) field.getContext().get(UifConstants.ContextVariableNames.IS_ADD_LINE));
257 if (!isAddLine) {
258 return;
259 }
260
261 List<KeyValue> keyValues = new ArrayList<KeyValue>();
262 List<String> alreadyAddedTypes = new ArrayList<String>();
263
264 for (HolidayWrapper holidayWrapper : hcForm.getHolidays()) {
265 alreadyAddedTypes.add(holidayWrapper.getTypeKey());
266 }
267
268
269 ConcreteKeyValue topKeyValue = new ConcreteKeyValue();
270 topKeyValue.setKey("");
271 topKeyValue.setValue("Select holiday type");
272 keyValues.add(topKeyValue);
273
274 try {
275 List<TypeInfo> types = getHolidayTypes();
276 for (TypeInfo type : types) {
277 if (!alreadyAddedTypes.contains(type.getKey())){
278 ConcreteKeyValue keyValue = new ConcreteKeyValue();
279 keyValue.setKey(type.getKey());
280 keyValue.setValue(type.getName());
281 keyValues.add(keyValue);
282 }
283 }
284 } catch (Exception e) {
285 throw new RuntimeException(e);
286 }
287
288 ((SelectControl) field.getControl()).setOptions(keyValues);
289 }
290
291
292 public List<TypeInfo> getHolidayTypes() throws InvalidParameterException, MissingParameterException, PermissionDeniedException, OperationFailedException {
293 if(holidayTypes == null) {
294 holidayTypes = Collections.unmodifiableList(getAcalService().getHolidayTypes(createContextInfo()));
295 }
296 return holidayTypes;
297 }
298
299 private Date getStartDateWithUpdatedTime(TimeSetWrapper timeSetWrapper,boolean isSaveAction){
300
301 if (!timeSetWrapper.isAllDay()){
302 if (StringUtils.isNotBlank(timeSetWrapper.getStartTime())){
303 String startTime = timeSetWrapper.getStartTime();
304 String startTimeApPm = timeSetWrapper.getStartTimeAmPm();
305
306 if (isSaveAction && StringUtils.startsWith(startTime,"12:") && StringUtils.equalsIgnoreCase(startTimeApPm,"am")){
307 startTime = StringUtils.replace(startTime,"12:","00:");
308 }
309 return AcalCommonUtils.getDateWithTime(timeSetWrapper.getStartDate(), startTime, startTimeApPm);
310 }else{
311 timeSetWrapper.setStartTime("12:00");
312 timeSetWrapper.setStartTimeAmPm("AM");
313 return AcalCommonUtils.getDateWithTime(timeSetWrapper.getStartDate(),
314 timeSetWrapper.getStartTime(), timeSetWrapper.getStartTimeAmPm());
315 }
316 }else{
317 return timeSetWrapper.getStartDate();
318 }
319
320 }
321
322 private void setHolidayEndDate(HolidayWrapper holidayWrapper) {
323 holidayWrapper.getHolidayInfo().setIsDateRange(holidayWrapper.isDateRange());
324 Date endDateToInfo = timeSetWrapperEndDate(holidayWrapper);
325 holidayWrapper.getHolidayInfo().setEndDate(endDateToInfo);
326 }
327
328 private Date timeSetWrapperEndDate(TimeSetWrapper timeSetWrapper) {
329 Date endDateToInfo;
330
331 if (timeSetWrapper.isAllDay()) {
332 if (timeSetWrapper.isDateRange()) {
333
334 endDateToInfo = AcalCommonUtils.getDateWithTime(timeSetWrapper.getEndDate(), CalendarConstants.DEFAULT_END_TIME, "PM");
335 }
336 else {
337 endDateToInfo = null;
338 timeSetWrapper.setEndDate(null);
339 }
340
341
342 timeSetWrapper.setStartTime(null);
343 timeSetWrapper.setStartTimeAmPm("AM");
344 timeSetWrapper.setEndTime(null);
345 timeSetWrapper.setEndTimeAmPm("AM");
346 }
347 else {
348 if (timeSetWrapper.isDateRange()){
349 String endTime = timeSetWrapper.getEndTime();
350 String endTimeAmPm = timeSetWrapper.getEndTimeAmPm();
351 Date endDate = timeSetWrapper.getEndDate();
352
353 if (StringUtils.isBlank(endTime)){
354 endTime = CalendarConstants.DEFAULT_END_TIME;
355 endTimeAmPm = "PM";
356 }
357 timeSetWrapper.setEndTime(endTime);
358 timeSetWrapper.setEndTimeAmPm(endTimeAmPm);
359
360 endDateToInfo = AcalCommonUtils.getDateWithTime(endDate, endTime, endTimeAmPm);
361 } else {
362 timeSetWrapper.setEndDate(null);
363 timeSetWrapper.setEndTime(null);
364 timeSetWrapper.setEndTimeAmPm("AM");
365 endDateToInfo = null;
366 }
367 }
368
369 return endDateToInfo;
370 }
371
372 public AcademicCalendarService getAcalService() {
373 if(acalService == null) {
374 acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART));
375 }
376 return this.acalService;
377 }
378
379
380 public void validateHolidayCalendar(HolidayCalendarForm hcForm){
381 HolidayCalendarInfo hcInfo = hcForm.getHolidayCalendarInfo();
382
383 if (!isValidHcalName(hcInfo)){
384 GlobalVariables.getMessageMap().putError("holidayCalendarInfo.name", "error.enroll.calendar.duplicateName");
385 }
386
387 if (!AcalCommonUtils.isValidDateRange(hcInfo.getStartDate(), hcInfo.getEndDate())){
388 GlobalVariables.getMessageMap().putErrorForSectionId("KS-HolidayCalendar-MetaSection",
389 "error.enroll.daterange.invalid", "Calendar",
390 AcalCommonUtils.formatDate(hcInfo.getStartDate()), AcalCommonUtils.formatDate(hcInfo.getEndDate()));
391 }
392
393
394 int index = -1;
395 for (HolidayWrapper holiday : hcForm.getHolidays()) {
396 ++index;
397
398 if (!AcalCommonUtils.isDateWithinRange(hcInfo.getStartDate(), hcInfo.getEndDate(), holiday.getStartDate()) ||
399 !AcalCommonUtils.isDateWithinRange(hcInfo.getStartDate(), hcInfo.getEndDate(), holiday.getEndDate())){
400 GlobalVariables.getMessageMap().putWarningForSectionId("KS-HolidayCalendar-HolidaySection",
401 "error.enroll.holiday.dateNotInHcal", holiday.getTypeName());
402 }
403
404 isValidTimeSetWrapper("KS-HolidayCalendar-HolidaySection", holiday.getTypeKey(), holiday, holiday.getTypeName());
405 }
406
407 }
408
409 public void populateHolidayCalendarDefaults(HolidayCalendarForm hcForm){
410
411 for (HolidayWrapper holidayWrapper : hcForm.getHolidays()) {
412 holidayWrapper.getHolidayInfo().setStartDate(getStartDateWithUpdatedTime(holidayWrapper,false));
413 setHolidayEndDate(holidayWrapper);
414 }
415 }
416
417 private boolean isValidHcalName(HolidayCalendarInfo hcal){
418
419 QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
420 List<Predicate> pList = new ArrayList<Predicate>();
421 Predicate p = equal("atpType",AcademicCalendarServiceConstants.HOLIDAY_CALENDAR_TYPE_KEY);
422 pList.add(p);
423
424 p = equalIgnoreCase("name", hcal.getName());
425 pList.add(p);
426
427 Predicate[] preds = new Predicate[pList.size()];
428 pList.toArray(preds);
429 qBuilder.setPredicates(and(preds));
430
431 try {
432 List<HolidayCalendarInfo> hcals = getAcalService().searchForHolidayCalendars(qBuilder.build(), createContextInfo());
433 boolean valid = hcals.isEmpty();
434
435 if (!valid && StringUtils.isNotBlank(hcal.getId())){
436 for (HolidayCalendarInfo hc : hcals) {
437 if (!StringUtils.equals(hc.getId(),hcal.getId())){
438 valid = false;
439 break;
440 }
441 valid = true;
442 }
443 }
444 return valid;
445 } catch (Exception e) {
446 throw new RuntimeException(e);
447 }
448 }
449
450
451 protected void processBeforeAddLine(View view, CollectionGroup collectionGroup, Object model, Object addLine) {
452 ContextInfo contextInfo = createContextInfo();
453 if (addLine instanceof HolidayCalendarInfo) {
454 HolidayCalendarInfo inputLine = (HolidayCalendarInfo)addLine;
455 try {
456 System.out.println("HC id =" +inputLine.getId());
457
458 HolidayCalendarInfo exists = getAcalService().getHolidayCalendar(inputLine.getId(), contextInfo);
459
460 inputLine.setName(exists.getName());
461 inputLine.setId(exists.getId());
462 inputLine.setTypeKey(exists.getTypeKey());
463 inputLine.setAdminOrgId(exists.getAdminOrgId());
464 inputLine.setStartDate(exists.getStartDate());
465 inputLine.setEndDate(exists.getEndDate());
466 }catch (Exception e) {
467 throw new RuntimeException(e);
468 }
469
470 }else if (addLine instanceof HolidayCalendarWrapper){
471 HolidayCalendarWrapper inputLine = (HolidayCalendarWrapper)addLine;
472 List<HolidayWrapper> holidays = new ArrayList<HolidayWrapper>();
473 try {
474 String holidayCalendarId = inputLine.getId();
475 if (!StringUtils.isEmpty(holidayCalendarId)) {
476 HolidayCalendarInfo hcInfo = getAcalService().getHolidayCalendar(inputLine.getId(), contextInfo);
477 inputLine.setHolidayCalendarInfo(hcInfo);
478 inputLine.setAdminOrgName(AcalCommonUtils.getAdminOrgNameById(hcInfo.getAdminOrgId()));
479 StateInfo hcState = getAcalService().getHolidayCalendarState(hcInfo.getStateKey(), contextInfo);
480 inputLine.setStateName(hcState.getName());
481 List<HolidayInfo> holidayInfoList = getAcalService().getHolidaysForHolidayCalendar(hcInfo.getId(), contextInfo);
482 for(HolidayInfo holidayInfo : holidayInfoList){
483 HolidayWrapper holiday = new HolidayWrapper(holidayInfo);
484 TypeInfo typeInfo = getAcalService().getHolidayType(holidayInfo.getTypeKey(), contextInfo);
485 holiday.setTypeName(typeInfo.getName());
486 holidays.add(holiday);
487 }
488 inputLine.setHolidays(holidays);
489 }
490 }catch (Exception e){
491 throw new RuntimeException(e);
492 }
493
494 } else if (addLine instanceof HolidayWrapper){
495 HolidayWrapper holiday = (HolidayWrapper)addLine;
496 try {
497 if (holiday.getTypeKey() != null && !StringUtils.isBlank(holiday.getTypeKey())) {
498 holiday.setTypeName(getHolidayTypeName(holiday.getTypeKey()));
499 }
500 } catch (Exception e) {
501 throw new RuntimeException(e);
502 }
503 } else {
504 super.processBeforeAddLine(view, collectionGroup, model, addLine);
505 }
506 }
507
508 protected boolean performAddLineValidation(View view, CollectionGroup collectionGroup, Object model, Object addLine) {
509 if (model instanceof HolidayCalendarForm) {
510 if (addLine instanceof HolidayWrapper) {
511 HolidayWrapper holidayWrapper = (HolidayWrapper)addLine;
512 if (!isValidTimeSetWrapper(collectionGroup.getId(), holidayWrapper.getTypeKey(), holidayWrapper, holidayWrapper.getTypeName())) {
513 return false;
514 }
515 }
516 }
517
518 return super.performAddLineValidation(view, collectionGroup, model, addLine);
519 }
520
521
522 private boolean isValidTimeSetWrapper(String collectionGroupId, String KeyDateType, TimeSetWrapper wrapper, String wrapperName) {
523 boolean isValid = true;
524
525 if(StringUtils.isEmpty(KeyDateType)) {
526 GlobalVariables.getMessageMap().putErrorForSectionId(collectionGroupId, CalendarConstants.MessageKeys.ERROR_KEY_DATE_TYPE_REQUIRED);
527
528 return false;
529 }
530
531
532 if (wrapper.getStartDate()!=null && (wrapper.getStartTime()==null || StringUtils.isBlank(wrapper.getStartTime())) &&
533 wrapper.getEndDate()==null && (wrapper.getEndTime()!=null && !StringUtils.isBlank(wrapper.getEndTime()))){
534 GlobalVariables.getMessageMap().putErrorForSectionId(collectionGroupId, CalendarConstants.MessageKeys.ERROR_INVALID_DATE_TIME, wrapperName);
535 return false;
536 }
537
538 else if (wrapper.getStartDate()==null && (wrapper.getStartTime()!=null && !StringUtils.isBlank(wrapper.getStartTime()))){
539 GlobalVariables.getMessageMap().putErrorForSectionId(collectionGroupId, CalendarConstants.MessageKeys.ERROR_INVALID_DATE_TIME, wrapperName);
540 return false;
541 }
542
543 else if (wrapper.getStartDate()==null && (wrapper.getStartTime()==null || StringUtils.isBlank(wrapper.getStartTime())) &&
544 wrapper.getEndDate()==null && (wrapper.getEndTime()!=null && !StringUtils.isBlank(wrapper.getEndTime()))){
545 GlobalVariables.getMessageMap().putErrorForSectionId(collectionGroupId, CalendarConstants.MessageKeys.ERROR_INVALID_DATE_TIME, wrapperName);
546 return false;
547 }
548
549
550 if (wrapper.getStartDate()==null && (wrapper.getStartTime()==null || StringUtils.isBlank(wrapper.getStartTime())) &&
551 wrapper.getEndDate()==null && (wrapper.getEndTime()==null || StringUtils.isBlank(wrapper.getEndTime()))){
552 GlobalVariables.getMessageMap().putWarningForSectionId(collectionGroupId, CalendarConstants.MessageKeys.ERROR_KEY_DATE_START_DATE_REQUIRED, wrapperName);
553 }
554
555 if (wrapper.getStartDate()!=null && (wrapper.getStartTime()==null || StringUtils.isBlank(wrapper.getStartTime())) &&
556 wrapper.getEndDate()==null && (wrapper.getEndTime()==null || StringUtils.isBlank(wrapper.getEndTime()))){
557 wrapper.setAllDay(true);
558 wrapper.setDateRange(false);
559 } else if (wrapper.getStartDate()!=null && (wrapper.getStartTime()!=null && !StringUtils.isBlank(wrapper.getStartTime())) &&
560 wrapper.getEndDate()==null && (wrapper.getEndTime()==null || StringUtils.isBlank(wrapper.getEndTime()))){
561 wrapper.setAllDay(false);
562 wrapper.setDateRange(false);
563 } else if (wrapper.getStartDate()==null && (wrapper.getStartTime()==null || StringUtils.isBlank(wrapper.getStartTime())) &&
564 wrapper.getEndDate()!=null && (wrapper.getEndTime()==null || StringUtils.isBlank(wrapper.getEndTime()))){
565 wrapper.setStartDate(wrapper.getEndDate());
566 wrapper.setEndDate(null);
567 wrapper.setAllDay(true);
568 wrapper.setDateRange(false);
569 } else if (wrapper.getStartDate()==null && (wrapper.getStartTime()==null || StringUtils.isBlank(wrapper.getStartTime())) &&
570 wrapper.getEndDate()!=null && (wrapper.getEndTime()!=null && !StringUtils.isBlank(wrapper.getEndTime()))){
571 wrapper.setStartDate(wrapper.getEndDate());
572 wrapper.setStartTime(wrapper.getEndTime());
573 wrapper.setEndDate(null);
574 wrapper.setEndTime(null);
575 wrapper.setAllDay(false);
576 wrapper.setDateRange(false);
577 } else if (wrapper.getStartDate()!=null && (wrapper.getStartTime()==null || StringUtils.isBlank(wrapper.getStartTime())) &&
578 wrapper.getEndDate()!=null && (wrapper.getEndTime()==null || StringUtils.isBlank(wrapper.getEndTime()))){
579 wrapper.setAllDay(true);
580 wrapper.setDateRange(true);
581 } else if (wrapper.getStartDate()!=null && (wrapper.getStartTime()!=null && !StringUtils.isBlank(wrapper.getStartTime())) &&
582 wrapper.getEndDate()!=null && (wrapper.getEndTime()==null || StringUtils.isBlank(wrapper.getEndTime()))){
583 wrapper.setAllDay(false);
584 wrapper.setDateRange(true);
585 timeSetWrapperEndDate(wrapper);
586 } else if (wrapper.getStartDate()!=null && (wrapper.getStartTime()==null || StringUtils.isBlank(wrapper.getStartTime())) &&
587 wrapper.getEndDate()!=null && (wrapper.getEndTime()!=null && !StringUtils.isBlank(wrapper.getEndTime()))){
588 wrapper.setAllDay(false);
589 wrapper.setDateRange(true);
590 getStartDateWithUpdatedTime(wrapper, false);
591 } else if (wrapper.getStartDate()!=null && (wrapper.getStartTime()!=null && !StringUtils.isBlank(wrapper.getStartTime())) &&
592 wrapper.getEndDate()!=null && (wrapper.getEndTime()!=null && !StringUtils.isBlank(wrapper.getEndTime()))){
593 wrapper.setAllDay(false);
594 wrapper.setDateRange(true);
595 } else if (wrapper.getStartDate()!=null && (wrapper.getStartTime()!=null && !StringUtils.isBlank(wrapper.getStartTime())) &&
596 wrapper.getEndDate()==null && (wrapper.getEndTime()!=null && !StringUtils.isBlank(wrapper.getEndTime()))){
597 wrapper.setEndDate(wrapper.getStartDate());
598 wrapper.setAllDay(false);
599 wrapper.setDateRange(true);
600 }
601
602
603 if (wrapper.getStartDate()!=null && wrapper.getEndDate()!=null){
604 if ((wrapper.getStartTime()!=null && !StringUtils.isBlank(wrapper.getStartTime())) &&
605 (wrapper.getEndTime()!=null && !StringUtils.isBlank(wrapper.getEndTime()))) {
606 Date startDate = getStartDateWithUpdatedTime(wrapper, false);
607 Date endDate = timeSetWrapperEndDate(wrapper);
608 if (!AcalCommonUtils.isValidDateRange(startDate, endDate)) {
609 GlobalVariables.getMessageMap().putErrorForSectionId(collectionGroupId, CalendarConstants.MessageKeys.ERROR_HOLIDAY_END_DATE_BEFORE_START, wrapperName);
610 return false;
611 }
612 } else {
613 if (!AcalCommonUtils.isValidDateRange(wrapper.getStartDate(), wrapper.getEndDate())) {
614 GlobalVariables.getMessageMap().putErrorForSectionId(collectionGroupId, CalendarConstants.MessageKeys.ERROR_HOLIDAY_END_DATE_BEFORE_START, wrapperName);
615 return false;
616 }
617 }
618 }
619
620 return isValid;
621 }
622
623 }