@Test public void pageThroughEndpoint() throws IOException, StudyImporterException { AtomicInteger counter = new AtomicInteger(0); ResourceService resourceService = new ResourceService() { @Override public InputStream retrieve(URI resourceName) throws IOException { int pageNumber = counter.getAndIncrement(); if (pageNumber == 0) { return getClass().getResourceAsStream("mangal-dataset.json"); } else if (pageNumber == 1) { return getClass().getResourceAsStream("mangal-dataset-partial.json"); } else { throw new IOException("no such page"); } } }; List<JsonNode> nodes = new ArrayList<>(); DatasetImporterForMangal.NodeListener listener = nodes::add; int pageSize = 100; int pageNumber = 0; String urlEndpoint = "https: DatasetImporterForMangal.retrievePagedResource(resourceService, listener, pageSize, pageNumber, urlEndpoint); assertThat(nodes.size(), Is.is(101)); }
public static void retrievePagedResource(ResourceService resourceService, NodeListener listener, int pageSize, int pageNumber, String urlEndpoint) throws StudyImporterException, IOException { URI pageUrl; do { pageUrl = getPagedUrl(urlEndpoint, pageNumber, pageSize); pageNumber++; } while (handlePagedResults(listener, resourceService.retrieve(pageUrl), pageSize)); }
DatasetImporterForMangal extends DatasetImporterWithListener { public static void retrievePagedResource(ResourceService resourceService, NodeListener listener, int pageSize, int pageNumber, String urlEndpoint) throws StudyImporterException, IOException { URI pageUrl; do { pageUrl = getPagedUrl(urlEndpoint, pageNumber, pageSize); pageNumber++; } while (handlePagedResults(listener, resourceService.retrieve(pageUrl), pageSize)); } }
DatasetImporterForMangal extends DatasetImporterWithListener { public static void retrievePagedResource(ResourceService resourceService, NodeListener listener, int pageSize, int pageNumber, String urlEndpoint) throws StudyImporterException, IOException { URI pageUrl; do { pageUrl = getPagedUrl(urlEndpoint, pageNumber, pageSize); pageNumber++; } while (handlePagedResults(listener, resourceService.retrieve(pageUrl), pageSize)); } DatasetImporterForMangal(ParserFactory parserFactory, NodeFactory nodeFactory); }
DatasetImporterForMangal extends DatasetImporterWithListener { public static void retrievePagedResource(ResourceService resourceService, NodeListener listener, int pageSize, int pageNumber, String urlEndpoint) throws StudyImporterException, IOException { URI pageUrl; do { pageUrl = getPagedUrl(urlEndpoint, pageNumber, pageSize); pageNumber++; } while (handlePagedResults(listener, resourceService.retrieve(pageUrl), pageSize)); } 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 retrievePagedResource(ResourceService resourceService, NodeListener listener, int pageSize, int pageNumber, String urlEndpoint) throws StudyImporterException, IOException { URI pageUrl; do { pageUrl = getPagedUrl(urlEndpoint, pageNumber, pageSize); pageNumber++; } while (handlePagedResults(listener, resourceService.retrieve(pageUrl), pageSize)); } 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; }