use of org.eol.globi.data.DatasetImporterForTSV.REFERENCE_URL in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCATest method importRecordsFromZip.
@Test
public void importRecordsFromZip() throws StudyImporterException, IOException {
URL resource = getClass().getResource("/org/globalbioticinteractions/dataset/dwca.zip");
DatasetImporterForDwCA studyImporterForDwCA = new DatasetImporterForDwCA(null, null);
DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("file:///some/path/data.zip"), inStream -> inStream);
JsonNode jsonNode = new ObjectMapper().readTree("{ " + "\"interactionTypeId\": \"http://purl.obolibrary.org/obo/RO_0002437\"," + "\"url\": \"" + resource.toExternalForm() + "\"" + "}");
dataset.setConfig(jsonNode);
studyImporterForDwCA.setDataset(dataset);
String expectedCitation = dataset.getCitation();
AtomicBoolean someRecords = new AtomicBoolean(false);
Set<String> resourceTypes = new TreeSet<>();
studyImporterForDwCA.setInteractionListener(new InteractionListener() {
@Override
public void on(Map<String, String> interaction) throws StudyImporterException {
String associatedTaxa = interaction.get("http://rs.tdwg.org/dwc/terms/associatedTaxa");
String dynamicProperties = interaction.get("http://rs.tdwg.org/dwc/terms/dynamicProperties");
assertThat(StringUtils.isNotBlank(associatedTaxa) || StringUtils.isNotBlank(dynamicProperties), is(true));
assertThat(interaction.get(SOURCE_TAXON_NAME), is(not(nullValue())));
assertThat(interaction.get(TaxonUtil.TARGET_TAXON_NAME), is(not(nullValue())));
assertThat(interaction.get(INTERACTION_TYPE_NAME), is(not(nullValue())));
assertThat(interaction.get(DatasetImporterForTSV.DATASET_CITATION), containsString(expectedCitation));
assertThat(interaction.get(REFERENCE_ID), startsWith("https://symbiota.ccber.ucsb.edu:443/collections/individual/index.php?occid"));
assertThat(interaction.get(DatasetImporterForTSV.REFERENCE_CITATION), startsWith("https://symbiota.ccber.ucsb.edu:443/collections/individual/index.php?occid"));
assertThat(interaction.get(REFERENCE_URL), startsWith("https://symbiota.ccber.ucsb.edu:443/collections/individual/index.php?occid"));
resourceTypes.addAll(Arrays.asList(splitByPipes(interaction.get(RESOURCE_TYPES))));
someRecords.set(true);
}
});
studyImporterForDwCA.importStudy();
assertThat(someRecords.get(), is(true));
assertThat(resourceTypes, containsInAnyOrder("http://rs.tdwg.org/dwc/terms/dynamicProperties", "http://rs.tdwg.org/dwc/terms/Occurrence", "http://rs.tdwg.org/dwc/terms/associatedTaxa"));
}
use of org.eol.globi.data.DatasetImporterForTSV.REFERENCE_URL in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCATest method importRecordsFromArctosArchive.
@Test
public void importRecordsFromArctosArchive() throws StudyImporterException, URISyntaxException {
URL resource = getClass().getResource("/org/globalbioticinteractions/dataset/arctos_mvz_bird_small.zip");
DatasetImporterForDwCA studyImporterForDwCA = new DatasetImporterForDwCA(null, null);
studyImporterForDwCA.setDataset(new DatasetImpl("some/namespace", resource.toURI(), inStream -> inStream));
List<String> families = new ArrayList<>();
AtomicBoolean someRecords = new AtomicBoolean(false);
studyImporterForDwCA.setInteractionListener(new InteractionListener() {
@Override
public void on(Map<String, String> interaction) throws StudyImporterException {
assertThat(interaction.get(REFERENCE_URL), startsWith("http://arctos.database.museum/guid/"));
assertThat(interaction.get(SOURCE_OCCURRENCE_ID), anyOf(is("http://arctos.database.museum/guid/MVZ:Bird:180448?seid=587053"), is("http://arctos.database.museum/guid/MVZ:Bird:183644?seid=158590"), is("http://arctos.database.museum/guid/MVZ:Bird:58090?seid=657121")));
if (interaction.containsKey(DatasetImporterForTSV.TARGET_OCCURRENCE_ID)) {
assertThat(interaction.get(DatasetImporterForTSV.TARGET_OCCURRENCE_ID), anyOf(is("http://arctos.database.museum/guid/MVZ:Herp:241200"), is("http://arctos.database.museum/guid/MVZ:Bird:183643"), is("http://arctos.database.museum/guid/MVZ:Bird:58093")));
}
assertThat(interaction.get(SOURCE_TAXON_FAMILY), anyOf(is("Accipitridae"), is("Strigidae")));
assertThat(interaction.get(DatasetImporterForTSV.RESOURCE_TYPES), is("http://rs.tdwg.org/dwc/terms/associatedOccurrences | http://rs.tdwg.org/dwc/terms/Occurrence"));
someRecords.set(true);
}
});
studyImporterForDwCA.importStudy();
assertThat(someRecords.get(), is(true));
}
use of org.eol.globi.data.DatasetImporterForTSV.REFERENCE_URL in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCATest method importRecords.
@Test
public void importRecords() throws StudyImporterException, URISyntaxException, IOException {
URL resource = getClass().getResource("/org/globalbioticinteractions/dataset/dwca.zip");
DatasetImporterForDwCA studyImporterForDwCA = new DatasetImporterForDwCA(null, null);
DatasetImpl dataset = new DatasetImpl("some/namespace", resource.toURI(), inStream -> inStream);
dataset.setConfig(new ObjectMapper().readTree("{ \"citation\": \"some citation\" }"));
studyImporterForDwCA.setDataset(dataset);
AtomicBoolean someRecords = new AtomicBoolean(false);
Set<String> resourceTypes = new TreeSet<>();
studyImporterForDwCA.setInteractionListener(new InteractionListener() {
@Override
public void on(Map<String, String> interaction) throws StudyImporterException {
String associatedTaxa = interaction.get("http://rs.tdwg.org/dwc/terms/associatedTaxa");
String dynamicProperties = interaction.get("http://rs.tdwg.org/dwc/terms/dynamicProperties");
assertThat(StringUtils.isNotBlank(associatedTaxa) || StringUtils.isNotBlank(dynamicProperties), is(true));
assertThat(interaction.get(SOURCE_TAXON_NAME), is(not(nullValue())));
assertThat(interaction.get(TaxonUtil.TARGET_TAXON_NAME), is(not(nullValue())));
assertThat(interaction.get(INTERACTION_TYPE_NAME), is(not(nullValue())));
assertThat(interaction.get(DatasetImporterForTSV.DATASET_CITATION), containsString("some citation"));
assertThat(interaction.get(DatasetImporterForTSV.DATASET_CITATION), containsString("Accessed at"));
assertThat(interaction.get(DatasetImporterForTSV.DATASET_CITATION), containsString("dataset/dwca.zip"));
assertThat(interaction.get(REFERENCE_ID), is(not(nullValue())));
assertThat(interaction.get(DatasetImporterForTSV.REFERENCE_CITATION), is(not(nullValue())));
assertThat(interaction.get(REFERENCE_URL), is(not(nullValue())));
resourceTypes.addAll(Arrays.asList(splitByPipes(interaction.get(RESOURCE_TYPES))));
someRecords.set(true);
}
});
studyImporterForDwCA.importStudy();
assertThat(someRecords.get(), is(true));
assertThat(resourceTypes, containsInAnyOrder("http://rs.tdwg.org/dwc/terms/dynamicProperties", "http://rs.tdwg.org/dwc/terms/Occurrence", "http://rs.tdwg.org/dwc/terms/associatedTaxa"));
}
use of org.eol.globi.data.DatasetImporterForTSV.REFERENCE_URL in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCA method mapReferenceInfo.
static void mapReferenceInfo(Record rec, Map<String, String> interactionProperties) {
String value = StringUtils.trim(rec.value(DcTerm.references));
if (StringUtils.isBlank(value)) {
value = StringUtils.trim(rec.value(DwcTerm.occurrenceID));
}
if (StringUtils.isNotBlank(value)) {
appendResourceType(interactionProperties, rec.rowType());
interactionProperties.put(REFERENCE_CITATION, value);
interactionProperties.put(REFERENCE_ID, value);
try {
URI referenceURI = new URI(value);
URL url = referenceURI.toURL();
interactionProperties.put(REFERENCE_URL, url.toString());
} catch (MalformedURLException | URISyntaxException | IllegalArgumentException e) {
// opportunistic extraction of url from references to take advantage of practice used in Symbiota)
}
}
}
Aggregations