Search in sources :

Example 1 with PowerPointDownload

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);
    }
}
Also used : OutputStream(java.io.OutputStream) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer) URL(java.net.URL) SlideShow(org.apache.poi.hslf.usermodel.SlideShow) AssetPointer(org.ambraproject.wombat.identity.AssetPointer) ByteSource(com.google.common.io.ByteSource) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Map(java.util.Map) PowerPointDownload(org.ambraproject.wombat.model.PowerPointDownload) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ByteSource (com.google.common.io.ByteSource)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 List (java.util.List)1 Map (java.util.Map)1 ArticlePointer (org.ambraproject.wombat.identity.ArticlePointer)1 AssetPointer (org.ambraproject.wombat.identity.AssetPointer)1 PowerPointDownload (org.ambraproject.wombat.model.PowerPointDownload)1 SlideShow (org.apache.poi.hslf.usermodel.SlideShow)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1