use of org.ambraproject.wombat.config.site.SiteParam 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";
}
Aggregations