Search in sources :

Example 1 with ProductionLineResponse

use of com.qcadoo.mes.productionLines.controller.dataProvider.ProductionLineResponse in project mes by qcadoo.

the class ProductionLinesApiController method saveProduct.

@ResponseBody
@RequestMapping(value = "/productionLine", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ProductionLineResponse saveProduct(@RequestBody ProductionLineRequest productionLine) {
    Entity productionLineEntity = dataDefinitionService.get(ProductionLinesConstants.PLUGIN_IDENTIFIER, ProductionLinesConstants.MODEL_PRODUCTION_LINE).create();
    productionLineEntity.setField(ProductionLineFields.NUMBER, productionLine.getNumber());
    productionLineEntity.setField(ProductionLineFields.NAME, productionLine.getName());
    productionLineEntity.setField(ProductionLineFields.PRODUCTION, Boolean.TRUE);
    productionLineEntity.setField(ProductionLineFields.QUANTITY_FOR_OTHER_WORKSTATION_TYPES, 1);
    productionLineEntity.setField(ProductionLineFields.SHIFTS, shiftsService.getShifts());
    productionLineEntity = productionLineEntity.getDataDefinition().save(productionLineEntity);
    if (productionLineEntity.isValid()) {
        ProductionLineResponse productionLineResponse = new ProductionLineResponse(ProductionLineResponse.StatusCode.OK);
        productionLineResponse.setId(productionLineEntity.getId());
        productionLineResponse.setNumber(productionLine.getNumber());
        productionLineResponse.setName(productionLine.getName());
        return productionLineResponse;
    } else {
        // 
        ErrorMessage numberError = productionLineEntity.getError(ProductionLineFields.NUMBER);
        if (Objects.nonNull(numberError) && numberError.getMessage().equals("qcadooView.validate.field.error.duplicated")) {
            ProductionLineResponse response = new ProductionLineResponse(ProductionLineResponse.StatusCode.ERROR);
            response.setMessage(translationService.translate("basic.dashboard.orderDefinitionWizard.error.validationError.productionLineDuplicated", LocaleContextHolder.getLocale()));
            return response;
        }
    }
    ProductionLineResponse response = new ProductionLineResponse(ProductionLineResponse.StatusCode.ERROR);
    response.setMessage(translationService.translate("basic.dashboard.orderDefinitionWizard.error.validationError.productionLineErrors", LocaleContextHolder.getLocale()));
    return response;
}
Also used : Entity(com.qcadoo.model.api.Entity) ProductionLineResponse(com.qcadoo.mes.productionLines.controller.dataProvider.ProductionLineResponse) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ProductionLineResponse (com.qcadoo.mes.productionLines.controller.dataProvider.ProductionLineResponse)1 Entity (com.qcadoo.model.api.Entity)1 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1