@Test public void parseWithDateRange() throws IOException, StudyImporterException { InputStream first2 = getClass().getResourceAsStream("/org/eol/globi/data/dbatvir/dbatvir-daterange.json"); List<Map<String, String>> links = new ArrayList<>(); InteractionListener interactionListener = links::add; DatasetImporterForDBatVir.parseInteractions(first2, interactionListener); assertThat(links.size(), Is.is(2)); assertThat(links.get(0).get(DatasetImporterForMetaTable.EVENT_DATE), Is.is("2012-03/2014-07")); }
public static void parseInteractions(InputStream pageStream, InteractionListener interactionListener) throws IOException, StudyImporterException { ObjectMapper objectMapper = getLenientObjectMapper(); JsonNode jsonNode = objectMapper.readTree(new InputStreamReader(pageStream, StandardCharsets.ISO_8859_1)); if (jsonNode.has("data")) { JsonNode data = jsonNode.get("data"); Map<String, String> link = new TreeMap<>(); for (JsonNode interactionNode : data) { String strainName = textValueOrEmpty(interactionNode, "StrainName"); String virusName = textValueOrEmpty(interactionNode, "Virus"); if (StringUtils.isNotBlank(strainName)) { link.put(TARGET_TAXON_NAME, strainName); link.put(TARGET_TAXON_RANK, strainName); } else if (StringUtils.isNotBlank(virusName)) { if (StringUtils.isNotBlank(virusName)) { link.put(TARGET_TAXON_NAME, virusName); link.put(TARGET_TAXON_RANK, virusName); } } String targetTaxonId = getTaxonId(interactionNode, "v_tax"); if (StringUtils.isNotBlank(targetTaxonId)) { link.put(TARGET_TAXON_ID, targetTaxonId); } String targetTaxonPath = Stream.of( textValueOrEmpty(interactionNode, "v_family"), virusName, strainName) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH, targetTaxonPath); String targetTaxonPathNames = Stream.of( "family", "species", "strain") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH_NAMES, targetTaxonPathNames); String targetTaxonPathIds = Stream.of( "", targetTaxonId, "") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH_IDS, targetTaxonPathIds); setPropertyIfNotBlank(link, interactionNode, SOURCE_TAXON_NAME, "Bat"); String sourceTaxonId = getTaxonId(interactionNode, "b_tax"); if (StringUtils.isNotBlank(sourceTaxonId)) { link.put(SOURCE_TAXON_ID, sourceTaxonId); } String sourceTaxonPath = Stream.of( textValueOrEmpty(interactionNode, "b_family"), textValueOrEmpty(interactionNode, "Bat")) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH, sourceTaxonPath); String sourceTaxonPathNames = Stream.of( "family", "species") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH_NAMES, sourceTaxonPathNames); String sourceTaxonPathIds = Stream.of( "", sourceTaxonId) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH_IDS, sourceTaxonPathIds); String value = JSONUtil.textValueOrNull(interactionNode, "CollectionDate"); if (StringUtils.isNotBlank(value)) { String replace = StringUtils.replace(value, "~", "/"); link.put(DatasetImporterForMetaTable.EVENT_DATE, replace); } String localityName = Stream.of(JSONUtil.textValueOrNull(interactionNode, "Country"), JSONUtil.textValueOrNull(interactionNode, "Location")) .filter(StringUtils::isNotBlank) .collect(Collectors.joining(" ")); if (StringUtils.isNotBlank(localityName)) { link.put(LOCALITY_NAME, localityName); } String refs = JSONUtil.textValueOrNull(interactionNode, "Refs"); if (StringUtils.isNotBlank(refs)) { link.put(REFERENCE_CITATION, scrubReferenceCitation(refs)); } String pubMedString = JSONUtil.textValueOrNull(interactionNode, "PubMed"); if (StringUtils.isNotBlank(pubMedString)) { String referenceId = extractFirstPubMedReferenceId(pubMedString); if (StringUtils.isNotBlank(referenceId)) { link.put(REFERENCE_ID, referenceId); link.put(REFERENCE_URL, referenceId); } } link.put(INTERACTION_TYPE_ID, InteractType.HOST_OF.getIRI()); link.put(INTERACTION_TYPE_NAME, InteractType.HOST_OF.getLabel()); interactionListener.newLink(link); } } }
DatasetImporterForDBatVir extends DatasetImporterWithListener { public static void parseInteractions(InputStream pageStream, InteractionListener interactionListener) throws IOException, StudyImporterException { ObjectMapper objectMapper = getLenientObjectMapper(); JsonNode jsonNode = objectMapper.readTree(new InputStreamReader(pageStream, StandardCharsets.ISO_8859_1)); if (jsonNode.has("data")) { JsonNode data = jsonNode.get("data"); Map<String, String> link = new TreeMap<>(); for (JsonNode interactionNode : data) { String strainName = textValueOrEmpty(interactionNode, "StrainName"); String virusName = textValueOrEmpty(interactionNode, "Virus"); if (StringUtils.isNotBlank(strainName)) { link.put(TARGET_TAXON_NAME, strainName); link.put(TARGET_TAXON_RANK, strainName); } else if (StringUtils.isNotBlank(virusName)) { if (StringUtils.isNotBlank(virusName)) { link.put(TARGET_TAXON_NAME, virusName); link.put(TARGET_TAXON_RANK, virusName); } } String targetTaxonId = getTaxonId(interactionNode, "v_tax"); if (StringUtils.isNotBlank(targetTaxonId)) { link.put(TARGET_TAXON_ID, targetTaxonId); } String targetTaxonPath = Stream.of( textValueOrEmpty(interactionNode, "v_family"), virusName, strainName) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH, targetTaxonPath); String targetTaxonPathNames = Stream.of( "family", "species", "strain") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH_NAMES, targetTaxonPathNames); String targetTaxonPathIds = Stream.of( "", targetTaxonId, "") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH_IDS, targetTaxonPathIds); setPropertyIfNotBlank(link, interactionNode, SOURCE_TAXON_NAME, "Bat"); String sourceTaxonId = getTaxonId(interactionNode, "b_tax"); if (StringUtils.isNotBlank(sourceTaxonId)) { link.put(SOURCE_TAXON_ID, sourceTaxonId); } String sourceTaxonPath = Stream.of( textValueOrEmpty(interactionNode, "b_family"), textValueOrEmpty(interactionNode, "Bat")) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH, sourceTaxonPath); String sourceTaxonPathNames = Stream.of( "family", "species") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH_NAMES, sourceTaxonPathNames); String sourceTaxonPathIds = Stream.of( "", sourceTaxonId) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH_IDS, sourceTaxonPathIds); String value = JSONUtil.textValueOrNull(interactionNode, "CollectionDate"); if (StringUtils.isNotBlank(value)) { String replace = StringUtils.replace(value, "~", "/"); link.put(DatasetImporterForMetaTable.EVENT_DATE, replace); } String localityName = Stream.of(JSONUtil.textValueOrNull(interactionNode, "Country"), JSONUtil.textValueOrNull(interactionNode, "Location")) .filter(StringUtils::isNotBlank) .collect(Collectors.joining(" ")); if (StringUtils.isNotBlank(localityName)) { link.put(LOCALITY_NAME, localityName); } String refs = JSONUtil.textValueOrNull(interactionNode, "Refs"); if (StringUtils.isNotBlank(refs)) { link.put(REFERENCE_CITATION, scrubReferenceCitation(refs)); } String pubMedString = JSONUtil.textValueOrNull(interactionNode, "PubMed"); if (StringUtils.isNotBlank(pubMedString)) { String referenceId = extractFirstPubMedReferenceId(pubMedString); if (StringUtils.isNotBlank(referenceId)) { link.put(REFERENCE_ID, referenceId); link.put(REFERENCE_URL, referenceId); } } link.put(INTERACTION_TYPE_ID, InteractType.HOST_OF.getIRI()); link.put(INTERACTION_TYPE_NAME, InteractType.HOST_OF.getLabel()); interactionListener.newLink(link); } } } }
DatasetImporterForDBatVir extends DatasetImporterWithListener { public static void parseInteractions(InputStream pageStream, InteractionListener interactionListener) throws IOException, StudyImporterException { ObjectMapper objectMapper = getLenientObjectMapper(); JsonNode jsonNode = objectMapper.readTree(new InputStreamReader(pageStream, StandardCharsets.ISO_8859_1)); if (jsonNode.has("data")) { JsonNode data = jsonNode.get("data"); Map<String, String> link = new TreeMap<>(); for (JsonNode interactionNode : data) { String strainName = textValueOrEmpty(interactionNode, "StrainName"); String virusName = textValueOrEmpty(interactionNode, "Virus"); if (StringUtils.isNotBlank(strainName)) { link.put(TARGET_TAXON_NAME, strainName); link.put(TARGET_TAXON_RANK, strainName); } else if (StringUtils.isNotBlank(virusName)) { if (StringUtils.isNotBlank(virusName)) { link.put(TARGET_TAXON_NAME, virusName); link.put(TARGET_TAXON_RANK, virusName); } } String targetTaxonId = getTaxonId(interactionNode, "v_tax"); if (StringUtils.isNotBlank(targetTaxonId)) { link.put(TARGET_TAXON_ID, targetTaxonId); } String targetTaxonPath = Stream.of( textValueOrEmpty(interactionNode, "v_family"), virusName, strainName) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH, targetTaxonPath); String targetTaxonPathNames = Stream.of( "family", "species", "strain") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH_NAMES, targetTaxonPathNames); String targetTaxonPathIds = Stream.of( "", targetTaxonId, "") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH_IDS, targetTaxonPathIds); setPropertyIfNotBlank(link, interactionNode, SOURCE_TAXON_NAME, "Bat"); String sourceTaxonId = getTaxonId(interactionNode, "b_tax"); if (StringUtils.isNotBlank(sourceTaxonId)) { link.put(SOURCE_TAXON_ID, sourceTaxonId); } String sourceTaxonPath = Stream.of( textValueOrEmpty(interactionNode, "b_family"), textValueOrEmpty(interactionNode, "Bat")) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH, sourceTaxonPath); String sourceTaxonPathNames = Stream.of( "family", "species") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH_NAMES, sourceTaxonPathNames); String sourceTaxonPathIds = Stream.of( "", sourceTaxonId) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH_IDS, sourceTaxonPathIds); String value = JSONUtil.textValueOrNull(interactionNode, "CollectionDate"); if (StringUtils.isNotBlank(value)) { String replace = StringUtils.replace(value, "~", "/"); link.put(DatasetImporterForMetaTable.EVENT_DATE, replace); } String localityName = Stream.of(JSONUtil.textValueOrNull(interactionNode, "Country"), JSONUtil.textValueOrNull(interactionNode, "Location")) .filter(StringUtils::isNotBlank) .collect(Collectors.joining(" ")); if (StringUtils.isNotBlank(localityName)) { link.put(LOCALITY_NAME, localityName); } String refs = JSONUtil.textValueOrNull(interactionNode, "Refs"); if (StringUtils.isNotBlank(refs)) { link.put(REFERENCE_CITATION, scrubReferenceCitation(refs)); } String pubMedString = JSONUtil.textValueOrNull(interactionNode, "PubMed"); if (StringUtils.isNotBlank(pubMedString)) { String referenceId = extractFirstPubMedReferenceId(pubMedString); if (StringUtils.isNotBlank(referenceId)) { link.put(REFERENCE_ID, referenceId); link.put(REFERENCE_URL, referenceId); } } link.put(INTERACTION_TYPE_ID, InteractType.HOST_OF.getIRI()); link.put(INTERACTION_TYPE_NAME, InteractType.HOST_OF.getLabel()); interactionListener.newLink(link); } } } DatasetImporterForDBatVir(ParserFactory parserFactory, NodeFactory nodeFactory); }
DatasetImporterForDBatVir extends DatasetImporterWithListener { public static void parseInteractions(InputStream pageStream, InteractionListener interactionListener) throws IOException, StudyImporterException { ObjectMapper objectMapper = getLenientObjectMapper(); JsonNode jsonNode = objectMapper.readTree(new InputStreamReader(pageStream, StandardCharsets.ISO_8859_1)); if (jsonNode.has("data")) { JsonNode data = jsonNode.get("data"); Map<String, String> link = new TreeMap<>(); for (JsonNode interactionNode : data) { String strainName = textValueOrEmpty(interactionNode, "StrainName"); String virusName = textValueOrEmpty(interactionNode, "Virus"); if (StringUtils.isNotBlank(strainName)) { link.put(TARGET_TAXON_NAME, strainName); link.put(TARGET_TAXON_RANK, strainName); } else if (StringUtils.isNotBlank(virusName)) { if (StringUtils.isNotBlank(virusName)) { link.put(TARGET_TAXON_NAME, virusName); link.put(TARGET_TAXON_RANK, virusName); } } String targetTaxonId = getTaxonId(interactionNode, "v_tax"); if (StringUtils.isNotBlank(targetTaxonId)) { link.put(TARGET_TAXON_ID, targetTaxonId); } String targetTaxonPath = Stream.of( textValueOrEmpty(interactionNode, "v_family"), virusName, strainName) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH, targetTaxonPath); String targetTaxonPathNames = Stream.of( "family", "species", "strain") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH_NAMES, targetTaxonPathNames); String targetTaxonPathIds = Stream.of( "", targetTaxonId, "") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH_IDS, targetTaxonPathIds); setPropertyIfNotBlank(link, interactionNode, SOURCE_TAXON_NAME, "Bat"); String sourceTaxonId = getTaxonId(interactionNode, "b_tax"); if (StringUtils.isNotBlank(sourceTaxonId)) { link.put(SOURCE_TAXON_ID, sourceTaxonId); } String sourceTaxonPath = Stream.of( textValueOrEmpty(interactionNode, "b_family"), textValueOrEmpty(interactionNode, "Bat")) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH, sourceTaxonPath); String sourceTaxonPathNames = Stream.of( "family", "species") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH_NAMES, sourceTaxonPathNames); String sourceTaxonPathIds = Stream.of( "", sourceTaxonId) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH_IDS, sourceTaxonPathIds); String value = JSONUtil.textValueOrNull(interactionNode, "CollectionDate"); if (StringUtils.isNotBlank(value)) { String replace = StringUtils.replace(value, "~", "/"); link.put(DatasetImporterForMetaTable.EVENT_DATE, replace); } String localityName = Stream.of(JSONUtil.textValueOrNull(interactionNode, "Country"), JSONUtil.textValueOrNull(interactionNode, "Location")) .filter(StringUtils::isNotBlank) .collect(Collectors.joining(" ")); if (StringUtils.isNotBlank(localityName)) { link.put(LOCALITY_NAME, localityName); } String refs = JSONUtil.textValueOrNull(interactionNode, "Refs"); if (StringUtils.isNotBlank(refs)) { link.put(REFERENCE_CITATION, scrubReferenceCitation(refs)); } String pubMedString = JSONUtil.textValueOrNull(interactionNode, "PubMed"); if (StringUtils.isNotBlank(pubMedString)) { String referenceId = extractFirstPubMedReferenceId(pubMedString); if (StringUtils.isNotBlank(referenceId)) { link.put(REFERENCE_ID, referenceId); link.put(REFERENCE_URL, referenceId); } } link.put(INTERACTION_TYPE_ID, InteractType.HOST_OF.getIRI()); link.put(INTERACTION_TYPE_NAME, InteractType.HOST_OF.getLabel()); interactionListener.newLink(link); } } } DatasetImporterForDBatVir(ParserFactory parserFactory, NodeFactory nodeFactory); static String scrubReferenceCitation(String refs); @Override void importStudy(); int getTotalCount(); static void parseInteractions(InputStream pageStream, InteractionListener interactionListener); static ObjectMapper getLenientObjectMapper(); }
DatasetImporterForDBatVir extends DatasetImporterWithListener { public static void parseInteractions(InputStream pageStream, InteractionListener interactionListener) throws IOException, StudyImporterException { ObjectMapper objectMapper = getLenientObjectMapper(); JsonNode jsonNode = objectMapper.readTree(new InputStreamReader(pageStream, StandardCharsets.ISO_8859_1)); if (jsonNode.has("data")) { JsonNode data = jsonNode.get("data"); Map<String, String> link = new TreeMap<>(); for (JsonNode interactionNode : data) { String strainName = textValueOrEmpty(interactionNode, "StrainName"); String virusName = textValueOrEmpty(interactionNode, "Virus"); if (StringUtils.isNotBlank(strainName)) { link.put(TARGET_TAXON_NAME, strainName); link.put(TARGET_TAXON_RANK, strainName); } else if (StringUtils.isNotBlank(virusName)) { if (StringUtils.isNotBlank(virusName)) { link.put(TARGET_TAXON_NAME, virusName); link.put(TARGET_TAXON_RANK, virusName); } } String targetTaxonId = getTaxonId(interactionNode, "v_tax"); if (StringUtils.isNotBlank(targetTaxonId)) { link.put(TARGET_TAXON_ID, targetTaxonId); } String targetTaxonPath = Stream.of( textValueOrEmpty(interactionNode, "v_family"), virusName, strainName) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH, targetTaxonPath); String targetTaxonPathNames = Stream.of( "family", "species", "strain") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH_NAMES, targetTaxonPathNames); String targetTaxonPathIds = Stream.of( "", targetTaxonId, "") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(TARGET_TAXON_PATH_IDS, targetTaxonPathIds); setPropertyIfNotBlank(link, interactionNode, SOURCE_TAXON_NAME, "Bat"); String sourceTaxonId = getTaxonId(interactionNode, "b_tax"); if (StringUtils.isNotBlank(sourceTaxonId)) { link.put(SOURCE_TAXON_ID, sourceTaxonId); } String sourceTaxonPath = Stream.of( textValueOrEmpty(interactionNode, "b_family"), textValueOrEmpty(interactionNode, "Bat")) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH, sourceTaxonPath); String sourceTaxonPathNames = Stream.of( "family", "species") .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH_NAMES, sourceTaxonPathNames); String sourceTaxonPathIds = Stream.of( "", sourceTaxonId) .map(StringUtils::trim) .collect(Collectors.joining(CharsetConstant.SEPARATOR)); link.put(SOURCE_TAXON_PATH_IDS, sourceTaxonPathIds); String value = JSONUtil.textValueOrNull(interactionNode, "CollectionDate"); if (StringUtils.isNotBlank(value)) { String replace = StringUtils.replace(value, "~", "/"); link.put(DatasetImporterForMetaTable.EVENT_DATE, replace); } String localityName = Stream.of(JSONUtil.textValueOrNull(interactionNode, "Country"), JSONUtil.textValueOrNull(interactionNode, "Location")) .filter(StringUtils::isNotBlank) .collect(Collectors.joining(" ")); if (StringUtils.isNotBlank(localityName)) { link.put(LOCALITY_NAME, localityName); } String refs = JSONUtil.textValueOrNull(interactionNode, "Refs"); if (StringUtils.isNotBlank(refs)) { link.put(REFERENCE_CITATION, scrubReferenceCitation(refs)); } String pubMedString = JSONUtil.textValueOrNull(interactionNode, "PubMed"); if (StringUtils.isNotBlank(pubMedString)) { String referenceId = extractFirstPubMedReferenceId(pubMedString); if (StringUtils.isNotBlank(referenceId)) { link.put(REFERENCE_ID, referenceId); link.put(REFERENCE_URL, referenceId); } } link.put(INTERACTION_TYPE_ID, InteractType.HOST_OF.getIRI()); link.put(INTERACTION_TYPE_NAME, InteractType.HOST_OF.getLabel()); interactionListener.newLink(link); } } } DatasetImporterForDBatVir(ParserFactory parserFactory, NodeFactory nodeFactory); static String scrubReferenceCitation(String refs); @Override void importStudy(); int getTotalCount(); static void parseInteractions(InputStream pageStream, InteractionListener interactionListener); static ObjectMapper getLenientObjectMapper();  }