use of javax.ws.rs.DefaultValue 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 javax.ws.rs.DefaultValue in project graylog2-server by Graylog2.
the class UsersResource method getPage.
@GET
@Timed
@Path("/paginated")
@ApiOperation(value = "Get paginated list of users")
@RequiresPermissions(RestPermissions.USERS_LIST)
@Produces(MediaType.APPLICATION_JSON)
public PaginatedResponse<UserOverviewDTO> 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(UserOverviewDTO.FIELD_FULL_NAME) @QueryParam("sort") String sort, @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") @DefaultValue("asc") @QueryParam("order") String order) {
SearchQuery searchQuery;
final AllUserSessions sessions = AllUserSessions.create(sessionService);
try {
searchQuery = searchQueryParser.parse(query);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Invalid argument in search query: " + e.getMessage());
}
final PaginatedList<UserOverviewDTO> result = paginatedUserService.findPaginated(searchQuery, page, perPage, sort, order);
final Set<String> allRoleIds = result.stream().flatMap(userDTO -> {
if (userDTO.roles() != null) {
return userDTO.roles().stream();
}
return Stream.empty();
}).collect(Collectors.toSet());
Map<String, String> roleNameMap;
try {
roleNameMap = getRoleNameMap(allRoleIds);
} catch (org.graylog2.database.NotFoundException e) {
throw new NotFoundException("Couldn't find roles: " + e.getMessage());
}
final UserOverviewDTO adminUser = getAdminUserDTO(sessions);
List<UserOverviewDTO> users = result.stream().map(userDTO -> {
UserOverviewDTO.Builder builder = userDTO.toBuilder().fillSession(sessions.forUser(userDTO));
if (userDTO.roles() != null) {
builder.roles(userDTO.roles().stream().map(roleNameMap::get).collect(Collectors.toSet()));
}
return builder.build();
}).collect(Collectors.toList());
final PaginatedList<UserOverviewDTO> userOverviewDTOS = new PaginatedList<>(users, result.pagination().total(), result.pagination().page(), result.pagination().perPage());
return PaginatedResponse.create("users", userOverviewDTOS, query, Collections.singletonMap("admin_user", adminUser));
}
use of javax.ws.rs.DefaultValue in project raml-module-builder by folio-org.
the class AnnotationGrabber method getParameterNames.
public static JsonObject getParameterNames(Method method) throws Exception {
// need to handle default values
JsonObject retObject = new JsonObject();
Parameter[] nonAnnotationParams = method.getParameters();
Annotation[][] annotations = method.getParameterAnnotations();
Class<?>[] parameterTypes = method.getParameterTypes();
int k = 0;
for (Annotation[] annotation : annotations) {
Class<?> parameterType = parameterTypes[k++];
if (annotation.length == 0) {
// we are here because - there is a param but it is not annotated - this
// will occur for post / put
// requests - the entity to save/update will not be annotated
JsonObject obj = null;
obj = new JsonObject();
// this will be
obj.put("value", nonAnnotationParams[k - 1].getName());
// a generic
// name - unless
// debug info
// turned on for
// javac (store
// information
// about method
// parameters)
obj.put("type", parameterType.getCanonicalName());
obj.put("order", k - 1);
obj.put("param_type", NON_ANNOTATED_PARAM);
retObject.put("" + (k - 1), obj);
}
JsonObject prevObjForDefaultVal = null;
for (Annotation a : annotation) {
JsonObject obj = null;
if (a instanceof HeaderParam) {
obj = new JsonObject();
obj.put("value", ((HeaderParam) a).value());
obj.put("type", parameterType.getCanonicalName());
obj.put("order", k - 1);
obj.put("param_type", HEADER_PARAM);
} else if (a instanceof PathParam) {
obj = new JsonObject();
obj.put("value", ((PathParam) a).value());
obj.put("type", parameterType.getCanonicalName());
obj.put("order", k - 1);
obj.put("param_type", PATH_PARAM);
} else if (a instanceof QueryParam) {
obj = new JsonObject();
obj.put("value", ((QueryParam) a).value());
obj.put("type", parameterType.getCanonicalName());
obj.put("order", k - 1);
obj.put("param_type", QUERY_PARAM);
} else if (a instanceof DefaultValue && prevObjForDefaultVal != null) {
// default values originate in the raml and appear after the parameter
// they are to be applied to
String defaultValue = ((DefaultValue) a).value();
// push it into the previously scanned parameter
prevObjForDefaultVal.put("default_value", defaultValue);
prevObjForDefaultVal = null;
}
if (obj != null) {
prevObjForDefaultVal = obj;
// obj may be null in case of @DefaultValue annotation which i am
// currently ignoring
retObject.put("" + (k - 1), obj);
}
}
}
return retObject;
}
Aggregations