Search in sources :

Example 11 with ConfigurationField

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

the class ConfigurationRequest method check.

public void check(Configuration configuration) throws ConfigurationException {
    for (ConfigurationField field : fields.values()) {
        if (field.isOptional().equals(ConfigurationField.Optional.NOT_OPTIONAL)) {
            final String type = field.getFieldType();
            final String fieldName = field.getName();
            log.debug("Checking for mandatory field \"{}\" of type {} in configuration", fieldName, type);
            switch(type) {
                case BooleanField.FIELD_TYPE:
                    if (!configuration.booleanIsSet(fieldName)) {
                        throw new ConfigurationException("Mandatory configuration field \"" + fieldName + "\" is missing or has the wrong data type");
                    }
                    break;
                case NumberField.FIELD_TYPE:
                    if (!configuration.intIsSet(fieldName)) {
                        throw new ConfigurationException("Mandatory configuration field \"" + fieldName + "\" is missing or has the wrong data type");
                    }
                    break;
                case ListField.FIELD_TYPE:
                    if (!configuration.listIsSet(fieldName)) {
                        throw new ConfigurationException("Mandatory configuration field \"" + fieldName + "\" is missing or has the wrong data type");
                    }
                    break;
                case TextField.FIELD_TYPE:
                case DropdownField.FIELD_TYPE:
                    if (!configuration.stringIsSet(fieldName)) {
                        throw new ConfigurationException("Mandatory configuration field \"" + fieldName + "\" is missing or has the wrong data type");
                    }
                    break;
                default:
                    throw new IllegalStateException("Unknown field type " + type + " for configuration field \"" + fieldName + "\". This is a bug.");
            }
        }
    }
}
Also used : ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField)

Example 12 with ConfigurationField

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

the class ConfigurationRequest method asList.

@JsonValue
public Map<String, Map<String, Object>> asList() {
    final Map<String, Map<String, Object>> configs = Maps.newLinkedHashMap();
    for (ConfigurationField f : fields.values()) {
        final Map<String, Object> config = Maps.newHashMap();
        config.put("type", f.getFieldType());
        config.put("human_name", f.getHumanName());
        config.put("description", f.getDescription());
        config.put("default_value", f.getDefaultValue());
        config.put("is_optional", f.isOptional().equals(ConfigurationField.Optional.OPTIONAL));
        config.put("attributes", f.getAttributes());
        config.put("additional_info", f.getAdditionalInformation());
        config.put("position", f.getPosition());
        configs.put(f.getName(), config);
    }
    return configs;
}
Also used : ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField) Map(java.util.Map) JsonValue(com.fasterxml.jackson.annotation.JsonValue)

Aggregations

ConfigurationField (org.graylog2.plugin.configuration.fields.ConfigurationField)12 Test (org.junit.Test)8 ConfigurationRequest (org.graylog2.plugin.configuration.ConfigurationRequest)7 TextField (org.graylog2.plugin.configuration.fields.TextField)7 Input (org.graylog2.inputs.Input)4 InputDescription (org.graylog2.shared.inputs.InputDescription)4 InputSummary (org.graylog2.rest.models.system.inputs.responses.InputSummary)2 InputsList (org.graylog2.rest.models.system.inputs.responses.InputsList)2 JsonValue (com.fasterxml.jackson.annotation.JsonValue)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Nonnull (javax.annotation.Nonnull)1