private String indexByGroovyScript ( DigitalObject object , Payload payload , String confOid , String rulesOid , Properties props ) throws RuleException { try { if ( engine == null ) { SimpleBindings bindings = new SimpleBindings ( ) ; ScriptEngineManager manager = new ScriptEngineManager ( ) ; engine = manager . getEngineByName ( "groovy" ) ; // the engine is stateful, and multiple queues means that // different queues will clash // still won't affect different messages coming through the same // queue as AMQ will deal with sycnhronization // will affect how config is read in the messaging scripts, // needs to access it as `configMap[<queue name>]` // configMap = new HashMap<String, HashMap<String, Object>>(); // engine.put("configMap", configMap); } JsonSimpleConfig jsonConfig = getConfigFile ( confOid ) ; // Get our data ready SimpleBindings bindings = new SimpleBindings ( ) ; Map < String , List < String > > fields = new HashMap < String , List < String > > ( ) ; bindings . put ( "fields" , fields ) ; bindings . put ( "jsonConfig" , jsonConfig ) ; bindings . put ( "indexer" , this ) ; bindings . put ( "object" , object ) ; bindings . put ( "payload" , payload ) ; bindings . put ( "params" , props ) ; bindings . put ( "log" , log ) ; // Run the data through our script Reader script = getGroovyObject ( rulesOid ) ; engine . setBindings ( bindings , ScriptContext . ENGINE_SCOPE ) ; SolrInputDocument document = ( SolrInputDocument ) engine . eval ( script ) ; StringWriter documentString = new StringWriter ( ) ; ClientUtils . writeXML ( document , documentString ) ; return documentString . toString ( ) ; } catch ( Exception e ) { throw new RuleException ( e ) ; } }
Index a payload using the provided data using a groovy script