use of org.eol.globi.domain.LocationImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForSimons method getOrCreateSampleLocation.
private Location getOrCreateSampleLocation(LabeledCSVParser csvParser, Map<String, String> columnToNormalizedTermMapper) throws StudyImporterException {
Double northing = parseAsDouble(csvParser, columnToNormalizedTermMapper.get(NORTHING));
Double easting = parseAsDouble(csvParser, columnToNormalizedTermMapper.get(EASTING));
Double latitude = null;
Double longitude = null;
if (easting != null && northing != null) {
UTMRef utmRef = new UTMRef(easting, northing, 'R', 16);
LatLng latLng = utmRef.toLatLng();
latitude = latLng.getLat();
longitude = latLng.getLng();
}
Double depth = parseAsDouble(csvParser, columnToNormalizedTermMapper.get(DEPTH));
Double altitude = depth == null ? null : -depth;
try {
return nodeFactory.getOrCreateLocation(new LocationImpl(latitude, longitude, altitude, null));
} catch (NodeFactoryException e) {
throw new StudyImporterException("failed to create location", e);
}
}
use of org.eol.globi.domain.LocationImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForGoMexSI2IT method assertThatSomeDataIsImported.
private static void assertThatSomeDataIsImported(NodeFactory nodeFactory, TaxonIndex taxonIndex) throws StudyImporterException, NodeFactoryException {
Study study = nodeFactory.findStudy("Divita et al 1983");
assertSpecimenProperties(((NodeBacked) study).getUnderlyingNode().getGraphDatabase());
assertNotNull(study);
assertThat(study.getTitle(), is("Divita et al 1983"));
assertThat(study.getExternalId(), is(ExternalIdUtil.urlForExternalId("GAME:2689")));
assertThat(study.getCitation(), is("Regina Divita, Mischelle Creel, Peter Sheridan. 1983. Foods of coastal fishes during brown shrimp Penaeus aztecus, migration from Texas estuaries (June - July 1981)."));
assertNotNull(nodeFactory.findStudy("Beaumariage 1973"));
assertNotNull(nodeFactory.findStudy("Baughman, 1943"));
assertNotNull(taxonIndex.findTaxonByName("Chloroscombrus chrysurus"));
assertNotNull(taxonIndex.findTaxonByName("Micropogonias undulatus"));
assertNotNull(taxonIndex.findTaxonByName("Amphipoda"));
assertNotNull(taxonIndex.findTaxonByName("Crustacea"));
Taxon taxon = taxonIndex.findTaxonByName("Scomberomorus cavalla");
List<String> preyList = new ArrayList<String>();
final List<String> titles = new ArrayList<String>();
Iterable<Relationship> classifiedAsRels = ((NodeBacked) taxon).getUnderlyingNode().getRelationships(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
int count = 0;
for (Relationship classifiedAsRel : classifiedAsRels) {
Node predatorSpecimen = classifiedAsRel.getStartNode();
Specimen predator = new SpecimenNode(predatorSpecimen);
Iterable<Relationship> stomachContents = NodeUtil.getStomachContents(predator);
for (Relationship prey : stomachContents) {
Relationship singleRelationship = prey.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING);
preyList.add((String) singleRelationship.getEndNode().getProperty("name"));
}
count++;
Relationship collectedBy = predatorSpecimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED), Direction.INCOMING);
assertThat(collectedBy, is(notNullValue()));
String title = (String) collectedBy.getStartNode().getProperty("title");
titles.add(title);
}
assertThat(count > 7, is(true));
assertThat(preyList, hasItem("Organic matter"));
assertThat(preyList, hasItem("Triglidae"));
assertThat(preyList, hasItem("Sparidae"));
assertThat(titles, hasItem("Beaumariage 1973"));
assertThat(titles, hasItem("Blanton et al 1972"));
assertNotNull(taxon);
final String footprintWKT = WKT_FOOTPRINT2;
LocationImpl expectedLocation = new LocationImpl(29.346953, -92.980614, -13.641, footprintWKT);
expectedLocation.setLocality("Louisiana inner continental shelf");
Location location = nodeFactory.findLocation(expectedLocation);
assertThat(location, is(notNullValue()));
assertThat(location.getFootprintWKT(), is(footprintWKT));
assertThat(location.getLocality(), is("Louisiana inner continental shelf"));
assertNotNull(location);
List<Environment> environments = location.getEnvironments();
assertThat(environments.size(), not(is(0)));
assertThat(environments.get(0).getExternalId(), is("http://cmecscatalog.org/classification/aquaticSetting/13"));
assertThat(environments.get(0).getName(), is("Marine Nearshore Subtidal"));
assertNotNull(nodeFactory.findStudy("GoMexSI"));
}
use of org.eol.globi.domain.LocationImpl 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;
}
use of org.eol.globi.domain.LocationImpl in project eol-globi-data by jhpoelen.
the class ExporterAssociationAggregatesTest method createTestData.
private void createTestData(Double length, String studyTitle) throws NodeFactoryException, ParseException {
Study myStudy = nodeFactory.getOrCreateStudy(new StudyImpl(studyTitle, "data source description", null, ExternalIdUtil.toCitation("contributor", "description", "pubYear")));
Specimen specimen = nodeFactory.createSpecimen(myStudy, setPathAndId(new TaxonImpl("Homo sapiens", null)));
specimen.setStomachVolumeInMilliLiter(666.0);
specimen.setLifeStage(new TermImpl("GlOBI:JUVENILE", "JUVENILE"));
specimen.setPhysiologicalState(new TermImpl("GlOBI:DIGESTATE", "DIGESTATE"));
specimen.setBodyPart(new TermImpl("GLOBI:BONE", "BONE"));
nodeFactory.setUnixEpochProperty(specimen, new Date(ExportTestUtil.utcTestTime()));
TaxonImpl taxon = new TaxonImpl("Canis lupus", null);
Specimen otherSpecimen = nodeFactory.createSpecimen(myStudy, setPathAndId(taxon));
otherSpecimen.setVolumeInMilliLiter(124.0);
specimen.ate(otherSpecimen);
specimen.ate(otherSpecimen);
if (null != length) {
specimen.setLengthInMm(length);
}
Location location = nodeFactory.getOrCreateLocation(new LocationImpl(44.0, 120.0, -60.0, null));
specimen.caughtIn(location);
}
use of org.eol.globi.domain.LocationImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForHurlbert method importInteraction.
protected void importInteraction(Set<String> regions, Set<String> locales, Set<String> habitats, Record record, Study study, String preyTaxonName, String predatorName) throws StudyImporterException {
try {
Taxon predatorTaxon = new TaxonImpl(predatorName);
Specimen predatorSpecimen = nodeFactory.createSpecimen(study, predatorTaxon);
setBasisOfRecordAsLiterature(predatorSpecimen);
Taxon preyTaxon = new TaxonImpl(preyTaxonName);
String preyNameId = StringUtils.trim(columnValueOrNull(record, "Prey_Name_ITIS_ID"));
if (NumberUtils.isDigits(preyNameId)) {
preyTaxon.setExternalId(TaxonomyProvider.ITIS.getIdPrefix() + preyNameId);
}
Specimen preySpecimen = nodeFactory.createSpecimen(study, preyTaxon);
setBasisOfRecordAsLiterature(preySpecimen);
String preyStage = StringUtils.trim(columnValueOrNull(record, "Prey_Stage"));
if (StringUtils.isNotBlank(preyStage)) {
Term lifeStage = nodeFactory.getOrCreateLifeStage("HULBERT:" + StringUtils.replace(preyStage, " ", "_"), preyStage);
preySpecimen.setLifeStage(lifeStage);
}
String preyPart = StringUtils.trim(columnValueOrNull(record, "Prey_Part"));
if (StringUtils.isNotBlank(preyPart)) {
Term term = nodeFactory.getOrCreateBodyPart("HULBERT:" + StringUtils.replace(preyPart, " ", "_"), preyPart);
preySpecimen.setBodyPart(term);
}
Date date = addCollectionDate(record, study);
nodeFactory.setUnixEpochProperty(predatorSpecimen, date);
nodeFactory.setUnixEpochProperty(preySpecimen, date);
LocationImpl location = new LocationImpl(null, null, null, null);
String longitude = columnValueOrNull(record, "Longitude_dd");
String latitude = columnValueOrNull(record, "Latitude_dd");
if (NumberUtils.isNumber(latitude) && NumberUtils.isNumber(longitude)) {
try {
LatLng latLng = LocationUtil.parseLatLng(latitude, longitude);
String altitude = columnValueOrNull(record, "Altitude_mean_m");
Double altitudeD = NumberUtils.isNumber(altitude) ? Double.parseDouble(altitude) : null;
location = new LocationImpl(latLng.getLat(), latLng.getLng(), altitudeD, null);
} catch (InvalidLocationException e) {
getLogger().warn(study, "found invalid (lat,lng) pair: (" + latitude + "," + longitude + ")");
}
}
String locationRegion = columnValueOrNull(record, "Location_Region");
String locationSpecific = columnValueOrNull(record, "Location_Specific");
location.setLocality(StringUtils.join(Arrays.asList(locationRegion, locationSpecific), ":"));
Location locationNode = nodeFactory.getOrCreateLocation(location);
String habitat_type = columnValueOrNull(record, "Habitat_type");
List<Term> habitatList = Arrays.stream(StringUtils.split(StringUtils.defaultIfBlank(habitat_type, ""), ";")).map(StringUtils::trim).map(habitat -> new TermImpl(idForHabitat(habitat), habitat)).collect(Collectors.toList());
nodeFactory.addEnvironmentToLocation(locationNode, habitatList);
preySpecimen.caughtIn(locationNode);
predatorSpecimen.caughtIn(locationNode);
predatorSpecimen.ate(preySpecimen);
} catch (NodeFactoryException e) {
throw new StudyImporterException("failed to create interaction between [" + predatorName + "] and [" + preyTaxonName + "]", e);
}
}
Aggregations