if (baseCalendarDTO.calendarExceptions != null) {
for (CalendarExceptionDTO exceptionDTO : baseCalendarDTO.calendarExceptions) {
if (StringUtils.isBlank(exceptionDTO.code)) {
throw new ValidationException(
"missing code in a calendar exception");
}
if (exceptionDTO.date == null) {
throw new ValidationException(
"missing date in a calendar exception");
}
// find by code
try {
CalendarException exception = baseCalendar
.getCalendarExceptionByCode(exceptionDTO.code);
update(exception, exceptionDTO);
} catch (InstanceNotFoundException e) {
// find by date
CalendarException exception = baseCalendar
.getOwnExceptionDay(DateConverter
.toLocalDate(exceptionDTO.date));
if (exception != null) {
throw new ValidationException(
"exception date already exists");
} else {
try {
baseCalendar
.addExceptionDay(toEntity(exceptionDTO));
} catch (IllegalArgumentException o) {
throw new ValidationException(o.getMessage());
}
}
}
}
}
if (baseCalendarDTO.calendarDatas != null) {
for (CalendarDataDTO calendarDataDTO : baseCalendarDTO.calendarDatas) {
if (StringUtils.isBlank(calendarDataDTO.code)) {
throw new ValidationException(
"missing code in a calendar data version");
}
// find by code
try {
CalendarData version = baseCalendar
.getCalendarDataByCode(calendarDataDTO.code);
update(version, calendarDataDTO);
} catch (InstanceNotFoundException e) {
try {
baseCalendar.addNewVersion(toEntity(calendarDataDTO));
} catch (IllegalArgumentException o) {
throw new ValidationException(o.getMessage());
}
}
}
}
BaseCalendar parent = null;
if (!StringUtils.isBlank(baseCalendarDTO.parent)) {
try {
parent = Registry.getBaseCalendarDAO().findByCode(
baseCalendarDTO.parent);
} catch (InstanceNotFoundException e) {
throw new ValidationException(
"The base calendar parent not found");
}
}
baseCalendar.updateUnvalidated(baseCalendarDTO.name, parent);