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

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

Introduction

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

Prototype

public abstract String getEntityAttribute(String name);

Source Link

Document

Get the value of any attribute put into this entity

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 va  2s  .  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;
    }

}

From source file:edu.uci.ics.sourcerer.search.analysis.EidToSimSnamesTransformer.java

License:Open Source License

public Object transformRow(Map<String, Object> row, Context context) {
    String codeServerUrl = context.getEntityAttribute("code-server-url");
    if (codeServerUrl != null)
        sg.setCodeServerUrl(codeServerUrl);

    String mltServerUrl = context.getEntityAttribute("mlt-server-url");
    if (mltServerUrl != null)
        sg.setMltServerUrl(mltServerUrl);

    String simServerUrl = context.getEntityAttribute("sim-server-url");
    if (simServerUrl != null)
        sg.setSimServerUrl(simServerUrl);

    String timeout = context.getEntityAttribute("http-timeout");
    if (timeout != null)
        sg.setTimeout(timeout);/*from w  w w.ja  v  a2s  . c  om*/

    String eid = ((BigInteger) row.get("eid")) + "";
    String etype = (String) row.get("etype");

    //        Logger.getLogger(this.getClass().getName()).log(Level.INFO, 
    //             "sim server: " + simServerUrl + " eid: " + eid);
    //        

    if (eid != null && etype != null) {

        if (etype.equals("CLASS") || etype.equals("METHOD") || etype.equals("CONSTRUCTOR")
        // || etype.equals("UNKNOWN")
        ) {

            String simMlt = sg.eidsViaMlt(eid);

            row.put("simMLT_eids_via_jdkLib_use", simMlt);
            //              Logger.getLogger(this.getClass().getName()).log(Level.INFO, 
            //                    "Got sim fqns via MLT: " + simMlt);
            //              
            String simTC = "''";
            String simHD = "''";

            if (simServerUrl == null) {
                simTC = SimEidGateway.eidsViaSimEntitiesTC(eid);
                simHD = SimEidGateway.eidsViaSimEntitiesHD(eid);
            } else {
                simTC = sg.eidsViaSimEntitiesTC(eid);
                simHD = sg.eidsViaSimEntitiesHD(eid);
            }

            row.put("simTC_eids_via_jdkLib_use", simTC);
            //              Logger.getLogger(this.getClass().getName()).log(Level.INFO, 
            //                    "Got sim eids via TC: " + simTC);

            row.put("simHD_eids_via_jdkLib_use", simHD);
            //              Logger.getLogger(this.getClass().getName()).log(Level.INFO, 
            //                    "Got sim eids via HD: " + simHD);

            // use file server
            if (codeServerUrl != null && codeServerUrl.length() > 0) {
                String code = sg.getCode(eid);
                if (code != null && code.length() > 0 && !code.startsWith("Unable to find")) {
                    row.put("code_text", code);
                }
            }
            // direct file access
            else {
                byte[] bcode = FileAccessor.lookupByEntityID(eid);
                if (bcode != null && bcode.length > 0) {
                    String code = new String(bcode);
                    row.put("code_text", code);
                }
            }
        }
    }

    return row;
}

From source file:fr.cnes.sitools.solr.transformer.WcsTransformer.java

License:Open Source License

/**
 * Sets up the Solr transformation's configuration.
 *
 * @param context context/*from  ww  w. ja v a2s  .c  o  m*/
 */
private void setupConfiguration(final Context context) {
    minOrder = (context.getEntityAttribute("minOrder") == null) ? DEFAULT_MIN_ORDER
            : Integer.valueOf(context.getEntityAttribute("minOrder"));
    maxOrder = (context.getEntityAttribute("maxOrder") == null) ? DEFAULT_MAX_ORDER
            : Integer.valueOf(context.getEntityAttribute("maxOrder"));
    String healpixScheme = context.getEntityAttribute("scheme");
    try {
        scheme = Scheme.valueOf(healpixScheme);
    } catch (IllegalArgumentException ex) {
        throw new RuntimeException("Healpix scheme must be set by defining scheme (=RING or NESTED) variable");
    }
    fields = context.getAllEntityFields();
}