use of org.ambraproject.wombat.model.PowerPointDownload in project wombat by PLOS.
the class PowerPointController method download.
@RequestMapping(name = "powerPoint", value = "/article/figure/powerpoint")
public void download(HttpServletRequest request, HttpServletResponse response, @SiteParam Site site, RequestedDoiVersion figureId) throws IOException {
AssetPointer assetPointer = articleResolutionService.toParentIngestion(figureId);
ArticlePointer parentArticleId = assetPointer.getParentArticle();
ArticleMetadata parentArticle = articleMetadataFactory.get(site, figureId.forDoi(parentArticleId.getDoi()), parentArticleId).validateVisibility("powerPoint");
List<Map<String, ?>> figureViewList = parentArticle.getFigureView();
Map<String, ?> figureMetadata = findFigureViewFor(figureViewList, assetPointer).orElseThrow(() -> new NotFoundException("Asset exists but is not a figure: " + assetPointer.getAssetDoi()));
String figureTitle = (String) figureMetadata.get("title");
String figureDescription = (String) figureMetadata.get("description");
URL articleUrl = buildArticleUrl(request, site, parentArticleId);
ByteSource imageFileSource = getImageFile(assetPointer);
ByteSource logoSource = new LogoSource(site.getTheme());
Map<String, ?> parentArticleMetadata = parentArticle.getIngestionMetadata();
List<Map<String, ?>> parentArticleAuthors = (List<Map<String, ?>>) parentArticle.getAuthors().get("authors");
SlideShow powerPointFile = new PowerPointDownload(parentArticleMetadata, parentArticleAuthors, articleUrl, figureTitle, figureDescription, imageFileSource, logoSource).createPowerPointFile();
response.setContentType(MediaType.MICROSOFT_POWERPOINT.toString());
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + getDownloadFilename(assetPointer));
try (OutputStream outputStream = response.getOutputStream()) {
powerPointFile.write(outputStream);
}
}
Aggregations