use of io.swagger.annotations.ApiParam 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);
}
use of io.swagger.annotations.ApiParam in project graylog2-server by Graylog2.
the class AuthzRolesResource method getUsersForRole.
@GET
@ApiOperation(value = "Get a paginated list of users for a role")
@Path("/{roleId}/assignees")
@Produces(MediaType.APPLICATION_JSON)
@RequiresPermissions(RestPermissions.USERS_LIST)
public PaginatedResponse<UserOverviewDTO> getUsersForRole(@ApiParam(name = "roleId") @PathParam("roleId") @NotEmpty String roleId, @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(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 = userSearchQueryParser.parse(query);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Invalid argument in search query: " + e.getMessage());
}
final PaginatedList<UserOverviewDTO> result = paginatedUserService.findPaginatedByRole(searchQuery, page, perPage, sort, order, ImmutableSet.of(roleId));
final Set<String> roleIds = result.stream().flatMap(u -> u.roles().stream()).collect(Collectors.toSet());
final Map<String, String> rolesMap = authzRolesService.findPaginatedByIds(new SearchQuery(""), 0, 0, AuthzRoleDTO.FIELD_NAME, "asc", roleIds).stream().collect(Collectors.toMap(AuthzRoleDTO::id, AuthzRoleDTO::name));
final List<UserOverviewDTO> users = result.stream().map(u -> {
final Set<String> roleNames = u.roles().stream().map(rolesMap::get).collect(Collectors.toSet());
return u.toBuilder().roles(roleNames).build();
}).collect(Collectors.toList());
final PaginatedList<UserOverviewDTO> enrichedResult = new PaginatedList<>(users, result.pagination().total(), result.pagination().page(), result.pagination().perPage());
return PaginatedResponse.create("users", enrichedResult, query);
}
use of io.swagger.annotations.ApiParam in project graylog2-server by Graylog2.
the class StreamResource method create.
@POST
@Timed
@ApiOperation(value = "Create a stream")
@RequiresPermissions(RestPermissions.STREAMS_CREATE)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.STREAM_CREATE)
public Response create(@ApiParam(name = "JSON body", required = true) final CreateStreamRequest cr, @Context UserContext userContext) throws ValidationException {
// Create stream.
final Stream stream = streamService.create(cr, getCurrentUser().getName());
stream.setDisabled(true);
final IndexSet indexSet = stream.getIndexSet();
if (!indexSet.getConfig().isWritable()) {
throw new BadRequestException("Assigned index set must be writable!");
} else if (!indexSet.getConfig().isRegularIndex()) {
throw new BadRequestException("Assigned index set is not usable");
}
final Set<StreamRule> streamRules = cr.rules().stream().map(streamRule -> streamRuleService.create(null, streamRule)).collect(Collectors.toSet());
final String id = streamService.saveWithRulesAndOwnership(stream, streamRules, userContext.getUser());
final Map<String, String> result = ImmutableMap.of("stream_id", id);
final URI streamUri = getUriBuilderToSelf().path(StreamResource.class).path("{streamId}").build(id);
return Response.created(streamUri).entity(result).build();
}
use of io.swagger.annotations.ApiParam in project graylog2-server by Graylog2.
the class IndicesResource method indexSetClosed.
@GET
@Timed
@Path("/{indexSetId}/closed")
@ApiOperation(value = "Get a list of closed indices that can be reopened.")
@Produces(MediaType.APPLICATION_JSON)
public ClosedIndices indexSetClosed(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
final Set<String> closedIndices = indices.getClosedIndices(indexSet).stream().filter(index -> isPermitted(RestPermissions.INDICES_READ, index)).collect(Collectors.toSet());
return ClosedIndices.create(closedIndices, closedIndices.size());
}
use of io.swagger.annotations.ApiParam in project graylog2-server by Graylog2.
the class IndicesResource method indexSetReopened.
@GET
@Timed
@Path("/{indexSetId}/reopened")
@ApiOperation(value = "Get a list of reopened indices, which will not be cleaned by retention cleaning")
@Produces(MediaType.APPLICATION_JSON)
public ClosedIndices indexSetReopened(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
final Set<String> reopenedIndices = indices.getReopenedIndices(indexSet).stream().filter(index -> isPermitted(RestPermissions.INDICES_READ, index)).collect(Collectors.toSet());
return ClosedIndices.create(reopenedIndices, reopenedIndices.size());
}
Aggregations