Search in sources :

Example 1 with BuildTypeOrTemplate

use of jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate in project teamcity-rest by JetBrains.

the class VcsRootInstanceFinder method getPrefilteredItems.

@NotNull
@Override
public ItemHolder<VcsRootInstance> getPrefilteredItems(@NotNull Locator locator) {
    setLocatorDefaults(locator);
    // should check it not in Filter as it considers current scope
    Boolean versionedSettingsUsagesOnly = locator.getSingleDimensionValueAsBoolean(HAS_VERSIONED_SETTINGS_ONLY);
    final String build = locator.getSingleDimensionValue(BUILD);
    if (build != null) {
        Stream<VcsRootInstance> vcsRootInstancesByBuilds = getVcsRootInstancesByBuilds(build);
        if (BooleanUtils.isTrue(versionedSettingsUsagesOnly)) {
            vcsRootInstancesByBuilds = vcsRootInstancesByBuilds.filter(vcsRootInstance -> vcsRootInstance.equals(myVersionedSettingsManager.getVersionedSettingsVcsRootInstance(vcsRootInstance.getParent().getProject())));
        } else if (BooleanUtils.isFalse(versionedSettingsUsagesOnly)) {
            vcsRootInstancesByBuilds = vcsRootInstancesByBuilds.filter(vcsRootInstance -> !vcsRootInstance.equals(myVersionedSettingsManager.getVersionedSettingsVcsRootInstance(vcsRootInstance.getParent().getProject())));
        }
        return FinderDataBinding.getItemHolder(vcsRootInstancesByBuilds);
    }
    final String vcsRootLocator = locator.getSingleDimensionValue(VCS_ROOT_DIMENSION);
    if (vcsRootLocator != null) {
        final List<SVcsRoot> vcsRoots = myVcsRootFinder.getItemsNotEmpty(vcsRootLocator).myEntries;
        final Set<VcsRootInstance> result = new TreeSet<>(VCS_ROOT_INSTANCE_COMPARATOR);
        final String buildTypesLocator = locator.getSingleDimensionValue(BUILD_TYPE);
        Predicate<SBuildType> filter;
        Set<SProject> projects;
        if (buildTypesLocator != null) {
            if (versionedSettingsUsagesOnly == null || !versionedSettingsUsagesOnly) {
                // is used below in the same condition
                ItemFilter<BuildTypeOrTemplate> buildTypeFilter = myBuildTypeFinder.getFilter(buildTypesLocator);
                filter = sBuildType -> buildTypeFilter.isIncluded(new BuildTypeOrTemplate(sBuildType));
            } else {
                filter = (a) -> true;
            }
            if (versionedSettingsUsagesOnly == null || versionedSettingsUsagesOnly) {
                // is used below in the same condition
                projects = myBuildTypeFinder.getItemsNotEmpty(buildTypesLocator).myEntries.stream().map(BuildTypeOrTemplate::getProject).collect(Collectors.toSet());
            } else {
                projects = null;
            }
        } else {
            filter = (a) -> true;
            projects = null;
        }
        filterOutUnrelatedWithoutParameterResolution(locator, vcsRoots);
        for (SVcsRoot vcsRoot : vcsRoots) {
            if (versionedSettingsUsagesOnly == null || !versionedSettingsUsagesOnly) {
                vcsRoot.getUsagesInConfigurations().stream().filter(filter).map(buildType -> buildType.getVcsRootInstanceForParent(vcsRoot)).filter(// minor performance optimization not to return roots which will be filtered in the filter
                rootInstance -> ((rootInstance != null) && hasPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, rootInstance))).forEach(result::add);
            }
            if (versionedSettingsUsagesOnly == null || versionedSettingsUsagesOnly) {
                Set<SProject> projectsBySettingsRoot = myVersionedSettingsManager.getProjectsBySettingsRoot(vcsRoot);
                result.addAll(getSettingsRootInstances(projects == null ? projectsBySettingsRoot : CollectionsUtil.intersect(projectsBySettingsRoot, projects)));
            }
        }
        return getItemHolder(result);
    }
    final String buildTypesLocator = locator.getSingleDimensionValue(BUILD_TYPE);
    if (buildTypesLocator != null) {
        return getItemHolder(getInstances(buildTypesLocator, versionedSettingsUsagesOnly));
    }
    // todo: support multiple here for "from all not archived projects" case
    final String projectLocator = locator.getSingleDimensionValue(AFFECTED_PROJECT);
    if (projectLocator != null) {
        return getItemHolder(getVcsRootInstancesUnderProject(myProjectFinder.getItem(projectLocator), versionedSettingsUsagesOnly));
    }
    // todo: (TeamCity) open API is there a better way to do this?
    // if reworked, can use checkPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, item);
    // when implemented, can also add to jetbrains.buildServer.usageStatistics.impl.providers.StaticServerUsageStatisticsProvider.publishNumberOfVcsRoots()
    final Set<VcsRootInstance> result = new TreeSet<>(VCS_ROOT_INSTANCE_COMPARATOR);
    if (versionedSettingsUsagesOnly == null || !versionedSettingsUsagesOnly) {
        for (SBuildType buildType : myProjectManager.getAllBuildTypes()) {
            if (myPermissionChecker.isPermissionGranted(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, buildType.getProjectId())) {
                result.addAll(buildType.getVcsRootInstances());
            }
        }
    }
    if (versionedSettingsUsagesOnly == null || versionedSettingsUsagesOnly) {
        result.addAll(getSettingsRootInstances(myProjectManager.getProjects()));
    }
    return getItemHolder(result);
}
Also used : java.util(java.util) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) LocatorName(jetbrains.buildServer.server.rest.swagger.constants.LocatorName) LocatorResource(jetbrains.buildServer.server.rest.swagger.annotations.LocatorResource) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) BooleanUtils(org.apache.commons.lang3.BooleanUtils) VersionedSettingsManager(jetbrains.buildServer.serverSide.versionedSettings.VersionedSettingsManager) ParametersProvider(jetbrains.buildServer.parameters.ParametersProvider) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) LocatorDimensionDataType(jetbrains.buildServer.server.rest.swagger.constants.LocatorDimensionDataType) AbstractMapParametersProvider(jetbrains.buildServer.parameters.impl.AbstractMapParametersProvider) VcsRoot(jetbrains.buildServer.server.rest.model.change.VcsRoot) ProjectManager(jetbrains.buildServer.serverSide.ProjectManager) SBuildType(jetbrains.buildServer.serverSide.SBuildType) Logger(com.intellij.openapi.diagnostic.Logger) CollectionsUtil(jetbrains.buildServer.util.CollectionsUtil) PagerData(jetbrains.buildServer.server.rest.model.PagerData) Constants(jetbrains.buildServer.server.rest.request.Constants) ServiceLocator(jetbrains.buildServer.ServiceLocator) Predicate(java.util.function.Predicate) jetbrains.buildServer.vcs(jetbrains.buildServer.vcs) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) CommonLocatorDimensionsList(jetbrains.buildServer.server.rest.swagger.constants.CommonLocatorDimensionsList) Stream(java.util.stream.Stream) LocatorDimension(jetbrains.buildServer.server.rest.swagger.annotations.LocatorDimension) Permission(jetbrains.buildServer.serverSide.auth.Permission) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull) ReferencesResolverUtil(jetbrains.buildServer.parameters.ReferencesResolverUtil) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) SProject(jetbrains.buildServer.serverSide.SProject) SBuildType(jetbrains.buildServer.serverSide.SBuildType) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with BuildTypeOrTemplate

use of jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate in project teamcity-rest by JetBrains.

the class BuildTypeFinderTest method testBuildTypeLegacyTemplateDimension.

@Test
public void testBuildTypeLegacyTemplateDimension() throws Exception {
    final BuildTypeOrTemplate template = new BuildTypeOrTemplate(createBuildTypeTemplate("template"));
    final BuildTypeOrTemplate buildConf = new BuildTypeOrTemplate(registerTemplateBasedBuildType("buildConf"));
    // noinspection ConstantConditions
    buildConf.getBuildType().attachToTemplate(template.getTemplate());
    check("template:true,id:" + template.getId(), template);
    check("template:true,internalId:" + template.getInternalId(), template);
    check("template:false,id:" + buildConf.getId(), buildConf);
    check("template:false,internalId:" + buildConf.getInternalId(), buildConf);
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Test(org.testng.annotations.Test)

Example 3 with BuildTypeOrTemplate

use of jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate in project teamcity-rest by JetBrains.

the class BuildTypeFinderTest method testProjectItem.

@Test
public void testProjectItem() throws Exception {
    myBuildType.remove();
    final SProject project10 = createProject("p10");
    final SProject project20 = createProject("p20");
    final SProject project10_10 = project10.createProject("p10_10", "xxx");
    final BuildTypeOrTemplate p10_bt10 = new BuildTypeOrTemplate(project10.createBuildType("p10_bt10", "xxx"));
    final BuildTypeOrTemplate p10_bt20 = new BuildTypeOrTemplate(project10.createBuildType("p10_bt20", "p10_bt20"));
    final BuildTypeOrTemplate p10_bt30 = new BuildTypeOrTemplate(project10.createBuildTypeTemplate("p10_bt30", "p10_bt30"));
    final BuildTypeOrTemplate p10_10_bt40 = new BuildTypeOrTemplate(project10_10.createBuildType("p10_10_bt40", "xxx"));
    final BuildTypeOrTemplate p20_bt50 = new BuildTypeOrTemplate(project20.createBuildType("p20_bt50", "xxx"));
    PagedSearchResult<BuildTypeOrTemplate> result = myBuildTypeFinder.getBuildTypesPaged(project10, null, true);
    assertEquals(String.valueOf(result.myEntries), 2, result.myEntries.size());
    result = myBuildTypeFinder.getBuildTypesPaged(project10, null, false);
    assertEquals(String.valueOf(result.myEntries), 1, result.myEntries.size());
    result = myBuildTypeFinder.getBuildTypesPaged(project10, "name:xxx", true);
    assertEquals(Arrays.asList(p10_bt10), result.myEntries);
    result = myBuildTypeFinder.getBuildTypesPaged(project10, "templateFlag:any", false);
    assertEquals(3, result.myEntries.size());
    result = myBuildTypeFinder.getBuildTypesPaged(project10, "project:$any", true);
    assertEquals(getDescription(result.myEntries), 4, result.myEntries.size());
    result = myBuildTypeFinder.getBuildTypesPaged(project10, "project:$any,affectedProject:(id:" + project10.getExternalId() + ")", true);
    assertEquals(getDescription(result.myEntries), 3, result.myEntries.size());
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Test(org.testng.annotations.Test)

Example 4 with BuildTypeOrTemplate

use of jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate in project teamcity-rest by JetBrains.

the class BuildTypeFinderTest method testBuildTypeTemplates.

@Test
public void testBuildTypeTemplates() throws Exception {
    final BuildTypeOrTemplate template = new BuildTypeOrTemplate(createBuildTypeTemplate("template"));
    final BuildTypeOrTemplate buildConf = new BuildTypeOrTemplate(registerTemplateBasedBuildType("buildConf"));
    // noinspection ConstantConditions
    buildConf.getBuildType().attachToTemplate(template.getTemplate());
    check("template:(id:" + template.getTemplate().getExternalId() + "),templateFlag:false", buildConf);
    check("name:" + buildConf.getName() + ",templateFlag:false", buildConf);
    check("name:" + buildConf.getName() + ",templateFlag:true");
    check("name:" + template.getName() + ",templateFlag:false");
    check("name:" + template.getName() + ",templateFlag:true", template);
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Test(org.testng.annotations.Test)

Example 5 with BuildTypeOrTemplate

use of jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate in project teamcity-rest by JetBrains.

the class BuildTypeFinderTest method testSnapshotDependencies.

@Test
public void testSnapshotDependencies() throws Exception {
    final BuildTypeOrTemplate buildConf01 = new BuildTypeOrTemplate(registerBuildType("buildConf01", "project"));
    final BuildTypeOrTemplate buildConf02 = new BuildTypeOrTemplate(registerBuildType("buildConf02", "project"));
    final BuildTypeOrTemplate buildConf1 = new BuildTypeOrTemplate(registerBuildType("buildConf1", "project"));
    final BuildTypeOrTemplate buildConf2 = new BuildTypeOrTemplate(registerBuildType("buildConf2", "project"));
    final BuildTypeOrTemplate buildConf31 = new BuildTypeOrTemplate(registerBuildType("buildConf31", "project"));
    final BuildTypeOrTemplate buildConf32 = new BuildTypeOrTemplate(registerBuildType("buildConf32", "project"));
    final BuildTypeOrTemplate buildConf4 = new BuildTypeOrTemplate(registerBuildType("buildConf4", "project"));
    final BuildTypeOrTemplate buildConf5 = new BuildTypeOrTemplate(registerBuildType("buildConf5", "project"));
    final BuildTypeOrTemplate buildConf6 = new BuildTypeOrTemplate(registerBuildType("buildConf6", "project"));
    addDependency(buildConf6.get(), buildConf5.getBuildType());
    addDependency(buildConf5.get(), buildConf31.getBuildType());
    addDependency(buildConf4.get(), buildConf31.getBuildType());
    addDependency(buildConf4.get(), buildConf32.getBuildType());
    addDependency(buildConf31.get(), buildConf2.getBuildType());
    addDependency(buildConf32.get(), buildConf2.getBuildType());
    addDependency(buildConf2.get(), buildConf1.getBuildType());
    addDependency(buildConf2.get(), buildConf01.getBuildType());
    addDependency(buildConf1.get(), buildConf01.getBuildType());
    addDependency(buildConf1.get(), buildConf02.getBuildType());
    final String baseToLocatorStart1 = "snapshotDependency:(from:(id:" + buildConf4.getId() + ")";
    check(baseToLocatorStart1 + ")");
    check(baseToLocatorStart1 + ",includeInitial:true)", buildConf4);
    check(baseToLocatorStart1 + ",includeInitial:false)");
    check(baseToLocatorStart1 + ",recursive:true)");
    check(baseToLocatorStart1 + ",includeInitial:true,recursive:false)", buildConf4);
    final String baseToLocatorStart2 = "snapshotDependency:(to:(id:" + buildConf4.getId() + ")";
    check(baseToLocatorStart2 + ")", buildConf31, buildConf32, buildConf2, buildConf1, buildConf01, buildConf02);
    check(baseToLocatorStart2 + ",includeInitial:true)", buildConf4, buildConf31, buildConf32, buildConf2, buildConf1, buildConf01, buildConf02);
    check(baseToLocatorStart2 + ",includeInitial:false)", buildConf31, buildConf32, buildConf2, buildConf1, buildConf01, buildConf02);
    check(baseToLocatorStart2 + ",recursive:true)", buildConf31, buildConf32, buildConf2, buildConf1, buildConf01, buildConf02);
    check(baseToLocatorStart2 + ",recursive:false)", buildConf31, buildConf32);
    check(baseToLocatorStart2 + ",includeInitial:true,recursive:true)", buildConf4, buildConf31, buildConf32, buildConf2, buildConf1, buildConf01, buildConf02);
    final String baseToLocatorStart3 = "snapshotDependency:(to:(id:" + buildConf31.getId() + ")";
    check(baseToLocatorStart3 + ")", buildConf2, buildConf1, buildConf01, buildConf02);
    check(baseToLocatorStart3 + ",includeInitial:true)", buildConf31, buildConf2, buildConf1, buildConf01, buildConf02);
    check(baseToLocatorStart3 + ",includeInitial:false)", buildConf2, buildConf1, buildConf01, buildConf02);
    check(baseToLocatorStart3 + ",recursive:true)", buildConf2, buildConf1, buildConf01, buildConf02);
    check(baseToLocatorStart3 + ",recursive:false)", buildConf2);
    check(baseToLocatorStart3 + ",includeInitial:true,recursive:true)", buildConf31, buildConf2, buildConf1, buildConf01, buildConf02);
    final String baseToLocatorStart4 = "snapshotDependency:(from:(id:" + buildConf31.getId() + ")";
    check(baseToLocatorStart4 + ")", buildConf5, buildConf4, buildConf6);
    check(baseToLocatorStart4 + ",includeInitial:true)", buildConf31, buildConf5, buildConf4, buildConf6);
    check(baseToLocatorStart4 + ",includeInitial:false)", buildConf5, buildConf4, buildConf6);
    check(baseToLocatorStart4 + ",recursive:true)", buildConf5, buildConf4, buildConf6);
    check(baseToLocatorStart4 + ",recursive:false)", buildConf5, buildConf4);
    check(baseToLocatorStart4 + ",includeInitial:true,recursive:true)", buildConf31, buildConf5, buildConf4, buildConf6);
    check("snapshotDependency:(from:(id:" + buildConf2.getId() + "),to:(id:" + buildConf31.getId() + "),includeInitial:true)", buildConf31, buildConf2);
    check("snapshotDependency:(from:(id:" + buildConf1.getId() + "),to:(id:" + buildConf4.getId() + "))", buildConf31, buildConf32, buildConf2);
    check("snapshotDependency:(from:(id:" + buildConf1.getId() + "),to:(id:" + buildConf5.getId() + "))", buildConf31, buildConf2);
    check("snapshotDependency:(from:(id:" + buildConf31.getId() + "),to:(id:" + buildConf32.getId() + "))");
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Test(org.testng.annotations.Test)

Aggregations

BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)97 ApiOperation (io.swagger.annotations.ApiOperation)65 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)24 Test (org.testng.annotations.Test)18 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)15 BuildType (jetbrains.buildServer.server.rest.model.buildType.BuildType)14 SArtifactDependency (jetbrains.buildServer.serverSide.artifacts.SArtifactDependency)14 SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)12 NotNull (org.jetbrains.annotations.NotNull)12 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)11 BeanContext (jetbrains.buildServer.server.rest.util.BeanContext)11 Nullable (org.jetbrains.annotations.Nullable)10 BuildTriggerDescriptor (jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor)8 ProjectRequestTest (jetbrains.buildServer.server.rest.request.ProjectRequestTest)8 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)8 Requirement (jetbrains.buildServer.requirements.Requirement)7 Dependency (jetbrains.buildServer.serverSide.dependency.Dependency)6 Logger (com.intellij.openapi.diagnostic.Logger)5 ServiceLocator (jetbrains.buildServer.ServiceLocator)5 Fields (jetbrains.buildServer.server.rest.model.Fields)5