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