@Test public void withEMLofINHS() throws URISyntaxException, IOException { Dataset origDataset = new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream); URI emlURI = getClass().getResource("inhs-eml.xml").toURI(); JsonNode config = EMLUtil.datasetWithEML(origDataset, emlURI); DatasetProxy proxy = new DatasetProxy(origDataset); proxy.setConfig(config); assertThat(proxy.getFormat(), is (MIME_TYPE_DWCA)); assertThat(proxy.getCitation(), is ("Illinois Natural History Survey Insect Collection. 2018-02-28.")); }
public static JsonNode datasetWithEML(ResourceService origDataset, URI emlURI) throws IOException { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(origDataset.retrieve(emlURI)); XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); String collectionName = StringUtils.trim(getFirstIfPresent(doc, xpath, " String datasetTitle = StringUtils.trim(getFirstIfPresent(doc, xpath, " String name = StringUtils.isBlank(collectionName) ? datasetTitle : collectionName; String pubDate = StringUtils.trim(getFirstIfPresent(doc, xpath, " String citation = StringUtils.trim(getFirstIfPresent(doc, xpath, " ObjectNode objectNode = new ObjectMapper().createObjectNode(); String datasetCitation = Stream.of(name, pubDate,citation) .filter(StringUtils::isNotBlank) .collect(Collectors.joining(". ")); objectNode.put("citation", datasetCitation + "."); objectNode.put("format", MIME_TYPE_DWCA); String string = new ObjectMapper().writeValueAsString(objectNode); return new ObjectMapper().readTree(string); } catch (XPathExpressionException | ParserConfigurationException | IOException | SAXException e) { throw new IOException("failed to handle xpath", e); } }
EMLUtil { public static JsonNode datasetWithEML(ResourceService origDataset, URI emlURI) throws IOException { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(origDataset.retrieve(emlURI)); XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); String collectionName = StringUtils.trim(getFirstIfPresent(doc, xpath, " String datasetTitle = StringUtils.trim(getFirstIfPresent(doc, xpath, " String name = StringUtils.isBlank(collectionName) ? datasetTitle : collectionName; String pubDate = StringUtils.trim(getFirstIfPresent(doc, xpath, " String citation = StringUtils.trim(getFirstIfPresent(doc, xpath, " ObjectNode objectNode = new ObjectMapper().createObjectNode(); String datasetCitation = Stream.of(name, pubDate,citation) .filter(StringUtils::isNotBlank) .collect(Collectors.joining(". ")); objectNode.put("citation", datasetCitation + "."); objectNode.put("format", MIME_TYPE_DWCA); String string = new ObjectMapper().writeValueAsString(objectNode); return new ObjectMapper().readTree(string); } catch (XPathExpressionException | ParserConfigurationException | IOException | SAXException e) { throw new IOException("failed to handle xpath", e); } } }
EMLUtil { public static JsonNode datasetWithEML(ResourceService origDataset, URI emlURI) throws IOException { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(origDataset.retrieve(emlURI)); XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); String collectionName = StringUtils.trim(getFirstIfPresent(doc, xpath, " String datasetTitle = StringUtils.trim(getFirstIfPresent(doc, xpath, " String name = StringUtils.isBlank(collectionName) ? datasetTitle : collectionName; String pubDate = StringUtils.trim(getFirstIfPresent(doc, xpath, " String citation = StringUtils.trim(getFirstIfPresent(doc, xpath, " ObjectNode objectNode = new ObjectMapper().createObjectNode(); String datasetCitation = Stream.of(name, pubDate,citation) .filter(StringUtils::isNotBlank) .collect(Collectors.joining(". ")); objectNode.put("citation", datasetCitation + "."); objectNode.put("format", MIME_TYPE_DWCA); String string = new ObjectMapper().writeValueAsString(objectNode); return new ObjectMapper().readTree(string); } catch (XPathExpressionException | ParserConfigurationException | IOException | SAXException e) { throw new IOException("failed to handle xpath", e); } }  }
EMLUtil { public static JsonNode datasetWithEML(ResourceService origDataset, URI emlURI) throws IOException { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(origDataset.retrieve(emlURI)); XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); String collectionName = StringUtils.trim(getFirstIfPresent(doc, xpath, " String datasetTitle = StringUtils.trim(getFirstIfPresent(doc, xpath, " String name = StringUtils.isBlank(collectionName) ? datasetTitle : collectionName; String pubDate = StringUtils.trim(getFirstIfPresent(doc, xpath, " String citation = StringUtils.trim(getFirstIfPresent(doc, xpath, " ObjectNode objectNode = new ObjectMapper().createObjectNode(); String datasetCitation = Stream.of(name, pubDate,citation) .filter(StringUtils::isNotBlank) .collect(Collectors.joining(". ")); objectNode.put("citation", datasetCitation + "."); objectNode.put("format", MIME_TYPE_DWCA); String string = new ObjectMapper().writeValueAsString(objectNode); return new ObjectMapper().readTree(string); } catch (XPathExpressionException | ParserConfigurationException | IOException | SAXException e) { throw new IOException("failed to handle xpath", e); } }  static JsonNode datasetWithEML(ResourceService origDataset, URI emlURI); }
EMLUtil { public static JsonNode datasetWithEML(ResourceService origDataset, URI emlURI) throws IOException { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(origDataset.retrieve(emlURI)); XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); String collectionName = StringUtils.trim(getFirstIfPresent(doc, xpath, " String datasetTitle = StringUtils.trim(getFirstIfPresent(doc, xpath, " String name = StringUtils.isBlank(collectionName) ? datasetTitle : collectionName; String pubDate = StringUtils.trim(getFirstIfPresent(doc, xpath, " String citation = StringUtils.trim(getFirstIfPresent(doc, xpath, " ObjectNode objectNode = new ObjectMapper().createObjectNode(); String datasetCitation = Stream.of(name, pubDate,citation) .filter(StringUtils::isNotBlank) .collect(Collectors.joining(". ")); objectNode.put("citation", datasetCitation + "."); objectNode.put("format", MIME_TYPE_DWCA); String string = new ObjectMapper().writeValueAsString(objectNode); return new ObjectMapper().readTree(string); } catch (XPathExpressionException | ParserConfigurationException | IOException | SAXException e) { throw new IOException("failed to handle xpath", e); } }  static JsonNode datasetWithEML(ResourceService origDataset, URI emlURI);  }