Search in sources :

Example 11 with MessageList

use of org.graylog.plugins.views.search.searchtypes.MessageList in project graylog2-server by Graylog2.

the class CommandFactoryTest method takesDefaultFieldsIfNotSpecifiedInResultFormat.

@Test
void takesDefaultFieldsIfNotSpecifiedInResultFormat() {
    MessageList ml = MessageList.builder().id("ml-id").build();
    Query q = validQueryBuilderWith(ml).build();
    Search s = searchWithQueries(q);
    ExportMessagesCommand command = buildFrom(s, ml.id(), ResultFormat.builder().build());
    assertThat(command.fieldsInOrder()).isEqualTo(DEFAULT_FIELDS);
}
Also used : Query(org.graylog.plugins.views.search.Query) Search(org.graylog.plugins.views.search.Search) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) Test(org.junit.jupiter.api.Test)

Example 12 with MessageList

use of org.graylog.plugins.views.search.searchtypes.MessageList in project graylog2-server by Graylog2.

the class CommandFactoryTest method takesQueryStringFromQueryIfOnlySpecifiedThere.

@Test
void takesQueryStringFromQueryIfOnlySpecifiedThere() {
    MessageList ml = MessageList.builder().id("ml-id").build();
    Query q = validQueryBuilderWith(ml).query(ElasticsearchQueryString.of("nacken")).build();
    Search s = searchWithQueries(q);
    ExportMessagesCommand command = buildFrom(s, ml.id());
    assertThat(command.queryString()).isEqualTo(q.query());
}
Also used : Query(org.graylog.plugins.views.search.Query) Search(org.graylog.plugins.views.search.Search) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) Test(org.junit.jupiter.api.Test)

Example 13 with MessageList

use of org.graylog.plugins.views.search.searchtypes.MessageList in project graylog2-server by Graylog2.

the class CommandFactory method buildWithMessageList.

public ExportMessagesCommand buildWithMessageList(Search search, String messageListId, ResultFormat resultFormat) {
    Query query = search.queryForSearchType(messageListId);
    SearchType searchType = searchTypeFrom(query, messageListId);
    final List<Decorator> decorators = searchType instanceof MessageList ? ((MessageList) searchType).decorators() : Collections.emptyList();
    ExportMessagesCommand.Builder commandBuilder = builderFrom(resultFormat).timeRange(resultFormat.timerange().orElse(toAbsolute(timeRangeFrom(query, searchType)))).queryString(queryStringFrom(search, query, searchType)).streams(streamsFrom(query, searchType)).decorators(decorators);
    return commandBuilder.build();
}
Also used : Decorator(org.graylog2.decorators.Decorator) Query(org.graylog.plugins.views.search.Query) SearchType(org.graylog.plugins.views.search.SearchType) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList)

Example 14 with MessageList

use of org.graylog.plugins.views.search.searchtypes.MessageList in project graylog2-server by Graylog2.

the class QueryTest method mergeWithExecutionState.

@Test
public void mergeWithExecutionState() throws Exception {
    final String messageListId = UUID.randomUUID().toString();
    Query query = Query.builder().id("abc123").timerange(RelativeRange.create(600)).query(ElasticsearchQueryString.of("*")).searchTypes(ImmutableSet.of(MessageList.builder().id(messageListId).build())).build();
    ExecutionStateGlobalOverride.Builder executionState = ExecutionStateGlobalOverride.builder();
    executionState.timerange(RelativeRange.create(60));
    executionState.searchTypesBuilder().put(messageListId, SearchTypeExecutionState.builder().offset(150).limit(300).build());
    final Query mergedQuery = query.applyExecutionState(executionState.build());
    assertThat(mergedQuery).isNotEqualTo(query).extracting(Query::timerange).extracting("range").containsExactly(60);
    final Optional<SearchType> messageList = mergedQuery.searchTypes().stream().filter(searchType -> messageListId.equals(searchType.id())).findFirst();
    assertThat(messageList).isPresent();
    final MessageList msgList = (MessageList) messageList.get();
    assertThat(msgList).extracting(MessageList::offset).containsExactly(150);
    assertThat(msgList).extracting(MessageList::limit).containsExactly(300);
}
Also used : BackendQuery(org.graylog.plugins.views.search.engine.BackendQuery) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) SizeSerializer(org.graylog2.shared.jackson.SizeSerializer) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) StreamFilter(org.graylog.plugins.views.search.filter.StreamFilter) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) ObjectIdSerializer(org.graylog2.database.ObjectIdSerializer) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Before(org.junit.Before) Period(org.joda.time.Period) PropertyNamingStrategy(com.fasterxml.jackson.databind.PropertyNamingStrategy) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JodaTimePeriodKeyDeserializer(org.graylog2.jackson.JodaTimePeriodKeyDeserializer) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) UUID(java.util.UUID) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) TimeUnit(java.util.concurrent.TimeUnit) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) RangeJsonSerializer(org.graylog2.shared.rest.RangeJsonSerializer) ExecutionStateGlobalOverride(org.graylog.plugins.views.search.rest.ExecutionStateGlobalOverride) SearchTypeExecutionState(org.graylog.plugins.views.search.rest.SearchTypeExecutionState) Optional(java.util.Optional) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) MetricsModule(com.codahale.metrics.json.MetricsModule) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) Mockito.mock(org.mockito.Mockito.mock) BackendQuery(org.graylog.plugins.views.search.engine.BackendQuery) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) ExecutionStateGlobalOverride(org.graylog.plugins.views.search.rest.ExecutionStateGlobalOverride) Test(org.junit.Test)

Example 15 with MessageList

use of org.graylog.plugins.views.search.searchtypes.MessageList in project graylog2-server by Graylog2.

the class CommandFactoryTest method takesDecoratorsFromMessageList.

@Test
void takesDecoratorsFromMessageList() {
    Decorator decorator = mock(Decorator.class);
    MessageList ml = MessageList.builder().id("ml-id").decorators(newArrayList(decorator)).build();
    Query q = validQueryBuilderWith(ml).build();
    Search s = searchWithQueries(q);
    ExportMessagesCommand command = buildFrom(s, ml.id());
    assertThat(command.decorators()).containsExactly(decorator);
}
Also used : Decorator(org.graylog2.decorators.Decorator) Query(org.graylog.plugins.views.search.Query) Search(org.graylog.plugins.views.search.Search) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) Test(org.junit.jupiter.api.Test)

Aggregations

MessageList (org.graylog.plugins.views.search.searchtypes.MessageList)27 Query (org.graylog.plugins.views.search.Query)15 Test (org.junit.Test)13 Search (org.graylog.plugins.views.search.Search)10 Test (org.junit.jupiter.api.Test)10 DocumentContext (com.jayway.jsonpath.DocumentContext)6 ESGeneratedQueryContext (org.graylog.storage.elasticsearch6.views.ESGeneratedQueryContext)6 ESGeneratedQueryContext (org.graylog.storage.elasticsearch7.views.ESGeneratedQueryContext)6 SearchType (org.graylog.plugins.views.search.SearchType)5 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)4 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)4 Optional (java.util.Optional)3 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)2 Named (com.google.inject.name.Named)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2