9 Replies Latest reply on Feb 11, 2015 1:26 AM by Maciej Swiderski

    Custom WorkItemHandler - variables being converted to String

    Victor Tatai Newbie

      Hello,

       

      I am in the process of implementing a custom WorkItemHandler which allows calling Spring bean methods. It is all working so far, except when I use an expression for setting a parameter such as:

       

       

      <dataInputAssociation>
      
      
       <targetRef>_3_Param3Input</targetRef>
      <assignment>
      <from xsi:type="tFormalExpression">#{processData}</from>
      <to xsi:type="tFormalExpression">_3_Param3Input</to>
      </assignment>
      </dataInputAssociation>
      
      
      

       

      (#{processData} is actually a java.util.Map)

       

      then in my custom WorkItemHandler, when I do WorkItem#getParameters() for that parameter, it is there, but it is converted as a String - i.e., it is not a Map anymore.

       

      I was actually able to debug and found this bit of code inside jBPM's WorkItemNodeInstance#createWorkItem():

       

      Object variableValue = variableScopeInstance.getVariable(paramName);
      String variableValueString = variableValue == null ? "" : variableValue.toString(); 
      replacements.put(paramName, variableValueString);
      
      
      

      I was actually able to see that variableValue is the map I am expecting, so the variable exists and is being located correctly. What seems odd to me is the conversion from variableValue to variableValueString by calling 'variableValue.toString()'.

       

      Perhaps I'm doing something wrong in my WorkItemHandler, but I can't really see what. Please help!

       

      For reference, my wid file is:

       

      import org.drools.process.core.datatype.impl.type.StringDataType;
      import org.drools.process.core.datatype.impl.type.ObjectDataType;
      [
        [
          "name" : "Spring",
          "parameters" : [
            "Bean" : new StringDataType(),
            "Method" : new StringDataType(),
            "Param1" : new ObjectDataType(),
            "Param2" : new ObjectDataType(),
            "Param3" : new ObjectDataType(),
            "Param4" : new ObjectDataType(),
            "Param5" : new ObjectDataType(),
            "Param6" : new ObjectDataType(),
            "Param7" : new ObjectDataType(),
            "Param8" : new ObjectDataType(),
            "Param9" : new ObjectDataType()
          ],
          "displayName" : "Spring",
          "icon" : "icons/spring.png"
        ]
      ]
      

       

      Thanks for the help,

       

      Victor