Package org.libreplan.business.costcategories.entities

Examples of org.libreplan.business.costcategories.entities.HourCost


        costCategoryDAO.save(costCategory);
    }

    @Override
    public void addHourCost() {
        HourCost hourCost = HourCost.create();
        hourCost.setCode("");
        costCategory.addHourCost(hourCost);

    }
View Full Code Here


        CostCategory costCategory = createValidCostCategory();
        TypeOfWorkHours type1 = TypeOfWorkHours.create(UUID.randomUUID().toString(),
                UUID.randomUUID().toString());
        type1.setDefaultPrice(BigDecimal.TEN);
        typeOfWorkHoursDAO.save(type1);
        HourCost hourCost1 = HourCost.create(BigDecimal.ONE, new LocalDate(2009, 11,1));
        hourCost1.setType(type1);
        hourCost1.setEndDate(new LocalDate(2009, 11,10));
        costCategory.addHourCost(hourCost1);

        HourCost hourCost2 = HourCost.create(BigDecimal.ONE, new LocalDate(2009, 11,1));
        hourCost2.setType(type1);
        hourCost2.setEndDate(new LocalDate(2009, 11,10));
        assertFalse(costCategory.canAddHourCost(hourCost2));

        hourCost2.setInitDate(new LocalDate(2009,10,15));
        hourCost2.setEndDate(new LocalDate(2009,11,1));
        assertFalse(costCategory.canAddHourCost(hourCost2));

        hourCost2.setInitDate(new LocalDate(2009,11,10));
        hourCost2.setEndDate(new LocalDate(2009,11,10));
        assertFalse(costCategory.canAddHourCost(hourCost2));

        hourCost2.setInitDate(new LocalDate(2009,10,15));
        hourCost2.setEndDate(new LocalDate(2009,10,20));
        assertTrue(costCategory.canAddHourCost(hourCost2));

        TypeOfWorkHours type2 = TypeOfWorkHours.create(UUID.randomUUID().toString(),
                UUID.randomUUID().toString());
        type2.setDefaultPrice(BigDecimal.TEN);
        typeOfWorkHoursDAO.save(type2);
        hourCost2.setType(type2);
        hourCost2.setInitDate(new LocalDate(2009,10,15));
        hourCost2.setEndDate(new LocalDate(2009,11,1));
        assertTrue(costCategory.canAddHourCost(hourCost2));

        hourCost2.setType(type1);
        hourCost2.setInitDate(new LocalDate(2009,10,15));
        hourCost2.setEndDate(null);
        assertFalse(costCategory.canAddHourCost(hourCost2));
        hourCost2.setInitDate(new LocalDate(2009,11,9));
        assertFalse(costCategory.canAddHourCost(hourCost2));
        hourCost2.setInitDate(new LocalDate(2009,11,11));
        assertTrue(costCategory.canAddHourCost(hourCost2));

        hourCost1.setEndDate(null);
        assertFalse(costCategory.canAddHourCost(hourCost2));
        hourCost2.setEndDate(new LocalDate(2009,11,30));
        assertFalse(costCategory.canAddHourCost(hourCost2));
        hourCost1.setEndDate(new LocalDate(2009,11,20));
        assertFalse(costCategory.canAddHourCost(hourCost2));
        hourCost1.setEndDate(new LocalDate(2009,12,1));
        assertTrue(costCategory.canAddHourCost(hourCost2));
View Full Code Here

    @Test
    @Transactional
    public void testListHourCosts() {
        CostCategory costCategory = createValidCostCategory();
        HourCost hourCost = HourCost.create(BigDecimal.ONE, new LocalDate(2009,11,1));
        TypeOfWorkHours type =
            TypeOfWorkHours.create(UUID.randomUUID().toString(), UUID.randomUUID().toString());
        hourCost.setType(type);
        int previous = costCategory.getHourCosts().size();

        costCategory.addHourCost(hourCost);
        costCategoryDAO.save(costCategory);
        assertEquals(previous + 1, costCategory.getHourCosts().size());

        costCategory.removeHourCost(hourCost);
        costCategoryDAO.save(costCategory);
        assertEquals(previous, costCategory.getHourCosts().size());
        assertNull(hourCost.getCategory());
    }
View Full Code Here

        //types have to be saved before using them
        //otherwise, the overlapping validation will fail
        typeOfWorkHoursDAO.save(type1);
        typeOfWorkHoursDAO.save(type2);

        HourCost hourCost1 = HourCost.create(BigDecimal.ONE, new LocalDate(2009, 11,1));
        hourCost1.setType(type1);
        hourCost1.setEndDate(new LocalDate(2009, 11,10));
        costCategory.addHourCost(hourCost1);

        HourCost hourCost2 = HourCost.create(BigDecimal.ONE, new LocalDate(2009, 11,1));
        hourCost2.setType(type2);
        hourCost2.setEndDate(new LocalDate(2009, 11,10));
        costCategory.addHourCost(hourCost2);

        //this save is correct
        costCategoryDAO.save(costCategory);

        hourCost2.setType(type1);
        //this save should throw a exception
        costCategoryDAO.save(costCategory);
    }
View Full Code Here

    }

    private void givenCostCategory() {
        costCategory = CostCategory.createUnvalidated("default-cost-category" + UUID.randomUUID(),
                "default-cost-category" + UUID.randomUUID(), true);
        HourCost hourCost = HourCost.createUnvalidated("default-hour-cost" + UUID.randomUUID(),
                new BigDecimal(50), new LocalDate());
        hourCost.setType(typesOfWorkHours.get(0));
        costCategory.addHourCost(hourCost);
        costCategoryDAO.save(costCategory);
    }
View Full Code Here

                        }
                    }
                });
        assertTrue(costCategory.getHourCosts().size() == 1);

        final HourCost hourCost = transactionService
                .runOnTransaction(new IOnTransaction<HourCost>() {
                    @Override
                    public HourCost execute() {
                        try {
                            HourCost cost = hourCostDAO
                                    .findByCode(hourCostCode);
                            cost.getType().getCode();
                            return cost;
                        } catch (InstanceNotFoundException e) {
                            throw new RuntimeException(e);
                        }
                    }
                });
        LocalDate currentDate = LocalDate.fromDateFields(new Date());
        assertTrue(hourCost.getInitDate().compareTo(currentDate) == 0);
        assertFalse(hourCost.getEndDate() == null);
        assertTrue(hourCost.getEndDate().compareTo(hourCost.getInitDate()) == 0);
        assertTrue(hourCost.getPriceCost().compareTo(new BigDecimal(3)) == 0);
        assertTrue(hourCost.getType().getCode().equalsIgnoreCase(
                typeOfWorkHoursCodeA));

        transactionService.runOnTransaction(new IOnTransaction<Void>() {
            @Override
            public Void execute() {
                costCategoryDAO.flush();
                sessionFactory.getCurrentSession().evict(costCategory);
                return null;
            }
        });

        costCategory.dontPoseAsTransientObjectAnymore();

        // Update the previous cost category
        Set<HourCostDTO> cc2_HourCostDTOs = new HashSet<HourCostDTO>();

        XMLGregorianCalendar initDate2 = DateConverter
                .toXMLGregorianCalendar(new Date());
        XMLGregorianCalendar endDate2 = DateConverter
                .toXMLGregorianCalendar(getNextMonthDate());

        HourCostDTO cc2_1_HourCostDTO = new HourCostDTO(hourCostCode,
                new BigDecimal(100), initDate2, endDate2, typeOfWorkHoursCodeB);
        cc2_HourCostDTOs.add(cc2_1_HourCostDTO);
        CostCategoryDTO cc2 = new CostCategoryDTO(costCategoryCode,
                "updateCC1", false, cc2_HourCostDTOs);

        /* Cost category type list. */
        costCategoryListDTO = createCostCategoryListDTO(cc2);

        instanceConstraintViolationsList = costCategoryService
                .addCostCategories(costCategoryListDTO).instanceConstraintViolationsList;

        /* Test. */
        assertTrue(instanceConstraintViolationsList.toString(),
                instanceConstraintViolationsList.size() == 0);
        transactionService.runOnTransaction(new IOnTransaction<Void>() {
            @Override
            public Void execute() {
                assertTrue(costCategoryDAO.existsByCode(cc1.code));
                assertTrue(hourCostDAO.existsByCode(cc1_1_HourCostDTO.code));
                return null;
            }
        });

        final CostCategory costCategory2 = transactionService
                .runOnTransaction(new IOnTransaction<CostCategory>() {
                    @Override
                    public CostCategory execute() {
                        CostCategory cost;
                        try {
                            cost = costCategoryDAO.findByCode(costCategoryCode);
                            cost.getHourCosts().size();
                            return cost;
                        } catch (InstanceNotFoundException e) {
                            throw new RuntimeException(e);
                        }
                    }
                });

        // Check if the changes was updated
        assertTrue(costCategory2.getHourCosts().size() == 1);
        assertTrue(costCategory2.getName().equalsIgnoreCase("updateCC1"));
        assertFalse(costCategory2.getEnabled());

        final HourCost hourCost2 = transactionService
                .runOnTransaction(new IOnTransaction<HourCost>() {
                    @Override
                    public HourCost execute() {
                        try {
                            HourCost cost = hourCostDAO
                                    .findByCode(cc1_1_HourCostDTO.code);
                            cost.getType().getCode();
                            return cost;
                        } catch (InstanceNotFoundException e) {
                            throw new RuntimeException(e);
                        }
                    }
View Full Code Here

        CostCategory costCategory = CostCategory.createUnvalidated(StringUtils
                .trim(costCategoryDTO.code), StringUtils
                .trim(costCategoryDTO.name), costCategoryDTO.enabled);

        for (HourCostDTO hourCostDTO : costCategoryDTO.hourCostDTOs) {
            HourCost hourCost = toEntity(hourCostDTO);
            hourCost.setCategory(costCategory);
            costCategory.addHourCost(hourCost);
        }

        return costCategory;
View Full Code Here

        if(hourCostDTO.initDate != null){
            initDate = DateConverter.toLocalDate(hourCostDTO.initDate);
        }

        //Create new hour cost
        HourCost hourCost = HourCost.createUnvalidated(hourCostDTO.code,
                hourCostDTO.priceCost, initDate);

        // optional properties
        if (hourCostDTO.endDate != null) {
            hourCost.setEndDate(DateConverter.toLocalDate(hourCostDTO.endDate));
        }

        if (hourCostDTO.type != null) {
            try {
                TypeOfWorkHours typeOfWorkHours = Registry
                        .getTypeOfWorkHoursDAO().findUniqueByCode(
                                hourCostDTO.type);
                hourCost.setType(typeOfWorkHours);
            } catch (InstanceNotFoundException e) {
                throw new ValidationException(
                        "There is no type of work hours with this code");
            }
        }
View Full Code Here

            if (StringUtils.isBlank(hourCostDTO.code)) {
                throw new ValidationException("missing code in a hour cost");
            }

            try {
                HourCost hourCost = costCategory
                        .getHourCostByCode(hourCostDTO.code);
                updateHourCost(hourCost, hourCostDTO);
            } catch (InstanceNotFoundException e) {
                HourCost hourCost = toEntity(hourCostDTO);
                hourCost.setCategory(costCategory);
                costCategory.addHourCost(hourCost);
            }
        }

        /* 2: Update cost category basic properties. */
 
View Full Code Here

        return costCategoryModel.getHourCosts();
    }


    private TypeOfWorkHours getTypeOfWorkHours(Row listitem) {
        HourCost hourCost = (HourCost) listitem.getValue();
        return hourCost.getType();
    }
View Full Code Here

TOP

Related Classes of org.libreplan.business.costcategories.entities.HourCost

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.