use of alien4cloud.model.common.AbstractSuggestionEntry in project alien4cloud by alien4cloud.
the class SuggestionService method checkPropertyConstraints.
private void checkPropertyConstraints(String prefix, Class<? extends AbstractInheritableToscaType> type, String elementId, String propertyName, List<PropertyConstraint> constraints, ParsingContext context) {
if (constraints != null && !constraints.isEmpty()) {
for (PropertyConstraint propertyConstraint : constraints) {
if (propertyConstraint instanceof EqualConstraint) {
EqualConstraint equalConstraint = (EqualConstraint) propertyConstraint;
String valueToCheck = equalConstraint.getEqual();
if (checkProperty(prefix, propertyName, valueToCheck, type, elementId, context) == null) {
createSuggestionEntry(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, CapabilityType.class, Sets.newHashSet(valueToCheck), elementId, propertyName);
}
} else if (propertyConstraint instanceof ValidValuesConstraint) {
ValidValuesConstraint validValuesConstraint = (ValidValuesConstraint) propertyConstraint;
if (validValuesConstraint.getValidValues() != null && !validValuesConstraint.getValidValues().isEmpty()) {
AbstractSuggestionEntry foundSuggestion = null;
for (String valueToCheck : validValuesConstraint.getValidValues()) {
foundSuggestion = checkProperty(prefix, propertyName, valueToCheck, type, elementId, context);
if (foundSuggestion == null) {
// No suggestion exists don't need to check any more for other values
break;
}
}
if (foundSuggestion == null) {
createSuggestionEntry(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, CapabilityType.class, Sets.newHashSet(validValuesConstraint.getValidValues()), elementId, propertyName);
}
}
}
}
}
}
use of alien4cloud.model.common.AbstractSuggestionEntry in project alien4cloud by alien4cloud.
the class SuggestionService method addSuggestionValueToSuggestionEntry.
public void addSuggestionValueToSuggestionEntry(String suggestionId, String newValue) {
AbstractSuggestionEntry suggestion = alienDAO.findById(AbstractSuggestionEntry.class, suggestionId);
if (suggestion == null) {
throw new NotFoundException("Suggestion entry [" + suggestionId + "] cannot be found");
}
// TODO: should check the format of new value
if (suggestion.getSuggestions().contains(newValue)) {
return;
}
suggestion.getSuggestions().add(newValue);
alienDAO.save(suggestion);
}
use of alien4cloud.model.common.AbstractSuggestionEntry 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