title: gremlin user defined steps in faunus script map
body: <p>Background:  I have several months experience using Gremlin and Faunus, incl. the ScriptMap step.  </p>
  
  <p>Problem: User defined Gremlin steps work fine when loaded in the shell as part of a script.  However, the same steps apparently have no effect when defined in a Faunus ScriptMap script.     </p>
  
  <pre><code> /***********Faunus Driver*************/
  
  //usage gremlin -e &lt;hhis file&gt; NOTE: to run in gremlin remove .submit() at end of pipe
  import Java.io.Console;
  //get args
  console = System.console()
  mapperpath=console. readLine ('&gt; &lt;map script path&gt;: ')
  refns=console.readLine('&gt; &lt;reference namespace&gt;: ')
  refinterestkey-console.readLine('&gt; &lt;interest field&gt;: ')
  //currently not in use
  refinterestval=console.readLine('&gt; &lt;interest value&gt;: ')         
  mainpropkey=console.readLine('&gt; ^main field&gt;: ')
  delim=console.readLine('&gt; &lt;main delimiter&gt;: ')
  args=[]
  args [0]=refns
  args [1]=refinterestkey
  args[2]=refinterestval
  args [3]=mainpropkey
  args [4]=delim
  args=(String[]) args.toArray()
  f=FaunusFactory.open('propertyfile')
  f.V().filter('{it.get Property("_namespace") =="streamernamespace" &amp;&amp; it.getProperty("_entity")==" selector"}').script(mapperpath, args).submit()
  f.shutdown()
  
  /***********Script Mapper*************/
  
  Gremlin.defineStep ("findMatch", [Vertex, Pipe], 
      {streamer,  interestindicator, fieldofinterest, fun -&gt;
      _().has (interestindicator , true).has(fieldofinterest, 
                                  fun(streamer)
      }
  )
  Gremlin.defineStep("connectMatch", [Vertex, Pipe], {streamer -&gt;
  // copy and link streaming vertices to matching vertices in main graph 
  _().transform({if(main!= null) {
          mylog.info("reference vertex " + main.id    
                                 +" &amp; streaming vertex"+streamer.id+" match on main " +main.getProperty(fieldofinterest));
          clone=g.addVertex(null);
          ElementHelper.copyProperties(streamer, clone);
          clone.setProperty("_namespace", main.getProperty("__namespace"));
          mylog.info("create clone "+clone.id+" in "+clone.getProperty("_namespace"));
          g.addEdge(main, clone, streamer.getProperty("source");
          mylog.info("created edge "+ e);
          g.commit()
      }})
  })
  
  def g
  def refns
  def refinterestkey
  def refinterestval
  def mainpropkey
  def delim
  def normValue
  
  def setup(args) {
      refns=args[0] 
      refinterestkey=args[1]
      refinterestval=args[2] 
      mainpropkey=args[3] 
      delim=args[4] 
      normValue = {obj-&gt; seltype=obj.getProperty("type");
              seltypenorm=seltype.trim().toUpperCase();   
              desc=obj.getProperty("description"); 
              if(desc.contains(delim}) (
                  selnum=desc.split(delim) [1].trim ()
              } else selnum=desc.trim();
              selnorm=seltypenorm.concat(delim).concat(selnum); 
              mylog.info ("streamer selector (" + seltype", "+desc+") normalized as "+selnorm);
              return selnorm
     }
      mylog=java.util.logging.Logger.getLogger("script_map")
      mylog.info ("configuring connection to reference graph
      conf=new BaseConfiguration()
      conf.setProperty("storage.backend", "cassandra"}
      conf.setProperty!"storage.keyspace", "titan"}
      conf.setProperty("storage.index.index-name", "titan")
      conf.setProperty("storage.hostname", "localhost")
      g=TitanFactory.open(conf)
      isstepsloaded = Gremlin.getStepnames().contains("findMatch"} &amp;&amp; 
      Gremlin.getStepNames().contain("connectMatch"}
      mylog.info("custom steps available?: "+isstepsloaded)
  }
  def map{v, args) { 
      try{
      incoming=g.v(v.id)
      mylog.info{"current streamer id: "+incoming.id)
      if(incoming.getProperty("_entity")=="selector") {
                      mylog.info("process incoming vertex "+incoming.id)          
                      g.V{"_namespace", refns).findMatch(incoming,refinterestkey, mainpropkey,normValue).connectMatch(incoming).iterate ()
      } 
      }catch(Exception e) {
              mylog.info("map method exception raised");
              mylog.severe(e.getMessage()
      }
              g.commit()
  }
  def cleanup(args) { g.shutdown()}
  </code></pre>