Search in sources :

Example 1 with BooleanField

use of org.graylog2.plugin.configuration.fields.BooleanField in project graylog2-server by Graylog2.

the class AvailableAlarmCallbackSummaryResponse method extractRequestedConfiguration.

public List<RequestedConfigurationField> extractRequestedConfiguration(Map<String, Map<String, Object>> config) {
    List<RequestedConfigurationField> result = Lists.newArrayList();
    List<RequestedConfigurationField> booleanFields = Lists.newArrayList();
    for (Map.Entry<String, Map<String, Object>> entry : config.entrySet()) {
        try {
            String fieldType = (String) entry.getValue().get("type");
            switch(fieldType) {
                case "text":
                    result.add(new TextField(entry));
                    continue;
                case "number":
                    result.add(new NumberField(entry));
                    continue;
                case "boolean":
                    booleanFields.add(new BooleanField(entry));
                    continue;
                case "dropdown":
                    result.add(new DropdownField(entry));
                    continue;
                default:
                    LOG.info("Unknown field type [{}].", fieldType);
            }
        } catch (Exception e) {
            LOG.error("Skipping invalid configuration field [" + entry.getKey() + "]", e);
        }
    }
    result.addAll(booleanFields);
    return result;
}
Also used : DropdownField(org.graylog2.rest.models.configuration.responses.DropdownField) BooleanField(org.graylog2.rest.models.configuration.responses.BooleanField) RequestedConfigurationField(org.graylog2.rest.models.configuration.responses.RequestedConfigurationField) TextField(org.graylog2.rest.models.configuration.responses.TextField) Map(java.util.Map) NumberField(org.graylog2.rest.models.configuration.responses.NumberField)

Example 2 with BooleanField

use of org.graylog2.plugin.configuration.fields.BooleanField in project graylog2-server by Graylog2.

the class ConfigurationMapConverterTest method testConvertValues.

@Test
public void testConvertValues() throws Exception {
    final ImmutableMap<String, String> dropdownChoices = ImmutableMap.of("a", "1", "b", "2");
    final ConfigurationRequest cr = new ConfigurationRequest();
    cr.addField(new TextField("string", "string", "default", ""));
    cr.addField(new TextField("empty-string", "empty", "", ""));
    cr.addField(new TextField("null-string", "null", null, ""));
    cr.addField(new TextField("non-string", "non-string", null, ""));
    cr.addField(new NumberField("number", "number", 42, ""));
    cr.addField(new BooleanField("boolean-true", "true", false, ""));
    cr.addField(new BooleanField("boolean-false", "false", false, ""));
    cr.addField(new DropdownField("dropdown", "dropdown", "a", dropdownChoices, "", ConfigurationField.Optional.NOT_OPTIONAL));
    cr.addField(new DropdownField("dropdown-empty", "dropdown-empty", "", dropdownChoices, "", ConfigurationField.Optional.NOT_OPTIONAL));
    cr.addField(new DropdownField("dropdown-null", "dropdown-null", "", dropdownChoices, "", ConfigurationField.Optional.NOT_OPTIONAL));
    final UUID uuid = UUID.randomUUID();
    final Map<String, Object> data = new HashMap<>();
    data.put("string", "foo");
    data.put("empty-string", "");
    data.put("null-string", null);
    data.put("non-string", uuid);
    data.put("number", "5");
    data.put("boolean-true", "true");
    data.put("boolean-false", "false");
    data.put("dropdown", "a");
    data.put("dropdown-empty", "");
    data.put("dropdown-null", null);
    final Map<String, Object> config = ConfigurationMapConverter.convertValues(data, cr);
    assertThat(config).contains(entry("string", "foo"), entry("empty-string", ""), entry("null-string", ""), entry("non-string", uuid.toString()), entry("number", 5), entry("boolean-true", true), entry("boolean-false", false), entry("dropdown", "a"), entry("dropdown-empty", ""), entry("dropdown-null", ""));
}
Also used : DropdownField(org.graylog2.plugin.configuration.fields.DropdownField) BooleanField(org.graylog2.plugin.configuration.fields.BooleanField) HashMap(java.util.HashMap) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) TextField(org.graylog2.plugin.configuration.fields.TextField) UUID(java.util.UUID) NumberField(org.graylog2.plugin.configuration.fields.NumberField) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 ConfigurationRequest (org.graylog2.plugin.configuration.ConfigurationRequest)1 BooleanField (org.graylog2.plugin.configuration.fields.BooleanField)1 DropdownField (org.graylog2.plugin.configuration.fields.DropdownField)1 NumberField (org.graylog2.plugin.configuration.fields.NumberField)1 TextField (org.graylog2.plugin.configuration.fields.TextField)1 BooleanField (org.graylog2.rest.models.configuration.responses.BooleanField)1 DropdownField (org.graylog2.rest.models.configuration.responses.DropdownField)1 NumberField (org.graylog2.rest.models.configuration.responses.NumberField)1 RequestedConfigurationField (org.graylog2.rest.models.configuration.responses.RequestedConfigurationField)1 TextField (org.graylog2.rest.models.configuration.responses.TextField)1 Test (org.junit.Test)1