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")));
}
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";
}
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";
}
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;
}
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()));
}
}
Aggregations