Search in sources :

Example 36 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class ListGroups method getAllGroups.

private List<GroupInfo> getAllGroups() throws OrmException {
    List<GroupInfo> groupInfos;
    List<AccountGroup> groupList;
    if (!projects.isEmpty()) {
        Map<AccountGroup.UUID, AccountGroup> groups = new HashMap<>();
        for (final ProjectControl projectControl : projects) {
            final Set<GroupReference> groupsRefs = projectControl.getAllGroups();
            for (final GroupReference groupRef : groupsRefs) {
                final AccountGroup group = groupCache.get(groupRef.getUUID());
                if (group != null) {
                    groups.put(group.getGroupUUID(), group);
                }
            }
        }
        groupList = filterGroups(groups.values());
    } else {
        groupList = filterGroups(groupCache.all());
    }
    groupInfos = Lists.newArrayListWithCapacity(groupList.size());
    int found = 0;
    int foundIndex = 0;
    for (AccountGroup group : groupList) {
        if (foundIndex++ < start) {
            continue;
        }
        if (limit > 0 && ++found > limit) {
            break;
        }
        groupInfos.add(json.addOptions(options).format(GroupDescriptions.forAccountGroup(group)));
    }
    return groupInfos;
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) HashMap(java.util.HashMap) GroupReference(com.google.gerrit.common.data.GroupReference) ProjectControl(com.google.gerrit.server.project.ProjectControl)

Example 37 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class ListGroups method suggestGroups.

private List<GroupInfo> suggestGroups() throws OrmException, BadRequestException {
    if (conflictingSuggestParameters()) {
        throw new BadRequestException("You should only have no more than one --project and -n with --suggest");
    }
    List<GroupReference> groupRefs = Lists.newArrayList(Iterables.limit(groupBackend.suggest(suggest, Iterables.getFirst(projects, null)), limit <= 0 ? 10 : Math.min(limit, 10)));
    List<GroupInfo> groupInfos = Lists.newArrayListWithCapacity(groupRefs.size());
    for (final GroupReference ref : groupRefs) {
        GroupDescription.Basic desc = groupBackend.get(ref.getUUID());
        if (desc != null) {
            groupInfos.add(json.addOptions(options).format(desc));
        }
    }
    return groupInfos;
}
Also used : GroupDescription(com.google.gerrit.common.data.GroupDescription) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) GroupReference(com.google.gerrit.common.data.GroupReference)

Example 38 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class CreateGroupCommand method createGroup.

private GroupResource createGroup() throws RestApiException, OrmException, IOException {
    GroupInput input = new GroupInput();
    input.description = groupDescription;
    input.visibleToAll = visibleToAll;
    if (ownerGroupId != null) {
        input.ownerId = String.valueOf(ownerGroupId.get());
    }
    GroupInfo group = createGroupFactory.create(groupName).apply(TopLevelResource.INSTANCE, input);
    return groups.parse(TopLevelResource.INSTANCE, IdString.fromUrl(group.id));
}
Also used : GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) GroupInfo(com.google.gerrit.extensions.common.GroupInfo)

Aggregations

GroupInfo (com.google.gerrit.extensions.common.GroupInfo)38 Test (org.junit.Test)20 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)11 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 GroupAssert.assertGroupInfo (com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo)8 GroupDescription (com.google.gerrit.common.data.GroupDescription)5 ArrayList (java.util.ArrayList)5 GroupReference (com.google.gerrit.common.data.GroupReference)4 GroupInput (com.google.gerrit.extensions.api.groups.GroupInput)4 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)4 TestAccount (com.google.gerrit.acceptance.TestAccount)3 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)3 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)3 GroupControl (com.google.gerrit.server.account.GroupControl)3 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 Account (com.google.gerrit.reviewdb.client.Account)2 AccountGroupById (com.google.gerrit.reviewdb.client.AccountGroupById)2 Project (com.google.gerrit.reviewdb.client.Project)2 Message (com.google.gerrit.testutil.FakeEmailSender.Message)2