Search in sources :

Example 1 with CyclicDependencyFoundException

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));
}
Also used : DependencyFactory(jetbrains.buildServer.serverSide.dependency.DependencyFactory) BuildTypeFinder(jetbrains.buildServer.server.rest.data.BuildTypeFinder) CyclicDependencyFoundException(jetbrains.buildServer.serverSide.dependency.CyclicDependencyFoundException) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) Dependency(jetbrains.buildServer.serverSide.dependency.Dependency) HashMap(java.util.HashMap) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CyclicDependencyFoundException

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;
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) CyclicDependencyFoundException(jetbrains.buildServer.serverSide.dependency.CyclicDependencyFoundException) Fields(jetbrains.buildServer.server.rest.model.Fields) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BuildType(jetbrains.buildServer.server.rest.model.buildType.BuildType) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)2 CyclicDependencyFoundException (jetbrains.buildServer.serverSide.dependency.CyclicDependencyFoundException)2 ApiOperation (io.swagger.annotations.ApiOperation)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BuildTypeFinder (jetbrains.buildServer.server.rest.data.BuildTypeFinder)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 Fields (jetbrains.buildServer.server.rest.model.Fields)1 BuildType (jetbrains.buildServer.server.rest.model.buildType.BuildType)1 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)1 Dependency (jetbrains.buildServer.serverSide.dependency.Dependency)1 DependencyFactory (jetbrains.buildServer.serverSide.dependency.DependencyFactory)1 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)1 NotNull (org.jetbrains.annotations.NotNull)1