use of com.google.gerrit.server.query.group.GroupQueryProcessor in project gerrit by GerritCodeReview.
the class QueryGroups method apply.
@Override
public Response<List<GroupInfo>> apply(TopLevelResource resource) throws BadRequestException, MethodNotAllowedException, PermissionBackendException {
if (Strings.isNullOrEmpty(query)) {
throw new BadRequestException("missing query field");
}
GroupQueryProcessor queryProcessor = queryProcessorProvider.get();
if (queryProcessor.isDisabled()) {
throw new MethodNotAllowedException("query disabled");
}
if (start != 0) {
queryProcessor.setStart(start);
}
if (limit != 0) {
queryProcessor.setUserProvidedLimit(limit);
}
try {
QueryResult<InternalGroup> result = queryProcessor.query(queryBuilder.parse(query));
List<InternalGroup> groups = result.entities();
ArrayList<GroupInfo> groupInfos = Lists.newArrayListWithCapacity(groups.size());
json.addOptions(options);
for (InternalGroup group : groups) {
groupInfos.add(json.format(new InternalGroupDescription(group)));
}
if (!groupInfos.isEmpty() && result.more()) {
groupInfos.get(groupInfos.size() - 1)._moreGroups = true;
}
return Response.ok(groupInfos);
} catch (QueryParseException e) {
throw new BadRequestException(e.getMessage());
}
}
Aggregations