Search in sources :

Example 1 with ParametersPersistableEntity

use of jetbrains.buildServer.server.rest.data.parameters.ParametersPersistableEntity in project teamcity-rest by JetBrains.

the class BuildRequest method getAttributes.

/**
 * Experimental support only
 * Changing of some attributes is not supported and can result in strange and "unpredictable" behavior.
 */
@Path("/{buildLocator}/attributes")
@ApiOperation(value = "getAttributes", nickname = "getAttributes", hidden = true)
public ParametersSubResource getAttributes(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, @QueryParam("fields") String fields) {
    BuildPromotionEx build = (BuildPromotionEx) myBuildPromotionFinder.getItem(buildLocator);
    myPermissionChecker.checkPermission(Permission.EDIT_PROJECT, build);
    return new ParametersSubResource(myBeanContext, new ParametersPersistableEntity() {

        @Override
        public void addParameter(@NotNull final Parameter param) {
            build.setAttribute(param.getName(), param.getValue());
        }

        @Override
        public void removeParameter(@NotNull final String paramName) {
            build.setAttribute(paramName, null);
        }

        @NotNull
        @Override
        public Collection<Parameter> getParametersCollection(@Nullable final Locator locator) {
            return build.getAttributes().entrySet().stream().map(entry -> new SimpleParameter(entry.getKey(), String.valueOf(entry.getValue()))).collect(Collectors.toList());
        }

        @Nullable
        @Override
        public Parameter getParameter(@NotNull final String paramName) {
            return new SimpleParameter(paramName, String.valueOf(build.getAttribute(paramName)));
        }

        @Override
        public void persist(@NotNull String description) {
        // should not need a separate action
        }
    }, getBuildHref(build) + "/attributes");
}
Also used : ParametersPersistableEntity(jetbrains.buildServer.server.rest.data.parameters.ParametersPersistableEntity) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 ParametersPersistableEntity (jetbrains.buildServer.server.rest.data.parameters.ParametersPersistableEntity)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1