Search in sources :

Example 16 with BadRequestException

use of jetbrains.buildServer.server.rest.errors.BadRequestException 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)

Example 17 with BadRequestException

use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.

the class Project method setFieldValueAndPersist.

public static void setFieldValueAndPersist(final SProject project, final String field, final String value, @NotNull final ServiceLocator serviceLocator) {
    if ("name".equals(field)) {
        if (StringUtil.isEmpty(value)) {
            throw new BadRequestException("Project name cannot be empty.");
        }
        project.setName(value);
        project.schedulePersisting("Project name changed");
        return;
    } else if ("id".equals(field)) {
        if (StringUtil.isEmpty(value)) {
            throw new BadRequestException("Project id cannot be empty.");
        }
        project.setExternalId(value);
        return;
    } else if ("description".equals(field)) {
        project.setDescription(value);
        project.schedulePersisting("Project description changed");
        return;
    } else if ("archived".equals(field)) {
        project.setArchived(Boolean.parseBoolean(value), serviceLocator.getSingletonService(UserFinder.class).getCurrentUser());
        return;
    } else if ("readOnlyUI".equals(field) && TeamCityProperties.getBoolean("rest.projectRequest.allowSetReadOnlyUI")) {
        boolean editable = !Boolean.parseBoolean(value);
        ((ProjectEx) project).setEditable(editable);
        project.schedulePersisting("Project editing is " + (editable ? "enabled" : "disabled"));
        return;
    }
    throw new BadRequestException("Setting field '" + field + "' is not supported. Supported are: name, description, archived");
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException)

Example 18 with BadRequestException

use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.

the class PropEntitiesProjectFeature method setTo.

public boolean setTo(@NotNull final SProject project, @NotNull final ServiceLocator serviceLocator) {
    Storage original = new Storage(project);
    removeAll(project);
    try {
        if (propEntities != null) {
            for (PropEntityProjectFeature entity : propEntities) {
                entity.addToInternal(project, serviceLocator);
            }
        }
        return true;
    } catch (Exception e) {
        original.apply(project);
        throw new BadRequestException("Error replacing items", e);
    }
}
Also used : BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException)

Example 19 with BadRequestException

use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.

the class ProjectRequest method createEmptyBuildType.

@POST
@Path("/{projectLocator}/buildTypes")
@Produces({ "application/xml", "application/json" })
@Consumes({ "text/plain" })
@ApiOperation(hidden = true, value = "Use createBuildType instead")
public BuildType createEmptyBuildType(@ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator, String name, @QueryParam("fields") String fields) {
    SProject project = myProjectFinder.getItem(projectLocator);
    if (StringUtil.isEmpty(name)) {
        throw new BadRequestException("Build type name cannot be empty.");
    }
    final SBuildType buildType = project.createBuildType(name);
    buildType.schedulePersisting("A new build configuration is created");
    return new BuildType(new BuildTypeOrTemplate(buildType), new Fields(fields), myBeanContext);
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Fields(jetbrains.buildServer.server.rest.model.Fields) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BuildType(jetbrains.buildServer.server.rest.model.buildType.BuildType) ApiOperation(io.swagger.annotations.ApiOperation)

Example 20 with BadRequestException

use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.

the class ProjectRequest method createEmptyBuildTypeTemplate.

@POST
@Path("/{projectLocator}/templates")
@Produces({ "application/xml", "application/json" })
@Consumes({ "text/plain" })
@ApiOperation(hidden = true, value = "Use createBuildTypeTemplate instead")
public BuildType createEmptyBuildTypeTemplate(@ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator, String name, @QueryParam("fields") String fields) {
    SProject project = myProjectFinder.getItem(projectLocator, true);
    if (StringUtil.isEmpty(name)) {
        throw new BadRequestException("Build type template name cannot be empty.");
    }
    final BuildTypeTemplate buildType = project.createBuildTypeTemplate(name);
    buildType.schedulePersisting("A new build configuration template is created");
    return new BuildType(new BuildTypeOrTemplate(buildType), new Fields(fields), myBeanContext);
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Fields(jetbrains.buildServer.server.rest.model.Fields) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BuildType(jetbrains.buildServer.server.rest.model.buildType.BuildType) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)128 NotNull (org.jetbrains.annotations.NotNull)52 ApiOperation (io.swagger.annotations.ApiOperation)39 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)35 ServiceLocator (jetbrains.buildServer.ServiceLocator)28 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)22 Nullable (org.jetbrains.annotations.Nullable)22 SUser (jetbrains.buildServer.users.SUser)19 Fields (jetbrains.buildServer.server.rest.model.Fields)17 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)16 Collectors (java.util.stream.Collectors)10 SProject (jetbrains.buildServer.serverSide.SProject)9 StringUtil (jetbrains.buildServer.util.StringUtil)9 Date (java.util.Date)8 jetbrains.buildServer.serverSide (jetbrains.buildServer.serverSide)8 java.util (java.util)7 Locator (jetbrains.buildServer.server.rest.data.Locator)7 OperationException (jetbrains.buildServer.server.rest.errors.OperationException)7 PagerData (jetbrains.buildServer.server.rest.model.PagerData)7 Permission (jetbrains.buildServer.serverSide.auth.Permission)7