Example usage for org.apache.solr.handler.dataimport Context resolve

List of usage examples for org.apache.solr.handler.dataimport Context resolve

Introduction

In this page you can find the example usage for org.apache.solr.handler.dataimport Context resolve.

Prototype

public abstract Object resolve(String var);

Source Link

Document

Use this directly to resolve variable

Usage

From source file:edu.stsci.registry.solr.OAIPMHEntityProcessor.java

@Override
public void init(Context context) {
    super.init(context);
    logger.debug("In init");
    rowIterator = null;/*from  w ww  . ja v a  2  s .c  o  m*/
    httpClient = HttpClients.createDefault();
    process = context.currentProcess(); //DELTA_DUMP or ...

    String waitStr = context.getEntityAttribute(WAIT_SECS);
    if (waitStr != null) {
        waitSeconds = Integer.valueOf(waitStr);
    }

    if (process.equals(Context.FIND_DELTA)) {
        logger.info("Find delta");
        deletedNodes = new ArrayList<>();
        modifiedNodes = new ArrayList<>();
        Map<String, Object> stats = context.getStats();
        //long docCount = (long) stats.get("docCount");
        //for(String key : stats.keySet()){
        //    logger.info(key + " " + stats.get(key).toString());
        //}
        // If we have no documents in the index, don't do a delta import
        //logger.info("docCount = " + docCount);
        // These stats aren't working (always 0) so don't rely on them
        //if(docCount > 0){        

        Map<String, Object> importerMap = (Map<String, Object>) context
                .resolve(ConfigNameConstants.IMPORTER_NS_SHORT);
        String lastIndexStr = (String) importerMap.get(SolrWriter.LAST_INDEX_KEY);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            lastImport = dateFormat.parse(lastIndexStr);
            logger.info("lastImport: " + lastIndexStr);
        } catch (ParseException ex) {
            logger.error(ex);
        }
        //}
        XPath xpath = XPathFactory.newInstance().newXPath();

        while (true) {
            boolean hasResumption = initNodes();
            logger.debug("Delta found " + nodes.getLength() + " new nodes");

            while (currentNode < nodes.getLength()) {
                logger.debug("Current node: " + currentNode);
                Node node = nodes.item(currentNode);
                try {
                    Node nodeStat;

                    nodeStat = (Node) xpath.evaluate(STATUS_EXPRESSION, node, XPathConstants.NODE);
                    if (nodeStat != null) {
                        String status = nodeStat.getTextContent();
                        if (status.equals("deleted")) {
                            deletedNodes.add(node);
                        } else {
                            modifiedNodes.add(node);
                        }

                    } else {
                        modifiedNodes.add(node);
                    }
                } catch (XPathExpressionException ex) {
                    logger.error("Error getting node status", ex);
                }
                currentNode++;
            }
            if (!hasResumption)
                break;
        }
        logger.info("Found " + deletedNodes.size() + " deleted nodes.");
        logger.info("Found " + modifiedNodes.size() + " new or modified nodes.");
        currentDeletedNode = 0;
        currentModifiedNode = 0;

    }

    if (process.equals(Context.FULL_DUMP)) {
        logger.debug("Full import");
        initNodes();
    }

    if (process.equals(Context.DELTA_DUMP)) {
        logger.debug("Delta dump");
        returnedRow = false;
    }

}