Search in sources :

Example 11 with AccountGroupMember

use of com.google.gerrit.reviewdb.client.AccountGroupMember in project gerrit by GerritCodeReview.

the class AddMembers method addMembers.

public void addMembers(AccountGroup.Id groupId, Collection<? extends Account.Id> newMemberIds) throws OrmException, IOException {
    Map<Account.Id, AccountGroupMember> newAccountGroupMembers = new HashMap<>();
    for (Account.Id accId : newMemberIds) {
        if (!newAccountGroupMembers.containsKey(accId)) {
            AccountGroupMember.Key key = new AccountGroupMember.Key(accId, groupId);
            AccountGroupMember m = db.get().accountGroupMembers().get(key);
            if (m == null) {
                m = new AccountGroupMember(key);
                newAccountGroupMembers.put(m.getAccountId(), m);
            }
        }
    }
    if (!newAccountGroupMembers.isEmpty()) {
        auditService.dispatchAddAccountsToGroup(self.get().getAccountId(), newAccountGroupMembers.values());
        db.get().accountGroupMembers().insert(newAccountGroupMembers.values());
        for (AccountGroupMember m : newAccountGroupMembers.values()) {
            accountCache.evict(m.getAccountId());
        }
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) AccountGroupMember(com.google.gerrit.reviewdb.client.AccountGroupMember) HashMap(java.util.HashMap)

Example 12 with AccountGroupMember

use of com.google.gerrit.reviewdb.client.AccountGroupMember 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)

Aggregations

AccountGroupMember (com.google.gerrit.reviewdb.client.AccountGroupMember)12 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)9 Account (com.google.gerrit.reviewdb.client.Account)8 ArrayList (java.util.ArrayList)8 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)5 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)4 OrmException (com.google.gwtorm.server.OrmException)3 GroupDetail (com.google.gerrit.common.data.GroupDetail)2 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)2 AccountGroupById (com.google.gerrit.reviewdb.client.AccountGroupById)2 AccountGroupMemberAudit (com.google.gerrit.reviewdb.client.AccountGroupMemberAudit)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 GroupDescription (com.google.gerrit.common.data.GroupDescription)1 Permission (com.google.gerrit.common.data.Permission)1 InvalidSshKeyException (com.google.gerrit.common.errors.InvalidSshKeyException)1 NameAlreadyUsedException (com.google.gerrit.common.errors.NameAlreadyUsedException)1 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)1 AccountInput (com.google.gerrit.extensions.api.accounts.AccountInput)1 AuthType (com.google.gerrit.extensions.client.AuthType)1