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;
}
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;
}
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);
}
}
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);
}
}
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);
}
Aggregations