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;
}
Aggregations