Search in sources :

Example 1 with Files

use of jetbrains.buildServer.server.rest.model.files.Files in project teamcity-rest by JetBrains.

the class Build method getArtifacts.

@XmlElement(name = "artifacts")
public Files getArtifacts() {
    return ValueWithDefault.decideDefaultIgnoringAccessDenied(myFields.isIncluded("artifacts", false), new ValueWithDefault.Value<Files>() {

        public Files get() {
            final Fields nestedFields = myFields.getNestedField("artifacts");
            final String childrenLocator = nestedFields.getLocator();
            final FileApiUrlBuilder builder = FilesSubResource.fileApiUrlBuilder(childrenLocator, BuildRequest.getBuildArtifactsHref(myBuildPromotion));
            return new Files(builder.getChildrenHref(null), new Files.DefaultFilesProvider(builder, myBeanContext) {

                @NotNull
                @Override
                protected List<? extends Element> getItems() {
                    return BuildArtifactsFinder.getItems(BuildArtifactsFinder.getArtifactElement(myBuildPromotion, "", myServiceLocator), childrenLocator, builder, myServiceLocator);
                }

                @Override
                public int getCount() {
                    if (myItems != null) {
                        return myItems.size();
                    }
                    Integer cheapCount = getCheapCount();
                    if (cheapCount != null) {
                        return cheapCount;
                    }
                    return super.getCount();
                }

                @Override
                public boolean isCountCheap() {
                    if (super.isCountCheap())
                        return true;
                    return getCheapCount() != null;
                }

                private Integer myCachedCheapCount = null;

                private boolean myCheapCountIsCalculated = false;

                @Nullable
                private Integer getCheapCount() {
                    if (!myCheapCountIsCalculated) {
                        myCachedCheapCount = getCheapCountInternal();
                        myCheapCountIsCalculated = true;
                    }
                    return myCachedCheapCount;
                }

                @Nullable
                private Integer getCheapCountInternal() {
                    if (!((BuildPromotionEx) myBuildPromotion).hasComputedArtifactsState())
                        return null;
                    // optimize response by using cached artifacts presence
                    BuildPromotionEx.ArtifactsState state = ((BuildPromotionEx) myBuildPromotion).getArtifactStateInfo().getState();
                    if (state == BuildPromotionEx.ArtifactsState.NO_ARTIFACTS)
                        return 0;
                    Integer requestedCount = BuildArtifactsFinder.getCountIfDefaultLocator(childrenLocator);
                    // not default locator
                    if (requestedCount == null)
                        return null;
                    if (state == BuildPromotionEx.ArtifactsState.HIDDEN_ONLY)
                        return 0;
                    if (requestedCount == 1 && state == BuildPromotionEx.ArtifactsState.HAS_ARTIFACTS)
                        return 1;
                    return null;
                }
            }, nestedFields, myBeanContext);
        }
    });
}
Also used : FileApiUrlBuilder(jetbrains.buildServer.server.rest.model.files.FileApiUrlBuilder) ValueWithDefault(jetbrains.buildServer.server.rest.util.ValueWithDefault) Files(jetbrains.buildServer.server.rest.model.files.Files) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 2 with Files

use of jetbrains.buildServer.server.rest.model.files.Files 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)

Aggregations

FileApiUrlBuilder (jetbrains.buildServer.server.rest.model.files.FileApiUrlBuilder)2 Files (jetbrains.buildServer.server.rest.model.files.Files)2 ApiOperation (io.swagger.annotations.ApiOperation)1 List (java.util.List)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 ArchiveElement (jetbrains.buildServer.server.rest.data.ArchiveElement)1 Locator (jetbrains.buildServer.server.rest.data.Locator)1 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)1 Fields (jetbrains.buildServer.server.rest.model.Fields)1 ValueWithDefault (jetbrains.buildServer.server.rest.util.ValueWithDefault)1 Element (jetbrains.buildServer.util.browser.Element)1 ArtifactElement (jetbrains.buildServer.web.artifacts.browser.ArtifactElement)1 ArtifactTreeElement (jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement)1 NotNull (org.jetbrains.annotations.NotNull)1