Search in sources :

Example 6 with Locator

use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.

the class Change method getChangeFromPosted.

@NotNull
public SVcsModification getChangeFromPosted(final ChangeFinder changeFinder) {
    String locatorText;
    if (submittedId != null) {
        if (submittedLocator != null) {
            throw new BadRequestException("Both 'locator' and 'id' attributes are specified. Only one should be present.");
        }
        final Locator locator = Locator.createEmptyLocator().setDimension(ChangeFinder.DIMENSION_ID, String.valueOf(submittedId));
        if (submittedPersonal != null && submittedPersonal) {
            locator.setDimension(ChangeFinder.PERSONAL, "true");
        }
        locatorText = locator.getStringRepresentation();
    } else {
        if (submittedLocator == null) {
            throw new BadRequestException("No change specified. Either 'id' or 'locator' attribute should be present.");
        }
        locatorText = submittedLocator;
    }
    return changeFinder.getItem(locatorText).getSVcsModification();
}
Also used : Locator(jetbrains.buildServer.server.rest.data.Locator) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with Locator

use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.

the class TestScopesRequest method serveGroupedTestOccurrences.

// Very highly experimental
@GET
@Path("/{scopeName}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(hidden = true, value = "highly experimental")
public TestScopes serveGroupedTestOccurrences(@QueryParam("locator") String locatorText, @PathParam("scopeName") String scopeName, @QueryParam("fields") String fields, @Context UriInfo uriInfo, @Context HttpServletRequest request) {
    Set<String> supportedGroupings = new HashSet<>(Arrays.asList("package", "suite", "class"));
    if (!supportedGroupings.contains(scopeName)) {
        throw new BadRequestException("Invalid scope. Only scopes " + String.join(",", supportedGroupings) + " are supported.");
    }
    Locator patchedLocator = new Locator(locatorText);
    patchedLocator.setDimension(TestScopesCollector.SCOPE_TYPE, scopeName);
    PagedSearchResult<TestScope> items = myTestScopesCollector.getPagedItems(patchedLocator);
    PagerData pager = new PagerData(uriInfo.getRequestUriBuilder(), request.getContextPath(), items, locatorText, "locator");
    return new TestScopes(items.myEntries, new Fields(fields), pager, uriInfo, myBeanContext);
}
Also used : ServiceLocator(jetbrains.buildServer.ServiceLocator) Locator(jetbrains.buildServer.server.rest.data.Locator) Fields(jetbrains.buildServer.server.rest.model.Fields) TestScope(jetbrains.buildServer.server.rest.data.problem.scope.TestScope) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) PagerData(jetbrains.buildServer.server.rest.model.PagerData) TestScopes(jetbrains.buildServer.server.rest.model.problem.scope.TestScopes) HashSet(java.util.HashSet) ApiOperation(io.swagger.annotations.ApiOperation)

Example 8 with Locator

use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.

the class ChangeRequest method getUniqueCommiters.

/**
 * Experimental support only!
 * @since 2021.1.1
 */
@GET
@Path("/{changeLocator}/commiters")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get unique commiters of the matching changes.", nickname = "getUniqueCommiters", hidden = true)
public Commiters getUniqueCommiters(@ApiParam(format = LocatorName.CHANGE) @PathParam("changeLocator") String changeLocator, @QueryParam("fields") String fields) {
    Locator patchedChangeLocator = Locator.createPotentiallyEmptyLocator(changeLocator);
    if (!patchedChangeLocator.isAnyPresent(PagerData.COUNT)) {
        String lookupLimit = TeamCityProperties.getProperty("rest.request.changes.committersLookupLimit", DEFAULT_CHANGES_LOOKUP_LIMIT_FOR_COMMITERS);
        patchedChangeLocator.setDimension(PagerData.COUNT, lookupLimit);
    }
    PagedSearchResult<SVcsModificationOrChangeDescriptor> changes = myChangeFinder.getItems(patchedChangeLocator.getStringRepresentation());
    List<CommiterData> commiters = ChangeUtil.getUniqueCommiters(changes.myEntries.stream().map(modOrDesc -> modOrDesc.getSVcsModification()));
    return new Commiters(commiters, new Fields(fields), myBeanContext);
}
Also used : CommiterData(jetbrains.buildServer.server.rest.data.change.CommiterData) Fields(jetbrains.buildServer.server.rest.model.Fields) Items(jetbrains.buildServer.server.rest.model.Items) BuildTypeFinder(jetbrains.buildServer.server.rest.data.BuildTypeFinder) BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) LocatorName(jetbrains.buildServer.server.rest.swagger.constants.LocatorName) Issues(jetbrains.buildServer.server.rest.model.issue.Issues) ApiParam(io.swagger.annotations.ApiParam) PagedSearchResult(jetbrains.buildServer.server.rest.data.PagedSearchResult) ArrayList(java.util.ArrayList) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ApiOperation(io.swagger.annotations.ApiOperation) ChangeStatusProvider(jetbrains.buildServer.vcs.ChangeStatusProvider) HttpServletRequest(javax.servlet.http.HttpServletRequest) CommiterData(jetbrains.buildServer.server.rest.data.change.CommiterData) TestScopeTreeCollector(jetbrains.buildServer.server.rest.data.problem.scope.TestScopeTreeCollector) ChangeFinder(jetbrains.buildServer.server.rest.data.ChangeFinder) UriBuilder(javax.ws.rs.core.UriBuilder) Api(io.swagger.annotations.Api) ProblemOccurrencesTree(jetbrains.buildServer.server.rest.model.problem.scope.ProblemOccurrencesTree) SBuildType(jetbrains.buildServer.serverSide.SBuildType) ChangeStatus(jetbrains.buildServer.vcs.ChangeStatus) PagerData(jetbrains.buildServer.server.rest.model.PagerData) TestScopeTree(jetbrains.buildServer.server.rest.model.problem.scope.TestScopeTree) TeamCityProperties(jetbrains.buildServer.serverSide.TeamCityProperties) Context(javax.ws.rs.core.Context) ServiceLocator(jetbrains.buildServer.ServiceLocator) ProblemOccurrencesTreeCollector(jetbrains.buildServer.server.rest.data.problem.scope.ProblemOccurrencesTreeCollector) StringUtil(com.intellij.openapi.util.text.StringUtil) Builds(jetbrains.buildServer.server.rest.model.build.Builds) ApiUrlBuilder(jetbrains.buildServer.server.rest.ApiUrlBuilder) Locator(jetbrains.buildServer.server.rest.data.Locator) Collectors(java.util.stream.Collectors) BeanFactory(jetbrains.buildServer.server.rest.util.BeanFactory) ChangeUtil(jetbrains.buildServer.server.rest.data.change.ChangeUtil) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Stream(java.util.stream.Stream) javax.ws.rs(javax.ws.rs) jetbrains.buildServer.server.rest.model.change(jetbrains.buildServer.server.rest.model.change) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) BuildTypes(jetbrains.buildServer.server.rest.model.buildType.BuildTypes) Entries(jetbrains.buildServer.server.rest.model.Entries) UriInfo(javax.ws.rs.core.UriInfo) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) NotNull(org.jetbrains.annotations.NotNull) SVcsModification(jetbrains.buildServer.vcs.SVcsModification) ServiceLocator(jetbrains.buildServer.ServiceLocator) Locator(jetbrains.buildServer.server.rest.data.Locator) Fields(jetbrains.buildServer.server.rest.model.Fields) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) ApiOperation(io.swagger.annotations.ApiOperation)

Example 9 with Locator

use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.

the class ChangeRequest method getChangeProblemsTree.

/**
 *  Experimental, subject to change
 *  @since 2021.2
 */
@GET
@Path("/{changeLocator}/problemsTree")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get problems tree for the matching change.", nickname = "getChangeProblemsTree", hidden = true)
public ProblemOccurrencesTree getChangeProblemsTree(@ApiParam(format = LocatorName.CHANGE) @PathParam("changeLocator") String changeLocator, // todo: remove after ui migration
@QueryParam(ProblemOccurrencesTreeCollector.SUB_TREE_ROOT_ID) String subTreeRootId, @QueryParam("treeLocator") String treeLocatorText, @QueryParam("fields") String fields) {
    final SVcsModification change = myChangeFinder.getItem(changeLocator).getSVcsModification();
    ChangeStatusProvider myStatusProvider = myServiceLocator.getSingletonService(ChangeStatusProvider.class);
    ChangeStatus changeStatus = myStatusProvider.getMergedChangeStatus(change);
    Stream<BuildPromotion> firstBuildsPromotions = changeStatus.getBuildTypesStatusMap().values().stream().filter(Objects::nonNull);
    Locator treeLocator = Locator.createPotentiallyEmptyLocator(treeLocatorText);
    if (subTreeRootId != null) {
        treeLocator.setDimension(ProblemOccurrencesTreeCollector.SUB_TREE_ROOT_ID, subTreeRootId);
    }
    return new ProblemOccurrencesTree(myProblemOccurrencesTreeCollector.getTreeFromBuildPromotions(firstBuildsPromotions, treeLocator), new Fields(fields), myBeanContext);
}
Also used : SVcsModification(jetbrains.buildServer.vcs.SVcsModification) ChangeStatus(jetbrains.buildServer.vcs.ChangeStatus) BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) ServiceLocator(jetbrains.buildServer.ServiceLocator) Locator(jetbrains.buildServer.server.rest.data.Locator) Fields(jetbrains.buildServer.server.rest.model.Fields) Objects(java.util.Objects) ProblemOccurrencesTree(jetbrains.buildServer.server.rest.model.problem.scope.ProblemOccurrencesTree) ChangeStatusProvider(jetbrains.buildServer.vcs.ChangeStatusProvider) ApiOperation(io.swagger.annotations.ApiOperation)

Example 10 with Locator

use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.

the class DownloadedArtifacts method getFilteredInfo.

@NotNull
private Map<SBuild, List<ArtifactInfo>> getFilteredInfo() {
    Map<SBuild, List<ArtifactInfo>> result = new HashMap<>();
    String buildLocatorText = myFields.getLocator();
    FilterConditionChecker<BuildPromotion> buildFilter;
    if (StringUtil.isNotEmpty(buildLocatorText)) {
        Locator buildLocator = Locator.locator(buildLocatorText);
        buildFilter = myBeanContext.getSingletonService(BuildPromotionFinder.class).getFilter(buildLocator);
        buildLocator.checkLocatorFullyProcessed();
    } else {
        buildFilter = b -> true;
    }
    for (Map.Entry<Build, List<ArtifactInfo>> buildArtifacts : myArtifacts.getArtifacts().entrySet()) {
        SBuild build = (SBuild) buildArtifacts.getKey();
        if (!buildFilter.isIncluded(build.getBuildPromotion())) {
            continue;
        }
        result.put(build, buildArtifacts.getValue());
    }
    return result;
}
Also used : SBuild(jetbrains.buildServer.serverSide.SBuild) BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) Locator(jetbrains.buildServer.server.rest.data.Locator) HashMap(java.util.HashMap) Build(jetbrains.buildServer.Build) SBuild(jetbrains.buildServer.serverSide.SBuild) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Locator (jetbrains.buildServer.server.rest.data.Locator)19 NotNull (org.jetbrains.annotations.NotNull)9 ServiceLocator (jetbrains.buildServer.ServiceLocator)8 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)8 ApiOperation (io.swagger.annotations.ApiOperation)7 Fields (jetbrains.buildServer.server.rest.model.Fields)7 BuildPromotion (jetbrains.buildServer.serverSide.BuildPromotion)5 PagerData (jetbrains.buildServer.server.rest.model.PagerData)4 ChangeStatus (jetbrains.buildServer.vcs.ChangeStatus)4 ChangeStatusProvider (jetbrains.buildServer.vcs.ChangeStatusProvider)4 SVcsModification (jetbrains.buildServer.vcs.SVcsModification)4 List (java.util.List)3 Objects (java.util.Objects)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 TestCountersData (jetbrains.buildServer.server.rest.data.problem.TestCountersData)2 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)2