Search in sources :

Example 6 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage 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 7 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.

the class OrderStatesListenerServicePFTD method createTransferDocumentsForUnusedMaterials.

private Either<String, Void> createTransferDocumentsForUnusedMaterials(final Entity locationFrom, final Entity locationTo, final Map<Entity, BigDecimal> products, final Entity order) {
    DocumentBuilder document = documentManagementService.getDocumentBuilder().transfer(locationFrom, locationTo);
    if (products.isEmpty()) {
        return Either.right(null);
    }
    for (Map.Entry<Entity, BigDecimal> entry : products.entrySet()) {
        Entity product = entry.getKey();
        BigDecimal quantity = entry.getValue();
        if (quantity.compareTo(BigDecimal.ZERO) > 0) {
            BigDecimal givenQuantity = quantity;
            String givenUnit = product.getStringField(ProductFields.ADDITIONAL_UNIT);
            BigDecimal conversion = BigDecimal.ONE;
            if (!StringUtils.isEmpty(givenUnit)) {
                PossibleUnitConversions unitConversions = unitConversionService.getPossibleConversions(product.getStringField(ProductFields.UNIT), searchCriteriaBuilder -> searchCriteriaBuilder.add(SearchRestrictions.belongsTo(UnitConversionItemFieldsB.PRODUCT, product)));
                if (unitConversions.isDefinedFor(givenUnit)) {
                    givenQuantity = unitConversions.convertTo(quantity, givenUnit);
                    conversion = unitConversions.asUnitToConversionMap().get(givenUnit);
                }
            } else {
                givenUnit = product.getStringField(ProductFields.UNIT);
            }
            Entity position = document.createPosition(product, quantity, givenQuantity, givenUnit, conversion, null, null, null, null, null);
            document.addPosition(position);
        }
    }
    Entity acceptedDocument = acceptTransferDocument(document, order);
    if (!acceptedDocument.isValid()) {
        for (ErrorMessage error : acceptedDocument.getGlobalErrors()) {
            order.addGlobalError(error.getMessage(), error.getVars());
        }
        order.addGlobalError(L_ACCEPT_INBOUND_DOCUMENT_ERROR);
        return Either.left(L_ACCEPT_INBOUND_DOCUMENT_ERROR);
    }
    return Either.right(null);
}
Also used : Entity(com.qcadoo.model.api.Entity) DocumentBuilder(com.qcadoo.mes.materialFlowResources.service.DocumentBuilder) PossibleUnitConversions(com.qcadoo.model.api.units.PossibleUnitConversions) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) MultiHashMap(org.apache.commons.collections.MultiHashMap) MultiMap(org.apache.commons.collections.MultiMap) BigDecimal(java.math.BigDecimal)

Example 8 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage 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 9 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.

the class AnomalyProductionTrackingDetailsListeners method perform.

@Transactional(propagation = Propagation.REQUIRES_NEW)
private boolean perform(ViewDefinitionState view) {
    boolean valid = validate(view);
    if (valid) {
        createAnomalies(view);
        clearQuantitiesInRR(view);
        view.addMessage("productionCounting.anomalyProductionTrackingDetails.reasonsCreated", ComponentState.MessageType.SUCCESS);
        CheckBoxComponent generated = (CheckBoxComponent) view.getComponentByReference("generated");
        generated.setChecked(true);
        return true;
    } else {
        view.addMessage(new ErrorMessage("productionCounting.anomalyReasonDetails.reasonIsRequired", false));
        return false;
    }
}
Also used : ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.

the class ProductionTrackingListenerService method closeOrder.

private void closeOrder(final Entity productionTracking) {
    final Entity order = productionTracking.getBelongsToField(ORDER);
    Entity orderFromDB = order.getDataDefinition().get(order.getId());
    if (!orderClosingHelper.orderShouldBeClosed(productionTracking)) {
        return;
    }
    if (order.getStringField(STATE).equals(COMPLETED.getStringValue())) {
        productionTracking.addGlobalMessage("productionCounting.order.orderIsAlreadyClosed", false, false);
        return;
    }
    final StateChangeContext orderStateChangeContext = stateChangeContextBuilder.build(orderStateChangeAspect.getChangeEntityDescriber(), orderFromDB, OrderState.COMPLETED.getStringValue());
    orderStateChangeAspect.changeState(orderStateChangeContext);
    orderFromDB = order.getDataDefinition().get(orderStateChangeContext.getOwner().getId());
    if (orderFromDB.getStringField(STATE).equals(COMPLETED.getStringValue())) {
        productionTracking.addGlobalMessage("productionCounting.order.orderClosed", false, false);
    } else if (StateChangeStatus.PAUSED.equals(orderStateChangeContext.getStatus())) {
        productionTracking.addGlobalMessage("productionCounting.order.orderWillBeClosedAfterExtSync", false, false);
    } else {
        productionTracking.addGlobalError("productionCounting.order.orderCannotBeClosed", false);
        List<ErrorMessage> errors = Lists.newArrayList();
        if (!orderFromDB.getErrors().isEmpty()) {
            errors.addAll(order.getErrors().values());
        }
        if (!orderFromDB.getGlobalErrors().isEmpty()) {
            errors.addAll(order.getGlobalErrors());
        }
        if (!orderStateChangeContext.getAllMessages().isEmpty()) {
            for (Entity entity : orderStateChangeContext.getAllMessages()) {
                errors.add(new ErrorMessage(getKey(entity), getArgs(entity)));
            }
        }
        if (!errors.isEmpty()) {
            StringBuilder errorMessages = new StringBuilder();
            for (ErrorMessage errorMessage : errors) {
                String translatedErrorMessage = translationService.translate(errorMessage.getMessage(), LocaleContextHolder.getLocale(), errorMessage.getVars());
                errorMessages.append(translatedErrorMessage);
                errorMessages.append(", ");
            }
            productionTracking.addGlobalError("orders.order.orderStates.error", errorMessages.toString());
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) List(java.util.List) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage)

Aggregations

ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)50 Entity (com.qcadoo.model.api.Entity)30 BigDecimal (java.math.BigDecimal)11 Test (org.junit.Test)11 Transactional (org.springframework.transaction.annotation.Transactional)8 Map (java.util.Map)7 DataDefinition (com.qcadoo.model.api.DataDefinition)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 FormComponent (com.qcadoo.view.api.components.FormComponent)5 TranslationService (com.qcadoo.localization.api.TranslationService)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 LocaleContextHolder (org.springframework.context.i18n.LocaleContextHolder)4 Lists (com.google.common.collect.Lists)3 OrderFields (com.qcadoo.mes.orders.constants.OrderFields)3 ProductFlowThruDivisionConstants (com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants)3 WarehouseIssueParameterService (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueParameterService)3 ProductsToIssueFields (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields)3 WarehouseIssueFields (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.WarehouseIssueFields)3 StateChangeContext (com.qcadoo.mes.states.StateChangeContext)3