Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Ensure compatibility with both JDK 7 and 8 JSR-223 Script Engines
- try { load("nashorn:mozilla_compat.js"); } catch(e) { }
- // Import the interface required by the Script snap.
- importPackage(com.snaplogic.scripting.language);
- // Import the Java utility classes.
- importPackage(java.util);
- /**
- * Create an object that implements the methods defined by the "ScriptHook"
- * interface. We'll be passing this object to the constructor for the
- * ScriptHook interface.
- */
- var impl = {
- /*
- * These variables (input, output, error, log) are defined by the
- * ExecuteScript snap when evaluating this script.
- */
- input : input,
- output : output,
- error : error,
- log : log,
- /**
- * The "execute()" method is called once when the pipeline is started
- * and allowed to process its inputs or just send data to its outputs.
- *
- * Exceptions are automatically caught and sent to the error view.
- */
- execute : function () {
- var interfaceIds = new java.util.ArrayList();
- var interfaceParams = new java.util.ArrayList();
- while (this.input.hasNext()) {
- var doc = this.input.next();
- var interfaceId = doc.interface_id;
- var paramName = doc.param_name;
- var paramValue = doc.param_value;
- var index = -1;
- if(!interfaceIds.contains(interfaceId)) {
- interfaceIds.add(interfaceId);
- var interfaceMap = new java.util.LinkedHashMap();
- interfaceMap.put("interface_id", interfaceId);
- interfaceParams.add(interfaceMap);
- }
- index = interfaceIds.indexOf(interfaceId);
- if(index >= 0) {
- interfaceParams.get(index).put(paramName,paramValue);
- }
- }
- for(var i=0; i<interfaceParams.size(); i++) {
- this.output.write(interfaceParams.get(i));
- }
- }
- };
- /**
- * The Script Snap will look for a ScriptHook object in the "hook"
- * variable. The snap will then call the hook's "execute" method.
- */
- var hook = new com.snaplogic.scripting.language.ScriptHook(impl);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement