Search in sources :

Example 66 with DOI

use of org.globalbioticinteractions.doi.DOI in project eol-globi-data by jhpoelen.

the class DOIResolverImplTest method extractDOI.

@Test
public void extractDOI() throws IOException, MalformedDOIException {
    String response = IOUtils.toString(getClass().getResourceAsStream("crossRefReply.json"), StandardCharsets.UTF_8);
    DOI doi = new DOIResolverImpl().extractDOI(response);
    assertThat(doi.toString(), is("10.1002/(sici)1098-2345(1997)42:1<1::aid-ajp1>3.0.co;2-0"));
}
Also used : DOI(org.globalbioticinteractions.doi.DOI) Test(org.junit.Test)

Example 67 with DOI

use of org.globalbioticinteractions.doi.DOI in project eol-globi-data by jhpoelen.

the class DatasetImplTest method doiScrubbing.

@Test
public void doiScrubbing() throws IOException {
    Dataset dataset = new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream);
    dataset.setConfig(new ObjectMapper().readTree("{\"doi\": \"doi:http://dx.doi.org/10.2980/1195-6860(2006)13[23:TDOFUB]2.0.CO;2\" }"));
    assertThat(dataset.getDOI(), is(new DOI("2980", "1195-6860(2006)13[23:TDOFUB]2.0.CO;2")));
}
Also used : Dataset(org.globalbioticinteractions.dataset.Dataset) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DOI(org.globalbioticinteractions.doi.DOI) Test(org.junit.Test)

Example 68 with DOI

use of org.globalbioticinteractions.doi.DOI 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 69 with DOI

use of org.globalbioticinteractions.doi.DOI in project eol-globi-data by jhpoelen.

the class NodeFactoryNeo4j method createDatasetNode.

Node createDatasetNode(Dataset dataset) {
    Node datasetNode = createDatasetNode();
    datasetNode.setProperty(DatasetConstant.NAMESPACE, dataset.getNamespace());
    URI archiveURI = dataset.getArchiveURI();
    if (archiveURI != null) {
        String archiveURIString = archiveURI.toString();
        datasetNode.setProperty(DatasetConstant.ARCHIVE_URI, archiveURIString);
        createExternalIdRelationIfExists(datasetNode, archiveURIString, RelTypes.HAS_EXTERNAL_ID);
    }
    URI configURI = dataset.getConfigURI();
    if (configURI != null) {
        datasetNode.setProperty(DatasetConstant.CONFIG_URI, configURI.toString());
    }
    JsonNode config = dataset.getConfig();
    if (config != null) {
        try {
            datasetNode.setProperty(DatasetConstant.CONFIG, new ObjectMapper().writeValueAsString(config));
        } catch (IOException e) {
            LOG.warn("failed to serialize dataset config");
        }
    }
    datasetNode.setProperty(StudyConstant.FORMAT, dataset.getFormat());
    DOI doi = dataset.getDOI();
    if (doi != null) {
        String doiString = doi.toString();
        datasetNode.setProperty(StudyConstant.DOI, doiString);
        createExternalIdRelationIfExists(datasetNode, doiString, RelTypes.HAS_DOI);
    }
    datasetNode.setProperty(DatasetConstant.CITATION, StringUtils.defaultIfBlank(dataset.getCitation(), "no citation"));
    datasetNode.setProperty(DatasetConstant.SHOULD_RESOLVE_REFERENCES, dataset.getOrDefault(DatasetConstant.SHOULD_RESOLVE_REFERENCES, "true"));
    datasetNode.setProperty(DatasetConstant.LAST_SEEN_AT, dataset.getOrDefault(DatasetConstant.LAST_SEEN_AT, Long.toString(System.currentTimeMillis())));
    indexDatasetNode(dataset, datasetNode);
    return datasetNode;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) LocationNode(org.eol.globi.domain.LocationNode) EnvironmentNode(org.eol.globi.domain.EnvironmentNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) Node(org.neo4j.graphdb.Node) SeasonNode(org.eol.globi.domain.SeasonNode) DatasetNode(org.eol.globi.domain.DatasetNode) StudyNode(org.eol.globi.domain.StudyNode) InteractionNode(org.eol.globi.domain.InteractionNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) URI(java.net.URI) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DOI(org.globalbioticinteractions.doi.DOI)

Example 70 with DOI

use of org.globalbioticinteractions.doi.DOI in project eol-globi-data by jhpoelen.

the class DatasetImporterForStrona method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    LabeledCSVParser dataParser;
    try {
        dataParser = getParserFactory().createParser(RESOURCE_PATH, CharsetConstant.UTF8);
    } catch (IOException e) {
        throw new StudyImporterException("failed to read resource [" + RESOURCE_PATH + "]", e);
    }
    try {
        Study study = getNodeFactory().getOrCreateStudy(new StudyImpl("strona2013", new DOI("1890", "12-1419.1"), SOURCE));
        while (dataParser.getLine() != null) {
            if (importFilter.shouldImportRecord((long) dataParser.getLastLineNumber())) {
                try {
                    String parasiteName = StringUtils.trim(dataParser.getValueByLabel("P_SP"));
                    String hostName = StringUtils.trim(dataParser.getValueByLabel("H_SP"));
                    if (areNamesAvailable(parasiteName, hostName)) {
                        Specimen parasite = getNodeFactory().createSpecimen(study, new TaxonImpl(parasiteName, null));
                        Specimen host = getNodeFactory().createSpecimen(study, new TaxonImpl(hostName, null));
                        parasite.interactsWith(host, InteractType.PARASITE_OF);
                    }
                } catch (NodeFactoryException | NumberFormatException e) {
                    throw new StudyImporterException("failed to import line [" + (dataParser.lastLineNumber() + 1) + "]", e);
                }
            }
        }
    } catch (IOException | NodeFactoryException e) {
        throw new StudyImporterException("problem importing [" + RESOURCE_PATH + "]", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException) Specimen(org.eol.globi.domain.Specimen) DOI(org.globalbioticinteractions.doi.DOI)

Aggregations

DOI (org.globalbioticinteractions.doi.DOI)74 Test (org.junit.Test)50 StudyImpl (org.eol.globi.domain.StudyImpl)28 IOException (java.io.IOException)15 Study (org.eol.globi.domain.Study)15 Specimen (org.eol.globi.domain.Specimen)13 StudyNode (org.eol.globi.domain.StudyNode)12 Matchers.containsString (org.hamcrest.Matchers.containsString)12 TaxonImpl (org.eol.globi.domain.TaxonImpl)11 URI (java.net.URI)10 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)8 MalformedDOIException (org.globalbioticinteractions.doi.MalformedDOIException)8 Location (org.eol.globi.domain.Location)7 LocationImpl (org.eol.globi.domain.LocationImpl)7 ArrayList (java.util.ArrayList)6 Dataset (org.globalbioticinteractions.dataset.Dataset)6 Reader (java.io.Reader)5 StringReader (java.io.StringReader)5