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();
}
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);
}
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());
}
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);
}
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);
}
Aggregations