Search in sources :

Example 1 with AssetPointer

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

the class FigurePageController method renderFigurePage.

/**
 * Serve a page displaying a single figure.
 */
@RequestMapping(name = "figurePage", value = "/article/figure")
public String renderFigurePage(Model model, @SiteParam Site site, RequestedDoiVersion figureId) throws IOException {
    AssetPointer assetPointer = articleResolutionService.toParentIngestion(figureId);
    model.addAttribute("figurePtr", assetPointer.asParameterMap());
    ArticlePointer articlePointer = assetPointer.getParentArticle();
    RequestedDoiVersion articleId = figureId.forDoi(articlePointer.getDoi());
    ArticleMetadata articleMetadata = articleMetadataFactory.get(site, articleId, articlePointer);
    model.addAttribute("article", articleMetadata.getIngestionMetadata());
    Map<String, ?> figureMetadata = articleMetadata.getFigureView().stream().filter((Map<String, ?> fig) -> fig.get("doi").equals(assetPointer.getAssetDoi())).collect(MoreCollectors.onlyElement());
    model.addAttribute("figure", figureMetadata);
    String descriptionHtml = getDescriptionHtml(site, articlePointer, figureMetadata);
    model.addAttribute("descriptionHtml", descriptionHtml);
    return site + "/ftl/article/figure";
}
Also used : RequestedDoiVersion(org.ambraproject.wombat.identity.RequestedDoiVersion) AssetPointer(org.ambraproject.wombat.identity.AssetPointer) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with AssetPointer

use of org.ambraproject.wombat.identity.AssetPointer 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 3 with AssetPointer

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

the class ArticleAssetController method serve.

private void serve(HttpServletRequest requestFromClient, HttpServletResponse responseToClient, AssetUrlStyle requestedStyle, Site site, RequestedDoiVersion id, String fileType, boolean isDownload) throws IOException {
    AssetPointer asset = articleResolutionService.toParentIngestion(id);
    Map<String, ?> itemMetadata = articleService.getItemMetadata(asset);
    String itemType = (String) itemMetadata.get("itemType");
    AssetUrlStyle itemStyle = AssetUrlStyle.findByItemType(itemType);
    if (requestedStyle != itemStyle) {
        Link redirectLink = itemStyle.buildRedirectLink(requestMappingContextDictionary, site, id, fileType, isDownload);
        String location = redirectLink.get(requestFromClient);
        log.warn(String.format("Redirecting %s request for %s to <%s>. Bad link?", requestedStyle, asset.asParameterMap(), location));
        redirectTo(responseToClient, location);
        return;
    }
    Map<String, ?> files = (Map<String, ?>) itemMetadata.get("files");
    Map<String, ?> fileRepoKey = (Map<String, ?>) files.get(fileType);
    if (fileRepoKey == null) {
        fileRepoKey = handleUnmatchedFileType(id, itemType, fileType, files);
    }
    // TODO: Check visibility against site?
    ContentKey contentKey = createKey(fileRepoKey);
    try (CloseableHttpResponse responseFromApi = corpusContentApi.request(contentKey, ImmutableList.of())) {
        forwardAssetResponse(responseFromApi, responseToClient, isDownload);
    }
}
Also used : ContentKey(org.ambraproject.wombat.service.remote.ContentKey) AssetPointer(org.ambraproject.wombat.identity.AssetPointer) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Link(org.ambraproject.wombat.config.site.url.Link)

Example 4 with AssetPointer

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

AssetPointer (org.ambraproject.wombat.identity.AssetPointer)4 Map (java.util.Map)3 ArticlePointer (org.ambraproject.wombat.identity.ArticlePointer)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ByteSource (com.google.common.io.ByteSource)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 List (java.util.List)1 Link (org.ambraproject.wombat.config.site.url.Link)1 NotFoundException (org.ambraproject.wombat.controller.NotFoundException)1 RequestedDoiVersion (org.ambraproject.wombat.identity.RequestedDoiVersion)1 PowerPointDownload (org.ambraproject.wombat.model.PowerPointDownload)1 ContentKey (org.ambraproject.wombat.service.remote.ContentKey)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 SlideShow (org.apache.poi.hslf.usermodel.SlideShow)1