use of com.google.gerrit.exceptions.NoSuchGroupException in project gerrit by GerritCodeReview.
the class PutOptions method apply.
@Override
public Response<GroupOptionsInfo> apply(GroupResource resource, GroupOptionsInfo input) throws NotInternalGroupException, AuthException, BadRequestException, ResourceNotFoundException, IOException, ConfigInvalidException {
GroupDescription.Internal internalGroup = resource.asInternalGroup().orElseThrow(NotInternalGroupException::new);
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;
}
if (internalGroup.isVisibleToAll() != input.visibleToAll) {
AccountGroup.UUID groupUuid = internalGroup.getGroupUUID();
GroupDelta groupDelta = GroupDelta.builder().setVisibleToAll(input.visibleToAll).build();
try {
groupsUpdateProvider.get().updateGroup(groupUuid, groupDelta);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
}
GroupOptionsInfo options = new GroupOptionsInfo();
if (input.visibleToAll) {
options.visibleToAll = true;
}
return Response.ok(options);
}
use of com.google.gerrit.exceptions.NoSuchGroupException in project gerrit by GerritCodeReview.
the class PutName method renameGroup.
private void renameGroup(GroupDescription.Internal group, String newName) throws ResourceConflictException, ResourceNotFoundException, IOException, ConfigInvalidException {
AccountGroup.UUID groupUuid = group.getGroupUUID();
GroupDelta groupDelta = GroupDelta.builder().setName(AccountGroup.nameKey(newName)).build();
try {
groupsUpdateProvider.get().updateGroup(groupUuid, groupDelta);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
} catch (DuplicateKeyException e) {
throw new ResourceConflictException("group with name " + newName + " already exists", e);
}
}
use of com.google.gerrit.exceptions.NoSuchGroupException in project gerrit by GerritCodeReview.
the class ListSubgroups method getDirectSubgroups.
public List<GroupInfo> getDirectSubgroups(GroupDescription.Internal group, GroupControl groupControl) throws PermissionBackendException {
boolean ownerOfParent = groupControl.isOwner();
List<GroupInfo> included = new ArrayList<>();
for (AccountGroup.UUID subgroupUuid : group.getSubgroups()) {
try {
GroupControl i = controlFactory.controlFor(subgroupUuid);
if (ownerOfParent || i.isVisible()) {
included.add(json.format(i.getGroup()));
}
} catch (NoSuchGroupException notFound) {
logger.atWarning().log("Group %s no longer available, subgroup of %s", subgroupUuid, group.getName());
continue;
}
}
included.sort(comparing((GroupInfo g) -> nullToEmpty(g.name)).thenComparing(g -> nullToEmpty(g.id)));
return included;
}
use of com.google.gerrit.exceptions.NoSuchGroupException in project gerrit by GerritCodeReview.
the class DeleteSubgroups method apply.
@Override
public Response<?> apply(GroupResource resource, Input input) throws AuthException, NotInternalGroupException, UnprocessableEntityException, ResourceNotFoundException, IOException, ConfigInvalidException {
GroupDescription.Internal internalGroup = resource.asInternalGroup().orElseThrow(NotInternalGroupException::new);
input = Input.init(input);
final GroupControl control = resource.getControl();
if (!control.canRemoveGroup()) {
throw new AuthException(String.format("Cannot delete groups from group %s", internalGroup.getName()));
}
Set<AccountGroup.UUID> subgroupsToRemove = new HashSet<>();
for (String subgroupIdentifier : input.groups) {
GroupDescription.Basic subgroup = groupResolver.parse(subgroupIdentifier);
subgroupsToRemove.add(subgroup.getGroupUUID());
}
AccountGroup.UUID groupUuid = internalGroup.getGroupUUID();
try {
removeSubgroups(groupUuid, subgroupsToRemove);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
return Response.none();
}
use of com.google.gerrit.exceptions.NoSuchGroupException in project gerrit by GerritCodeReview.
the class GroupsUpdate method updateGroupInNoteDb.
@VisibleForTesting
public UpdateResult updateGroupInNoteDb(AccountGroup.UUID groupUuid, GroupDelta groupDelta) throws IOException, ConfigInvalidException, DuplicateKeyException, NoSuchGroupException {
try (Repository allUsersRepo = repoManager.openRepository(allUsersName)) {
GroupConfig groupConfig = GroupConfig.loadForGroup(allUsersName, allUsersRepo, groupUuid);
groupConfig.setGroupDelta(groupDelta, auditLogFormatter);
if (!groupConfig.getLoadedGroup().isPresent()) {
throw new NoSuchGroupException(groupUuid);
}
InternalGroup originalGroup = groupConfig.getLoadedGroup().get();
GroupNameNotes groupNameNotes = null;
if (groupDelta.getName().isPresent()) {
AccountGroup.NameKey oldName = originalGroup.getNameKey();
AccountGroup.NameKey newName = groupDelta.getName().get();
groupNameNotes = GroupNameNotes.forRename(allUsersName, allUsersRepo, groupUuid, oldName, newName);
}
commit(allUsersRepo, groupConfig, groupNameNotes);
InternalGroup updatedGroup = groupConfig.getLoadedGroup().orElseThrow(() -> new IllegalStateException("Updated group wasn't automatically loaded"));
return getUpdateResult(originalGroup, updatedGroup);
}
}
Aggregations