@Override public Iterable<ErrorMessage> apply(final Entity input) { return input.getGlobalErrors(); } }));
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(); } }
private void copyErrors(Entity resource, FormComponent resourceForm) { resource.getGlobalErrors().forEach(error -> { resourceForm.addMessage(error); }); resource.getErrors().values().forEach(error -> { resourceForm.addMessage(error); }); } }
private void copyMessages(Entity entity, Entity mainEntity) { if (mainEntity != null && mainEntity.equals(entity) && entity.getGlobalErrors() == mainEntity.getGlobalErrors()) { return; } if (componentMessagesHolder == null) { return; } for (ErrorMessage errorMessage : entity.getGlobalErrors()) { componentMessagesHolder.addMessage(errorMessage); } for (ErrorMessage errorMessage : entity.getErrors().values()) { componentMessagesHolder.addMessage(errorMessage); } for (GlobalMessage globalMessage : entity.getGlobalMessages()) { componentMessagesHolder.addMessage(globalMessage); } }
private void addPositionErrors(ViewDefinitionState view, Entity saved) { saved.getGlobalErrors().forEach(view::addMessage); if (!saved.getErrors().isEmpty()) { view.addMessage("materialFlow.document.fillResources.global.error.positionNotValid", ComponentState.MessageType.FAILURE, false, saved.getBelongsToField(PositionFields.PRODUCT).getStringField(ProductFields.NUMBER)); } }
public StateChangeStatus tryCorrect(final Entity productionRecord, final boolean logMessages) { Long userId = securityService.getCurrentUserId(); productionRecord.setField(USER_CHANGE_STATE, userId); String userLogin = securityService.getCurrentUserName(); stateExecutorService.changeState(ProductionTrackingStateServiceMarker.class, productionRecord, userLogin, ProductionTrackingStateStringValues.CORRECTED); if (productionRecord.isValid()) { return StateChangeStatus.SUCCESSFUL; } else { if (logMessages) { LOGGER.error(productionRecord.getErrors().toString()); LOGGER.error(productionRecord.getGlobalErrors().toString()); } return StateChangeStatus.FAILURE; } }
public StateChangeStatus tryAccept(final Entity productionRecord, final boolean logMessages) { Long userId = securityService.getCurrentUserId(); productionRecord.setField(USER_CHANGE_STATE, userId); String userLogin = securityService.getCurrentUserName(); stateExecutorService.changeState(ProductionTrackingStateServiceMarker.class, productionRecord, userLogin, ProductionTrackingStateStringValues.ACCEPTED); if (productionRecord.isValid()) { return StateChangeStatus.SUCCESSFUL; } else { if (logMessages) { LOGGER.error(productionRecord.getErrors().toString()); LOGGER.error(productionRecord.getGlobalErrors().toString()); } return StateChangeStatus.FAILURE; } }
public static void copyErrorsFromEntity(final StateChangeContext stateChangeContext, final Entity entity) { for (ErrorMessage globalError : entity.getGlobalErrors()) { stateChangeContext.addValidationError(globalError.getMessage(), globalError.getVars()); } for (Entry<String, ErrorMessage> fieldErrorMessageEntry : entity.getErrors().entrySet()) { final ErrorMessage fieldErrorMessage = fieldErrorMessageEntry.getValue(); stateChangeContext.addFieldValidationError(fieldErrorMessageEntry.getKey(), fieldErrorMessage.getMessage(), fieldErrorMessage.getVars()); } }
private Either<List<ErrorMessage>, Entity> setupPPS(final Entity pps, final List<Entity> savedProgresses, final boolean hasCorrections) { List<Entity> otherTypeProgresses = findProgressesMatching(pps, !hasCorrections); List<Entity> progresses = Lists.newLinkedList(Iterables.concat(otherTypeProgresses, savedProgresses)); pps.setField(ProductionPerShiftFields.PROGRES_FOR_DAYS, progresses); if (saved(pps).isValid()) { return Either.right(pps); } return Either.left(pps.getGlobalErrors()); }
public void checkResourcesStock(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FormComponent formComponent = (FormComponent) view.getComponentByReference(L_FORM); Entity document = formComponent.getPersistedEntityWithIncludedFormValues(); resourceStockService.checkResourcesStock(document); if (document.getGlobalErrors().isEmpty()) { view.addMessage("materialFlow.document.checkResourcesStock.global.message.success", MessageType.SUCCESS, true); } formComponent.setEntity(document); }
private boolean checkValueOfQuantity(final DataDefinition basicProductionCountingDD, final Entity basicProductionCounting) { BigDecimal usedQuantity = basicProductionCounting.getDecimalField(BasicProductionCountingFields.USED_QUANTITY); BigDecimal producedQuantity = basicProductionCounting.getDecimalField(BasicProductionCountingFields.PRODUCED_QUANTITY); if ((usedQuantity == null) && (producedQuantity == null)) { return true; } if ((usedQuantity != null) && (usedQuantity.compareTo(BigDecimal.ZERO) == -1)) { basicProductionCounting.addError(basicProductionCountingDD.getField(BasicProductionCountingFields.USED_QUANTITY), "basicProductionCounting.basicProductionCounting.quantity.error.lowerThanZero"); } if ((producedQuantity != null) && (producedQuantity.compareTo(BigDecimal.ZERO) == -1)) { basicProductionCounting.addError(basicProductionCountingDD.getField(BasicProductionCountingFields.PRODUCED_QUANTITY), "basicProductionCounting.basicProductionCounting.quantity.error.lowerThanZero"); } if (!basicProductionCounting.getGlobalErrors().isEmpty() || !basicProductionCounting.getErrors().isEmpty()) { return false; } return true; }
private void copyMessages(Entity entity, final ViewDefinitionState componentMessagesHolder) { if (componentMessagesHolder == null) { return; } for (ErrorMessage errorMessage : entity.getGlobalErrors()) { componentMessagesHolder.addMessage(errorMessage); } for (ErrorMessage errorMessage : entity.getErrors().values()) { componentMessagesHolder.addMessage(errorMessage); } for (GlobalMessage globalMessage : entity.getGlobalMessages()) { componentMessagesHolder.addMessage(globalMessage); } }
@Override public void afterCompletion(int status) { super.afterCompletion(status); if (TransactionSynchronization.STATUS_ROLLED_BACK == status) { document.getGlobalErrors().stream() .filter(errorMessage -> "materialFlow.error.position.quantity.notEnoughResources" .equals(errorMessage.getMessage())) .forEach(errorMessage -> logService.add(LogService.Builder .error("document", translationService.translate("materialFlowResources.document.accept", LocaleContextHolder.getLocale())) .withMessage(translationService.translate("materialFlow.error.position.quantity.notEnough", LocaleContextHolder.getLocale())) .withItem1(document.getStringField(DocumentFields.NUMBER)) .withItem2(errorMessage.getVars()[0]).withItem3(errorMessage.getVars()[1]))); } } });
private Entity createNewOrderPrint(final Set<Entity> orders, final String plugin, final String entityName, final Map<String, Object> entityFieldsMap, final Locale locale) { DataDefinition data = dataDefinitionService.get(plugin, entityName); Entity entity = data.create(); entity.setField("name", generateOrderPrintName(orders, locale)); entity.setField("generated", true); entity.setField("worker", pdfHelper.getDocumentAuthor()); entity.setField("date", new Date()); if (data.getField("orders") != null) { entity.setField("orders", Lists.newArrayList(orders)); } if (entityFieldsMap != null) { for (Map.Entry<String, Object> entityFieldsMapEntry : entityFieldsMap.entrySet()) { entity.setField(entityFieldsMapEntry.getKey(), entityFieldsMapEntry.getValue()); } } Entity saved = data.save(entity); if (!saved.isValid()) { throw new IllegalStateException("Entity " + saved + " is not valid! - " + saved.getErrors() + " / " + saved.getGlobalErrors()); } return saved; }
private void addPositionErrors(final Entity document, final Entity saved) { if (!saved.isValid()) { document.setNotValid(); saved.getGlobalErrors().forEach(e -> document.addGlobalError(e.getMessage(), e.getAutoClose(), e.getVars())); if (!saved.getErrors().isEmpty()) { document.addGlobalError("materialFlow.document.fillResources.global.error.positionNotValid", false, saved .getBelongsToField(PositionFields.PRODUCT).getStringField(ProductFields.NUMBER)); } } }
@Transactional(propagation = Propagation.REQUIRES_NEW) private void tryAcceptProductionTracking(ViewDefinitionState view, boolean performed) throws JSONException { if (performed) { Long productionRecordId = view.getJsonContext().getLong("window.mainTab.form.productionTrackingId"); Entity productionRecord = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_PRODUCTION_TRACKING).get(productionRecordId); Long userId = securityService.getCurrentUserId(); productionRecord.setField("user", userId); String userLogin = securityService.getCurrentUserName(); stateExecutorService.changeState(ProductionTrackingStateServiceMarker.class, productionRecord, userLogin, ProductionTrackingStateStringValues.ACCEPTED); if (productionRecord.isValid()) { view.addMessage("productionCounting.anomalyProductionTrackingDetails.productionTrackingAccepted", ComponentState.MessageType.SUCCESS); } else { view.addMessage("productionCounting.anomalyProductionTrackingDetails.productionTrackingNotAccepted", ComponentState.MessageType.FAILURE); productionRecord.getGlobalErrors().forEach(view::addMessage); } } }
private CreationDocumentResponse build(DocumentsStatus documentsStatus, DocumentBuilder documentBuilder) { Entity document; try { if (DocumentsStatus.ACCEPTED.getStrValue().equals(documentsStatus.getStrValue())) { document = documentBuilder.setAccepted().buildWithEntityRuntimeException(); } else { document = documentBuilder.buildWithEntityRuntimeException(); } if (!document.isValid()) { List<ErrorMessage> errors = Lists.newArrayList(); errors.addAll(document.getGlobalErrors()); return new CreationDocumentResponse(false, errors); } CreationDocumentResponse creationDocumentResponse = new CreationDocumentResponse(true); creationDocumentResponse.setDocument(document); return creationDocumentResponse; } catch (DocumentBuildException e) { return new CreationDocumentResponse(false, e.getGlobalErrors()); } }
private void copyPositionMessages(Entity invalidPosition, final ViewDefinitionState componentMessagesHolder) { if (componentMessagesHolder == null) { return; } Locale locale = LocaleContextHolder.getLocale(); String productNumber = Optional.of(invalidPosition).map(ip -> ip.getBelongsToField(PositionFields.PRODUCT)) .map(p -> p.getStringField(ProductFields.NUMBER)).orElse("???"); for (ErrorMessage errorMessage : invalidPosition.getGlobalErrors()) { String translatedMessage = translationService.translate(errorMessage.getMessage(), locale, errorMessage.getVars()); translatedMessage = translationService.translate("productFlowThruDivision.issue.documentBuild.position.error", locale, translatedMessage, productNumber); componentMessagesHolder.addTranslatedMessage(translatedMessage, ComponentState.MessageType.FAILURE, errorMessage.getAutoClose(), errorMessage.isExtraLarge()); } for (ErrorMessage errorMessage : invalidPosition.getErrors().values()) { String translatedMessage = translationService.translate(errorMessage.getMessage(), locale, errorMessage.getVars()); translatedMessage = translationService.translate("productFlowThruDivision.issue.documentBuild.position.error", locale, translatedMessage, productNumber); componentMessagesHolder.addTranslatedMessage(translatedMessage, ComponentState.MessageType.FAILURE, errorMessage.getAutoClose(), errorMessage.isExtraLarge()); } }
@Override @Transactional public void createResourcesForReceiptDocuments(final Entity document) { Entity warehouse = document.getBelongsToField(DocumentFields.LOCATION_TO); Object date = document.getField(DocumentFields.TIME); for (Entity position : document.getHasManyField(DocumentFields.POSITIONS)) { createResource(document, warehouse, position, date); position = position.getDataDefinition().save(position); if (!position.isValid()) { document.setNotValid(); position.getGlobalErrors().forEach(e -> document.addGlobalError(e.getMessage(), e.getAutoClose(), e.getVars())); position.getErrors().values() .forEach(e -> document.addGlobalError(e.getMessage(), e.getAutoClose(), e.getVars())); } } }
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(); } } }