Search in sources :

Example 6 with DatasetImpl

use of org.globalbioticinteractions.dataset.DatasetImpl in project eol-globi-data by jhpoelen.

the class DatasetImporterForZenodoMetadataTest method paginate.

@Test
public void paginate() throws IOException, StudyImporterException {
    AtomicInteger counter = new AtomicInteger(0);
    final DatasetImporterForZenodoMetadata studyImporterForZenodoMetadata = new DatasetImporterForZenodoMetadata(null, null);
    studyImporterForZenodoMetadata.setInteractionListener(new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
        }
    });
    final DatasetImpl dataset = new DatasetImpl("name/space", URI.create("some:uri"), in -> in) {

        @Override
        public InputStream retrieve(URI resourceName) throws IOException {
            if (StringUtils.contains(resourceName.getHost(), "zenodo.org")) {
                counter.incrementAndGet();
            }
            InputStream is;
            if (URI.create("https://sandbox.zenodo.org/api/records/?sort=mostrecent&custom=%5Bobo%3ARO_0002453%5D%3A%5B%3A%5D&page=2&size=10").equals(resourceName)) {
                is = DatasetImporterForZenodoMetadataTest.class.getResourceAsStream("zenodo/search-results-page-2.json");
            } else if (URI.create("https://zenodo.org/api/records/?custom=%5Bobo%3ARO_0002453%5D%3A%5B%3A%5D").equals(resourceName)) {
                is = DatasetImporterForZenodoMetadataTest.class.getResourceAsStream("zenodo/search-results-page-1.json");
            } else {
                throw new IOException("kaboom!");
            }
            return is;
        }
    };
    studyImporterForZenodoMetadata.setDataset(dataset);
    studyImporterForZenodoMetadata.importStudy();
    assertThat(counter.get(), Is.is(2));
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputStream(java.io.InputStream) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) IOException(java.io.IOException) URI(java.net.URI) Test(org.junit.Test)

Example 7 with DatasetImpl

use of org.globalbioticinteractions.dataset.DatasetImpl in project eol-globi-data by jhpoelen.

the class NodeFactoryWithDatasetContextTest method getOrCreateStudyEmptyStudySource.

@Test
public void getOrCreateStudyEmptyStudySource() throws NodeFactoryException {
    NodeFactory factory = Mockito.mock(NodeFactory.class);
    Dataset dataset = new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream);
    NodeFactoryWithDatasetContext factoryWithDS = new NodeFactoryWithDatasetContext(factory, dataset);
    factoryWithDS.getOrCreateStudy(new StudyImpl("some title"));
    ArgumentCaptor<Study> argument = ArgumentCaptor.forClass(Study.class);
    verify(factory).getOrCreateStudy(argument.capture());
    assertEquals("some title", argument.getValue().getTitle());
}
Also used : Study(org.eol.globi.domain.Study) Dataset(org.globalbioticinteractions.dataset.Dataset) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Test(org.junit.Test)

Example 8 with DatasetImpl

use of org.globalbioticinteractions.dataset.DatasetImpl in project eol-globi-data by jhpoelen.

the class NodeFactoryWithDatasetContextTest method getOrCreateStudy.

@Test
public void getOrCreateStudy() throws NodeFactoryException {
    NodeFactory factory = Mockito.mock(NodeFactory.class);
    Dataset dataset = new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream);
    NodeFactoryWithDatasetContext factoryWithDS = new NodeFactoryWithDatasetContext(factory, dataset);
    factoryWithDS.getOrCreateStudy(new StudyImpl("some title"));
    ArgumentCaptor<Study> argument = ArgumentCaptor.forClass(Study.class);
    verify(factory).getOrCreateStudy(argument.capture());
    assertEquals("some title", argument.getValue().getTitle());
    String sourceCitation = CitationUtil.sourceCitationLastAccessed(dataset);
    assertThat(StringUtils.contains(sourceCitation, "<some:uri>. Accessed at <some:uri> on"), Is.is(true));
}
Also used : Study(org.eol.globi.domain.Study) Dataset(org.globalbioticinteractions.dataset.Dataset) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Test(org.junit.Test)

Example 9 with DatasetImpl

use of org.globalbioticinteractions.dataset.DatasetImpl 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 10 with DatasetImpl

use of org.globalbioticinteractions.dataset.DatasetImpl in project eol-globi-data by jhpoelen.

the class IndexInteractionsTest method indexInteractions.

@Test
public void indexInteractions() throws NodeFactoryException {
    TaxonIndex taxonIndex = getOrCreateTaxonIndex();
    // see https://github.com/globalbioticinteractions/globalbioticinteractions/wiki/Nanopubs
    StudyImpl study = new StudyImpl("some study", new DOI("123.23", "222"), "some study citation");
    NodeFactoryWithDatasetContext factory = new NodeFactoryWithDatasetContext(nodeFactory, new DatasetImpl("some/namespace", URI.create("https://some.uri"), inStream -> inStream));
    Study interaction = factory.getOrCreateStudy(study);
    TaxonImpl donaldTaxon = new TaxonImpl("donald duck", "NCBI:1234");
    Specimen donald = factory.createSpecimen(interaction, donaldTaxon);
    donald.classifyAs(taxonIndex.getOrCreateTaxon(donaldTaxon));
    TaxonImpl mickeyTaxon = new TaxonImpl("mickey mouse", "NCBI:4444");
    Taxon mickeyTaxonNCBI = taxonIndex.getOrCreateTaxon(new TaxonImpl("mickey mouse", "EOL:567"));
    NodeUtil.connectTaxa(mickeyTaxon, (TaxonNode) mickeyTaxonNCBI, getGraphDb(), RelTypes.SAME_AS);
    Specimen mickey = factory.createSpecimen(interaction, mickeyTaxon);
    mickey.classifyAs(taxonIndex.getOrCreateTaxon(mickeyTaxon));
    donald.ate(mickey);
    new IndexInteractions(new GraphServiceFactoryProxy(getGraphDb())).index();
    NodeFactoryNeo4j nodeFactoryNeo4j = new NodeFactoryNeo4j2(getGraphDb());
    StudyImpl study1 = new StudyImpl("some study", new DOI("123.23", "222"), "come citation");
    study1.setOriginatingDataset(new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream));
    StudyNode someStudy = nodeFactoryNeo4j.getOrCreateStudy(study1);
    assertThat(interaction.getOriginatingDataset().getNamespace(), is(someStudy.getOriginatingDataset().getNamespace()));
    assertThat(interaction.getTitle(), is(someStudy.getTitle()));
    RelationshipType hasParticipant = NodeUtil.asNeo4j(RelTypes.HAS_PARTICIPANT);
    Set<Long> ids = new HashSet<>();
    List<Long> idList = new ArrayList<>();
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(someStudy.getUnderlyingNode()), new RelationshipListener() {

        @Override
        public void on(Relationship specimen) {
            assertThat(specimen.getEndNode().hasRelationship(Direction.INCOMING, hasParticipant), Is.is(true));
            Iterable<Relationship> relationships = specimen.getEndNode().getRelationships(hasParticipant, Direction.INCOMING);
            for (Relationship relationship : relationships) {
                long id = relationship.getStartNode().getId();
                ids.add(id);
                idList.add(id);
            }
        }
    });
    assertThat(ids.size(), Is.is(1));
    assertThat(idList.size(), Is.is(2));
    Node interactionNode = getGraphDb().getNodeById(idList.get(0));
    assertTrue(interactionNode.hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.DERIVED_FROM)));
    assertTrue(interactionNode.hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.ACCESSED_AT)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TaxonIndex(org.eol.globi.data.TaxonIndex) NodeUtil(org.eol.globi.util.NodeUtil) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Specimen(org.eol.globi.domain.Specimen) Direction(org.neo4j.graphdb.Direction) RelTypes(org.eol.globi.domain.RelTypes) StudyImpl(org.eol.globi.domain.StudyImpl) Node(org.neo4j.graphdb.Node) Is(org.hamcrest.core.Is) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TaxonImpl(org.eol.globi.domain.TaxonImpl) RelationshipListener(org.eol.globi.util.RelationshipListener) DOI(org.globalbioticinteractions.doi.DOI) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GraphDBTestCase(org.eol.globi.data.GraphDBTestCase) Taxon(org.eol.globi.domain.Taxon) NodeFactoryNeo4j2(org.eol.globi.data.NodeFactoryNeo4j2) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StudyNode(org.eol.globi.domain.StudyNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) List(java.util.List) Relationship(org.neo4j.graphdb.Relationship) NodeFactoryException(org.eol.globi.data.NodeFactoryException) RelationshipType(org.neo4j.graphdb.RelationshipType) Study(org.eol.globi.domain.Study) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) TaxonNode(org.eol.globi.domain.TaxonNode) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) TaxonNode(org.eol.globi.domain.TaxonNode) StudyImpl(org.eol.globi.domain.StudyImpl) RelationshipType(org.neo4j.graphdb.RelationshipType) ArrayList(java.util.ArrayList) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) RelationshipListener(org.eol.globi.util.RelationshipListener) Specimen(org.eol.globi.domain.Specimen) TaxonIndex(org.eol.globi.data.TaxonIndex) DOI(org.globalbioticinteractions.doi.DOI) HashSet(java.util.HashSet) Study(org.eol.globi.domain.Study) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) StudyNode(org.eol.globi.domain.StudyNode) Relationship(org.neo4j.graphdb.Relationship) NodeFactoryNeo4j2(org.eol.globi.data.NodeFactoryNeo4j2) Test(org.junit.Test)

Aggregations

DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)83 Test (org.junit.Test)73 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)50 URI (java.net.URI)32 JsonNode (com.fasterxml.jackson.databind.JsonNode)31 Dataset (org.globalbioticinteractions.dataset.Dataset)25 ArrayList (java.util.ArrayList)22 IOException (java.io.IOException)21 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)21 InteractionListener (org.eol.globi.process.InteractionListener)19 URL (java.net.URL)18 Map (java.util.Map)17 StudyNode (org.eol.globi.domain.StudyNode)17 HashMap (java.util.HashMap)16 Is.is (org.hamcrest.core.Is.is)16 List (java.util.List)15 StudyImpl (org.eol.globi.domain.StudyImpl)15 StringUtils (org.apache.commons.lang3.StringUtils)14 CoreMatchers.nullValue (org.hamcrest.CoreMatchers.nullValue)14 Is (org.hamcrest.core.Is)14