@Test public void testGenerateParent_DROBNUSTKYPage() throws SecurityException, NoSuchMethodException, IOException, ParserConfigurationException, SAXException, LexerException, ProcessSubtreeException, DocumentException, XPathExpressionException, JAXBException, OutOfRangeException { ProcessingIndexFeeder feeder = createMock(ProcessingIndexFeeder.class); StatisticsAccessLog acLog = EasyMock.createMock(StatisticsAccessLog.class); Locale locale = new Locale("cs","CZ"); CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(); cacheManager.init(); HazelcastServerNode.ensureHazelcastNode(); FedoraAccessAkubraImpl fa4 = createMockBuilder(FedoraAccessAkubraImpl.class) .withConstructor(KConfiguration.getInstance(), feeder, acLog, cacheManager) .addMockedMethod("getRelsExt") .addMockedMethod("isImageFULLAvailable") .addMockedMethod("isStreamAvailable") .addMockedMethod("getDC") .addMockedMethod("getBiblioMods") .addMockedMethod(FedoraAccessAkubraImpl.class.getMethod("getKrameriusModelName", String.class)) .createMock(); for (int i = 0; i < DataPrepare.DROBNUSTKY_PIDS.length; i++) { String pid = DataPrepare.DROBNUSTKY_PIDS[i]; String model = DataPrepare.MODELS_MAPPING.get(pid); PIDParser parser = new PIDParser(model); parser.disseminationURI(); String objectId = parser.getObjectId(); EasyMock.expect(fa4.getKrameriusModelName(pid)).andReturn(objectId).anyTimes(); } DataPrepare.drobnustkyRelsExt(fa4); DataPrepare.drobnustkyWithIMGFULL(fa4); DataPrepare.drobnustkyDCS(fa4); DataPrepare.drobnustkyMODS(fa4); ResourceBundleService bundleService = EasyMock.createMock(ResourceBundleService.class); EasyMock.expect(bundleService.getResourceBundle("labels", locale)).andReturn(new PropertyResourceBundle(new StringReader(BUNLDE))).anyTimes(); EasyMock.expect(bundleService.getResourceBundle("base", locale)).andReturn(new PropertyResourceBundle(new StringReader(BUNLDE))).anyTimes(); SolrAccess solrAccess = EasyMock.createMock(SolrAccess.class); Set<String> keys = DataPrepare.PATHS_MAPPING.keySet(); for (String key : keys) { EasyMock.expect(solrAccess.getPath(key)).andReturn(new ObjectPidsPath[] { DataPrepare.PATHS_MAPPING.get(key) }).anyTimes(); } replay(fa4,feeder, solrAccess, bundleService,acLog); Injector injector = Guice.createInjector(new _Module(locale, fa4, bundleService, solrAccess)); FirstPagePDFService fpageService = injector.getInstance(FirstPagePDFService.class); DocumentService docService = injector.getInstance(DocumentService.class); PreparedDocument renderedDocument = docService.buildDocumentAsFlat(DataPrepare.PATHS_MAPPING.get(DataPrepare.DROBNUSTKY_PIDS[2]), DataPrepare.DROBNUSTKY_PIDS[2], 20, null); Assert.assertNotNull(renderedDocument.getPages().size() > 0); String generatedTemplate = ((FirstPagePDFServiceImpl)fpageService).templateParent(renderedDocument, DataPrepare.PATHS_MAPPING.get(DataPrepare.DROBNUSTKY_PIDS[2])); Document renderedDoc = XMLUtils.parseDocument(new StringReader(generatedTemplate)); InputStream expected = FirstPagePDFServiceImplTest.class.getResourceAsStream("drobnustky_pages_selection.xml"); String expectedString = IOUtils.readAsString(expected, Charset.forName("UTF-8"), true); Document expectedDoc = XMLUtils.parseDocument(new StringReader(expectedString)); Document expectedWOws = XMLUnit.getWhitespaceStrippedDocument(expectedDoc); Document renderedWOws = XMLUnit.getWhitespaceStrippedDocument(renderedDoc); Diff diff = XMLUnit.compareXML(expectedWOws, renderedWOws); Assert.assertTrue(diff.toString(),diff.similar()); }
String templateParent(PreparedDocument rdoc, ObjectPidsPath path) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException, JAXBException { ResourceBundle resourceBundle = resourceBundleService.getResourceBundle("base", localesProvider.get()); StringTemplate template = new StringTemplate(IOUtils.readAsString(this.getClass().getResourceAsStream("templates/_first_page.st"), Charset.forName("UTF-8"), true)); FirstPageViewObject fpvo = prepareViewObject(resourceBundle); GeneratedItem itm = new GeneratedItem(); Map<String, LinkedHashSet<String>> detailItemValues = new HashMap<String, LinkedHashSet<String>>(); Map<String, Map<String, List<String>>> mods = processModsFromPath(path, null); String rootPid = path.getRoot(); if (mods.get(rootPid).containsKey(TitleBuilder.MODS_TITLE)) { List<String> list = mods.get(rootPid).get(TitleBuilder.MODS_TITLE); if (!list.isEmpty()) { String key = TitleBuilder.MODS_TITLE; itemVals(detailItemValues, list, key); } } String[] rProps = renderedProperties(true); String[] fromRootToLeaf = path.getPathFromRootToLeaf(); for (int i = 0; i < fromRootToLeaf.length; i++) { String pidPath = fromRootToLeaf[i]; for (String prop : rProps) { if (mods.get(pidPath).containsKey(prop)) { List<String> list = mods.get(pidPath).get(prop); itemVals(detailItemValues, list, prop); } } } List<DetailItem> details = new ArrayList<FirstPagePDFServiceImpl.DetailItem>(); LinkedHashSet<String> maintitles = detailItemValues.get(TitleBuilder.MODS_TITLE); String key = maintitles != null && maintitles.size() > 1 ? resourceBundle.getString("pdf.fp.titles") : resourceBundle.getString("pdf.fp.title"); if (maintitles != null && (!maintitles.isEmpty())) { details.add(new DetailItem(key, vals(maintitles).toString())); } String[] props = renderedProperties(true); for(String prop: props) { LinkedHashSet<String> vals = detailItemValues.get(prop); key = vals != null && vals.size() > 1 ? resourceBundle.getString(i18nKey(prop)+"s") : resourceBundle.getString(i18nKey(prop)); if (vals != null && (!vals.isEmpty())) { details.add(new DetailItem(key, vals(vals).toString())); } } pagesInParentPdf(rdoc, resourceBundle, details); itm.setDetailItems((DetailItem[]) details.toArray(new DetailItem[details.size()])); fpvo.setGeneratedItems( new GeneratedItem[] { itm }); template.setAttribute("viewinfo", fpvo); String templateText = template.toString(); return templateText; }
FirstPagePDFServiceImpl implements FirstPagePDFService { String templateParent(PreparedDocument rdoc, ObjectPidsPath path) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException, JAXBException { ResourceBundle resourceBundle = resourceBundleService.getResourceBundle("base", localesProvider.get()); StringTemplate template = new StringTemplate(IOUtils.readAsString(this.getClass().getResourceAsStream("templates/_first_page.st"), Charset.forName("UTF-8"), true)); FirstPageViewObject fpvo = prepareViewObject(resourceBundle); GeneratedItem itm = new GeneratedItem(); Map<String, LinkedHashSet<String>> detailItemValues = new HashMap<String, LinkedHashSet<String>>(); Map<String, Map<String, List<String>>> mods = processModsFromPath(path, null); String rootPid = path.getRoot(); if (mods.get(rootPid).containsKey(TitleBuilder.MODS_TITLE)) { List<String> list = mods.get(rootPid).get(TitleBuilder.MODS_TITLE); if (!list.isEmpty()) { String key = TitleBuilder.MODS_TITLE; itemVals(detailItemValues, list, key); } } String[] rProps = renderedProperties(true); String[] fromRootToLeaf = path.getPathFromRootToLeaf(); for (int i = 0; i < fromRootToLeaf.length; i++) { String pidPath = fromRootToLeaf[i]; for (String prop : rProps) { if (mods.get(pidPath).containsKey(prop)) { List<String> list = mods.get(pidPath).get(prop); itemVals(detailItemValues, list, prop); } } } List<DetailItem> details = new ArrayList<FirstPagePDFServiceImpl.DetailItem>(); LinkedHashSet<String> maintitles = detailItemValues.get(TitleBuilder.MODS_TITLE); String key = maintitles != null && maintitles.size() > 1 ? resourceBundle.getString("pdf.fp.titles") : resourceBundle.getString("pdf.fp.title"); if (maintitles != null && (!maintitles.isEmpty())) { details.add(new DetailItem(key, vals(maintitles).toString())); } String[] props = renderedProperties(true); for(String prop: props) { LinkedHashSet<String> vals = detailItemValues.get(prop); key = vals != null && vals.size() > 1 ? resourceBundle.getString(i18nKey(prop)+"s") : resourceBundle.getString(i18nKey(prop)); if (vals != null && (!vals.isEmpty())) { details.add(new DetailItem(key, vals(vals).toString())); } } pagesInParentPdf(rdoc, resourceBundle, details); itm.setDetailItems((DetailItem[]) details.toArray(new DetailItem[details.size()])); fpvo.setGeneratedItems( new GeneratedItem[] { itm }); template.setAttribute("viewinfo", fpvo); String templateText = template.toString(); return templateText; } }
FirstPagePDFServiceImpl implements FirstPagePDFService { String templateParent(PreparedDocument rdoc, ObjectPidsPath path) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException, JAXBException { ResourceBundle resourceBundle = resourceBundleService.getResourceBundle("base", localesProvider.get()); StringTemplate template = new StringTemplate(IOUtils.readAsString(this.getClass().getResourceAsStream("templates/_first_page.st"), Charset.forName("UTF-8"), true)); FirstPageViewObject fpvo = prepareViewObject(resourceBundle); GeneratedItem itm = new GeneratedItem(); Map<String, LinkedHashSet<String>> detailItemValues = new HashMap<String, LinkedHashSet<String>>(); Map<String, Map<String, List<String>>> mods = processModsFromPath(path, null); String rootPid = path.getRoot(); if (mods.get(rootPid).containsKey(TitleBuilder.MODS_TITLE)) { List<String> list = mods.get(rootPid).get(TitleBuilder.MODS_TITLE); if (!list.isEmpty()) { String key = TitleBuilder.MODS_TITLE; itemVals(detailItemValues, list, key); } } String[] rProps = renderedProperties(true); String[] fromRootToLeaf = path.getPathFromRootToLeaf(); for (int i = 0; i < fromRootToLeaf.length; i++) { String pidPath = fromRootToLeaf[i]; for (String prop : rProps) { if (mods.get(pidPath).containsKey(prop)) { List<String> list = mods.get(pidPath).get(prop); itemVals(detailItemValues, list, prop); } } } List<DetailItem> details = new ArrayList<FirstPagePDFServiceImpl.DetailItem>(); LinkedHashSet<String> maintitles = detailItemValues.get(TitleBuilder.MODS_TITLE); String key = maintitles != null && maintitles.size() > 1 ? resourceBundle.getString("pdf.fp.titles") : resourceBundle.getString("pdf.fp.title"); if (maintitles != null && (!maintitles.isEmpty())) { details.add(new DetailItem(key, vals(maintitles).toString())); } String[] props = renderedProperties(true); for(String prop: props) { LinkedHashSet<String> vals = detailItemValues.get(prop); key = vals != null && vals.size() > 1 ? resourceBundle.getString(i18nKey(prop)+"s") : resourceBundle.getString(i18nKey(prop)); if (vals != null && (!vals.isEmpty())) { details.add(new DetailItem(key, vals(vals).toString())); } } pagesInParentPdf(rdoc, resourceBundle, details); itm.setDetailItems((DetailItem[]) details.toArray(new DetailItem[details.size()])); fpvo.setGeneratedItems( new GeneratedItem[] { itm }); template.setAttribute("viewinfo", fpvo); String templateText = template.toString(); return templateText; }  }
FirstPagePDFServiceImpl implements FirstPagePDFService { String templateParent(PreparedDocument rdoc, ObjectPidsPath path) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException, JAXBException { ResourceBundle resourceBundle = resourceBundleService.getResourceBundle("base", localesProvider.get()); StringTemplate template = new StringTemplate(IOUtils.readAsString(this.getClass().getResourceAsStream("templates/_first_page.st"), Charset.forName("UTF-8"), true)); FirstPageViewObject fpvo = prepareViewObject(resourceBundle); GeneratedItem itm = new GeneratedItem(); Map<String, LinkedHashSet<String>> detailItemValues = new HashMap<String, LinkedHashSet<String>>(); Map<String, Map<String, List<String>>> mods = processModsFromPath(path, null); String rootPid = path.getRoot(); if (mods.get(rootPid).containsKey(TitleBuilder.MODS_TITLE)) { List<String> list = mods.get(rootPid).get(TitleBuilder.MODS_TITLE); if (!list.isEmpty()) { String key = TitleBuilder.MODS_TITLE; itemVals(detailItemValues, list, key); } } String[] rProps = renderedProperties(true); String[] fromRootToLeaf = path.getPathFromRootToLeaf(); for (int i = 0; i < fromRootToLeaf.length; i++) { String pidPath = fromRootToLeaf[i]; for (String prop : rProps) { if (mods.get(pidPath).containsKey(prop)) { List<String> list = mods.get(pidPath).get(prop); itemVals(detailItemValues, list, prop); } } } List<DetailItem> details = new ArrayList<FirstPagePDFServiceImpl.DetailItem>(); LinkedHashSet<String> maintitles = detailItemValues.get(TitleBuilder.MODS_TITLE); String key = maintitles != null && maintitles.size() > 1 ? resourceBundle.getString("pdf.fp.titles") : resourceBundle.getString("pdf.fp.title"); if (maintitles != null && (!maintitles.isEmpty())) { details.add(new DetailItem(key, vals(maintitles).toString())); } String[] props = renderedProperties(true); for(String prop: props) { LinkedHashSet<String> vals = detailItemValues.get(prop); key = vals != null && vals.size() > 1 ? resourceBundle.getString(i18nKey(prop)+"s") : resourceBundle.getString(i18nKey(prop)); if (vals != null && (!vals.isEmpty())) { details.add(new DetailItem(key, vals(vals).toString())); } } pagesInParentPdf(rdoc, resourceBundle, details); itm.setDetailItems((DetailItem[]) details.toArray(new DetailItem[details.size()])); fpvo.setGeneratedItems( new GeneratedItem[] { itm }); template.setAttribute("viewinfo", fpvo); String templateText = template.toString(); return templateText; }  @Override void selection(PreparedDocument rdoc, OutputStream os, String[] pids,  FontMap fontMap); String[] renderedProperties(boolean oneRoot); String i18nValue(ResourceBundle bundle, String modsKey); String i18nKey(String modsKey); String localizedModel(ResourceBundle resourceBundle, String pid); @Override void parent(PreparedDocument rdoc, OutputStream os, ObjectPidsPath path,   FontMap fontMap); }
FirstPagePDFServiceImpl implements FirstPagePDFService { String templateParent(PreparedDocument rdoc, ObjectPidsPath path) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException, JAXBException { ResourceBundle resourceBundle = resourceBundleService.getResourceBundle("base", localesProvider.get()); StringTemplate template = new StringTemplate(IOUtils.readAsString(this.getClass().getResourceAsStream("templates/_first_page.st"), Charset.forName("UTF-8"), true)); FirstPageViewObject fpvo = prepareViewObject(resourceBundle); GeneratedItem itm = new GeneratedItem(); Map<String, LinkedHashSet<String>> detailItemValues = new HashMap<String, LinkedHashSet<String>>(); Map<String, Map<String, List<String>>> mods = processModsFromPath(path, null); String rootPid = path.getRoot(); if (mods.get(rootPid).containsKey(TitleBuilder.MODS_TITLE)) { List<String> list = mods.get(rootPid).get(TitleBuilder.MODS_TITLE); if (!list.isEmpty()) { String key = TitleBuilder.MODS_TITLE; itemVals(detailItemValues, list, key); } } String[] rProps = renderedProperties(true); String[] fromRootToLeaf = path.getPathFromRootToLeaf(); for (int i = 0; i < fromRootToLeaf.length; i++) { String pidPath = fromRootToLeaf[i]; for (String prop : rProps) { if (mods.get(pidPath).containsKey(prop)) { List<String> list = mods.get(pidPath).get(prop); itemVals(detailItemValues, list, prop); } } } List<DetailItem> details = new ArrayList<FirstPagePDFServiceImpl.DetailItem>(); LinkedHashSet<String> maintitles = detailItemValues.get(TitleBuilder.MODS_TITLE); String key = maintitles != null && maintitles.size() > 1 ? resourceBundle.getString("pdf.fp.titles") : resourceBundle.getString("pdf.fp.title"); if (maintitles != null && (!maintitles.isEmpty())) { details.add(new DetailItem(key, vals(maintitles).toString())); } String[] props = renderedProperties(true); for(String prop: props) { LinkedHashSet<String> vals = detailItemValues.get(prop); key = vals != null && vals.size() > 1 ? resourceBundle.getString(i18nKey(prop)+"s") : resourceBundle.getString(i18nKey(prop)); if (vals != null && (!vals.isEmpty())) { details.add(new DetailItem(key, vals(vals).toString())); } } pagesInParentPdf(rdoc, resourceBundle, details); itm.setDetailItems((DetailItem[]) details.toArray(new DetailItem[details.size()])); fpvo.setGeneratedItems( new GeneratedItem[] { itm }); template.setAttribute("viewinfo", fpvo); String templateText = template.toString(); return templateText; }  @Override void selection(PreparedDocument rdoc, OutputStream os, String[] pids,  FontMap fontMap); String[] renderedProperties(boolean oneRoot); String i18nValue(ResourceBundle bundle, String modsKey); String i18nKey(String modsKey); String localizedModel(ResourceBundle resourceBundle, String pid); @Override void parent(PreparedDocument rdoc, OutputStream os, ObjectPidsPath path,   FontMap fontMap);  }