use of org.eol.globi.domain.LocationImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForBaremore method importStudy.
@Override
public void importStudy() throws StudyImporterException {
Study study;
try {
LabeledCSVParser parser = parserFactory.createParser(DATA_SOURCE, CharsetConstant.UTF8);
String[] line;
study = nodeFactory.getOrCreateStudy(new StudyImpl("Baremore 2010", StudyImporterForGoMexSI2.GOMEXI_SOURCE_DESCRIPTION, "doi:10.3354/ab00214", ExternalIdUtil.toCitation("Ivy E. Baremore", "Prey Selection By The Atlantic Angel Shark Squatina Dumeril In The Northeastern Gulf Of Mexico.", "2010")));
Location collectionLocation = nodeFactory.getOrCreateLocation(new LocationImpl(29.219302, -87.06665, null, null));
Map<Integer, Specimen> specimenMap = new HashMap<Integer, Specimen>();
while ((line = parser.getLine()) != null) {
Integer sharkId = Integer.parseInt(line[0]);
String collectionDateString = line[1];
if (isBlank(collectionDateString)) {
getLogger().warn(study, "line [" + parser.getLastLineNumber() + "] in [" + DATA_SOURCE + "]: missing collection date");
} else {
Specimen predatorSpecimen = specimenMap.get(sharkId);
if (predatorSpecimen == null) {
predatorSpecimen = nodeFactory.createSpecimen(study, new TaxonImpl("Squatina dumeril", null));
predatorSpecimen.caughtIn(collectionLocation);
addLifeStage(parser, predatorSpecimen);
addCollectionDate(collectionDateString, predatorSpecimen);
}
specimenMap.put(sharkId, predatorSpecimen);
String totalLengthInCm = line[3];
try {
Double lengthInMm = Double.parseDouble(totalLengthInCm) * 10.0;
predatorSpecimen.setLengthInMm(lengthInMm);
} catch (NumberFormatException ex) {
throw new StudyImporterException("failed to parse length [" + totalLengthInCm);
}
String preySpeciesDescription = line[7];
if (StringUtils.isBlank(preySpeciesDescription)) {
getLogger().info(study, "found blank prey species description [" + preySpeciesDescription + "] on line [" + parser.lastLineNumber() + "]");
} else {
Specimen preySpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(preySpeciesDescription, null));
preySpecimen.caughtIn(collectionLocation);
predatorSpecimen.ate(preySpecimen);
nodeFactory.setUnixEpochProperty(preySpecimen, nodeFactory.getUnixEpochProperty(predatorSpecimen));
}
}
}
} catch (IOException e) {
throw new StudyImporterException("failed to parse labels", e);
}
}
use of org.eol.globi.domain.LocationImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForAkin method parseLocation.
private Location parseLocation(String[] siteInfo) throws StudyImporterException, IOException, NodeFactoryException {
Double longitude;
Double latitude;
// TODO note that this study was taken in shallow water ~ 0.7m, probably better to include a depth range?
Double altitude = -0.7d;
String latitudeString = siteInfo[7];
try {
latitude = Double.parseDouble(latitudeString);
} catch (NumberFormatException ex) {
throw new StudyImporterException("failed to parse latitude [" + latitudeString + "]");
}
String longitudeString = siteInfo[8];
try {
longitude = Double.parseDouble(longitudeString);
} catch (NumberFormatException ex) {
throw new StudyImporterException("failed to parse longitude [" + longitudeString + "]");
}
return nodeFactory.getOrCreateLocation(new LocationImpl(latitude, longitude, altitude, null));
}
use of org.eol.globi.domain.LocationImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForBlewett method buildLocationTimeMaps.
private void buildLocationTimeMaps(Map<String, Location> collectionLocationMap, Map<String, Date> collectionTimeMap, Study study) throws IOException, StudyImporterException {
LabeledCSVParser locationParser = parserFactory.createParser("blewett/SnookDietData2000_02_Charlotte_Harbor_FL_Blewett_date_and_abiotic.csv", CharsetConstant.UTF8);
String[] line;
while ((line = locationParser.getLine()) != null) {
if (line.length < 3) {
getLogger().warn(study, "line:" + locationParser.getLastLineNumber() + " [" + StringUtils.join(line, ",") + "] has missing location information");
}
String collectionCode = locationParser.getValueByLabel(COLLECTION_NO);
if (StringUtils.isBlank(collectionCode)) {
getLogger().warn(study, "blank location code for line: [" + locationParser.getLastLineNumber() + "]");
}
String latitude = locationParser.getValueByLabel("Latitude");
if (StringUtils.isBlank(latitude)) {
getLogger().warn(study, "blank value for lattitude for line: [" + locationParser.getLastLineNumber() + "]");
}
String longitude = locationParser.getValueByLabel("Longitude");
if (StringUtils.isBlank(longitude)) {
getLogger().warn(study, "blank value for longitude for line: [" + locationParser.getLastLineNumber() + "]");
}
Location location;
try {
location = nodeFactory.getOrCreateLocation(new LocationImpl(Double.parseDouble(latitude), Double.parseDouble(longitude), 0.0, null));
} catch (NodeFactoryException e) {
throw new StudyImporterException("failed to create location", e);
}
collectionLocationMap.put(collectionCode, location);
String timeString = locationParser.getValueByLabel("Time");
if (StringUtils.isBlank(timeString)) {
getLogger().warn(study, "blank value for time for line: [" + locationParser.getLastLineNumber() + "]");
}
String dateString = locationParser.getValueByLabel("Date");
if (StringUtils.isBlank(dateString)) {
getLogger().warn(study, "blank value for date for line: [" + locationParser.getLastLineNumber() + "]");
}
String dateTimeString = dateString + " " + timeString;
try {
Date dateTime = parseDateString(dateTimeString);
collectionTimeMap.put(collectionCode, dateTime);
} catch (ParseException e) {
throw new StudyImporterException("failed to parse date time [" + dateTimeString + "] for collection [" + collectionCode + "] on line [" + locationParser.getLastLineNumber() + "]");
}
}
}
use of org.eol.globi.domain.LocationImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForBarnes method addInteractionForPredator.
private void addInteractionForPredator(LabeledCSVParser parser, Study localStudy, String predatorName) throws NodeFactoryException, StudyImporterException {
Specimen predator = nodeFactory.createSpecimen(localStudy, new TaxonImpl(predatorName, null));
addLifeStage(parser, predator);
Double latitude = LocationUtil.parseDegrees(parser.getValueByLabel("Latitude"));
Double longitude = LocationUtil.parseDegrees(parser.getValueByLabel("Longitude"));
String depth = parser.getValueByLabel("Depth");
Double altitudeInMeters = -1.0 * Double.parseDouble(depth);
Location location = nodeFactory.getOrCreateLocation(new LocationImpl(latitude, longitude, altitudeInMeters, null));
predator.caughtIn(location);
String preyName = parser.getValueByLabel("Prey");
if (StringUtils.isBlank(preyName)) {
getLogger().warn(localStudy, "found empty prey name on line [" + parser.lastLineNumber() + "]");
} else {
Specimen prey = nodeFactory.createSpecimen(localStudy, new TaxonImpl(preyName, null));
prey.caughtIn(location);
predator.ate(prey);
}
}
use of org.eol.globi.domain.LocationImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForSeltmann method createInteraction.
protected void createInteraction(LabeledCSVParser occurrence, Study study, Map<String, String> assoc, String targetName, String sourceName, Date date, InteractType interactType) throws StudyImporterException {
Specimen source = nodeFactory.createSpecimen(study, new TaxonImpl(sourceName, null));
Specimen target = nodeFactory.createSpecimen(study, new TaxonImpl(targetName, null));
source.interactsWith(target, interactType);
String sourceBasisOfRecord = occurrence.getValueByLabel("basisOfRecord");
source.setBasisOfRecord(nodeFactory.getOrCreateBasisOfRecord(sourceBasisOfRecord, sourceBasisOfRecord));
final String recordId = occurrence.getValueByLabel(FIELD_IDIGBIO_RECORD_ID);
source.setProperty(FIELD_IDIGBIO_RECORD_ID, recordId);
source.setExternalId(recordId);
source.setProperty(FIELD_OCCURRENCE_ID, occurrence.getValueByLabel(FIELD_OCCURRENCE_ID));
source.setProperty(FIELD_CATALOG_NUMBER, occurrence.getValueByLabel(FIELD_CATALOG_NUMBER));
String targetBasisOfRecord = assoc.get("dwc:basisOfRecord");
target.setBasisOfRecord(nodeFactory.getOrCreateBasisOfRecord(targetBasisOfRecord, targetBasisOfRecord));
final String assocRecordId = assoc.get(FIELD_IDIGBIO_RECORD_ID);
target.setProperty(FIELD_IDIGBIO_RECORD_ID, assocRecordId);
target.setExternalId(assocRecordId);
nodeFactory.setUnixEpochProperty(source, date);
nodeFactory.setUnixEpochProperty(target, date);
String latitude = occurrence.getValueByLabel("decimalLatitude");
String longitude = occurrence.getValueByLabel("decimalLongitude");
if (StringUtils.isNotBlank(latitude) && StringUtils.isNotBlank(longitude)) {
Location loc = nodeFactory.getOrCreateLocation(new LocationImpl(Double.parseDouble(latitude), Double.parseDouble(longitude), null, null));
source.caughtIn(loc);
}
}
Aggregations