Search in sources :

Example 31 with StudyImpl

use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForByrnes method importLine.

private void importLine(LabeledCSVParser parser, Map<String, String> refMap) throws StudyImporterException {
    Study localStudy = null;
    try {
        String refList = StringUtils.trim(parser.getValueByLabel("Reference"));
        String[] refs;
        if (StringUtils.isBlank(refList)) {
            refs = new String[] { "Byrnes, J.E. et al., 2011. Climate-driven increases in storm frequency simplify kelp forest food webs. Global Change Biology, 17(8), pp.2513–2524. Available at: http://dx.doi.org/10.1111/j.1365-2486.2011.02409.x." };
        } else {
            refs = StringUtils.split(refList, ",");
        }
        for (String ref : refs) {
            String singleShortRef = StringUtils.trim(ref);
            String longRef = refMap.get(singleShortRef);
            String citation = StringUtils.isBlank(longRef) ? singleShortRef : longRef;
            localStudy = nodeFactory.getOrCreateStudy(new StudyImpl("BYRNES-" + StringUtils.abbreviate(citation, 32), SOURCE, null, citation));
            String predatorName = parser.getValueByLabel("Predator");
            if (StringUtils.isBlank(predatorName)) {
                getLogger().warn(localStudy, "found empty predator name on line [" + parser.lastLineNumber() + "]");
            } else {
                addInteractionForPredator(parser, localStudy, predatorName);
            }
        }
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("problem creating nodes at line [" + parser.lastLineNumber() + "]", e);
    } catch (NumberFormatException e) {
        String message = "skipping record, found malformed field at line [" + parser.lastLineNumber() + "]: ";
        if (localStudy != null) {
            getLogger().warn(localStudy, message + e.getMessage());
        }
    }
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl)

Example 32 with StudyImpl

use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForBarnes method importLine.

private void importLine(LabeledCSVParser parser, Map<String, String> refMap) throws StudyImporterException {
    Study localStudy = null;
    try {
        String shortReference = StringUtils.trim(parser.getValueByLabel("Reference"));
        if (!refMap.containsKey(shortReference)) {
            throw new StudyImporterException("failed to find ref [" + shortReference + "] on line [" + parser.lastLineNumber() + "]");
        }
        String longReference = refMap.get(shortReference);
        localStudy = nodeFactory.getOrCreateStudy(new StudyImpl("BARNES-" + shortReference, SOURCE, null, ExternalIdUtil.toCitation(null, longReference, null)));
        String predatorName = parser.getValueByLabel("Predator");
        if (StringUtils.isBlank(predatorName)) {
            getLogger().warn(localStudy, "found empty predator name on line [" + parser.lastLineNumber() + "]");
        } else {
            addInteractionForPredator(parser, localStudy, predatorName);
        }
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("problem creating nodes at line [" + parser.lastLineNumber() + "]", e);
    } catch (NumberFormatException e) {
        String message = "skipping record, found malformed field at line [" + parser.lastLineNumber() + "]: ";
        if (localStudy != null) {
            getLogger().warn(localStudy, message + e.getMessage());
        }
    }
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl)

Example 33 with StudyImpl

use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForBioInfo method createStudy.

protected Study createStudy(String refId, String citation) throws NodeFactoryException {
    String sourceCitation = "Food Webs and Species Interactions in the Biodiversity of UK and Ireland (Online). 2015. Data provided by Malcolm Storey. Also available from " + BIOINFO_URL + ".";
    String bioInfoId = TaxonomyProvider.BIO_INFO + "ref:" + refId;
    StudyImpl study1 = new StudyImpl(bioInfoId, sourceCitation, null, citation);
    study1.setExternalId(ExternalIdUtil.urlForExternalId(bioInfoId));
    return nodeFactory.getOrCreateStudy(study1);
}
Also used : StudyImpl(org.eol.globi.domain.StudyImpl)

Example 34 with StudyImpl

use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForBlewett method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    String citation = "Blewett DA, Hensley RA, and Stevens PW, Feeding Habits of Common Snook, Centropomus Undecimalis, in Charlotte Harbor, Florida, Gulf and Caribbean Research Vol 18, 1–13, 2006. doi:10.18785/gcr.1801.01 ";
    Study study = nodeFactory.getOrCreateStudy(new StudyImpl("Blewett 2006", StudyImporterForGoMexSI2.GOMEXI_SOURCE_DESCRIPTION, null, citation));
    try {
        Map<String, Location> collectionLocationMap = new HashMap<>();
        Map<String, Date> collectionTimeMap = new HashMap<String, Date>();
        buildLocationTimeMaps(collectionLocationMap, collectionTimeMap, study);
        parsePredatorPreyInteraction(study, collectionLocationMap, collectionTimeMap);
    } catch (IOException e) {
        throw new StudyImporterException("failed to read resource", e);
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to create taxon", e);
    } catch (TermLookupServiceException e) {
        throw new StudyImporterException("failed to map terms", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) TermLookupServiceException(org.eol.globi.service.TermLookupServiceException) HashMap(java.util.HashMap) StudyImpl(org.eol.globi.domain.StudyImpl) IOException(java.io.IOException) Date(java.util.Date) Location(org.eol.globi.domain.Location)

Example 35 with StudyImpl

use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.

the class NodeFactoryIT method createLogMessage.

@Test
public void createLogMessage() throws NodeFactoryException {
    Study bla = nodeFactory.createStudy(new StudyImpl("bla", null, null, null));
    bla.appendLogMessage("one two three", Level.INFO);
    List<LogMessage> logMessages = bla.getLogMessages();
    assertThat(logMessages.size(), is(1));
    assertThat(logMessages.get(0).getMessage(), is("one two three"));
    assertThat(logMessages.get(0).getLevel(), is("INFO"));
}
Also used : Study(org.eol.globi.domain.Study) LogMessage(org.eol.globi.domain.LogMessage) StudyImpl(org.eol.globi.domain.StudyImpl) Test(org.junit.Test)

Aggregations

StudyImpl (org.eol.globi.domain.StudyImpl)82 Study (org.eol.globi.domain.Study)60 Test (org.junit.Test)40 Specimen (org.eol.globi.domain.Specimen)33 TaxonImpl (org.eol.globi.domain.TaxonImpl)33 IOException (java.io.IOException)20 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)17 Location (org.eol.globi.domain.Location)15 StringWriter (java.io.StringWriter)12 LocationImpl (org.eol.globi.domain.LocationImpl)12 Date (java.util.Date)9 HashMap (java.util.HashMap)9 Taxon (org.eol.globi.domain.Taxon)9 StudyNode (org.eol.globi.domain.StudyNode)7 Node (org.neo4j.graphdb.Node)7 File (java.io.File)6 TermImpl (org.eol.globi.domain.TermImpl)6 DatasetImpl (org.eol.globi.service.DatasetImpl)6 InteractType (org.eol.globi.domain.InteractType)5 NonResolvingTaxonIndex (org.eol.globi.taxon.NonResolvingTaxonIndex)5