use of org.eol.globi.service.TermLookupServiceException in project eol-globi-data by jhpoelen.
the class StudyImporterForBlewett method importStudy.
@Override
public void importStudy() throws StudyImporterException {
String citation = "Blewett DA, Hensley RA, and Stevens PW, Feeding Habits of Common Snook, Centropomus Undecimalis, in Charlotte Harbor, Florida, Gulf and Caribbean Research Vol 18, 1–13, 2006. doi:10.18785/gcr.1801.01 ";
Study study = nodeFactory.getOrCreateStudy(new StudyImpl("Blewett 2006", StudyImporterForGoMexSI2.GOMEXI_SOURCE_DESCRIPTION, null, citation));
try {
Map<String, Location> collectionLocationMap = new HashMap<>();
Map<String, Date> collectionTimeMap = new HashMap<String, Date>();
buildLocationTimeMaps(collectionLocationMap, collectionTimeMap, study);
parsePredatorPreyInteraction(study, collectionLocationMap, collectionTimeMap);
} catch (IOException e) {
throw new StudyImporterException("failed to read resource", e);
} catch (NodeFactoryException e) {
throw new StudyImporterException("failed to create taxon", e);
} catch (TermLookupServiceException e) {
throw new StudyImporterException("failed to map terms", e);
}
}
use of org.eol.globi.service.TermLookupServiceException in project eol-globi-data by jhpoelen.
the class StudyImporterForAkin method addPrey.
private void addPrey(Study study, LabeledCSVParser parser, String[] header, String[] line, Specimen specimen, Location location) throws StudyImporterException {
int firstPreyIndex = findIndexForColumnWithNameThrowOnMissing("Detritus", header);
for (int i = firstPreyIndex; i < line.length; i++) {
String preySpeciesName = header[i];
if (StringUtils.isNotBlank(preySpeciesName)) {
String preyVolumeString = line[i];
try {
if (StringUtils.isNotBlank(preyVolumeString)) {
double volume = Double.parseDouble(preyVolumeString);
if (volume > 0) {
Specimen prey = nodeFactory.createSpecimen(study, new TaxonImpl(preySpeciesName, null));
prey.setLifeStage(parseLifeStage(nodeFactory.getTermLookupService(), preySpeciesName));
prey.setVolumeInMilliLiter(volume);
prey.caughtIn(location);
specimen.ate(prey);
}
}
} catch (NumberFormatException ex) {
throw new StudyImporterException("failed to parse volume of prey [" + preySpeciesName + "] in stomach [" + preyVolumeString + "] on line [" + parser.getLastLineNumber() + "]");
} catch (TermLookupServiceException e) {
throw new StudyImporterException("failed to parse life stage of prey [" + preySpeciesName + "] in stomach [" + preyVolumeString + "] on line [" + parser.getLastLineNumber() + "]");
}
}
}
}
use of org.eol.globi.service.TermLookupServiceException in project eol-globi-data by jhpoelen.
the class TermLookupServiceImpl method buildMapping.
private void buildMapping(List<URI> uriList) throws TermLookupServiceException {
mapping = new HashMap<>();
for (URI uri : uriList) {
try {
String response = contentToString(uri);
CSVParse parser = CSVTSVUtil.createCSVParse(new StringReader(response));
parser.changeDelimiter(getDelimiter());
if (hasHeader()) {
parser = CSVTSVUtil.createLabeledCSVParser(parser);
}
String[] line;
while ((line = parser.getLine()) != null) {
if (line.length < 4) {
LOG.info("line: [" + parser.getLastLineNumber() + "] in [" + uriList + "] contains less than 4 columns");
} else {
String sourceName = line[1];
String targetId = line[2];
String targetName = line[3];
if (StringUtils.isNotBlank(sourceName) && StringUtils.isNotBlank(targetId) && StringUtils.isNotBlank(targetName)) {
List<Term> terms = mapping.computeIfAbsent(sourceName, k -> new ArrayList<>());
terms.add(new TermImpl(targetId, targetName));
}
}
}
} catch (IOException e) {
throw new TermLookupServiceException("failed to retrieve mapping from [" + uriList + "]", e);
}
}
}
use of org.eol.globi.service.TermLookupServiceException in project eol-globi-data by jhpoelen.
the class NodeFactoryNeo4jTest method createAndFindEnvironment.
@Test
public void createAndFindEnvironment() throws NodeFactoryException {
getNodeFactory().setEnvoLookupService(new TermLookupService() {
@Override
public List<Term> lookupTermByName(String name) throws TermLookupServiceException {
ArrayList<Term> terms = new ArrayList<>();
terms.add(new TermImpl("NS:" + name, StringUtils.replace(name, " ", "_")));
return terms;
}
});
Location location = getNodeFactory().getOrCreateLocation(new LocationImpl(0.0, 1.0, 2.0, null));
List<Environment> first = getNodeFactory().getOrCreateEnvironments(location, "BLA:123", "this and that");
location = getNodeFactory().getOrCreateLocation(new LocationImpl(0.0, 1.0, 2.0, null));
List<Environment> second = getNodeFactory().getOrCreateEnvironments(location, "BLA:123", "this and that");
assertThat(first.size(), is(second.size()));
assertThat(((NodeBacked) first.get(0)).getNodeID(), is(((NodeBacked) second.get(0)).getNodeID()));
EnvironmentNode foundEnvironment = getNodeFactory().findEnvironment("this_and_that");
assertThat(foundEnvironment, is(notNullValue()));
List<Environment> environments = location.getEnvironments();
assertThat(environments.size(), is(1));
Environment environment = environments.get(0);
NodeBacked environmentNode = (NodeBacked) environment;
assertThat(environmentNode.getNodeID(), is(foundEnvironment.getNodeID()));
assertThat(environment.getName(), is("this_and_that"));
assertThat(environment.getExternalId(), is("NS:this and that"));
Location anotherLocation = getNodeFactory().getOrCreateLocation(new LocationImpl(48.2, 123.1, null, null));
LocationNode anotherLocationNode = (LocationNode) anotherLocation;
assertThat(anotherLocationNode.getEnvironments().size(), is(0));
anotherLocationNode.addEnvironment((EnvironmentNode) environment);
assertThat(anotherLocationNode.getEnvironments().size(), is(1));
// don't add environment that has already been associated
anotherLocationNode.addEnvironment(environment);
assertThat(anotherLocationNode.getEnvironments().size(), is(1));
getNodeFactory().getOrCreateEnvironments(anotherLocation, "BLA:124", "that");
assertThat(anotherLocationNode.getEnvironments().size(), is(2));
}
Aggregations