Package org.libreplan.business.calendars.entities

Examples of org.libreplan.business.calendars.entities.BaseCalendar


        if (StringUtils.isBlank(calendarCode)) {
            calendar = Registry.getConfigurationDAO().getConfiguration().
                getDefaultCalendar().newDerivedResourceCalendar();

        } else {
            BaseCalendar baseCalendar = Registry.getBaseCalendarDAO()
                    .findByCode(calendarCode);
            calendar = baseCalendar.newDerivedResourceCalendar();
        }

        setCalendar(calendar);

    }
View Full Code Here


    public Order createValidOrder(String name) {
        Order order = Order.create();
        order.setName(name);
        order.setCode(UUID.randomUUID().toString());
        order.setInitDate(new Date());
        BaseCalendar basicCalendar = BaseCalendarTest.createBasicCalendar();
        calendarDAO.save(basicCalendar);
        order.setCalendar(basicCalendar);
        orderDAO.save(order);
        return order;
    }
View Full Code Here

            LocalDate start, LocalDate end, int totalHours) {

        final LocalDate previousEndDate = resourceAllocation.getEndDate();

        EffortDuration capacity;
        BaseCalendar calendar = resourceAllocation.getTask().getCalendar();
        int daysDuration = daysWithAllocatedHours(resourceAllocation).size();

        // Calculate hours per day and round values
        BigDecimal[] hoursToAllocatePerDay = generateHoursToAllocateFor(daysDuration, totalHours);
        hoursToAllocatePerDay = roundValues(hoursToAllocatePerDay, HOUR_FRAGMENTATION);

        // Calculate reminder (difference between totalHours and sum of hours calculated)
        BigDecimal totalHoursToAllocate = sumHoursPerDay(hoursToAllocatePerDay);
        assert(totalHoursToAllocate.compareTo(BigDecimal.valueOf(totalHours)) <= 0);
        BigDecimal remindingHours = BigDecimal.valueOf(totalHours).subtract(totalHoursToAllocate);
        allocateRemindingHours(hoursToAllocatePerDay, remindingHours);
        avoidZeroHoursInDays(hoursToAllocatePerDay);

        assert(hoursToAllocatePerDay.length == daysDuration);

        // Starting from startDate do allocation, one slot of hours per day in resource
        LocalDate day = new LocalDate(start);
        EffortDuration hours = EffortDuration.zero();
        int i = 0;
        while (i < hoursToAllocatePerDay.length) {
            hours = EffortDuration
                    .fromHoursAsBigDecimal(hoursToAllocatePerDay[i]);
            capacity = calendar.getCapacityOn(PartialDay.wholeDay(day));
            if (!EffortDuration.zero().equals(capacity)) {
                allocate(resourceAllocation, day, hours);
                i++;
            }
            day = day.plusDays(1);
View Full Code Here

    }

    private void removeResourceCalendarInstances(List<BaseCalendar> list) {
        for (Iterator<BaseCalendar> iterator = list.iterator(); iterator
                .hasNext();) {
            BaseCalendar baseCalendar = iterator.next();
            if (baseCalendar instanceof ResourceCalendar) {
                iterator.remove();
            }
        }
    }
View Full Code Here

    }

    private BaseCalendar mockCalendarWithAvailability(
            final AvailabilityTimeLine availability,
            final EffortDuration workingDay) {
        final BaseCalendar result = createNiceMock(BaseCalendar.class);
        expect(result.getAvailability()).andReturn(availability).anyTimes();
        expect(result.getCapacityOn(isA(PartialDay.class)))
                .andAnswer(new IAnswer<EffortDuration>() {

                    @Override
                    public EffortDuration answer() throws Throwable {
                        PartialDay day = (PartialDay) getCurrentArguments()[0];
                        if (availability.isValid(day.getDate())) {
                            return day.limitWorkingDay(workingDay);
                        } else {
                            return zero();
                        }
                    }
                }).anyTimes();
        expect(
                result.asDurationOn(isA(PartialDay.class),
                        isA(ResourcesPerDay.class))).andAnswer(
                new IAnswer<EffortDuration>() {

                    @Override
                    public EffortDuration answer() throws Throwable {
                        PartialDay day = (PartialDay) getCurrentArguments()[0];
                        ResourcesPerDay resourcesPerDay = (ResourcesPerDay) getCurrentArguments()[1];
                        if (availability.isValid(day.getDate())) {
                            return day.limitWorkingDay(resourcesPerDay
                                    .asDurationGivenWorkingDayOf(workingDay));
                        } else {
                            return zero();
                        }
                    }
                }).anyTimes();
        expect(result.thereAreCapacityFor(isA(AvailabilityTimeLine.class),
                        isA(ResourcesPerDay.class), isA(EffortDuration.class)))
                .andAnswer(new IAnswer<Boolean>() {

                    @Override
                    public Boolean answer() throws Throwable {
View Full Code Here

    private Order createValidOrder(String name) {
        Order order = Order.create();
        order.setName(name);
        order.setCode(UUID.randomUUID().toString());
        order.setInitDate(new Date());
        BaseCalendar basicCalendar = BaseCalendarTest.createBasicCalendar();
        calendarDAO.save(basicCalendar);
        OrderVersion orderVersion = ResourceAllocationDAOTest.setupVersionUsing(scenarioManager,
                order);
        order.useSchedulingDataFor(orderVersion);
        return order;
View Full Code Here

                baseCalendars.add(toBaseCalendar(calendarDTO, null));

            } else {

                BaseCalendar parent = findBaseCalendarParent(baseCalendars,
                        calendarDTO.parent);

                if (parent != null) {

                    baseCalendars.add(toBaseCalendar(calendarDTO, parent));
View Full Code Here

        Set<CalendarException> calendarExceptions = getCalendarExceptions(calendarDTO.calendarExceptions);

        List<CalendarData> calendarDatas = getCalendarDatas(
                calendarDTO.calendarWeeks, parent);

        BaseCalendar baseCalendar = BaseCalendar.createUnvalidated(code, name,
                parent, calendarExceptions, calendarDatas);

        baseCalendar.setCodeAutogenerated(true);

        baseCalendar.setName(name);

        if (parent != null) {
            baseCalendar.setParent(parent);
        }

        baseCalendar.generateCalendarExceptionCodes(entitySequenceDAO
                .getNumberOfDigitsCode(EntityNameEnum.CALENDAR));

        return baseCalendar;
    }
View Full Code Here

        return Profile.create(UUID.randomUUID().toString(), roles);
    }

    private Order createValidOrder() {
        Order order = Order.create();
        BaseCalendar baseCalendar = BaseCalendar.createBasicCalendar();
        baseCalendar.setName(UUID.randomUUID().toString());
        baseCalendarDAO.save(baseCalendar);
        order.setCalendar(baseCalendar);
        order.setInitDate(new Date());
        order.setName(UUID.randomUUID().toString());
        order.setCode(UUID.randomUUID().toString());
View Full Code Here

    @Test
    @Transactional
    public void testCreateAndSave() {
        int previous = baseCalendarModel.getBaseCalendars().size();
        baseCalendarModel.initCreate();
        BaseCalendar baseCalendar = baseCalendarModel.getBaseCalendar();
        baseCalendar.setName("Test");
        Capacity capacity = Capacity.create(hours(8));
        setCapacity(baseCalendar, capacity);
        baseCalendarModel.confirmSave();
        Map<Long, Set<BaseCalendar>> currentCalendars = BaseEntity
                .byId(baseCalendarModel.getBaseCalendars());
        assertThat(currentCalendars.size(), equalTo(previous + 1));

        BaseCalendar createdCalendar = currentCalendars
                .get(baseCalendar.getId()).iterator().next();
        assertThat(createdCalendar, notNullValue());
        assertThat(createdCalendar.getCapacityConsideringCalendarDatasOn(
                new LocalDate(), Days.MONDAY), equalTo(capacity));
    }
View Full Code Here

TOP

Related Classes of org.libreplan.business.calendars.entities.BaseCalendar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.