Search in sources :

Example 1 with ArticlePointer

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

the class BrowseController method transformIssueImageMetadata.

private void transformIssueImageMetadata(Model model, Site site, String imageArticleDoi) throws IOException {
    RequestedDoiVersion requestedDoiVersion = RequestedDoiVersion.of(imageArticleDoi);
    ArticleMetadata imageArticleMetadata;
    try {
        imageArticleMetadata = articleMetadataFactory.get(site, requestedDoiVersion);
    } catch (NotFoundException e) {
        throw new RuntimeException("Issue's image article not found: " + requestedDoiVersion, e);
    }
    ArticlePointer issueImageArticleId = imageArticleMetadata.getArticlePointer();
    String issueDesc = (String) imageArticleMetadata.getIngestionMetadata().get("description");
    model.addAttribute("issueTitle", articleTransformService.transformImageDescription(site, issueImageArticleId, XmlUtil.extractElement(issueDesc, "title")));
    model.addAttribute("issueDescription", articleTransformService.transformImageDescription(site, issueImageArticleId, XmlUtil.removeElement(issueDesc, "title")));
}
Also used : RequestedDoiVersion(org.ambraproject.wombat.identity.RequestedDoiVersion) EntityNotFoundException(org.ambraproject.wombat.service.EntityNotFoundException) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer)

Example 2 with ArticlePointer

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

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

the class FigurePageController method renderFiguresPage.

/**
 * Serve a page listing all figures for an article.
 */
@RequestMapping(name = "figuresPage", value = "/article/figures")
public String renderFiguresPage(Model model, @SiteParam Site site, RequestedDoiVersion articleId) throws IOException {
    ArticleMetadata articleMetadata = articleMetadataFactory.get(site, articleId).validateVisibility("figuresPage");
    model.addAttribute("article", articleMetadata.getIngestionMetadata());
    ArticlePointer articlePointer = articleMetadata.getArticlePointer();
    List<Map<String, ?>> figures = articleMetadata.getFigureView().stream().map((Map<String, ?> figureMetadata) -> {
        String descriptionHtml = getDescriptionHtml(site, articlePointer, figureMetadata);
        return ImmutableMap.<String, Object>builder().putAll(figureMetadata).put("descriptionHtml", descriptionHtml).build();
    }).collect(Collectors.toList());
    model.addAttribute("figures", figures);
    return site + "/ftl/article/figures";
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ArticlePointer

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

the class ArticleMetadata method createAmendment.

/**
 * @param site           the site being rendered
 * @param relatedArticle a relationship to an amendment to this article
 * @return a model of the amendment
 * @throws IllegalArgumentException if the relationship is not of an amendment type
 */
private Map<String, Object> createAmendment(Site site, Map<String, ?> relatedArticle) {
    AmendmentType amendmentType = getAmendmentType(relatedArticle).orElseThrow(IllegalArgumentException::new);
    String doi = (String) relatedArticle.get("doi");
    ArticlePointer amendmentId;
    Map<String, Object> amendment;
    Map<String, ?> authors;
    try {
        // always uses latest revision
        amendmentId = factory.articleResolutionService.toIngestion(RequestedDoiVersion.of(doi));
        amendment = (Map<String, Object>) factory.articleApi.requestObject(amendmentId.asApiAddress().build(), Map.class);
        authors = factory.articleApi.requestObject(amendmentId.asApiAddress().addToken("authors").build(), Map.class);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    amendment.putAll(authors);
    // Display the body only on non-correction amendments. Would be better if this were configurable per theme.
    if (amendmentType != AmendmentType.CORRECTION) {
        String body;
        try {
            body = getAmendmentBody(amendmentId);
        } catch (IOException e) {
            throw new RuntimeException("Could not get body for amendment: " + doi, e);
        }
        amendment.put("body", body);
    }
    amendment.put("type", amendmentType.getLabel());
    return amendment;
}
Also used : IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer)

Example 5 with ArticlePointer

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

the class ArticleResolutionService method resolve.

private static ArticlePointer resolve(RequestedDoiVersion id, Map<String, ?> articleOverview) {
    final String canonicalDoi = (String) Objects.requireNonNull(articleOverview.get("doi"));
    final Map<String, Number> revisionTable = (Map<String, Number>) Objects.requireNonNull(articleOverview.get("revisions"));
    OptionalInt ingestionNumber = id.getIngestionNumber();
    if (ingestionNumber.isPresent()) {
        return new ArticlePointer(id, canonicalDoi, ingestionNumber.getAsInt(), OptionalInt.empty());
    }
    OptionalInt revisionNumber = id.getRevisionNumber();
    if (revisionNumber.isPresent()) {
        int revisionValue = revisionNumber.getAsInt();
        Number ingestionForRevision = revisionTable.get(Integer.toString(revisionValue));
        if (ingestionForRevision == null) {
            String message = String.format("Article %s has no revision %d", id.getDoi(), revisionValue);
            throw new NotFoundException(message);
        }
        return new ArticlePointer(id, canonicalDoi, ingestionForRevision.intValue(), OptionalInt.of(revisionValue));
    } else {
        RevisionPointer latestRevision = findLatestRevision(revisionTable).orElseThrow(() -> {
            String message = String.format("Article %s has no published revisions", id.getDoi());
            return new NotFoundException(message);
        });
        return new ArticlePointer(id, canonicalDoi, latestRevision.getIngestionNumber(), OptionalInt.of(latestRevision.getRevisionNumber()));
    }
}
Also used : NotFoundException(org.ambraproject.wombat.controller.NotFoundException) OptionalInt(java.util.OptionalInt) Map(java.util.Map) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer)

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