/** * Makes a {@link CalendarException} from a {@link CalendarExceptionDTO}. * * @param calendarExceptionDTO * CalendarExceptionDTO to extract data from. * @return CalendarException with the CalendarException that we want. * @throws InstanceNotFoundException */ private CalendarException toCalendarException(CalendarExceptionDTO calendarExceptionDTO) throws InstanceNotFoundException { LocalDate date = null; if (calendarExceptionDTO.date != null) { date = LocalDate.fromDateFields(calendarExceptionDTO.date); } CalendarExceptionType calendarExceptionType; if (calendarExceptionDTO.working) { calendarExceptionType = calendarExceptionTypeDAO.findUniqueByName("WORKING_DAY"); } else { calendarExceptionType = calendarExceptionTypeDAO.findUniqueByName("NOT_WORKING_DAY"); } return CalendarException.create( date, EffortDuration.hours(calendarExceptionDTO.hours).plus(EffortDuration.minutes(calendarExceptionDTO.minutes)), calendarExceptionType); }
@Override @Transactional public void loadRequiredData() { if (calendarExceptionTypeDAO.getAll().size() == 0) { for (PredefinedCalendarExceptionTypes type : PredefinedCalendarExceptionTypes.values()) { CalendarExceptionType calendarExceptionType = type.getCalendarExceptionType(); calendarExceptionType.setCode( entitySequenceDAO.getNextEntityCodeWithoutTransaction( EntityNameEnum.CALENDAR_EXCEPTION_TYPE)); calendarExceptionType.setCodeAutogenerated(true); calendarExceptionTypeDAO.save(calendarExceptionType); } } boolean condition = calendarExceptionTypeDAO.existsByName( PredefinedCalendarExceptionTypes.NOT_WORKING_DAY.getCalendarExceptionType()); if (!condition) { CalendarExceptionType calendarExceptionType = PredefinedCalendarExceptionTypes.NOT_WORKING_DAY.getCalendarExceptionType(); calendarExceptionType.setCode( entitySequenceDAO.getNextEntityCodeWithoutTransaction( EntityNameEnum.CALENDAR_EXCEPTION_TYPE)); calendarExceptionType.setCodeAutogenerated(true); calendarExceptionTypeDAO.save(calendarExceptionType); } condition = calendarExceptionTypeDAO.existsByName( PredefinedCalendarExceptionTypes.WORKING_DAY.getCalendarExceptionType()); if (!condition) { CalendarExceptionType calendarExceptionType = PredefinedCalendarExceptionTypes.WORKING_DAY.getCalendarExceptionType(); calendarExceptionType.setCode( entitySequenceDAO.getNextEntityCodeWithoutTransaction( EntityNameEnum.CALENDAR_EXCEPTION_TYPE)); calendarExceptionType.setCodeAutogenerated(true); calendarExceptionTypeDAO.save(calendarExceptionType); } }
@Override @Transactional(readOnly = true) public List<CalendarExceptionType> getCalendarExceptionTypes() { return calendarExceptionTypeDAO.list(CalendarExceptionType.class); }