Search in sources :

Example 1 with SBuildType

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);
}
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 SBuildType

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));
}
Also used : User(jetbrains.buildServer.users.User) SBuildType(jetbrains.buildServer.serverSide.SBuildType) ProblemWrapper(jetbrains.buildServer.server.rest.data.problem.ProblemWrapper) STest(jetbrains.buildServer.serverSide.STest) SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with SBuildType

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));
}
Also used : BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) SBuildType(jetbrains.buildServer.serverSide.SBuildType) SProject(jetbrains.buildServer.serverSide.SProject) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with SBuildType

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;
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) User(jetbrains.buildServer.server.rest.model.user.User) Date(java.util.Date) InvestigationFinder(jetbrains.buildServer.server.rest.data.investigations.InvestigationFinder) ArrayList(java.util.ArrayList) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ResponsibilityEntryEx(jetbrains.buildServer.responsibility.ResponsibilityEntryEx) XmlType(javax.xml.bind.annotation.XmlType) Comment(jetbrains.buildServer.server.rest.model.Comment) STest(jetbrains.buildServer.serverSide.STest) TypedFinderBuilder(jetbrains.buildServer.server.rest.data.TypedFinderBuilder) InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) Api(io.swagger.annotations.Api) SBuildType(jetbrains.buildServer.serverSide.SBuildType) ModelDescription(jetbrains.buildServer.server.rest.swagger.annotations.ModelDescription) XmlAttribute(javax.xml.bind.annotation.XmlAttribute) TeamCityProperties(jetbrains.buildServer.serverSide.TeamCityProperties) ProblemWrapper(jetbrains.buildServer.server.rest.data.problem.ProblemWrapper) ServiceLocator(jetbrains.buildServer.ServiceLocator) BuildType(jetbrains.buildServer.BuildType) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) ValueWithDefault(jetbrains.buildServer.server.rest.util.ValueWithDefault) Collectors(java.util.stream.Collectors) List(java.util.List) ResponsibilityEntry(jetbrains.buildServer.responsibility.ResponsibilityEntry) Resolution(jetbrains.buildServer.server.rest.model.problem.Resolution) ResponsibilityFacadeEx(jetbrains.buildServer.responsibility.ResponsibilityFacadeEx) SProject(jetbrains.buildServer.serverSide.SProject) UserFinder(jetbrains.buildServer.server.rest.data.UserFinder) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) NotNull(org.jetbrains.annotations.NotNull) ApiModelProperty(io.swagger.annotations.ApiModelProperty) InvestigationRequest(jetbrains.buildServer.server.rest.request.InvestigationRequest) XmlElement(javax.xml.bind.annotation.XmlElement) InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) ResponsibilityFacadeEx(jetbrains.buildServer.responsibility.ResponsibilityFacadeEx) ArrayList(java.util.ArrayList) ResponsibilityEntryEx(jetbrains.buildServer.responsibility.ResponsibilityEntryEx) InvestigationFinder(jetbrains.buildServer.server.rest.data.investigations.InvestigationFinder) SProject(jetbrains.buildServer.serverSide.SProject) Date(java.util.Date) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ResponsibilityEntry(jetbrains.buildServer.responsibility.ResponsibilityEntry) SBuildType(jetbrains.buildServer.serverSide.SBuildType) BuildType(jetbrains.buildServer.BuildType) STest(jetbrains.buildServer.serverSide.STest) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with SBuildType

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));
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Filter(jetbrains.buildServer.util.filters.Filter) SBuildType(jetbrains.buildServer.serverSide.SBuildType) ArrayList(java.util.ArrayList)

Aggregations

SBuildType (jetbrains.buildServer.serverSide.SBuildType)7 SProject (jetbrains.buildServer.serverSide.SProject)5 ServiceLocator (jetbrains.buildServer.ServiceLocator)4 NotNull (org.jetbrains.annotations.NotNull)4 Collectors (java.util.stream.Collectors)3 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)3 STest (jetbrains.buildServer.serverSide.STest)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 UserFinder (jetbrains.buildServer.server.rest.data.UserFinder)2 ProblemWrapper (jetbrains.buildServer.server.rest.data.problem.ProblemWrapper)2 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)2 Fields (jetbrains.buildServer.server.rest.model.Fields)2 BeanContext (jetbrains.buildServer.server.rest.util.BeanContext)2 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)2 ProjectManager (jetbrains.buildServer.serverSide.ProjectManager)2 Nullable (org.jetbrains.annotations.Nullable)2 Logger (com.intellij.openapi.diagnostic.Logger)1 Api (io.swagger.annotations.Api)1