use of io.crate.metadata.settings.StringSetting in project crate by crate.
the class RepositoryParamValidator method convertAndValidate.
public Settings convertAndValidate(String type, Optional<GenericProperties> genericProperties, ParameterContext parameterContext) {
TypeSettings typeSettings = this.typeSettings.get(type);
if (typeSettings == null) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Invalid repository type \"%s\"", type));
}
Map<String, SettingsApplier> allSettings = typeSettings.all();
// create string settings applier for all dynamic settings
Optional<GenericProperties> dynamicProperties = typeSettings.dynamicProperties(genericProperties);
if (dynamicProperties.isPresent()) {
// allSettings are immutable by default, copy map
allSettings = Maps.newHashMap(allSettings);
for (String key : dynamicProperties.get().properties().keySet()) {
allSettings.put(key, new SettingsAppliers.StringSettingsApplier(new StringSetting(key, true)));
}
}
// convert and validate all settings
Settings settings = GenericPropertiesConverter.settingsFromProperties(genericProperties, parameterContext, allSettings).build();
Set<String> names = settings.getAsMap().keySet();
Sets.SetView<String> missingRequiredSettings = Sets.difference(typeSettings.required().keySet(), names);
if (!missingRequiredSettings.isEmpty()) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "The following required parameters are missing to create a repository of type \"%s\": [%s]", type, Joiner.on(", ").join(missingRequiredSettings)));
}
return settings;
}
Aggregations