use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForSPIRE method importValidLink.
private void importValidLink(Map<String, String> properties) throws NodeFactoryException {
Study study = nodeFactory.getOrCreateStudy(new StudyImpl(properties.get(StudyConstant.TITLE), SOURCE_SPIRE, null, properties.get(StudyConstant.DESCRIPTION)));
try {
Specimen predator = createSpecimen(properties.get(PREDATOR_NAME), study);
String locality = properties.get(LOCALITY_ORIGINAL);
LatLng latLng = getGeoNamesService().findLatLng(locality);
if (latLng == null) {
getLogger().warn(study, "failed to find location for county [" + locality + "]");
} else {
Location location = nodeFactory.getOrCreateLocation(new LocationImpl(latLng.getLat(), latLng.getLng(), null, null));
predator.caughtIn(location);
String habitat = properties.get(OF_HABITAT);
if (StringUtils.isNotBlank(habitat)) {
addEnvironment(location, "SPIRE:" + habitat, habitat);
}
}
Specimen prey = createSpecimen(properties.get(PREY_NAME), study);
predator.ate(prey);
} catch (NodeFactoryException e) {
getLogger().warn(study, "failed to import trophic link with properties [" + properties + "]: " + e.getMessage());
} catch (IOException e) {
getLogger().warn(study, "failed to import trophic link with properties [" + properties + "]: " + e.getMessage());
}
}
use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForWrast method importStudy.
@Override
public void importStudy() throws StudyImporterException {
String citation = "Wrast JL. Spatiotemporal And Habitat-mediated Food Web Dynamics in Lavaca Bay, Texas. 2008. Master Thesis.";
StudyImpl study1 = new StudyImpl("Wrast 2008", StudyImporterForGoMexSI2.GOMEXI_SOURCE_DESCRIPTION, null, citation);
study1.setExternalId("http://www.fisheries.tamucc.edu/people_files/FINAL%20WRAST%20THESIS.pdf");
Study study = nodeFactory.getOrCreateStudy(study1);
try {
LabeledCSVParser csvParser = parserFactory.createParser(LAVACA_BAY_DATA_SOURCE, CharsetConstant.UTF8);
LengthParser parser = new LengthParserImpl(COLUMN_MAPPER.get(LENGTH_IN_MM));
getPredatorSpecimenMap().clear();
while (csvParser.getLine() != null) {
addNextRecordToStudy(csvParser, study, COLUMN_MAPPER, parser);
}
} catch (IOException e) {
throw new StudyImporterException("failed to create study [" + LAVACA_BAY_DATA_SOURCE + "]", e);
} finally {
getPredatorSpecimenMap().clear();
}
}
use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.
the class ExportTaxonCacheTest method exportOnePredatorTwoPrey.
@Test
public void exportOnePredatorTwoPrey() throws NodeFactoryException, IOException {
taxonIndex = ExportTestUtil.taxonIndexWithEnricher(null, getGraphDb());
Study study = nodeFactory.getOrCreateStudy(new StudyImpl("title", "source", null, "citation"));
Taxon taxon = new TaxonImpl("Homo sapiens");
taxon.setExternalId("homoSapiensId");
taxon.setPath("one\ttwo three");
taxon.setExternalUrl("http://some/thing");
taxon.setThumbnailUrl("http://thing/some");
Taxon human = taxonIndex.getOrCreateTaxon(taxon);
TaxonImpl taxon1 = new TaxonImpl("Canis lupus", "canisLupusId");
taxon1.setPath("four five six");
taxonIndex.getOrCreateTaxon(taxon1);
NodeUtil.connectTaxa(new TaxonImpl("Alternate Homo sapiens no path", "alt:123"), (TaxonNode) human, getGraphDb(), RelTypes.SAME_AS);
final TaxonImpl altTaxonWithPath = new TaxonImpl("Alternate Homo sapiens", "alt:123");
altTaxonWithPath.setPath("some path here");
NodeUtil.connectTaxa(altTaxonWithPath, (TaxonNode) human, getGraphDb(), RelTypes.SAME_AS);
NodeUtil.connectTaxa(new TaxonImpl("Similar Homo sapiens", "alt:456"), (TaxonNode) human, getGraphDb(), RelTypes.SIMILAR_TO);
StringWriter writer = new StringWriter();
new ExportTaxonCache().exportStudy(study, writer, true);
assertThat(writer.toString(), is("id\tname\trank\tcommonNames\tpath\tpathIds\tpathNames\texternalUrl\tthumbnailUrl" + "\nhomoSapiensId\tHomo sapiens\t\t\tone two three\t\t\thttp://some/thing\thttp://thing/some" + "\nalt:123\tAlternate Homo sapiens\t\t\tsome path here\t\t\thttp://some/thing\thttp://thing/some" + "\ncanisLupusId\tCanis lupus\t\t\tfour five six\t\t\t\t"));
}
use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.
the class ExportTaxonMapTest method exportOnePredatorTwoPrey.
@Test
public void exportOnePredatorTwoPrey() throws NodeFactoryException, IOException {
final PropertyEnricher taxonEnricher = new PropertyEnricher() {
@Override
public Map<String, String> enrich(Map<String, String> properties) {
Taxon taxon = new TaxonImpl();
TaxonUtil.mapToTaxon(properties, taxon);
if ("Homo sapiens".equals(taxon.getName())) {
taxon.setExternalId("homoSapiensId");
taxon.setPath("one two three");
} else if ("Canis lupus".equals(taxon.getName())) {
taxon.setExternalId("canisLupusId");
taxon.setPath("four\tfive six");
}
return TaxonUtil.taxonToMap(taxon);
}
@Override
public void shutdown() {
}
};
taxonIndex = ExportTestUtil.taxonIndexWithEnricher(taxonEnricher, getGraphDb());
Study study = nodeFactory.getOrCreateStudy(new StudyImpl("title", "source", null, "citation"));
Taxon taxon = new TaxonImpl("Homo sapiens");
taxon.setExternalId("homoSapiensId");
taxon.setPath("one two three");
taxon.setExternalUrl("http://some/thing");
taxon.setThumbnailUrl("http://thing/some");
nodeFactory.createSpecimen(study, taxon);
Taxon human = taxonIndex.getOrCreateTaxon(taxon);
TaxonImpl dog = new TaxonImpl("Canis lupus");
dog.setExternalId("canisLupusId");
dog.setPath("four\tfive six");
nodeFactory.createSpecimen(study, dog);
final TaxonImpl altTaxonWithPath = new TaxonImpl("Alternate Homo sapiens", "alt:123");
altTaxonWithPath.setPath("some path here");
NodeUtil.connectTaxa(altTaxonWithPath, (TaxonNode) human, getGraphDb(), RelTypes.SAME_AS);
NodeUtil.connectTaxa(new TaxonImpl("Alternate Homo sapiens no path", "alt:123"), (TaxonNode) human, getGraphDb(), RelTypes.SAME_AS);
NodeUtil.connectTaxa(new TaxonImpl("Similar Homo sapiens", "alt:456"), (TaxonNode) human, getGraphDb(), RelTypes.SIMILAR_TO);
resolveNames();
StringWriter writer = new StringWriter();
new ExportTaxonMap().exportStudy(study, writer, true);
assertThat(writer.toString(), is("providedTaxonId\tprovidedTaxonName\tresolvedTaxonId\tresolvedTaxonName" + "\nhomoSapiensId\tHomo sapiens\thomoSapiensId\tHomo sapiens" + "\nhomoSapiensId\tHomo sapiens\talt:123\tAlternate Homo sapiens" + "\ncanisLupusId\tCanis lupus\tcanisLupusId\tCanis lupus"));
}
use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.
the class ExportTestUtil method createTestData.
public static Study createTestData(Double length, NodeFactory factory) throws NodeFactoryException, ParseException {
Study myStudy = factory.createStudy(new StudyImpl("myStudy", null, null, null));
Specimen specimen1 = factory.createSpecimen(myStudy, new TaxonImpl("Homo sapiens", "EOL:45634"));
specimen1.setStomachVolumeInMilliLiter(666.0);
specimen1.setLifeStage(new TermImpl("GLOBI:JUVENILE", "JUVENILE"));
specimen1.setPhysiologicalState(new TermImpl("GLOBI:DIGESTATE", "DIGESTATE"));
specimen1.setBodyPart(new TermImpl("GLOBI:BONE", "BONE"));
factory.setUnixEpochProperty(specimen1, ExportTestUtil.utcTestDate());
final Specimen specimen2 = factory.createSpecimen(myStudy, new TaxonImpl("Canis lupus", "EOL:123"));
specimen2.setVolumeInMilliLiter(124.0);
specimen1.ate(specimen2);
final Specimen specimen3 = factory.createSpecimen(myStudy, new TaxonImpl("Canis lupus", "EOL:123"));
specimen3.setVolumeInMilliLiter(18.0);
specimen1.ate(specimen3);
if (null != length) {
specimen1.setLengthInMm(length);
}
Location location = factory.getOrCreateLocation(new LocationImpl(88.0, -120.0, -60.0, null));
specimen1.caughtIn(location);
return myStudy;
}
Aggregations