Search in sources :

Example 1 with ListGroups

use of com.google.gerrit.server.restapi.group.ListGroups in project gerrit by GerritCodeReview.

the class GroupsImpl method list.

private SortedMap<String, GroupInfo> list(ListRequest req) throws RestApiException {
    TopLevelResource tlr = TopLevelResource.INSTANCE;
    ListGroups list = listGroups.get();
    list.setOptions(req.getOptions());
    for (String project : req.getProjects()) {
        try {
            ProjectResource rsrc = projects.parse(tlr, IdString.fromDecoded(project));
            list.addProject(rsrc.getProjectState());
        } catch (Exception e) {
            throw asRestApiException("Error looking up project " + project, e);
        }
    }
    for (String group : req.getGroups()) {
        list.addGroup(groupResolver.parse(group).getGroupUUID());
    }
    list.setVisibleToAll(req.getVisibleToAll());
    if (req.getOwnedBy() != null) {
        list.setOwnedBy(req.getOwnedBy());
    }
    if (req.getUser() != null) {
        try {
            list.setUser(accountResolver.resolve(req.getUser()).asUnique().account().id());
        } catch (Exception e) {
            throw asRestApiException("Error looking up user " + req.getUser(), e);
        }
    }
    list.setOwned(req.getOwned());
    list.setLimit(req.getLimit());
    list.setStart(req.getStart());
    list.setMatchSubstring(req.getSubstring());
    list.setMatchRegex(req.getRegex());
    list.setSuggest(req.getSuggest());
    try {
        return list.apply(tlr).value();
    } catch (Exception e) {
        throw asRestApiException("Cannot list groups", e);
    }
}
Also used : TopLevelResource(com.google.gerrit.extensions.restapi.TopLevelResource) ListGroups(com.google.gerrit.server.restapi.group.ListGroups) ProjectResource(com.google.gerrit.server.project.ProjectResource) IdString(com.google.gerrit.extensions.restapi.IdString) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Aggregations

BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 IdString (com.google.gerrit.extensions.restapi.IdString)1 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)1 TopLevelResource (com.google.gerrit.extensions.restapi.TopLevelResource)1 ApiUtil.asRestApiException (com.google.gerrit.server.api.ApiUtil.asRestApiException)1 ProjectResource (com.google.gerrit.server.project.ProjectResource)1 ListGroups (com.google.gerrit.server.restapi.group.ListGroups)1