Skip to content

Commit

Permalink
DROOLS-6630 DMN Signavio Profile multi-instance with complex inputs (a…
Browse files Browse the repository at this point in the history
…pache#3876) (apache#3890)

* DROOLS-6630 reproducer

* fix

* fix
  • Loading branch information
tarilabs authored Oct 8, 2021
1 parent 524bcc2 commit c6b1cbf
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.kie.dmn.core.impl.DMNContextImpl;
import org.kie.dmn.core.impl.DMNModelImpl;
import org.kie.dmn.core.impl.DMNResultImpl;
import org.kie.dmn.feel.FEEL;
import org.kie.dmn.feel.runtime.functions.AllFunction;
import org.kie.dmn.feel.runtime.functions.AnyFunction;
import org.kie.dmn.feel.runtime.functions.FEELFnResult;
Expand Down Expand Up @@ -116,7 +117,7 @@ public void compileEvaluator(DMNNode node, DMNCompilerImpl compiler, DMNCompiler
getMIDL(node).orElseThrow(() -> new IllegalStateException("Node doesn't contain multi instance decision logic!" + node.toString()));

// set the evaluator accordingly to Signavio logic.
di.setEvaluator(new MultiInstanceDecisionNodeEvaluator(midl, model, di));
di.setEvaluator(new MultiInstanceDecisionNodeEvaluator(midl, model, di, ctx.getFeelHelper().newFEELInstance()));

// Remove the top level decision and its dependencies, from the DMN Model (Decision|BKM|InputData) indexes
// Remember that as the dependencies will be removed from indexes, are no longer available at evalutation from the DMNExpressionEvaluator
Expand Down Expand Up @@ -144,11 +145,13 @@ public static class MultiInstanceDecisionNodeEvaluator implements DMNExpressionE
private DecisionNodeImpl di;
private String contextIteratorName;
private DecisionNodeImpl topLevelDecision;
private final FEEL feel;

public MultiInstanceDecisionNodeEvaluator(MultiInstanceDecisionLogic mi, DMNModelImpl model, DecisionNodeImpl di) {
public MultiInstanceDecisionNodeEvaluator(MultiInstanceDecisionLogic mi, DMNModelImpl model, DecisionNodeImpl di, FEEL feel) {
this.mi = mi;
this.model = model;
this.di = di;
this.feel = feel;
contextIteratorName = model.getInputById( mi.iteratorShapeId ).getName();
topLevelDecision = (DecisionNodeImpl) model.getDecisionById(mi.topLevelDecisionId);
}
Expand All @@ -163,7 +166,7 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d
List<? super Object> invokationResults = new ArrayList<>();

try {
Object cycleOnRaw = dmnContext.get( mi.iterationExpression );
Object cycleOnRaw = feel.evaluate(mi.iterationExpression, dmnContext.getAll());
Collection<?> cycleOn = null;
if ( cycleOnRaw instanceof Collection ) {
cycleOn = (Collection<?>) cycleOnRaw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.kie.api.KieServices;
Expand Down Expand Up @@ -269,4 +272,25 @@ private void checkBothFunctionsAreWorking(DMNRuntime runtime) {
assertThat((List<?>) evaluateAll.getDecisionResultByName("zipvararg").getResult(), iterableWithSize(2));
assertThat((List<?>) evaluateAll.getDecisionResultByName("zipsinglelist").getResult(), iterableWithSize(2));
}

@Test
public void testSignavioIterateMultiinstanceWithComplexInputs() {
DMNRuntime runtime = createRuntime("Iterate Complex List.dmn");

DMNContext context = runtime.newContext();
Map<String, Object> johnDoe = new HashMap<>();
johnDoe.put("iD", "id-john");
johnDoe.put("name", "John Doe");
Map<String, Object> alice = new HashMap<>();
alice.put("iD", "id-alice");
alice.put("name", "Alice");
context.set("customer", Collections.singletonMap("persons", Arrays.asList(johnDoe, alice)));

DMNModel model0 = runtime.getModels().get(0);
LOG.info("EVALUATE ALL:");
DMNResult evaluateAll = runtime.evaluateAll(model0, context);
LOG.info("{}", evaluateAll);

assertEquals(Arrays.asList("John Doe", "Alice"), evaluateAll.getDecisionResultByName("extractNames").getResult());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<dmn:definitions namespace="http://www.signavio.com/dmn/1.2/diagram/3053f20d4a8a49c5a12a8bb73e2fe745.xml" exporterVersion="14.16.0" name="Iterate Complex List" id="id-5680dc4c8952426c80429b1abc08d018" sigExt:revisionNumber="1" sigExt:revisionId="c726cc3d596d487990da19e4300e7a43" xmlns="http://www.signavio.com/dmn/1.2/diagram/3053f20d4a8a49c5a12a8bb73e2fe745.xml" xmlns:dmn="http://www.omg.org/spec/DMN/20180521/MODEL/" xmlns:sigExt="http://www.signavio.com/schema/dmn/1.2/" xmlns:feel="http://www.omg.org/spec/DMN/20180521/FEEL/">
<dmn:extensionElements/>
<dmn:itemDefinition typeLanguage="http://www.omg.org/spec/DMN/20180521/FEEL/" isCollection="false" name="getName" id="id-634bbc9ca1a0c50a6301373f8588df00" label="getName">
<dmn:typeRef>string</dmn:typeRef>
</dmn:itemDefinition>
<dmn:itemDefinition typeLanguage="http://www.omg.org/spec/DMN/20180521/FEEL/" isCollection="true" name="extractNames" id="id-cc17b3592eaf0a07fc3c0148f79e54dc" label="extractNames">
<dmn:typeRef>string</dmn:typeRef>
</dmn:itemDefinition>
<dmn:itemDefinition isCollection="false" name="customer" id="id-f1be5fe8a27afffbc8ab2fa7fa8d7e7b" label="customer">
<dmn:itemComponent typeLanguage="http://www.signavio.com/dmn/1.2/diagram/3053f20d4a8a49c5a12a8bb73e2fe745.xml" isCollection="true" name="persons" id="id-f1be5fe8a27afffbc8ab2fa7fa8d7e7b-relation-0" label="persons" sigExt:slotId="0">
<dmn:typeRef>person</dmn:typeRef>
</dmn:itemComponent>
</dmn:itemDefinition>
<dmn:itemDefinition isCollection="false" name="person" id="id-63fabfe379468e1402f4ee6694092cab" label="Person" sigExt:glossaryId="324af605ce9c46808c9c7633a0ff9e3c">
<dmn:itemComponent typeLanguage="http://www.omg.org/spec/DMN/20180521/FEEL/" isCollection="false" name="iD" id="id-63fabfe379468e1402f4ee6694092cab-relation-0" label="ID" sigExt:slotId="0">
<dmn:typeRef>string</dmn:typeRef>
</dmn:itemComponent>
<dmn:itemComponent typeLanguage="http://www.omg.org/spec/DMN/20180521/FEEL/" isCollection="false" name="name" id="id-63fabfe379468e1402f4ee6694092cab-relation-1" label="Name" sigExt:slotId="1">
<dmn:typeRef>string</dmn:typeRef>
</dmn:itemComponent>
</dmn:itemDefinition>
<dmn:inputData name="person_iterator" id="id-921036b2323af779707b1b600d78061f" label="Person" sigExt:diagramId="3053f20d4a8a49c5a12a8bb73e2fe745" sigExt:shapeId="sid-CF93E224-C19F-4F45-978A-72E726CE6936">
<dmn:extensionElements/>
<dmn:variable typeRef="person" name="person_iterator" id="id-921036b2323af779707b1b600d78061f_variable"/>
</dmn:inputData>
<dmn:inputData name="customer" id="id-362a4f59d2eb3b3857e1378ce3d6482e" label="customer" sigExt:diagramId="3053f20d4a8a49c5a12a8bb73e2fe745" sigExt:shapeId="sid-A9086029-E92E-4569-9E94-BA701BFC406C">
<dmn:extensionElements/>
<dmn:variable typeRef="customer" name="customer" id="id-362a4f59d2eb3b3857e1378ce3d6482e_variable"/>
</dmn:inputData>
<dmn:decision name="extractNames" id="id-d467daf38cb9452cd81a8d09dddc5b13" label="extractNames" sigExt:diagramId="3053f20d4a8a49c5a12a8bb73e2fe745" sigExt:shapeId="sid-A7328AB0-2095-454E-A296-72ECB8B1D997">
<dmn:extensionElements>
<sigExt:MultiInstanceDecisionLogic>
<sigExt:iterationExpression>customer.persons</sigExt:iterationExpression>
<sigExt:iteratorShapeId>id-921036b2323af779707b1b600d78061f</sigExt:iteratorShapeId>
<sigExt:aggregationFunction>COLLECT</sigExt:aggregationFunction>
<sigExt:topLevelDecisionId>id-838d8273165a607537d68c474c21baac</sigExt:topLevelDecisionId>
</sigExt:MultiInstanceDecisionLogic>
</dmn:extensionElements>
<dmn:variable typeRef="extractNames" name="extractNames" id="id-d467daf38cb9452cd81a8d09dddc5b13_variable"/>
<dmn:informationRequirement>
<dmn:requiredInput href="#id-362a4f59d2eb3b3857e1378ce3d6482e"/>
</dmn:informationRequirement>
</dmn:decision>
<dmn:decision name="getName" id="id-838d8273165a607537d68c474c21baac" label="getName" sigExt:diagramId="3053f20d4a8a49c5a12a8bb73e2fe745" sigExt:shapeId="sid-BB843B49-6A33-4B05-A3AC-CDA7C6287D28">
<dmn:extensionElements/>
<dmn:variable typeRef="getName" name="getName" id="id-838d8273165a607537d68c474c21baac_variable"/>
<dmn:informationRequirement>
<dmn:requiredInput href="#id-921036b2323af779707b1b600d78061f"/>
</dmn:informationRequirement>
<dmn:literalExpression expressionLanguage="http://www.omg.org/spec/DMN/20180521/FEEL/">
<dmn:text>person_iterator.name</dmn:text>
</dmn:literalExpression>
</dmn:decision>
</dmn:definitions>

0 comments on commit c6b1cbf

Please sign in to comment.