use of org.eol.globi.service.TaxonUtil.TARGET_TAXON_NAME in project eol-globi-data by jhpoelen.
the class InteractionImporterTest method assertSymbiotaDateString.
public void assertSymbiotaDateString(String symbiotaTime, String expectedUTC) throws StudyImporterException {
final InteractionListener listener = getAssertingInteractionImporter();
final TreeMap<String, String> link = new TreeMap<>();
link.put(SOURCE_TAXON_NAME, "donald");
link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, "http://purl.obolibrary.org/obo/RO_0002470");
link.put(TARGET_TAXON_NAME, "mini");
link.put(DatasetImporterForMetaTable.EVENT_DATE, symbiotaTime);
link.put(REFERENCE_ID, "123");
link.put(DATASET_CITATION, "some source ref");
link.put(REFERENCE_CITATION, "");
listener.on(link);
AtomicBoolean foundSpecimen = new AtomicBoolean(false);
RelationshipListener someListener = relationship -> {
final SpecimenNode someSpecimen = new SpecimenNode(relationship.getEndNode());
assertTrue(someSpecimen.getUnderlyingNode().hasRelationship(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.COLLECTED)));
try {
Date eventDate = nodeFactory.getUnixEpochProperty(someSpecimen);
assertThat(DateUtil.printDate(eventDate), is(expectedUTC));
} catch (NodeFactoryException e) {
fail(e.getMessage());
}
foundSpecimen.set(true);
};
handleRelations(someListener, RelTypes.COLLECTED);
assertThat(foundSpecimen.get(), is(true));
}
use of org.eol.globi.service.TaxonUtil.TARGET_TAXON_NAME in project eol-globi-data by jhpoelen.
the class InteractionImporterTest method importBlankCitation.
@Test
public void importBlankCitation() throws StudyImporterException {
final InteractionListener listener = new InteractionImporter(nodeFactory, (GeoNamesService) null, null);
final TreeMap<String, String> link = new TreeMap<String, String>();
link.put(SOURCE_OCCURRENCE_ID, "123");
link.put(SOURCE_CATALOG_NUMBER, "catalogNumber123");
link.put(SOURCE_COLLECTION_CODE, "collectionCode123");
link.put(SOURCE_COLLECTION_ID, "collectionId123");
link.put(SOURCE_INSTITUTION_CODE, "institutionCode123");
link.put(TARGET_OCCURRENCE_ID, "456");
link.put(TARGET_CATALOG_NUMBER, "targetCatalogNumber123");
link.put(TARGET_COLLECTION_CODE, "targetCollectionCode123");
link.put(TARGET_COLLECTION_ID, "targetCollectionId123");
link.put(TARGET_INSTITUTION_CODE, "targetInstitutionCode123");
link.put(SOURCE_TAXON_NAME, "donald");
link.put(SOURCE_TAXON_ID, "duck");
link.put(SOURCE_BODY_PART_ID, "bla:123");
link.put(SOURCE_BODY_PART_NAME, "snout");
link.put(SOURCE_LIFE_STAGE_ID, "some:stage");
link.put(SOURCE_LIFE_STAGE_NAME, "stage");
link.put(TARGET_TAXON_NAME, "mini");
link.put(TARGET_TAXON_ID, "mouse");
link.put(TARGET_BODY_PART_ID, "bla:345");
link.put(TARGET_BODY_PART_NAME, "tail");
link.put(DatasetImporterForMetaTable.EVENT_DATE, "20160404T21:31:40Z");
link.put(DatasetImporterForMetaTable.LATITUDE, "12.1");
link.put(DatasetImporterForMetaTable.LONGITUDE, "13.2");
link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, "http://purl.obolibrary.org/obo/RO_0002470");
link.put(REFERENCE_ID, "123");
link.put(DATASET_CITATION, "some source ref");
link.put(REFERENCE_CITATION, "");
link.put(REFERENCE_DOI, "doi:1234");
listener.on(link);
final AtomicBoolean foundPair = new AtomicBoolean(false);
RelationshipListener relationshipListener = relationship -> {
final SpecimenNode predator = new SpecimenNode(relationship.getEndNode());
for (Relationship stomachRel : NodeUtil.getStomachContents(predator)) {
final SpecimenNode prey = new SpecimenNode(stomachRel.getEndNode());
final TaxonNode preyTaxon = getOrigTaxon(prey);
final TaxonNode predTaxon = getOrigTaxon(predator);
assertThat(preyTaxon.getName(), is("mini"));
assertThat(preyTaxon.getExternalId(), is("mouse"));
assertThat(predTaxon.getName(), is("donald"));
assertThat(predTaxon.getExternalId(), is("duck"));
assertLocation(predator.getSampleLocation());
assertLocation(prey.getSampleLocation());
assertThat(predator.getExternalId(), is("123"));
assertThat(prey.getExternalId(), is("456"));
assertThat(predator.getLifeStage().getId(), is("some:stage"));
assertThat(predator.getLifeStage().getName(), is("stage"));
assertThat(predator.getProperty(OCCURRENCE_ID), is("123"));
assertThat(predator.getProperty(CATALOG_NUMBER), is("catalogNumber123"));
assertThat(predator.getProperty(COLLECTION_CODE), is("collectionCode123"));
assertThat(predator.getProperty(COLLECTION_ID), is("collectionId123"));
assertThat(predator.getProperty(INSTITUTION_CODE), is("institutionCode123"));
assertThat(prey.getProperty(OCCURRENCE_ID), is("456"));
assertThat(prey.getProperty(CATALOG_NUMBER), is("targetCatalogNumber123"));
assertThat(prey.getProperty(COLLECTION_CODE), is("targetCollectionCode123"));
assertThat(prey.getProperty(COLLECTION_ID), is("targetCollectionId123"));
assertThat(prey.getProperty(INSTITUTION_CODE), is("targetInstitutionCode123"));
foundPair.set(true);
assertThat(relationship.getProperty(SpecimenConstant.EVENT_DATE), is(notNullValue()));
List<SpecimenNode> specimens = Arrays.asList(predator, prey);
for (SpecimenNode specimen : specimens) {
assertThat(specimen.getBodyPart().getId(), is(notNullValue()));
assertThat(specimen.getBodyPart().getName(), is(notNullValue()));
}
}
};
handleRelations(relationshipListener, RelTypes.COLLECTED);
assertThat(foundPair.get(), is(true));
}
use of org.eol.globi.service.TaxonUtil.TARGET_TAXON_NAME in project eol-globi-data by jhpoelen.
the class InteractionImporterTest method importWithTaxonHierarchy.
@Test
public void importWithTaxonHierarchy() throws StudyImporterException {
final InteractionListener listener = getAssertingInteractionImporter();
final TreeMap<String, String> link = new TreeMap<>();
link.put(SOURCE_TAXON_NAME, "Donald duck");
link.put(SOURCE_TAXON_RANK, "species");
link.put(SOURCE_TAXON_PATH, "Aves | Donald | Donald duck");
link.put(SOURCE_TAXON_PATH_IDS, "AvesId | DonaldId | DonaldId duckId");
link.put(SOURCE_TAXON_PATH_NAMES, "class | genus | species");
link.put(SOURCE_TAXON_SPECIFIC_EPITHET, "duck");
link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, InteractType.ATE.getIRI());
link.put(TARGET_TAXON_NAME, "mini");
link.put(TARGET_TAXON_RANK, "species");
link.put(TARGET_TAXON_PATH_IDS, "miniId");
link.put(DATASET_CITATION, "some source ref");
link.put(REFERENCE_ID, "123");
link.put(REFERENCE_CITATION, "");
listener.on(link);
AtomicInteger foundSpecimen = new AtomicInteger(0);
RelationshipListener someListener = relationship -> {
final SpecimenNode someSpecimen = new SpecimenNode(relationship.getEndNode());
assertTrue(someSpecimen.getUnderlyingNode().hasRelationship(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.COLLECTED)));
assertTrue(someSpecimen.getUnderlyingNode().hasRelationship(NodeUtil.asNeo4j(RelTypes.ORIGINALLY_DESCRIBED_AS)));
Node taxonNode = someSpecimen.getUnderlyingNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.ORIGINALLY_DESCRIBED_AS), Direction.OUTGOING).getEndNode();
TaxonNode taxon = new TaxonNode(taxonNode);
if (someSpecimen.getUnderlyingNode().hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE))) {
assertThat(taxon.getPath(), is("Aves | Donald | Donald duck"));
assertThat(taxon.getPathNames(), is("class | genus | species"));
assertThat(taxon.getRank(), is("species"));
assertThat(taxon.getPathIds(), is("AvesId | DonaldId | DonaldId duckId"));
foundSpecimen.incrementAndGet();
}
};
handleRelations(someListener, RelTypes.COLLECTED);
assertThat(foundSpecimen.get(), is(1));
}
use of org.eol.globi.service.TaxonUtil.TARGET_TAXON_NAME in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCATest method importRecordsFromUnresolvedResourceRelationshipArchive.
@Test
public void importRecordsFromUnresolvedResourceRelationshipArchive() throws StudyImporterException, URISyntaxException {
URL resource = getClass().getResource("fmnh-rr-unresolved-targetid-test.zip");
AtomicInteger recordCounter = new AtomicInteger(0);
DatasetImporterForDwCA studyImporterForDwCA = new DatasetImporterForDwCA(null, null);
studyImporterForDwCA.setDataset(new DatasetImpl("some/namespace", resource.toURI(), inStream -> inStream));
studyImporterForDwCA.setInteractionListener(interaction -> {
if (interaction.get(TARGET_OCCURRENCE_ID) != null) {
assertNull(interaction.get(TARGET_TAXON_NAME));
assertThat(interaction.get(TARGET_OCCURRENCE_ID), is("http://n2t.net/ark:/65665/37d63a454-d948-4b1d-89db-89809887ef41"));
recordCounter.incrementAndGet();
}
assertThat(interaction.get(DatasetImporterForTSV.RESOURCE_TYPES), is("http://rs.tdwg.org/dwc/terms/ResourceRelationship | http://rs.tdwg.org/dwc/terms/Occurrence"));
});
studyImporterForDwCA.importStudy();
assertThat(recordCounter.get(), greaterThan(0));
}
use of org.eol.globi.service.TaxonUtil.TARGET_TAXON_NAME in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCA method importInteractionsFromResourceRelationships.
private static void importInteractionsFromResourceRelationships(InteractionListener interactionListener, ArchiveFile resourceExtension, Map<String, Map<String, Map<String, String>>> termTypeIdPropMap, List<DwcTerm> termTypes) {
for (Record record : resourceExtension) {
Map<String, String> props = new TreeMap<>();
appendResourceType(props, resourceExtension.getRowType());
String sourceId = record.value(DwcTerm.resourceID);
String relationship = record.value(DwcTerm.relationshipOfResource);
Optional<Term> relationshipOfResourceIDTerm = record.terms().stream().filter(x -> StringUtils.equals(x.simpleName(), "relationshipOfResourceID")).findFirst();
String relationshipTypeIdValue = relationshipOfResourceIDTerm.map(record::value).orElse(null);
String targetId = record.value(DwcTerm.relatedResourceID);
if (StringUtils.isNotBlank(sourceId)) {
appendVerbatimResourceRelationsValues(record, props);
String relationshipAccordingTo = record.value(DwcTerm.relationshipAccordingTo);
if (StringUtils.isNotBlank(relationshipAccordingTo)) {
props.putIfAbsent(REFERENCE_CITATION, relationshipAccordingTo);
}
putIfAbsentAndNotBlank(props, INTERACTION_TYPE_NAME, relationship);
putIfAbsentAndNotBlank(props, INTERACTION_TYPE_ID, relationshipTypeIdValue);
putIfAbsentAndNotBlank(props, DatasetImporterForMetaTable.EVENT_DATE, record.value(DwcTerm.relationshipEstablishedDate));
for (DwcTerm termType : termTypes) {
String key = termType.qualifiedName();
if (StringUtils.isNoneBlank(key) && termTypeIdPropMap.containsKey(key)) {
Map<String, Map<String, String>> propMap = termTypeIdPropMap.get(termType.qualifiedName());
populatePropertiesAssociatedWithId(props, sourceId, true, propMap.get(sourceId), labelPairFor(termType));
extractNameFromRelationshipRemarks(record).ifPresent(name -> props.put(TARGET_TAXON_NAME, name));
populatePropertiesAssociatedWithId(props, targetId, false, propMap.get(targetId), labelPairFor(termType));
}
}
try {
interactionListener.on(props);
} catch (StudyImporterException e) {
//
}
}
}
}
Aggregations