-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Labels
Description
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:
- Use INFO level - configuredExpressions list has 180 elements.
- Use ERROR level - configuredExpressions list has 120 elements.
- 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());
}
Reactions are currently unavailable