@Test public void metaToMetaTables() throws URISyntaxException, IOException { Dataset origDataset = new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream); String uriString = "jar:" + getClass().getResource("dwca.zip").toURI().toString() + "!/vampire-moth-dwca-c4549a1690b84595c88946f477057b9ab76e5360/eml.xml"; JsonNode config = EMLUtil.datasetWithEML(origDataset, URI.create(uriString)); DatasetProxy proxy = new DatasetProxy(origDataset); proxy.setConfig(config); assertThat(proxy.getCitation(), is ("Occurrence Records for vampire-moths-and-their-fruit-piercing-relatives. 2018-09-27. South Central California Network - 2ba077c1-aa41-455e-9a84-bccb61a91230.")); assertThat(proxy.getFormat(), is (MIME_TYPE_DWCA)); }
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);  }