use of org.graylog2.database.PaginatedList in project graylog2-server by Graylog2.
the class DashboardsResource method views.
@GET
@ApiOperation("Get a list of all dashboards")
@Timed
public PaginatedResponse<ViewSummaryDTO> views(@ApiParam(name = "page") @QueryParam("page") @DefaultValue("1") int page, @ApiParam(name = "per_page") @QueryParam("per_page") @DefaultValue("50") int perPage, @ApiParam(name = "sort", value = "The field to sort the result on", required = true, allowableValues = "id,title,created_at") @DefaultValue(ViewDTO.FIELD_TITLE) @QueryParam("sort") String sortField, @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") @DefaultValue("asc") @QueryParam("order") String order, @ApiParam(name = "query") @QueryParam("query") String query, @Context SearchUser searchUser) {
if (!ViewDTO.SORT_FIELDS.contains(sortField.toLowerCase(ENGLISH))) {
sortField = ViewDTO.FIELD_TITLE;
}
try {
final SearchQuery searchQuery = searchQueryParser.parse(query);
final PaginatedList<ViewSummaryDTO> result = dbService.searchSummariesPaginatedByType(ViewDTO.Type.DASHBOARD, searchQuery, searchUser::canReadView, order, sortField, page, perPage);
return PaginatedResponse.create("views", result, query);
} catch (IllegalArgumentException e) {
throw new BadRequestException(e.getMessage(), e);
}
}
use of org.graylog2.database.PaginatedList in project graylog2-server by Graylog2.
the class AuthzRolesResource method getList.
@GET
@Timed
@ApiOperation(value = "Get a paginated list of all roles")
@RequiresPermissions(RestPermissions.ROLES_READ)
public PaginatedResponse<AuthzRoleDTO> getList(@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 = "name,description") @DefaultValue(AuthzRoleDTO.FIELD_NAME) @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<AuthzRoleDTO> result = authzRolesService.findPaginated(searchQuery, page, perPage, sort, order);
final Map<String, Set<Map<String, String>>> userRoleMap = userRoleContext(result);
return PaginatedResponse.create("roles", result, query, ImmutableMap.of("users", userRoleMap));
}
use of org.graylog2.database.PaginatedList in project graylog2-server by Graylog2.
the class AuthServiceBackendsResource method getUsers.
@GET
@Path("{backendId}/users")
@ApiOperation("Get paginated users for an authentication service backend")
@RequiresPermissions({ RestPermissions.AUTH_SERVICE_GLOBAL_CONFIG_READ, RestPermissions.USERS_READ })
public PaginatedResponse<UserOverviewDTO> getUsers(@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 = "username,full_name,email") @DefaultValue(UserOverviewDTO.FIELD_FULL_NAME) @QueryParam("sort") String sort, @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") @DefaultValue("asc") @QueryParam("order") String order, @ApiParam(name = "backendId", required = true) @PathParam("backendId") @NotBlank String backendId) {
final AuthServiceBackendDTO activeConfig = loadConfig(backendId);
final PaginatedList<UserOverviewDTO> userList = userService.findPaginatedByAuthServiceBackend(parseSearchQuery(query), page, perPage, sort, order, activeConfig.id());
return PaginatedResponse.create("users", userList, query, Collections.singletonMap("roles", createRoleContext(userList.delegate())));
}
use of org.graylog2.database.PaginatedList 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);
}
use of org.graylog2.database.PaginatedList in project graylog2-server by Graylog2.
the class GrokResource method getPage.
@GET
@Timed
@Path("/paginated")
@ApiOperation("Get existing grok patterns paged")
@Produces(MediaType.APPLICATION_JSON)
public PaginatedResponse<GrokPattern> 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(GrokPattern.FIELD_NAME) @QueryParam("sort") String sort, @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") @DefaultValue("asc") @QueryParam("order") String order) {
checkPermission(RestPermissions.INPUTS_READ);
SearchQuery searchQuery;
try {
searchQuery = searchQueryParser.parse(query);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Invalid argument in search query: " + e.getMessage());
}
final PaginatedList<GrokPattern> result = paginatedGrokPatternService.findPaginated(searchQuery, page, perPage, sort, order);
return PaginatedResponse.create("patterns", result);
}
Aggregations