Search in sources :

Example 1 with Theme

use of org.ambraproject.wombat.config.theme.Theme in project wombat by PLOS.

the class AssetServiceImpl method concatenateFiles.

/**
 * Retrieves the given files and concatenates them into a single file.
 *
 * @param filenames list of servlet paths corresponding to the files to concatenate
 * @param site      specifies the journal/site
 * @param extension specifies the type of file created (e.g. ".css", ".js")
 * @return File with all filenames concatenated.  It is the responsibility of the caller to delete this file (since it
 * will end up being minified eventually).
 * @throws IOException
 */
private File concatenateFiles(List<String> filenames, Site site, String extension) throws IOException {
    File result = File.createTempFile("concatenated_", extension);
    Theme theme = site.getTheme();
    try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(result))) {
        for (String filename : filenames) {
            try (InputStream is = theme.getStaticResource(filename)) {
                if (is == null) {
                    throw new RuntimeException(String.format("Static resource missing from %s: %s", site, filename));
                }
                IOUtils.copy(is, bos);
                // just in case
                bos.write('\n');
            }
        }
    }
    return result;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) Theme(org.ambraproject.wombat.config.theme.Theme) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with Theme

use of org.ambraproject.wombat.config.theme.Theme in project wombat by PLOS.

the class ArticleMetadataTest method testValidateVisibility.

@Test
public void testValidateVisibility() {
    HashMap<String, String> journalMetadata = new HashMap<>();
    journalMetadata.put("journalKey", "fakeKey");
    HashMap<String, HashMap<String, String>> ingestionMetadata = new HashMap<>();
    ingestionMetadata.put("journal", journalMetadata);
    Theme theme = mock(Theme.class);
    HashMap<String, Object> journalAttrs = new HashMap<>();
    journalAttrs.put("journalKey", "fakeKey");
    journalAttrs.put("journalName", "fakeName");
    when(theme.getConfigMap(any())).thenReturn(journalAttrs);
    Site site = new Site("foo", theme, mock(SiteRequestScheme.class), "foo");
    ArticleMetadata articleMetadata = articleMetadataFactory.newInstance(site, mock(RequestedDoiVersion.class), mock(ArticlePointer.class), ingestionMetadata, new HashMap(), new ArrayList());
    articleMetadata.validateVisibility("whatever");
}
Also used : Site(org.ambraproject.wombat.config.site.Site) HashMap(java.util.HashMap) SiteRequestScheme(org.ambraproject.wombat.config.site.url.SiteRequestScheme) ArrayList(java.util.ArrayList) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer) RequestedDoiVersion(org.ambraproject.wombat.identity.RequestedDoiVersion) Theme(org.ambraproject.wombat.config.theme.Theme) Test(org.junit.Test)

Example 3 with Theme

use of org.ambraproject.wombat.config.theme.Theme in project wombat by PLOS.

the class ArticleMetadataTest method testValidateVisibilityFail.

@Test(expected = InternalRedirectException.class)
public void testValidateVisibilityFail() {
    HashMap<String, String> journalMetadata = new HashMap<>();
    journalMetadata.put("journalKey", "someKey");
    HashMap<String, HashMap<String, String>> ingestionMetadata = new HashMap<>();
    ingestionMetadata.put("journal", journalMetadata);
    Theme theme = mock(Theme.class);
    HashMap<String, Object> journalAttrs = new HashMap<>();
    journalAttrs.put("journalKey", "fakeKey");
    journalAttrs.put("journalName", "fakeName");
    when(theme.getConfigMap(any())).thenReturn(journalAttrs);
    Site site = new Site("foo", theme, mock(SiteRequestScheme.class), "foo");
    when(theme.resolveForeignJournalKey(any(), any())).thenReturn(site);
    ArticleMetadata articleMetadata = spy(articleMetadataFactory.newInstance(site, mock(RequestedDoiVersion.class), mock(ArticlePointer.class), ingestionMetadata, new HashMap(), new ArrayList()));
    Link mockLink = mock(Link.class);
    doReturn(mockLink).when(articleMetadata).buildCrossSiteRedirect(any(), any());
    articleMetadata.validateVisibility("whatever");
}
Also used : Site(org.ambraproject.wombat.config.site.Site) HashMap(java.util.HashMap) SiteRequestScheme(org.ambraproject.wombat.config.site.url.SiteRequestScheme) ArrayList(java.util.ArrayList) Theme(org.ambraproject.wombat.config.theme.Theme) Link(org.ambraproject.wombat.config.site.url.Link) Test(org.junit.Test)

Example 4 with Theme

use of org.ambraproject.wombat.config.theme.Theme in project wombat by PLOS.

the class TestSpringConfiguration method themeGraph.

@Bean
public ThemeGraph themeGraph() throws ThemeGraph.ThemeConfigurationException {
    TestClasspathTheme rootTheme = new TestClasspathTheme("root", ImmutableList.of());
    TestClasspathTheme theme1 = new TestClasspathTheme("site1", ImmutableList.of(rootTheme));
    TestClasspathTheme theme2 = new TestClasspathTheme("site2", ImmutableList.of(rootTheme));
    Set<Theme> themes = ImmutableSet.of(rootTheme, theme1, theme2);
    return new ThemeGraph(Maps.uniqueIndex(themes, Theme::getKey));
}
Also used : TestClasspathTheme(org.ambraproject.wombat.config.theme.TestClasspathTheme) Theme(org.ambraproject.wombat.config.theme.Theme) TestClasspathTheme(org.ambraproject.wombat.config.theme.TestClasspathTheme) ThemeGraph(org.ambraproject.wombat.config.theme.ThemeGraph) Bean(org.springframework.context.annotation.Bean)

Example 5 with Theme

use of org.ambraproject.wombat.config.theme.Theme in project wombat by PLOS.

the class ArticleMetadataTest method testGetFigureView.

@Test
public void testGetFigureView() {
    Map<String, String> asset = new HashMap<>();
    asset.put("doi", "fakeDoi");
    List<Map<String, String>> assets = new ArrayList<>();
    assets.add(asset);
    HashMap<String, List<Map<String, String>>> ingestionMetadata = new HashMap<>();
    ingestionMetadata.put("assetsLinkedFromManuscript", assets);
    Map<String, String> item = new HashMap<>();
    item.put("itemType", "figure");
    Map<String, Map<String, String>> itemTable = new HashMap<>();
    itemTable.put("fakeDoi", item);
    Theme theme = mock(Theme.class);
    HashMap<String, Object> journalAttrs = new HashMap<>();
    journalAttrs.put("journalKey", "fakeKey");
    journalAttrs.put("journalName", "fakeName");
    when(theme.getConfigMap(any())).thenReturn(journalAttrs);
    Site site = new Site("foo", theme, mock(SiteRequestScheme.class), "foo");
    ArticleMetadata articleMetadata = articleMetadataFactory.newInstance(site, mock(RequestedDoiVersion.class), mock(ArticlePointer.class), ingestionMetadata, itemTable, new ArrayList());
    HashMap<String, String> expected = new HashMap<>();
    expected.put("type", "figure");
    expected.put("doi", "fakeDoi");
    List<Map<String, ?>> expectedFigureView = new ArrayList<>();
    expectedFigureView.add(expected);
    assertEquals(articleMetadata.getFigureView(), expectedFigureView);
}
Also used : Site(org.ambraproject.wombat.config.site.Site) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SiteRequestScheme(org.ambraproject.wombat.config.site.url.SiteRequestScheme) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer) RequestedDoiVersion(org.ambraproject.wombat.identity.RequestedDoiVersion) Theme(org.ambraproject.wombat.config.theme.Theme) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Test(org.junit.Test)

Aggregations

Theme (org.ambraproject.wombat.config.theme.Theme)13 SiteRequestScheme (org.ambraproject.wombat.config.site.url.SiteRequestScheme)4 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Site (org.ambraproject.wombat.config.site.Site)3 Test (org.junit.Test)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 FileNotFoundException (java.io.FileNotFoundException)2 Map (java.util.Map)2 RuntimeConfigurationException (org.ambraproject.wombat.config.RuntimeConfigurationException)2 ArticlePointer (org.ambraproject.wombat.identity.ArticlePointer)2 RequestedDoiVersion (org.ambraproject.wombat.identity.RequestedDoiVersion)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 MultiTemplateLoader (freemarker.cache.MultiTemplateLoader)1 TemplateLoader (freemarker.cache.TemplateLoader)1