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.");
}
}
}
}
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;
}
Aggregations