@Test(expected = IOException.class) public void occurrenceRemarksMalformed() throws IOException { String occurrenceRemarks = "{\"hostGen\":\"Potamotrygon\",\"hostSpec\":\"sp.\",\"hostHiTax\":\"Pisces: Rajiformes: Potamotrygonidae\",\"hostBodyLoc\":\"gill\",\"hostFldNo\":\"Code: AC06-069\",\"hostRemarks\":\"sp. \"jam1\"\"}"; try { DatasetImporterForDwCA.parseUSNMStyleHostOccurrenceRemarks(occurrenceRemarks); } catch (IOException ex) { assertThat(ex.getMessage(), is("found likely malformed host description [{\"hostGen\":\"Potamotrygon\",\"hostSpec\":\"sp.\",\"hostHiTax\":\"Pisces: Rajiformes: Potamotrygonidae\",\"hostBodyLoc\":\"gill\",\"hostFldNo\":\"Code: AC06-069\",\"hostRemarks\":\"sp. \"jam1\"\"}], see https: throw ex; } }
public static Map<String, String> parseUSNMStyleHostOccurrenceRemarks(String occurrenceRemarks) throws IOException { Map<String, String> properties = Collections.emptyMap(); String candidateJsonChunk = null; String[] split = StringUtils.splitPreserveAllTokens(occurrenceRemarks, "{"); if (split.length > 1) { String[] splitClosing = StringUtils.splitPreserveAllTokens(split[1], "}"); if (splitClosing.length > 1) { candidateJsonChunk = "{" + splitClosing[0] + "}"; } } if (StringUtils.isNotBlank(candidateJsonChunk)) { try { properties = parseJsonChunk(candidateJsonChunk); } catch (IOException ex) { if (StringUtils.contains(candidateJsonChunk, "hostGen")) { throw new IOException("found likely malformed host description [" + candidateJsonChunk + "], see https: } } } return properties; }
DatasetImporterForDwCA extends DatasetImporterWithListener { public static Map<String, String> parseUSNMStyleHostOccurrenceRemarks(String occurrenceRemarks) throws IOException { Map<String, String> properties = Collections.emptyMap(); String candidateJsonChunk = null; String[] split = StringUtils.splitPreserveAllTokens(occurrenceRemarks, "{"); if (split.length > 1) { String[] splitClosing = StringUtils.splitPreserveAllTokens(split[1], "}"); if (splitClosing.length > 1) { candidateJsonChunk = "{" + splitClosing[0] + "}"; } } if (StringUtils.isNotBlank(candidateJsonChunk)) { try { properties = parseJsonChunk(candidateJsonChunk); } catch (IOException ex) { if (StringUtils.contains(candidateJsonChunk, "hostGen")) { throw new IOException("found likely malformed host description [" + candidateJsonChunk + "], see https: } } } return properties; } }
DatasetImporterForDwCA extends DatasetImporterWithListener { public static Map<String, String> parseUSNMStyleHostOccurrenceRemarks(String occurrenceRemarks) throws IOException { Map<String, String> properties = Collections.emptyMap(); String candidateJsonChunk = null; String[] split = StringUtils.splitPreserveAllTokens(occurrenceRemarks, "{"); if (split.length > 1) { String[] splitClosing = StringUtils.splitPreserveAllTokens(split[1], "}"); if (splitClosing.length > 1) { candidateJsonChunk = "{" + splitClosing[0] + "}"; } } if (StringUtils.isNotBlank(candidateJsonChunk)) { try { properties = parseJsonChunk(candidateJsonChunk); } catch (IOException ex) { if (StringUtils.contains(candidateJsonChunk, "hostGen")) { throw new IOException("found likely malformed host description [" + candidateJsonChunk + "], see https: } } } return properties; } DatasetImporterForDwCA(ParserFactory parserFactory, NodeFactory nodeFactory); }
DatasetImporterForDwCA extends DatasetImporterWithListener { public static Map<String, String> parseUSNMStyleHostOccurrenceRemarks(String occurrenceRemarks) throws IOException { Map<String, String> properties = Collections.emptyMap(); String candidateJsonChunk = null; String[] split = StringUtils.splitPreserveAllTokens(occurrenceRemarks, "{"); if (split.length > 1) { String[] splitClosing = StringUtils.splitPreserveAllTokens(split[1], "}"); if (splitClosing.length > 1) { candidateJsonChunk = "{" + splitClosing[0] + "}"; } } if (StringUtils.isNotBlank(candidateJsonChunk)) { try { properties = parseJsonChunk(candidateJsonChunk); } catch (IOException ex) { if (StringUtils.contains(candidateJsonChunk, "hostGen")) { throw new IOException("found likely malformed host description [" + candidateJsonChunk + "], see https: } } } return properties; } DatasetImporterForDwCA(ParserFactory parserFactory, NodeFactory nodeFactory); @Override void importStudy(); int importCore(Archive archive, InteractionListener interactionListener); void handleRecord(InteractionListener interactionListener, Record rec); static void addRoyalSaskatchewanMuseumOwlPelletCollectionStyleRemarks(List<Map<String, String>> interactionCandidates, String occurrenceRemarks); static Map<String, String> parseRoyalSaskatchewanMuseumOwlPelletCollectionStyleRemarks(String occurrenceRemarks); void addUSNMStyleHostOccurrenceRemarks(List<Map<String, String>> interactionCandidates, String occurrenceRemarks); static void mapCoreProperties(Record rec, Map<String, String> interactionProperties); static void mapLocationAndReferenceInfo(Record rec, Map<String, String> interactionProperties); static void mapSourceProperties(Record rec, Map<String, String> interactionProperties); static void mapIfAvailable(Record rec, Map<String, String> interactionProperties, String key, Term term); static void mapIfAvailable(Map<String, String> interactionProperties, String key, String value); static Map<String, String> parseUSNMStyleHostOccurrenceRemarks(String occurrenceRemarks); static Map<String, String> parseJsonChunk(String candidateJsonChunk); }
DatasetImporterForDwCA extends DatasetImporterWithListener { public static Map<String, String> parseUSNMStyleHostOccurrenceRemarks(String occurrenceRemarks) throws IOException { Map<String, String> properties = Collections.emptyMap(); String candidateJsonChunk = null; String[] split = StringUtils.splitPreserveAllTokens(occurrenceRemarks, "{"); if (split.length > 1) { String[] splitClosing = StringUtils.splitPreserveAllTokens(split[1], "}"); if (splitClosing.length > 1) { candidateJsonChunk = "{" + splitClosing[0] + "}"; } } if (StringUtils.isNotBlank(candidateJsonChunk)) { try { properties = parseJsonChunk(candidateJsonChunk); } catch (IOException ex) { if (StringUtils.contains(candidateJsonChunk, "hostGen")) { throw new IOException("found likely malformed host description [" + candidateJsonChunk + "], see https: } } } return properties; } DatasetImporterForDwCA(ParserFactory parserFactory, NodeFactory nodeFactory); @Override void importStudy(); int importCore(Archive archive, InteractionListener interactionListener); void handleRecord(InteractionListener interactionListener, Record rec); static void addRoyalSaskatchewanMuseumOwlPelletCollectionStyleRemarks(List<Map<String, String>> interactionCandidates, String occurrenceRemarks); static Map<String, String> parseRoyalSaskatchewanMuseumOwlPelletCollectionStyleRemarks(String occurrenceRemarks); void addUSNMStyleHostOccurrenceRemarks(List<Map<String, String>> interactionCandidates, String occurrenceRemarks); static void mapCoreProperties(Record rec, Map<String, String> interactionProperties); static void mapLocationAndReferenceInfo(Record rec, Map<String, String> interactionProperties); static void mapSourceProperties(Record rec, Map<String, String> interactionProperties); static void mapIfAvailable(Record rec, Map<String, String> interactionProperties, String key, Term term); static void mapIfAvailable(Map<String, String> interactionProperties, String key, String value); static Map<String, String> parseUSNMStyleHostOccurrenceRemarks(String occurrenceRemarks); static Map<String, String> parseJsonChunk(String candidateJsonChunk); static final String EXTENSION_ASSOCIATED_TAXA; static final String EXTENSION_RESOURCE_RELATIONSHIP; static final String EXTENSION_TAXON; static final Pattern EX_NOTATION; static final Pattern REARED_EX_NOTATION; static final Pattern PATTERN_ASSOCIATED_TAXA_IDEA; static final Pattern PATTERN_ASSOCIATED_TAXA_EAE; }