Search in sources :

Example 6 with ArticlePointer

use of org.ambraproject.wombat.identity.ArticlePointer in project wombat by PLOS.

the class ArticleResolutionService method toParentIngestion.

public AssetPointer toParentIngestion(RequestedDoiVersion assetId) throws IOException {
    Map<String, ?> doiOverview;
    try {
        doiOverview = articleApi.requestObject(ApiAddress.builder("dois").embedDoi(assetId.getDoi()).build(), Map.class);
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(e);
    }
    String type = (String) doiOverview.get("type");
    if (!ARTICLE_ASSET_TYPES.contains(type)) {
        throw new NotFoundException("Not an article asset: " + assetId);
    }
    Map<String, ?> parentArticle = (Map<String, ?>) doiOverview.get("article");
    ArticlePointer parentArticlePtr = resolve(assetId, parentArticle);
    String canonicalAssetDoi = (String) doiOverview.get("doi");
    return new AssetPointer(canonicalAssetDoi, parentArticlePtr);
}
Also used : AssetPointer(org.ambraproject.wombat.identity.AssetPointer) NotFoundException(org.ambraproject.wombat.controller.NotFoundException) Map(java.util.Map) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer)

Example 7 with ArticlePointer

use of org.ambraproject.wombat.identity.ArticlePointer in project wombat by PLOS.

the class ArticleController method renderArticle.

// TODO: this method currently makes 5 backend RPCs, all sequentially. Explore reducing this
// number, or doing them in parallel, if this is a performance bottleneck.
@RequestMapping(name = "article", value = "/article")
public String renderArticle(HttpServletRequest request, Model model, @SiteParam Site site, RequestedDoiVersion articleId) throws IOException {
    ArticlePointer articlePointer = articleMetadataFactory.get(site, articleId).validateVisibility("article").populate(request, model).fillAmendments(model).getArticlePointer();
    XmlContent xmlContent = getXmlContent(site, articlePointer, request);
    model.addAttribute("articleText", xmlContent.html);
    model.addAttribute("references", xmlContent.references);
    return site + "/ftl/article/article";
}
Also used : ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with ArticlePointer

use of org.ambraproject.wombat.identity.ArticlePointer 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

ArticlePointer (org.ambraproject.wombat.identity.ArticlePointer)8 Map (java.util.Map)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 AssetPointer (org.ambraproject.wombat.identity.AssetPointer)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 NotFoundException (org.ambraproject.wombat.controller.NotFoundException)2 RequestedDoiVersion (org.ambraproject.wombat.identity.RequestedDoiVersion)2 ImmutableList (com.google.common.collect.ImmutableList)1 ByteSource (com.google.common.io.ByteSource)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 List (java.util.List)1 OptionalInt (java.util.OptionalInt)1 PowerPointDownload (org.ambraproject.wombat.model.PowerPointDownload)1 EntityNotFoundException (org.ambraproject.wombat.service.EntityNotFoundException)1 SlideShow (org.apache.poi.hslf.usermodel.SlideShow)1