Search in sources :

Example 1 with MapValidator

use of org.graylog2.database.validators.MapValidator in project graylog2-server by Graylog2.

the class InputImpl method getValidations.

@Override
public Map<String, Validator> getValidations() {
    final ImmutableMap.Builder<String, Validator> validations = ImmutableMap.builder();
    //validations.put(MessageInput.FIELD_INPUT_ID, new FilledStringValidator());
    validations.put(MessageInput.FIELD_TITLE, new FilledStringValidator());
    validations.put(MessageInput.FIELD_TYPE, new FilledStringValidator());
    validations.put(MessageInput.FIELD_CONFIGURATION, new MapValidator());
    validations.put(MessageInput.FIELD_CREATOR_USER_ID, new FilledStringValidator());
    validations.put(MessageInput.FIELD_CREATED_AT, new DateValidator());
    validations.put(MessageInput.FIELD_CONTENT_PACK, new OptionalStringValidator());
    return validations.build();
}
Also used : DateValidator(org.graylog2.database.validators.DateValidator) MapValidator(org.graylog2.database.validators.MapValidator) FilledStringValidator(org.graylog2.database.validators.FilledStringValidator) OptionalStringValidator(org.graylog2.database.validators.OptionalStringValidator) ImmutableMap(com.google.common.collect.ImmutableMap) OptionalStringValidator(org.graylog2.database.validators.OptionalStringValidator) Validator(org.graylog2.plugin.database.validators.Validator) MapValidator(org.graylog2.database.validators.MapValidator) DateValidator(org.graylog2.database.validators.DateValidator) FilledStringValidator(org.graylog2.database.validators.FilledStringValidator)

Example 2 with MapValidator

use of org.graylog2.database.validators.MapValidator in project graylog2-server by Graylog2.

the class InputImpl method getEmbeddedValidations.

@Override
public Map<String, Validator> getEmbeddedValidations(String key) {
    if (EMBEDDED_EXTRACTORS.equals(key)) {
        final ImmutableMap.Builder<String, Validator> validations = ImmutableMap.builder();
        validations.put(Extractor.FIELD_ID, new FilledStringValidator());
        validations.put(Extractor.FIELD_TITLE, new FilledStringValidator());
        validations.put(Extractor.FIELD_TYPE, new FilledStringValidator());
        validations.put(Extractor.FIELD_CURSOR_STRATEGY, new FilledStringValidator());
        validations.put(Extractor.FIELD_TARGET_FIELD, new FilledStringValidator());
        validations.put(Extractor.FIELD_SOURCE_FIELD, new FilledStringValidator());
        validations.put(Extractor.FIELD_CREATOR_USER_ID, new FilledStringValidator());
        validations.put(Extractor.FIELD_EXTRACTOR_CONFIG, new MapValidator());
        return validations.build();
    }
    if (EMBEDDED_STATIC_FIELDS.equals(key)) {
        return ImmutableMap.of(FIELD_STATIC_FIELD_KEY, new FilledStringValidator(), FIELD_STATIC_FIELD_VALUE, new FilledStringValidator());
    }
    return Collections.emptyMap();
}
Also used : MapValidator(org.graylog2.database.validators.MapValidator) FilledStringValidator(org.graylog2.database.validators.FilledStringValidator) ImmutableMap(com.google.common.collect.ImmutableMap) OptionalStringValidator(org.graylog2.database.validators.OptionalStringValidator) Validator(org.graylog2.plugin.database.validators.Validator) MapValidator(org.graylog2.database.validators.MapValidator) DateValidator(org.graylog2.database.validators.DateValidator) FilledStringValidator(org.graylog2.database.validators.FilledStringValidator)

Example 3 with MapValidator

use of org.graylog2.database.validators.MapValidator in project graylog2-server by Graylog2.

the class MapValidatorTest method testValidate.

@Test
public void testValidate() throws Exception {
    Validator v = new MapValidator();
    assertFalse(v.validate(null).passed());
    assertFalse(v.validate(new LinkedList<Integer>()).passed());
    assertFalse(v.validate(9001).passed());
    assertFalse(v.validate("foo").passed());
    Map<String, String> actuallyFilledMap = new TreeMap<String, String>();
    actuallyFilledMap.put("foo", "bar");
    actuallyFilledMap.put("lol", "wut");
    assertTrue(v.validate(actuallyFilledMap).passed());
    assertTrue(v.validate(new HashMap<String, String>()).passed());
}
Also used : TreeMap(java.util.TreeMap) Validator(org.graylog2.plugin.database.validators.Validator) Test(org.junit.Test)

Aggregations

Validator (org.graylog2.plugin.database.validators.Validator)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 DateValidator (org.graylog2.database.validators.DateValidator)2 FilledStringValidator (org.graylog2.database.validators.FilledStringValidator)2 MapValidator (org.graylog2.database.validators.MapValidator)2 OptionalStringValidator (org.graylog2.database.validators.OptionalStringValidator)2 TreeMap (java.util.TreeMap)1 Test (org.junit.Test)1