DMN complex usage

Hello, loving flowable. How can I use a complex variable instance inside of a DMN table? For instance I have process variables that are maps of maps. The JUEL expression seems to be able to figure out this type of process variable but it seems like only simple type process variables can be used in the DMN table as variables. For instance ${product.type} as a Juel expression will get me the product process variable then the type variable nested inside of it. But using product.type as a variable inside of the DMN editor will try to find the product.type process variable which will result in no value returned. How do I resolve? Thanks

Hi.

I don’t understand exactly what the map is here. Is product a single complex object with a property type?
Could you share an example on what you’re trying to do?

Regards,

Yvo

Hello, maybe there is a better way of doing this, but my objective here is to take a JSON response from an HTTP task and parse it into a process variable that is representitive of the JSON’s structure. (As you probably know Objects in JSON can be nested N levels deep.) Then use some of those process variables in a DMN decision activity.

For example, my service returns a response like this. Then I want to use TestResults.Udid in a DMN table. My code is here below, the result of the code is a Map<String, Object> where the object can be a String or another Map, and then set as a process variable.

String json = “[\n” +
" {\n" +
" “DeviceFirmware”: “2.23.03”,\n" +
" “DeviceInternalMemory”: “16 GB”,\n" +
" “ESN”: “N/A”,\n" +
" “FRPLock”: “Off”,\n" +
" “DeviceUdid”: “c8d9dae7c32c1ec13cded6175eed82f475d2575b”,\n" +
" “DeviceImei”: “359307060740418”,\n" +
" “DeviceModelNumber”: “MG562LL/A”,\n" +
" “DeviceBrand”: “Apple”,\n" +
" “TestResults”: {\n" +
" “FailedTests”: [\n" +
" “Battery”,\n" +
" “Fingerprint Sensor”,\n" +
" “Front Microphone”,\n" +
" “Network Connectivity”\n" +
" ],\n" +
" “Udid”: “c8d9dae7c32c1ec13cded6175eed82f475d2575b”,\n" +
" “PassTests”: [\n" +
" “Accelerometer”,\n" +
" “Audio Test”,\n" +
" “Bluetooth”,\n" +
" “Camera Test”,\n" +
" “Digitizer”,\n" +
" “Earpiece”,\n" +
" “Flash”,\n" +
" “Flip Switch”,\n" +
" “Front Camera”,\n" +
" “Front Camera Quality”,\n" +
" “GPS”,\n" +
" “Glass Cracked”,\n" +
" “Headset Port”,\n" +
" “Headset-Left”,\n" +
" “Headset-Right”,\n" +
" “Home Button”,\n" +
" “LCD”,\n" +
" “Loud Speaker”,\n" +
" “Microphone”,\n" +
" “Power Button”,\n" +
" “Proximity Sensor”,\n" +
" “Rear Camera”,\n" +
" “Rear Camera Quality”,\n" +
" “Sim Reader”,\n" +
" “Vibration”,\n" +
" “Video Microphone”,\n" +
" “Volume Down Button”,\n" +
" “Volume Up Button”,\n" +
" “WiFi”\n" +
" ]\n" +
" },\n" +
" “DeviceColor”: “Gold”,\n" +
" “DeviceSerialNo”: “DNPPW2W1G5MF”,\n" +
" “DeviceBatteryCurrentMaxCapacity”: 40,\n" +
" “DeviceTitle”: “MG562”,\n" +
" “IsAppInstalled”: true,\n" +
" “DeviceConnectionStatus”: “Connected”,\n" +
" “DeviceBatteryDesignMaxCapacity”: 1751,\n" +
" “DeviceOsVersion”: “8.3”,\n" +
" “DeviceMake”: “Apple”,\n" +
" “DeviceBatteryCycle”: 6,\n" +
" “DeviceCarrier”: “T-Mobile”,\n" +
" “DeviceGrade”: “”,\n" +
" “DeviceName”: “iPhone 6”\n" +
" }\n" +
"]";

Map<String, Object> jsonValues = getJsonValues(saveProcessInstanceVariableRequest.getVariableValue());
processEngine.getRuntimeService().setVariable(processInstance.getSuperExecutionId(), saveProcessInstanceVariableRequest.getVariableName(), jsonValues);

-----------------New File-------------
import org.flowable.engine.impl.util.json.JSONArray;
import org.flowable.engine.impl.util.json.JSONException;
import org.flowable.engine.impl.util.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**

  • Created by zeviel.persellin on 10/29/17.
    */
    public class JsonParser
    {
    public static Map<String, Object> getJsonValues(String json)
    {
    Map<String, Object> strings = new HashMap();
    if(isJsonObject(json))
    {
    JSONObject jsonObject = new JSONObject(json);
    fillMap(strings, jsonObject);

     }
     else if(isJsonArray(json))
     {
         JSONArray jsonArray = new JSONArray(json);
         jsonArray.length();
         for(int i = 0; i < jsonArray.length(); i++)
         {
             if(jsonArray.get(0) instanceof  JSONObject)
             {
                 JSONObject jsonObject = (JSONObject) jsonArray.get(0);
                 fillMap(strings, jsonObject);
             }
    
         }
    
     }
    
     return strings;
    

    }

    private static boolean isJsonObject(String json)
    {

     if(!isJsonArray(json))
     {
         try {
             new JSONObject(json);
         } catch (JSONException ex) {
             return false;
         }
         return true;
     }
     else
     {
         return false;
     }
    

    }

    private static boolean isJsonArray(String json)
    {

     try {
         new JSONArray(json);
     } catch (JSONException ex) {
         return false;
     }
     return true;
    

    }

    private static void fillMap(Map<String, Object> strings, JSONObject jsonObject)
    {
    Iterator iterator = jsonObject.keys();
    while(iterator.hasNext())
    {
    String key = (String)iterator.next();
    if(isJsonObject(jsonObject.getString(key)))
    {
    strings.put(key, getJsonValues(jsonObject.getString(key)));
    }
    else if(isJsonArray(jsonObject.getString(key)))
    {
    JSONArray jsonArray = new JSONArray(jsonObject.getString(key));
    for(int i = 0; i < jsonArray.length(); i++)
    {
    if(jsonArray.get(0) instanceof JSONObject)
    {
    JSONObject jsonObject1 = (JSONObject) jsonArray.get(i);
    strings.put(key + i, getJsonValues(jsonObject.getString(key)));
    }
    else
    {
    strings.put(key + i, jsonArray.get(i));
    }

             }
         }
         else
         {
             strings.put(key, jsonObject.getString(key));
         }
     }
    

    }
    }

@Zeviel_Persellin Did you find option to use complex json inside DMN Rule ?