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