use of org.eol.globi.service.PropertyEnricherException in project eol-globi-data by jhpoelen.
the class TaxonCacheService method initTaxonCache.
private void initTaxonCache() throws PropertyEnricherException {
DB db = initDb("taxonCache");
String taxonCacheName = "taxonCacheById";
if (db.exists(taxonCacheName)) {
LOG.info("re-using pre-existing cache");
resolvedIdToTaxonMap = db.getTreeMap(taxonCacheName);
} else {
LOG.info("no pre-existing cache found, rebuilding...");
LOG.info("taxon cache loading [" + taxonCacheResource + "]...");
StopWatch watch = new StopWatch();
watch.start();
try {
resolvedIdToTaxonMap = db.createTreeMap(taxonCacheName).pumpPresort(100000).pumpIgnoreDuplicates().pumpSource(taxonCacheIterator(taxonCacheResource, new LineSkipper() {
@Override
public boolean shouldSkipLine(LabeledCSVParser parser) {
final Taxon taxon = TaxonCacheParser.parseLine(parser);
return StringUtils.isBlank(taxon.getPath());
}
})).keySerializer(BTreeKeySerializer.STRING).make();
} catch (IOException e) {
throw new PropertyEnricherException("failed to instantiate taxonCache: [" + e.getMessage() + "]", e);
}
watch.stop();
LOG.info("taxon cache loading [" + taxonCacheResource + "] done.");
logCacheLoadStats(watch.getTime(), resolvedIdToTaxonMap.size());
watch.reset();
}
}
use of org.eol.globi.service.PropertyEnricherException in project eol-globi-data by jhpoelen.
the class XmlUtil method extractPathNoJoin.
public static List<String> extractPathNoJoin(String xmlContent, String elementName, String valuePrefix, String valueSuffix) throws PropertyEnricherException {
List<String> ranks = new ArrayList<String>();
try {
InputStream is = IOUtils.toInputStream(xmlContent, "UTF-8");
String xpathExpr = "//*[local-name() = '" + elementName + "']";
NodeList nodes = (NodeList) applyXPath(is, xpathExpr, XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Node item = nodes.item(i);
Node firstChild = item.getFirstChild();
if (null != firstChild) {
String nodeValue = firstChild.getNodeValue();
if (StringUtils.isNotBlank(nodeValue)) {
ranks.add(valuePrefix + nodeValue + valueSuffix);
}
}
}
} catch (Exception e) {
throw new PropertyEnricherException("failed to handle response [" + xmlContent + "]", e);
}
return ranks;
}
Aggregations