Package org.libreplan.business.workreports.entities

Examples of org.libreplan.business.workreports.entities.WorkReport


            .getInstance();

    public static WorkReport toEntity(WorkReportDTO workReportDTO)
            throws InstanceNotFoundException {

        WorkReport workReport = WorkReport.create();

        // Mandatory fields
        workReport.setCode(workReportDTO.code);

        try {
            WorkReportType workReportType = Registry.getWorkReportTypeDAO()
                    .findUniqueByCode(workReportDTO.workReportType);
            workReport.setWorkReportType(workReportType);
        } catch (InstanceNotFoundException e) {
            throw new ValidationException(
                    "There is no type of work report with this code");
        }

        for (WorkReportLineDTO workReportLineDTO : workReportDTO.workReportLines) {
            workReport
                    .addWorkReportLine(toEntity(workReportLineDTO, workReport));
        }

        // Optional fields
        if (workReportDTO.date != null) {
            workReport.setDate(DateConverter.toDate(workReportDTO.date));
        }

        bindingStrategy.assignOrderElementsToWorkReportLine(workReport,
                bindingStrategy.getOrderElementsBound(workReportDTO));

        if (workReportDTO.resource != null) {
            try {
                Resource resource = Registry.getResourceDAO().findByCode(
                        workReportDTO.resource);
                workReport.setResource(resource);
            } catch (InstanceNotFoundException e) {
                workReport.setResource(null);
                throw new ValidationException(
                        "There is no resource with this code");
            }
        }

        if (workReportDTO.labels != null && !workReportDTO.labels.isEmpty()) {
            try {
                workReport.setLabels(LabelReferenceConverter
                        .toEntity(workReportDTO.labels));
            } catch (InstanceNotFoundException e) {
                throw new ValidationException(MessageFormat.format(
                        "There is no label with this code ",
                        (String) e.getKey()));
            }
        }

        if (workReportDTO.descriptionValues != null
                && !workReportDTO.descriptionValues.isEmpty()) {
            workReport
                    .setDescriptionValues(toEntity(workReportDTO.descriptionValues));
        }

        return workReport;
    }
View Full Code Here


        WorkReportType workReportType = givenBasicWorkReportType();
        workReportType.setDateIsSharedByLines(true);
        workReportType.setOrderElementIsSharedInLines(true);
        workReportType.setResourceIsSharedInLines(true);

        WorkReport workReport = givenBasicWorkReport();
        workReport.setWorkReportType(workReportType);

        WorkReportLine workReportLine1 = givenBasicWorkReportLine(workReport);
        workReport.addWorkReportLine(workReportLine1);

        workReport.setDate(new Date());
        workReport.setOrderElement(givenOrderLine());
        workReport.setResource(givenWorker());

        assertNotNull(workReportLine1.getDate());
        assertNotNull(workReportLine1.getOrderElement());
        assertNotNull(workReportLine1.getResource());

        WorkReportLine workReportLine2 = givenBasicWorkReportLine(workReport);
        workReport.addWorkReportLine(workReportLine2);

        assertNotNull(workReportLine2.getDate());
        assertNotNull(workReportLine2.getOrderElement());
        assertNotNull(workReportLine2.getResource());
View Full Code Here

    public void checkHoursCalculatedByClock() {
        WorkReportType workReportType = givenBasicWorkReportType();
        workReportType
                .setHoursManagement(HoursManagementEnum.HOURS_CALCULATED_BY_CLOCK);

        WorkReport workReport = WorkReport.create(workReportType);
        WorkReportLine workReportLine = givenBasicWorkReportLine(workReport);

        workReport.addWorkReportLine(workReportLine);

        workReportLine.setEffort(EffortDuration.hours(10));
        assertNull(workReportLine.getEffort());

        LocalTime start = new LocalTime(8, 0);
View Full Code Here

        WorkReportType workReportType = givenBasicWorkReportType();
        workReportType
                .setHoursManagement(HoursManagementEnum.HOURS_CALCULATED_BY_CLOCK);

        WorkReport workReport = WorkReport.create(workReportType);

        WorkReportLine workReportLine = givenBasicWorkReportLine(workReport);
        workReport.addWorkReportLine(workReportLine);

        workReportLine.setEffort(EffortDuration.hours(10));
        LocalTime start = new LocalTime(8, 0);
        LocalTime end = start.plusHours(8);
View Full Code Here

    }

    public WorkReportLine createValidWorkReportLine() {
        Resource resource = createValidWorker();

        WorkReport workReport = createValidWorkReport();
        workReportDAO.save(workReport);

        WorkReportLine workReportLine = WorkReportLine.create(workReport);
        workReport.addWorkReportLine(workReportLine);
        workReportLine.setDate(new Date());
        workReportLine.setEffort(EffortDuration.hours(100));
        workReportLine.setResource(resource);
        workReportLine.setOrderElement(createValidOrderElement());
        workReportLine.setTypeOfWorkHours(createValidTypeOfWorkHours());
View Full Code Here

    }

    public WorkReport createValidWorkReport() {
        WorkReportType workReportType = createValidWorkReportType();
        workReportTypeDAO.save(workReportType);
        WorkReport workReport = WorkReport.create(workReportType);
        return workReport;
    }
View Full Code Here

        return workReportLine;
    }

    private WorkReport givenBasicWorkReport() {
        WorkReport workReport = WorkReport.create();
        workReport.setCode("work-report-code-" + UUID.randomUUID());

        return workReport;
    }
View Full Code Here

        return workReport;
    }

    @Test
    public void checkImpossibleSetFieldsAtWorkReportLevel() {
        WorkReport workReport = WorkReport.create(givenBasicWorkReportType());

        assertNull(workReport.getDate());
        assertNull(workReport.getOrderElement());
        assertNull(workReport.getResource());

        workReport.setDate(new Date());
        workReport.setOrderElement(givenOrderLine());
        workReport.setResource(givenWorker());

        assertNull(workReport.getDate());
        assertNull(workReport.getOrderElement());
        assertNull(workReport.getResource());
    }
View Full Code Here

    }

    @Test
    @Transactional
    public void testSaveWorkReport() {
        WorkReport workReport = createValidWorkReport();
        workReportDAO.save(workReport);
        assertTrue(workReportDAO.exists(workReport.getId()));
    }
View Full Code Here

    }

    @Test
    @Transactional
    public void testRemoveWorkReport() throws InstanceNotFoundException {
        WorkReport workReport = createValidWorkReport();
        workReportDAO.save(workReport);
        workReportDAO.remove(workReport.getId());
        assertFalse(workReportDAO.exists(workReport.getId()));
    }
View Full Code Here

TOP

Related Classes of org.libreplan.business.workreports.entities.WorkReport

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.