Search in sources :

Example 1 with GroupDetail

use of com.google.gerrit.common.data.GroupDetail in project gerrit by GerritCodeReview.

the class GroupMembers method getGroupMembers.

private Set<Account> getGroupMembers(final AccountGroup group, final Project.NameKey project, final Set<AccountGroup.UUID> seen) throws NoSuchGroupException, OrmException, NoSuchProjectException, IOException {
    seen.add(group.getGroupUUID());
    final GroupDetail groupDetail = groupDetailFactory.create(group.getId()).call();
    final Set<Account> members = new HashSet<>();
    if (groupDetail.members != null) {
        for (final AccountGroupMember member : groupDetail.members) {
            members.add(accountCache.get(member.getAccountId()).getAccount());
        }
    }
    if (groupDetail.includes != null) {
        for (final AccountGroupById groupInclude : groupDetail.includes) {
            final AccountGroup includedGroup = groupCache.get(groupInclude.getIncludeUUID());
            if (includedGroup != null && !seen.contains(includedGroup.getGroupUUID())) {
                members.addAll(listAccounts(includedGroup.getGroupUUID(), project, seen));
            }
        }
    }
    return members;
}
Also used : GroupDetail(com.google.gerrit.common.data.GroupDetail) Account(com.google.gerrit.reviewdb.client.Account) AccountGroupMember(com.google.gerrit.reviewdb.client.AccountGroupMember) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) AccountGroupById(com.google.gerrit.reviewdb.client.AccountGroupById) HashSet(java.util.HashSet)

Example 2 with GroupDetail

use of com.google.gerrit.common.data.GroupDetail in project gerrit by GerritCodeReview.

the class ListMembers method getMembers.

private Map<Account.Id, AccountInfo> getMembers(final AccountGroup.UUID groupUUID, final HashSet<AccountGroup.UUID> seenGroups) throws OrmException {
    seenGroups.add(groupUUID);
    final Map<Account.Id, AccountInfo> members = new HashMap<>();
    final AccountGroup group = groupCache.get(groupUUID);
    if (group == null) {
        // the included group is an external group and can't be resolved
        return Collections.emptyMap();
    }
    final GroupDetail groupDetail;
    try {
        groupDetail = groupDetailFactory.create(group.getId()).call();
    } catch (NoSuchGroupException e) {
        // the included group is not visible
        return Collections.emptyMap();
    }
    if (groupDetail.members != null) {
        for (final AccountGroupMember m : groupDetail.members) {
            if (!members.containsKey(m.getAccountId())) {
                members.put(m.getAccountId(), accountLoader.get(m.getAccountId()));
            }
        }
    }
    if (recursive) {
        if (groupDetail.includes != null) {
            for (final AccountGroupById includedGroup : groupDetail.includes) {
                if (!seenGroups.contains(includedGroup.getIncludeUUID())) {
                    members.putAll(getMembers(includedGroup.getIncludeUUID(), seenGroups));
                }
            }
        }
    }
    accountLoader.fill();
    return members;
}
Also used : GroupDetail(com.google.gerrit.common.data.GroupDetail) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) AccountGroupMember(com.google.gerrit.reviewdb.client.AccountGroupMember) HashMap(java.util.HashMap) AccountGroupById(com.google.gerrit.reviewdb.client.AccountGroupById) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException) AccountGroupById(com.google.gerrit.reviewdb.client.AccountGroupById)

Example 3 with GroupDetail

use of com.google.gerrit.common.data.GroupDetail in project gerrit by GerritCodeReview.

the class GroupDetailFactory method call.

@Override
public GroupDetail call() throws OrmException, NoSuchGroupException {
    control = groupControl.validateFor(groupId);
    AccountGroup group = groupCache.get(groupId);
    GroupDetail detail = new GroupDetail();
    detail.setGroup(group);
    detail.setMembers(loadMembers());
    detail.setIncludes(loadIncludes());
    return detail;
}
Also used : GroupDetail(com.google.gerrit.common.data.GroupDetail) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup)

Aggregations

GroupDetail (com.google.gerrit.common.data.GroupDetail)3 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)3 AccountGroupById (com.google.gerrit.reviewdb.client.AccountGroupById)2 AccountGroupMember (com.google.gerrit.reviewdb.client.AccountGroupMember)2 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)1 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)1 Account (com.google.gerrit.reviewdb.client.Account)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1