Search in sources :

Example 1 with GroupQueryProcessor

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());
    }
}
Also used : InternalGroupDescription(com.google.gerrit.server.group.InternalGroupDescription) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) GroupQueryProcessor(com.google.gerrit.server.query.group.GroupQueryProcessor) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) InternalGroup(com.google.gerrit.entities.InternalGroup) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Aggregations

InternalGroup (com.google.gerrit.entities.InternalGroup)1 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)1 QueryParseException (com.google.gerrit.index.query.QueryParseException)1 InternalGroupDescription (com.google.gerrit.server.group.InternalGroupDescription)1 GroupQueryProcessor (com.google.gerrit.server.query.group.GroupQueryProcessor)1