use of jetbrains.buildServer.serverSide.SBuildType 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.SBuildType 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));
}
use of jetbrains.buildServer.serverSide.SBuildType in project teamcity-rest by JetBrains.
the class RootApiRequest method serveBuildFieldShort.
@GET
@ApiOperation(value = "serveBuildFieldShort", hidden = true)
@Path("/{projectLocator}/{btLocator}/{buildLocator}/{field}")
@Produces("text/plain")
public String serveBuildFieldShort(@PathParam("projectLocator") String projectLocator, @PathParam("btLocator") String buildTypeLocator, @PathParam("buildLocator") String buildLocator, @PathParam("field") String field) {
SProject project = myProjectFinder.getItem(projectLocator);
SBuildType buildType = myBuildTypeFinder.getBuildType(project, buildTypeLocator, false);
final BuildPromotion buildPromotion = myBuildFinder.getBuildPromotion(buildType, buildLocator);
return Build.getFieldValue(buildPromotion, field, new BeanContext(myDataProvider.getBeanFactory(), myDataProvider.getServer(), myApiUrlBuilder));
}
use of jetbrains.buildServer.serverSide.SBuildType in project teamcity-rest by JetBrains.
the class Investigation method getFromPostedAndApply.
@NotNull
public List<InvestigationWrapper> getFromPostedAndApply(@NotNull final ServiceLocator serviceLocator, final boolean allowMultipleResult) {
checkIsValid();
if (target == null) {
throw new BadRequestException("Invalid 'investigation' entity: 'target' should be specified");
}
ProblemTarget.ProblemTargetData targetData;
try {
targetData = target.getFromPosted(serviceLocator);
} catch (BadRequestException e) {
throw new BadRequestException("Invalid 'investigation' entity: " + e.getMessage());
}
ResponsibilityEntry entry = new ResponsibilityEntryEx(TypedFinderBuilder.getEnumValue(state, ResponsibilityEntry.State.class), assignee.getFromPosted(serviceLocator.getSingletonService(UserFinder.class)), serviceLocator.getSingletonService(UserFinder.class).getCurrentUser(), new Date(), assignment == null || assignment.getTextFromPosted() == null ? "" : assignment.getTextFromPosted(), resolution.getFromPostedForInvestigation(serviceLocator));
ResponsibilityFacadeEx responsibilityFacade = serviceLocator.getSingletonService(ResponsibilityFacadeEx.class);
InvestigationFinder investigationFinder = serviceLocator.findSingletonService(InvestigationFinder.class);
assert investigationFinder != null;
List<InvestigationWrapper> resultEntries = new ArrayList<>(1);
if (targetData.isAnyProblem()) {
List<BuildType> buildTypesFromPosted = scope.getBuildTypesFromPosted(serviceLocator);
if (!allowMultipleResult && buildTypesFromPosted.size() > 1) {
throw new OnlySingleEntitySupportedException("Invalid 'scope' entity: for this request only single buildType is supported within 'buildTypes' entity");
}
for (BuildType buildType : buildTypesFromPosted) {
responsibilityFacade.setBuildTypeResponsibility(buildType, entry);
resultEntries.add(investigationFinder.getItem(InvestigationFinder.getLocator((SBuildType) buildType)));
}
} else {
if (scope.buildTypes != null) {
throw new BadRequestException("Invalid 'investigation' entity: Invalid 'scope' entity: 'buildTypes' should not be specified for not buildType-level investigation");
}
SProject project = scope.getProjectFromPosted(serviceLocator);
List<STest> tests = targetData.getTests();
if (!tests.isEmpty()) {
if (!allowMultipleResult && tests.size() > 1) {
throw new OnlySingleEntitySupportedException("Invalid 'target' entity: for this request only single test is supported within 'tests' entity");
}
responsibilityFacade.setTestNameResponsibility(tests.stream().map(sTest -> sTest.getName()).distinct().collect(Collectors.toList()), project.getProjectId(), entry);
tests.stream().map(test -> // only one item should be found in the project
investigationFinder.getItem(InvestigationFinder.getLocatorForTest(test.getTestNameId(), project))).distinct().forEachOrdered(resultEntries::add);
}
List<Long> problems = targetData.getProblemIds();
if (!problems.isEmpty()) {
if (!allowMultipleResult && problems.size() > 1) {
throw new OnlySingleEntitySupportedException("Invalid 'target' entity: for this request only single problem is supported within 'problems' entity");
}
responsibilityFacade.setBuildProblemResponsibility(// seems like only id is used inside
problems.stream().distinct().map(problemId -> ProblemWrapper.getBuildProblemInfo(problemId.intValue(), project.getProjectId())).collect(Collectors.toList()), project.getProjectId(), entry);
problems.stream().distinct().map(problemId -> // only one item should be found in the project
investigationFinder.getItem(InvestigationFinder.getLocatorForProblem(problemId.intValue(), project))).forEachOrdered(resultEntries::add);
}
}
if (!allowMultipleResult && resultEntries.size() != 1) {
throw new BadRequestException("Invalid 'investigation' entity: Invalid 'target' entity: found " + resultEntries.size() + " result entities, while exactly one is required");
}
return resultEntries;
}
use of jetbrains.buildServer.serverSide.SBuildType in project teamcity-rest by JetBrains.
the class TestScopeFilterProducer method createFromLocator.
public TestScopeFilter createFromLocator(@NotNull Locator locator) {
locator.addSupportedDimensions(SUPPORTED_DIMENSIONS);
List<Filter<STestRun>> conditions = new ArrayList<>();
String suiteConditionDef = locator.getSingleDimensionValue("suite");
if (suiteConditionDef != null) {
ValueCondition condition = ParameterCondition.createValueCondition(suiteConditionDef);
conditions.add(item -> condition.matches(item.getTest().getName().getSuite()));
}
String packageConditionDef = locator.getSingleDimensionValue("package");
if (packageConditionDef != null) {
ValueCondition condition = ParameterCondition.createValueCondition(packageConditionDef);
conditions.add(item -> condition.matches(item.getTest().getName().getPackageName()));
}
String classConditionDef = locator.getSingleDimensionValue("class");
if (classConditionDef != null) {
ValueCondition condition = ParameterCondition.createValueCondition(classConditionDef);
conditions.add(item -> condition.matches(item.getTest().getName().getClassName()));
}
String buildTypeConditionDef = locator.getSingleDimensionValue("buildType");
if (buildTypeConditionDef != null) {
ItemFilter<BuildTypeOrTemplate> filter = myBuildTypefinder.getFilter(buildTypeConditionDef);
conditions.add(item -> {
SBuildType bt = item.getBuild().getBuildType();
if (bt == null)
return false;
return filter.isIncluded(new BuildTypeOrTemplate(bt));
});
}
return new TestScopeFilterImpl(conditions, StringUtil.join(",", suiteConditionDef, packageConditionDef, classConditionDef, buildTypeConditionDef));
}
Aggregations