Search in sources :

Example 1 with OperationResponse

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) OperationResponse(com.qcadoo.mes.technologies.controller.dataProvider.OperationResponse) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

OperationResponse (com.qcadoo.mes.technologies.controller.dataProvider.OperationResponse)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