in rest-api/src/jetbrains/buildServer/server/rest/data/finder/impl/BuildTypeFinder.java [480:584]
public ItemHolder<BuildTypeOrTemplate> getPrefilteredItems(@NotNull final Locator locator) {
//this should be the first one as the order returned here is important!
final String selectedForUser = locator.getSingleDimensionValue(DIMENSION_SELECTED);
if (selectedForUser != null) {
return ItemHolder.of(getSelectedByUser(locator, selectedForUser));
}
/*
this uses weird order of the results which is probably not what is needed
String buildLocator = locator.getSingleDimensionValue(BUILD);
if (buildLocator != null) {
List<BuildPromotion> builds = myServiceLocator.getSingletonService(BuildPromotionFinder.class).getItems(buildLocator).myEntries;
Set<BuildTypeOrTemplate> buildTypes = builds.stream().map(build -> build.getBuildType()).filter(Objects::nonNull).map(buildType -> new BuildTypeOrTemplate(buildType))
.collect(Collectors.toCollection(() -> new LinkedHashSet<>()));
return ItemHolder.of(buildTypes);
}
*/
final String snapshotDependencies = locator.getSingleDimensionValue(SNAPSHOT_DEPENDENCY);
if (snapshotDependencies != null) {
final GraphFinder<BuildTypeOrTemplate> graphFinder = new GraphFinder<BuildTypeOrTemplate>(this, new SnapshotDepsTraverser(myPermissionChecker));
return ItemHolder.of(graphFinder.getItems(snapshotDependencies).getEntries());
}
final String artifactDependencies = locator.getSingleDimensionValue(ARTIFACT_DEPENDENCY);
if (artifactDependencies != null) {
final GraphFinder<BuildTypeOrTemplate> graphFinder = new GraphFinder<BuildTypeOrTemplate>(this, new ArtifactDepsTraverser(myPermissionChecker));
return ItemHolder.of(graphFinder.getItems(artifactDependencies).getEntries());
}
final String vcsRoot = locator.getSingleDimensionValue(VCS_ROOT_DIMENSION);
if (vcsRoot != null) {
final Set<SVcsRoot> vcsRoots = new HashSet<SVcsRoot>(myServiceLocator.getSingletonService(VcsRootFinder.class).getItems(vcsRoot).getEntries());
final VcsManager vcsManager = myServiceLocator.getSingletonService(VcsManager.class);
final LinkedHashSet<BuildTypeOrTemplate> result = new LinkedHashSet<BuildTypeOrTemplate>();
for (SVcsRoot root : vcsRoots) {
//can optimize more by checking template flag here
result.addAll(BuildTypes.fromBuildTypes(root.getUsagesInConfigurations()));
result.addAll(BuildTypes.fromTemplates(vcsManager.getAllTemplateUsages(root)));
}
//order of the result is not well defined here, might need to resort...
return ItemHolder.of(result);
}
final String vcsRootInstance = locator.getSingleDimensionValue(VCS_ROOT_INSTANCE_DIMENSION);
if (vcsRootInstance != null) {
final Set<jetbrains.buildServer.vcs.VcsRootInstance> vcsRootInstances =
new HashSet<jetbrains.buildServer.vcs.VcsRootInstance>(myServiceLocator.getSingletonService(VcsRootInstanceFinder.class).getItems(vcsRootInstance).getEntries());
final List<SBuildType> result = new ArrayList<SBuildType>();
for (jetbrains.buildServer.vcs.VcsRootInstance root : vcsRootInstances) {
result.addAll(root.getUsages().keySet());
//cannot find templates by instances
}
//order of the result is not well defined here, might need to resort...
return ItemHolder.of(BuildTypes.fromBuildTypes(result));
}
final String templateLocator = locator.getSingleDimensionValue(TEMPLATE_DIMENSION_NAME);
if (templateLocator != null) {
final BuildTypeTemplate buildTemplate;
try {
buildTemplate = getBuildTemplate(null, templateLocator, true);
} catch (NotFoundException e) {
throw new NotFoundException("No templates found by locator '" + templateLocator + "' specified in '" + TEMPLATE_DIMENSION_NAME + "' dimension : " + e.getMessage());
} catch (BadRequestException e) {
throw new BadRequestException(
"Error while searching for templates by locator '" + templateLocator + "' specified in '" + TEMPLATE_DIMENSION_NAME + "' dimension : " + e.getMessage(), e);
}
return ItemHolder.of(BuildTypes.fromBuildTypes(buildTemplate.getUsages()));
}
List<SProject> projects = null;
final String projectLocator = locator.getSingleDimensionValue(DIMENSION_PROJECT);
if (projectLocator != null) {
projects = myProjectFinder.getItems(projectLocator).getEntries();
}
SProject affectedProject = null;
final String affectedProjectLocator = locator.getSingleDimensionValue(AFFECTED_PROJECT);
if (affectedProjectLocator != null) {
affectedProject = myProjectFinder.getItem(affectedProjectLocator);
}
List<BuildTypeOrTemplate> result = new ArrayList<BuildTypeOrTemplate>();
Boolean template = locator.getSingleDimensionValueAsBoolean(TEMPLATE_FLAG_DIMENSION_NAME);
if (template == null || !template) {
if (projects != null) {
result.addAll(getBuildTypes(projects));
} else if (affectedProject != null) {
result.addAll(BuildTypes.fromBuildTypes(affectedProject.getBuildTypes()));
} else {
result.addAll(BuildTypes.fromBuildTypes(myProjectManager.getAllBuildTypes()));
}
}
if (template == null || template) {
if (projects != null) {
result.addAll(getTemplates(projects));
} else if (affectedProject != null) {
result.addAll(BuildTypes.fromTemplates(affectedProject.getBuildTypeTemplates()));
} else {
result.addAll(BuildTypes.fromTemplates(myProjectManager.getAllTemplates()));
}
}
return ItemHolder.of(result);
}