use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class OrderReportService method printForOrder.
public Entity printForOrder(final ComponentState state, final String plugin, final String entityName, final Map<String, Object> entityFieldsMap, final OrderValidator orderValidator) {
if (!(state instanceof GridComponent)) {
throw new IllegalStateException("method avalible only for grid");
}
GridComponent gridState = (GridComponent) state;
Set<Entity> ordersEntities = new HashSet<Entity>();
if (gridState.getSelectedEntitiesIds().isEmpty()) {
state.addMessage("qcadooView.message.noRecordSelected", MessageType.FAILURE);
return null;
}
List<ErrorMessage> errors = Lists.newLinkedList();
for (Long orderId : gridState.getSelectedEntitiesIds()) {
Entity order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get(orderId);
if (order == null) {
errors.add(new ErrorMessage("qcadooView.message.entityNotFound"));
continue;
}
ErrorMessage errorMessage = orderValidator.validateOrder(order);
if (errorMessage == null) {
ordersEntities.add(order);
} else {
errors.add(errorMessage);
}
}
if (errors.isEmpty()) {
return createNewOrderPrint(ordersEntities, plugin, entityName, entityFieldsMap, state.getLocale());
} else {
StringBuilder errorMessages = new StringBuilder();
for (ErrorMessage error : errors) {
errorMessages.append(" - ");
String translatedError = translationService.translate(error.getMessage(), state.getLocale(), error.getVars());
errorMessages.append(translatedError);
errorMessages.append("\n");
}
state.addTranslatedMessage(errorMessages.toString(), MessageType.FAILURE, false);
}
return null;
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class BasicException method createMessageForValidationErrors.
private static String createMessageForValidationErrors(final String message, final Entity entity) {
StringBuilder sb = new StringBuilder();
sb.append(message).append("\n");
for (ErrorMessage error : entity.getGlobalErrors()) {
sb.append("- ").append(error.getMessage()).append("\n");
}
for (Map.Entry<String, ErrorMessage> error : entity.getErrors().entrySet()) {
sb.append("- ").append(error.getKey()).append(" - ").append(error.getValue().getMessage()).append("\n");
}
return sb.toString();
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class BasicApiController method saveProduct.
@ResponseBody
@RequestMapping(value = "/product", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ProductResponse saveProduct(@RequestBody ProductRequest product) {
Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).create();
productEntity.setField(ProductFields.NUMBER, product.getNumber());
productEntity.setField(ProductFields.NAME, product.getName());
productEntity.setField(ProductFields.UNIT, product.getUnit());
productEntity.setField(ProductFields.ENTITY_TYPE, ProductFamilyElementType.PARTICULAR_PRODUCT.getStringValue());
productEntity.setField(ProductFields.GLOBAL_TYPE_OF_MATERIAL, product.getGlobalTypeOfMaterial());
productEntity = productEntity.getDataDefinition().save(productEntity);
if (productEntity.isValid()) {
ProductResponse productResponse = new ProductResponse(ProductResponse.StatusCode.OK);
productResponse.setId(productEntity.getId());
productResponse.setNumber(product.getNumber());
productResponse.setName(product.getName());
productResponse.setUnit(product.getUnit());
return productResponse;
} else {
//
ErrorMessage numberError = productEntity.getError(ProductFields.NUMBER);
if (Objects.nonNull(numberError) && numberError.getMessage().equals("qcadooView.validate.field.error.duplicated")) {
ProductResponse response = new ProductResponse(ProductResponse.StatusCode.ERROR);
response.setMessage(translationService.translate("basic.dashboard.orderDefinitionWizard.error.validationError.productDuplicated", LocaleContextHolder.getLocale()));
return response;
}
}
ProductResponse response = new ProductResponse(ProductResponse.StatusCode.ERROR);
response.setMessage(translationService.translate("basic.dashboard.orderDefinitionWizard.error.validationError.productErrors", LocaleContextHolder.getLocale()));
return response;
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class SubassemblyToWorkstationHelperHooks method onSave.
public void onSave(DataDefinition subassemblyToWorkstationHelperDD, Entity subassemblyToWorkstationHelper) {
DataDefinition subassemblyDD = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBASSEMBLY);
Entity subassembly = subassemblyToWorkstationHelper.getBelongsToField(SubassemblyToWorkstationHelperFields.SUBASSEMBLY);
if (subassembly != null) {
subassembly.setField(SubassemblyFields.WORKSTATION, subassemblyToWorkstationHelper.getField(SubassemblyToWorkstationHelperFields.WORKSTATION));
subassembly.setField(SubassemblyFields.TYPE, subassemblyToWorkstationHelper.getField(SubassemblyToWorkstationHelperFields.TYPE));
subassembly = subassemblyDD.save(subassembly);
if (!subassembly.isValid()) {
for (Map.Entry<String, ErrorMessage> entry : subassembly.getErrors().entrySet()) {
subassemblyToWorkstationHelper.addGlobalError(entry.getValue().getMessage(), entry.getValue().getAutoClose(), entry.getValue().getVars());
subassemblyToWorkstationHelper.addError(subassemblyToWorkstationHelperDD.getField(SubassemblyToWorkstationHelperFields.TYPE), entry.getValue().getMessage());
}
for (ErrorMessage msg : subassembly.getGlobalErrors()) {
subassemblyToWorkstationHelper.addGlobalError(msg.getMessage(), msg.getAutoClose(), msg.getVars());
subassemblyToWorkstationHelper.addError(subassemblyToWorkstationHelperDD.getField(SubassemblyToWorkstationHelperFields.TYPE), msg.getMessage());
}
subassemblyToWorkstationHelper.setNotValid();
}
}
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class OrderStatesListenerServicePFTD method tryAcceptInboundDocumentsFor.
@Transactional()
private Either<String, Void> tryAcceptInboundDocumentsFor(final Entity order) {
updateDocumentQuantities(order);
DataDefinition documentDD = dataDefinitionService.get(MaterialFlowResourcesConstants.PLUGIN_IDENTIFIER, MaterialFlowResourcesConstants.MODEL_DOCUMENT);
SearchResult searchResult = documentDD.find().add(SearchRestrictions.belongsTo(DocumentFieldsPFTD.ORDER, order)).add(SearchRestrictions.eq(DocumentFields.TYPE, DocumentType.INTERNAL_INBOUND.getStringValue())).list();
String priceBasedOn = parameterService.getParameter().getStringField(ParameterFieldsPC.PRICE_BASED_ON);
boolean isNominalProductCost = priceBasedOn != null && priceBasedOn.equals(PriceBasedOn.NOMINAL_PRODUCT_COST.getStringValue());
Optional<BigDecimal> price = Optional.empty();
if (!isNominalProductCost) {
price = Optional.ofNullable(order.getDecimalField("productPricePerUnit"));
}
for (Entity document : searchResult.getEntities()) {
if (!isNominalProductCost) {
fillInDocumentPositionsPrice(document, order.getBelongsToField(OrderFields.PRODUCT), price);
}
if (DocumentState.of(document) == DocumentState.ACCEPTED) {
LOG.warn("Document {} already accepted.", document.getId());
continue;
}
Entity acceptedDocument = acceptInboundDocument(document);
if (!acceptedDocument.isValid()) {
documentStateChangeService.buildFailureStateChange(acceptedDocument.getId());
for (ErrorMessage error : acceptedDocument.getGlobalErrors()) {
order.addGlobalError(error.getMessage(), error.getVars());
}
order.addGlobalError(L_ACCEPT_INBOUND_DOCUMENT_ERROR);
return Either.left(L_ACCEPT_INBOUND_DOCUMENT_ERROR);
}
}
Either<String, Void> documentsForNotUsedMaterials = createDocumentsForNotUsedMaterials(order);
if (documentsForNotUsedMaterials.isLeft()) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}
return documentsForNotUsedMaterials;
}
Aggregations