use of org.ambraproject.wombat.config.site.Site 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.config.site.Site in project wombat by PLOS.
the class SearchControllerTest method testCommonParams.
@Test
public void testCommonParams() throws IOException {
Map<String, List<String>> params = new HashMap<>();
params.put("page", Collections.singletonList("7"));
params.put("filterSubjects", Arrays.asList("subject1", "subject2"));
Site site = MockSiteUtil.getByUniqueJournalKey(siteSet, "journal1Key");
SearchController.CommonParams commonParams = new SearchController.CommonParams(siteSet, site);
commonParams.parseParams(params, false);
// Default results per page should be 15
assertEquals(commonParams.start, 90);
assertEquals(commonParams.sortOrder, SolrSearchApiImpl.SolrSortOrder.RELEVANCE);
assertEquals(commonParams.dateRange, SolrSearchApiImpl.SolrEnumeratedDateRange.ALL_TIME);
assertTrue(commonParams.articleTypes.isEmpty());
assertTrue(commonParams.journalKeys.isEmpty());
assertTrue(commonParams.filterJournalNames.isEmpty());
assertEquals(commonParams.subjectList.size(), 2);
assertEquals(commonParams.subjectList.get(0), "subject1");
assertEquals(commonParams.subjectList.get(1), "subject2");
assertTrue(commonParams.isFiltered);
}
use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class TestTheme method testResolveForeignJournalKey.
@Test(dataProvider = "booleans")
public void testResolveForeignJournalKey(final boolean useJournalKeyMap) throws Exception {
SiteRequestScheme dummyScheme = SiteRequestScheme.builder().build();
Theme homeTheme = new StubTheme("homeTheme", "homeJournal") {
@Override
protected Map<String, Object> getJournalConfigMap() {
Map<String, Object> map = super.getJournalConfigMap();
if (useJournalKeyMap) {
ImmutableMap<String, String> otherJournals = ImmutableMap.of("targetJournal", "targetSite");
map.put("otherJournals", otherJournals);
}
return map;
}
};
Site homeSite = new Site("homeSite", homeTheme, dummyScheme, "");
Theme targetTheme = new StubTheme("targetTheme", "targetJournal");
Site targetSite = new Site("targetSite", targetTheme, dummyScheme, "");
SiteSet siteSet = new SiteSet(ImmutableList.of(homeSite, targetSite));
Site resolved = homeTheme.resolveForeignJournalKey(siteSet, "targetJournal");
assertEquals(resolved, targetSite);
}
use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class DoiToJournalResolutionService method getJournalKeysFromDois.
public List<String> getJournalKeysFromDois(List<String> dois, Site site) throws IOException {
if (dois.isEmpty()) {
return new ArrayList<String>();
}
List<String> quoted = dois.stream().map(doi -> {
return "\"" + QueryParser.escape(doi) + "\"";
}).collect(Collectors.toList());
ArticleSearchQuery explicitDoiSearchQuery = ArticleSearchQuery.builder().setSimple(false).setRows(dois.size()).setQuery("id:(" + String.join(" OR ", quoted) + ")").setFields(ImmutableList.of("journal_key", "journal_name")).build();
List<Map<String, Object>> docs = solrSearchApi.search(explicitDoiSearchQuery).getDocs();
Map<String, String> keysMap = new HashMap<String, String>();
docs.forEach(data -> {
keysMap.put((String) data.get("id"), (String) data.get("journal_key"));
});
List<String> journalKeys = dois.stream().map(id -> {
if (keysMap.containsKey(id)) {
return keysMap.get(id);
} else {
return "";
}
}).collect(Collectors.toList());
return journalKeys;
}
use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class TopLevelLockssManifestService method printPage.
/**
* @param request the HTTP request whose response we are building
* @param writer the buffer into which to print the response
*/
private void printPage(HttpServletRequest request, PrintWriter writer) {
for (String line : PREAMBLE) {
writer.println(line);
}
for (Site site : getSitesByDistinctJournalKey()) {
String journalName = site.getJournalName();
Link.Factory.PatternBuilder pattern = Link.toAbsoluteAddress(site).toPattern(requestMappingContextDictionary, "lockssYears");
Link manifestLink;
try {
manifestLink = pattern.build();
} catch (Link.PatternNotFoundException e) {
// omit link for this site
continue;
}
String manifestUrl = manifestLink.get(request);
writer.println(String.format(" <li><a href=\"%s\">%s</a></li>", manifestUrl, journalName));
}
for (String line : POSTAMBLE) {
writer.println(line);
}
}
Aggregations