javagroovyorientdborientdb-2.1orientdb2.2

How to pass Map type of parameter to orientdb groovy function from Java


I am trying to pass Map as a input to my orientdb groovy function. But Groovy function is considering my Map input parameter as String.

Please suggest how to pass Map type of input parameter to orientdb groovy function.

code

public void MapInputTest() {
     Map < String, Object > inputMap = new HashMap < String, Object > ();
     inputMap.put("serviceId", "ETHA12721205");
     inputMap.put("serviceId1", "ETHA127212051");
     inputMap.put("serviceId2", "ETHA127212052");

     g.execute(Script.function("MapInputFunction", inputMap));
     System.out.println("returnedString is : ");
}

groovy function:

def MapInputFunction(Map mapInput) {
    println("class type of input parameter" + mapInput.getClass())
    println("class type " + mapInput)
    def tempMap = [: ]
    tempMap = mapInput
    return tempMap.get('serviceId')
}

error

com.orientechnologies.orient.core.exception.OCommandExecutionException: Failed to execute command: function.MapInputFunction Cause:No signature of method: Script1.MapInputFunction() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [ETHA127212051, ETHA12721205, ETHA127212052]
    Possible solutions: MapInputFunction2(), MapInputFunction(java.lang.Object)
        at platform.orientdb.storage.DataGridStorage.executeCommand(DataGridStorage.java:631)
        at platform.orientdb.storage.DataGridStorage.command(DataGridStorage.java:601)
        at platform.orientdb.storage.message.CommandMessage.processMessage(CommandMessage.java:27)
        at platform.orientdb.storage.message.TxMessage.process(TxMessage.java:52)
        at platform.orientdb.storage.actor.TransactionActor.processMessage(TransactionActor.java:71)
        at platform.orientdb.storage.actor.ExternalStorageActor.onReceive(ExternalStorageActor.java:16)
        at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:165)
        at akka.actor.Actor$class.aroundReceive(Actor.scala:484)
        at akka.actor.UntypedActor.aroundReceive(UntypedActor.scala:95)
        at akka.actor.ActorCell.receiveMessage(ActorCell.scala:526)
        at akka.actor.ActorCell.invoke(ActorCell.scala:495)
        at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257)
        at akka.dispatch.Mailbox.run(Mailbox.scala:224)
        at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
        at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)*emphasized text*
        at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
        at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
        at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

Solution

  • In the script, let's say the name of the parameter is inputMap

    then send the below

     Map < String, Object > parameters= new HashMap < String, Object > ();
         parameters.put("serviceId", "ETHA12721205");
         parameters.put("serviceId1", "ETHA127212051");
    
     Map < String, Object > inputMap = new HashMap < String, Object > ();
    inputMap.put("inputMap",inputMap)
    
         g.execute(Script.function("MapInputFunction", inputMap));
         System.out.println("returnedString is : ");
    

    The script will able to read the inputMap as Map data-structure