Search in sources :

Example 6 with ResourceService

use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.

the class InteractTypeMapperFactoryImplTest method nonMatchingBlankMapping.

@Test
public void nonMatchingBlankMapping() throws TermLookupServiceException, IOException {
    ResourceService resourceService = Mockito.mock(ResourceService.class);
    when(resourceService.retrieve(URI.create("interaction_types_ignored.csv"))).thenReturn(IOUtils.toInputStream("interaction_type_ignored\nshouldBeIgnored", StandardCharsets.UTF_8));
    String mapping = "provided_interaction_type_label,provided_interaction_type_id,mapped_to_interaction_type_label,mapped_to_interaction_type_id" + "\n,,interactsWith, http://purl.obolibrary.org/obo/RO_0002437";
    when(resourceService.retrieve(URI.create("interaction_types_mapping.csv"))).thenReturn(IOUtils.toInputStream(mapping, StandardCharsets.UTF_8));
    InteractTypeMapperFactory interactTypeMapperFactory = new InteractTypeMapperFactoryImpl(resourceService);
    assertThat(interactTypeMapperFactory.create().getInteractType("foo"), is(nullValue()));
}
Also used : ResourceService(org.eol.globi.service.ResourceService) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 7 with ResourceService

use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.

the class InteractionListenerImplTest method processMessageWithOIgnoredInteractionType.

@Test
public void processMessageWithOIgnoredInteractionType() throws StudyImporterException, IOException {
    ResourceService resourceService = Mockito.mock(ResourceService.class);
    when(resourceService.retrieve(URI.create("interaction_types_ignored.csv"))).thenReturn(IOUtils.toInputStream("provided_interaction_type_id\nshouldBeIgnored", StandardCharsets.UTF_8)).thenReturn(IOUtils.toInputStream("provided_interaction_type_id\nshouldBeIgnored", StandardCharsets.UTF_8));
    when(resourceService.retrieve(URI.create("interaction_types_mapping.csv"))).thenReturn(IOUtils.toInputStream(getTestMap(), StandardCharsets.UTF_8));
    Dataset dataset = new DatasetImpl("bla", resourceService, URI.create("foo:bar"));
    InteractionListenerImpl interactionListener = new InteractionListenerImpl(nodeFactory, null, null, dataset);
    HashMap<String, String> interaction = new HashMap<>();
    interaction.put(SOURCE_TAXON_NAME, "sourceName");
    interaction.put(DatasetImporterForTSV.INTERACTION_TYPE_NAME, "shouldBeIgnored");
    interaction.put(TARGET_TAXON_NAME, "targetName");
    interaction.put(REFERENCE_ID, "citation");
    assertStudyCount(0L);
    interactionListener.on(interaction);
    assertStudyCount(0L);
}
Also used : HashMap(java.util.HashMap) Dataset(org.globalbioticinteractions.dataset.Dataset) ResourceService(org.eol.globi.service.ResourceService) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Test(org.junit.Test)

Example 8 with ResourceService

use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.

the class DatasetImporterForMangalTest method pageThroughEndpoint.

@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://example.org/";
    DatasetImporterForMangal.retrievePagedResource(resourceService, listener, pageSize, pageNumber, urlEndpoint);
    assertThat(nodes.size(), Is.is(101));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResourceService(org.eol.globi.service.ResourceService) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) URI(java.net.URI) Test(org.junit.Test)

Example 9 with ResourceService

use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.

the class DatasetImporterForPensoftTest method generateTableData.

@Test
public void generateTableData() throws IOException, StudyImporterException {
    List<Map<String, String>> links = new ArrayList<>();
    parseRowsAndEnrich(getTableObj(), new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            links.add(interaction);
        }
    }, new ResourceService() {

        @Override
        public InputStream retrieve(URI resourceName) throws IOException {
            String journalQueryPrefix = "http://graph.openbiodiv.net/repositories/OpenBiodiv2020?query=PREFIX%20fabio:%20%3Chttp://purl.org/spar/fabio/%3E%0APREFIX%20prism:%20%3Chttp://prismstandard.org/namespaces/basic/2.0/%3E%0APREFIX%20doco:%20%3Chttp://purl.org/spar/doco/%3E%0APREFIX%20dc:%20%3Chttp://purl.org/dc/elements/1.1/%3E%0ASELECT%20%20%20%20?article%20%20%20%20?title%20%20%20%20?doi%20%20%20%20(group_concat(distinct%20?authorName;%20separator=%22,%20%22)%20as%20?authorsList)%20%20%20%20%20(%20REPLACE(str(?pubDate),%20%22(%5C%5Cd*)-.*%22,%20%22$1%22)%20as%20?pubYear)%20%20%20%20?journalName%20WHERE%20%7B%20%0A%20%20%20%20BIND(";
            String taxonQueryPrefix = "http://graph.openbiodiv.net/repositories/OpenBiodiv2020?query=PREFIX%20fabio:%20%3Chttp://purl.org/spar/fabio/%3E%0APREFIX%20prism:%20%3Chttp://prismstandard.org/namespaces/basic/2.0/%3E%0APREFIX%20doco:%20%3Chttp://purl.org/spar/doco/%3E%0APREFIX%20dc:%20%3Chttp://purl.org/dc/elements/1.1/%3E%0Aselect%20?name%20?rank%20?id%20?kingdom%20?phylum%20?class%20?order%20?family%20?genus%20?specificEpithet%20where%20%7B%20%7B%0A%20%20%20%20BIND";
            if (StringUtils.startsWith(resourceName.toString(), journalQueryPrefix)) {
                return getClass().getResourceAsStream("/org/eol/globi/data/pensoft/pensoft-sparql-result.txt");
            } else if (resourceName.toString().startsWith(taxonQueryPrefix)) {
                return getClass().getResourceAsStream("/org/eol/globi/data/pensoft/pensoft-sparql-result2.txt");
            } else {
                throw new RuntimeException("unexpected");
            }
        }
    });
    assertThat(links.size(), is(121));
    for (Map<String, String> link : links) {
        assertThat(link.get("tableSchema"), is("{\"columns\":[{\"name\":\"Family Name\",\"titles\":\"Family Name\",\"datatype\":\"string\"},{\"name\":\"Host Plant\",\"titles\":\"Host Plant\",\"datatype\":\"string\"},{\"name\":\"Thrips species\",\"titles\":\"Thrips species\",\"datatype\":\"string\"},{\"name\":\"Family Name_expanded_taxon_id\",\"titles\":\"Family Name_expanded_taxon_id\",\"datatype\":\"string\"},{\"name\":\"Family Name_expanded_taxon_name\",\"titles\":\"Family Name_expanded_taxon_name\",\"datatype\":\"string\"},{\"name\":\"Host Plant_expanded_taxon_id\",\"titles\":\"Host Plant_expanded_taxon_id\",\"datatype\":\"string\"},{\"name\":\"Host Plant_expanded_taxon_name\",\"titles\":\"Host Plant_expanded_taxon_name\",\"datatype\":\"string\"},{\"name\":\"Thrips species_expanded_taxon_id\",\"titles\":\"Thrips species_expanded_taxon_id\",\"datatype\":\"string\"},{\"name\":\"Thrips species_expanded_taxon_name\",\"titles\":\"Thrips species_expanded_taxon_name\",\"datatype\":\"string\"}]}"));
    }
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ResourceService(org.eol.globi.service.ResourceService) IOException(java.io.IOException) URI(java.net.URI) InteractionListener(org.eol.globi.process.InteractionListener) Map(java.util.Map) Test(org.junit.Test)

Example 10 with ResourceService

use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.

the class DatasetImporterForZenodoMetadataIT method findAnnotations.

@Test
public void findAnnotations() throws IOException, StudyImporterException {
    final ResourceService resourceService = TestUtil.getResourceServiceTest();
    final InputStream searchResultStream = resourceService.retrieve(URI.create("https://sandbox.zenodo.org/api/records/?custom=%5Bobo%3ARO_0002453%5D%3A%5B%3A%5D"));
    assertInteractionOfExamplePub(searchResultStream);
}
Also used : InputStream(java.io.InputStream) ResourceService(org.eol.globi.service.ResourceService) Test(org.junit.Test)

Aggregations

ResourceService (org.eol.globi.service.ResourceService)34 Test (org.junit.Test)31 IOException (java.io.IOException)9 Matchers.anyString (org.mockito.Matchers.anyString)9 URI (java.net.URI)7 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)3 InteractType (org.eol.globi.domain.InteractType)3 InteractionListener (org.eol.globi.process.InteractionListener)3 TermLookupService (org.eol.globi.service.TermLookupService)3 DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 HashMap (java.util.HashMap)2 Term (org.eol.globi.domain.Term)2 TermLookupServiceConfigurationException (org.eol.globi.service.TermLookupServiceConfigurationException)2 TermLookupServiceException (org.eol.globi.service.TermLookupServiceException)2 Dataset (org.globalbioticinteractions.dataset.Dataset)2 OpenBiodivClientImpl (org.globalbioticinteractions.util.OpenBiodivClientImpl)2 SparqlClient (org.globalbioticinteractions.util.SparqlClient)2