private void reattachAndLoadCalendar(TaskElement taskElement) { BaseCalendar calendar = taskElement.getCalendar(); if (calendar == null) { return; } baseCalendarDAO.reattach(calendar); forceLoadCalendar(calendar); calendar.getCapacityOn(PartialDay.wholeDay(taskElement.getIntraDayStartDate().getDate())); }
private void forceLoadCalendar(BaseCalendar baseCalendar) { for (CalendarData calendarData : baseCalendar.getCalendarDataVersions()) { calendarData.getHoursPerDay().size(); if (calendarData.getParent() != null) { forceLoadCalendar(calendarData.getParent()); } } baseCalendar.getExceptions().size(); }
@Override public Set<IntegrationEntity> getChildren() { Set<IntegrationEntity> children = new HashSet<IntegrationEntity>(); if (baseCalendar != null) { children.addAll(baseCalendar.getExceptions()); children.addAll(baseCalendar.getCalendarDataVersions()); children.addAll(baseCalendar.getCalendarAvailabilities()); } return children; }
@Override public void checkInvalidValuesCalendar(BaseCalendar entity) throws ValidationException { if (baseCalendarDAO.thereIsOtherWithSameName(entity)) { InvalidValue[] invalidValues2 = { new InvalidValue(_( "{0} already exists", entity.getName()), BaseCalendar.class, "name", entity.getName(), entity) }; throw new ValidationException(invalidValues2, _("Could not save the new calendar")); } }
/** * Don't pose as transient anymore calendar and all data hanging from * calendar (data versions, availabilities and exceptions) * * @param calendar */ private void dontPoseAsTransientObjectAnymore(BaseCalendar calendar) { calendar.dontPoseAsTransientObjectAnymore(); for (CalendarData each: calendar.getCalendarDataVersions()) { each.dontPoseAsTransientObjectAnymore(); } for (CalendarAvailability each : calendar.getCalendarAvailabilities()) { each.dontPoseAsTransientObjectAnymore(); } for (CalendarException each : calendar.getExceptions()) { each.dontPoseAsTransientObjectAnymore(); } }
/** * Search for a {@link BaseCalendar} that has this name. * * @param baseCalendars * List<BaseCalendar> to search into. * @param name * Search condition * @return BaseCalendar with the name equal to the search condition. */ private BaseCalendar findBaseCalendarParent( List<BaseCalendar> baseCalendars, String name) { for (BaseCalendar baseCalendar: baseCalendars){ if (Objects.equals(baseCalendar.getName(), name)){ return baseCalendar; } } return null; }
@Override @Transactional(readOnly = true) public List<BaseCalendar> getPossibleParentCalendars() { List<BaseCalendar> baseCalendars = getBaseCalendars(); if (getBaseCalendar() != null) { for (BaseCalendar calendar : baseCalendars) { if (calendar.getId().equals(getBaseCalendar().getId())) { baseCalendars.remove(calendar); break; } } } return baseCalendars; }
private static void loadingExceptionsWithTheirTypes( BaseCalendar baseCalendar) { Set<CalendarException> exceptions = baseCalendar.getExceptions(); for (CalendarException each : exceptions) { each.getType().getName(); } }
@Transactional public void generateCalendarCodes() { if (getBaseCalendar().isCodeAutogenerated()) { baseCalendar .generateCalendarExceptionCodes(getNumberOfDigitsCode()); } }
@Override public boolean isOwnExceptionDay() { if (baseCalendar != null) { return (baseCalendar.getOwnExceptionDay(selectedDate) != null); } return false; }
@Override @Transactional(readOnly = true) public void initCreate() { editing = false; boolean codeGenerated = (configurationDAO.getConfiguration() != null) ? configurationDAO .getConfiguration().getGenerateCodeForBaseCalendars() : false; this.baseCalendar = BaseCalendar.createBasicCalendar(""); if (codeGenerated) { setDefaultCode(); } baseCalendar.setCodeAutogenerated(codeGenerated); }
public static void forceLoadBaseCalendar(BaseCalendar baseCalendar) { for (CalendarData calendarData : baseCalendar.getCalendarDataVersions()) { if (calendarData.getParent() != null) { forceLoadBaseCalendar(calendarData.getParent()); } } loadingExceptionsWithTheirTypes(baseCalendar); }
@Override @Transactional(readOnly = true) public boolean isDefaultCalendar(BaseCalendar baseCalendar) { Configuration configuration = configurationDAO.getConfiguration(); if (configuration == null) { return false; } BaseCalendar defaultCalendar = configuration.getDefaultCalendar(); if (defaultCalendar == null) { return false; } if (baseCalendar == null) { return false; } return baseCalendar.getId().equals( defaultCalendar .getId()); }
@Override @Transactional public void confirmRemove(BaseCalendar calendar) { try { baseCalendarDAO.remove(calendar.getId()); } catch (InstanceNotFoundException e) { throw new RuntimeException(e); } }
@Override public void createException(CalendarExceptionType type, LocalDate startDate, LocalDate endDate, Capacity capacity) { for (LocalDate date = startDate; date.compareTo(endDate) <= 0; date = date .plusDays(1)) { if (baseCalendar.getOwnExceptionDay(date) != null) { getBaseCalendar().updateExceptionDay(date, capacity, type); } else { CalendarException day = CalendarException.create("", date, capacity, type); getBaseCalendar().addExceptionDay(day); } } }
@Override @Transactional(readOnly = true) public void setParent(BaseCalendar parent) { try { parent = baseCalendarDAO.find(parent.getId()); } catch (InstanceNotFoundException e) { throw new RuntimeException(e); } forceLoad(parent); if (getBaseCalendar() != null) { getBaseCalendar().setParent(parent, selectedDate); } }
/** * Makes a {@link BaseCalendar} from a {@link CalendarDTO}. * * @param calendarDTO * CalendarDTO to extract data from. * @return BaseCalendar with the calendar that we want. * @throws InstanceNotFoundException, ValidationException */ private BaseCalendar toBaseCalendar(CalendarDTO calendarDTO, BaseCalendar parent) throws InstanceNotFoundException { String code = getCode(EntityNameEnum.CALENDAR); String name = validateName(calendarDTO.name); Set<CalendarException> calendarExceptions = getCalendarExceptions(calendarDTO.calendarExceptions); List<CalendarData> calendarData = getCalendarData(calendarDTO.calendarWeeks, parent); BaseCalendar baseCalendar = BaseCalendar.createUnvalidated(code, name, parent, calendarExceptions, calendarData); baseCalendar.setCodeAutogenerated(true); baseCalendar.setName(name); if (parent != null) { baseCalendar.setParent(parent); } baseCalendar.generateCalendarExceptionCodes(entitySequenceDAO.getNumberOfDigitsCode(EntityNameEnum.CALENDAR)); return baseCalendar; }
protected BaseCalendar getFromDB(BaseCalendar baseCalendar) { return getFromDB(baseCalendar.getId()); }