use of jetbrains.buildServer.server.rest.model.files.FileApiUrlBuilder in project teamcity-rest by JetBrains.
the class FilesSubResource method getZipped.
@GET
@Path("/archived" + "{path:(/.*)?}")
@Produces({ MediaType.WILDCARD })
@ApiOperation(value = "Get specific file zipped.", nickname = "getZippedFile")
public Response getZipped(@PathParam("path") final String path, @QueryParam("basePath") final String basePath, @QueryParam("locator") final String locator, @QueryParam("name") final String name, @Context HttpServletRequest request) {
final String processedPath = myProvider.preprocess(StringUtil.removeLeadingSlash(path));
String actualBasePath = basePath != null ? myProvider.preprocess(basePath) : processedPath;
String finalName = myProvider.preprocess(name);
if (StringUtil.isEmpty(finalName)) {
finalName = myProvider.getArchiveName(processedPath) + ".zip";
}
// include al files recursively by default
String actualLocator = Locator.setDimensionIfNotPresent(locator, BuildArtifactsFinder.DIMENSION_RECURSIVE, "true");
// do not expand archives by default
actualLocator = Locator.setDimensionIfNotPresent(actualLocator, BuildArtifactsFinder.ARCHIVES_DIMENSION_NAME, "false");
final FileApiUrlBuilder urlBuilder = fileApiUrlBuilder(locator, myUrlPrefix);
final List<ArtifactTreeElement> elements = BuildArtifactsFinder.getItems(myProvider.getElement(processedPath), actualBasePath, actualLocator, urlBuilder, myBeanContext.getServiceLocator());
final ArchiveElement archiveElement = new ArchiveElement(elements, finalName);
final Response.ResponseBuilder builder = getContentByStream(archiveElement, request, new StreamingOutputProvider() {
@Override
public boolean isRangeSupported() {
return false;
}
@Override
public StreamingOutput getStreamingOutput(@Nullable final Long startOffset, @Nullable final Long length) {
return archiveElement.getStreamingOutput(startOffset, length, () -> "request " + WebUtil.getRequestDump(request));
}
});
for (ArtifactTreeElement element : elements) {
if (!myProvider.fileContentServed(Util.concatenatePath(actualBasePath, element.getFullName()), request))
break;
}
// see jetbrains.buildServer.web.util.WebUtil.addCacheHeadersForIE and http://youtrack.jetbrains.com/issue/TW-9821 for details)
if (WebUtil.isIE10OrLower(request)) {
builder.header("Cache-Control", "private,must-revalidate");
builder.header("Pragma", "private");
}
return builder.build();
}
use of jetbrains.buildServer.server.rest.model.files.FileApiUrlBuilder 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.FileApiUrlBuilder 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