use of com.qcadoo.model.api.validators.ErrorMessage 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;
}
use of com.qcadoo.model.api.validators.ErrorMessage 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;
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class LogService method add.
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Entity add(Builder builder) {
validate(builder);
DataDefinition logDD = getLogDD();
Entity logEntity = logDD.create();
logEntity.setField(LogFields.ACTION, builder.action);
if (builder.createTime == null) {
logEntity.setField(LogFields.CREATE_TIME, new Date());
} else {
logEntity.setField(LogFields.CREATE_TIME, builder.createTime);
}
logEntity.setField(LogFields.DETAILS, builder.details);
logEntity.setField(LogFields.ITEM_1, builder.item1);
logEntity.setField(LogFields.ITEM_2, builder.item2);
logEntity.setField(LogFields.ITEM_3, builder.item3);
logEntity.setField(LogFields.LOG_LEVEL, builder.logLevel.getCode());
logEntity.setField(LogFields.MESSAGE, builder.message);
logEntity.setField(LogFields.LOG_TYPE, builder.type);
Long userId = securityService.getCurrentUserOrQcadooBotId();
logEntity.setField(LogFields.USER, userId);
Entity saved = logDD.save(logEntity);
if (!saved.isValid()) {
StringBuilder logErrors = new StringBuilder();
for (Map.Entry<String, ErrorMessage> errorEntry : saved.getErrors().entrySet()) {
logErrors.append(errorEntry.getKey() + " : " + errorEntry.getValue().getMessage());
}
LOGGER.warn(saved.toString());
LOGGER.warn(logErrors.toString());
}
return saved;
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class DeliveryStateServiceMF method createDocuments.
@Transactional(propagation = Propagation.REQUIRES_NEW)
private void createDocuments(final StateChangeContext stateChangeContext, final Entity delivery) {
Entity location = getLocation(delivery);
if (Objects.isNull(location)) {
return;
}
Entity currency = getCurrency(delivery);
List<Entity> deliveredProducts = delivery.getHasManyField(DeliveryFields.DELIVERED_PRODUCTS);
DocumentBuilder documentBuilder = documentManagementService.getDocumentBuilder();
documentBuilder.receipt(location);
documentBuilder.setField(DocumentFieldsDTMF.DELIVERY, delivery);
documentBuilder.setField(DocumentFields.COMPANY, delivery.getField(DeliveryFields.SUPPLIER));
for (Entity deliveredProduct : deliveredProducts) {
BigDecimal quantity = deliveredProduct.getDecimalField(DeliveredProductFields.DELIVERED_QUANTITY);
Optional<BigDecimal> damagedQuantity = Optional.ofNullable(deliveredProduct.getDecimalField(DeliveredProductFields.DAMAGED_QUANTITY));
BigDecimal positionQuantity = quantity.subtract(damagedQuantity.orElse(BigDecimal.ZERO), numberService.getMathContext());
if (positionQuantity.compareTo(BigDecimal.ZERO) > 0) {
Entity product = getProduct(deliveredProduct);
String additionalUnit = product.getStringField(ProductFields.ADDITIONAL_UNIT);
BigDecimal givenQuantity = deliveredProduct.getDecimalField(DeliveredProductFields.ADDITIONAL_QUANTITY);
BigDecimal conversion = deliveredProduct.getDecimalField(DeliveredProductFields.CONVERSION);
if (StringUtils.isEmpty(additionalUnit)) {
additionalUnit = product.getStringField(ProductFields.UNIT);
}
List<Entity> attributes = prepareAttributes(deliveredProduct);
documentBuilder.addPosition(product, positionQuantity, numberService.setScaleWithDefaultMathContext(givenQuantity), additionalUnit, conversion, currencyService.getConvertedValue(deliveredProduct.getDecimalField(DeliveredProductFields.PRICE_PER_UNIT), currency), getBatch(deliveredProduct), getProductionDate(deliveredProduct), getExpirationDate(deliveredProduct), null, getStorageLocation(deliveredProduct), getPalletNumber(deliveredProduct), getTypeOfPallet(deliveredProduct), getAdditionalCode(deliveredProduct), isWaste(deliveredProduct), deliveredProduct.getStringField(L_QUALITY_RATING), attributes);
}
}
Entity createdDocument = documentBuilder.setAccepted().build();
if (!createdDocument.isValid()) {
delivery.addGlobalError("deliveriesToMaterialFlow.deliveryStateValidator.error.document", true);
for (ErrorMessage error : createdDocument.getGlobalErrors()) {
delivery.addGlobalError(error.getMessage(), error.getAutoClose());
}
} else {
tryCreateIssuesForDeliveriesReservations(stateChangeContext);
}
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class DeliveryByPalletTypeReportListeners method validate.
private boolean validate(final ViewDefinitionState view, final Entity entity) {
if (Objects.isNull(entity.getDateField(L_FROM_DATE))) {
FieldComponent dateFromField = (FieldComponent) view.getComponentByReference(L_FROM_DATE);
dateFromField.addMessage(new ErrorMessage("qcadooView.validate.field.error.missing", false));
return false;
} else if (Objects.isNull(entity.getDateField(L_TO_DATE))) {
FieldComponent dateFromField = (FieldComponent) view.getComponentByReference(L_TO_DATE);
dateFromField.addMessage(new ErrorMessage("qcadooView.validate.field.error.missing", false));
return false;
}
if (entity.getDateField(L_FROM_DATE).after(entity.getDateField(L_TO_DATE))) {
FieldComponent dateFromField = (FieldComponent) view.getComponentByReference(L_FROM_DATE);
dateFromField.addMessage(new ErrorMessage("deliveries.deliveryByPalletTypeReport.fromAfterTo", false));
return false;
}
return true;
}
Aggregations