This is an automated email from the ASF dual-hosted git repository.
gitgabrio pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-runtimes.git
The following commit(s) were added to refs/heads/main by this push:
new addf17a5ff [incubator-kie-issues#2150] Implementing DMNAnnotated bean
awareness on DMNContext population (#4101)
addf17a5ff is described below
commit addf17a5ff6c03b3cc562a84e3fc3344fde09251
Author: Gabriele Cardosi <[email protected]>
AuthorDate: Thu Oct 23 12:24:50 2025 +0200
[incubator-kie-issues#2150] Implementing DMNAnnotated bean awareness on
DMNContext population (#4101)
* [incubator-kie-issues#2150] Implementing DMNAnnotated bean awareness on
DMNContext population
* [incubator-kie-issues#2150] Add unit tests. Fixed execution logic
* [incubator-kie-issues#2150] Add missing license
* [incubator-kie-issues#2150] Fixing format
* [incubator-kie-issues#2150] Fixing impsort
---------
Co-authored-by: Gabriele-Cardosi <[email protected]>
---
jbpm/jbpm-bpmn2/pom.xml | 11 ++
.../bpmn2/rule/DecisionRuleTypeEngineImpl.java | 39 ++++++-
.../bpmn2/rule/DecisionRuleTypeEngineImplTest.java | 124 +++++++++++++++++++++
3 files changed, 170 insertions(+), 4 deletions(-)
diff --git a/jbpm/jbpm-bpmn2/pom.xml b/jbpm/jbpm-bpmn2/pom.xml
index 2abe87075e..ce155f8758 100755
--- a/jbpm/jbpm-bpmn2/pom.xml
+++ b/jbpm/jbpm-bpmn2/pom.xml
@@ -97,6 +97,17 @@
<artifactId>angus-activation</artifactId>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git
a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/rule/DecisionRuleTypeEngineImpl.java
b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/rule/DecisionRuleTypeEngineImpl.java
index 23220b2bf4..2d7e750faf 100644
---
a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/rule/DecisionRuleTypeEngineImpl.java
+++
b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/rule/DecisionRuleTypeEngineImpl.java
@@ -18,6 +18,7 @@
*/
package org.jbpm.bpmn2.rule;
+import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -31,9 +32,10 @@ import org.kie.dmn.api.core.DMNContext;
import org.kie.dmn.api.core.DMNMessage;
import org.kie.dmn.api.core.DMNResult;
import org.kie.dmn.api.core.DMNRuntime;
+import org.kie.dmn.feel.lang.impl.JavaBackedType;
+import org.kie.dmn.feel.lang.types.BuiltInType;
import org.kie.kogito.decision.DecisionModel;
import org.kie.kogito.dmn.DmnDecisionModel;
-import org.kie.kogito.dmn.rest.DMNJSONUtils;
public class DecisionRuleTypeEngineImpl implements DecisionRuleTypeEngine {
@@ -51,9 +53,9 @@ public class DecisionRuleTypeEngineImpl implements
DecisionRuleTypeEngine {
namespace,
model))
.get();
-
- //Input Binding
- DMNContext context = DMNJSONUtils.ctx(modelInstance,
jsonResolver.resolveAll(getInputs(rsni)));
+ // Input binding
+ Map<String, Object> variables = getDMNAnnotatedAdjustedMap(rsni);
+ DMNContext context = modelInstance.newContext(variables);
DMNResult dmnResult = modelInstance.evaluateAll(context);
if (dmnResult.hasErrors()) {
String errors =
dmnResult.getMessages(DMNMessage.Severity.ERROR).stream()
@@ -68,4 +70,33 @@ public class DecisionRuleTypeEngineImpl implements
DecisionRuleTypeEngine {
rsni.triggerCompleted();
}
+
+ Map<String, Object> getDMNAnnotatedAdjustedMap(RuleSetNodeInstance rsni) {
+ // Get inputs
+ Map<String, Object> inputs = getInputs(rsni);
+ // resolve inputs with the JsonResolver' objectMapper
+ Map<String, Object> jsonResolvedInputs =
jsonResolver.resolveAll(inputs);
+ return getDMNAnnotatedAdjustedMap(inputs, jsonResolvedInputs);
+ }
+
+ Map<String, Object> getDMNAnnotatedAdjustedMap(Map<String, Object>
rsniInputs, Map<String, Object> jsonResolvedInputs) {
+ Map<String, Object> toReturn = new HashMap<>(jsonResolvedInputs);
+ // Retrieving DMN-annotated inputs
+ Map<String, Object> dmnAnnotatedBeans = rsniInputs.entrySet()
+ .stream()
+ .filter(entry -> isDMNAnnotatedBean(entry.getValue()))
+ .collect(Collectors.toMap(Map.Entry::getKey,
Map.Entry::getValue));
+ // replacing/adding DMN-annotated beans inside returned Map
+ toReturn.putAll(dmnAnnotatedBeans);
+ return toReturn;
+ }
+
+ boolean isDMNAnnotatedBean(Object bean) {
+ return bean != null && isDMNAnnotatedClass(bean.getClass());
+ }
+
+ boolean isDMNAnnotatedClass(Class<?> clazz) {
+ return !JavaBackedType.of(clazz).equals(BuiltInType.UNKNOWN);
+ }
+
}
diff --git
a/jbpm/jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/rule/DecisionRuleTypeEngineImplTest.java
b/jbpm/jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/rule/DecisionRuleTypeEngineImplTest.java
new file mode 100644
index 0000000000..734933a2d3
--- /dev/null
+++
b/jbpm/jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/rule/DecisionRuleTypeEngineImplTest.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jbpm.bpmn2.rule;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.process.core.transformation.JsonResolver;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.FEELProperty;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class DecisionRuleTypeEngineImplTest {
+
+ private static DecisionRuleTypeEngineImpl DECISION_RULE_TYPE_ENGINE;
+ private static JsonResolver JSON_RESOLVER;
+
+ @BeforeAll
+ static void setup() {
+ DECISION_RULE_TYPE_ENGINE = new DecisionRuleTypeEngineImpl();
+ JSON_RESOLVER = new JsonResolver();
+ }
+
+ @Test
+ void getDMNAnnotatedAdjustedMap() {
+ Map<String, Object> rsniInputs = new HashMap<>();
+ rsniInputs.put("SOMETHING", "true");
+ DMNAnnotated dmnAnnotated = new DMNAnnotated("first", "last");
+ rsniInputs.put("dmnAnnotated", dmnAnnotated);
+ NOTDMNAnnotated notDMNAnnotated = new NOTDMNAnnotated("first", "last");
+ rsniInputs.put("notDMNAnnotated", notDMNAnnotated);
+ Map<String, Object> jsonResolvedInputs =
JSON_RESOLVER.resolveAll(rsniInputs);
+ Map<String, Object> retrieved =
DECISION_RULE_TYPE_ENGINE.getDMNAnnotatedAdjustedMap(rsniInputs,
jsonResolvedInputs);
+ assertThat(retrieved)
+ .containsEntry("SOMETHING", "true")
+ .containsEntry("dmnAnnotated", dmnAnnotated);
+ assertThat(retrieved.get("notDMNAnnotated")).isInstanceOf(Map.class);
+ }
+
+ @Test
+ void isDMNAnnotatedBean() {
+ DMNAnnotated dmnAnnotated = new DMNAnnotated("first", "last");
+
assertThat(DECISION_RULE_TYPE_ENGINE.isDMNAnnotatedBean(dmnAnnotated)).isTrue();
+ NOTDMNAnnotated notDMNAnnotated = new NOTDMNAnnotated("first", "last");
+
assertThat(DECISION_RULE_TYPE_ENGINE.isDMNAnnotatedBean(notDMNAnnotated)).isFalse();
+ }
+
+ @Test
+ void isDMNAnnotatedClass() {
+
assertThat(DECISION_RULE_TYPE_ENGINE.isDMNAnnotatedClass(DMNAnnotated.class)).isTrue();
+
assertThat(DECISION_RULE_TYPE_ENGINE.isDMNAnnotatedClass(NOTDMNAnnotated.class)).isFalse();
+ }
+
+ private static class DMNAnnotated {
+ private String firstName;
+ private String lastName;
+
+ public DMNAnnotated(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ @FEELProperty("first name")
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+ }
+
+ private static class NOTDMNAnnotated {
+ private String firstName;
+ private String lastName;
+
+ public NOTDMNAnnotated(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]