@Test public void testGenerateSelection_NarodniListyDrobnustky() throws SecurityException, NoSuchMethodException, IOException, ParserConfigurationException, SAXException, LexerException, ProcessSubtreeException, DocumentException, InstantiationException, IllegalAccessException, XPathExpressionException, JAXBException, OutOfRangeException { StatisticsAccessLog acLog = EasyMock.createMock(StatisticsAccessLog.class); Locale locale = new Locale("cs","CZ"); ProcessingIndexFeeder feeder = createMock(ProcessingIndexFeeder.class); 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.NARODNI_LISTY.length; i++) { String pid = DataPrepare.NARODNI_LISTY[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(); } 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.narodniListyRelsExt(fa4); DataPrepare.narodniListyIMGFULL(fa4); DataPrepare.narodniListyDCs(fa4); DataPrepare.narodniListyMods(fa4); 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); String[] pids = { "uuid:b38eba10-91f6-11dc-9eec-000d606f5dc6", "uuid:94a3ed60-92d6-11dc-beb4-000d606f5dc6", "uuid:b3987e10-91f6-11dc-96f6-000d606f5dc6", "uuid:94a3ed60-92d6-11dc-93df-000d606f5dc6", "uuid:b3a21b00-91f6-11dc-b8b2-000d606f5dc6", "uuid:94a68570-92d6-11dc-be5a-000d606f5dc6", "uuid:4a7c2e50-af36-11dd-9643-000d606f5dc6", "uuid:4a7ec660-af36-11dd-a782-000d606f5dc6" }; PreparedDocument renderedDocument = docService.buildDocumentFromSelection(pids, null); Assert.assertNotNull(renderedDocument.getPages().size() > 0); String generatedTemplate = ((FirstPagePDFServiceImpl)fpageService).templateSelection(renderedDocument,pids); Document renderedDoc = XMLUtils.parseDocument(new StringReader(generatedTemplate)); InputStream expected = FirstPagePDFServiceImplTest.class.getResourceAsStream("narodni_listy_drobnustky_selection_pages.xml"); Document expectedDoc = XMLUtils.parseDocument(new InputStreamReader(expected, "UTF-8")); Document expectedWOws = XMLUnit.getWhitespaceStrippedDocument(expectedDoc); Document renderedWOws = XMLUnit.getWhitespaceStrippedDocument(renderedDoc); Diff diff = XMLUnit.compareXML(expectedWOws, renderedWOws); Assert.assertTrue(diff.toString(),diff.similar()); }
String templateSelection(PreparedDocument rdoc, String ... pids) throws XPathExpressionException, IOException, ParserConfigurationException, SAXException { 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, ObjectPidsPath> pathsMapping = new HashMap<String, ObjectPidsPath>(); LinkedHashSet<String> roots = new LinkedHashSet<String>(); for (String pid : pids) { ObjectPidsPath sPath = selectOnePath(pid); pathsMapping.put(pid, sPath); roots.add(sPath.getRoot()); } for (String pid : pids) { ObjectPidsPath path = pathsMapping.get(pid); 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(roots.size() == 1); 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())); } for(String prop: renderedProperties(roots.size() == 1)) { 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())); } } pagesInSelectiontPdf(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 templateSelection(PreparedDocument rdoc, String ... pids) throws XPathExpressionException, IOException, ParserConfigurationException, SAXException { 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, ObjectPidsPath> pathsMapping = new HashMap<String, ObjectPidsPath>(); LinkedHashSet<String> roots = new LinkedHashSet<String>(); for (String pid : pids) { ObjectPidsPath sPath = selectOnePath(pid); pathsMapping.put(pid, sPath); roots.add(sPath.getRoot()); } for (String pid : pids) { ObjectPidsPath path = pathsMapping.get(pid); 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(roots.size() == 1); 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())); } for(String prop: renderedProperties(roots.size() == 1)) { 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())); } } pagesInSelectiontPdf(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 templateSelection(PreparedDocument rdoc, String ... pids) throws XPathExpressionException, IOException, ParserConfigurationException, SAXException { 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, ObjectPidsPath> pathsMapping = new HashMap<String, ObjectPidsPath>(); LinkedHashSet<String> roots = new LinkedHashSet<String>(); for (String pid : pids) { ObjectPidsPath sPath = selectOnePath(pid); pathsMapping.put(pid, sPath); roots.add(sPath.getRoot()); } for (String pid : pids) { ObjectPidsPath path = pathsMapping.get(pid); 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(roots.size() == 1); 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())); } for(String prop: renderedProperties(roots.size() == 1)) { 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())); } } pagesInSelectiontPdf(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 templateSelection(PreparedDocument rdoc, String ... pids) throws XPathExpressionException, IOException, ParserConfigurationException, SAXException { 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, ObjectPidsPath> pathsMapping = new HashMap<String, ObjectPidsPath>(); LinkedHashSet<String> roots = new LinkedHashSet<String>(); for (String pid : pids) { ObjectPidsPath sPath = selectOnePath(pid); pathsMapping.put(pid, sPath); roots.add(sPath.getRoot()); } for (String pid : pids) { ObjectPidsPath path = pathsMapping.get(pid); 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(roots.size() == 1); 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())); } for(String prop: renderedProperties(roots.size() == 1)) { 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())); } } pagesInSelectiontPdf(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 templateSelection(PreparedDocument rdoc, String ... pids) throws XPathExpressionException, IOException, ParserConfigurationException, SAXException { 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, ObjectPidsPath> pathsMapping = new HashMap<String, ObjectPidsPath>(); LinkedHashSet<String> roots = new LinkedHashSet<String>(); for (String pid : pids) { ObjectPidsPath sPath = selectOnePath(pid); pathsMapping.put(pid, sPath); roots.add(sPath.getRoot()); } for (String pid : pids) { ObjectPidsPath path = pathsMapping.get(pid); 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(roots.size() == 1); 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())); } for(String prop: renderedProperties(roots.size() == 1)) { 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())); } } pagesInSelectiontPdf(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);  }