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-examples.git
The following commit(s) were added to refs/heads/main by this push:
new 4751498fe [Fix #3475] Adding end metadata usage example (#1912)
4751498fe is described below
commit 4751498fe1de415c775a5f835ffc8049a267f5c8
Author: Francisco Javier Tirado Sarti
<[email protected]>
AuthorDate: Fri May 3 16:03:22 2024 +0200
[Fix #3475] Adding end metadata usage example (#1912)
---
.../serverless-workflow-error-quarkus/README.md | 2 ++
.../src/main/resources/errorWithMetadata.sw.json | 18 ++++++++++++++++++
.../java/org/kie/kogito/examples/ErrorRestIT.java | 21 +++++++++++++++++++++
3 files changed, 41 insertions(+)
diff --git
a/serverless-workflow-examples/serverless-workflow-error-quarkus/README.md
b/serverless-workflow-examples/serverless-workflow-error-quarkus/README.md
index 8cf762393..612799da9 100644
--- a/serverless-workflow-examples/serverless-workflow-error-quarkus/README.md
+++ b/serverless-workflow-examples/serverless-workflow-error-quarkus/README.md
@@ -11,6 +11,8 @@ The main feature of this demo is that if the number is odd,
an exception is thro
Hence, this workflow expects JSON input containing a natural number. This
number is passed using a service operation to `EvenService` java class. If the
number is even, the workflow moves to the next defined state, injecting "even"
`numberType`. But if the number is odd, the class throws an
`IllegalArgumentException`. This exception is handled and redirected to odd
inject node by using [inline workflow error
handling](https://github.com/serverlessworkflow/specification/blob/main/specific
[...]
+As per 0.8 version of the specification, there is no standard way to set a
process in error. To do that, users can use a custom metadata key called
`errorMessage` which will contain either the error message to be associated to
the process instance or an expression that returns the error message to
associated to the process instance. In addition to the workflow described
before, this example includes a file called `errorWithMEtadata.sw.json` that
illustrate the usage of such metadata.
+
## Installing and Running
diff --git
a/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/resources/errorWithMetadata.sw.json
b/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/resources/errorWithMetadata.sw.json
new file mode 100644
index 000000000..7a7a9551e
--- /dev/null
+++
b/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/resources/errorWithMetadata.sw.json
@@ -0,0 +1,18 @@
+{
+ "id": "errorWithMetadata",
+ "version": "1.0",
+ "name": "Workflow Error example with metadata",
+ "description": "An example of how to abort a workflow with error given a
condition",
+ "start": "checkEven",
+ "states": [
+ {
+ "name": "checkEven",
+ "type": "operation",
+ "actions": [],
+ "end" : true,
+ "metadata": {
+ "errorMessage": "if .number % 2 != 0 then \"Is Odd number!!!!\" else
null end"
+ }
+ }
+ ]
+}
diff --git
a/serverless-workflow-examples/serverless-workflow-error-quarkus/src/test/java/org/kie/kogito/examples/ErrorRestIT.java
b/serverless-workflow-examples/serverless-workflow-error-quarkus/src/test/java/org/kie/kogito/examples/ErrorRestIT.java
index a1225c096..099437d6c 100644
---
a/serverless-workflow-examples/serverless-workflow-error-quarkus/src/test/java/org/kie/kogito/examples/ErrorRestIT.java
+++
b/serverless-workflow-examples/serverless-workflow-error-quarkus/src/test/java/org/kie/kogito/examples/ErrorRestIT.java
@@ -56,4 +56,25 @@ public class ErrorRestIT {
.statusCode(201)
.body("workflowdata.numberType", is("even"));
}
+
+ @Test
+ public void testErrorWithMetadata() {
+ given()
+ .contentType(ContentType.JSON)
+ .accept(ContentType.JSON)
+ .body("{\"number\" : 12342}")
+ .when()
+ .post("/errorWithMetadata")
+ .then()
+ .statusCode(201);
+
+ given()
+ .contentType(ContentType.JSON)
+ .accept(ContentType.JSON)
+ .body("{\"number\" : 12341}")
+ .when()
+ .post("/errorWithMetadata")
+ .then()
+ .statusCode(400);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]