Package org.libreplan.business.common.exceptions

Examples of org.libreplan.business.common.exceptions.ValidationException$InstantiatedInvalidValue


    public final static void updateWorkReport(WorkReport workReport,
            WorkReportDTO workReportDTO) throws ValidationException {

        if (StringUtils.isBlank(workReportDTO.code)) {
            throw new ValidationException("missing code in a work report.");
        }

        /*
         * 1: Update the existing work report line or add new
         * work report line.
         */
        for (WorkReportLineDTO lineDTO : workReportDTO.workReportLines) {

            /* Step 1.1: requires each work report line DTO to have a code. */
            if (StringUtils.isBlank(lineDTO.code)) {
                throw new ValidationException(
                        "missing code in a work report line");
            }

            try {
                WorkReportLine line = workReport
                        .getWorkReportLineByCode(lineDTO.code);
                updateWorkReportLine(line, lineDTO);
            } catch (InstanceNotFoundException e) {
                try {
                    workReport.addWorkReportLine(toEntity(lineDTO, workReport));
                } catch (InstanceNotFoundException o) {
                    throw new ValidationException(
                            "missing type of work hours in a work report line");
                }
            }
        }

        /*
         * 2: Update the existing labels
         */
        if (workReportDTO.labels != null) {
            for (LabelReferenceDTO labelDTO : workReportDTO.labels) {

                /* Step 2.1: requires each label reference DTO to have a code. */
                if (StringUtils.isBlank(labelDTO.code)) {
                    throw new ValidationException("missing code in a label");
                }

                try {
                    Set<Label> labels = workReport.getLabels();
                    updateLabel(labelDTO, labels);
                } catch (InstanceNotFoundException e) {
                    throw new ValidationException(
                            "work report has not this label type assigned");
                }
            }
        }

        /*
         * 3: Update the existing description values
         */
        if (workReportDTO.descriptionValues != null) {
            for (DescriptionValueDTO valueDTO : workReportDTO.descriptionValues) {

                /* Step 3.1: requires each description value DTO to have a code. */
                if (StringUtils.isBlank(valueDTO.fieldName)) {
                    throw new ValidationException(
                            "missing field name in a description value");
                }

                try {
                    DescriptionValue value = workReport
                            .getDescriptionValueByFieldName(valueDTO.fieldName);
                    value.setValue(StringUtils.trim(valueDTO.value));
                } catch (InstanceNotFoundException e) {
                    throw new ValidationException(
                            "work report has not any description value with this field name");
                }
            }
        }

        /*
         * 4: Update basic properties in existing work report
         */

        /* Step 4.1: Update the date. */
        Date date = DateConverter.toDate(workReportDTO.date);
        workReport.setDate(date);

        /* Step 4.2: Update the resource. */
        String resourceCode = workReportDTO.resource;
        if (!Strings.isBlank(resourceCode)) {
            try {
                Resource resource = Registry.getResourceDAO().findByCode(
                        resourceCode);
                workReport.setResource(resource);
            } catch (InstanceNotFoundException e) {
                throw new ValidationException(
                        "There is no resource with this code");
            }
        }

        /* Step 4.3: Update the order element. */
        String orderElementCode = workReportDTO.orderElement;
        if ((orderElementCode != null) && (!orderElementCode.isEmpty())) {
            try {
                OrderElement orderElement = Registry.getOrderElementDAO()
                    .findUniqueByCode(orderElementCode);
                workReport.setOrderElement(orderElement);
            } catch (InstanceNotFoundException e) {
                throw new ValidationException("There is no task with this code");
            }
        }
    }
View Full Code Here


                for (LabelReferenceDTO labelDTO : workReportLineDTO.labels) {

                // * Step 2.1: requires each label reference DTO to have a code.
                // */
                if (StringUtils.isBlank(labelDTO.code)) {
                    throw new ValidationException("missing code in a label");
                }

                try {
                    Set<Label> labels = workReportLine.getLabels();
                    updateLabel(labelDTO, labels);
                } catch (InstanceNotFoundException e) {
                    throw new ValidationException(
                            "there are not work report lines with assigned labels of this type");
                }
            }
        }
        /*
         * 2: Update the existing description values
         */
        updateDescriptionValues(workReportLineDTO.descriptionValues,
                workReportLine);

        /*
         * 3: Update basic properties in existing work report line
         */

        /* Step 3.1: Update the date. */
        Date date = DateConverter.toDate(workReportLineDTO.date);
        workReportLine.setDate(date);

        /* Step 3.2: Update the resource. */
        String resourceCode = workReportLineDTO.resource;
        if (!Strings.isBlank(resourceCode)) {
            try {
                Resource resource = Registry.getResourceDAO().findByCode(
                        resourceCode);
                workReportLine.setResource(resource);
            } catch (InstanceNotFoundException e) {
                throw new ValidationException(
                        "There is no resource with this code");
            }
        }

        /* Step 3.3: Update the order element. */
        String orderElementCode = workReportLineDTO.orderElement;
        try {
            OrderElement orderElement = Registry.getOrderElementDAO()
                    .findUniqueByCode(orderElementCode);
            workReportLine.setOrderElement(orderElement);
        } catch (InstanceNotFoundException e) {
            throw new ValidationException("There is no task with this code");
        }

        /* Step 3.4: Update the type of work hours. */
        if(workReportLineDTO.typeOfWorkHours != null){
            try{
                TypeOfWorkHours typeOfWorkHours = Registry.getTypeOfWorkHoursDAO().findUniqueByCode(workReportLineDTO.typeOfWorkHours);
                workReportLine.setTypeOfWorkHours(typeOfWorkHours);
            } catch (InstanceNotFoundException e) {
                throw new ValidationException(
                        "There is no type of work hours with this code");
            }
        }

        /*
 
View Full Code Here

        if (descriptionValues != null) {
            for (DescriptionValueDTO valueDTO : descriptionValues) {

                    /* Step 3.1: requires each description value DTO to have a code. */
                if (StringUtils.isBlank(valueDTO.fieldName)) {
                    throw new ValidationException(
                            "missing field name in a description value");
                }

                try {
                    DescriptionValue value = workReportLine
                        .getDescriptionValueByFieldName(valueDTO.fieldName);
                    value.setValue(StringUtils.trim(valueDTO.value));
                } catch (InstanceNotFoundException e) {
                    throw new ValidationException(
                            "work report have not any description value with this field name");
                }
            }
        }
    }
View Full Code Here

            // Check no code is repeated in this order
            if (order instanceof OrderLineGroup) {
                repeatedOrder = ((OrderLineGroup) order)
                        .findRepeatedOrderCode();
                if (repeatedOrder != null) {
                    throw new ValidationException(_(
                            "Repeated Project code {0} in Project {1}",
                            repeatedOrder.getCode(), repeatedOrder.getName()));
                }
            }

            // Check no code is repeated within the DB
            repeatedOrder = Registry.getOrderElementDAO()
                    .findRepeatedOrderCodeInDB(order);
            if (repeatedOrder != null) {
                throw new ValidationException(_(
                        "Repeated Project code {0} in Project {1}",
                        repeatedOrder.getCode(), repeatedOrder.getName()));
            }
        }
View Full Code Here

            if (order instanceof OrderLineGroup) {
                repeatedHoursGroup = ((OrderLineGroup) order)
                        .findRepeatedHoursGroupCode();
                if (repeatedHoursGroup != null) {
                    throw new ValidationException(_(
                            "Repeated Hours Group code {0} in Project {1}",
                            repeatedHoursGroup.getCode(), repeatedHoursGroup
                                    .getParentOrderLine().getName()));
                }
            }

            repeatedHoursGroup = Registry.getHoursGroupDAO()
                    .findRepeatedHoursGroupCodeInDB(order.getHoursGroups());
            if (repeatedHoursGroup != null) {
                throw new ValidationException(_(
                        "Repeated Hours Group code {0} in Project {1}",
                        repeatedHoursGroup.getCode(), repeatedHoursGroup
                                .getParentOrderLine().getName()));
            }
        }
View Full Code Here

            // limiting resource allocation
            Set<ResourceAllocation<?>> allocations = t
                    .getLimitingResourceAllocations();

            if (allocations.isEmpty() || allocations.size() != 1) {
                throw new ValidationException("Incorrect limiting resource "
                        + "allocation configuration");
            }

            for (ResourceAllocation<?> r : allocations) {
                result = r.getLimitingResourceQueueElement();
View Full Code Here

   private void thereIsOtherWithSameNameAndType(String name,List<CriterionDTO> criterions)
        throws ValidationException{
        for(CriterionDTO criterion : criterions){
            if(criterion.getName().equals(name)){
                throw new ValidationException(invalidValue(
                        _("Already exists another "
                                + "criterion with the same name"), "name",
                        criterion.getName(), criterion));
            }
            thereIsOtherWithSameNameAndType(name,criterion.getChildren());
View Full Code Here

    }

    public void validateNameNotEmpty(String name)
        throws ValidationException{
        if(name.isEmpty()){
            throw new ValidationException(
                    invalidValue(_("Name of criterion is empty."), "name",
                        "",criterionType));
            }
    }
View Full Code Here

            throws ValidationException {
        if (list.size() == 1)
            workReportEntity.setOrderElement(list.get(0));
        else {
            if (workReportEntity instanceof WorkReportLine)
                throw new ValidationException(
                    "List must have exactly one element");
        }
    }
View Full Code Here

        if (date == null) {
            if (version.equals(getBaseCalendar().getFirstCalendarData())) {
                return;
            } else {
                throw new ValidationException(_("This date cannot be empty"));
            }
        }

        LocalDate newStartDate = LocalDate.fromDateFields(date);
        CalendarData prevVersion = getBaseCalendar().getPrevious(version);
        if ((newStartDate != null) && (prevVersion != null)) {
            if (getBaseCalendar().getPrevious(prevVersion) == null) {
                return;
            }
            LocalDate prevStartDate = getBaseCalendar()
                    .getPrevious(prevVersion).getExpiringDate();
            if ((prevStartDate == null)
                    || ((newStartDate
                            .compareTo(prevStartDate) > 0))) {
                prevVersion.setExpiringDate(newStartDate);
                return;
            }
        }
        throw new ValidationException(
                _("This date can not include the whole previous work week"));
    }
View Full Code Here

TOP

Related Classes of org.libreplan.business.common.exceptions.ValidationException$InstantiatedInvalidValue

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.