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));
}
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());
}
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));
}
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);
}
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)));
}
Aggregations