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);
}
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);
}
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);
}
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");
}
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;
}
Aggregations