use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class UserRequest method deleteToken.
@DELETE
@Path("/{userLocator}/tokens/{name}")
@ApiOperation(value = "Remove an authentication token from the matching user.", nickname = "deleteUserToken")
public void deleteToken(@ApiParam(format = LocatorName.USER) @PathParam("userLocator") String userLocator, @PathParam("name") @NotNull final String name, @Context @NotNull final BeanContext beanContext) {
if (TeamCityProperties.getBooleanOrTrue(UserFinder.REST_CHECK_ADDITIONAL_PERMISSIONS_ON_USERS_AND_GROUPS)) {
myUserFinder.checkViewAllUsersPermission();
}
final TokenAuthenticationModel tokenAuthenticationModel = myBeanContext.getSingletonService(TokenAuthenticationModel.class);
SUser user = myUserFinder.getItem(userLocator, true);
try {
tokenAuthenticationModel.deleteToken(user.getId(), name);
} catch (AuthenticationTokenStorage.DeletionException e) {
throw new NotFoundException(e.getMessage());
}
}
use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class AggregatedBuildArtifactsElementBuilder method getBuildAggregatedArtifactElement.
@NotNull
public static Element getBuildAggregatedArtifactElement(@NotNull final String path, @NotNull final List<BuildPromotion> builds, @NotNull final ServiceLocator serviceLocator) {
final AggregatedBuildArtifactsElementBuilder result = new AggregatedBuildArtifactsElementBuilder();
int i = 0;
for (BuildPromotion buildPromotion : builds) {
try {
final Element artifactElement = BuildArtifactsFinder.getArtifactElement(buildPromotion, path, serviceLocator);
LOG.debug("Found artifact file with path '" + path + "' in " + i + "/" + builds.size() + " build: " + LogUtil.describe(buildPromotion));
result.add(artifactElement);
} catch (NotFoundException e) {
LOG.debug("Ignoring not found error in artifacts aggregation request: " + e.toString());
} catch (AuthorizationFailedException e) {
LOG.debug("Ignoring authentication error in artifacts aggregation request: " + e.toString());
}
i++;
}
return result.get();
}
use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class AvatarRequest method getAvatarWithHash.
@GET
@Produces(MediaType.IMAGE_PNG_VALUE)
@Path("/{userLocator}/{size}/avatar.{hash}.png")
@ApiOperation("Get a users avatar")
public Response getAvatarWithHash(@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, @PathParam("hash") String hash) 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);
if (!hash.equals(user.getPropertyValue(AVATAR_HASH)))
throw new NotFoundException("Avatar with hash - " + hash + " not found");
final BufferedImage image = myUserAvatarsManager.getAvatar(user, size);
if (image == null)
throw new NotFoundException("avatar (username: " + user.getUsername() + ") not found");
response.setHeader(HttpHeaders.CACHE_CONTROL, CACHE_CONTROL_MAX_AGE + CACHE_CONTROL_NEVER_EXPIRES);
ImageIO.write(image, "png", response.getOutputStream());
return Response.ok().build();
}
use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class BuildTypeRequest method getArtifactDependency.
public static SArtifactDependency getArtifactDependency(@NotNull final BuildTypeOrTemplate buildType, @NotNull final String artifactDepLocator) {
if (StringUtil.isEmpty(artifactDepLocator)) {
throw new BadRequestException("Empty artifact dependency locator is not supported.");
}
final Locator locator = new Locator(artifactDepLocator, "id", Locator.LOCATOR_SINGLE_VALUE_UNUSED_NAME);
final String artifactDepId;
if (locator.isSingleValue()) {
artifactDepId = locator.getSingleValue();
} else {
artifactDepId = locator.getSingleDimensionValue("id");
}
locator.checkLocatorFullyProcessed();
if (StringUtil.isEmpty(artifactDepId)) {
throw new BadRequestException("Cannot find id in artifact dependency locator '" + artifactDepLocator + "'");
}
for (SArtifactDependency dep : buildType.get().getArtifactDependencies()) {
if (artifactDepId.equals(dep.getId())) {
return dep;
}
}
try {
final Integer orderNumber = Integer.parseInt(artifactDepId);
try {
SArtifactDependency result = buildType.get().getArtifactDependencies().get(orderNumber);
LOG.debug("Found artifact dependency by order number " + orderNumber + " instead of id. This behavior is obsolete, use id (" + result.getId() + ") instead of order number.");
return result;
} catch (IndexOutOfBoundsException e) {
throw new NotFoundException("Could not find artifact dependency by id '" + artifactDepId + "' in " + buildType.getText() + " with id '" + buildType.getId() + "'");
}
} catch (NumberFormatException e) {
// not a number either: report error:
throw new NotFoundException("Could not find artifact dependency by id '" + artifactDepId + "' in " + buildType.getText() + " with id '" + buildType.getId() + "'");
}
}
use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class BuildTypeRequest method updateVcsRootEntryCheckoutRules.
@PUT
@Path("/{btLocator}/vcs-root-entries/{vcsRootLocator}/" + VcsRootEntry.CHECKOUT_RULES)
@Consumes({ "text/plain" })
@Produces({ "text/plain" })
@ApiOperation(value = "Update checkout rules of a VCS root of the matching build configuration.", nickname = "updateBuildTypeVcsRootCheckoutRules")
public String updateVcsRootEntryCheckoutRules(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator, String newCheckoutRules) {
final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
if (!buildType.get().containsVcsRoot(vcsRoot.getId())) {
throw new NotFoundException("VCS root with id '" + vcsRoot.getExternalId() + "' is not attached to the build type.");
}
buildType.get().setCheckoutRules(vcsRoot, new CheckoutRules(newCheckoutRules != null ? newCheckoutRules : ""));
buildType.persist("VCS root checkout rules changed");
// not handling setting errors...
return buildType.get().getCheckoutRules(vcsRoot).getAsString();
}
Aggregations