Search in sources :

Example 11 with PropertyEnricherException

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();
    }
}
Also used : PropertyEnricherException(org.eol.globi.service.PropertyEnricherException) Taxon(org.eol.globi.domain.Taxon) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException) DB(org.mapdb.DB) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 12 with PropertyEnricherException

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;
}
Also used : PropertyEnricherException(org.eol.globi.service.PropertyEnricherException) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) XPathExpressionException(javax.xml.xpath.XPathExpressionException) PropertyEnricherException(org.eol.globi.service.PropertyEnricherException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

PropertyEnricherException (org.eol.globi.service.PropertyEnricherException)12 IOException (java.io.IOException)6 Taxon (org.eol.globi.domain.Taxon)4 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 TaxonNode (org.eol.globi.domain.TaxonNode)3 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 StopWatch (org.apache.commons.lang3.time.StopWatch)2 JsonProcessingException (org.codehaus.jackson.JsonProcessingException)2 TaxonImpl (org.eol.globi.domain.TaxonImpl)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1