use of org.eol.globi.domain.TermImpl in project eol-globi-data by jhpoelen.
the class TaxonUtil method mapToTaxon.
public static void mapToTaxon(Map<String, String> properties, Taxon taxon) {
taxon.setName(properties.get(NAME));
taxon.setRank(properties.get(RANK));
final String externalId = properties.get(EXTERNAL_ID);
taxon.setExternalId(externalId);
taxon.setPath(properties.get(PATH));
taxon.setPathIds(properties.get(PATH_IDS));
taxon.setPathNames(properties.get(PATH_NAMES));
taxon.setCommonNames(properties.get(COMMON_NAMES));
final String externalUrl = properties.get(EXTERNAL_URL);
if (StringUtils.isBlank(externalUrl) && StringUtils.isNotBlank(externalId)) {
taxon.setExternalUrl(ExternalIdUtil.urlForExternalId(externalId));
} else {
taxon.setExternalUrl(externalUrl);
}
taxon.setThumbnailUrl(properties.get(THUMBNAIL_URL));
String statusId = properties.get(STATUS_ID);
String statusLabel = properties.get(STATUS_LABEL);
if (StringUtils.isNotBlank(statusId) && StringUtils.isNotBlank(statusLabel)) {
taxon.setStatus(new TermImpl(statusId, statusLabel));
}
taxon.setNameSource(properties.get(NAME_SOURCE));
taxon.setNameSourceURL(properties.get(NAME_SOURCE_URL));
taxon.setNameSourceAccessedAt(properties.get(NAME_SOURCE_ACCESSED_AT));
}
use of org.eol.globi.domain.TermImpl 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.TermImpl 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.TermImpl in project eol-globi-data by jhpoelen.
the class InteractionListenerImpl method setBasisOfRecordIfAvailable.
private void setBasisOfRecordIfAvailable(Map<String, String> link, Specimen specimen) {
final String basisOfRecordName = link.get(BASIS_OF_RECORD_NAME);
final String basisOfRecordId = link.get(BASIS_OF_RECORD_ID);
if (StringUtils.isNotBlank(basisOfRecordName) || StringUtils.isNotBlank(basisOfRecordId)) {
specimen.setBasisOfRecord(new TermImpl(basisOfRecordId, basisOfRecordName));
}
}
use of org.eol.globi.domain.TermImpl 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