I am executing a DMN based decision model that got extracted from signavio tool. The model contains zip function as well as MID. see below the sample of my decision table
<decision name="collateOrder" id="id-85c7398c9bc186c1e2396c4625ebbcc1" label="Collate Order" sigExt:shapeId="sid-C47674E0-8CDE-4A4A-84E8-3DD179DCF72C" sigExt:diagramId="8462cb232d98419493d4ef846516a070">
<extensionElements/>
<variable typeRef="sig:collateOrder" name="collateOrder" id="id-85c7398c9bc186c1e2396c4625ebbcc1_variable"/>
<informationRequirement>
<requiredInput href="#id-a47f651b80111a121d93cf07939b20dc"/>
</informationRequirement>
<literalExpression expressionLanguage="http://www.omg.org/spec/FEEL/20140401">
<text>zip(["Item Name", "Item Price", "Item Quantity"], [order.itemName, order.price, order.quantity])</text>
</literalExpression>
</decision>
I am using kie-dmn-signavio-7.37.0.Final.jar
on my java code, i pass argument like below
DMNContext context = runtime.newContext();
List fieldList = Arrays.asList("itemName", "price", "quantity");
List<String> itemList = Arrays.asList("item1", "item2", "item3");
List<BigDecimal> priceList = Arrays.asList(new BigDecimal(1000), new BigDecimal(200), new BigDecimal(3000));
List<Integer> qtyList = Arrays.asList(100, 20, 300);
List<List> valLiist = Arrays.asList(itemList, priceList, qtyList);
List<List> finalList = Arrays.asList(fieldList, valLiist);
context.set("order", finalList);
DMNResult evaluateAll = runtime.evaluateAll(model0, context);
When i run my code, i am getting below error message 23:52:26.989 [main] ERROR org.kie.dmn.core.ast.DMNLiteralExpressionEvaluator - FEEL ERROR while evaluating literal expression 'zip(["Item Name", "Item Price", "Item Quantity"], ... [string clipped after 50 chars, total length is 96]': The parameter 'values', in function zip(), values must be a list of the same size as of attributes.
Not sure what is wrong on my input.
Appreciate your help.
see below the sample of my decision table
The sample snippet you provided actually is not a decision table but a FEEL literal expression :)
Regardless, I believe you are not using the Signavio's extended zip function correctly.
zip(attributes, values1, ..., valuesN) Assembles a list of objects out of a list of attributes and multiple lists of values.
So in your case because you have attributes of size 3, you must supply 3 lists of N elements each.
In other words:
zip(["Item Name", "Item Price", "Item Quantity"],
list of names,
list of prices,
list of qtys)
that for your DMN model it would be like saying:
zip(["Item Name", "Item Price", "Item Quantity"], order.itemName, order.price, order.quantity)
Also on your Java input you are not supplying the expected composite object, order
is a list of complex object each having "itemName", "price", "quantity"
attributes.
Once I fixed those issues it works fine, I will include sample DMN and Java test snippet below.
Important. However it is a bit difficult to understand the use-case based on the elements provided in the original question, so you might want to revise if the zip()
function use is needed at all, and just make use of DMN Standard functionalities.
Full fixed example DMN model:
<dmn:definitions xmlns:dmn="http://www.omg.org/spec/DMN/20180521/MODEL/" xmlns="https://kiegroup.org/dmn/_CEDFCB71-C301-4AF7-8438-3C906965946C" xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/" xmlns:kie="http://www.drools.org/kie/dmn/1.2" xmlns:dmndi="http://www.omg.org/spec/DMN/20180521/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" xmlns:feel="http://www.omg.org/spec/DMN/20180521/FEEL/" id="_C606E3BA-A1A8-4D0A-A1E8-AE404B568CC0" name="9B64A25E-4853-4D7B-B8FE-33E98234AE51" typeLanguage="http://www.omg.org/spec/DMN/20180521/FEEL/" namespace="https://kiegroup.org/dmn/_CEDFCB71-C301-4AF7-8438-3C906965946C">
<dmn:extensionElements/>
<dmn:inputData id="_AFE2999A-D71C-4C4B-B1D7-CC1DB6650FC1" name="order">
<dmn:extensionElements/>
<dmn:variable id="_F69956F1-49DA-46C8-A0DA-9E84AF18D0B2" name="order"/>
</dmn:inputData>
<dmn:decision id="_48E05B28-5BEB-457E-BCDB-16023684FA3E" name="collateOrder">
<dmn:extensionElements/>
<dmn:variable id="_69BECEE8-924A-411C-84EE-769432DF5C22" name="collateOrder"/>
<dmn:informationRequirement id="_4533C1C4-E3F3-4557-ABE1-A2264908875F">
<dmn:requiredInput href="#_AFE2999A-D71C-4C4B-B1D7-CC1DB6650FC1"/>
</dmn:informationRequirement>
<dmn:literalExpression id="_F029607F-4296-4ADE-B669-AC6FD5AB91FD">
<dmn:text>zip(["Item Name", "Item Price", "Item Quantity"], order.itemName, order.price, order.quantity)</dmn:text>
</dmn:literalExpression>
</dmn:decision>
</dmn:definitions>
test snippet:
DMNContext context = runtime.newContext();
Map<String, Object> item1 = new HashMap<>();
item1.put("itemName", "item1");
item1.put("price", new BigDecimal(1000));
item1.put("quantity", 100);
Map<String, Object> item2 = new HashMap<>();
item2.put("itemName", "item2");
item2.put("price", new BigDecimal(200));
item2.put("quantity", 20);
Map<String, Object> item3 = new HashMap<>();
item3.put("itemName", "item3");
item3.put("price", new BigDecimal(3000));
item3.put("quantity", 300);
context.set("order", Arrays.asList(item1, item2, item3));
DMNResult evaluateAll = runtime.evaluateAll(model0, context);
System.out.println(evaluateAll.getContext());
results:
{
order: [{itemName=item1, quantity=100, price=1000}, {itemName=item2, quantity=20, price=200}, {itemName=item3, quantity=300, price=3000}]
collateOrder: [{Item Name=item1, Item Quantity=100, Item Price=1000}, {Item Name=item2, Item Quantity=20, Item Price=200}, {Item Name=item3, Item Quantity=300, Item Price=3000}]
}