Search in sources :

Example 26 with ErrorMessage

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

the class BasicApiController method saveWorkstation.

@ResponseBody
@RequestMapping(value = "/workstation", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public WorkstationResponse saveWorkstation(@RequestBody WorkstationRequest workstation) {
    Entity workstationEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_WORKSTATION).create();
    workstationEntity.setField(WorkstationFields.NUMBER, workstation.getNumber());
    workstationEntity.setField(WorkstationFields.NAME, workstation.getName());
    workstationEntity.setField(WorkstationFields.WORKSTATION_TYPE, workstation.getType());
    workstationEntity = workstationEntity.getDataDefinition().save(workstationEntity);
    if (workstationEntity.isValid()) {
        WorkstationResponse workstationResponse = new WorkstationResponse(WorkstationResponse.StatusCode.OK);
        workstationResponse.setId(workstationEntity.getId());
        workstationResponse.setNumber(workstation.getNumber());
        workstationResponse.setName(workstation.getName());
        return workstationResponse;
    } else {
        // 
        ErrorMessage numberError = workstationEntity.getError(WorkstationFields.NUMBER);
        if (Objects.nonNull(numberError) && numberError.getMessage().equals("qcadooView.validate.field.error.duplicated")) {
            WorkstationResponse response = new WorkstationResponse(WorkstationResponse.StatusCode.ERROR);
            response.setMessage(translationService.translate("basic.dashboard.operationalTasksDefinitionWizard.error.validationError.workstationDuplicated", LocaleContextHolder.getLocale()));
            return response;
        }
    }
    WorkstationResponse response = new WorkstationResponse(WorkstationResponse.StatusCode.ERROR);
    response.setMessage(translationService.translate("basic.dashboard.operationalTasksDefinitionWizard.error.validationError.workstationErrors", LocaleContextHolder.getLocale()));
    return response;
}
Also used : Entity(com.qcadoo.model.api.Entity) WorkstationResponse(com.qcadoo.mes.basic.controllers.dataProvider.responses.WorkstationResponse) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with ErrorMessage

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

the class BasicApiController method saveWorkstationType.

@ResponseBody
@RequestMapping(value = "/workstationType", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public WorkstationResponse saveWorkstationType(@RequestBody WorkstationRequest workstation) {
    Entity workstationEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_WORKSTATION_TYPE).create();
    workstationEntity.setField(WorkstationTypeFields.NUMBER, workstation.getNumber());
    workstationEntity.setField(WorkstationTypeFields.NAME, workstation.getName());
    workstationEntity = workstationEntity.getDataDefinition().save(workstationEntity);
    if (workstationEntity.isValid()) {
        WorkstationResponse workstationResponse = new WorkstationResponse(WorkstationResponse.StatusCode.OK);
        workstationResponse.setId(workstationEntity.getId());
        workstationResponse.setNumber(workstation.getNumber());
        workstationResponse.setName(workstation.getName());
        return workstationResponse;
    } else {
        // 
        ErrorMessage numberError = workstationEntity.getError(WorkstationFields.NUMBER);
        if (Objects.nonNull(numberError) && numberError.getMessage().equals("qcadooView.validate.field.error.duplicated")) {
            WorkstationResponse response = new WorkstationResponse(WorkstationResponse.StatusCode.ERROR);
            response.setMessage(translationService.translate("basic.dashboard.operationalTasksDefinitionWizard.error.validationError.workstationTypeDuplicated", LocaleContextHolder.getLocale()));
            return response;
        }
    }
    WorkstationResponse response = new WorkstationResponse(WorkstationResponse.StatusCode.ERROR);
    response.setMessage(translationService.translate("basic.dashboard.operationalTasksDefinitionWizard.error.validationError.workstationErrors", LocaleContextHolder.getLocale()));
    return response;
}
Also used : Entity(com.qcadoo.model.api.Entity) WorkstationResponse(com.qcadoo.mes.basic.controllers.dataProvider.responses.WorkstationResponse) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with ErrorMessage

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

the class LogService method add.

@Transactional(propagation = Propagation.REQUIRES_NEW)
public Entity add(Builder builder) {
    validate(builder);
    DataDefinition logDD = getLogDD();
    Entity logEntity = logDD.create();
    logEntity.setField(LogFields.ACTION, builder.action);
    if (builder.createTime == null) {
        logEntity.setField(LogFields.CREATE_TIME, new Date());
    } else {
        logEntity.setField(LogFields.CREATE_TIME, builder.createTime);
    }
    logEntity.setField(LogFields.DETAILS, builder.details);
    logEntity.setField(LogFields.ITEM_1, builder.item1);
    logEntity.setField(LogFields.ITEM_2, builder.item2);
    logEntity.setField(LogFields.ITEM_3, builder.item3);
    logEntity.setField(LogFields.LOG_LEVEL, builder.logLevel.getCode());
    logEntity.setField(LogFields.MESSAGE, builder.message);
    logEntity.setField(LogFields.LOG_TYPE, builder.type);
    Long userId = securityService.getCurrentUserOrQcadooBotId();
    logEntity.setField(LogFields.USER, userId);
    Entity saved = logDD.save(logEntity);
    if (!saved.isValid()) {
        StringBuilder logErrors = new StringBuilder();
        for (Map.Entry<String, ErrorMessage> errorEntry : saved.getErrors().entrySet()) {
            logErrors.append(errorEntry.getKey() + " : " + errorEntry.getValue().getMessage());
        }
        LOGGER.warn(saved.toString());
        LOGGER.warn(logErrors.toString());
    }
    return saved;
}
Also used : Entity(com.qcadoo.model.api.Entity) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) DataDefinition(com.qcadoo.model.api.DataDefinition) Map(java.util.Map) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with ErrorMessage

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

the class DeliveryStateServiceMF method createDocuments.

@Transactional(propagation = Propagation.REQUIRES_NEW)
private void createDocuments(final StateChangeContext stateChangeContext, final Entity delivery) {
    Entity location = getLocation(delivery);
    if (Objects.isNull(location)) {
        return;
    }
    Entity currency = getCurrency(delivery);
    List<Entity> deliveredProducts = delivery.getHasManyField(DeliveryFields.DELIVERED_PRODUCTS);
    DocumentBuilder documentBuilder = documentManagementService.getDocumentBuilder();
    documentBuilder.receipt(location);
    documentBuilder.setField(DocumentFieldsDTMF.DELIVERY, delivery);
    documentBuilder.setField(DocumentFields.COMPANY, delivery.getField(DeliveryFields.SUPPLIER));
    for (Entity deliveredProduct : deliveredProducts) {
        BigDecimal quantity = deliveredProduct.getDecimalField(DeliveredProductFields.DELIVERED_QUANTITY);
        Optional<BigDecimal> damagedQuantity = Optional.ofNullable(deliveredProduct.getDecimalField(DeliveredProductFields.DAMAGED_QUANTITY));
        BigDecimal positionQuantity = quantity.subtract(damagedQuantity.orElse(BigDecimal.ZERO), numberService.getMathContext());
        if (positionQuantity.compareTo(BigDecimal.ZERO) > 0) {
            Entity product = getProduct(deliveredProduct);
            String additionalUnit = product.getStringField(ProductFields.ADDITIONAL_UNIT);
            BigDecimal givenQuantity = deliveredProduct.getDecimalField(DeliveredProductFields.ADDITIONAL_QUANTITY);
            BigDecimal conversion = deliveredProduct.getDecimalField(DeliveredProductFields.CONVERSION);
            if (StringUtils.isEmpty(additionalUnit)) {
                additionalUnit = product.getStringField(ProductFields.UNIT);
            }
            List<Entity> attributes = prepareAttributes(deliveredProduct);
            documentBuilder.addPosition(product, positionQuantity, numberService.setScaleWithDefaultMathContext(givenQuantity), additionalUnit, conversion, currencyService.getConvertedValue(deliveredProduct.getDecimalField(DeliveredProductFields.PRICE_PER_UNIT), currency), getBatch(deliveredProduct), getProductionDate(deliveredProduct), getExpirationDate(deliveredProduct), null, getStorageLocation(deliveredProduct), getPalletNumber(deliveredProduct), getTypeOfPallet(deliveredProduct), getAdditionalCode(deliveredProduct), isWaste(deliveredProduct), deliveredProduct.getStringField(L_QUALITY_RATING), attributes);
        }
    }
    Entity createdDocument = documentBuilder.setAccepted().build();
    if (!createdDocument.isValid()) {
        delivery.addGlobalError("deliveriesToMaterialFlow.deliveryStateValidator.error.document", true);
        for (ErrorMessage error : createdDocument.getGlobalErrors()) {
            delivery.addGlobalError(error.getMessage(), error.getAutoClose());
        }
    } else {
        tryCreateIssuesForDeliveriesReservations(stateChangeContext);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) DocumentBuilder(com.qcadoo.mes.materialFlowResources.service.DocumentBuilder) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) BigDecimal(java.math.BigDecimal) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with ErrorMessage

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

the class DeliveryByPalletTypeReportListeners method validate.

private boolean validate(final ViewDefinitionState view, final Entity entity) {
    if (Objects.isNull(entity.getDateField(L_FROM_DATE))) {
        FieldComponent dateFromField = (FieldComponent) view.getComponentByReference(L_FROM_DATE);
        dateFromField.addMessage(new ErrorMessage("qcadooView.validate.field.error.missing", false));
        return false;
    } else if (Objects.isNull(entity.getDateField(L_TO_DATE))) {
        FieldComponent dateFromField = (FieldComponent) view.getComponentByReference(L_TO_DATE);
        dateFromField.addMessage(new ErrorMessage("qcadooView.validate.field.error.missing", false));
        return false;
    }
    if (entity.getDateField(L_FROM_DATE).after(entity.getDateField(L_TO_DATE))) {
        FieldComponent dateFromField = (FieldComponent) view.getComponentByReference(L_FROM_DATE);
        dateFromField.addMessage(new ErrorMessage("deliveries.deliveryByPalletTypeReport.fromAfterTo", false));
        return false;
    }
    return true;
}
Also used : FieldComponent(com.qcadoo.view.api.components.FieldComponent) 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