Search in sources :

Example 16 with Locator

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

the class FilesSubResource method getChildren.

@GET
@Path(FilesSubResource.CHILDREN + "{path:(/.*)?}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "getChildren", hidden = true)
public Files getChildren(@PathParam("path") @DefaultValue("") final String path, @QueryParam("basePath") final String basePath, @QueryParam("locator") final String locator, @QueryParam("fields") String fields) {
    if (!myArchiveBrowsingSupported && locator != null) {
        final Boolean browseArchives = new Locator(locator).getSingleDimensionValueAsBoolean(BuildArtifactsFinder.ARCHIVES_DIMENSION_NAME);
        if (browseArchives != null && browseArchives) {
            throw new BadRequestException("Archive browsing is not supported for this request, remove '" + BuildArtifactsFinder.ARCHIVES_DIMENSION_NAME + "' dimension");
        }
    }
    final FileApiUrlBuilder builder = fileApiUrlBuilder(locator, myUrlPrefix);
    final Element rootElement = myProvider.getElement(myProvider.preprocess(StringUtil.removeLeadingSlash(path)));
    return new Files(null, new Files.DefaultFilesProvider(builder, myBeanContext) {

        @Override
        @NotNull
        public List<? extends Element> getItems() {
            return BuildArtifactsFinder.getItems(rootElement, myProvider.preprocess(basePath), locator, builder, myBeanContext.getServiceLocator());
        }
    }, new Fields(fields), myBeanContext);
}
Also used : Locator(jetbrains.buildServer.server.rest.data.Locator) FileApiUrlBuilder(jetbrains.buildServer.server.rest.model.files.FileApiUrlBuilder) Fields(jetbrains.buildServer.server.rest.model.Fields) ArchiveElement(jetbrains.buildServer.server.rest.data.ArchiveElement) Element(jetbrains.buildServer.util.browser.Element) ArtifactElement(jetbrains.buildServer.web.artifacts.browser.ArtifactElement) ArtifactTreeElement(jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) List(java.util.List) Files(jetbrains.buildServer.server.rest.model.files.Files) NotNull(org.jetbrains.annotations.NotNull) ApiOperation(io.swagger.annotations.ApiOperation)

Example 17 with Locator

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

the class ChangeRequest method getChangeFailedTestsTree.

/**
 *  Experimental, subject to change
 *  @since 2021.2
 */
@GET
@Path("/{changeLocator}/testsTree")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get failed tests tree for the matching change.", nickname = "getChangeFailedTestsTree", hidden = true)
public TestScopeTree getChangeFailedTestsTree(@ApiParam(format = LocatorName.CHANGE) @PathParam("changeLocator") String changeLocator, // todo: remove after ui migration
@QueryParam(TestScopeTreeCollector.SUBTREE_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 TestScopeTree(myTestScopeTreeCollector.getSlicedTreeFromBuildPromotions(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) TestScopeTree(jetbrains.buildServer.server.rest.model.problem.scope.TestScopeTree) Objects(java.util.Objects) ChangeStatusProvider(jetbrains.buildServer.vcs.ChangeStatusProvider) ApiOperation(io.swagger.annotations.ApiOperation)

Example 18 with Locator

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

the class ChangeRequest method getFilteredFiles.

/**
 * Experimental support only!
 * todo: Is it better to have this somewhere in Change model? E.g. fields=change(files($filterByBuildType(<buildTypeId>),name,...)))
 * @since 2021.1.1
 */
@GET
@Path("/{changeLocator}/files")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get files of the matching change filtered by relation to a given buildType.", nickname = "getFilteredFiles", hidden = true)
public FileChanges getFilteredFiles(@ApiParam(format = LocatorName.CHANGE) @PathParam("changeLocator") String changeLocatorString, @QueryParam("buildTypeId") String builtTypeId, @QueryParam("fields") String fields) {
    Locator changeLocator = Locator.createPotentiallyEmptyLocator(changeLocatorString);
    SVcsModification change = myChangeFinder.getItem(changeLocator.getStringRepresentation()).getSVcsModification();
    if (builtTypeId == null) {
        // Convenience method, same as Change.getFileChanges()
        ChangeStatusProvider myStatusProvider = myServiceLocator.getSingletonService(ChangeStatusProvider.class);
        ChangeStatus changeStatus = myStatusProvider.getMergedChangeStatus(change);
        return new FileChanges(new ArrayList<>(changeStatus.getMergedVcsModificationInfo().getChangedFiles()), new Fields(fields));
    }
    SBuildType buildType = myBuildTypeFinder.getItem(builtTypeId).getBuildType();
    if (buildType == null) {
        throw new NotFoundException("Build type not found.");
    }
    if (change.getRelatedConfigurations().stream().noneMatch(relatedBt -> relatedBt.getExternalId().equals(buildType.getExternalId()))) {
        ChangeStatusProvider myStatusProvider = myServiceLocator.getSingletonService(ChangeStatusProvider.class);
        ChangeStatus changeStatus = myStatusProvider.getMergedChangeStatus(change);
        return new FileChanges(new ArrayList<>(changeStatus.getMergedVcsModificationInfo().getChangedFiles()), new Fields(fields));
    }
    return new FileChanges(change.getFilteredChanges(buildType), new Fields(fields));
}
Also used : SVcsModification(jetbrains.buildServer.vcs.SVcsModification) ChangeStatus(jetbrains.buildServer.vcs.ChangeStatus) ServiceLocator(jetbrains.buildServer.ServiceLocator) Locator(jetbrains.buildServer.server.rest.data.Locator) Fields(jetbrains.buildServer.server.rest.model.Fields) SBuildType(jetbrains.buildServer.serverSide.SBuildType) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) ChangeStatusProvider(jetbrains.buildServer.vcs.ChangeStatusProvider) ApiOperation(io.swagger.annotations.ApiOperation)

Example 19 with Locator

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

the class ProblemOccurrencesTreeCollector method prepareLocator.

private String prepareLocator(@NotNull Locator original) {
    Locator result = Locator.createEmptyLocator();
    result.setDimension(ProblemOccurrenceFinder.AFFECTED_PROJECT, original.getDimensionValue(ProblemOccurrenceFinder.AFFECTED_PROJECT));
    result.setDimension(ProblemOccurrenceFinder.BUILD, original.getDimensionValue(ProblemOccurrenceFinder.BUILD));
    result.setDimension(ProblemOccurrenceFinder.TYPE, original.getDimensionValue(ProblemOccurrenceFinder.TYPE));
    result.setDimension(ProblemOccurrenceFinder.CURRENTLY_INVESTIGATED, original.getDimensionValue(ProblemOccurrenceFinder.CURRENTLY_INVESTIGATED));
    result.setDimension(ProblemOccurrenceFinder.CURRENTLY_MUTED, original.getDimensionValue(ProblemOccurrenceFinder.CURRENTLY_MUTED));
    result.setDimension(PagerData.COUNT, "-1");
    return result.toString();
}
Also used : Locator(jetbrains.buildServer.server.rest.data.Locator)

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