Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. // Ensure compatibility with both JDK 7 and 8 JSR-223 Script Engines
  2. try { load("nashorn:mozilla_compat.js"); } catch(e) { }
  3.  
  4. // Import the interface required by the Script snap.
  5. importPackage(com.snaplogic.scripting.language);
  6.  
  7. // Import the Java utility classes.
  8. importPackage(java.util);
  9.  
  10. /**
  11. * Create an object that implements the methods defined by the "ScriptHook"
  12. * interface. We'll be passing this object to the constructor for the
  13. * ScriptHook interface.
  14. */
  15. var impl = {
  16. /*
  17. * These variables (input, output, error, log) are defined by the
  18. * ExecuteScript snap when evaluating this script.
  19. */
  20. input : input,
  21. output : output,
  22. error : error,
  23. log : log,
  24.  
  25. /**
  26. * The "execute()" method is called once when the pipeline is started
  27. * and allowed to process its inputs or just send data to its outputs.
  28. *
  29. * Exceptions are automatically caught and sent to the error view.
  30. */
  31. execute : function () {
  32. var interfaceIds = new java.util.ArrayList();
  33. var interfaceParams = new java.util.ArrayList();
  34. while (this.input.hasNext()) {
  35. var doc = this.input.next();
  36.  
  37. var interfaceId = doc.interface_id;
  38. var paramName = doc.param_name;
  39. var paramValue = doc.param_value;
  40.  
  41. var index = -1;
  42.  
  43. if(!interfaceIds.contains(interfaceId)) {
  44. interfaceIds.add(interfaceId);
  45. var interfaceMap = new java.util.LinkedHashMap();
  46. interfaceMap.put("interface_id", interfaceId);
  47. interfaceParams.add(interfaceMap);
  48. }
  49.  
  50. index = interfaceIds.indexOf(interfaceId);
  51. if(index >= 0) {
  52. interfaceParams.get(index).put(paramName,paramValue);
  53. }
  54. }
  55.  
  56. for(var i=0; i<interfaceParams.size(); i++) {
  57. this.output.write(interfaceParams.get(i));
  58. }
  59. }
  60. };
  61.  
  62. /**
  63. * The Script Snap will look for a ScriptHook object in the "hook"
  64. * variable. The snap will then call the hook's "execute" method.
  65. */
  66. var hook = new com.snaplogic.scripting.language.ScriptHook(impl);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement