use of jetbrains.buildServer.vcs.VcsManager in project teamcity-rest by JetBrains.
the class BuildTypeFinder method getPrefilteredItems.
@NotNull
@Override
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 getItemHolder(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 FinderDataBinding.getItemHolder(buildTypes);
}
*/
final String snapshotDependencies = locator.getSingleDimensionValue(SNAPSHOT_DEPENDENCY);
if (snapshotDependencies != null) {
final GraphFinder<BuildTypeOrTemplate> graphFinder = new GraphFinder<BuildTypeOrTemplate>(this, new SnapshotDepsTraverser(myPermissionChecker));
return getItemHolder(graphFinder.getItems(snapshotDependencies).myEntries);
}
final String artifactDependencies = locator.getSingleDimensionValue(ARTIFACT_DEPENDENCY);
if (artifactDependencies != null) {
final GraphFinder<BuildTypeOrTemplate> graphFinder = new GraphFinder<BuildTypeOrTemplate>(this, new ArtifactDepsTraverser(myPermissionChecker));
return getItemHolder(graphFinder.getItems(artifactDependencies).myEntries);
}
final String vcsRoot = locator.getSingleDimensionValue(VCS_ROOT_DIMENSION);
if (vcsRoot != null) {
final Set<SVcsRoot> vcsRoots = new HashSet<SVcsRoot>(myServiceLocator.getSingletonService(VcsRootFinder.class).getItems(vcsRoot).myEntries);
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 getItemHolder(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).myEntries);
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 getItemHolder(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 getItemHolder(BuildTypes.fromBuildTypes(buildTemplate.getUsages()));
}
List<SProject> projects = null;
final String projectLocator = locator.getSingleDimensionValue(DIMENSION_PROJECT);
if (projectLocator != null) {
projects = myProjectFinder.getItems(projectLocator).myEntries;
}
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 getItemHolder(result);
}
Aggregations