Search in sources :

Example 1 with StringSetting

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;
}
Also used : SettingsAppliers(io.crate.metadata.settings.SettingsAppliers) SettingsApplier(io.crate.metadata.settings.SettingsApplier) StringSetting(io.crate.metadata.settings.StringSetting) Sets(com.google.common.collect.Sets) GenericProperties(io.crate.sql.tree.GenericProperties) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

Sets (com.google.common.collect.Sets)1 SettingsApplier (io.crate.metadata.settings.SettingsApplier)1 SettingsAppliers (io.crate.metadata.settings.SettingsAppliers)1 StringSetting (io.crate.metadata.settings.StringSetting)1 GenericProperties (io.crate.sql.tree.GenericProperties)1 Settings (org.elasticsearch.common.settings.Settings)1