use of org.ambraproject.wombat.identity.RequestedDoiVersion in project wombat by PLOS.
the class ArticleController method renderArticleCommentTree.
/**
* Serves a request for an expanded view of a single comment and any replies.
*
* @param model data to pass to the view
* @param site current site
* @param commentDoi specifies the comment
* @return path to the template
* @throws IOException
*/
@RequestMapping(name = "articleCommentTree", value = "/article/comment")
public String renderArticleCommentTree(HttpServletRequest request, Model model, @SiteParam Site site, @RequestParam("id") String commentDoi) throws IOException {
requireNonemptyParameter(commentDoi);
Map<String, Object> comment;
try {
comment = commentService.getComment(commentDoi, site);
} catch (CommentService.CommentNotFoundException e) {
throw new NotFoundException(e);
} catch (UserApi.UserApiException e) {
log.error(e.getMessage(), e);
model.addAttribute("userApiError", e);
// Get a copy of the comment that is not populated with userApi data.
// This articleApi call is redundant to one that commentService.getComment would have made before throwing.
// TODO: Prevent extra articleApi call
comment = getComment(commentDoi);
}
RequestedDoiVersion doi = RequestedDoiVersion.of(getParentArticleDoiFromComment(comment));
articleMetadataFactory.get(site, doi).validateVisibility("articleCommentTree").populate(request, model);
model.addAttribute("comment", comment);
addCommentAvailability(model);
return site + "/ftl/article/comment/comment";
}
use of org.ambraproject.wombat.identity.RequestedDoiVersion in project wombat by PLOS.
the class ArticleController method emailArticle.
/**
* @param model data passed in from the view
* @param site current site
* @return path to the template
* @throws IOException
*/
@RequestMapping(name = "emailPost", value = "/article/email", method = RequestMethod.POST)
public String emailArticle(HttpServletRequest request, HttpServletResponse response, Model model, @SiteParam Site site, RequestedDoiVersion articleId, @RequestParam("articleUri") String articleUri, @RequestParam("emailToAddresses") String emailToAddresses, @RequestParam("emailFrom") String emailFrom, @RequestParam("senderName") String senderName, @RequestParam("note") String note, @RequestParam(value = "authorPhone", required = false) String authorPhone, @RequestParam(value = "authorAffiliation", required = false) String authorAffiliation) throws IOException, MessagingException {
requireNonemptyParameter(articleUri);
model.addAttribute("emailToAddresses", emailToAddresses);
model.addAttribute("emailFrom", emailFrom);
model.addAttribute("senderName", senderName);
model.addAttribute("note", note);
model.addAttribute("articleUri", articleUri);
List<InternetAddress> toAddresses = Splitter.on(CharMatcher.anyOf("\n\r")).omitEmptyStrings().splitToList(emailToAddresses).stream().map(email -> EmailMessage.createAddress(null, /*name*/
email)).collect(Collectors.toList());
Set<String> errors = validateEmailArticleInput(toAddresses, emailFrom, senderName);
if (applyValidation(response, model, errors)) {
return renderEmailThisArticle(request, model, site, articleId);
}
Map<String, ?> articleMetadata = articleMetadataFactory.get(site, articleId).validateVisibility("emailPost").getIngestionMetadata();
String title = articleMetadata.get("title").toString();
model.addAttribute("article", articleMetadata);
model.addAttribute("journalName", site.getJournalName());
if (honeypotService.checkHoneypot(request, authorPhone, authorAffiliation)) {
response.setStatus(HttpStatus.CREATED.value());
return site + "/ftl/article/emailSuccess";
}
Multipart content = freemarkerMailService.createContent(site, "emailThisArticle", model);
EmailMessage message = EmailMessage.builder().addToEmailAddresses(toAddresses).setSenderAddress(EmailMessage.createAddress(senderName, emailFrom)).setSubject("An Article from " + site.getJournalName() + ": " + title).setContent(content).setEncoding(freeMarkerConfig.getConfiguration().getDefaultEncoding()).build();
message.send(javaMailSender);
response.setStatus(HttpStatus.CREATED.value());
return site + "/ftl/article/emailSuccess";
}
use of org.ambraproject.wombat.identity.RequestedDoiVersion in project wombat by PLOS.
the class ArticleResolutionServiceTest method testToParentIngestionNotAnAsset.
@Test(expected = NotFoundException.class)
public void testToParentIngestionNotAnAsset() throws IOException {
Map<String, Object> doiOverview = makeSampleDoiOverview();
doiOverview.put("type", "not_an_asset_type");
when(articleApi.requestObject(any(), eq(Map.class))).thenReturn(doiOverview);
RequestedDoiVersion assetId = RequestedDoiVersion.of("info:doi/10.1371/journal.pcbi.1002012.g002");
articleResolutionService.toParentIngestion(assetId);
}
use of org.ambraproject.wombat.identity.RequestedDoiVersion 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.RequestedDoiVersion in project wombat by PLOS.
the class CommentController method renderArticleCommentTree.
/**
* Serves a request for an expanded view of a single comment and any replies.
*
* @param model data to pass to the view
* @param site current site
* @param commentDoi specifies the comment
* @return path to the template
* @throws IOException
*/
@RequestMapping(name = "articleCommentTree", value = "/article/comment")
public String renderArticleCommentTree(HttpServletRequest request, Model model, @SiteParam Site site, @RequestParam("id") String commentDoi) throws IOException {
requireNonemptyParameter(commentDoi);
Map<String, Object> comment;
try {
comment = commentService.getComment(commentDoi, site);
} catch (CommentService.CommentNotFoundException e) {
throw new NotFoundException(e);
} catch (UserApi.UserApiException e) {
log.error(e.getMessage(), e);
model.addAttribute("userApiError", e);
// Get a copy of the comment that is not populated with userApi data.
// This articleApi call is redundant to one that commentService.getComment would have made before throwing.
// TODO: Prevent extra articleApi call
comment = getComment(commentDoi);
}
RequestedDoiVersion doi = RequestedDoiVersion.of(getParentArticleDoiFromComment(comment));
articleMetadataFactory.get(site, doi).validateVisibility("articleCommentTree").populate(request, model);
model.addAttribute("comment", comment);
addCommentAvailability(model);
return site + "/ftl/article/comment/comment";
}
Aggregations