Search in sources :

Example 6 with NotFoundException

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());
    }
}
Also used : SUser(jetbrains.buildServer.users.SUser) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) ApiOperation(io.swagger.annotations.ApiOperation)

Example 7 with NotFoundException

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();
}
Also used : BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) Element(jetbrains.buildServer.util.browser.Element) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with NotFoundException

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();
}
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 9 with NotFoundException

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() + "'");
    }
}
Also used : ServiceLocator(jetbrains.buildServer.ServiceLocator) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) SArtifactDependency(jetbrains.buildServer.serverSide.artifacts.SArtifactDependency)

Example 10 with NotFoundException

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();
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)47 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)26 ApiOperation (io.swagger.annotations.ApiOperation)19 NotNull (org.jetbrains.annotations.NotNull)14 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)13 ServiceLocator (jetbrains.buildServer.ServiceLocator)10 SUser (jetbrains.buildServer.users.SUser)10 SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)10 Nullable (org.jetbrains.annotations.Nullable)8 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)7 AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)5 Fields (jetbrains.buildServer.server.rest.model.Fields)5 Converter (jetbrains.buildServer.util.Converter)4 RevisionsNotFoundException (jetbrains.buildServer.vcs.impl.RevisionsNotFoundException)4 Logger (com.intellij.openapi.diagnostic.Logger)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 SUserGroup (jetbrains.buildServer.groups.SUserGroup)3 SArtifactDependency (jetbrains.buildServer.serverSide.artifacts.SArtifactDependency)3 Permission (jetbrains.buildServer.serverSide.auth.Permission)3