use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class TestTheme method testResolveForeignJournalKey.
@Test
public void testResolveForeignJournalKey() 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(targetSite, resolved);
}
use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class SearchControllerTest method testAddArticleLinks.
@Test
public void testAddArticleLinks() throws IOException {
SearchController searchController = new MySearchController();
List<Map<String, Object>> docs = new ArrayList<>(1);
Map<String, Object> doc = new HashMap<>();
List<String> crossPubbedJournals = new ArrayList<>(1);
crossPubbedJournals.add("journal1Key");
doc.put("id", "12345");
doc.put("eissn", "123");
docs.add(doc);
SolrSearchApi.Result searchResults = SolrSearchApi.Result.builder().setDocs(docs).setNumFound(1).setStart(0).build();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("someContextPath");
Site site = MockSiteUtil.getByUniqueJournalKey(siteSet, "journal2Key");
List<Map<String, Object>> actualDocs = searchController.addArticleLinks(searchResults, request, site, siteSet).getDocs();
assertEquals(1, actualDocs.size());
Map<String, Object> actualDoc = actualDocs.get(0);
assertEquals("12345", actualDoc.get("id"));
assertTrue(actualDoc.get("link").toString().endsWith("someContextPath/site1/article?id=12345"));
}
use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class ThemeGraphTest method testCanOverridePropertyFromRoot.
@Test
public void testCanOverridePropertyFromRoot() throws IOException {
Site site = MockSiteUtil.getByUniqueJournalKey(siteSet, "journal2Key");
Map<String, Object> journal = site.getTheme().getConfigMap("homepage");
Object inheritedValue = journal.get("defaultSelection");
// expected to match src/test/resources/test_themes/site2/config/homepage.json
assertEquals(inheritedValue, "popular");
}
use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class SearchController method initializeEIssnToJournalKeyMap.
/**
* Initializes the eIssnToJournalKey map if necessary by calling rhino to get eISSNs for all journals.
*
* @param siteSet set of all sites
* @param currentSite site associated with the current request
* @throws IOException
*/
@VisibleForTesting
protected synchronized void initializeEIssnToJournalKeyMap(SiteSet siteSet, Site currentSite) throws IOException {
if (eIssnToJournalKey == null) {
Map<String, String> mutable = new HashMap<>();
for (Site site : siteSet.getSites()) {
Map<String, String> rhinoResult = (Map<String, String>) articleApi.requestObject(ApiAddress.builder("journals").addToken(site.getJournalKey()).build(), Map.class);
mutable.put(rhinoResult.get("eIssn"), site.getJournalKey());
}
eIssnToJournalKey = ImmutableMap.copyOf(mutable);
}
}
use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class ArticleExcerptTransformDirective method getValue.
@Override
protected String getValue(Environment env, Map params) throws TemplateModelException, IOException {
Object xmlParam = params.get("xml");
if (!(xmlParam instanceof TemplateScalarModel)) {
throw new TemplateModelException("xml param must be a non-null string");
}
String xml = ((TemplateScalarModel) xmlParam).getAsString();
boolean isTextOnly = TemplateModelUtil.getBooleanValue((TemplateModel) params.get("textOnly"));
if (isTextOnly) {
return StringEscapeUtils.escapeHtml(XmlUtil.extractText(xml));
}
Site site = new SitePageContext(siteResolver, env).getSite();
Transformer transformer = SITE_TRANSFORMER_FACTORY.build(site);
StringWriter html = new StringWriter();
try {
transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(html));
} catch (TransformerException e) {
throw new RuntimeException(e);
}
return html.toString();
}
Aggregations