Skip to content

The configuredExpressions variable has wrong values quantity after limitConfiguredExpressionsBySeverity is applied #107

@radiovideo

Description

@radiovideo

See: org.sitenv.vocabularies.validation.services.VocabularyValidationService#validate

The configuredExpressions variable has wrong values quantity in case we want to validate same document more than two times with the different severity level. As a result we can get different validation results.
Validation iterations:

  1. Use INFO level - configuredExpressions list has 180 elements.
  2. Use ERROR level - configuredExpressions list has 120 elements.
  3. Use INFO level again - configuredExpressions list has 120 elements. Not 180 as it was before ERROR.
    In this case we can add a new list as a local variable and add suitable ConfiguredExpressions to it for each validation process.

Possible fix:

private void validate(Map<String, ArrayList<VocabularyValidationResult>> vocabularyValidationResultMap, String configuredXpathExpression, XPath xpath, Document doc, SeverityLevel severityLevel) throws XPathExpressionException {
		List<ConfiguredExpression> limitedConfiguredExpressions = new ArrayList<>();
		if (severityLevel != SeverityLevel.INFO) {
			limitConfiguredExpressionsBySeverity(severityLevel, limitedConfiguredExpressions);
		} else {
			limitedConfiguredExpressions = vocabularyValidationConfigurations;
		}

		globalCodeValidatorResults.setVocabularyValidationConfigurationsCount(limitedConfiguredExpressions.size());
		globalCodeValidatorResults.setVocabularyValidationConfigurationsErrorCount(determineConfigurationsErrorCount());

		for (ConfiguredExpression configuredExpression : limitedConfiguredExpressions) {
private void limitConfiguredExpressionsBySeverity(SeverityLevel severityLevelLimit, List<ConfiguredExpression> configuredExpressions) {
		// This improves performance since it is run before the expressions are processed
		logger.info("limiting configured expressions by severity level: " + severityLevelLimit.name());
		for (ConfiguredExpression configuredExpression : vocabularyValidationConfigurations) {
			// NodeCodeSystemMatchesConfiguredCodeSystemValidator defaults to ERROR severity dynamically
			configuredExpression.getConfiguredValidators().parallelStream()
					.filter(configuredValidator -> !configuredValidator.getName().equalsIgnoreCase("NodeCodeSystemMatchesConfiguredCodeSystemValidator"))
					.map(configuredValidator -> configuredValidator.getConfiguredValidationResultSeverityLevel().getSeverityLevelConversion())
					.forEach(configuredSeverityLevelConversion -> {
						if (severityLevelLimit == SeverityLevel.WARNING && configuredSeverityLevelConversion != SeverityLevel.INFO) {
							// skip may/info configurations so we only process warnings and errors
							configuredExpressions.add(configuredExpression);
						}
						if (severityLevelLimit == SeverityLevel.ERROR && configuredSeverityLevelConversion == SeverityLevel.ERROR) {
							// skip may/info and should/warnings configurations so we only process errors
							configuredExpressions.add(configuredExpression);
						}
			});
		}
		configuredExpressions.removeIf(configuredExpression -> configuredExpression.getConfiguredValidators().isEmpty());
	}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions