use of org.graylog2.plugin.decorators.SearchResponseDecorator in project graylog2-server by Graylog2.
the class DecoratorProcessorImpl method decorate.
@Override
public SearchResponse decorate(SearchResponse searchResponse, Optional<String> streamId) {
try {
final List<SearchResponseDecorator> searchResponseDecorators = streamId.isPresent() ? decoratorResolver.searchResponseDecoratorsForStream(streamId.get()) : decoratorResolver.searchResponseDecoratorsForGlobal();
final Optional<SearchResponseDecorator> metaDecorator = searchResponseDecorators.stream().reduce((f, g) -> (v) -> g.apply(f.apply(v)));
if (metaDecorator.isPresent()) {
final Map<String, ResultMessageSummary> originalMessages = searchResponse.messages().stream().collect(Collectors.toMap(this::getMessageKey, Function.identity()));
final SearchResponse newSearchResponse = metaDecorator.get().apply(searchResponse);
final Set<String> newFields = extractFields(newSearchResponse.messages());
final List<ResultMessageSummary> decoratedMessages = newSearchResponse.messages().stream().map(resultMessage -> {
final ResultMessageSummary originalMessage = originalMessages.get(getMessageKey(resultMessage));
if (originalMessage != null) {
return resultMessage.toBuilder().decorationStats(DecorationStats.create(originalMessage.message(), resultMessage.message())).build();
}
return resultMessage;
}).collect(Collectors.toList());
return newSearchResponse.toBuilder().messages(decoratedMessages).fields(newFields).decorationStats(this.getSearchDecoratorStats(decoratedMessages)).build();
}
} catch (Exception e) {
LOG.error("Error decorating search response", e);
}
return searchResponse;
}
Aggregations