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;
}
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");
}
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");
}
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));
}
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);
}
Aggregations