Search in sources :

Example 6 with Validator

use of org.graylog2.plugin.database.validators.Validator 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 7 with Validator

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

the class AccessTokenImpl method getValidations.

@Override
public Map<String, Validator> getValidations() {
    Map<String, Validator> validations = Maps.newHashMap();
    validations.put(USERNAME, new FilledStringValidator());
    validations.put(TOKEN, new FilledStringValidator());
    validations.put(NAME, new FilledStringValidator());
    return validations;
}
Also used : FilledStringValidator(org.graylog2.database.validators.FilledStringValidator) Validator(org.graylog2.plugin.database.validators.Validator) FilledStringValidator(org.graylog2.database.validators.FilledStringValidator)

Example 8 with Validator

use of org.graylog2.plugin.database.validators.Validator 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)8 FilledStringValidator (org.graylog2.database.validators.FilledStringValidator)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 OptionalStringValidator (org.graylog2.database.validators.OptionalStringValidator)3 Test (org.junit.Test)3 DateValidator (org.graylog2.database.validators.DateValidator)2 MapValidator (org.graylog2.database.validators.MapValidator)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 BasicDBObject (com.mongodb.BasicDBObject)1 DBCollection (com.mongodb.DBCollection)1 DBCursor (com.mongodb.DBCursor)1 DBObject (com.mongodb.DBObject)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ObjectId (org.bson.types.ObjectId)1