Search in sources :

Example 1 with AccountGroupById

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

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

the class ListIncludedGroups method apply.

@Override
public List<GroupInfo> apply(GroupResource rsrc) throws MethodNotAllowedException, OrmException {
    if (rsrc.toAccountGroup() == null) {
        throw new MethodNotAllowedException();
    }
    boolean ownerOfParent = rsrc.getControl().isOwner();
    List<GroupInfo> included = new ArrayList<>();
    for (AccountGroupById u : dbProvider.get().accountGroupById().byGroup(rsrc.toAccountGroup().getId())) {
        try {
            GroupControl i = controlFactory.controlFor(u.getIncludeUUID());
            if (ownerOfParent || i.isVisible()) {
                included.add(json.format(i.getGroup()));
            }
        } catch (NoSuchGroupException notFound) {
            log.warn(String.format("Group %s no longer available, included into %s", u.getIncludeUUID(), rsrc.getGroup().getName()));
            continue;
        }
    }
    Collections.sort(included, new Comparator<GroupInfo>() {

        @Override
        public int compare(GroupInfo a, GroupInfo b) {
            int cmp = nullToEmpty(a.name).compareTo(nullToEmpty(b.name));
            if (cmp != 0) {
                return cmp;
            }
            return nullToEmpty(a.id).compareTo(nullToEmpty(b.id));
        }
    });
    return included;
}
Also used : GroupControl(com.google.gerrit.server.account.GroupControl) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ArrayList(java.util.ArrayList) AccountGroupById(com.google.gerrit.reviewdb.client.AccountGroupById) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException)

Example 3 with AccountGroupById

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

the class DbGroupMemberAuditListener method onAddGroupsToGroup.

@Override
public void onAddGroupsToGroup(Account.Id me, Collection<AccountGroupById> added) {
    List<AccountGroupByIdAud> includesAudit = new ArrayList<>();
    for (AccountGroupById groupInclude : added) {
        AccountGroupByIdAud audit = new AccountGroupByIdAud(groupInclude, me, TimeUtil.nowTs());
        includesAudit.add(audit);
    }
    try (ReviewDb db = schema.open()) {
        db.accountGroupByIdAud().insert(includesAudit);
    } catch (OrmException e) {
        logOrmExceptionForGroups("Cannot log add groups to group event performed by user", me, added, e);
    }
}
Also used : AccountGroupByIdAud(com.google.gerrit.reviewdb.client.AccountGroupByIdAud) OrmException(com.google.gwtorm.server.OrmException) ArrayList(java.util.ArrayList) AccountGroupById(com.google.gerrit.reviewdb.client.AccountGroupById) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 4 with AccountGroupById

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

the class DbGroupMemberAuditListener method onDeleteGroupsFromGroup.

@Override
public void onDeleteGroupsFromGroup(Account.Id me, Collection<AccountGroupById> removed) {
    final List<AccountGroupByIdAud> auditUpdates = new ArrayList<>();
    try (ReviewDb db = schema.open()) {
        for (final AccountGroupById g : removed) {
            AccountGroupByIdAud audit = null;
            for (AccountGroupByIdAud a : db.accountGroupByIdAud().byGroupInclude(g.getGroupId(), g.getIncludeUUID())) {
                if (a.isActive()) {
                    audit = a;
                    break;
                }
            }
            if (audit != null) {
                audit.removed(me, TimeUtil.nowTs());
                auditUpdates.add(audit);
            }
        }
        db.accountGroupByIdAud().update(auditUpdates);
    } catch (OrmException e) {
        logOrmExceptionForGroups("Cannot log delete groups from group event performed by user", me, removed, e);
    }
}
Also used : AccountGroupByIdAud(com.google.gerrit.reviewdb.client.AccountGroupByIdAud) OrmException(com.google.gwtorm.server.OrmException) ArrayList(java.util.ArrayList) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) AccountGroupById(com.google.gerrit.reviewdb.client.AccountGroupById)

Example 5 with AccountGroupById

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

the class DbGroupMemberAuditListener method logOrmExceptionForGroups.

private void logOrmExceptionForGroups(String header, Account.Id me, Collection<AccountGroupById> values, OrmException e) {
    List<String> descriptions = new ArrayList<>();
    for (AccountGroupById m : values) {
        AccountGroup.UUID groupUuid = m.getIncludeUUID();
        String groupName = groupBackend.get(groupUuid).getName();
        AccountGroup.Id targetGroupId = m.getGroupId();
        String targetGroupName = groupCache.get(targetGroupId).getName();
        descriptions.add(MessageFormat.format("group {0}/{1}, group {2}/{3}", groupUuid, groupName, targetGroupId, targetGroupName));
    }
    logOrmException(header, me, descriptions, e);
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) ArrayList(java.util.ArrayList) AccountGroupById(com.google.gerrit.reviewdb.client.AccountGroupById)

Aggregations

AccountGroupById (com.google.gerrit.reviewdb.client.AccountGroupById)8 ArrayList (java.util.ArrayList)6 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)5 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)3 GroupControl (com.google.gerrit.server.account.GroupControl)3 GroupDescription (com.google.gerrit.common.data.GroupDescription)2 GroupDetail (com.google.gerrit.common.data.GroupDetail)2 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)2 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)2 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 Account (com.google.gerrit.reviewdb.client.Account)2 AccountGroupByIdAud (com.google.gerrit.reviewdb.client.AccountGroupByIdAud)2 AccountGroupMember (com.google.gerrit.reviewdb.client.AccountGroupMember)2 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)2 OrmException (com.google.gwtorm.server.OrmException)2 HashMap (java.util.HashMap)2 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)1 HashSet (java.util.HashSet)1