Search in sources :

Example 1 with ActionErrors

use of jetbrains.buildServer.controllers.ActionErrors in project teamcity-rest by JetBrains.

the class BuildRequest method setBuildStatus.

@POST
@Path("/{buildLocator}/status")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Change status of the build.", nickname = "setBuildStatus")
public Response setBuildStatus(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, @QueryParam("fields") String fields, BuildStatusUpdate statusUpdate, @Context HttpServletRequest request) {
    BuildPromotion build = myBuildPromotionFinder.getItem(buildLocator);
    AuthorityHolder authorityHolder = myBeanContext.getSingletonService(SecurityContext.class).getAuthorityHolder();
    ChangeBuildStatusProcessor processor = new ChangeBuildStatusProcessor(build.getAssociatedBuild(), (SUser) authorityHolder.getAssociatedUser(), statusUpdate.status, statusUpdate.comment);
    ActionErrors errors = processor.doChangeStatus();
    if (errors.hasErrors()) {
        List<String> errorStrings = new ArrayList<>();
        for (ActionErrors.Error e : errors.getErrors()) {
            errorStrings.add(e.getMessage());
        }
        return Response.status(Response.Status.BAD_REQUEST).entity(new BuildStatusUpdateResult(build, errorStrings, new Fields(fields), myBeanContext)).build();
    }
    return Response.ok().entity(new BuildStatusUpdateResult(build, Collections.emptyList(), new Fields(fields), myBeanContext)).build();
}
Also used : SecurityContext(jetbrains.buildServer.serverSide.auth.SecurityContext) ChangeBuildStatusProcessor(jetbrains.buildServer.controllers.actions.ChangeBuildStatusProcessor) ActionErrors(jetbrains.buildServer.controllers.ActionErrors) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 ActionErrors (jetbrains.buildServer.controllers.ActionErrors)1 ChangeBuildStatusProcessor (jetbrains.buildServer.controllers.actions.ChangeBuildStatusProcessor)1 SecurityContext (jetbrains.buildServer.serverSide.auth.SecurityContext)1