Search in sources :

Example 6 with Requirement

use of jetbrains.buildServer.requirements.Requirement in project teamcity-rest by JetBrains.

the class BuildTypeRequest method addAgentRequirement.

/**
 * Creates new agent requirement. 'id' attribute is ignored in the submitted descriptor.
 * Reports error if new requirement cannot be created (e.g. another requirement is present for the parameter).
 */
@POST
@Path("/{btLocator}/agent-requirements")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Add an agent requirement to the matching build configuration.", nickname = "addAgentRequirementToBuildType")
public PropEntityAgentRequirement addAgentRequirement(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @QueryParam("fields") String fields, PropEntityAgentRequirement description) {
    final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
    final Requirement result = description.addTo(buildType.getSettingsEx(), myServiceLocator);
    buildType.persist("Agent requirement added");
    return new PropEntityAgentRequirement(result, buildType.getSettingsEx(), new Fields(fields), myBeanContext);
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Requirement(jetbrains.buildServer.requirements.Requirement) ApiOperation(io.swagger.annotations.ApiOperation)

Example 7 with Requirement

use of jetbrains.buildServer.requirements.Requirement in project teamcity-rest by JetBrains.

the class BuildTypeRequest method replaceAgentRequirement.

@PUT
@Path("/{btLocator}/agent-requirements/{agentRequirementLocator}")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update an agent requirement of the matching build configuration.", nickname = "replaceAgentRequirement")
public PropEntityAgentRequirement replaceAgentRequirement(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @PathParam("agentRequirementLocator") String agentRequirementLocator, @QueryParam("fields") String fields, PropEntityAgentRequirement description) {
    final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
    final Requirement requirement = getAgentRequirement(buildType, agentRequirementLocator);
    final Requirement result = description.replaceIn(buildType.getSettingsEx(), requirement, myServiceLocator);
    return new PropEntityAgentRequirement(result, buildType.getSettingsEx(), new Fields(fields), myBeanContext);
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Requirement(jetbrains.buildServer.requirements.Requirement) ApiOperation(io.swagger.annotations.ApiOperation)

Example 8 with Requirement

use of jetbrains.buildServer.requirements.Requirement in project teamcity-rest by JetBrains.

the class BuildTypeRequest method changeRequirementSetting.

@PUT
@Path("/{btLocator}/agent-requirements/{agentRequirementLocator}/{fieldName}")
@Consumes({ "text/plain" })
@Produces({ "text/plain" })
@ApiOperation(value = "Update a parameter of an agent requirement of the matching build configuration.", nickname = "setAgentRequirementParameter")
public String changeRequirementSetting(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @PathParam("agentRequirementLocator") String agentRequirementLocator, @PathParam("fieldName") String name, String newValue) {
    final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
    final Requirement requirement = getAgentRequirement(buildType, agentRequirementLocator);
    String id = requirement.getId();
    if (id == null) {
        throw new BadRequestException("Could not get field of a requirement which does not have id");
    }
    PropEntityStep.setSetting(buildType.get(), id, name, newValue);
    buildType.persist("Agent requirement settings changed");
    return PropEntityStep.getSetting(buildType.get(), id, name);
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Requirement(jetbrains.buildServer.requirements.Requirement) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ApiOperation(io.swagger.annotations.ApiOperation)

Example 9 with Requirement

use of jetbrains.buildServer.requirements.Requirement in project teamcity-rest by JetBrains.

the class BuildTypeRequest method deleteAgentRequirement.

@DELETE
@Path("/{btLocator}/agent-requirements/{agentRequirementLocator}")
@ApiOperation(value = "Remove an agent requirement of the matching build configuration.", nickname = "deleteAgentRequirement")
public void deleteAgentRequirement(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @PathParam("agentRequirementLocator") String agentRequirementLocator) {
    final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
    final Requirement requirement = getAgentRequirement(buildType, agentRequirementLocator);
    PropEntityAgentRequirement.removeFrom(buildType.get(), requirement);
    buildType.persist("Agent requirement removed");
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Requirement(jetbrains.buildServer.requirements.Requirement) ApiOperation(io.swagger.annotations.ApiOperation)

Example 10 with Requirement

use of jetbrains.buildServer.requirements.Requirement in project teamcity-rest by JetBrains.

the class PropEntityAgentRequirement method addToMain.

@NotNull
public Requirement addToMain(@NotNull final BuildTypeSettingsEx buildType, @NotNull final ServiceLocator serviceLocator) {
    final Map<String, String> propertiesMap = properties == null ? Collections.emptyMap() : properties.getMap();
    String propertyName = propertiesMap.get(NAME_PROPERTY_NAME);
    if (StringUtil.isEmpty(propertyName)) {
        throw new BadRequestException("No name is specified. Make sure '" + NAME_PROPERTY_NAME + "' property is present and has not empty value");
    }
    Requirement similar = getInheritedOrSameIdSimilar(buildType, serviceLocator);
    if (inherited != null && inherited && similar != null) {
        return similar;
    }
    if (similar != null && id != null && id.equals(similar.getId())) {
        // todo
        return similar;
    }
    @NotNull final RequirementFactory factory = serviceLocator.getSingletonService(RequirementFactory.class);
    String forcedId = null;
    // special case for "overriden" entities
    if (id != null) {
        for (Requirement item : buildType.getRequirements()) {
            if (id.equals(item.getId())) {
                forcedId = id;
                break;
            }
        }
    }
    Requirement requirementToAdd;
    if (forcedId != null) {
        requirementToAdd = factory.createRequirement(forcedId, propertyName, propertiesMap.get(NAME_PROPERTY_VALUE), getSubmittedType());
    } else {
        requirementToAdd = factory.createRequirement(propertyName, propertiesMap.get(NAME_PROPERTY_VALUE), getSubmittedType());
    }
    String requirementId = requirementToAdd.getId();
    if (requirementId == null && disabled != null) {
        // throw exception before adding requirement to the model
        throw new OperationException("Cannot set disabled state for an entity without id");
    }
    buildType.addRequirement(requirementToAdd);
    if (disabled != null) {
        buildType.setEnabled(requirementId, !disabled);
    }
    return requirementToAdd;
}
Also used : Requirement(jetbrains.buildServer.requirements.Requirement) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) RequirementFactory(jetbrains.buildServer.serverSide.RequirementFactory) NotNull(org.jetbrains.annotations.NotNull) OperationException(jetbrains.buildServer.server.rest.errors.OperationException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Requirement (jetbrains.buildServer.requirements.Requirement)19 Test (org.testng.annotations.Test)10 ApiOperation (io.swagger.annotations.ApiOperation)6 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)6 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)5 TestFor (jetbrains.buildServer.util.TestFor)3 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)2 NotNull (org.jetbrains.annotations.NotNull)2 ServiceLocator (jetbrains.buildServer.ServiceLocator)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 OperationException (jetbrains.buildServer.server.rest.errors.OperationException)1 Build (jetbrains.buildServer.server.rest.model.build.Build)1 RequirementFactory (jetbrains.buildServer.serverSide.RequirementFactory)1 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)1 SUser (jetbrains.buildServer.users.SUser)1