This is an automated email from the ASF dual-hosted git repository.
fjtiradosarti 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 46733441e1 [Fix #3576] Searching for unique id in recursive way (#3582)
46733441e1 is described below
commit 46733441e140f495ba796ad71dd1512a0fb30a2b
Author: Francisco Javier Tirado Sarti
<[email protected]>
AuthorDate: Mon Jul 22 13:02:40 2024 +0200
[Fix #3576] Searching for unique id in recursive way (#3582)
Signed-off-by: Francisco Javier Tirado Sarti <[email protected]>
---
.../jbpm/ruleflow/core/RuleFlowProcessFactory.java | 24 ++++--
.../src/main/resources/compensation.sw.json | 93 ++++++++++++++++++++++
.../quarkus/workflows/CompensationRestIT.java | 60 ++++++++++++++
3 files changed, 169 insertions(+), 8 deletions(-)
diff --git
a/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/RuleFlowProcessFactory.java
b/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/RuleFlowProcessFactory.java
index 3c6089e19a..ea9a67f0a9 100755
---
a/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/RuleFlowProcessFactory.java
+++
b/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/RuleFlowProcessFactory.java
@@ -420,20 +420,28 @@ public class RuleFlowProcessFactory extends
RuleFlowNodeContainerFactory<RuleFlo
}
protected Node findNodeByIdOrUniqueIdInMetadata(NodeContainer
nodeContainer, final String nodeRef, String errorMsg) {
- Node node = null;
- // try looking for a node with same "UniqueId" (in metadata)
- for (Node containerNode : nodeContainer.getNodes()) {
- if (nodeRef.equals(containerNode.getUniqueId())) {
- node = containerNode;
- break;
- }
- }
+ Node node = findNodeByUniqueId(nodeContainer, nodeRef);
if (node == null) {
throw new IllegalArgumentException(errorMsg);
}
return node;
}
+ private Node findNodeByUniqueId(NodeContainer nodeContainer, final String
nodeRef) {
+ for (Node containedNode : nodeContainer.getNodes()) {
+ if (nodeRef.equals(containedNode.getUniqueId())) {
+ return containedNode;
+ }
+ if (containedNode instanceof NodeContainer) {
+ Node result = findNodeByUniqueId((NodeContainer)
containedNode, nodeRef);
+ if (result != null) {
+ return result;
+ }
+ }
+ }
+ return null;
+ }
+
private void postProcessNodes(RuleFlowProcess process, NodeContainer
container) {
for (Node node : container.getNodes()) {
diff --git
a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/compensation.sw.json
b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/compensation.sw.json
new file mode 100644
index 0000000000..884b5fc16d
--- /dev/null
+++
b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/compensation.sw.json
@@ -0,0 +1,93 @@
+{
+ "id": "compensation",
+ "version": "1.0",
+ "name": "Workflow Error example",
+ "description": "An example of how compensation works",
+ "start": "printStatus",
+ "errors": [
+ {
+ "name": "OddException",
+ "code": "java.lang.RuntimeException"
+ }
+ ],
+ "functions": [
+ {
+ "name": "isEven",
+ "type": "custom",
+ "operation":
"service:java:org.kie.kogito.workflows.services.EvenService::isEven"
+ }],
+ "states": [
+ {
+ "name": "printStatus",
+ "type": "inject",
+ "data": {
+ "compensated": false
+ },
+ "compensatedBy" : "compensating",
+ "transition": "branch"
+ },
+ {
+ "name": "branch",
+ "type": "switch",
+ "dataConditions": [
+ {
+ "condition": ".shouldCompensate==true",
+ "transition": {
+ "nextState" : "finish_compensate",
+ "compensate" : true
+ }
+ },
+ {
+ "condition": ".shouldCompensate==false",
+ "transition": {
+ "nextState" : "finish_not_compensate",
+ "compensate" : false
+ }
+ }
+ ]
+ },
+ {
+ "name": "compensating",
+ "usedForCompensation" : true,
+ "type": "inject",
+ "data": {
+ "compensated": true
+ },
+ "transition" : "compensating_more"
+ },
+ {
+ "name": "compensating_more",
+ "usedForCompensation" : true,
+ "type": "operation",
+ "actions": [{ "functionRef": {
+ "refName": "isEven",
+ "arguments": {
+ "number": ".number"
+ }
+ }}],
+ "onErrors": [
+ {
+ "errorRef": "OddException",
+ "transition": "OddHandler"
+ }
+ ]
+ },
+ { "name": "OddHandler",
+ "type":"inject",
+ "data": { "isEven": false},
+ "end": true
+ },
+ {
+ "name": "finish_compensate",
+ "type": "operation",
+ "actions": [],
+ "end": true
+ },
+ {
+ "name": "finish_not_compensate",
+ "type": "operation",
+ "actions": [],
+ "end": true
+ }
+ ]
+}
diff --git
a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/CompensationRestIT.java
b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/CompensationRestIT.java
new file mode 100644
index 0000000000..11cab0d9f0
--- /dev/null
+++
b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/CompensationRestIT.java
@@ -0,0 +1,60 @@
+/*
+ * 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.kie.kogito.quarkus.workflows;
+
+import org.junit.jupiter.api.Test;
+
+import io.quarkus.test.junit.QuarkusIntegrationTest;
+import io.restassured.http.ContentType;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.CoreMatchers.is;
+
+@QuarkusIntegrationTest
+public class CompensationRestIT {
+
+ @Test
+ public void testErrorRest() {
+ given()
+ .contentType(ContentType.JSON)
+ .accept(ContentType.JSON)
+ .body("{\"shouldCompensate\" : true, \"number\":2}").when()
+ .post("/compensation")
+ .then()
+ .statusCode(201)
+ .body("workflowdata.compensated", is(true));
+ given()
+ .contentType(ContentType.JSON)
+ .accept(ContentType.JSON)
+ .body("{\"shouldCompensate\" : true, \"number\":3}").when()
+ .post("/compensation")
+ .then()
+ .statusCode(201)
+ .body("workflowdata.compensated", is(true))
+ .body("workflowdata.isEven", is(false));
+ given()
+ .contentType(ContentType.JSON)
+ .accept(ContentType.JSON)
+ .body("{\"shouldCompensate\" : false}").when()
+ .post("/compensation")
+ .then()
+ .statusCode(201)
+ .body("workflowdata.compensated", is(false));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]