Example #1
0
 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()));
 }
Example #2
0
 private void forceLoadCalendar(BaseCalendar baseCalendar) {
   for (CalendarData calendarData : baseCalendar.getCalendarDataVersions()) {
     calendarData.getHoursPerDay().size();
     if (calendarData.getParent() != null) {
       forceLoadCalendar(calendarData.getParent());
     }
   }
   baseCalendar.getExceptions().size();
 }
Example #3
0
 @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;
 }
Example #4
0
 @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"));
     }
 }
Example #5
0
 /**
  * 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;
    }
Example #7
0
    @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;
    }
Example #8
0
 private static void loadingExceptionsWithTheirTypes(
         BaseCalendar baseCalendar) {
     Set<CalendarException> exceptions = baseCalendar.getExceptions();
     for (CalendarException each : exceptions) {
         each.getType().getName();
     }
 }
Example #9
0
 @Transactional
 public void generateCalendarCodes() {
     if (getBaseCalendar().isCodeAutogenerated()) {
         baseCalendar
                 .generateCalendarExceptionCodes(getNumberOfDigitsCode());
     }
 }
Example #10
0
 @Override
 public boolean isOwnExceptionDay() {
     if (baseCalendar != null) {
         return (baseCalendar.getOwnExceptionDay(selectedDate) != null);
     }
     return false;
 }
Example #11
0
    @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);
    }
Example #12
0
 public static void forceLoadBaseCalendar(BaseCalendar baseCalendar) {
     for (CalendarData calendarData : baseCalendar.getCalendarDataVersions()) {
         if (calendarData.getParent() != null) {
             forceLoadBaseCalendar(calendarData.getParent());
         }
     }
     loadingExceptionsWithTheirTypes(baseCalendar);
 }
Example #13
0
 @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());
 }
Example #14
0
 @Override
 @Transactional
 public void confirmRemove(BaseCalendar calendar) {
     try {
         baseCalendarDAO.remove(calendar.getId());
     } catch (InstanceNotFoundException e) {
         throw new RuntimeException(e);
     }
 }
Example #15
0
 @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);
         }
     }
 }
Example #16
0
    @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;
    }
Example #18
0
 protected BaseCalendar getFromDB(BaseCalendar baseCalendar) {
     return getFromDB(baseCalendar.getId());
 }