use of org.graylog2.database.PaginatedList in project graylog2-server by Graylog2.
the class SidecarResource method sidecars.
@GET
@Timed
@ApiOperation(value = "Lists existing Sidecar registrations using pagination")
@RequiresPermissions(SidecarRestPermissions.SIDECARS_READ)
public SidecarListResponse sidecars(@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,name,id") @DefaultValue(Sidecar.FIELD_NODE_NAME) @QueryParam("sort") String sort, @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") @DefaultValue("asc") @QueryParam("order") String order, @ApiParam(name = "only_active") @QueryParam("only_active") @DefaultValue("false") boolean onlyActive) {
final String mappedQuery = sidecarStatusMapper.replaceStringStatusSearchQuery(query);
SearchQuery searchQuery;
try {
searchQuery = searchQueryParser.parse(mappedQuery);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Invalid argument in search query: " + e.getMessage());
}
final PaginatedList<Sidecar> sidecars = onlyActive ? sidecarService.findPaginated(searchQuery, activeSidecarFilter, page, perPage, sort, order) : sidecarService.findPaginated(searchQuery, page, perPage, sort, order);
final List<SidecarSummary> collectorSummaries = sidecarService.toSummaryList(sidecars, activeSidecarFilter);
final long total = sidecarService.count();
return SidecarListResponse.create(query, sidecars.pagination(), total, onlyActive, sort, order, collectorSummaries);
}
use of org.graylog2.database.PaginatedList in project graylog2-server by Graylog2.
the class AdministrationResource method administration.
@POST
@Timed
@ApiOperation(value = "Lists existing Sidecar registrations including compatible sidecars using pagination")
@RequiresPermissions({ SidecarRestPermissions.SIDECARS_READ, SidecarRestPermissions.COLLECTORS_READ, SidecarRestPermissions.CONFIGURATIONS_READ })
@NoAuditEvent("this is not changing any data")
public SidecarListResponse administration(@ApiParam(name = "JSON body", required = true) @Valid @NotNull AdministrationRequest request) {
final String sort = Sidecar.FIELD_NODE_NAME;
final String order = "asc";
final String mappedQuery = sidecarStatusMapper.replaceStringStatusSearchQuery(request.query());
SearchQuery searchQuery;
try {
searchQuery = searchQueryParser.parse(mappedQuery);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Invalid argument in search query: " + e.getMessage());
}
final long total = sidecarService.count();
final Optional<Predicate<Sidecar>> filters = administrationFiltersFactory.getFilters(request.filters());
final List<Collector> collectors = getCollectors(request.filters());
final PaginatedList<Sidecar> sidecars = sidecarService.findPaginated(searchQuery, filters.orElse(null), request.page(), request.perPage(), sort, order);
final List<SidecarSummary> sidecarSummaries = sidecarService.toSummaryList(sidecars, activeSidecarFilter);
final List<SidecarSummary> summariesWithCollectors = sidecarSummaries.stream().map(collector -> {
final List<String> compatibleCollectors = collectors.stream().filter(c -> c.nodeOperatingSystem().equalsIgnoreCase(collector.nodeDetails().operatingSystem())).map(Collector::id).collect(Collectors.toList());
return collector.toBuilder().collectors(compatibleCollectors).build();
}).filter(collectorSummary -> !filters.isPresent() || collectorSummary.collectors().size() > 0).collect(Collectors.toList());
return SidecarListResponse.create(request.query(), sidecars.pagination(), total, false, sort, order, summariesWithCollectors, request.filters());
}
use of org.graylog2.database.PaginatedList in project graylog2-server by Graylog2.
the class EventDefinitionsResource method list.
@GET
@ApiOperation("List event definitions")
public PaginatedResponse<EventDefinitionDto> list(@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) {
final SearchQuery searchQuery = searchQueryParser.parse(query);
final PaginatedList<EventDefinitionDto> result = dbService.searchPaginated(searchQuery, event -> {
return isPermitted(RestPermissions.EVENT_DEFINITIONS_READ, event.id());
}, "title", page, perPage);
final ImmutableMap<String, Object> context = contextService.contextFor(result.delegate());
return PaginatedResponse.create("event_definitions", result, query, context);
}
use of org.graylog2.database.PaginatedList in project graylog2-server by Graylog2.
the class RuleResource method getPage.
@GET
@Path("/paginated")
@ApiOperation(value = "Get a paginated list of pipeline rules")
@Produces(MediaType.APPLICATION_JSON)
@RequiresPermissions(PipelineRestPermissions.PIPELINE_RULE_READ)
public PaginatedResponse<RuleSource> 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,id") @DefaultValue(RuleDao.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 PaginatedList<RuleDao> result = paginatedRuleService.findPaginated(searchQuery, page, perPage, sort, order);
final List<RuleSource> ruleSourceList = result.stream().map(dao -> RuleSource.fromDao(pipelineRuleParser, dao)).collect(Collectors.toList());
final PaginatedList<RuleSource> rules = new PaginatedList<>(ruleSourceList, result.pagination().total(), result.pagination().page(), result.pagination().perPage());
return PaginatedResponse.create("rules", rules, prepareContextForPaginatedResponse(result.delegate()));
}
use of org.graylog2.database.PaginatedList in project graylog2-server by Graylog2.
the class PipelineResource method getPage.
@GET
@Path("/paginated")
@ApiOperation(value = "Get a paginated list of pipelines")
@Produces(MediaType.APPLICATION_JSON)
public PaginatedResponse<PipelineSource> 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,id") @DefaultValue(PipelineDao.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());
}
Predicate<PipelineDao> filter = dao -> isPermitted(PipelineRestPermissions.PIPELINE_READ, dao.id());
final PaginatedList<PipelineDao> result = paginatedPipelineService.findPaginated(searchQuery, filter, page, perPage, sort, order);
final List<PipelineSource> pipelineList = result.stream().map(dao -> PipelineSource.fromDao(pipelineRuleParser, dao)).collect(Collectors.toList());
final PaginatedList<PipelineSource> pipelines = new PaginatedList<>(pipelineList, result.pagination().total(), result.pagination().page(), result.pagination().perPage());
return PaginatedResponse.create("pipelines", pipelines);
}
Aggregations