use of jetbrains.buildServer.groups.CycleDetectedException in project teamcity-rest by JetBrains.
the class Group method setGroupParents.
public static void setGroupParents(@NotNull final SUserGroup group, @NotNull final Set<SUserGroup> newParents, final boolean revertOnError, @NotNull final ServiceLocator serviceLocator) {
// workaround for TW-52253
serviceLocator.getSingletonService(PermissionChecker.class).getServerActionChecker().checkCanEditUserGroup(group);
Set<SUserGroup> currentParents = group.getParentGroups().stream().map(userGroup -> (SUserGroup) userGroup).collect(Collectors.toSet());
currentParents.stream().filter(userGroup -> !newParents.contains(userGroup)).forEach(userGroup -> userGroup.removeSubgroup(group));
try {
newParents.stream().filter(userGroup -> !currentParents.contains(userGroup)).forEach(userGroup -> userGroup.addSubgroup(group));
} catch (CycleDetectedException e) {
if (revertOnError)
setGroupParents(group, currentParents, false, serviceLocator);
throw new BadRequestException("Error encountered while trying to set new parent groups", e);
} catch (AccessDeniedException e) {
if (revertOnError)
setGroupParents(group, currentParents, false, serviceLocator);
throw e;
} catch (Exception e) {
if (revertOnError)
setGroupParents(group, currentParents, false, serviceLocator);
throw new OperationException("Error encountered while trying to set new parent groups", e);
}
}
Aggregations