Search in sources :

Example 1 with ExecutionStateGlobalOverride

use of org.graylog.plugins.views.search.rest.ExecutionStateGlobalOverride in project graylog2-server by Graylog2.

the class QueryTest method appliesExecutionStateQueryToGlobalOverride.

@Test
public void appliesExecutionStateQueryToGlobalOverride() {
    final ExecutionStateGlobalOverride executionState = ExecutionStateGlobalOverride.builder().query(ElasticsearchQueryString.of("NACKEN")).build();
    Query sut = validQueryBuilder().build();
    Query query = sut.applyExecutionState(executionState);
    assertThat(query.globalOverride()).hasValueSatisfying(go -> assertThat(go.query()).contains(ElasticsearchQueryString.of("NACKEN")));
}
Also used : BackendQuery(org.graylog.plugins.views.search.engine.BackendQuery) ExecutionStateGlobalOverride(org.graylog.plugins.views.search.rest.ExecutionStateGlobalOverride) Test(org.junit.Test)

Example 2 with ExecutionStateGlobalOverride

use of org.graylog.plugins.views.search.rest.ExecutionStateGlobalOverride in project graylog2-server by Graylog2.

the class Query method applyExecutionState.

Query applyExecutionState(ExecutionStateGlobalOverride state) {
    if (state == null || !state.hasValues()) {
        return this;
    }
    if (state.timerange().isPresent() || state.query().isPresent() || !state.searchTypes().isEmpty() || !state.keepSearchTypes().isEmpty()) {
        final Builder builder = toBuilder();
        if (state.timerange().isPresent() || state.query().isPresent()) {
            final GlobalOverride.Builder globalOverrideBuilder = globalOverride().map(GlobalOverride::toBuilder).orElseGet(GlobalOverride::builder);
            state.timerange().ifPresent(timeRange -> {
                globalOverrideBuilder.timerange(timeRange);
                builder.timerange(timeRange);
            });
            state.query().ifPresent(query -> {
                globalOverrideBuilder.query(query);
                builder.query(query);
            });
            builder.globalOverride(globalOverrideBuilder.build());
        }
        if (!state.searchTypes().isEmpty() || !state.keepSearchTypes().isEmpty()) {
            final Set<SearchType> searchTypesToKeep = !state.keepSearchTypes().isEmpty() ? filterForWhiteListFromState(searchTypes(), state) : searchTypes();
            final Set<SearchType> searchTypesWithOverrides = applyAvailableOverrides(state, searchTypesToKeep);
            builder.searchTypes(ImmutableSet.copyOf(searchTypesWithOverrides));
        }
        return builder.build();
    }
    return this;
}
Also used : JsonPOJOBuilder(com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder) ExecutionStateGlobalOverride(org.graylog.plugins.views.search.rest.ExecutionStateGlobalOverride)

Example 3 with ExecutionStateGlobalOverride

use of org.graylog.plugins.views.search.rest.ExecutionStateGlobalOverride in project graylog2-server by Graylog2.

the class QueryTest method appliesExecutionStateTimeRangeToGlobalOverride.

@Test
public void appliesExecutionStateTimeRangeToGlobalOverride() throws InvalidRangeParametersException {
    final ExecutionStateGlobalOverride executionState = ExecutionStateGlobalOverride.builder().timerange(RelativeRange.create(60)).build();
    Query sut = validQueryBuilder().build();
    Query query = sut.applyExecutionState(executionState);
    assertThat(query.globalOverride()).hasValueSatisfying(go -> assertThat(go.timerange()).contains(relativeRange(60)));
}
Also used : BackendQuery(org.graylog.plugins.views.search.engine.BackendQuery) ExecutionStateGlobalOverride(org.graylog.plugins.views.search.rest.ExecutionStateGlobalOverride) Test(org.junit.Test)

Example 4 with ExecutionStateGlobalOverride

use of org.graylog.plugins.views.search.rest.ExecutionStateGlobalOverride in project graylog2-server by Graylog2.

the class QueryTest method appliesExecutionStateTimeRangeAndQueryToGlobalOverrideIfBothArePresent.

@Test
public void appliesExecutionStateTimeRangeAndQueryToGlobalOverrideIfBothArePresent() throws InvalidRangeParametersException {
    final ExecutionStateGlobalOverride executionState = ExecutionStateGlobalOverride.builder().timerange(RelativeRange.create(60)).query(ElasticsearchQueryString.of("NACKEN")).build();
    Query sut = validQueryBuilder().build();
    Query query = sut.applyExecutionState(executionState);
    assertThat(query.globalOverride()).hasValueSatisfying(go -> {
        assertThat(go.timerange()).contains(relativeRange(60));
        assertThat(go.query()).contains(ElasticsearchQueryString.of("NACKEN"));
    });
}
Also used : BackendQuery(org.graylog.plugins.views.search.engine.BackendQuery) ExecutionStateGlobalOverride(org.graylog.plugins.views.search.rest.ExecutionStateGlobalOverride) Test(org.junit.Test)

Aggregations

ExecutionStateGlobalOverride (org.graylog.plugins.views.search.rest.ExecutionStateGlobalOverride)4 BackendQuery (org.graylog.plugins.views.search.engine.BackendQuery)3 Test (org.junit.Test)3 JsonPOJOBuilder (com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder)1