Search in sources :

Example 1 with LookupResult

use of org.graylog2.plugin.lookup.LookupResult in project graylog2-server by Graylog2.

the class LookupTableTesterResource method doTestLookupTable.

private LookupTableTesterResponse doTestLookupTable(String string, String lookupTableName) {
    if (!lookupTableService.hasTable(lookupTableName)) {
        return LookupTableTesterResponse.error("Lookup table <" + lookupTableName + "> doesn't exist");
    }
    final LookupTableService.Function table = lookupTableService.newBuilder().lookupTable(lookupTableName).build();
    final LookupResult result = table.lookup(string.trim());
    if (result == null) {
        return LookupTableTesterResponse.emptyResult(string);
    }
    return LookupTableTesterResponse.result(string, result);
}
Also used : LookupResult(org.graylog2.plugin.lookup.LookupResult) LookupTableService(org.graylog2.lookup.LookupTableService)

Example 2 with LookupResult

use of org.graylog2.plugin.lookup.LookupResult in project graylog2-server by Graylog2.

the class LookupTable method addStringList.

public LookupResult addStringList(@Nonnull Object key, @Nonnull List<String> value, boolean keepDuplicates) {
    final LookupResult result = dataAdapter().addStringList(key, value, keepDuplicates);
    cache().purge(LookupCacheKey.create(dataAdapter(), key));
    return result;
}
Also used : LookupResult(org.graylog2.plugin.lookup.LookupResult)

Example 3 with LookupResult

use of org.graylog2.plugin.lookup.LookupResult in project graylog2-server by Graylog2.

the class HTTPJSONPathDataAdapterTest method parseEmptyBody.

@Test
public void parseEmptyBody() throws Exception {
    final JsonPath singlePath = JsonPath.compile("$.hello");
    final JsonPath multiPath = JsonPath.compile("$.list");
    final LookupResult result = HTTPJSONPathDataAdapter.parseBody(singlePath, multiPath, emptyBody);
    assertThat(result).isNull();
}
Also used : LookupResult(org.graylog2.plugin.lookup.LookupResult) JsonPath(com.jayway.jsonpath.JsonPath) Test(org.junit.Test)

Example 4 with LookupResult

use of org.graylog2.plugin.lookup.LookupResult in project graylog2-server by Graylog2.

the class HTTPJSONPathDataAdapterTest method parseBodyWithMapMultiValue.

@Test
public void parseBodyWithMapMultiValue() throws Exception {
    final JsonPath singlePath = JsonPath.compile("$.hello");
    final JsonPath multiPath = JsonPath.compile("$.map");
    final LookupResult result = HTTPJSONPathDataAdapter.parseBody(singlePath, multiPath, body);
    assertThat(result.isEmpty()).isFalse();
    assertThat(result.hasError()).isFalse();
    assertThat(result.singleValue()).isEqualTo("world");
    assertThat(result.multiValue()).isNotNull();
    assertThat(result.multiValue()).isInstanceOf(Map.class);
    assertThat(result.multiValue()).containsOnly(entry("key1", "value1"), entry("key2", "value2"));
}
Also used : LookupResult(org.graylog2.plugin.lookup.LookupResult) JsonPath(com.jayway.jsonpath.JsonPath) Test(org.junit.Test)

Example 5 with LookupResult

use of org.graylog2.plugin.lookup.LookupResult in project graylog2-server by Graylog2.

the class HTTPJSONPathDataAdapterTest method parseBodyWithListMultiValue.

@Test
public void parseBodyWithListMultiValue() throws Exception {
    final JsonPath singlePath = JsonPath.compile("$.hello");
    final JsonPath multiPath = JsonPath.compile("$.list");
    final LookupResult result = HTTPJSONPathDataAdapter.parseBody(singlePath, multiPath, body);
    assertThat(result.isEmpty()).isFalse();
    assertThat(result.hasError()).isFalse();
    assertThat(result.singleValue()).isEqualTo("world");
    assertThat(result.multiValue()).isNotNull();
    assertThat(result.multiValue()).isInstanceOf(Map.class);
    assertThat(result.multiValue()).containsKey("value");
    // noinspection ConstantConditions
    assertThat(result.multiValue().get("value")).isInstanceOf(Collection.class);
    // noinspection unchecked,ConstantConditions
    assertThat((Collection) result.multiValue().get("value")).containsOnly("a", "b", "c");
    assertThat(result.stringListValue()).containsOnly("a", "b", "c");
}
Also used : LookupResult(org.graylog2.plugin.lookup.LookupResult) Collection(java.util.Collection) JsonPath(com.jayway.jsonpath.JsonPath) Test(org.junit.Test)

Aggregations

LookupResult (org.graylog2.plugin.lookup.LookupResult)17 LookupTableService (org.graylog2.lookup.LookupTableService)5 JsonPath (com.jayway.jsonpath.JsonPath)3 Test (org.junit.Test)3 Timer (com.codahale.metrics.Timer)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 DocumentContext (com.jayway.jsonpath.DocumentContext)1 InvalidJsonException (com.jayway.jsonpath.InvalidJsonException)1 InvalidPathException (com.jayway.jsonpath.InvalidPathException)1 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)1 UnknownHostException (java.net.UnknownHostException)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 HttpUrl (okhttp3.HttpUrl)1