use of alien4cloud.tosca.parser.ParsingErrorLevel in project alien4cloud by alien4cloud.
the class SuggestionService method checkProperty.
private AbstractSuggestionEntry checkProperty(String nodePrefix, String propertyName, String propertyTextValue, Class<? extends AbstractInheritableToscaType> type, String elementId, ParsingContext context) {
AbstractSuggestionEntry suggestionEntry = getSuggestionEntry(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, type.getSimpleName().toLowerCase(), elementId, propertyName);
if (suggestionEntry != null) {
PriorityQueue<SuggestionService.MatchedSuggestion> similarValues = getJaroWinklerMatchedSuggestions(suggestionEntry.getSuggestions(), propertyTextValue, 0.8);
if (!similarValues.isEmpty()) {
// Has some similar values in the system already
SuggestionService.MatchedSuggestion mostMatched = similarValues.poll();
if (!mostMatched.getValue().equals(propertyTextValue)) {
// If user has entered a property value not the same as the most matched in the system
ParsingErrorLevel level;
if (mostMatched.getPriority() == 1.0) {
// It's really identical if we take out all white spaces and lower / upper case
level = ParsingErrorLevel.WARNING;
} else {
// It's pretty similar
level = ParsingErrorLevel.INFO;
// Add suggestion anyway
addSuggestionValueToSuggestionEntry(suggestionEntry.getId(), propertyTextValue);
}
context.getParsingErrors().add(new ParsingError(level, ErrorCode.POTENTIAL_BAD_PROPERTY_VALUE, null, null, null, null, "At path [" + nodePrefix + "." + propertyName + "] existing value [" + mostMatched.getValue() + "] is very similar to [" + propertyTextValue + "]"));
}
} else {
// Not similar add suggestion
addSuggestionValueToSuggestionEntry(suggestionEntry.getId(), propertyTextValue);
}
}
return suggestionEntry;
}
Aggregations