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