use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class AllGroupsIndexer method collectGroups.
private List<AccountGroup.UUID> collectGroups(ProgressMonitor progress) throws OrmException {
progress.beginTask("Collecting groups", ProgressMonitor.UNKNOWN);
List<AccountGroup.UUID> uuids = new ArrayList<>();
try (ReviewDb db = schemaFactory.open()) {
for (AccountGroup group : db.accountGroups().all()) {
uuids.add(group.getGroupUUID());
}
}
progress.endTask();
return uuids;
}
use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class PutDescription method apply.
@Override
public Response<String> apply(GroupResource resource, Input input) throws AuthException, MethodNotAllowedException, ResourceNotFoundException, OrmException, IOException {
if (input == null) {
// Delete would set description to null.
input = new Input();
}
if (resource.toAccountGroup() == null) {
throw new MethodNotAllowedException();
} else if (!resource.getControl().isOwner()) {
throw new AuthException("Not group owner");
}
AccountGroup group = db.get().accountGroups().get(resource.toAccountGroup().getId());
if (group == null) {
throw new ResourceNotFoundException();
}
group.setDescription(Strings.emptyToNull(input.description));
db.get().accountGroups().update(Collections.singleton(group));
groupCache.evict(group);
return Strings.isNullOrEmpty(input.description) ? Response.<String>none() : Response.ok(input.description);
}
use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class PutOwner method apply.
@Override
public GroupInfo apply(GroupResource resource, Input input) throws ResourceNotFoundException, MethodNotAllowedException, AuthException, BadRequestException, UnprocessableEntityException, OrmException, IOException {
AccountGroup group = resource.toAccountGroup();
if (group == null) {
throw new MethodNotAllowedException();
} else if (!resource.getControl().isOwner()) {
throw new AuthException("Not group owner");
}
if (input == null || Strings.isNullOrEmpty(input.owner)) {
throw new BadRequestException("owner is required");
}
group = db.get().accountGroups().get(group.getId());
if (group == null) {
throw new ResourceNotFoundException();
}
GroupDescription.Basic owner = groupsCollection.parse(input.owner);
if (!group.getOwnerGroupUUID().equals(owner.getGroupUUID())) {
group.setOwnerGroupUUID(owner.getGroupUUID());
db.get().accountGroups().update(Collections.singleton(group));
groupCache.evict(group);
}
return json.format(owner);
}
use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class QueryGroups method apply.
@Override
public List<GroupInfo> apply(TopLevelResource resource) throws BadRequestException, MethodNotAllowedException, OrmException {
if (Strings.isNullOrEmpty(query)) {
throw new BadRequestException("missing query field");
}
GroupIndex searchIndex = indexes.getSearchIndex();
if (searchIndex == null) {
throw new MethodNotAllowedException("no group index");
}
if (start != 0) {
queryProcessor.setStart(start);
}
if (limit != 0) {
queryProcessor.setLimit(limit);
}
try {
QueryResult<AccountGroup> result = queryProcessor.query(queryBuilder.parse(query));
List<AccountGroup> groups = result.entities();
ArrayList<GroupInfo> groupInfos = Lists.newArrayListWithCapacity(groups.size());
json.addOptions(options);
for (AccountGroup group : groups) {
groupInfos.add(json.format(GroupDescriptions.forAccountGroup(group)));
}
if (!groupInfos.isEmpty() && result.more()) {
groupInfos.get(groupInfos.size() - 1)._moreGroups = true;
}
return groupInfos;
} catch (QueryParseException e) {
throw new BadRequestException(e.getMessage());
}
}
use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class Index method apply.
@Override
public Response<?> apply(GroupResource rsrc, Input input) throws IOException, AuthException, UnprocessableEntityException {
if (!rsrc.getControl().isOwner()) {
throw new AuthException("not allowed to index group");
}
AccountGroup group = GroupDescriptions.toAccountGroup(rsrc.getGroup());
if (group == null) {
throw new UnprocessableEntityException(String.format("External Group Not Allowed: %s", rsrc.getGroupUUID().get()));
}
// evicting the group from the cache, reindexes the group
groupCache.evict(group);
return Response.none();
}
Aggregations