Search in sources :

Example 1 with DocumentBuildException

use of com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException in project mes by qcadoo.

the class WarehouseIssueDocumentsService method build.

private CreationDocumentResponse build(final DocumentsStatus documentsStatus, final DocumentBuilder documentBuilder) {
    Entity document;
    try {
        if (DocumentsStatus.ACCEPTED.getStrValue().equals(documentsStatus.getStrValue())) {
            document = documentBuilder.setAccepted().buildWithEntityRuntimeException();
        } else {
            document = documentBuilder.buildWithEntityRuntimeException();
        }
        if (!document.isValid()) {
            List<ErrorMessage> errors = Lists.newArrayList();
            errors.addAll(document.getGlobalErrors());
            return new CreationDocumentResponse(false, errors);
        }
        CreationDocumentResponse creationDocumentResponse = new CreationDocumentResponse(true);
        creationDocumentResponse.setDocument(document);
        return creationDocumentResponse;
    } catch (DocumentBuildException e) {
        return new CreationDocumentResponse(false, e.getGlobalErrors());
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) CreationDocumentResponse(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.CreationDocumentResponse) DocumentBuildException(com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException)

Example 2 with DocumentBuildException

use of com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException in project mes by qcadoo.

the class DetailedProductionCountingAndProgressListenersBPC method resourceIssue.

public void resourceIssue(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent formComponent = (FormComponent) view.getComponentByReference(L_ORDER);
    Entity order = formComponent.getEntity().getDataDefinition().get(formComponent.getEntity().getId());
    GridComponent grid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
    Set<Long> ids = grid.getSelectedEntitiesIds();
    List<Entity> pcqs = dataDefinitionService.get(BasicProductionCountingConstants.PLUGIN_IDENTIFIER, BasicProductionCountingConstants.MODEL_PRODUCTION_COUNTING_QUANTITY).find().add(SearchRestrictions.in("id", ids)).list().getEntities();
    if (!canIssueMaterials(order, pcqs)) {
        formComponent.setEntity(order);
        return;
    }
    try {
        productionCountingDocumentService.createInternalOutboundDocument(order, pcqs, false);
        if (order.isValid()) {
            productionCountingDocumentService.updateProductionCountingQuantity(pcqs);
            productionTrackingListenerServicePFTD.updateCostsForOrder(order);
            view.addMessage("productFlowThruDivision.productionCountingQuantity.success.createInternalOutboundDocument", ComponentState.MessageType.SUCCESS);
        }
    } catch (DocumentBuildException documentBuildException) {
        boolean errorsDisplayed = true;
        for (ErrorMessage error : documentBuildException.getEntity().getGlobalErrors()) {
            if (error.getMessage().equalsIgnoreCase(L_ERROR_NOT_ENOUGH_RESOURCES)) {
                order.addGlobalError(error.getMessage(), false, error.getVars());
            } else {
                errorsDisplayed = false;
                order.addGlobalError(error.getMessage(), error.getVars());
            }
        }
        if (!errorsDisplayed) {
            order.addGlobalError("productFlowThruDivision.productionCountingQuantity.productionCountingQuantityError.createInternalOutboundDocument");
        }
        formComponent.setEntity(order);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) GridComponent(com.qcadoo.view.api.components.GridComponent) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) DocumentBuildException(com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException)

Example 3 with DocumentBuildException

use of com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException in project mes by qcadoo.

the class ProductionTrackingDocumentsHelper method groupAndFilterInProducts.

public Multimap<Long, Entity> groupAndFilterInProducts(final Entity order, final List<Entity> trackingOperationProductInComponents) {
    Multimap<Long, Entity> groupedRecordInProducts = ArrayListMultimap.create();
    SearchCriteriaBuilder scb = getProductionCountingQuantityDD().find().add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.ORDER, order)).add(SearchRestrictions.eq(ProductionCountingQuantityFields.ROLE, ProductionCountingQuantityRole.USED.getStringValue()));
    List<Entity> productionCountingQuantities = scb.list().getEntities();
    for (Entity topic : trackingOperationProductInComponents) {
        BigDecimal usedQuantity = topic.getDecimalField(L_USED_QUANTITY);
        if (Objects.nonNull(usedQuantity) && BigDecimal.ZERO.compareTo(usedQuantity) < 0) {
            Entity product = topic.getBelongsToField(TrackingOperationProductInComponentFields.PRODUCT);
            Entity productionTracking = topic.getBelongsToField(TrackingOperationProductInComponentFields.PRODUCTION_TRACKING);
            Entity toc = productionTracking.getBelongsToField(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT);
            Either<Boolean, Entity> eitherWarehouse = getWarehouseForProduct(productionCountingQuantities, toc, product);
            if (eitherWarehouse.isRight()) {
                Entity warehouse = eitherWarehouse.getRight();
                if (Objects.isNull(warehouse)) {
                    DocumentBuilder documentBuilder = documentManagementService.getDocumentBuilder();
                    Entity emptyDocumentForErrorHandling = documentBuilder.createDocument(userService.getCurrentUserEntity());
                    emptyDocumentForErrorHandling.setNotValid();
                    emptyDocumentForErrorHandling.addGlobalError("productFlowThruDivision.productionCountingQuantity.productionCountingQuantityError.warehouseNotSet", product.getStringField(ProductFields.NUMBER));
                    throw new DocumentBuildException(emptyDocumentForErrorHandling, Lists.newArrayList());
                }
                groupedRecordInProducts.put(warehouse.getId(), topic);
            }
        }
    }
    return groupedRecordInProducts;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) DocumentBuilder(com.qcadoo.mes.materialFlowResources.service.DocumentBuilder) BigDecimal(java.math.BigDecimal) DocumentBuildException(com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException)

Example 4 with DocumentBuildException

use of com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException in project mes by qcadoo.

the class ProductionCountingDocumentService method checkForEmptyPositions.

private void checkForEmptyPositions(boolean useUsedQuantity, List<ProductionCountingQuantityHolder> entries) {
    for (ProductionCountingQuantityHolder entry : entries) {
        BigDecimal quantity = null;
        if (useUsedQuantity) {
            quantity = entry.getUsedQuantity();
        } else {
            quantity = entry.getPlannedQuantity().subtract(BigDecimalUtils.convertNullToZero(entry.getUsedQuantity()));
        }
        if (BigDecimal.ZERO.compareTo(quantity) >= 0) {
            DocumentBuilder documentBuilder = documentManagementService.getDocumentBuilder();
            Entity emptyDocumentForErrorHandling = documentBuilder.createDocument(userService.getCurrentUserEntity());
            emptyDocumentForErrorHandling.setNotValid();
            emptyDocumentForErrorHandling.addGlobalError("productFlowThruDivision.productionCountingQuantity.productionCountingQuantityError.emptyPosition", entry.getProduct().getStringField(ProductFields.NUMBER));
            throw new DocumentBuildException(emptyDocumentForErrorHandling, Lists.newArrayList());
        }
    }
}
Also used : DocumentBuilder(com.qcadoo.mes.materialFlowResources.service.DocumentBuilder) BigDecimal(java.math.BigDecimal) DocumentBuildException(com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException)

Aggregations

DocumentBuildException (com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException)4 Entity (com.qcadoo.model.api.Entity)3 DocumentBuilder (com.qcadoo.mes.materialFlowResources.service.DocumentBuilder)2 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)2 BigDecimal (java.math.BigDecimal)2 CreationDocumentResponse (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.CreationDocumentResponse)1 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)1 FormComponent (com.qcadoo.view.api.components.FormComponent)1 GridComponent (com.qcadoo.view.api.components.GridComponent)1