use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.
the class VcsRootFinder method getPrefilteredItems.
@NotNull
@Override
public ItemHolder<SVcsRoot> getPrefilteredItems(@NotNull Locator locator) {
final String affectedProjectLocator = locator.getSingleDimensionValue(AFFECTED_PROJECT);
if (affectedProjectLocator != null) {
List<SProject> projects = myProjectFinder.getItems(affectedProjectLocator).myEntries;
projects.forEach(project -> myPermissionChecker.checkProjectPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, project.getProjectId()));
return FinderDataBinding.getItemHolder(projects.stream().flatMap(p -> p.getVcsRoots().stream()).collect(Collectors.toSet()));
}
final String projectLocator = locator.getSingleDimensionValue(PROJECT);
if (projectLocator != null) {
List<SProject> projects = myProjectFinder.getItemsNotEmpty(projectLocator).myEntries;
projects.forEach(project -> myPermissionChecker.checkProjectPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, project.getProjectId()));
// consistent with Project.java:183
return FinderDataBinding.getItemHolder(projects.stream().flatMap(p -> p.getOwnVcsRoots().stream()));
}
final List<SVcsRoot> allRegisteredVcsRoots = myVcsManager.getAllRegisteredVcsRoots();
final List<SVcsRoot> result = new ArrayList<SVcsRoot>(allRegisteredVcsRoots.size());
for (SVcsRoot root : allRegisteredVcsRoots) {
try {
checkPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, root);
result.add(root);
} catch (AuthorizationFailedException e) {
// ignore
}
}
return getItemHolder(result);
}
use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.
the class AgentPoolFinder method getPoolProjects.
// todo: TeamCity API: what is the due way to do this? http://youtrack.jetbrains.com/issue/TW-33307
/**
* Gets all projects associated with the specified pool.
*/
@NotNull
public List<SProject> getPoolProjects(@NotNull final AgentPool agentPool) {
final Set<String> projectIds = myAgentPoolManager.getPoolProjects(agentPool.getAgentPoolId());
final ProjectManager projectManager = myServiceLocator.getSingletonService(ProjectManager.class);
final List<SProject> result = new ArrayList<SProject>(projectIds.size());
for (String projectId : projectIds) {
final SProject project = projectManager.findProjectById(projectId);
if (project != null) {
result.add(project);
} else {
// todo: include not present projects into the list
}
}
return result;
}
use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.
the class PermissionAssignmentFinder method getPermissions.
@NotNull
private FinderDataBinding.ItemHolder<PermissionAssignmentData> getPermissions(@NotNull final TypedFinderBuilder.DimensionObjects dimensions, @NotNull final AuthorityHolder authorityHolder, @NotNull final ServiceLocator serviceLocator) {
/* The rest of the code in this method is mostly performance optimization producing the same results (with possibly changed sorting).
if (true) {
List<Permission> globalPermissions = authorityHolder.getGlobalPermissions().toList();
Set<Permission> globalPermissionsSet = new HashSet<>(globalPermissions); //TeamCity API issue: this set is used to exclude global permissions from project-level ones
return FinderDataBinding.getItemHolder(Stream.concat(
globalPermissions.stream().map(p -> new PermissionAssignmentData(p)),
authorityHolder.getProjectsPermissions().entrySet().stream().flatMap(
entry -> entry.getValue().toList().stream().filter(p -> !globalPermissionsSet.contains(p)).map(p -> new PermissionAssignmentData(p, entry.getKey())))));
}
*/
List<Permission> permissions_raw = dimensions.get(PERMISSION);
List<List<SProject>> projects_raw = dimensions.get(PROJECT);
if (projects_raw != null && !projects_raw.isEmpty() && projects_raw.size() > 1) {
throw new BadRequestException("Multiple projects dimensions are not supported");
}
@Nullable List<SProject> projects = projects_raw == null || projects_raw.isEmpty() ? null : projects_raw.get(0);
if (permissions_raw != null && !permissions_raw.isEmpty() && permissions_raw.size() > 1) {
throw new BadRequestException("Multiple permissions dimensions are not supported");
}
// permissions_raw is ANDed, permissions is ORed, but so far it is not supported: todo implement
List<Permission> permissions = permissions_raw;
Stream<PermissionAssignmentData> result = Stream.empty();
List<Boolean> global_raw = dimensions.get(GLOBAL);
if (global_raw != null && !global_raw.isEmpty() && global_raw.size() > 1) {
throw new BadRequestException("Multiple global dimensions are not supported");
}
Boolean global = global_raw == null ? null : global_raw.get(0);
if ((permissions == null || permissions.isEmpty())) {
if (projects == null) {
if (global == null || global) {
result = Stream.concat(result, authorityHolder.getGlobalPermissions().toList().stream().map(p -> new PermissionAssignmentData(p)));
}
if (global == null || !global) {
result = Stream.concat(result, authorityHolder.getProjectsPermissions().entrySet().stream().flatMap(entry -> entry.getValue().toList().stream().filter(p -> p.isProjectAssociationSupported()).map(p -> new PermissionAssignmentData(p, entry.getKey()))));
}
return FinderDataBinding.getItemHolder(result);
}
if (global == null || global) {
result = Stream.concat(result, authorityHolder.getGlobalPermissions().toList().stream().filter(p -> p.isProjectAssociationSupported()).map(p -> new PermissionAssignmentData(p)));
}
if (global == null || !global) {
result = Stream.concat(result, projects.stream().flatMap(project -> {
Permissions projectPermissions = authorityHolder.getProjectsPermissions().get(project.getProjectId());
return projectPermissions == null ? Stream.empty() : projectPermissions.toList().stream().filter(p -> p.isProjectAssociationSupported()).map(p -> new PermissionAssignmentData(p, project.getProjectId()));
}));
}
return FinderDataBinding.getItemHolder(result);
}
if (projects == null) {
if (global == null || global) {
result = Stream.concat(result, permissions.stream().filter(p -> authorityHolder.isPermissionGrantedGlobally(p)).map(p -> new PermissionAssignmentData(p)));
}
if (global == null || !global) {
List<SProject> allProjects = serviceLocator.getSingletonService(ProjectManager.class).getProjects();
result = Stream.concat(result, permissions.stream().filter(p -> p.isProjectAssociationSupported()).flatMap(p -> allProjects.stream().filter(project -> {
Permissions projectPermissions = authorityHolder.getProjectsPermissions().get(project.getProjectId());
return projectPermissions != null && projectPermissions.contains(p);
}).map(project -> new PermissionAssignmentData(p, project.getProjectId()))));
}
return FinderDataBinding.getItemHolder(result);
}
if (global == null || global) {
result = Stream.concat(result, permissions.stream().filter(p -> p.isProjectAssociationSupported()).filter(p -> authorityHolder.isPermissionGrantedGlobally(p)).map(p -> new PermissionAssignmentData(p)));
}
if (global == null || !global) {
result = Stream.concat(result, projects.stream().flatMap(project -> permissions.stream().filter(p -> p.isProjectAssociationSupported()).filter(p -> {
Permissions projectPermissions = authorityHolder.getProjectsPermissions().get(project.getProjectId());
return projectPermissions != null && projectPermissions.contains(p);
}).map(p -> new PermissionAssignmentData(p, project.getProjectId()))));
}
return FinderDataBinding.getItemHolder(result);
}
use of jetbrains.buildServer.serverSide.SProject 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);
}
use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.
the class InvestigationFinder method getPrefilteredItems.
@NotNull
@Override
public ItemHolder<InvestigationWrapper> getPrefilteredItems(@NotNull final Locator locator) {
final String problemDimension = locator.getSingleDimensionValue(PROBLEM_DIMENSION);
if (problemDimension != null) {
final ProblemWrapper problem = myProblemFinder.getItem(problemDimension);
return getItemHolder(problem.getInvestigations());
}
final String testDimension = locator.getSingleDimensionValue(TEST_DIMENSION);
if (testDimension != null) {
final STest test = myTestFinder.getItem(testDimension);
return getItemHolder(getInvestigationWrappers(test));
}
final String buildTypeDimension = locator.getSingleDimensionValue(BUILD_TYPE);
if (buildTypeDimension != null) {
final SBuildType buildType = myBuildTypeFinder.getBuildType(null, buildTypeDimension, false);
return getItemHolder(getInvestigationWrappersForBuildType(buildType));
}
@Nullable User user = null;
final String investigatorDimension = locator.getSingleDimensionValue(ASSIGNEE);
if (investigatorDimension != null) {
user = myUserFinder.getItem(investigatorDimension);
}
final String assignmentProjectDimension = locator.getSingleDimensionValue(ASSIGNMENT_PROJECT);
if (assignmentProjectDimension != null) {
@NotNull final SProject project = myProjectFinder.getItem(assignmentProjectDimension);
return getItemHolder(getInvestigationWrappersForProject(project, user));
}
final String affectedProjectDimension = locator.getSingleDimensionValue(AFFECTED_PROJECT);
if (affectedProjectDimension != null) {
@NotNull final SProject project = myProjectFinder.getItem(affectedProjectDimension);
return getItemHolder(getInvestigationWrappersForProjectWithSubprojects(project, user));
}
if (user != null) {
return getItemHolder(getInvestigationWrappersForProjectWithSubprojects(myProjectFinder.getRootProject(), user));
}
locator.markUnused(ASSIGNEE);
return getItemHolder(getInvestigationWrappersForProjectWithSubprojects(myProjectFinder.getRootProject(), null));
}
Aggregations