Search in sources :

Example 11 with NoSuchGroupException

use of com.google.gerrit.common.errors.NoSuchGroupException 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 12 with NoSuchGroupException

use of com.google.gerrit.common.errors.NoSuchGroupException in project gerrit by GerritCodeReview.

the class GetGroups method apply.

@Override
public List<GroupInfo> apply(AccountResource resource) throws OrmException {
    IdentifiedUser user = resource.getUser();
    Account.Id userId = user.getAccountId();
    List<GroupInfo> groups = new ArrayList<>();
    for (AccountGroup.UUID uuid : user.getEffectiveGroups().getKnownGroups()) {
        GroupControl ctl;
        try {
            ctl = groupControlFactory.controlFor(uuid);
        } catch (NoSuchGroupException e) {
            continue;
        }
        if (ctl.isVisible() && ctl.canSeeMember(userId)) {
            groups.add(json.format(ctl.getGroup()));
        }
    }
    return groups;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ArrayList(java.util.ArrayList) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException)

Aggregations

NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)12 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 GroupReference (com.google.gerrit.common.data.GroupReference)3 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)3 Account (com.google.gerrit.reviewdb.client.Account)3 GroupControl (com.google.gerrit.server.account.GroupControl)3 AccessSection (com.google.gerrit.common.data.AccessSection)2 GroupDescription (com.google.gerrit.common.data.GroupDescription)2 Permission (com.google.gerrit.common.data.Permission)2 PermissionRule (com.google.gerrit.common.data.PermissionRule)2 AccountGroupById (com.google.gerrit.reviewdb.client.AccountGroupById)2 Project (com.google.gerrit.reviewdb.client.Project)2 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)2 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)2 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)2 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)2 NoSuchProjectException (com.google.gerrit.server.project.NoSuchProjectException)2 HashSet (java.util.HashSet)2