Search in sources :

Example 1 with WorkstationResponse

use of com.qcadoo.mes.basic.controllers.dataProvider.responses.WorkstationResponse 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 2 with WorkstationResponse

use of com.qcadoo.mes.basic.controllers.dataProvider.responses.WorkstationResponse 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)

Aggregations

WorkstationResponse (com.qcadoo.mes.basic.controllers.dataProvider.responses.WorkstationResponse)2 Entity (com.qcadoo.model.api.Entity)2 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2