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