Search in sources :

Example 1 with CycleDetectedException

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);
    }
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) HashMap(java.util.HashMap) PagedSearchResult(jetbrains.buildServer.server.rest.data.PagedSearchResult) SUserGroup(jetbrains.buildServer.groups.SUserGroup) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) RoleAssignment(jetbrains.buildServer.server.rest.model.user.RoleAssignment) OperationException(jetbrains.buildServer.server.rest.errors.OperationException) XmlType(javax.xml.bind.annotation.XmlType) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) Map(java.util.Map) UserGroupManager(jetbrains.buildServer.groups.UserGroupManager) ModelDescription(jetbrains.buildServer.server.rest.swagger.annotations.ModelDescription) XmlAttribute(javax.xml.bind.annotation.XmlAttribute) PermissionChecker(jetbrains.buildServer.server.rest.data.PermissionChecker) RoleAssignments(jetbrains.buildServer.server.rest.model.user.RoleAssignments) Properties(jetbrains.buildServer.server.rest.model.Properties) ServiceLocator(jetbrains.buildServer.ServiceLocator) StringUtil(com.intellij.openapi.util.text.StringUtil) Set(java.util.Set) Users(jetbrains.buildServer.server.rest.model.user.Users) RoleEntry(jetbrains.buildServer.serverSide.auth.RoleEntry) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) ApiUrlBuilder(jetbrains.buildServer.server.rest.ApiUrlBuilder) Locator(jetbrains.buildServer.server.rest.data.Locator) ValueWithDefault(jetbrains.buildServer.server.rest.util.ValueWithDefault) Collectors(java.util.stream.Collectors) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) GroupRequest(jetbrains.buildServer.server.rest.request.GroupRequest) UserFinder(jetbrains.buildServer.server.rest.data.UserFinder) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) NotNull(org.jetbrains.annotations.NotNull) CycleDetectedException(jetbrains.buildServer.groups.CycleDetectedException) PropertyKey(jetbrains.buildServer.users.PropertyKey) SUser(jetbrains.buildServer.users.SUser) XmlElement(javax.xml.bind.annotation.XmlElement) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) CycleDetectedException(jetbrains.buildServer.groups.CycleDetectedException) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) SUserGroup(jetbrains.buildServer.groups.SUserGroup) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) OperationException(jetbrains.buildServer.server.rest.errors.OperationException) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) CycleDetectedException(jetbrains.buildServer.groups.CycleDetectedException) OperationException(jetbrains.buildServer.server.rest.errors.OperationException)

Aggregations

StringUtil (com.intellij.openapi.util.text.StringUtil)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)1 XmlType (javax.xml.bind.annotation.XmlType)1 ServiceLocator (jetbrains.buildServer.ServiceLocator)1 CycleDetectedException (jetbrains.buildServer.groups.CycleDetectedException)1 SUserGroup (jetbrains.buildServer.groups.SUserGroup)1 UserGroupManager (jetbrains.buildServer.groups.UserGroupManager)1 ApiUrlBuilder (jetbrains.buildServer.server.rest.ApiUrlBuilder)1 Locator (jetbrains.buildServer.server.rest.data.Locator)1 PagedSearchResult (jetbrains.buildServer.server.rest.data.PagedSearchResult)1 PermissionChecker (jetbrains.buildServer.server.rest.data.PermissionChecker)1 UserFinder (jetbrains.buildServer.server.rest.data.UserFinder)1 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1