Search in sources :

Example 81 with BadRequestException

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

the class AvatarRequest method getAvatar.

@GET
@Produces(MediaType.IMAGE_PNG_VALUE)
@Path("/{userLocator}/{size}/avatar.png")
@ApiOperation("Get a users avatar")
public Response getAvatar(@Context HttpServletResponse response, @ApiParam(format = LocatorName.USER) @PathParam("userLocator") String userLocator, @ApiParam(value = "avatar's size", allowableValues = "range[" + MIN_AVATAR_SIZE + ", " + MAX_AVATAR_SIZE + "]") @PathParam("size") Integer size) throws IOException {
    if (size < MIN_AVATAR_SIZE || size > MAX_AVATAR_SIZE) {
        throw new BadRequestException("\"size\" must be bigger or equal than " + MIN_AVATAR_SIZE + " and lower or equal than " + MAX_AVATAR_SIZE);
    }
    final SUser user = myUserFinder.getItem(userLocator);
    final BufferedImage image = myUserAvatarsManager.getAvatar(user, size);
    if (image == null)
        throw new NotFoundException("avatar (username: " + user.getUsername() + ") not found");
    final int avatarCacheLifeTime = getAvatarCacheLifetime();
    response.setHeader(HttpHeaders.CACHE_CONTROL, CACHE_CONTROL_MAX_AGE + avatarCacheLifeTime);
    ImageIO.write(image, "png", response.getOutputStream());
    return Response.ok().build();
}
Also used : SUser(jetbrains.buildServer.users.SUser) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) BufferedImage(java.awt.image.BufferedImage) ApiOperation(io.swagger.annotations.ApiOperation)

Example 82 with BadRequestException

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

the class AgentPoolRequest method createPool.

@POST
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Create a new agent pool.", nickname = "createAgentPool")
public AgentPool createPool(AgentPool agentPool) {
    if (agentPool.agents != null) {
        throw new BadRequestException("Creating an agent pool with agents is not supported. Please add agents after the pool creation");
    }
    final jetbrains.buildServer.serverSide.agentPools.AgentPool newAgentPool;
    try {
        AgentPoolLimits agentDetails = AgentPoolLimits.DEFAULT;
        if (agentPool.maxAgents != null) {
            agentDetails = new AgentPoolLimitsImpl(AgentPoolLimits.DEFAULT.getMinAgents(), agentPool.maxAgents != null ? Integer.valueOf(agentPool.maxAgents) : AgentPoolLimits.DEFAULT.getMaxAgents());
        }
        newAgentPool = myServiceLocator.getSingletonService(AgentPoolManager.class).createNewAgentPool(agentPool.name, agentDetails);
    } catch (AgentPoolCannotBeRenamedException e) {
        throw new BadRequestException("Agent pool with name \'" + agentPool.name + "' already exists.");
    }
    if (agentPool.projects != null) {
        replaceProjects("id:" + newAgentPool, agentPool.projects);
    }
    return new AgentPool(newAgentPool, Fields.LONG, myBeanContext);
}
Also used : BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) AgentPool(jetbrains.buildServer.server.rest.model.agent.AgentPool) ApiOperation(io.swagger.annotations.ApiOperation)

Example 83 with BadRequestException

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

the class PropEntityProjectFeature method addToInternal.

@NotNull
public SProjectFeatureDescriptor addToInternal(@NotNull final SProject project, @NotNull final ServiceLocator serviceLocator) {
    if (StringUtil.isEmpty(type)) {
        throw new BadRequestException("Project feature cannot have empty 'type'.");
    }
    @NotNull final ProjectFeatureDescriptorFactory factory = serviceLocator.getSingletonService(ProjectFeatureDescriptorFactory.class);
    String forcedId = null;
    // special case for "overriden" entities
    if (id != null) {
        for (SProjectFeatureDescriptor item : project.getOwnFeatures()) {
            if (id.equals(item.getId())) {
                forcedId = id;
                break;
            }
        }
    }
    SProjectFeatureDescriptor newFeature;
    if (forcedId != null) {
        newFeature = factory.createProjectFeature(forcedId, type, properties != null ? properties.getMap() : new HashMap<String, String>(), project.getProjectId());
    } else {
        newFeature = factory.createNewProjectFeature(type, properties != null ? properties.getMap() : new HashMap<String, String>(), project.getProjectId());
    }
    try {
        project.addFeature(newFeature);
    } catch (Exception e) {
        final String details = getDetails(project, newFeature, e);
        throw new BadRequestException("Error adding feature: " + details, e);
    }
    return getFeatureByLocator(project, newFeature.getId());
}
Also used : ProjectFeatureDescriptorFactory(jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) SProjectFeatureDescriptor(jetbrains.buildServer.serverSide.SProjectFeatureDescriptor) NotNull(org.jetbrains.annotations.NotNull) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) InvalidStateException(jetbrains.buildServer.server.rest.errors.InvalidStateException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) NotNull(org.jetbrains.annotations.NotNull)

Example 84 with BadRequestException

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

the class AgentRequest method setAuthorizedInfo.

@PUT
@Path("/{agentLocator}/authorizedInfo")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update the authorization info of the matching agent.", nickname = "setAuthorizedInfo")
public AgentAuthorizedInfo setAuthorizedInfo(@ApiParam(format = LocatorName.AGENT) @PathParam("agentLocator") String agentLocator, AgentAuthorizedInfo authorizedInfo, @QueryParam("fields") String fields) {
    final SBuildAgent agent = myAgentFinder.getItem(agentLocator);
    if (authorizedInfo == null)
        throw new BadRequestException("No data is sent as payload.");
    String commentText = authorizedInfo.getCommentTextFromPosted();
    Boolean value = authorizedInfo.getStatusFromPosted();
    if (value == null && commentText == null)
        throw new BadRequestException("Neither value nor comment are provided, nothing to change");
    agent.setAuthorized(value != null ? value : agent.isAuthorized(), myServiceLocator.getSingletonService(UserFinder.class).getCurrentUser(), Agent.getActualActionComment(commentText));
    return new AgentAuthorizedInfo(agent, new Fields(fields), myBeanContext);
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) ApiOperation(io.swagger.annotations.ApiOperation)

Example 85 with BadRequestException

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

the class AgentPoolRequest method replaceProjects.

/**
 * Associates the posted set of projects with the pool which replaces earlier associations on this pool
 * @param agentPoolLocator
 * @param projects
 * @return
 */
@PUT
@Path("/{agentPoolLocator}/projects")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update projects of the matching agent pool.", nickname = "setAgentPoolProjects")
public Projects replaceProjects(@ApiParam(format = LocatorName.AGENT_POOL) @PathParam("agentPoolLocator") String agentPoolLocator, Projects projects) {
    final jetbrains.buildServer.serverSide.agentPools.AgentPool agentPool = myAgentPoolFinder.getItem(agentPoolLocator);
    final AgentPoolManager agentPoolManager = myServiceLocator.getSingletonService(AgentPoolManager.class);
    final int agentPoolId = agentPool.getAgentPoolId();
    final List<SProject> projectsList = projects.getProjectsFromPosted(myProjectFinder);
    final Set<String> projectIds = new HashSet<String>(projectsList.size());
    for (SProject project : projectsList) {
        projectIds.add(project.getProjectId());
    }
    try {
        agentPoolManager.dissociateProjectsFromPool(agentPoolId, agentPoolManager.getPoolProjects(agentPoolId));
        agentPoolManager.associateProjectsWithPool(agentPoolId, projectIds);
    } catch (NoSuchAgentPoolException e) {
        throw new BadRequestException("Agent pool with id \'" + agentPoolId + "' is not found.");
    }
    return new Projects(myAgentPoolFinder.getPoolProjects(agentPool), null, Fields.LONG, myBeanContext);
}
Also used : Projects(jetbrains.buildServer.server.rest.model.project.Projects) SProject(jetbrains.buildServer.serverSide.SProject) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) HashSet(java.util.HashSet) 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