@Test public void testEmptyOcrExport() throws Exception { URL url = Kramerius4ExportTest.class.getResource("Kramerius4ExportTestPage.xml"); Path resPath = Paths.get(url.toURI()); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(resPath.toFile()); XPath xpath = XPathFactory.newInstance().newXPath(); NodeList nl = (NodeList)xpath .compile(" .evaluate(doc, XPathConstants.NODESET); Path emptyOcr = Files.createTempFile("proarcKramerius4ExportTest", null); emptyOcr.toFile().setReadable(true, false); emptyOcr.toFile().deleteOnExit(); for (int i = 0; i < nl.getLength(); i++) { Node binaryContentNode = nl.item(i); Element contentLocation = doc.createElement("contentLocation"); contentLocation.setAttribute("TYPE", "URL"); contentLocation.setAttribute("REF", emptyOcr.toUri().toString()); nl.item(i).getParentNode().replaceChild(contentLocation, binaryContentNode); } DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(domSource, result); writer.flush(); String xml = writer.toString(); fedora.ingest(xml); File output = temp.getRoot(); boolean hierarchy = true; String[] pids = {"uuid:f74f3cf3-f3be-4cac-95da-8e50331414a2"}; RemoteStorage storage = fedora.getRemoteStorage(); Kramerius4Export instance = new Kramerius4Export(storage, config); File target = instance.export(output, hierarchy, "export status", pids); assertNotNull(target); File foxml = ExportUtils.pidAsXmlFile(target, pids[0]); String foxmlAsURI = foxml.toURI().toASCIIString(); XMLAssert.assertXpathEvaluatesTo(DatatypeConverter.printBase64Binary(System.lineSeparator().getBytes()), streamXPath(StringEditor.OCR_ID) + " fedora.cleanUp(); fedora.ingest(foxml.toURI().toURL()); }
public File export(File output, boolean hierarchy, String log, String... pids) { if (!output.exists() || !output.isDirectory()) { throw new IllegalStateException(String.valueOf(output)); } if (pids == null || pids.length == 0) { throw new IllegalArgumentException(); } ExportResultLog reslog = new ExportResultLog(); ExportResult result = new ExportResult(); result.setInputPid(pids[0]); reslog.getExports().add(result); File target = ExportUtils.createFolder(output, "k4_" + FoxmlUtils.pidAsUuid(pids[0]), exportOptions.isOverwritePackage()); HashSet<String> selectedPids = new HashSet<String>(Arrays.asList(pids)); toExport.addAll(selectedPids); try { String[] parentModels = {NdkPlugin.MODEL_MONOGRAPHTITLE, OldPrintPlugin.MODEL_MONOGRAPHTITLE}; boolean hasParent = hasParent(target, hierarchy, selectedPids, parentModels); for (String pid = toExport.poll(); pid != null; pid = toExport.poll()) { exportPid(target, hierarchy, pid, hasParent); } exportParents(target, selectedPids, hasParent); storeExportResult(target, log); } catch (RuntimeException ex) { result.setStatus(ResultStatus.FAILED); reslog.getExports().add(result); result.getError().add(new ResultError(null, ex)); result.setEnd(); ExportUtils.writeExportResult(target, reslog); throw ex; } result.setStatus(ResultStatus.OK); result.setEnd(); ExportUtils.writeExportResult(target, reslog); return target; }
Kramerius4Export { public File export(File output, boolean hierarchy, String log, String... pids) { if (!output.exists() || !output.isDirectory()) { throw new IllegalStateException(String.valueOf(output)); } if (pids == null || pids.length == 0) { throw new IllegalArgumentException(); } ExportResultLog reslog = new ExportResultLog(); ExportResult result = new ExportResult(); result.setInputPid(pids[0]); reslog.getExports().add(result); File target = ExportUtils.createFolder(output, "k4_" + FoxmlUtils.pidAsUuid(pids[0]), exportOptions.isOverwritePackage()); HashSet<String> selectedPids = new HashSet<String>(Arrays.asList(pids)); toExport.addAll(selectedPids); try { String[] parentModels = {NdkPlugin.MODEL_MONOGRAPHTITLE, OldPrintPlugin.MODEL_MONOGRAPHTITLE}; boolean hasParent = hasParent(target, hierarchy, selectedPids, parentModels); for (String pid = toExport.poll(); pid != null; pid = toExport.poll()) { exportPid(target, hierarchy, pid, hasParent); } exportParents(target, selectedPids, hasParent); storeExportResult(target, log); } catch (RuntimeException ex) { result.setStatus(ResultStatus.FAILED); reslog.getExports().add(result); result.getError().add(new ResultError(null, ex)); result.setEnd(); ExportUtils.writeExportResult(target, reslog); throw ex; } result.setStatus(ResultStatus.OK); result.setEnd(); ExportUtils.writeExportResult(target, reslog); return target; } }
Kramerius4Export { public File export(File output, boolean hierarchy, String log, String... pids) { if (!output.exists() || !output.isDirectory()) { throw new IllegalStateException(String.valueOf(output)); } if (pids == null || pids.length == 0) { throw new IllegalArgumentException(); } ExportResultLog reslog = new ExportResultLog(); ExportResult result = new ExportResult(); result.setInputPid(pids[0]); reslog.getExports().add(result); File target = ExportUtils.createFolder(output, "k4_" + FoxmlUtils.pidAsUuid(pids[0]), exportOptions.isOverwritePackage()); HashSet<String> selectedPids = new HashSet<String>(Arrays.asList(pids)); toExport.addAll(selectedPids); try { String[] parentModels = {NdkPlugin.MODEL_MONOGRAPHTITLE, OldPrintPlugin.MODEL_MONOGRAPHTITLE}; boolean hasParent = hasParent(target, hierarchy, selectedPids, parentModels); for (String pid = toExport.poll(); pid != null; pid = toExport.poll()) { exportPid(target, hierarchy, pid, hasParent); } exportParents(target, selectedPids, hasParent); storeExportResult(target, log); } catch (RuntimeException ex) { result.setStatus(ResultStatus.FAILED); reslog.getExports().add(result); result.getError().add(new ResultError(null, ex)); result.setEnd(); ExportUtils.writeExportResult(target, reslog); throw ex; } result.setStatus(ResultStatus.OK); result.setEnd(); ExportUtils.writeExportResult(target, reslog); return target; } Kramerius4Export(RemoteStorage rstorage, AppConfiguration configuration);  Kramerius4Export(RemoteStorage rstorage, AppConfiguration appConfiguration, String policy); }
Kramerius4Export { public File export(File output, boolean hierarchy, String log, String... pids) { if (!output.exists() || !output.isDirectory()) { throw new IllegalStateException(String.valueOf(output)); } if (pids == null || pids.length == 0) { throw new IllegalArgumentException(); } ExportResultLog reslog = new ExportResultLog(); ExportResult result = new ExportResult(); result.setInputPid(pids[0]); reslog.getExports().add(result); File target = ExportUtils.createFolder(output, "k4_" + FoxmlUtils.pidAsUuid(pids[0]), exportOptions.isOverwritePackage()); HashSet<String> selectedPids = new HashSet<String>(Arrays.asList(pids)); toExport.addAll(selectedPids); try { String[] parentModels = {NdkPlugin.MODEL_MONOGRAPHTITLE, OldPrintPlugin.MODEL_MONOGRAPHTITLE}; boolean hasParent = hasParent(target, hierarchy, selectedPids, parentModels); for (String pid = toExport.poll(); pid != null; pid = toExport.poll()) { exportPid(target, hierarchy, pid, hasParent); } exportParents(target, selectedPids, hasParent); storeExportResult(target, log); } catch (RuntimeException ex) { result.setStatus(ResultStatus.FAILED); reslog.getExports().add(result); result.getError().add(new ResultError(null, ex)); result.setEnd(); ExportUtils.writeExportResult(target, reslog); throw ex; } result.setStatus(ResultStatus.OK); result.setEnd(); ExportUtils.writeExportResult(target, reslog); return target; } Kramerius4Export(RemoteStorage rstorage, AppConfiguration configuration);  Kramerius4Export(RemoteStorage rstorage, AppConfiguration appConfiguration, String policy); File export(File output, boolean hierarchy, String log, String... pids); static void removeNils(Element elm); }
Kramerius4Export { public File export(File output, boolean hierarchy, String log, String... pids) { if (!output.exists() || !output.isDirectory()) { throw new IllegalStateException(String.valueOf(output)); } if (pids == null || pids.length == 0) { throw new IllegalArgumentException(); } ExportResultLog reslog = new ExportResultLog(); ExportResult result = new ExportResult(); result.setInputPid(pids[0]); reslog.getExports().add(result); File target = ExportUtils.createFolder(output, "k4_" + FoxmlUtils.pidAsUuid(pids[0]), exportOptions.isOverwritePackage()); HashSet<String> selectedPids = new HashSet<String>(Arrays.asList(pids)); toExport.addAll(selectedPids); try { String[] parentModels = {NdkPlugin.MODEL_MONOGRAPHTITLE, OldPrintPlugin.MODEL_MONOGRAPHTITLE}; boolean hasParent = hasParent(target, hierarchy, selectedPids, parentModels); for (String pid = toExport.poll(); pid != null; pid = toExport.poll()) { exportPid(target, hierarchy, pid, hasParent); } exportParents(target, selectedPids, hasParent); storeExportResult(target, log); } catch (RuntimeException ex) { result.setStatus(ResultStatus.FAILED); reslog.getExports().add(result); result.getError().add(new ResultError(null, ex)); result.setEnd(); ExportUtils.writeExportResult(target, reslog); throw ex; } result.setStatus(ResultStatus.OK); result.setEnd(); ExportUtils.writeExportResult(target, reslog); return target; } Kramerius4Export(RemoteStorage rstorage, AppConfiguration configuration);  Kramerius4Export(RemoteStorage rstorage, AppConfiguration appConfiguration, String policy); File export(File output, boolean hierarchy, String log, String... pids); static void removeNils(Element elm); static final String KRAMERIUS_RELATION_NS; static final String KRAMERIUS_RELATION_PREFIX; static final String OAI_NS; static final String[] ALLOWED_POLICY; }