@Test public void buildNetworkMap() throws IOException, StudyImporterException { ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode = objectMapper.readTree(getClass().getResourceAsStream("mangal-network.json")); JsonNode singleNode = jsonNode.get(0); Map<String, Map<String, String>> networkMap = new TreeMap<>(); Map<String, Map<String, String>> datasetMap = new TreeMap<String, Map<String, String>>() {{ put("1", new TreeMap<String, String>() {{ put(DatasetImporterForTSV.REFERENCE_CITATION, "some citation"); put(DatasetImporterForTSV.REFERENCE_URL, "some url"); put(DatasetImporterForTSV.REFERENCE_DOI, "some doi"); }}); }}; DatasetImporterForMangal.appendNetworkToMap(singleNode, networkMap, datasetMap); assertThat(networkMap.containsKey("19"), Is.is(true)); Map<String, String> aNetwork = networkMap.get("19"); assertThat(aNetwork.get(DatasetImporterForTSV.DECIMAL_LATITUDE), Is.is("39.2798")); assertThat(aNetwork.get(DatasetImporterForTSV.DECIMAL_LONGITUDE), Is.is("-89.8818")); assertThat(aNetwork.get(DatasetImporterForTSV.REFERENCE_CITATION), Is.is("some citation")); assertThat(aNetwork.get(DatasetImporterForTSV.REFERENCE_DOI), Is.is("some doi")); assertThat(aNetwork.get(DatasetImporterForTSV.REFERENCE_URL), Is.is("some url")); }
public static void appendNetworkToMap(JsonNode singleNode, Map<String, Map<String, String>> networkMap, Map<String, Map<String, String>> datasetMap ) throws StudyImporterException { TreeMap<String, String> props = new TreeMap<>(); if (hasNonEmptyValueFor(singleNode, "dataset_id")) { String datasetId = singleNode.get("dataset_id").asText(); if (!datasetMap.containsKey(datasetId)) { throw new StudyImporterException("failed to find dataset with id [" + datasetId + "]"); } props.putAll(datasetMap.get(datasetId)); } if (hasNonEmptyValueFor(singleNode, "geom")) { JsonNode geom = singleNode.get("geom"); if (hasNonEmptyValueFor(geom, "type") && hasNonEmptyValueFor(geom, "coordinates")) { JsonNode coordinates = geom.get("coordinates"); if (coordinates.isArray() && coordinates.size() == 2) { props.put(DatasetImporterForTSV.DECIMAL_LONGITUDE, coordinates.get(0).asText()); props.put(DatasetImporterForTSV.DECIMAL_LATITUDE, coordinates.get(1).asText()); } } } networkMap.put(singleNode.get("id").asText(), props); }
DatasetImporterForMangal extends DatasetImporterWithListener { public static void appendNetworkToMap(JsonNode singleNode, Map<String, Map<String, String>> networkMap, Map<String, Map<String, String>> datasetMap ) throws StudyImporterException { TreeMap<String, String> props = new TreeMap<>(); if (hasNonEmptyValueFor(singleNode, "dataset_id")) { String datasetId = singleNode.get("dataset_id").asText(); if (!datasetMap.containsKey(datasetId)) { throw new StudyImporterException("failed to find dataset with id [" + datasetId + "]"); } props.putAll(datasetMap.get(datasetId)); } if (hasNonEmptyValueFor(singleNode, "geom")) { JsonNode geom = singleNode.get("geom"); if (hasNonEmptyValueFor(geom, "type") && hasNonEmptyValueFor(geom, "coordinates")) { JsonNode coordinates = geom.get("coordinates"); if (coordinates.isArray() && coordinates.size() == 2) { props.put(DatasetImporterForTSV.DECIMAL_LONGITUDE, coordinates.get(0).asText()); props.put(DatasetImporterForTSV.DECIMAL_LATITUDE, coordinates.get(1).asText()); } } } networkMap.put(singleNode.get("id").asText(), props); } }
DatasetImporterForMangal extends DatasetImporterWithListener { public static void appendNetworkToMap(JsonNode singleNode, Map<String, Map<String, String>> networkMap, Map<String, Map<String, String>> datasetMap ) throws StudyImporterException { TreeMap<String, String> props = new TreeMap<>(); if (hasNonEmptyValueFor(singleNode, "dataset_id")) { String datasetId = singleNode.get("dataset_id").asText(); if (!datasetMap.containsKey(datasetId)) { throw new StudyImporterException("failed to find dataset with id [" + datasetId + "]"); } props.putAll(datasetMap.get(datasetId)); } if (hasNonEmptyValueFor(singleNode, "geom")) { JsonNode geom = singleNode.get("geom"); if (hasNonEmptyValueFor(geom, "type") && hasNonEmptyValueFor(geom, "coordinates")) { JsonNode coordinates = geom.get("coordinates"); if (coordinates.isArray() && coordinates.size() == 2) { props.put(DatasetImporterForTSV.DECIMAL_LONGITUDE, coordinates.get(0).asText()); props.put(DatasetImporterForTSV.DECIMAL_LATITUDE, coordinates.get(1).asText()); } } } networkMap.put(singleNode.get("id").asText(), props); } DatasetImporterForMangal(ParserFactory parserFactory, NodeFactory nodeFactory); }
DatasetImporterForMangal extends DatasetImporterWithListener { public static void appendNetworkToMap(JsonNode singleNode, Map<String, Map<String, String>> networkMap, Map<String, Map<String, String>> datasetMap ) throws StudyImporterException { TreeMap<String, String> props = new TreeMap<>(); if (hasNonEmptyValueFor(singleNode, "dataset_id")) { String datasetId = singleNode.get("dataset_id").asText(); if (!datasetMap.containsKey(datasetId)) { throw new StudyImporterException("failed to find dataset with id [" + datasetId + "]"); } props.putAll(datasetMap.get(datasetId)); } if (hasNonEmptyValueFor(singleNode, "geom")) { JsonNode geom = singleNode.get("geom"); if (hasNonEmptyValueFor(geom, "type") && hasNonEmptyValueFor(geom, "coordinates")) { JsonNode coordinates = geom.get("coordinates"); if (coordinates.isArray() && coordinates.size() == 2) { props.put(DatasetImporterForTSV.DECIMAL_LONGITUDE, coordinates.get(0).asText()); props.put(DatasetImporterForTSV.DECIMAL_LATITUDE, coordinates.get(1).asText()); } } } networkMap.put(singleNode.get("id").asText(), props); } DatasetImporterForMangal(ParserFactory parserFactory, NodeFactory nodeFactory); static URI getPagedUrl(String urlEndpoint, int page, int limit); static void retrievePagedResource(ResourceService resourceService, NodeListener listener, int pageSize, int pageNumber, String urlEndpoint); static boolean handlePagedResults(NodeListener listener, InputStream resource, int limit); static void appendNodeToMap(JsonNode singleNode, Map<String, Map<String, String>> nodeMap); static boolean hasNonEmptyValueFor(JsonNode jsonNode, String key); static void appendReferenceToMap(JsonNode aReference, Map<String, Map<String, String>> refMap); static void appendNetworkToMap(JsonNode singleNode,
                                          Map<String, Map<String, String>> networkMap,
                                          Map<String, Map<String, String>> datasetMap
    ); static void appendDatasetToMap(JsonNode aDataset, Map<String, Map<String, String>> datasetMap, Map<String, Map<String, String>> refMap); static Map<String, String> parseInteraction(JsonNode singleInteraction, Map<String, Map<String, String>> nodeMap, Map<String, Map<String, String>> networkMap); static void addNameLabel(Map<String, Map<String, String>> nodeMap, JsonNode singleInteraction, Map<String, String> interaction, String nodeLabel, String nameLabel); @Override void importStudy(); }
DatasetImporterForMangal extends DatasetImporterWithListener { public static void appendNetworkToMap(JsonNode singleNode, Map<String, Map<String, String>> networkMap, Map<String, Map<String, String>> datasetMap ) throws StudyImporterException { TreeMap<String, String> props = new TreeMap<>(); if (hasNonEmptyValueFor(singleNode, "dataset_id")) { String datasetId = singleNode.get("dataset_id").asText(); if (!datasetMap.containsKey(datasetId)) { throw new StudyImporterException("failed to find dataset with id [" + datasetId + "]"); } props.putAll(datasetMap.get(datasetId)); } if (hasNonEmptyValueFor(singleNode, "geom")) { JsonNode geom = singleNode.get("geom"); if (hasNonEmptyValueFor(geom, "type") && hasNonEmptyValueFor(geom, "coordinates")) { JsonNode coordinates = geom.get("coordinates"); if (coordinates.isArray() && coordinates.size() == 2) { props.put(DatasetImporterForTSV.DECIMAL_LONGITUDE, coordinates.get(0).asText()); props.put(DatasetImporterForTSV.DECIMAL_LATITUDE, coordinates.get(1).asText()); } } } networkMap.put(singleNode.get("id").asText(), props); } DatasetImporterForMangal(ParserFactory parserFactory, NodeFactory nodeFactory); static URI getPagedUrl(String urlEndpoint, int page, int limit); static void retrievePagedResource(ResourceService resourceService, NodeListener listener, int pageSize, int pageNumber, String urlEndpoint); static boolean handlePagedResults(NodeListener listener, InputStream resource, int limit); static void appendNodeToMap(JsonNode singleNode, Map<String, Map<String, String>> nodeMap); static boolean hasNonEmptyValueFor(JsonNode jsonNode, String key); static void appendReferenceToMap(JsonNode aReference, Map<String, Map<String, String>> refMap); static void appendNetworkToMap(JsonNode singleNode,
                                          Map<String, Map<String, String>> networkMap,
                                          Map<String, Map<String, String>> datasetMap
    ); static void appendDatasetToMap(JsonNode aDataset, Map<String, Map<String, String>> datasetMap, Map<String, Map<String, String>> refMap); static Map<String, String> parseInteraction(JsonNode singleInteraction, Map<String, Map<String, String>> nodeMap, Map<String, Map<String, String>> networkMap); static void addNameLabel(Map<String, Map<String, String>> nodeMap, JsonNode singleInteraction, Map<String, String> interaction, String nodeLabel, String nameLabel); @Override void importStudy(); static final String MANGAL_API_ENDPOINT; static final Map<String, InteractType> INTERACTION_TYPE_MAP; }