Examples of CostCategory


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

            public Void execute() {
                assertTrue(costCategoryDAO.existsByCode(cc1.code));
                return null;
            }
        });
        final CostCategory costCategory = transactionService
                .runOnTransaction(new IOnTransaction<CostCategory>() {
                    @Override
                    public CostCategory execute() {
                        CostCategory cost;
                        try {
                            cost = costCategoryDAO.findByCode(cc1.code);
                            cost.getHourCosts().size();
                            return cost;
                        } catch (InstanceNotFoundException e) {
                            throw new RuntimeException(e);
                        }
                    }
                });
        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

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

    @Test
    @Transactional
    public void testAddResourceWithCostAssignments() {

        /* Create a CostCategory. */
        CostCategory costCategory = createCostCategory();

        /* Create resource DTOs. */
        MachineDTO m1 = new MachineDTO("name", "desc");
        ResourcesCostCategoryAssignmentDTO a1m1 = new ResourcesCostCategoryAssignmentDTO(
                ' ' + costCategory.getName().toUpperCase() + ' ', getDate(2001,
                        1, 1), null);
        m1.resourcesCostCategoryAssignments.add(a1m1);
        m1.resourcesCostCategoryAssignments
                .add(new ResourcesCostCategoryAssignmentDTO(costCategory
                        .getName(), getDate(2000, 1, 1), getDate(2000, 4, 1)));

        MachineDTO m2 = new MachineDTO("name", "desc");
        m2.resourcesCostCategoryAssignments
                .add(new ResourcesCostCategoryAssignmentDTO(a1m1.code,
                        costCategory.getName().toUpperCase(), getDate(2001, 1,
                                1), null)); // Repeated assignment code
        // (used by another machine).
        m2.resourcesCostCategoryAssignments
                .add(new ResourcesCostCategoryAssignmentDTO(null, costCategory
                        .getName().toUpperCase(), getDate(2000, 1, 1), getDate(
                        2000, 4, 1))); // Missing
        // assignment code (autogenerated code).

        MachineDTO m3 = new MachineDTO("name", "desc");
        ResourcesCostCategoryAssignmentDTO a1m3 = new ResourcesCostCategoryAssignmentDTO(
                costCategory.getName(), getDate(2001, 1, 1), null);
        m3.resourcesCostCategoryAssignments.add(a1m3);
        m3.resourcesCostCategoryAssignments
                .add(new ResourcesCostCategoryAssignmentDTO(a1m3.code, // Repeated
                                                                       // assignment
                                                                       // code
                                                                       // in
                                                                       // this
                                                                       // machine.
                        costCategory.getName(), getDate(2000, 1, 1), getDate(
                                2000, 4, 1)));

        /* Test. */
        List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = resourceService
                .addResources(createResourceListDTO(m1, m2, m3)).instanceConstraintViolationsList;
View Full Code Here

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

    @Test
    @Transactional
    public void testAddResourceWithCostAssignmentWithoutStartDate() {

        /* Create a CostCategory. */
        CostCategory costCategory = createCostCategory();

        /* Create a resource DTO. */
        MachineDTO machineDTO = new MachineDTO("name", "desc");
        machineDTO.resourcesCostCategoryAssignments
                .add(new ResourcesCostCategoryAssignmentDTO(costCategory
                        .getName(), null, // Start date not specified.
                        getDate(2000, 1, 1)));

        /* Test. */
        assertOneConstraintViolation(resourceService
View Full Code Here

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

    @Test
    @Transactional
    public void testAddResourceWithCostAssignmentWithNegativeInterval() {

        /* Create a CostCategory. */
        CostCategory costCategory = createCostCategory();

        /* Create a resource DTO. */
        MachineDTO machineDTO = new MachineDTO("name", "desc");
        machineDTO.resourcesCostCategoryAssignments
                .add(new ResourcesCostCategoryAssignmentDTO(costCategory
                        .getName(), getDate(2000, 2, 1), getDate(2000, 1, 1)));

        /* Test. */
        assertOneConstraintViolation(resourceService
                .addResources(createResourceListDTO(machineDTO)));
View Full Code Here

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

    @Test
    @Transactional
    public void testAddResourcesWithOverlappingInCostAssignments() {

        /* Create a CostCategory. */
        CostCategory costCategory = createCostCategory();

        /*
         * Create a resource DTOs. Each resource contains one cost assignment
         * overlapping.
         */
        MachineDTO m1 = createMachineDTOWithTwoCostsAssignments("m1",
                costCategory.getName(), getDate(2000, 1, 1), null, getDate(
                        2000, 2, 1), null);

        MachineDTO m2 = createMachineDTOWithTwoCostsAssignments("m2",
                costCategory.getName(), getDate(2000, 2, 1), null, getDate(
                        2000, 1, 1), getDate(2000, 3, 1));

        MachineDTO m3 = createMachineDTOWithTwoCostsAssignments("m3",
                costCategory.getName(), getDate(2000, 2, 1),
                getDate(2000, 4, 1), getDate(2000, 3, 1), null);

        MachineDTO m4 = createMachineDTOWithTwoCostsAssignments("m4",
                costCategory.getName(), getDate(2000, 2, 1),
                getDate(2000, 5, 1), getDate(2000, 1, 1), getDate(2000, 3, 1));

        MachineDTO m5 = createMachineDTOWithTwoCostsAssignments("m5",
                costCategory.getName(), getDate(2000, 2, 1),
                getDate(2000, 5, 1), getDate(2000, 3, 1), getDate(2000, 4, 1));

        MachineDTO m6 = createMachineDTOWithTwoCostsAssignments("m6",
                costCategory.getName(), getDate(2000, 2, 1),
                getDate(2000, 5, 1), getDate(2000, 4, 1), getDate(2000, 6, 1));

        MachineDTO m7 = createMachineDTOWithTwoCostsAssignments("m7",
                costCategory.getName(), getDate(2000, 2, 1),
                getDate(2000, 5, 1), getDate(2000, 1, 1), getDate(2000, 2, 1));

        MachineDTO m8 = createMachineDTOWithTwoCostsAssignments("m8",
                costCategory.getName(), getDate(2000, 2, 1),
                getDate(2000, 5, 1), getDate(2000, 5, 1), getDate(2000, 6, 1));

        MachineDTO m9 = createMachineDTOWithTwoCostsAssignments("m9",
                costCategory.getName(), getDate(2000, 2, 1),
                getDate(2000, 5, 1), getDate(2000, 2, 1), getDate(2000, 5, 1));

        /* Test. */
        ResourceListDTO resourceDTOs = createResourceListDTO(m1, m2, m3, m4,
                m5, m6, m7, m8, m9);
View Full Code Here

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

    @Transactional
    public void testUpdateResources() throws InstanceNotFoundException {

        CriterionType ctMachine = createCriterionType(ResourceEnum.MACHINE);
        CriterionType ctWorker = createCriterionType(ResourceEnum.WORKER);
        CostCategory costCategory = createCostCategory();

        /* Create a machine DTO. */
        MachineDTO m1 = new MachineDTO("name", "desc");
        CriterionSatisfactionDTO m1s1 = new CriterionSatisfactionDTO(
                ctMachine
                .getName(), "c1", getDate(2000, 1, 1), getDate(2000, 2, 1));
        m1.criterionSatisfactions.add(m1s1);
        ResourcesCostCategoryAssignmentDTO m1a1 = new ResourcesCostCategoryAssignmentDTO(
                costCategory.getName(), getDate(2000, 1, 1),
                getDate(2000, 2, 1));
        m1.resourcesCostCategoryAssignments.add(m1a1);

        /* Create a worker DTO. */
        String nif = getUniqueName();
        WorkerDTO w1 = new WorkerDTO(getUniqueName(), "surname", nif);
        CriterionSatisfactionDTO w1s1 = new CriterionSatisfactionDTO(
                ctWorker
                .getName(), "c1", getDate(2000, 1, 1), getDate(2000, 2, 1));
        w1.criterionSatisfactions.add(w1s1);
        ResourcesCostCategoryAssignmentDTO w1a1 = new ResourcesCostCategoryAssignmentDTO(
                costCategory.getName(), getDate(2000, 1, 1),
                getDate(2000, 2, 1));
        w1.resourcesCostCategoryAssignments.add(w1a1);

        /* Add resources. */
        assertNoConstraintViolations(resourceService
                .addResources(createResourceListDTO(m1, w1)));

        /*
         * Build DTOs for making the following update: + m1: update name, m1s1's
         * start date, and add a new cost category assignment. + w1: update
         * surname, w1a1's start date, and add a new criterion satisfaction.
         */
        MachineDTO m1Updated = new MachineDTO(m1.code, "name" + "UPDATED", null);
        CriterionSatisfactionDTO m1s1Updated = new CriterionSatisfactionDTO(
                m1s1.code, null, null, getDate(2000, 1, 2), null);
        m1Updated.criterionSatisfactions.add(m1s1Updated);
        ResourcesCostCategoryAssignmentDTO m1a2 = new ResourcesCostCategoryAssignmentDTO(
                costCategory.getName(), getDate(2000, 3, 1),
                getDate(2000, 4, 1));
        m1Updated.resourcesCostCategoryAssignments.add(m1a2);

        WorkerDTO w1Updated = new WorkerDTO(w1.code, null, "surname"
                + "UPDATED", null);
View Full Code Here

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

        IOnTransaction<CostCategory> create =
            new IOnTransaction<CostCategory>() {

            @Override
            public CostCategory execute() {
                CostCategory costCategory =
                    CostCategory.create(getUniqueName());
                costCategoryDAO.save(costCategory);
                return costCategory;
            }
        };
View Full Code Here

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

    @Override
    public CostCategory findUniqueByName(String name)
    throws InstanceNotFoundException {
        Criteria c = getSession().createCriteria(CostCategory.class).
        add(Restrictions.eq("name", name).ignoreCase());
        CostCategory costCategory = (CostCategory) c.uniqueResult();

        if (costCategory == null) {
            throw new InstanceNotFoundException(name,
                    CostCategory.class.getName());
        } else {
View Full Code Here

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

            throws InstanceNotFoundException {
        Validate.notNull(code);

        Criteria c = getSession().createCriteria(CostCategory.class).add(
                Restrictions.eq("code", code).ignoreCase());
        CostCategory costCategory = (CostCategory) c.uniqueResult();

        if (costCategory == null) {
            throw new InstanceNotFoundException(code, CostCategory.class
                    .getName());
        } else {
View Full Code Here

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

    @Transactional(readOnly=true)
    public CostCategory findByNameCaseInsensitive(String name)
            throws InstanceNotFoundException {
        Criteria c = getSession().createCriteria(CostCategory.class);
        c.add(Restrictions.ilike("name", name, MatchMode.EXACT));
        CostCategory result = (CostCategory) c.uniqueResult();

        if (result == null) {
            throw new InstanceNotFoundException(name,
                    getEntityClass().getName());
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.