Search in sources :

Example 76 with DatasetImpl

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

the class DatasetImporterForZOVERTest method importDataset.

@Test
public void importDataset() throws StudyImporterException {
    List<Map<String, String>> interactions = new ArrayList<>();
    DatasetImporterForZOVER importer = new DatasetImporterForZOVER(null, null);
    importer.setDatabases(Collections.singletonList(DatasetImporterForZOVER.ZOVER_CHIROPTERA));
    importer.setInteractionListener(new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            interactions.add(interaction);
        }
    });
    DatasetImpl dataset = new DatasetImpl("some/namespace", new ResourceService() {

        @Override
        public InputStream retrieve(URI resourceName) throws IOException {
            InputStream is = null;
            if (StringUtils.equals("http://www.mgc.ac.cn/cgi-bin/ZOVER/lineage2json1.pl?type=viruses&host=chiroptera", resourceName.toString())) {
                is = getClass().getResourceAsStream("zover/chiroptera_chopped.json");
            } else if (StringUtils.equals("http://www.mgc.ac.cn/ZOVER/json/chiroptera_viruses_363628.json", resourceName.toString())) {
                is = getClass().getResourceAsStream("zover/chiroptera_viruses_363628.json");
            }
            return is;
        }
    }, URI.create("some:uri")) {
    };
    importer.setDataset(dataset);
    importer.importStudy();
    assertThat(interactions.size(), is(1));
    Map<String, String> interaction = interactions.get(0);
    assertThat(interaction.get(SOURCE_TAXON_NAME), is("Torque teno Tadarida brasiliensis virus"));
    assertThat(interaction.get(SOURCE_TAXON_ID), is("NCBI:1543419"));
    assertThat(interaction.get(TARGET_TAXON_NAME), is("Tadarida brasiliensis"));
    assertThat(interaction.get(TARGET_TAXON_ID), is("NCBI:9438"));
    assertThat(interaction.get(INTERACTION_TYPE_NAME), is("pathogenOf"));
    assertThat(interaction.get(INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002556"));
    assertThat(interaction.get(REFERENCE_CITATION), is(nullValue()));
    assertThat(interaction.get(REFERENCE_URL), is("https://www.ncbi.nlm.nih.gov/nuccore/KM434181"));
    assertThat(interaction.get(REFERENCE_DOI), is(nullValue()));
    assertThat(interaction.get(REFERENCE_ID), is("urn:lsid:cn.ac.mgc:tick:363628"));
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ResourceService(org.eol.globi.service.ResourceService) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) IOException(java.io.IOException) URI(java.net.URI) InteractionListener(org.eol.globi.process.InteractionListener) Map(java.util.Map) Test(org.junit.Test)

Example 77 with DatasetImpl

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

the class NodeFactoryWithDatasetContextTest method createStudy.

@Test
public void createStudy() {
    NodeFactory factory = Mockito.mock(NodeFactory.class);
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream);
    NodeFactoryWithDatasetContext factoryWithDS = new NodeFactoryWithDatasetContext(factory, dataset);
    StudyImpl study = new StudyImpl("some title", new DOI("123", "abc"), "some citation");
    study.setExternalId("some:id");
    factoryWithDS.createStudy(study);
    ArgumentCaptor<Study> argument = ArgumentCaptor.forClass(Study.class);
    verify(factory).createStudy(argument.capture());
    assertEquals("some title", argument.getValue().getTitle());
    assertEquals("some citation", argument.getValue().getCitation());
    assertEquals("10.123/abc", argument.getValue().getDOI().toString());
    assertEquals("some:id", argument.getValue().getExternalId());
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) DOI(org.globalbioticinteractions.doi.DOI) Test(org.junit.Test)

Example 78 with DatasetImpl

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

the class DatasetImplTest method useCitationFromMultipleTableDefinitions.

@Test
public void useCitationFromMultipleTableDefinitions() throws IOException {
    Dataset dataset = new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream);
    dataset.setConfig(new ObjectMapper().readTree(getClass().getResourceAsStream("/org/eol/globi/data/test-meta-globi-default-external-schemas.json")));
    assertThat(dataset.getCitation(), is("Seltzer, Carrie; Wysocki, William; Palacios, Melissa; Eickhoff, Anna; Pilla, Hannah; Aungst, Jordan; Mercer, Aaron; Quicho, Jamie; Voss, Neil; Xu, Man; J. Ndangalasi, Henry; C. Lovett, Jon; J. Cordeiro, Norbert (2015): Plant-animal interactions from Africa. figshare. https://dx.doi.org/10.6084/m9.figshare.1526128"));
}
Also used : Dataset(org.globalbioticinteractions.dataset.Dataset) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 79 with DatasetImpl

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

the class DatasetProxyTest method getMappedResource.

@Test
public void getMappedResource() throws IOException, URISyntaxException {
    URL original = getClass().getResource("/org/globalbioticinteractions/content/original.txt");
    URL proxied = getClass().getResource("/org/globalbioticinteractions/content/proxied.txt");
    JsonNode configProxy = new ObjectMapper().readTree("{ \"resources\": { \"archive\": \"" + proxied.toURI() + "\" } }");
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com"), inStream -> inStream);
    dataset.setConfig(null);
    final String hashOfOriginal = "0682c5f2076f099c34cfdd15a9e063849ed437a49677e6fcc5b4198c76575be5";
    final String hashOfProxied = "b09f17ea1b5ca77b7a01a3ed62c84b38578817eddb34f827666c898a27504f67";
    DatasetProxy datasetProxy = new DatasetProxy(dataset);
    datasetProxy.setConfig(configProxy);
    DatasetProxy testDataset = datasetProxy;
    TestHashUtil.assertContentHash(testDataset.retrieve(URI.create("archive")), hashOfProxied);
    JsonNode config = new ObjectMapper().readTree("{ \"resources\": { \"archive\": \"" + original.toURI() + "\" } }");
    testDataset = getTestDataset(config, configProxy);
    TestHashUtil.assertContentHash(testDataset.retrieve(URI.create("archive")), hashOfProxied);
    testDataset = getTestDataset(config, null);
    TestHashUtil.assertContentHash(testDataset.retrieve(URI.create("archive")), hashOfOriginal);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DatasetProxy(org.globalbioticinteractions.dataset.DatasetProxy) Test(org.junit.Test)

Example 80 with DatasetImpl

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

the class DatasetImportUtilTest method listDependencies.

@Test
public void listDependencies() throws StudyImporterException, IOException {
    String jsonConfig = "{" + "  \"format\": \"dwca\", " + "  \"citation\": \"The MSB Division of Parasitology Collection\"," + "  \"url\": \"http://ipt.vertnet.org:8080/ipt/archive.do?r=msb_para\"," + "  \"references\": [" + "    {" + "      \"format\": \"dwca\"," + "      \"url\": \"http://ipt.vertnet.org:8080/ipt/archive.do?r=msb_host\"," + "      \"citation\": \"The MSB Division of Host Collection\"" + "    }, {" + "      \"format\": \"dwca\"," + "      \"url\": \"http://ipt.vertnet.org:8080/ipt/archive.do?r=msb_host2\"," + "      \"citation\": \"The MSB Division of Host Collection2\"" + "    }]" + "}";
    final DatasetImpl datasetOrig = new DatasetImpl("name/space", URI.create("some:uri"), in -> in);
    JsonNode objectNode = new ObjectMapper().readTree(jsonConfig);
    datasetOrig.setConfig(objectNode);
    final List<Dataset> references = getReferences(datasetOrig);
    assertThat(references.size(), Is.is(2));
}
Also used : Dataset(org.globalbioticinteractions.dataset.Dataset) JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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