Search in sources :

Example 21 with Site

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);
}
Also used : Site(org.ambraproject.wombat.config.site.Site) SiteRequestScheme(org.ambraproject.wombat.config.site.url.SiteRequestScheme) SiteSet(org.ambraproject.wombat.config.site.SiteSet) Test(org.junit.Test)

Example 22 with Site

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"));
}
Also used : Site(org.ambraproject.wombat.config.site.Site) HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ArrayList(java.util.ArrayList) SolrSearchApi(org.ambraproject.wombat.service.remote.SolrSearchApi) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 23 with Site

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");
}
Also used : Site(org.ambraproject.wombat.config.site.Site) Test(org.junit.Test)

Example 24 with Site

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);
    }
}
Also used : Site(org.ambraproject.wombat.config.site.Site) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) MultiValueMap(org.springframework.util.MultiValueMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 25 with Site

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();
}
Also used : Site(org.ambraproject.wombat.config.site.Site) TemplateModelException(freemarker.template.TemplateModelException) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) TemplateScalarModel(freemarker.template.TemplateScalarModel) TransformerException(javax.xml.transform.TransformerException)

Aggregations

Site (org.ambraproject.wombat.config.site.Site)27 HashMap (java.util.HashMap)11 Map (java.util.Map)10 ArrayList (java.util.ArrayList)9 List (java.util.List)7 SiteRequestScheme (org.ambraproject.wombat.config.site.url.SiteRequestScheme)7 Test (org.junit.Test)7 Link (org.ambraproject.wombat.config.site.url.Link)6 ImmutableList (com.google.common.collect.ImmutableList)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 SiteSet (org.ambraproject.wombat.config.site.SiteSet)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 StringWriter (java.io.StringWriter)4 ArticlePointer (org.ambraproject.wombat.identity.ArticlePointer)4 RequestedDoiVersion (org.ambraproject.wombat.identity.RequestedDoiVersion)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 RequestMappingContextDictionary (org.ambraproject.wombat.config.site.RequestMappingContextDictionary)3 Theme (org.ambraproject.wombat.config.theme.Theme)3 Logger (org.slf4j.Logger)3