use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class PutOptions method apply.
@Override
public GroupOptionsInfo apply(GroupResource resource, GroupOptionsInfo input) throws MethodNotAllowedException, AuthException, BadRequestException, ResourceNotFoundException, OrmException, IOException {
if (resource.toAccountGroup() == null) {
throw new MethodNotAllowedException();
} else if (!resource.getControl().isOwner()) {
throw new AuthException("Not group owner");
}
if (input == null) {
throw new BadRequestException("options are required");
}
if (input.visibleToAll == null) {
input.visibleToAll = false;
}
AccountGroup group = db.get().accountGroups().get(resource.toAccountGroup().getId());
if (group == null) {
throw new ResourceNotFoundException();
}
group.setVisibleToAll(input.visibleToAll);
db.get().accountGroups().update(Collections.singleton(group));
groupCache.evict(group);
GroupOptionsInfo options = new GroupOptionsInfo();
if (group.isVisibleToAll()) {
options.visibleToAll = true;
}
return options;
}
use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class ListGroups method getAllGroups.
private List<GroupInfo> getAllGroups() throws OrmException {
List<GroupInfo> groupInfos;
List<AccountGroup> groupList;
if (!projects.isEmpty()) {
Map<AccountGroup.UUID, AccountGroup> groups = new HashMap<>();
for (final ProjectControl projectControl : projects) {
final Set<GroupReference> groupsRefs = projectControl.getAllGroups();
for (final GroupReference groupRef : groupsRefs) {
final AccountGroup group = groupCache.get(groupRef.getUUID());
if (group != null) {
groups.put(group.getGroupUUID(), group);
}
}
}
groupList = filterGroups(groups.values());
} else {
groupList = filterGroups(groupCache.all());
}
groupInfos = Lists.newArrayListWithCapacity(groupList.size());
int found = 0;
int foundIndex = 0;
for (AccountGroup group : groupList) {
if (foundIndex++ < start) {
continue;
}
if (limit > 0 && ++found > limit) {
break;
}
groupInfos.add(json.addOptions(options).format(GroupDescriptions.forAccountGroup(group)));
}
return groupInfos;
}
use of com.google.gerrit.reviewdb.client.AccountGroup 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;
}
use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class Schema_87 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
for (AccountGroup.Id id : scanSystemGroups(db)) {
AccountGroup group = db.accountGroups().get(id);
if (group != null && SystemGroupBackend.isSystemGroup(group.getGroupUUID())) {
db.accountGroups().delete(Collections.singleton(group));
db.accountGroupNames().deleteKeys(Collections.singleton(group.getNameKey()));
}
}
}
use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class GroupQueryBuilder method owner.
@Operator
public Predicate<AccountGroup> owner(String owner) throws QueryParseException {
AccountGroup group = args.groupCache.get(new AccountGroup.UUID(owner));
if (group != null) {
return GroupPredicates.owner(group.getGroupUUID());
}
GroupReference g = GroupBackends.findBestSuggestion(args.groupBackend, owner);
if (g == null) {
throw error("Group " + owner + " not found");
}
return GroupPredicates.owner(g.getUUID());
}
Aggregations