use of org.graylog2.rest.resources.streams.responses.StreamPageListResponse in project graylog2-server by Graylog2.
the class StreamResource method getPage.
@GET
@Timed
@Path("/paginated")
@ApiOperation(value = "Get a paginated list of streams")
@Produces(MediaType.APPLICATION_JSON)
public StreamPageListResponse getPage(@ApiParam(name = "page") @QueryParam("page") @DefaultValue("1") int page, @ApiParam(name = "per_page") @QueryParam("per_page") @DefaultValue("50") int perPage, @ApiParam(name = "query") @QueryParam("query") @DefaultValue("") String query, @ApiParam(name = "sort", value = "The field to sort the result on", required = true, allowableValues = "title,description") @DefaultValue(StreamImpl.FIELD_TITLE) @QueryParam("sort") String sort, @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") @DefaultValue("asc") @QueryParam("order") String order) {
SearchQuery searchQuery;
try {
searchQuery = searchQueryParser.parse(query);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Invalid argument in search query: " + e.getMessage());
}
final Predicate<StreamDTO> permissionFilter = streamDTO -> isPermitted(RestPermissions.STREAMS_READ, streamDTO.id());
final PaginatedList<StreamDTO> result = paginatedStreamService.findPaginated(searchQuery, permissionFilter, page, perPage, sort, order);
final List<String> streamIds = result.stream().map(streamDTO -> streamDTO.id()).collect(Collectors.toList());
final Map<String, List<StreamRule>> streamRuleMap = streamRuleService.loadForStreamIds(streamIds);
final List<StreamDTO> streams = result.stream().map(streamDTO -> {
List<StreamRule> rules = streamRuleMap.getOrDefault(streamDTO.id(), Collections.emptyList());
return streamDTO.toBuilder().rules(rules).build();
}).collect(Collectors.toList());
final long total = paginatedStreamService.count();
final PaginatedList<StreamDTO> streamDTOS = new PaginatedList<>(streams, result.pagination().total(), result.pagination().page(), result.pagination().perPage());
return StreamPageListResponse.create(query, streamDTOS.pagination(), total, sort, order, streams);
}
Aggregations