use of com.qcadoo.mes.technologies.controller.dataProvider.OperationResponse in project mes by qcadoo.
the class TechnologyApiController method saveOperation.
@ResponseBody
@RequestMapping(value = "/operation", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public OperationResponse saveOperation(@RequestBody OperationRequest operation) {
Entity operationEntity = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION).create();
operationEntity.setField(OperationFields.NUMBER, operation.getNumber());
operationEntity.setField(OperationFields.NAME, operation.getName());
operationEntity.setField(OperationFields.QUANTITY_OF_WORKSTATIONS, 1);
operationEntity.setField(OperationFields.ASSIGNED_TO_OPERATION, "01workstations");
operationEntity.setField(OperationFields.CREATE_OPERATION_OUTPUT, true);
operationEntity.setField("tpz", 0);
operationEntity.setField("tj", 0);
operationEntity.setField("timeNextOperation", 0);
operationEntity.setField("productionInOneCycle", BigDecimal.ONE);
operationEntity.setField("machineUtilization", BigDecimal.ONE);
operationEntity.setField("laborUtilization", BigDecimal.valueOf(1L));
operationEntity.setField("nextOperationAfterProducedType", "01all");
operationEntity.setField("nextOperationAfterProducedQuantity", BigDecimal.ZERO);
operationEntity.setField("minStaff", 1);
operationEntity.setField("tjDecreasesForEnlargedStaff", false);
operationEntity.setField("optimalStaff", 1);
operationEntity = operationEntity.getDataDefinition().save(operationEntity);
if (operationEntity.isValid()) {
OperationResponse operationResponse = new OperationResponse(OperationResponse.StatusCode.OK);
operationResponse.setId(operationEntity.getId());
operationResponse.setNumber(operation.getNumber());
return operationResponse;
} else {
//
ErrorMessage numberError = operationEntity.getError(ProductionLineFields.NUMBER);
if (Objects.nonNull(numberError) && numberError.getMessage().equals("qcadooView.validate.field.error.duplicated")) {
OperationResponse response = new OperationResponse(OperationResponse.StatusCode.ERROR);
response.setMessage(translationService.translate("basic.dashboard.orderDefinitionWizard.error.validationError.operationDuplicated", LocaleContextHolder.getLocale()));
return response;
}
}
OperationResponse response = new OperationResponse(OperationResponse.StatusCode.ERROR);
response.setMessage(translationService.translate("basic.dashboard.orderDefinitionWizard.error.validationError.operationErrors", LocaleContextHolder.getLocale()));
return response;
}
Aggregations