use of jetbrains.buildServer.serverSide.dependency.CyclicDependencyFoundException in project teamcity-rest by JetBrains.
the class PropEntitySnapshotDep method addTo.
@NotNull
@Override
public Dependency addTo(@NotNull final BuildTypeSettingsEx buildType, @NotNull final ServiceLocator serviceLocator) {
if (!SNAPSHOT_DEPENDENCY_TYPE_NAME.equals(type)) {
throw new BadRequestException("Snapshot dependency should have type '" + SNAPSHOT_DEPENDENCY_TYPE_NAME + "'.");
}
final Map<String, String> propertiesMap = properties == null ? Collections.emptyMap() : properties.getMap();
// compatibility mode with pre-8.0
final String buildTypeIdFromProperty = propertiesMap.get(NAME_SOURCE_BUILD_TYPE_ID);
String buildTypeIdDependOn = getBuildTypeExternalIdForDependency(sourceBuildType, buildTypeIdFromProperty, serviceLocator);
BuildTypeUtil.checkCanUseBuildTypeAsDependency(buildTypeIdDependOn, serviceLocator);
Dependency similar = getInheritedOrSameIdSimilar(buildType, serviceLocator);
if (inherited != null && inherited && similar != null) {
return similar;
}
if (similar != null && id != null && id.equals(similar.getDependOnExternalId())) {
// todo
return similar;
}
// todo: (TeamCity) for some reason API does not report adding dependency with same id. Seems like it just ignores the call
if (getSnapshotDepOrNull(buildType, buildTypeIdDependOn) != null) {
throw new BadRequestException("Snapshot dependency on build type with id '" + buildTypeIdDependOn + "' already exists.");
}
final Dependency result = serviceLocator.getSingletonService(DependencyFactory.class).createDependency(buildTypeIdDependOn);
for (Map.Entry<String, String> property : propertiesMap.entrySet()) {
if (!NAME_SOURCE_BUILD_TYPE_ID.equals(property.getKey())) {
setDependencyOption(property.getKey(), property.getValue(), result);
}
}
try {
buildType.addDependency(result);
} catch (CyclicDependencyFoundException e) {
throw new BadRequestException("Error adding dependency", e);
}
return getSnapshotDep(buildType, result.getDependOnExternalId(), serviceLocator.getSingletonService(BuildTypeFinder.class));
}
use of jetbrains.buildServer.serverSide.dependency.CyclicDependencyFoundException in project teamcity-rest by JetBrains.
the class ProjectRequest method setDefaultTemplate.
@PUT
@Path("/{projectLocator}/defaultTemplate")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update the default template of the matching project.", nickname = "setDefaultTemplate")
public BuildType setDefaultTemplate(@ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator, BuildType defaultTemplate, @QueryParam("fields") String fields) {
ProjectEx project = (ProjectEx) myProjectFinder.getItem(projectLocator, true);
if (defaultTemplate == null)
throw new BadRequestException("No payload found while template is expected");
BuildTypeOrTemplate newDefaultTemplate = defaultTemplate.getBuildTypeFromPosted(myBuildTypeFinder);
BuildTypeTemplate result = newDefaultTemplate.getTemplate();
if (result == null) {
throw new BadRequestException("Found build type when template is expected: " + LogUtil.describe(newDefaultTemplate.getBuildType()));
}
Boolean inherited = newDefaultTemplate.isInherited();
BuildTypeTemplate currentDefaultTemplate = project.getDefaultTemplate();
if (inherited == null || !inherited || (currentDefaultTemplate != null && !currentDefaultTemplate.getInternalId().equals(newDefaultTemplate.getInternalId()))) {
try {
project.setDefaultTemplate(result);
} catch (CyclicDependencyFoundException e) {
throw new BadRequestException(e.getMessage());
}
project.schedulePersisting("Default template changed");
}
BuildType template = Project.getDefaultTemplate(project, new Fields(fields), myBeanContext);
if (template == null)
throw new NotFoundException("No default template present");
return template;
}
Aggregations