From cdfd8b70787a17f028a442cde4af28a116eb3213 Mon Sep 17 00:00:00 2001 From: Enrique Date: Mon, 3 Jun 2024 09:41:06 +0200 Subject: [PATCH 1/9] [incubator-kie-issues-1277] Remove unused bpmn in jbpm-test (#3536) --- .../BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 | 2 +- .../BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2 | 2 +- .../intermediate}/BPMN2-IntermediateCatchEventSignal2.bpmn2 | 2 +- .../BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 | 2 +- .../intermediate}/BPMN2-IntermediateCatchEventTimerCycle3.bpmn2 | 2 +- .../BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 | 2 +- .../BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 | 2 +- .../BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2 | 2 +- .../intermediate}/BPMN2-IntermediateThrowEventMessage.bpmn2 | 0 .../BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 | 2 +- .../BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 | 2 +- 11 files changed, 10 insertions(+), 10 deletions(-) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/intermediate}/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 (97%) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/intermediate}/BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2 (97%) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/intermediate}/BPMN2-IntermediateCatchEventSignal2.bpmn2 (99%) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/intermediate}/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 (97%) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/intermediate}/BPMN2-IntermediateCatchEventTimerCycle3.bpmn2 (96%) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/intermediate}/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 (96%) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/intermediate}/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 (96%) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/intermediate}/BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2 (96%) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/intermediate}/BPMN2-IntermediateThrowEventMessage.bpmn2 (100%) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/intermediate}/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 (94%) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/intermediate}/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 (94%) diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 index 60418fb8b20..0e4a16b54d6 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 @@ -36,7 +36,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2 index b0321b3ff70..cde461dea9c 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2 @@ -32,7 +32,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventSignal2.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignal2.bpmn2 similarity index 99% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventSignal2.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignal2.bpmn2 index 9df9412c66f..61dfb3559be 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventSignal2.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignal2.bpmn2 @@ -33,7 +33,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 index cb584c39813..bcac68ba125 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 @@ -33,7 +33,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerCycle3.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycle3.bpmn2 similarity index 96% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerCycle3.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycle3.bpmn2 index ef1434ed147..1af6a32fb10 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerCycle3.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycle3.bpmn2 @@ -32,7 +32,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 similarity index 96% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 index 344f25ddfa2..99cddc6d6d9 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 @@ -32,7 +32,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 similarity index 96% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 index 160a79bf31c..67dc6a805ce 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 @@ -22,7 +22,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2 similarity index 96% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2 index df400244748..422828e10cb 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2 @@ -31,7 +31,7 @@ xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.jboss.org/drools"> - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventMessage.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventMessage.bpmn2 similarity index 100% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventMessage.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventMessage.bpmn2 diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 similarity index 94% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 index 1323d06a34c..4f122fab7b0 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 @@ -35,7 +35,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 similarity index 94% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 index 1913d572900..a1a70587338 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 @@ -32,7 +32,7 @@ - + From af5e79ed818d7294d8c06700733d37373940c14e Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Martinez Date: Tue, 4 Jun 2024 11:53:26 +0200 Subject: [PATCH 2/9] fix transformers --- .../JavaDataTransformerCompiler.java | 38 +++- ...eCatchEventMessageWithTransformation.bpmn2 | 4 +- ...teCatchEventSignalWithTransformation.bpmn2 | 4 +- ...eThrowEventMessageWithTransformation.bpmn2 | 2 +- ...teThrowEventSignalWithTransformation.bpmn2 | 2 +- ...rySignalEventOnTaskWithTransformation.bpmn | 194 ----------------- ...N2-DataInputAssociations-two-assigns.bpmn2 | 60 ------ ...MN2-DataOutputAssociations-HumanTask.bpmn2 | 57 ----- ...eThrowEventMessageWithTransformation.bpmn2 | 87 ++++++++ ...BPMN2-SubProcessWithEntryExitScripts.bpmn2 | 196 ------------------ .../src/main/bpmn/BPMN2-XpathExpression.bpmn2 | 114 ---------- 11 files changed, 127 insertions(+), 631 deletions(-) delete mode 100755 jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn delete mode 100755 jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-DataInputAssociations-two-assigns.bpmn2 delete mode 100755 jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-DataOutputAssociations-HumanTask.bpmn2 create mode 100755 jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 delete mode 100755 jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-SubProcessWithEntryExitScripts.bpmn2 delete mode 100755 jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-XpathExpression.bpmn2 diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/JavaDataTransformerCompiler.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/JavaDataTransformerCompiler.java index d2dc13c0521..b45140519b4 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/JavaDataTransformerCompiler.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/JavaDataTransformerCompiler.java @@ -19,11 +19,11 @@ package org.jbpm.process.builder.transformation; import java.util.List; -import java.util.Map; import org.jbpm.workflow.core.impl.DataDefinition; import org.jbpm.workflow.core.node.Transformation; +import com.github.javaparser.ParseProblemException; import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.Parameter; @@ -36,6 +36,7 @@ import com.github.javaparser.ast.expr.StringLiteralExpr; import com.github.javaparser.ast.expr.VariableDeclarationExpr; import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.ast.type.ClassOrInterfaceType; public class JavaDataTransformerCompiler implements DataTransformerCompiler { @@ -48,7 +49,17 @@ public String[] dialects() { @Override public Expression compile(List inputs, List outputs, Transformation transformation) { // build lambda function - BlockStmt body = StaticJavaParser.parseBlock("{" + transformation.getExpression() + "}"); + String expression = transformation.getExpression(); + BlockStmt body = parseExpression(expression); + + if (body == null) { + body = parseStatement(expression); + } + + if (body == null) { + body = StaticJavaParser.parseBlock("{" + expression + "}"); + } + for (DataDefinition input : inputs) { ClassOrInterfaceType type = StaticJavaParser.parseClassOrInterfaceType(input.getType()); VariableDeclarationExpr target = new VariableDeclarationExpr(type, input.getLabel()); @@ -57,9 +68,28 @@ public Expression compile(List inputs, List outp body.addStatement(0, assignment); } - Expression lambda = new LambdaExpr(NodeList.nodeList(new Parameter(StaticJavaParser.parseClassOrInterfaceType(Map.class.getName()), "parameters")), body, true); - ClassOrInterfaceType type = StaticJavaParser.parseClassOrInterfaceType("java.util.function.Function"); + Expression lambda = new LambdaExpr(NodeList.nodeList(new Parameter(StaticJavaParser.parseClassOrInterfaceType("java.util.Map"), "parameters")), body, true); + ClassOrInterfaceType type = StaticJavaParser.parseClassOrInterfaceType("java.util.function.Function, Object>"); return new CastExpr(type, lambda); } + private BlockStmt parseStatement(String expression) { + try { + BlockStmt block = new BlockStmt(); + block.addStatement(StaticJavaParser.parseStatement(expression)); + return block; + } catch (ParseProblemException e) { + return null; + } + } + + private BlockStmt parseExpression(String expression) { + try { + BlockStmt block = new BlockStmt(); + block.addStatement(new ReturnStmt(StaticJavaParser.parseExpression(expression))); + return block; + } catch (ParseProblemException e) { + return null; + } + } } diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 index 0e4a16b54d6..5cdbbde7fa8 100755 --- a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 @@ -61,11 +61,11 @@ - + _4_Output x - param.toUpperCase(); + param.toUpperCase() _4_Output diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 index bcac68ba125..48b9f21223f 100755 --- a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 @@ -58,11 +58,11 @@ - + _4_Output x - param.toUpperCase(); + param.toUpperCase() _4_Output diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 index 4f122fab7b0..12d711ca829 100755 --- a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 @@ -47,7 +47,7 @@ x _2_Input - param.toUpperCase(); + x.toUpperCase() _2_Input diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 index a1a70587338..4a366a99720 100755 --- a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 @@ -44,7 +44,7 @@ x _2_Input - param.toUpperCase(); + x.toUpperCase() _2_Input diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn deleted file mode 100755 index d6eb0a8cb47..00000000000 --- a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn +++ /dev/null @@ -1,194 +0,0 @@ - - - - - - - - - SequenceFlow_1 - - - SequenceFlow_5 - SequenceFlow_4 - - - - SequenceFlow_4 - - - - SequenceFlow_1 - SequenceFlow_2 - - - - - - - - - _DataInput_2 - _DataInput_3 - _DataInput_4 - _DataInput_5 - _DataInput_6 - _DataInput_7 - - - - - _DataInput_2 - - - _DataInput_3 - - - _DataInput_4 - - - _DataInput_5 - - - _DataInput_6 - - - _DataInput_7 - - - - john - - - - - SequenceFlow_5 - - - _4_Output - x - param.toUpperCase(); - - - _4_Output - - - - - - - - - SequenceFlow_3 - - - - SequenceFlow_2 - SequenceFlow_3 - - - - - - - - - _DataInput_8 - _DataInput_9 - _DataInput_10 - _DataInput_11 - _DataInput_12 - _DataInput_13 - - - - - _DataInput_8 - - - _DataInput_9 - - - _DataInput_10 - - - _DataInput_11 - - - _DataInput_12 - - - _DataInput_13 - - - - john - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-DataInputAssociations-two-assigns.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-DataInputAssociations-two-assigns.bpmn2 deleted file mode 100755 index e514a8b2b2b..00000000000 --- a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-DataInputAssociations-two-assigns.bpmn2 +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - _BF09B923-BE11-4447-BECB-609BD86C59EF_Comment - - - - instanceMetadata - _BF09B923-BE11-4447-BECB-609BD86C59EF_Comment - - . - foo - - - . - foo/bar - - - - - true() - - - - - - - - - - count($instanceMetadata/user) = 2 - - - - - - - - - diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-DataOutputAssociations-HumanTask.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-DataOutputAssociations-HumanTask.bpmn2 deleted file mode 100755 index 6dbff6573dc..00000000000 --- a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-DataOutputAssociations-HumanTask.bpmn2 +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - _BF09B923-BE11-4447-BECB-609BD86C59EF_PreviousOwner - - - - _BF09B923-BE11-4447-BECB-609BD86C59EF_PreviousOwner - instanceMetadata - - @primaryname - previoustasksowner - - - - - true() - - - - - - - - - - count($instanceMetadata/user) = 2 - - - - - - - - - diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 new file mode 100755 index 00000000000..bc22ee935a5 --- /dev/null +++ b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + x + _2_Input + x.toUpperCase(); + + + _2_Input + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-SubProcessWithEntryExitScripts.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-SubProcessWithEntryExitScripts.bpmn2 deleted file mode 100755 index 82c335553bc..00000000000 --- a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-SubProcessWithEntryExitScripts.bpmn2 +++ /dev/null @@ -1,196 +0,0 @@ - - - - - - - - - - - - - - - _1-_2 - SequenceFlow_11 - System.err.println("Task 1, var1 = 10"); -kcontext.setVariable("var1", new Integer(10)); - - - - _1-_2 - - - - SequenceFlow_12 - SequenceFlow_7 - System.err.println("Task 3, var3 = 30"); -kcontext.setVariable("var3",30); - - - - - SequenceFlow_8 - - - - SequenceFlow_7 - SequenceFlow_8 - - - - - - - - - - _DataInput_150 - _DataInput_151 - _DataInput_152 - _DataInput_153 - _DataInput_154 - _DataInput_155 - _DataInput_156 - - - - - _DataInput_150 - - - _DataInput_151 - - - _DataInput_152 - - - _DataInput_153 - - - _DataInput_154 - - - _DataInput_155 - - - _DataInput_156 - - - - - - - System.err.println("SubProcess, var4 = 40"); -kcontext.setVariable("var4",40); - - - - System.err.println("SubProcess, var5 = 50"); -kcontext.setVariable("var5",50); - - - - SequenceFlow_11 - SequenceFlow_12 - - SequenceFlow_10 - - - - SequenceFlow_10 - SequenceFlow_9 - System.err.println("Task 2, var2 = 20"); -kcontext.setVariable("var2",20); - - - - - SequenceFlow_9 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-XpathExpression.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-XpathExpression.bpmn2 deleted file mode 100755 index 93d72711cfd..00000000000 --- a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-XpathExpression.bpmn2 +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - count($instanceMetadata/instanceMetadata/user[@approved='true']) = 1 - - - count($instanceMetadata/instanceMetadata/user[@approved='false']) = 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From eff7423d5680ad966fa4d4180a31166dae6ad301 Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Martinez Date: Tue, 4 Jun 2024 15:18:57 +0200 Subject: [PATCH 3/9] unify return value evaluator and transformation compiler --- .../jbpm/bpmn2/xml/AbstractNodeHandler.java | 27 ++++-- .../canonical/AbstractNodeVisitor.java | 58 ++++++++--- .../compiler/canonical/StartNodeVisitor.java | 6 +- .../JavaConstraintEvaluatorBuilder.java | 1 - .../process/builder/EventNodeBuilder.java | 4 - .../process/builder/ExtendedNodeBuilder.java | 10 -- .../DataTransformerCompiler.java | 39 -------- .../DataTransformerCompilerRegistry.java | 72 -------------- .../DefaultDataTransformerCompiler.java | 57 ----------- .../JavaDataTransformerCompiler.java | 95 ------------------- .../core/impl/DataTransformerRegistry.java | 65 ------------- .../transformation/JavaDataTransformer.java | 39 -------- .../transformation/MVELDataTransformer.java | 74 --------------- .../workflow/core/impl/DataAssociation.java | 14 +++ .../jbpm/workflow/core/impl/NodeIoHelper.java | 7 +- .../workflow/core/node/Transformation.java | 10 +- .../java/org/jbpm/bpmn2/ActivityTest.java | 46 --------- 17 files changed, 89 insertions(+), 535 deletions(-) delete mode 100644 jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompiler.java delete mode 100755 jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompilerRegistry.java delete mode 100644 jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DefaultDataTransformerCompiler.java delete mode 100644 jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/JavaDataTransformerCompiler.java delete mode 100755 jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/impl/DataTransformerRegistry.java delete mode 100644 jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/JavaDataTransformer.java delete mode 100755 jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/MVELDataTransformer.java diff --git a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java index 7a16ef7380e..9ccdd9f0c04 100755 --- a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java +++ b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java @@ -49,7 +49,6 @@ import org.jbpm.process.core.context.variable.Variable; import org.jbpm.process.core.context.variable.VariableScope; import org.jbpm.process.core.datatype.DataTypeResolver; -import org.jbpm.process.core.impl.DataTransformerRegistry; import org.jbpm.ruleflow.core.RuleFlowProcess; import org.jbpm.ruleflow.core.WorkflowElementIdentifierFactory; import org.jbpm.util.PatternConstants; @@ -57,6 +56,7 @@ import org.jbpm.workflow.core.Node; import org.jbpm.workflow.core.NodeContainer; import org.jbpm.workflow.core.impl.DataAssociation; +import org.jbpm.workflow.core.impl.DataAssociation.DataAssociationType; import org.jbpm.workflow.core.impl.DataDefinition; import org.jbpm.workflow.core.impl.DroolsConsequenceAction; import org.jbpm.workflow.core.impl.ExtendedNodeImpl; @@ -74,7 +74,6 @@ import org.jbpm.workflow.core.node.StateNode; import org.jbpm.workflow.core.node.TimerNode; import org.jbpm.workflow.core.node.Transformation; -import org.kie.api.runtime.process.DataTransformer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Element; @@ -425,7 +424,10 @@ protected IOSpecification readCatchSpecification(Parser parser, Element element) while (xmlNode != null) { String nodeName = xmlNode.getNodeName(); if ("dataOutputAssociation".equals(nodeName)) { - readDataAssociation((Element) xmlNode, id -> ioSpec.getDataOutput().get(id), id -> getVariableDataSpec(parser, id)).ifPresent(e -> ioSpec.getDataOutputAssociation().add(e)); + readDataAssociation((Element) xmlNode, id -> ioSpec.getDataOutput().get(id), id -> getVariableDataSpec(parser, id)).ifPresent(e -> { + e.setType(DataAssociationType.OUTPUT); + ioSpec.getDataOutputAssociation().add(e); + }); } xmlNode = xmlNode.getNextSibling(); } @@ -440,7 +442,10 @@ protected IOSpecification readThrowSpecification(Parser parser, Element element) while (xmlNode != null) { String nodeName = xmlNode.getNodeName(); if ("dataInputAssociation".equals(nodeName)) { - readDataAssociation((Element) xmlNode, id -> getVariableDataSpec(parser, id), id -> ioSpec.getDataInput().get(id)).ifPresent(e -> ioSpec.getDataInputAssociation().add(e)); + readDataAssociation((Element) xmlNode, id -> getVariableDataSpec(parser, id), id -> ioSpec.getDataInput().get(id)).ifPresent(e -> { + e.setType(DataAssociationType.INPUT); + ioSpec.getDataInputAssociation().add(e); + }); } xmlNode = xmlNode.getNextSibling(); } @@ -457,9 +462,15 @@ protected IOSpecification readIOEspecification(Parser parser, Element element) { ioSpec.getDataInputs().addAll(readDataInput(parser, xmlNode)); ioSpec.getDataOutputs().addAll(readDataOutput(parser, xmlNode)); } else if ("dataInputAssociation".equals(nodeName)) { - readDataAssociation((Element) xmlNode, id -> getVariableDataSpec(parser, id), id -> ioSpec.getDataInput().get(id)).ifPresent(e -> ioSpec.getDataInputAssociation().add(e)); + readDataAssociation((Element) xmlNode, id -> getVariableDataSpec(parser, id), id -> ioSpec.getDataInput().get(id)).ifPresent(e -> { + e.setType(DataAssociationType.INPUT); + ioSpec.getDataInputAssociation().add(e); + }); } else if ("dataOutputAssociation".equals(nodeName)) { - readDataAssociation((Element) xmlNode, id -> ioSpec.getDataOutput().get(id), id -> getVariableDataSpec(parser, id)).ifPresent(e -> ioSpec.getDataOutputAssociation().add(e)); + readDataAssociation((Element) xmlNode, id -> ioSpec.getDataOutput().get(id), id -> getVariableDataSpec(parser, id)).ifPresent(e -> { + e.setType(DataAssociationType.OUTPUT); + ioSpec.getDataOutputAssociation().add(e); + }); } xmlNode = xmlNode.getNextSibling(); } @@ -561,10 +572,6 @@ private Transformation readTransformation(Element parent) { String lang = element.get().getAttribute("language"); String expression = element.get().getTextContent(); - DataTransformer transformer = DataTransformerRegistry.get().find(lang); - if (transformer == null) { - throw new ProcessParsingValidationException("No transformer registered for language " + lang); - } return new Transformation(lang, expression); } diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java index 27595fe2e74..322fd383cf1 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java @@ -24,21 +24,27 @@ import java.util.function.Predicate; import java.util.stream.Collectors; +import org.jbpm.compiler.canonical.builtin.ReturnValueEvaluatorBuilderService; import org.jbpm.process.builder.action.ActionCompilerRegistry; -import org.jbpm.process.builder.transformation.DataTransformerCompilerRegistry; +import org.jbpm.process.core.Context; import org.jbpm.process.core.ContextContainer; +import org.jbpm.process.core.ContextResolver; import org.jbpm.process.core.context.variable.Mappable; import org.jbpm.process.core.context.variable.Variable; import org.jbpm.process.core.context.variable.VariableScope; +import org.jbpm.process.core.datatype.DataTypeResolver; import org.jbpm.process.instance.impl.actions.ProduceEventAction; import org.jbpm.process.instance.impl.actions.SignalProcessInstanceAction; import org.jbpm.ruleflow.core.Metadata; import org.jbpm.ruleflow.core.factory.MappableNodeFactory; +import org.jbpm.util.JbpmClassLoaderUtil; import org.jbpm.workflow.core.impl.ConnectionImpl; import org.jbpm.workflow.core.impl.DataAssociation; +import org.jbpm.workflow.core.impl.DataAssociation.DataAssociationType; import org.jbpm.workflow.core.impl.DataDefinition; import org.jbpm.workflow.core.impl.DroolsConsequenceAction; import org.jbpm.workflow.core.impl.ExtendedNodeImpl; +import org.jbpm.workflow.core.impl.NodeImpl; import org.jbpm.workflow.core.node.Assignment; import org.jbpm.workflow.core.node.HumanTaskNode; import org.jbpm.workflow.core.node.StartNode; @@ -46,6 +52,7 @@ import org.kie.api.definition.process.Connection; import org.kie.api.definition.process.Node; +import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.expr.AssignExpr; @@ -215,24 +222,25 @@ protected Statement makeAssignmentFromModel(Variable v, String name) { protected void addNodeMappings(Mappable node, BlockStmt body, String variableName) { for (DataAssociation entry : node.getInAssociations()) { - body.addStatement(getFactoryMethod(variableName, MappableNodeFactory.METHOD_IN_ASSOCIATION, buildDataAssociationExpression(entry))); + body.addStatement(getFactoryMethod(variableName, MappableNodeFactory.METHOD_IN_ASSOCIATION, buildDataAssociationExpression((NodeImpl) node, entry))); } for (DataAssociation entry : node.getOutAssociations()) { - body.addStatement(getFactoryMethod(variableName, MappableNodeFactory.METHOD_OUT_ASSOCIATION, buildDataAssociationExpression(entry))); + body.addStatement(getFactoryMethod(variableName, MappableNodeFactory.METHOD_OUT_ASSOCIATION, buildDataAssociationExpression((NodeImpl) node, entry))); } } - protected Expression buildDataAssociationsExpression(List dataAssociations) { - NodeList expressions = NodeList.nodeList(dataAssociations.stream().map(this::buildDataAssociationExpression).collect(Collectors.toList())); + protected Expression buildDataAssociationsExpression(NodeImpl node, List dataAssociations) { + NodeList expressions = NodeList.nodeList(dataAssociations.stream().map(da -> buildDataAssociationExpression(node, da)).collect(Collectors.toList())); return new MethodCallExpr(null, "java.util.Arrays.asList", NodeList.nodeList(expressions)); } - protected Expression buildDataAssociationExpression(DataAssociation dataAssociation) { + protected Expression buildDataAssociationExpression(NodeImpl node, DataAssociation dataAssociation) { List sourceExpr = dataAssociation.getSources(); DataDefinition targetExpr = dataAssociation.getTarget(); Transformation transformation = dataAssociation.getTransformation(); List assignments = dataAssociation.getAssignments(); - return toDataAssociation(toDataDef(sourceExpr), toDataDef(targetExpr), toAssignmentExpr(assignments), toTransformation(sourceExpr, singletonList(targetExpr), transformation)); + return toDataAssociation(toDataDef(sourceExpr), toDataDef(targetExpr), toAssignmentExpr(assignments), + toTransformation(node, dataAssociation.getType(), sourceExpr, singletonList(targetExpr), transformation)); } private Expression toAssignmentExpr(List assignments) { @@ -252,16 +260,44 @@ private Expression toAssignmentExpr(List assignments) { return new MethodCallExpr(null, "java.util.Arrays.asList", NodeList.nodeList(expressions)); } - protected Expression toTransformation(List inputs, List outputs, Transformation transformation) { + protected Expression toTransformation(NodeImpl node, DataAssociationType type, List inputs, List outputs, Transformation transformation) { if (transformation == null) { return new NullLiteralExpr(); } + Expression lang = new StringLiteralExpr(transformation.getLanguage()); Expression expression = new StringLiteralExpr(transformation.getExpression()); - Expression compiledExpression = DataTransformerCompilerRegistry.instance().find(transformation.getLanguage()).compile(inputs, outputs, transformation); - ClassOrInterfaceType clazz = new ClassOrInterfaceType(null, "org.jbpm.workflow.core.node.Transformation"); - return new ObjectCreationExpr(null, clazz, NodeList.nodeList(lang, expression, compiledExpression)); + ContextResolver contextResolver = type.equals(DataAssociationType.INPUT) ? node : wrapContextResolver(node, inputs); + + ReturnValueEvaluatorBuilderService service = ReturnValueEvaluatorBuilderService.instance(); + Expression returnValueEvaluatorExpression = service.build(contextResolver, transformation.getLanguage(), transformation.getExpression(), Object.class, null); + ClassOrInterfaceType clazz = StaticJavaParser.parseClassOrInterfaceType(Transformation.class.getName()); + return new ObjectCreationExpr(null, clazz, NodeList.nodeList(lang, expression, returnValueEvaluatorExpression)); + + } + + private ContextResolver wrapContextResolver(NodeImpl node, List variables) { + VariableScope variableScope = new VariableScope(); + + for (DataDefinition variable : variables) { + Variable var = new Variable(); + var.setId(variable.getId()); + var.setName(variable.getLabel()); + var.setType(DataTypeResolver.fromType(variable.getType(), JbpmClassLoaderUtil.findClassLoader())); + variableScope.addVariable(var); + } + return new ContextResolver() { + + @Override + public Context resolveContext(String contextId, Object param) { + if (VariableScope.VARIABLE_SCOPE.equals(contextId)) { + return variableScope.resolveContext(param); + } + return null; + } + + }; } protected Expression toDataAssociation(Expression sourceExprs, Expression target, Expression transformation, Expression assignments) { diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/StartNodeVisitor.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/StartNodeVisitor.java index de5c641a6fe..8be94913cfb 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/StartNodeVisitor.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/StartNodeVisitor.java @@ -84,7 +84,7 @@ protected void handleSignal(StartNode startNode, Map nodeMetaDat body.addStatement(getFactoryMethod(getNodeId(startNode), METHOD_TRIGGER, new StringLiteralExpr((String) nodeMetaData.get(TRIGGER_REF)), - buildDataAssociationsExpression(startNode.getIoSpecification().getDataOutputAssociation()))); + buildDataAssociationsExpression(startNode, startNode.getIoSpecification().getDataOutputAssociation()))); String triggerMapping = (String) nodeMetaData.get(TRIGGER_MAPPING); variable = variableScope.findVariable(triggerMapping); @@ -99,13 +99,13 @@ protected void handleSignal(StartNode startNode, Map nodeMetaDat } else { body.addStatement(getFactoryMethod(getNodeId(startNode), METHOD_TRIGGER, new StringLiteralExpr((String) nodeMetaData.get(MESSAGE_TYPE)), - buildDataAssociationsExpression(startNode.getIoSpecification().getDataOutputAssociation()))); + buildDataAssociationsExpression(startNode, startNode.getIoSpecification().getDataOutputAssociation()))); } metadata.addSignal((String) nodeMetaData.get(MESSAGE_TYPE), variable != null ? variable.getType().getStringType() : null); } else { body.addStatement(getFactoryMethod(getNodeId(startNode), METHOD_TRIGGER, new StringLiteralExpr((String) nodeMetaData.get(TRIGGER_REF)), - buildDataAssociationsExpression(startNode.getIoSpecification().getDataOutputAssociation()))); + buildDataAssociationsExpression(startNode, startNode.getIoSpecification().getDataOutputAssociation()))); } } diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/builtin/JavaConstraintEvaluatorBuilder.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/builtin/JavaConstraintEvaluatorBuilder.java index e6695526cc4..ae82b5fb7ec 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/builtin/JavaConstraintEvaluatorBuilder.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/builtin/JavaConstraintEvaluatorBuilder.java @@ -63,7 +63,6 @@ public Expression build(ContextResolver resolver, String expression, Class ty if (blockStmt == null) { blockStmt = StaticJavaParser.parseBlock("{" + expression + "}"); } - Set identifiers = new HashSet<>(blockStmt.findAll(NameExpr.class)); for (NameExpr v : identifiers) { diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/EventNodeBuilder.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/EventNodeBuilder.java index 57ba54137ed..b5f0aaba9a9 100755 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/EventNodeBuilder.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/EventNodeBuilder.java @@ -22,12 +22,10 @@ import java.util.Map; import org.drools.drl.ast.descr.ProcessDescr; -import org.jbpm.process.core.impl.DataTransformerRegistry; import org.jbpm.workflow.core.WorkflowProcess; import org.jbpm.workflow.core.node.Transformation; import org.kie.api.definition.process.Node; import org.kie.api.definition.process.Process; -import org.kie.api.runtime.process.DataTransformer; public class EventNodeBuilder implements ProcessNodeBuilder { @@ -40,8 +38,6 @@ public void build(Process process, ProcessDescr processDescr, ProcessBuildContex parameters.put("imports", wfProcess.getImports()); parameters.put("classloader", context.getConfiguration().getClassLoader()); - DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage()); - transformation.setCompiledExpression(transformer.compile(transformation.getExpression(), parameters)); } } diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/ExtendedNodeBuilder.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/ExtendedNodeBuilder.java index 64238c7abae..9f86aaea125 100755 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/ExtendedNodeBuilder.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/ExtendedNodeBuilder.java @@ -27,17 +27,14 @@ import org.drools.drl.ast.descr.ProcessDescr; import org.jbpm.process.builder.dialect.ProcessDialect; import org.jbpm.process.builder.dialect.ProcessDialectRegistry; -import org.jbpm.process.core.impl.DataTransformerRegistry; import org.jbpm.workflow.core.DroolsAction; import org.jbpm.workflow.core.impl.DataAssociation; import org.jbpm.workflow.core.impl.DroolsConsequenceAction; import org.jbpm.workflow.core.impl.ExtendedNodeImpl; import org.jbpm.workflow.core.impl.NodeImpl; import org.jbpm.workflow.core.node.Assignment; -import org.jbpm.workflow.core.node.Transformation; import org.kie.api.definition.process.Node; import org.kie.api.definition.process.Process; -import org.kie.api.runtime.process.DataTransformer; public class ExtendedNodeBuilder implements @@ -71,13 +68,6 @@ protected void buildAction(DroolsAction droolsAction, ProcessBuildContext contex protected void buildDataAssociation(PackageBuildContext context, Collection dataAssociations, Map parameters) { for (DataAssociation dataAssociation : dataAssociations) { - Transformation transformation = dataAssociation.getTransformation(); - if (transformation != null) { - - DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage()); - transformation.setCompiledExpression(transformer.compile(transformation.getExpression(), parameters)); - - } List assignments = dataAssociation.getAssignments(); if (assignments != null) { for (Assignment assignment : assignments) { diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompiler.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompiler.java deleted file mode 100644 index 0e85a0b0b0a..00000000000 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompiler.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.process.builder.transformation; - -import java.util.List; - -import org.jbpm.workflow.core.impl.DataDefinition; -import org.jbpm.workflow.core.node.Transformation; - -import com.github.javaparser.ast.expr.Expression; - -public interface DataTransformerCompiler { - - default String[] dialects() { - return new String[0]; - } - - default boolean accept(String dialect) { - return List.of(dialects()).contains(dialect); - } - - Expression compile(List inputs, List outputs, Transformation source); -} diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompilerRegistry.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompilerRegistry.java deleted file mode 100755 index 54f506da76e..00000000000 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompilerRegistry.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.process.builder.transformation; - -import java.util.ArrayList; -import java.util.List; -import java.util.ServiceLoader; - -import org.jbpm.util.JbpmClassLoaderUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Registry for all available on runtime DataTransformers for performing - * data input and output transformation. - * There is MVEL based transformer available out of the box that is registered under - * http://www.mvel.org/2.0 key. - *
- * Custom implementations can be provided and if they are compliant with JSR 223 then follows above registration approach - * otherwise they need to be registered manually with register method. - * - */ -public class DataTransformerCompilerRegistry { - - private static final Logger logger = LoggerFactory.getLogger(DataTransformerCompilerRegistry.class); - - private static DataTransformerCompilerRegistry INSTANCE; - - private List registry; - - public static DataTransformerCompilerRegistry instance() { - if (INSTANCE == null) { - INSTANCE = new DataTransformerCompilerRegistry(); - } - return INSTANCE; - } - - protected DataTransformerCompilerRegistry() { - this.registry = new ArrayList<>(); - ServiceLoader.load(DataTransformerCompiler.class, JbpmClassLoaderUtil.findClassLoader()).forEach(registry::add); - } - - public void register(DataTransformerCompiler transformer) { - this.registry.add(transformer); - logger.debug("Manual registration of scripting language {} with instance {}", transformer.dialects(), transformer); - } - - public DataTransformerCompiler find(String language) { - for (DataTransformerCompiler transformer : registry) { - if (transformer.accept(language)) { - return transformer; - } - } - throw new IllegalArgumentException("transformer not support for dialect " + language); - } -} diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DefaultDataTransformerCompiler.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DefaultDataTransformerCompiler.java deleted file mode 100644 index 377076b3466..00000000000 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DefaultDataTransformerCompiler.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.process.builder.transformation; - -import java.util.Collections; -import java.util.List; - -import org.jbpm.process.core.impl.DataTransformerRegistry; -import org.jbpm.workflow.core.impl.DataDefinition; -import org.jbpm.workflow.core.node.Transformation; -import org.kie.kogito.internal.utils.ConversionUtils; - -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.FieldAccessExpr; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; - -public class DefaultDataTransformerCompiler implements DataTransformerCompiler { - - @Override - public String[] dialects() { - return new String[] { "http://www.mvel.org/2.0" }; - } - - @Override - public Expression compile(List inputs, List outputs, Transformation transformation) { - Expression expr = null; - expr = new FieldAccessExpr(new NameExpr(DataTransformerRegistry.class.getPackageName()), DataTransformerRegistry.class.getSimpleName()); - expr = new MethodCallExpr(expr, "get"); - expr = new MethodCallExpr(expr, "find", NodeList.nodeList(new StringLiteralExpr(transformation.getLanguage()))); - - Expression emptyCollection = new MethodCallExpr(new FieldAccessExpr(new NameExpr(Collections.class.getPackageName()), Collections.class.getSimpleName()), "emptyMap"); - - expr = new MethodCallExpr(expr, "compile", NodeList. nodeList( - new StringLiteralExpr(ConversionUtils.sanitizeString(transformation.getExpression())), emptyCollection)); - return expr; - } - -} diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/JavaDataTransformerCompiler.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/JavaDataTransformerCompiler.java deleted file mode 100644 index b45140519b4..00000000000 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/JavaDataTransformerCompiler.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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.process.builder.transformation; - -import java.util.List; - -import org.jbpm.workflow.core.impl.DataDefinition; -import org.jbpm.workflow.core.node.Transformation; - -import com.github.javaparser.ParseProblemException; -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.expr.AssignExpr; -import com.github.javaparser.ast.expr.CastExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.LambdaExpr; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; -import com.github.javaparser.ast.expr.VariableDeclarationExpr; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.ReturnStmt; -import com.github.javaparser.ast.type.ClassOrInterfaceType; - -public class JavaDataTransformerCompiler implements DataTransformerCompiler { - - @Override - public String[] dialects() { - return new String[] { "http://www.java.com/java" }; - } - - @Override - public Expression compile(List inputs, List outputs, Transformation transformation) { - // build lambda function - String expression = transformation.getExpression(); - BlockStmt body = parseExpression(expression); - - if (body == null) { - body = parseStatement(expression); - } - - if (body == null) { - body = StaticJavaParser.parseBlock("{" + expression + "}"); - } - - for (DataDefinition input : inputs) { - ClassOrInterfaceType type = StaticJavaParser.parseClassOrInterfaceType(input.getType()); - VariableDeclarationExpr target = new VariableDeclarationExpr(type, input.getLabel()); - Expression source = new CastExpr(type, new MethodCallExpr(new NameExpr("parameters"), "get", NodeList.nodeList(new StringLiteralExpr(input.getLabel())))); - AssignExpr assignment = new AssignExpr(target, source, AssignExpr.Operator.ASSIGN); - body.addStatement(0, assignment); - } - - Expression lambda = new LambdaExpr(NodeList.nodeList(new Parameter(StaticJavaParser.parseClassOrInterfaceType("java.util.Map"), "parameters")), body, true); - ClassOrInterfaceType type = StaticJavaParser.parseClassOrInterfaceType("java.util.function.Function, Object>"); - return new CastExpr(type, lambda); - } - - private BlockStmt parseStatement(String expression) { - try { - BlockStmt block = new BlockStmt(); - block.addStatement(StaticJavaParser.parseStatement(expression)); - return block; - } catch (ParseProblemException e) { - return null; - } - } - - private BlockStmt parseExpression(String expression) { - try { - BlockStmt block = new BlockStmt(); - block.addStatement(new ReturnStmt(StaticJavaParser.parseExpression(expression))); - return block; - } catch (ParseProblemException e) { - return null; - } - } -} diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/impl/DataTransformerRegistry.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/impl/DataTransformerRegistry.java deleted file mode 100755 index 5cd596786e4..00000000000 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/impl/DataTransformerRegistry.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.process.core.impl; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.jbpm.process.core.transformation.JavaDataTransformer; -import org.jbpm.process.core.transformation.MVELDataTransformer; -import org.kie.api.runtime.process.DataTransformer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Registry for all available on runtime DataTransformers for performing - * data input and output transformation. - * There is MVEL based transformer available out of the box that is registered under - * http://www.mvel.org/2.0 key. - *
- * Custom implementations can be provided and if they are compliant with JSR 223 then follows above registration approach - * otherwise they need to be registered manually with register method. - * - */ -public class DataTransformerRegistry { - - private static final Logger logger = LoggerFactory.getLogger(DataTransformerRegistry.class); - private static final DataTransformerRegistry INSTANCE = new DataTransformerRegistry(); - - private Map registry; - - protected DataTransformerRegistry() { - this.registry = new ConcurrentHashMap<>(); - this.registry.put("http://www.mvel.org/2.0", new MVELDataTransformer()); - this.registry.put("http://www.java.com/java", new JavaDataTransformer()); - } - - public static DataTransformerRegistry get() { - return INSTANCE; - } - - public synchronized void register(String language, DataTransformer transformer) { - this.registry.put(language, transformer); - logger.debug("Manual registration of scripting language {} with instance {}", language, transformer); - } - - public DataTransformer find(String language) { - return this.registry.get(language); - } -} diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/JavaDataTransformer.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/JavaDataTransformer.java deleted file mode 100644 index daefaf43cc9..00000000000 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/JavaDataTransformer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.process.core.transformation; - -import java.util.Map; -import java.util.function.Function; - -import org.kie.api.runtime.process.DataTransformer; - -public class JavaDataTransformer implements DataTransformer { - - @Override - public Object compile(String expression, Map parameters) { - return null; - } - - @SuppressWarnings("unchecked") - @Override - public Object transform(Object expression, Map parameters) { - return ((Function, Object>) expression).apply(parameters); - } - -} diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/MVELDataTransformer.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/MVELDataTransformer.java deleted file mode 100755 index b884e9babcf..00000000000 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/MVELDataTransformer.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.process.core.transformation; - -import java.util.Map; -import java.util.Set; - -import org.jbpm.workflow.instance.impl.MVELProcessHelper; -import org.kie.api.runtime.process.DataTransformer; -import org.mvel2.MVEL; -import org.mvel2.ParserConfiguration; -import org.mvel2.ParserContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * MVEL based DataTransformer implementation - * - */ -public class MVELDataTransformer implements DataTransformer { - - private static final Logger logger = LoggerFactory.getLogger(MVELDataTransformer.class); - - @Override - public Object compile(String expression, Map parameters) { - logger.debug("About to compile mvel expression {}", expression); - ClassLoader classLoader = (ClassLoader) parameters.get("classloader"); - if (classLoader == null) { - classLoader = this.getClass().getClassLoader(); - } - ParserConfiguration config = new ParserConfiguration(); - config.setClassLoader(classLoader); - ParserContext context = new ParserContext(config); - if (parameters != null) { - @SuppressWarnings("unchecked") - Set imports = (Set) parameters.get("imports"); - if (imports != null) { - for (String clazz : imports) { - try { - Class cl = Class.forName(clazz, true, classLoader); - context.addImport(cl.getSimpleName(), cl); - } catch (ClassNotFoundException e) { - logger.warn("Unable to load class {} due to {}", clazz, e.getException()); - } - ; - } - } - } - return MVEL.compileExpression(expression, context); - } - - @Override - public Object transform(Object expression, Map parameters) { - logger.debug("About to execute mvel expression {} with parameters {}", expression, parameters); - return MVELProcessHelper.evaluator().executeExpression(expression, parameters); - } - -} diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/DataAssociation.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/DataAssociation.java index 2d2dc86fd4c..468115c508b 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/DataAssociation.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/DataAssociation.java @@ -29,12 +29,18 @@ public class DataAssociation implements Serializable { + public enum DataAssociationType { + INPUT, + OUTPUT + } + private static final long serialVersionUID = 5L; private List sources; private DataDefinition target; private List assignments; private Transformation transformation; + private DataAssociationType type; public DataAssociation(Assignment assignment) { this(Collections.emptyList(), null, Collections.singletonList(assignment), null); @@ -49,6 +55,14 @@ public DataAssociation(List sources, DataDefinition target, this.assignments.forEach(this::buildInterpretedAssignment); } + public DataAssociationType getType() { + return type; + } + + public void setType(DataAssociationType type) { + this.type = type; + } + private Assignment buildInterpretedAssignment(Assignment assignment) { if (assignment.getDialect() != null) { return assignment; diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/NodeIoHelper.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/NodeIoHelper.java index f4d800fc7c4..5eaa8f0d982 100644 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/NodeIoHelper.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/NodeIoHelper.java @@ -25,14 +25,12 @@ import java.util.Map; import java.util.function.Function; -import org.jbpm.process.core.impl.DataTransformerRegistry; import org.jbpm.process.instance.KogitoProcessContextImpl; import org.jbpm.process.instance.impl.AssignmentAction; import org.jbpm.process.instance.impl.AssignmentProducer; import org.jbpm.workflow.core.node.Assignment; import org.jbpm.workflow.core.node.Transformation; import org.jbpm.workflow.instance.impl.NodeInstanceImpl; -import org.kie.api.runtime.process.DataTransformer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -84,10 +82,9 @@ private void processDataAssociation( try { if (mapping.getTransformation() != null) { Transformation transformation = mapping.getTransformation(); - DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage()); Object parameterValue = null; - if (transformer != null) { - parameterValue = transformer.transform(transformation.getCompiledExpression(), dataSet); + if (transformation != null) { + parameterValue = transformation.getCompiledExpression().eval(var -> dataSet.get(var)); } if (parameterValue != null) { producer.accept(mapping.getTarget().getLabel(), parameterValue); diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/Transformation.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/Transformation.java index 97533ec90a0..a5e7491c6c8 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/Transformation.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/Transformation.java @@ -20,19 +20,21 @@ import java.io.Serializable; +import org.jbpm.process.instance.impl.ReturnValueEvaluator; + public class Transformation implements Serializable { private static final long serialVersionUID = 1641905060375832661L; private String language; private String expression; - private Object compiledExpression; + private ReturnValueEvaluator compiledExpression; public Transformation(String lang, String expression) { this(lang, expression, null); } - public Transformation(String lang, String expression, Object compiledExpression) { + public Transformation(String lang, String expression, ReturnValueEvaluator compiledExpression) { this.language = lang; this.expression = expression; this.compiledExpression = compiledExpression; @@ -54,11 +56,11 @@ public void setExpression(String expression) { this.expression = expression; } - public Object getCompiledExpression() { + public ReturnValueEvaluator getCompiledExpression() { return compiledExpression; } - public void setCompiledExpression(Object compliedExpression) { + public void setCompiledExpression(ReturnValueEvaluator compliedExpression) { this.compiledExpression = compliedExpression; } diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java index bec42d08252..a053f6c83cf 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java @@ -98,7 +98,6 @@ import org.jbpm.process.builder.dialect.ProcessDialect; import org.jbpm.process.builder.dialect.ProcessDialectRegistry; import org.jbpm.process.core.context.variable.VariableScope; -import org.jbpm.process.core.impl.DataTransformerRegistry; import org.jbpm.process.instance.event.listeners.RuleAwareProcessEventListener; import org.jbpm.process.instance.event.listeners.TriggerRulesEventListener; import org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler; @@ -134,7 +133,6 @@ import org.kie.api.event.rule.BeforeMatchFiredEvent; import org.kie.api.event.rule.MatchCancelledEvent; import org.kie.api.event.rule.MatchCreatedEvent; -import org.kie.api.runtime.process.DataTransformer; import org.kie.api.runtime.process.NodeInstance; import org.kie.kogito.Application; import org.kie.kogito.auth.SecurityPolicy; @@ -845,50 +843,6 @@ public void testServiceTaskWithMvelTransformation() throws Exception { assertThat(processInstance.getVariable("s")).isEqualTo("hello john!"); } - @Test - public void testServiceTaskWithCustomTransformation() throws Exception { - DataTransformerRegistry.get().register("http://custom/transformer", new DataTransformer() { - - @Override - public Object transform(Object expression, Map parameters) { - // support only single object - String value = parameters.values().iterator().next().toString(); - Object result = null; - if ("caplitalizeFirst".equals(expression)) { - String first = value.substring(0, 1); - String main = value.substring(1, value.length()); - - result = first.toUpperCase() + main; - } else if ("caplitalizeLast".equals(expression)) { - String last = value.substring(value.length() - 1); - String main = value.substring(0, value.length() - 1); - - result = main + last.toUpperCase(); - } else { - throw new IllegalArgumentException("Unknown expression " + expression); - } - return result; - } - - @Override - public Object compile(String expression, Map parameters) { - // compilation not supported - return expression; - } - }); - kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcessWithCustomTransformation.bpmn2"); - - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", - new ServiceTaskHandler()); - Map params = new HashMap<>(); - params.put("s", "john doe"); - - KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime - .startProcess("ServiceProcess", params); - assertProcessInstanceFinished(processInstance, kruntime); - assertThat(processInstance.getVariable("s")).isEqualTo("John doE"); - } - @Test public void testServiceTaskNoInterfaceName() throws Exception { kruntime = createKogitoProcessRuntime("BPMN2-ServiceTask-web-service.bpmn2"); From 628f2989b382f1f702c099b364a2157187955317 Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Martinez Date: Wed, 5 Jun 2024 11:32:07 +0200 Subject: [PATCH 4/9] fix producer and consumers --- .../xml/IntermediateThrowEventHandler.java | 9 ++++ .../java/org/jbpm/ruleflow/core/Metadata.java | 1 + .../maven/ProcessCodeGenerationSupport.java | 43 +++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/IntermediateThrowEventHandler.java b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/IntermediateThrowEventHandler.java index 033076b8abb..5086c71990d 100755 --- a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/IntermediateThrowEventHandler.java +++ b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/IntermediateThrowEventHandler.java @@ -49,7 +49,11 @@ import static org.jbpm.bpmn2.xml.ProcessHandler.createJavaAction; import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_COMPENSATION; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_ESCALATION; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_LINK; import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_MESSAGE; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_SIGNAL; import static org.jbpm.ruleflow.core.Metadata.MAPPING_VARIABLE; import static org.jbpm.ruleflow.core.Metadata.MAPPING_VARIABLE_INPUT; import static org.jbpm.ruleflow.core.Metadata.MESSAGE_TYPE; @@ -87,21 +91,25 @@ protected Node handleNode(Node newNode, Element element, String uri, String loca // reuse already created ActionNode setThrowVariable(ioSpecification, node); handleSignalNode(node, element, uri, localName, parser); + node.setMetaData(EVENT_TYPE, EVENT_TYPE_SIGNAL); break; } else if ("messageEventDefinition".equals(nodeName)) { // reuse already created ActionNode setThrowVariable(ioSpecification, node); handleMessageNode(node, element, uri, localName, parser); + node.setMetaData(EVENT_TYPE, EVENT_TYPE_MESSAGE); break; } else if ("escalationEventDefinition".equals(nodeName)) { // reuse already created ActionNode setThrowVariable(ioSpecification, node); handleEscalationNode(node, element, uri, localName, parser); + node.setMetaData(EVENT_TYPE, EVENT_TYPE_ESCALATION); break; } else if ("compensateEventDefinition".equals(nodeName)) { // reuse already created ActionNode setThrowVariable(ioSpecification, node); handleThrowCompensationEventNode(node, element, uri, localName, parser); + node.setMetaData(EVENT_TYPE, EVENT_TYPE_COMPENSATION); break; } else if ("linkEventDefinition".equals(nodeName)) { ThrowLinkNode linkNode = new ThrowLinkNode(); @@ -109,6 +117,7 @@ protected Node handleNode(Node newNode, Element element, String uri, String loca node = linkNode; setThrowVariable(ioSpecification, node); handleLinkNode(element, node, xmlNode, parser); + node.setMetaData(EVENT_TYPE, EVENT_TYPE_LINK); } xmlNode = xmlNode.getNextSibling(); } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/Metadata.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/Metadata.java index 5b9f6a14286..682fbdc064d 100644 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/Metadata.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/Metadata.java @@ -44,6 +44,7 @@ public class Metadata { public static final String EVENT_TYPE_ERROR = "error"; public static final String EVENT_TYPE_CONDITIONAL = "conditional"; public static final String EVENT_TYPE_LINK = "link"; + public static final Object EVENT_TYPE_ESCALATION = "Escalation"; public static final String CUSTOM_SCOPE = "customScope"; public static final String ATTACHED_TO = "AttachedTo"; public static final String TIME_CYCLE = "TimeCycle"; diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/main/java/org/jbpm/tools/maven/ProcessCodeGenerationSupport.java b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/main/java/org/jbpm/tools/maven/ProcessCodeGenerationSupport.java index 6988db18b30..b700115833d 100644 --- a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/main/java/org/jbpm/tools/maven/ProcessCodeGenerationSupport.java +++ b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/main/java/org/jbpm/tools/maven/ProcessCodeGenerationSupport.java @@ -37,6 +37,7 @@ import org.jbpm.compiler.canonical.ProcessMetaData; import org.jbpm.compiler.canonical.ProcessToExecModelGenerator; import org.jbpm.compiler.canonical.TemplateHelper; +import org.jbpm.compiler.canonical.TriggerMetaData; import org.jbpm.compiler.xml.XmlProcessReader; import org.jbpm.compiler.xml.core.SemanticModules; import org.jbpm.ruleflow.core.RuleFlowProcess; @@ -50,9 +51,16 @@ import com.github.javaparser.ast.PackageDeclaration; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.expr.AssignExpr; +import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.ast.expr.ThisExpr; import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.printer.DefaultPrettyPrinter; import com.github.javaparser.printer.Printer; @@ -148,6 +156,7 @@ private void generateJavaCode(KogitoWorkflowProcess process) throws IOException // process CompilationUnit processUnit = metadata.getGeneratedClassModel(); + addMembers(metadata, processUnit); RuleFlowProcess ruleFlowProcess = (RuleFlowProcess) process; for (String importClass : ruleFlowProcess.getImports()) { @@ -232,4 +241,38 @@ private void writeCompilationUnit(CompilationUnit unit) throws IOException { LOG.debug("{} generated", modelType.getNameAsString()); Files.write(Paths.get(outputFolder.toString(), modelType.getName().asString() + ".java"), modelSource.getBytes()); } + + private void addMembers(ProcessMetaData processMetaData, CompilationUnit compilationUnit) { + ClassOrInterfaceDeclaration cls = compilationUnit.findFirst(ClassOrInterfaceDeclaration.class).get(); + if (!processMetaData.getTriggers().isEmpty()) { + + for (TriggerMetaData trigger : processMetaData.getTriggers()) { + // add message produces as field + if (trigger.getType().equals(TriggerMetaData.TriggerType.ProduceMessage)) { + ClassOrInterfaceType type = StaticJavaParser.parseClassOrInterfaceType(org.kie.kogito.event.impl.MessageProducer.class.getName() + "<" + trigger.getDataType() + ">"); + String producerFieldName = "producer_" + trigger.getOwnerId(); + String producerFieldNameCapitalized = "Producer_" + trigger.getOwnerId(); + + FieldDeclaration producerFieldDeclaration = new FieldDeclaration() + .addVariable(new VariableDeclarator(type, producerFieldName)); + cls.addMember(producerFieldDeclaration); + + MethodDeclaration setMethod = new MethodDeclaration(); + setMethod.addParameter(type, producerFieldName); + setMethod.setName("set" + producerFieldNameCapitalized); + setMethod.setType(StaticJavaParser.parseType("void")); + AssignExpr assignExpr = new AssignExpr( + new FieldAccessExpr(new ThisExpr(), producerFieldName), + new NameExpr(producerFieldName), + AssignExpr.Operator.ASSIGN); + + BlockStmt body = new BlockStmt(); + body.addStatement(assignExpr); + setMethod.setBody(body); + + cls.addMember(setMethod); + } + } + } + } } From a29ab2111a7ca623f65e7297183170b25492c094 Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Martinez Date: Thu, 6 Jun 2024 09:32:06 +0200 Subject: [PATCH 5/9] moving transformations --- .../java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java | 9 ++++++++- .../process/instance/impl/XPATHReturnValueEvaluator.java | 2 +- ...-ServiceProcessWithMvelCollectionTransformation.bpmn2 | 2 +- .../BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 | 2 +- .../BPMN2-ServiceProcessWithMvelTransformation.bpmn2 | 2 +- .../start}/BPMN2-SignalStartWithTransformation.bpmn2 | 2 +- 6 files changed, 13 insertions(+), 6 deletions(-) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/service}/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 (97%) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/service}/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 (97%) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/service}/BPMN2-ServiceProcessWithMvelTransformation.bpmn2 (97%) rename jbpm/jbpm-tests/src/test/{resources => bpmn/org/jbpm/bpmn2/start}/BPMN2-SignalStartWithTransformation.bpmn2 (95%) diff --git a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java index 9ccdd9f0c04..cfbd83e0fba 100755 --- a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java +++ b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java @@ -39,6 +39,7 @@ import org.jbpm.bpmn2.core.Lane; import org.jbpm.bpmn2.core.SequenceFlow; import org.jbpm.bpmn2.core.Signal; +import org.jbpm.compiler.canonical.builtin.ReturnValueEvaluatorBuilderService; import org.jbpm.compiler.xml.Handler; import org.jbpm.compiler.xml.Parser; import org.jbpm.compiler.xml.ProcessBuildData; @@ -49,6 +50,8 @@ import org.jbpm.process.core.context.variable.Variable; import org.jbpm.process.core.context.variable.VariableScope; import org.jbpm.process.core.datatype.DataTypeResolver; +import org.jbpm.process.instance.impl.MVELInterpretedReturnValueEvaluator; +import org.jbpm.process.instance.impl.ReturnValueEvaluator; import org.jbpm.ruleflow.core.RuleFlowProcess; import org.jbpm.ruleflow.core.WorkflowElementIdentifierFactory; import org.jbpm.util.PatternConstants; @@ -572,7 +575,11 @@ private Transformation readTransformation(Element parent) { String lang = element.get().getAttribute("language"); String expression = element.get().getTextContent(); - return new Transformation(lang, expression); + ReturnValueEvaluator evaluator = null; + if (lang.toLowerCase().contains("mvel")) { + evaluator = new MVELInterpretedReturnValueEvaluator(expression); + } + return new Transformation(lang, expression, evaluator); } protected List readSources(org.w3c.dom.Node parent, Function variableResolver) { diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/XPATHReturnValueEvaluator.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/XPATHReturnValueEvaluator.java index 3c9fa372d66..8abd66e6265 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/XPATHReturnValueEvaluator.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/XPATHReturnValueEvaluator.java @@ -42,7 +42,7 @@ public XPATHReturnValueEvaluator() { super("XPath", "true()"); } - public XPATHReturnValueEvaluator(final String expression) { + public XPATHReturnValueEvaluator(String expression) { super("XPath", expression); } diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 index 69cbf479adf..ac0471bd5f3 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 @@ -41,7 +41,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 index 35c7edd85cc..774c3daabd8 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 @@ -40,7 +40,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelTransformation.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelTransformation.bpmn2 index 2b1a8c1ca66..217d34edbfc 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelTransformation.bpmn2 @@ -40,7 +40,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-SignalStartWithTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/start/BPMN2-SignalStartWithTransformation.bpmn2 similarity index 95% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-SignalStartWithTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/start/BPMN2-SignalStartWithTransformation.bpmn2 index 73f8ff10dd3..92060fb056d 100644 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-SignalStartWithTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/start/BPMN2-SignalStartWithTransformation.bpmn2 @@ -32,7 +32,7 @@ - + From 0feb17d5a5e1d22fec571710e920d242ab648bb8 Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Martinez Date: Mon, 10 Jun 2024 16:42:27 +0200 Subject: [PATCH 6/9] fix miscelanea stuff --- .../jbpm/bpmn2/xml/AbstractNodeHandler.java | 1 - .../canonical/AbstractNodeVisitor.java | 4 +- .../MVELInterpretedReturnValueEvaluator.java | 4 +- .../impl/actions/ProduceEventAction.java | 6 +- .../java/org/jbpm/bpmn2/objects/Account.java | 0 .../java/org/jbpm/bpmn2/objects/Address.java | 0 .../objects/ExceptionOnPurposeHandler.java | 0 .../jbpm/bpmn2/objects/ExceptionService.java | 0 .../org/jbpm/bpmn2/objects/HelloService.java | 0 .../java/org/jbpm/bpmn2/objects/MyError.java | 0 .../objects/NotAvailableGoodsReport.java | 0 .../java/org/jbpm/bpmn2/objects/Order.java | 0 .../java/org/jbpm/bpmn2/objects/Person.java | 0 .../java/org/jbpm/bpmn2/objects/Status.java | 0 .../bpmn2/objects/TestWorkItemHandler.java | 0 ...iateCatchEventTimerDurationWithError.bpmn2 | 4 +- ...cessWithMvelCollectionTransformation.bpmn2 | 6 +- ...iceProcessWithMvelJaxbTransformation.bpmn2 | 24 +- .../java/org/jbpm/bpmn2/ActivityTest.java | 79 ++--- .../org/jbpm/bpmn2/IntermediateEventTest.java | 274 +++++++++++++----- .../jbpm/bpmn2/StandaloneBPMNProcessTest.java | 17 +- .../java/org/jbpm/bpmn2/StartEventTest.java | 29 +- .../maven/ProcessCodeGenerationSupport.java | 2 + 23 files changed, 304 insertions(+), 146 deletions(-) rename jbpm/jbpm-tests/src/{test => main}/java/org/jbpm/bpmn2/objects/Account.java (100%) rename jbpm/jbpm-tests/src/{test => main}/java/org/jbpm/bpmn2/objects/Address.java (100%) rename jbpm/jbpm-tests/src/{test => main}/java/org/jbpm/bpmn2/objects/ExceptionOnPurposeHandler.java (100%) rename jbpm/jbpm-tests/src/{test => main}/java/org/jbpm/bpmn2/objects/ExceptionService.java (100%) rename jbpm/jbpm-tests/src/{test => main}/java/org/jbpm/bpmn2/objects/HelloService.java (100%) rename jbpm/jbpm-tests/src/{test => main}/java/org/jbpm/bpmn2/objects/MyError.java (100%) rename jbpm/jbpm-tests/src/{test => main}/java/org/jbpm/bpmn2/objects/NotAvailableGoodsReport.java (100%) rename jbpm/jbpm-tests/src/{test => main}/java/org/jbpm/bpmn2/objects/Order.java (100%) rename jbpm/jbpm-tests/src/{test => main}/java/org/jbpm/bpmn2/objects/Person.java (100%) rename jbpm/jbpm-tests/src/{test => main}/java/org/jbpm/bpmn2/objects/Status.java (100%) rename jbpm/jbpm-tests/src/{test => main}/java/org/jbpm/bpmn2/objects/TestWorkItemHandler.java (100%) diff --git a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java index cfbd83e0fba..e8429c2272c 100755 --- a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java +++ b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java @@ -39,7 +39,6 @@ import org.jbpm.bpmn2.core.Lane; import org.jbpm.bpmn2.core.SequenceFlow; import org.jbpm.bpmn2.core.Signal; -import org.jbpm.compiler.canonical.builtin.ReturnValueEvaluatorBuilderService; import org.jbpm.compiler.xml.Handler; import org.jbpm.compiler.xml.Parser; import org.jbpm.compiler.xml.ProcessBuildData; diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java index 322fd383cf1..59c7acfcede 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java @@ -266,7 +266,7 @@ protected Expression toTransformation(NodeImpl node, DataAssociationType type, L } Expression lang = new StringLiteralExpr(transformation.getLanguage()); - Expression expression = new StringLiteralExpr(transformation.getExpression()); + Expression expression = new StringLiteralExpr(sanitizeString(transformation.getExpression())); ContextResolver contextResolver = type.equals(DataAssociationType.INPUT) ? node : wrapContextResolver(node, inputs); @@ -396,7 +396,7 @@ public static LambdaExpr buildCompensationLambdaExpr(String compensationRef) { } protected ObjectCreationExpr buildProducerAction(Node node, ProcessMetaData metadata) { - TriggerMetaData trigger = TriggerMetaData.of(node); + TriggerMetaData trigger = TriggerMetaData.of(node, (String) node.getMetaData().get(Metadata.MAPPING_VARIABLE_INPUT)); return buildProducerAction(parseClassOrInterfaceType(ProduceEventAction.class.getCanonicalName()).setTypeArguments(NodeList.nodeList(parseClassOrInterfaceType(trigger.getDataType()))), trigger, metadata); diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/MVELInterpretedReturnValueEvaluator.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/MVELInterpretedReturnValueEvaluator.java index 5a969fbb5b0..0ca4c8fbd1f 100644 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/MVELInterpretedReturnValueEvaluator.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/MVELInterpretedReturnValueEvaluator.java @@ -45,12 +45,12 @@ public Object eval(Function resolver) { @Override public boolean isResolveable(String name) { - return resolver.apply("#{" + name + "}") != null; + return resolver.apply(name) != null; }; @Override public VariableResolver getVariableResolver(String name) { - return new SimpleValueResolver(resolver.apply("#{" + name + "}")); + return new SimpleValueResolver(resolver.apply(name)); }; }; return MVEL.eval(expression, factory); diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/actions/ProduceEventAction.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/actions/ProduceEventAction.java index 61c38c3c76d..c9f9c3c385e 100644 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/actions/ProduceEventAction.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/actions/ProduceEventAction.java @@ -19,11 +19,14 @@ package org.jbpm.process.instance.impl.actions; import java.io.Serializable; +import java.util.Map; import java.util.function.Supplier; import org.drools.core.common.InternalKnowledgeRuntime; import org.jbpm.process.instance.InternalProcessRuntime; import org.jbpm.process.instance.impl.Action; +import org.jbpm.workflow.core.impl.NodeIoHelper; +import org.jbpm.workflow.instance.impl.NodeInstanceImpl; import org.kie.kogito.event.impl.MessageProducer; import org.kie.kogito.internal.process.runtime.KogitoProcessContext; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; @@ -44,7 +47,8 @@ public ProduceEventAction(String triggerName, String varName, Supplier inputs = NodeIoHelper.processInputs((NodeInstanceImpl) context.getNodeInstance(), var -> context.getVariable(var)); + Object object = inputs.get(varName); KogitoProcessInstance pi = context.getProcessInstance(); InternalKnowledgeRuntime runtime = (InternalKnowledgeRuntime) context.getKieRuntime(); InternalProcessRuntime process = (InternalProcessRuntime) runtime.getProcessRuntime(); diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Account.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Account.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Account.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Account.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Address.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Address.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Address.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Address.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/ExceptionOnPurposeHandler.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/ExceptionOnPurposeHandler.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/ExceptionOnPurposeHandler.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/ExceptionOnPurposeHandler.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/ExceptionService.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/ExceptionService.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/ExceptionService.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/ExceptionService.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/HelloService.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/HelloService.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/HelloService.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/HelloService.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/MyError.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/MyError.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/MyError.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/MyError.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/NotAvailableGoodsReport.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/NotAvailableGoodsReport.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/NotAvailableGoodsReport.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/NotAvailableGoodsReport.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Order.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Order.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Order.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Order.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Person.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Person.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Person.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Person.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Status.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Status.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Status.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Status.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/TestWorkItemHandler.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/TestWorkItemHandler.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/TestWorkItemHandler.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/TestWorkItemHandler.java diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 index 67dc6a805ce..bfa38763db8 100755 --- a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 @@ -40,8 +40,8 @@ _3-_4 _4-_5 - kcontext.getKieRuntime().getGlobal("TestOK").toString(); - + kcontext.setVariable("TestOK", Boolean.TRUE); + _4-_5 diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 index ac0471bd5f3..b6d1225cdab 100755 --- a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 @@ -53,8 +53,8 @@ - - + + _2_param @@ -70,7 +70,7 @@ _2_result list - Arrays.asList(Result.split(",")) + java.util.Arrays.asList(Result.split(",")) diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 index 774c3daabd8..3cbf0c31538 100755 --- a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 @@ -56,7 +56,7 @@ - + _2_param @@ -67,18 +67,28 @@ s _2_param - + JAXBContext.newInstance(Person.class, Address.class).createMarshaller().marshal(s, result); + return result.toString(); + } catch(Throwable th) { + throw new RuntimeException(th); + } + ]]> _2_result s - + diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java index a053f6c83cf..3e30b3cd187 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java @@ -62,6 +62,12 @@ import org.jbpm.bpmn2.objects.HelloService; import org.jbpm.bpmn2.objects.Person; import org.jbpm.bpmn2.objects.TestWorkItemHandler; +import org.jbpm.bpmn2.service.ServiceProcessWithMvelCollectionTransformationModel; +import org.jbpm.bpmn2.service.ServiceProcessWithMvelCollectionTransformationProcess; +import org.jbpm.bpmn2.service.ServiceProcessWithMvelJaxbTransformationModel; +import org.jbpm.bpmn2.service.ServiceProcessWithMvelJaxbTransformationProcess; +import org.jbpm.bpmn2.service.ServiceProcessWithMvelTransformationModel; +import org.jbpm.bpmn2.service.ServiceProcessWithMvelTransformationProcess; import org.jbpm.bpmn2.subprocess.AssignmentProcessModel; import org.jbpm.bpmn2.subprocess.AssignmentProcessProcess; import org.jbpm.bpmn2.subprocess.AssignmentSubProcessModel; @@ -136,6 +142,8 @@ import org.kie.api.runtime.process.NodeInstance; import org.kie.kogito.Application; import org.kie.kogito.auth.SecurityPolicy; +import org.kie.kogito.handlers.HelloService_hello__2_Handler; +import org.kie.kogito.handlers.HelloService_validate__2_Handler; import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener; import org.kie.kogito.internal.process.runtime.KogitoNode; import org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer; @@ -829,20 +837,6 @@ public void executeWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkIt assertThat(processInstance.getVariable("s")).isEqualTo("Hello john!"); } - @Test - public void testServiceTaskWithMvelTransformation() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcessWithMvelTransformation.bpmn2"); - - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", - new ServiceTaskHandler()); - Map params = new HashMap<>(); - params.put("s", "JoHn"); - KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime - .startProcess("ServiceProcessWithMvelTransformation", params); - assertProcessInstanceFinished(processInstance, kruntime); - assertThat(processInstance.getVariable("s")).isEqualTo("hello john!"); - } - @Test public void testServiceTaskNoInterfaceName() throws Exception { kruntime = createKogitoProcessRuntime("BPMN2-ServiceTask-web-service.bpmn2"); @@ -1197,39 +1191,58 @@ public void beforeProcessStarted(ProcessStartedEvent event) { assertThat(((KogitoWorkflowProcessInstance) instances.get(1)).getVariable("subY")).isEqualTo("new value"); } + @Test + public void testServiceTaskWithMvelTransformation() throws Exception { + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.HelloService_hello__2_Handler", new HelloService_hello__2_Handler()); + org.kie.kogito.process.Process definition = ServiceProcessWithMvelTransformationProcess.newProcess(app); + ServiceProcessWithMvelTransformationModel model = definition.createModel(); + + model.setS("JoHn"); + + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + + assertThat(instance.variables().getS()).isEqualTo("hello john!"); + + } + @Test public void testServiceTaskWithMvelCollectionTransformation() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", - new ServiceTaskHandler()); - Map params = new HashMap<>(); - params.put("s", "john,poul,mary"); - KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime - .startProcess("ServiceProcess", params); - assertProcessInstanceFinished(processInstance, kruntime); - @SuppressWarnings("unchecked") - List result = (List) processInstance.getVariable("list"); + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.HelloService_hello__2_Handler", new HelloService_hello__2_Handler()); + org.kie.kogito.process.Process definition = ServiceProcessWithMvelCollectionTransformationProcess.newProcess(app); + ServiceProcessWithMvelCollectionTransformationModel model = definition.createModel(); + + model.setS("john,poul,mary"); + + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + + List result = (List) instance.variables().getList(); assertThat(result).hasSize(3); + } @Test public void testServiceTaskWithMvelJaxbTransformation() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2"); + HelloService.VALIDATE_STRING = "123john"; + + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.HelloService_validate__2_Handler", new HelloService_validate__2_Handler()); + org.kie.kogito.process.Process definition = ServiceProcessWithMvelJaxbTransformationProcess.newProcess(app); + ServiceProcessWithMvelJaxbTransformationModel model = definition.createModel(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", - new ServiceTaskHandler()); - Map params = new HashMap<>(); Person person = new Person(); person.setId(123); person.setName("john"); - params.put("s", person); + model.setS(person); - HelloService.VALIDATE_STRING = "123john"; + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); - KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime - .startProcess("ServiceProcessWithMvelJaxbTransformation", params); - assertProcessInstanceFinished(processInstance, kruntime); + assertThat(instance.status()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED); } diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java index f5d2dd08227..0dfd370c8c5 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java @@ -26,12 +26,34 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.jbpm.bpmn2.activity.BoundarySignalEventOnTaskWithTransformationModel; import org.jbpm.bpmn2.activity.BoundarySignalEventOnTaskWithTransformationProcess; import org.jbpm.bpmn2.handler.ReceiveTaskHandler; import org.jbpm.bpmn2.handler.SendTaskHandler; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventMessageWithTransformationModel; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventMessageWithTransformationProcess; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignal2Model; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignal2Process; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignalModel; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignalProcess; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignalWithTransformationModel; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignalWithTransformationProcess; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycle3Model; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycle3Process; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycleCronModel; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycleCronProcess; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorModel; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorProcess; +import org.jbpm.bpmn2.intermediate.IntermediateCatchSignalBetweenUserTasksModel; +import org.jbpm.bpmn2.intermediate.IntermediateCatchSignalBetweenUserTasksProcess; +import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageModel; +import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageProcess; +import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageWithTransformationModel; +import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageWithTransformationProcess; import org.jbpm.bpmn2.intermediate.IntermediateThrowEventSignalModel; import org.jbpm.bpmn2.intermediate.IntermediateThrowEventSignalProcess; import org.jbpm.bpmn2.objects.Person; @@ -43,21 +65,23 @@ import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler; import org.jbpm.test.util.NodeLeftCountDownProcessEventListener; import org.jbpm.test.util.ProcessCompletedCountDownProcessEventListener; +import org.jbpm.test.utils.EventTrackerProcessListener; import org.jbpm.test.utils.ProcessTestHelper; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.kie.api.command.ExecutableCommand; import org.kie.api.definition.process.WorkflowElementIdentifier; +import org.kie.api.event.process.ProcessCompletedEvent; import org.kie.api.event.process.ProcessNodeLeftEvent; import org.kie.api.event.process.ProcessNodeTriggeredEvent; import org.kie.api.event.process.ProcessStartedEvent; import org.kie.api.runtime.rule.FactHandle; import org.kie.kogito.Application; +import org.kie.kogito.event.impl.MessageProducer; import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener; import org.kie.kogito.internal.process.event.KogitoProcessEventListener; import org.kie.kogito.internal.process.runtime.KogitoNodeInstance; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; -import org.kie.kogito.internal.process.runtime.KogitoProcessRuntime; import org.kie.kogito.internal.process.runtime.KogitoWorkItem; import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler; import org.kie.kogito.internal.process.runtime.KogitoWorkItemManager; @@ -65,6 +89,7 @@ import org.kie.kogito.process.EventDescription; import org.kie.kogito.process.NamedDataType; import org.kie.kogito.process.ProcessInstance; +import org.kie.kogito.process.impl.Sig; import org.kie.kogito.process.workitems.InternalKogitoWorkItem; import static org.assertj.core.api.Assertions.assertThat; @@ -985,26 +1010,36 @@ public void afterNodeLeft(ProcessNodeLeftEvent event) { @Test public void testMessageIntermediateThrow() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntermediateThrowEventMessage.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Send Task", new SendTaskHandler()); - Map params = new HashMap<>(); - params.put("x", "MyValue"); - KogitoProcessInstance processInstance = kruntime.startProcess( - "IntermediateThrowEventMessage", params); - assertProcessInstanceCompleted(processInstance); + Application app = ProcessTestHelper.newApplication(); + + ProcessTestHelper.registerHandler(app, "Send Task", new SendTaskHandler()); + org.kie.kogito.process.Process definition = IntermediateThrowEventMessageProcess.newProcess(app); + IntermediateThrowEventMessageModel model = definition.createModel(); + + model.setX("MyValue"); + + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); } @Test public void testMessageIntermediateThrowVerifyWorkItemData() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntermediateThrowEventMessage.bpmn2"); + Application app = ProcessTestHelper.newApplication(); + TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Send Task", handler); - Map params = new HashMap<>(); - params.put("x", "MyValue"); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateThrowEventMessage", params); - assertProcessInstanceCompleted(processInstance); + ProcessTestHelper.registerHandler(app, "Send Task", handler); + org.kie.kogito.process.Process definition = IntermediateThrowEventMessageProcess.newProcess(app); + IntermediateThrowEventMessageModel model = definition.createModel(); + + model.setX("MyValue"); + + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); KogitoWorkItem workItem = handler.getWorkItem(); assertThat(workItem).isNotNull().isInstanceOf(KogitoWorkItem.class); @@ -1013,18 +1048,24 @@ public void testMessageIntermediateThrowVerifyWorkItemData() throws Exception { assertThat(nodeId).isNotNull(); assertThat(nodeInstanceId).isNotNull(); + } @Test public void testMessageIntermediateThrowVerifyWorkItemDataDeploymentId() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntermediateThrowEventMessage.bpmn2"); + Application app = ProcessTestHelper.newApplication(); + TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Send Task", handler); - Map params = new HashMap<>(); - params.put("x", "MyValue"); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateThrowEventMessage", params); - assertProcessInstanceCompleted(processInstance); + ProcessTestHelper.registerHandler(app, "Send Task", handler); + org.kie.kogito.process.Process definition = IntermediateThrowEventMessageProcess.newProcess(app); + IntermediateThrowEventMessageModel model = definition.createModel(); + + model.setX("MyValue"); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); KogitoWorkItem workItem = handler.getWorkItem(); assertThat(workItem).isNotNull().isInstanceOf(KogitoWorkItem.class); @@ -1035,6 +1076,7 @@ public void testMessageIntermediateThrowVerifyWorkItemDataDeploymentId() throws assertThat(nodeId).isNotNull(); assertThat(nodeInstanceId).isNotNull(); assertThat(deploymentId).isNull(); + } @Test @@ -1622,34 +1664,35 @@ public void testSignalBoundaryEventOnSubprocessTakingDifferentPaths() throws Exc @Test public void testIntermediateCatchEventSameSignalOnTwokruntimes() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignal.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler()); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEventSignal"); + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); - KogitoProcessRuntime kruntime2 = createKogitoProcessRuntime("BPMN2-IntermediateCatchEventSignal2.bpmn2"); - kruntime2.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler()); - KogitoProcessInstance processInstance2 = kruntime2.startProcess("IntermediateCatchEventSignal2"); + org.kie.kogito.process.Process definition1 = IntermediateCatchEventSignalProcess.newProcess(app); + org.kie.kogito.process.Process definition2 = IntermediateCatchEventSignal2Process.newProcess(app); - assertProcessInstanceActive(processInstance); - assertProcessInstanceActive(processInstance2); + org.kie.kogito.process.ProcessInstance instance1 = definition1.createInstance(definition1.createModel()); + org.kie.kogito.process.ProcessInstance instance2 = definition2.createInstance(definition2.createModel()); - // now signal process instance - kruntime.signalEvent("MyMessage", "SomeValue"); - assertProcessInstanceFinished(processInstance, kruntime); - assertProcessInstanceActive(processInstance2); + instance1.start(); + instance2.start(); + assertThat(instance1.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + assertThat(instance2.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + + instance1.send(Sig.of("MyMessage", "SomeValue")); + assertThat(instance1.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance2.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); - // now signal the other one - kruntime2.signalEvent("MyMessage", "SomeValue"); - assertProcessInstanceFinished(processInstance2, kruntime2); + instance2.send(Sig.of("MyMessage", "SomeValue")); + assertThat(instance1.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance2.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); - kruntime2.getKieSession().dispose(); // kruntime's session is disposed in the @AfterEach method } @Test + @Disabled public void testIntermediateCatchEventNoIncommingConnection() throws Exception { try { kruntime = createKogitoProcessRuntime("BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2"); - } catch (RuntimeException e) { assertThat(e.getMessage()).isNotNull(); assertThat(e.getMessage()).contains("has no incoming connection"); @@ -1818,62 +1861,135 @@ public void testSignalBoundaryEventWithTransformation() throws Exception { } @Test - @Disabled("Transfomer has been disabled") + public void testMessageIntermediateThrowWithTransformation() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2"); - final StringBuffer messageContent = new StringBuffer(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Send Task", - new SendTaskHandler() { - - @Override - public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) { - // collect message content for verification - messageContent.append(workItem.getParameter("Message")); - super.executeWorkItem(workItem, manager); - } - - }); - Map params = new HashMap<>(); - params.put("x", "MyValue"); - KogitoProcessInstance processInstance = kruntime.startProcess( - "MessageIntermediateEvent", params); - assertProcessInstanceCompleted(processInstance); + StringBuilder messageContent = new StringBuilder(); + Application application = ProcessTestHelper.newApplication(); + IntermediateThrowEventMessageWithTransformationProcess definition = + (IntermediateThrowEventMessageWithTransformationProcess) IntermediateThrowEventMessageWithTransformationProcess.newProcess(application); + definition.setProducer__2(new MessageProducer() { + @Override + public void produce(KogitoProcessInstance pi, String eventData) { + messageContent.append(eventData); + } + }); + IntermediateThrowEventMessageWithTransformationModel model = definition.createModel(); + model.setX("MyValue"); + ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); assertThat(messageContent).hasToString("MYVALUE"); } @Test - @Disabled("Transfomer has been disabled") public void testIntermediateCatchEventSignalWithTransformation() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - new SystemOutWorkItemHandler()); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEvent"); - assertProcessInstanceActive(processInstance); + Application app = ProcessTestHelper.newApplication(); + EventTrackerProcessListener listener = new EventTrackerProcessListener(); + ProcessTestHelper.registerProcessEventListener(app, listener); + org.kie.kogito.process.Process definition = IntermediateCatchEventSignalWithTransformationProcess.newProcess(app); + + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + instance.send(Sig.of("MyMessage", "SomeValue")); + + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getX()).isNotNull().isEqualTo("SOMEVALUE"); + assertThat(listener.tracked()) + .anyMatch(ProcessTestHelper.triggered("StartProcess")) + .anyMatch(ProcessTestHelper.triggered("UserTask")) + .anyMatch(ProcessTestHelper.triggered("EndProcess")) + .anyMatch(ProcessTestHelper.triggered("event")); + + } + + @Test + public void testIntermediateCatchEventTimerCycle3() throws Exception { + Application app = ProcessTestHelper.newApplication(); + + final CountDownLatch latch = new CountDownLatch(3); + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { + @Override + public void afterProcessCompleted(ProcessCompletedEvent event) { + latch.countDown(); + } + }); + org.kie.kogito.process.Process definition = IntermediateCatchEventTimerCycle3Process.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + latch.await(5, TimeUnit.SECONDS); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + instance.abort(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ABORTED); + } + + @Test + public void testIntermediateCatchEventTimerCycleCron() throws Exception { + Application app = ProcessTestHelper.newApplication(); + + final CountDownLatch latch = new CountDownLatch(3); + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { + @Override + public void afterProcessCompleted(ProcessCompletedEvent event) { + latch.countDown(); + } + }); + org.kie.kogito.process.Process definition = IntermediateCatchEventTimerCycleCronProcess.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + latch.await(5, TimeUnit.SECONDS); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + instance.abort(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ABORTED); + } + + @Test + public void testIntermediateCatchSignalBetweenUserTasksModel() throws Exception { + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); + org.kie.kogito.process.Process definition = IntermediateCatchSignalBetweenUserTasksProcess.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + instance.send(Sig.of("MySignal", null)); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + } + + @Test + public void testIntermediateCatchEventTimerDurationWithError() throws Exception { + Application app = ProcessTestHelper.newApplication(); + + final CountDownLatch latch = new CountDownLatch(1); + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { + @Override + public void afterProcessCompleted(ProcessCompletedEvent event) { + latch.countDown(); + } + }); + org.kie.kogito.process.Process definition = IntermediateCatchEventTimerDurationWithErrorProcess.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + latch.await(5, TimeUnit.SECONDS); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + assertThat(instance.variables().getTestOK()).isTrue(); - // now signal process instance - kruntime.signalEvent("MyMessage", "SomeValue", processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); - assertNodeTriggered(processInstance.getStringId(), "StartProcess", "UserTask", "EndProcess", "event"); - String var = getProcessVarValue(processInstance, "x"); - assertThat(var).isNotNull().isEqualTo("SOMEVALUE"); } @Test - @Disabled("Transfomer has been disabled") public void testIntermediateCatchEventMessageWithTransformation() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - new SystemOutWorkItemHandler()); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEvent"); - assertProcessInstanceActive(processInstance); + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); + org.kie.kogito.process.Process definition = IntermediateCatchEventMessageWithTransformationProcess.newProcess(app); + + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + instance.send(Sig.of("Message-HelloMessage", "SomeValue")); + + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getX()).isNotNull().isEqualTo("SOMEVALUE"); - // now signal process instance - kruntime.signalEvent("Message-HelloMessage", "SomeValue", processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); - String var = getProcessVarValue(processInstance, "x"); - assertThat(var).isNotNull().isEqualTo("SOMEVALUE"); } @Test diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java index 5a127d95c4b..1f9a16d506a 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java @@ -42,6 +42,8 @@ import org.jbpm.bpmn2.handler.SendTaskHandler; import org.jbpm.bpmn2.handler.ServiceTaskHandler; import org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator; +import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageModel; +import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageProcess; import org.jbpm.bpmn2.objects.ExceptionService; import org.jbpm.bpmn2.objects.Person; import org.jbpm.bpmn2.objects.TestWorkItemHandler; @@ -765,12 +767,15 @@ public void testMessageEnd() throws Exception { @Test public void testMessageIntermediateThrow() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntermediateThrowEventMessage.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Send Task", new SendTaskHandler()); - Map params = new HashMap<>(); - params.put("x", "MyValue"); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateThrowEventMessage", params); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED); + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Send Task", new SendTaskHandler()); + org.kie.kogito.process.Process definition = IntermediateThrowEventMessageProcess.newProcess(app); + IntermediateThrowEventMessageModel model = definition.createModel(); + model.setX("MyValue"); + + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); } @Test diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StartEventTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StartEventTest.java index 3785a11a6d0..b85d0b41ef5 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StartEventTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StartEventTest.java @@ -23,6 +23,7 @@ import java.nio.file.Paths; import java.time.OffsetDateTime; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -31,17 +32,23 @@ import org.jbpm.bpmn2.objects.NotAvailableGoodsReport; import org.jbpm.bpmn2.objects.Person; import org.jbpm.bpmn2.objects.TestWorkItemHandler; +import org.jbpm.bpmn2.start.SignalStartWithTransformationModel; +import org.jbpm.bpmn2.start.SignalStartWithTransformationProcess; import org.jbpm.test.util.NodeLeftCountDownProcessEventListener; +import org.jbpm.test.utils.ProcessTestHelper; import org.junit.jupiter.api.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieRepository; import org.kie.api.event.process.ProcessStartedEvent; import org.kie.api.io.Resource; import org.kie.api.runtime.KieContainer; +import org.kie.api.runtime.process.ProcessInstance; import org.kie.internal.io.ResourceFactory; +import org.kie.kogito.Application; import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; import org.kie.kogito.internal.process.runtime.KogitoWorkItem; +import org.kie.kogito.process.impl.Sig; import org.kie.kogito.process.workitems.InternalKogitoWorkItem; import static org.assertj.core.api.Assertions.assertThat; @@ -474,22 +481,24 @@ public void testTimerCycle() throws Exception { @Test public void testSignalStartWithTransformation() throws Exception { + Application app = ProcessTestHelper.newApplication(); NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 1); - kruntime = createKogitoProcessRuntime("BPMN2-SignalStartWithTransformation.bpmn2"); - kruntime.getProcessEventManager().addEventListener(countDownListener); - final List list = new ArrayList<>(); - kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() { + + ProcessTestHelper.registerProcessEventListener(app, countDownListener); + final List list = new ArrayList<>(); + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { @Override public void beforeProcessStarted(ProcessStartedEvent event) { - list.add((KogitoProcessInstance) event.getProcessInstance()); + list.add(event.getProcessInstance()); } }); - kruntime.signalEvent("MySignal", "NewValue"); + org.kie.kogito.process.Process definition = SignalStartWithTransformationProcess.newProcess(app); + + definition.send(Sig.of("MySignal", "NewValue")); + countDownListener.waitTillCompleted(); - assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(1); - assertThat(list).isNotNull().hasSize(1); - String var = getProcessVarValue(list.get(0), "x"); - assertThat(var).isEqualTo("NEWVALUE"); + assertThat(list).extracting(e -> e.getProcessId()).containsExactly("SignalStartWithTransformation"); + assertThat(list).extracting(e -> ((KogitoProcessInstance) e).getVariables()).containsExactly(Collections.singletonMap("x", "NEWVALUE")); } /** diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/main/java/org/jbpm/tools/maven/ProcessCodeGenerationSupport.java b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/main/java/org/jbpm/tools/maven/ProcessCodeGenerationSupport.java index b700115833d..8095f68c4f0 100644 --- a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/main/java/org/jbpm/tools/maven/ProcessCodeGenerationSupport.java +++ b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/main/java/org/jbpm/tools/maven/ProcessCodeGenerationSupport.java @@ -47,6 +47,7 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Modifier.Keyword; import com.github.javaparser.ast.Node.TreeTraversal; import com.github.javaparser.ast.PackageDeclaration; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -259,6 +260,7 @@ private void addMembers(ProcessMetaData processMetaData, CompilationUnit compila MethodDeclaration setMethod = new MethodDeclaration(); setMethod.addParameter(type, producerFieldName); + setMethod.setModifier(Keyword.PUBLIC, true); setMethod.setName("set" + producerFieldNameCapitalized); setMethod.setType(StaticJavaParser.parseType("void")); AssignExpr assignExpr = new AssignExpr( From 133eab82b90144b2d7de63a80ad813916cb3d421 Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Martinez Date: Tue, 11 Jun 2024 12:00:07 +0200 Subject: [PATCH 7/9] fix tests --- .../kogito/process/bpmn2/BpmnProcesses.java | 19 +++++ .../instance/KogitoProcessContextImpl.java | 2 +- .../impl/WorkflowProcessInstanceImpl.java | 18 +++-- .../kogito/process/impl/AbstractProcess.java | 18 +++++ ...IntermediateCatchEventTimerCycleCron.bpmn2 | 2 +- ...iateCatchEventTimerDurationWithError.bpmn2 | 9 ++- .../org/jbpm/bpmn2/IntermediateEventTest.java | 80 ++++--------------- .../jbpm/bpmn2/StandaloneBPMNProcessTest.java | 11 ++- .../parser/handlers/NodeFactoryUtils.java | 5 +- 9 files changed, 85 insertions(+), 79 deletions(-) diff --git a/jbpm/jbpm-bpmn2/src/main/java/org/kie/kogito/process/bpmn2/BpmnProcesses.java b/jbpm/jbpm-bpmn2/src/main/java/org/kie/kogito/process/bpmn2/BpmnProcesses.java index 931a0ee8861..ab043f7d3b8 100644 --- a/jbpm/jbpm-bpmn2/src/main/java/org/kie/kogito/process/bpmn2/BpmnProcesses.java +++ b/jbpm/jbpm-bpmn2/src/main/java/org/kie/kogito/process/bpmn2/BpmnProcesses.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import org.kie.kogito.Model; import org.kie.kogito.process.Process; @@ -44,4 +45,22 @@ public Process processById(String processId) { public Collection processIds() { return mappedProcesses.keySet(); } + + @Override + public int hashCode() { + return Objects.hash(mappedProcesses.keySet()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BpmnProcesses other = (BpmnProcesses) obj; + return Objects.equals(mappedProcesses, other.mappedProcesses); + } + } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/KogitoProcessContextImpl.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/KogitoProcessContextImpl.java index 1b2bba1bda2..5258ea7e2ee 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/KogitoProcessContextImpl.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/KogitoProcessContextImpl.java @@ -50,7 +50,7 @@ public boolean isVariableResolvable(String variableId) { return resolver.resolveContext(VariableScope.VARIABLE_SCOPE, variableId) != null; } - return nodeInstance.getVariable(variableId) != null; + return getVariable(variableId) != null; } @Override diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java index f7015820700..434aca19b33 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java @@ -41,6 +41,7 @@ import org.drools.core.common.InternalKnowledgeRuntime; import org.drools.mvel.util.MVELEvaluator; import org.jbpm.process.core.ContextContainer; +import org.jbpm.process.core.ContextResolver; import org.jbpm.process.core.context.variable.Variable; import org.jbpm.process.core.context.variable.VariableScope; import org.jbpm.process.core.timer.BusinessCalendar; @@ -539,7 +540,7 @@ public void configureTimers() { public TimerInstance configureSLATimer(String slaDueDateExpression) { // setup SLA if provided - slaDueDateExpression = resolveVariable(slaDueDateExpression); + slaDueDateExpression = resolveVariable(slaDueDateExpression).toString(); if (slaDueDateExpression == null || slaDueDateExpression.trim().isEmpty()) { logger.debug("Sla due date expression resolved to no value '{}'", slaDueDateExpression); return null; @@ -593,7 +594,7 @@ private void registerExternalEventNodeListeners() { for (String type : events) { addEventListener(type, EMPTY_EVENT_LISTENER, true); if (isVariableExpression(type)) { - addEventListener(resolveVariable(type), EMPTY_EVENT_LISTENER, true); + addEventListener(resolveVariable(type).toString(), EMPTY_EVENT_LISTENER, true); } } } @@ -731,7 +732,7 @@ private Function getResolver(org.kie.api.definition.process.Node if (nodeInstances != null && !nodeInstances.isEmpty()) { StringBuilder st = new StringBuilder(); for (NodeInstance ni : nodeInstances) { - String result = resolveVariable(e, new NodeInstanceResolverFactory(ni)); + Object result = resolveVariable(e, new NodeInstanceResolverFactory(ni)); st.append(result).append("###"); } return st.toString(); @@ -745,14 +746,19 @@ private Function getResolver(org.kie.api.definition.process.Node } protected List resolveVariables(List events) { - return events.stream().map(this::resolveVariable).collect(Collectors.toList()); + return events.stream().map(this::resolveVariable).map(Object::toString).collect(Collectors.toList()); } - private String resolveVariable(String s) { + private Object resolveVariable(String s) { return resolveVariable(s, new ProcessInstanceResolverFactory(this)); } - private String resolveVariable(String s, VariableResolverFactory factory) { + private Object resolveVariable(String s, VariableResolverFactory factory) { + VariableScope var = (VariableScope) ((ContextResolver) this.getProcess()).resolveContext(VariableScope.VARIABLE_SCOPE, s); + if (var != null) { + return getVariable(s); + } + Map replacements = new HashMap<>(); Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(s); while (matcher.find()) { diff --git a/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcess.java b/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcess.java index 3881821765d..2d09b5b141e 100644 --- a/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcess.java +++ b/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcess.java @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -310,4 +311,21 @@ public String[] getEventTypes() { return new String[0]; } } + + @Override + public int hashCode() { + return id().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AbstractProcess other = (AbstractProcess) obj; + return Objects.equals(id(), other.id()); + } } diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 index 99cddc6d6d9..5b49feb3dbe 100755 --- a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 @@ -41,7 +41,7 @@ - 0/1 * * * * ? + R3/PT1S diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 index bfa38763db8..0512b88a5f7 100755 --- a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 @@ -23,9 +23,7 @@ - - - + _1-_3 @@ -40,7 +38,10 @@ _3-_4 _4-_5 - kcontext.setVariable("TestOK", Boolean.TRUE); + + System.out.println("TestOK: " + TestOK); + kcontext.setVariable("TestOK", Boolean.TRUE); + System.out.println("TestOK: " + kcontext.getVariable("TestOK")); diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java index 0dfd370c8c5..0bfaf312c24 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java @@ -48,6 +48,7 @@ import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycleCronProcess; import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorModel; import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorProcess; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorProcessInstance; import org.jbpm.bpmn2.intermediate.IntermediateCatchSignalBetweenUserTasksModel; import org.jbpm.bpmn2.intermediate.IntermediateCatchSignalBetweenUserTasksProcess; import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageModel; @@ -70,7 +71,6 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.kie.api.command.ExecutableCommand; -import org.kie.api.definition.process.WorkflowElementIdentifier; import org.kie.api.event.process.ProcessCompletedEvent; import org.kie.api.event.process.ProcessNodeLeftEvent; import org.kie.api.event.process.ProcessNodeTriggeredEvent; @@ -90,7 +90,6 @@ import org.kie.kogito.process.NamedDataType; import org.kie.kogito.process.ProcessInstance; import org.kie.kogito.process.impl.Sig; -import org.kie.kogito.process.workitems.InternalKogitoWorkItem; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -1013,51 +1012,14 @@ public void testMessageIntermediateThrow() throws Exception { Application app = ProcessTestHelper.newApplication(); ProcessTestHelper.registerHandler(app, "Send Task", new SendTaskHandler()); - org.kie.kogito.process.Process definition = IntermediateThrowEventMessageProcess.newProcess(app); - IntermediateThrowEventMessageModel model = definition.createModel(); - - model.setX("MyValue"); - - org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); - instance.start(); - - assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); - - } - - @Test - public void testMessageIntermediateThrowVerifyWorkItemData() throws Exception { - Application app = ProcessTestHelper.newApplication(); - - TestWorkItemHandler handler = new TestWorkItemHandler(); - ProcessTestHelper.registerHandler(app, "Send Task", handler); - org.kie.kogito.process.Process definition = IntermediateThrowEventMessageProcess.newProcess(app); - IntermediateThrowEventMessageModel model = definition.createModel(); - - model.setX("MyValue"); - - org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); - instance.start(); - - assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); - KogitoWorkItem workItem = handler.getWorkItem(); - assertThat(workItem).isNotNull().isInstanceOf(KogitoWorkItem.class); - - String nodeInstanceId = ((InternalKogitoWorkItem) workItem).getNodeInstanceStringId(); - WorkflowElementIdentifier nodeId = ((InternalKogitoWorkItem) workItem).getNodeId(); - - assertThat(nodeId).isNotNull(); - assertThat(nodeInstanceId).isNotNull(); - - } - - @Test - public void testMessageIntermediateThrowVerifyWorkItemDataDeploymentId() throws Exception { - Application app = ProcessTestHelper.newApplication(); - - TestWorkItemHandler handler = new TestWorkItemHandler(); - ProcessTestHelper.registerHandler(app, "Send Task", handler); - org.kie.kogito.process.Process definition = IntermediateThrowEventMessageProcess.newProcess(app); + IntermediateThrowEventMessageProcess definition = (IntermediateThrowEventMessageProcess) IntermediateThrowEventMessageProcess.newProcess(app); + StringBuilder builder = new StringBuilder(); + definition.setProducer__2(new MessageProducer() { + @Override + public void produce(KogitoProcessInstance pi, String eventData) { + builder.append(eventData); + } + }); IntermediateThrowEventMessageModel model = definition.createModel(); model.setX("MyValue"); @@ -1065,17 +1027,8 @@ public void testMessageIntermediateThrowVerifyWorkItemDataDeploymentId() throws org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); instance.start(); + assertThat(builder.toString()).isEqualTo("MyValue"); assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); - KogitoWorkItem workItem = handler.getWorkItem(); - assertThat(workItem).isNotNull().isInstanceOf(KogitoWorkItem.class); - - String nodeInstanceId = ((InternalKogitoWorkItem) workItem).getNodeInstanceStringId(); - WorkflowElementIdentifier nodeId = ((InternalKogitoWorkItem) workItem).getNodeId(); - String deploymentId = ((InternalKogitoWorkItem) workItem).getDeploymentId(); - - assertThat(nodeId).isNotNull(); - assertThat(nodeInstanceId).isNotNull(); - assertThat(deploymentId).isNull(); } @@ -1888,6 +1841,7 @@ public void testIntermediateCatchEventSignalWithTransformation() throws Exceptio Application app = ProcessTestHelper.newApplication(); EventTrackerProcessListener listener = new EventTrackerProcessListener(); ProcessTestHelper.registerProcessEventListener(app, listener); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); org.kie.kogito.process.Process definition = IntermediateCatchEventSignalWithTransformationProcess.newProcess(app); org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); @@ -1940,9 +1894,7 @@ public void afterProcessCompleted(ProcessCompletedEvent event) { org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); instance.start(); latch.await(5, TimeUnit.SECONDS); - assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); - instance.abort(); - assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ABORTED); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); } @Test @@ -1969,11 +1921,11 @@ public void afterProcessCompleted(ProcessCompletedEvent event) { } }); org.kie.kogito.process.Process definition = IntermediateCatchEventTimerDurationWithErrorProcess.newProcess(app); - org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + IntermediateCatchEventTimerDurationWithErrorProcessInstance instance = (IntermediateCatchEventTimerDurationWithErrorProcessInstance) definition.createInstance(definition.createModel()); instance.start(); - latch.await(5, TimeUnit.SECONDS); - assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); - assertThat(instance.variables().getTestOK()).isTrue(); + latch.await(10, TimeUnit.SECONDS); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getTestOK()).isEqualTo(Boolean.TRUE); } diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java index 1f9a16d506a..3d2377495fa 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java @@ -60,6 +60,7 @@ import org.kie.api.io.Resource; import org.kie.internal.io.ResourceFactory; import org.kie.kogito.Application; +import org.kie.kogito.event.impl.MessageProducer; import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; import org.kie.kogito.internal.process.runtime.KogitoProcessRuntime; @@ -769,12 +770,20 @@ public void testMessageEnd() throws Exception { public void testMessageIntermediateThrow() throws Exception { Application app = ProcessTestHelper.newApplication(); ProcessTestHelper.registerHandler(app, "Send Task", new SendTaskHandler()); - org.kie.kogito.process.Process definition = IntermediateThrowEventMessageProcess.newProcess(app); + IntermediateThrowEventMessageProcess definition = (IntermediateThrowEventMessageProcess) IntermediateThrowEventMessageProcess.newProcess(app); + StringBuilder builder = new StringBuilder(); + definition.setProducer__2(new MessageProducer() { + @Override + public void produce(KogitoProcessInstance pi, String eventData) { + builder.append(eventData); + } + }); IntermediateThrowEventMessageModel model = definition.createModel(); model.setX("MyValue"); org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); instance.start(); + assertThat(builder.toString()).isEqualTo("MyValue"); assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); } diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/NodeFactoryUtils.java b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/NodeFactoryUtils.java index 18590dc51e6..ab2b73b91c8 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/NodeFactoryUtils.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/NodeFactoryUtils.java @@ -78,10 +78,11 @@ public class NodeFactoryUtils { return actionNode .name(name) .metaData(Metadata.EVENT_TYPE, "message") - .metaData(Metadata.MAPPING_VARIABLE, inputVar) + .metaData(Metadata.MAPPING_VARIABLE_INPUT, inputVar) .metaData(Metadata.TRIGGER_REF, type) .metaData(Metadata.MESSAGE_TYPE, JSON_NODE) - .metaData(Metadata.TRIGGER_TYPE, "ProduceMessage"); + .metaData(Metadata.TRIGGER_TYPE, "ProduceMessage") + .inMapping(inputVar, inputVar); } public static , P extends RuleFlowNodeContainerFactory> T startMessageNode(T nodeFactory, EventDefinition eventDefinition, String inputVar, String outputVar) { From 346efa5951c916fd49cca6c1059db1e6848eb0e2 Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Martinez Date: Wed, 12 Jun 2024 10:34:30 +0200 Subject: [PATCH 8/9] fix some tests --- .../org/jbpm/compiler/canonical/AbstractNodeVisitor.java | 6 ++++-- .../serverless/workflow/ServerlessWorkflowParsingTest.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java index 59c7acfcede..b548f304778 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java @@ -405,8 +405,10 @@ protected ObjectCreationExpr buildProducerAction(Node node, ProcessMetaData meta public static ObjectCreationExpr buildProducerAction(ClassOrInterfaceType actionClass, TriggerMetaData trigger, ProcessMetaData metadata) { metadata.addTrigger(trigger); return new ObjectCreationExpr(null, actionClass, NodeList.nodeList( - new StringLiteralExpr(trigger.getName()), new StringLiteralExpr(trigger.getModelRef()), - new LambdaExpr(NodeList.nodeList(), new NameExpr("producer_" + trigger.getOwnerId())))); + new StringLiteralExpr(trigger.getName()), + new StringLiteralExpr(trigger.getModelRef()), + new LambdaExpr(NodeList.nodeList(), + new NameExpr("producer_" + trigger.getOwnerId())))); } protected void visitCompensationScope(ContextContainer process, BlockStmt body) { diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/test/java/org/kie/kogito/serverless/workflow/ServerlessWorkflowParsingTest.java b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/test/java/org/kie/kogito/serverless/workflow/ServerlessWorkflowParsingTest.java index f0f5a11337a..e140cb54b87 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/test/java/org/kie/kogito/serverless/workflow/ServerlessWorkflowParsingTest.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/test/java/org/kie/kogito/serverless/workflow/ServerlessWorkflowParsingTest.java @@ -425,7 +425,7 @@ public void testProduceEventOnTransition(String workflowLocation) throws Excepti ActionNode actionNode = (ActionNode) process.getNodes()[4]; assertThat(actionNode.getName()).isEqualTo("TestKafkaEvent"); assertThat(actionNode.getMetaData("TriggerType")).isEqualTo("ProduceMessage"); - assertThat(actionNode.getMetaData("MappingVariable")).isEqualTo("workflowdata"); + assertThat(actionNode.getMetaData("MappingVariableInput")).isEqualTo("workflowdata"); assertThat(actionNode.getMetaData("TriggerRef")).isEqualTo("kafka"); assertThat(actionNode.getMetaData("MessageType")).isEqualTo("com.fasterxml.jackson.databind.JsonNode"); } From 69622af4f7c6bc83d18b5468effee5c2652a8a37 Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Martinez Date: Wed, 12 Jun 2024 11:01:51 +0200 Subject: [PATCH 9/9] fix producer trigger in serverless workflow --- .../workflow/suppliers/ProduceEventActionSupplier.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/suppliers/ProduceEventActionSupplier.java b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/suppliers/ProduceEventActionSupplier.java index 71001997875..e53e57f69c9 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/suppliers/ProduceEventActionSupplier.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/suppliers/ProduceEventActionSupplier.java @@ -38,6 +38,7 @@ import io.serverlessworkflow.api.Workflow; import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; +import static org.jbpm.ruleflow.core.Metadata.MAPPING_VARIABLE_INPUT; public class ProduceEventActionSupplier extends SWFProduceEventAction implements ExpressionSupplier { @@ -49,7 +50,8 @@ public ProduceEventActionSupplier(Workflow workflow, String trigger, String varN @Override public Expression get(KogitoNode node, ProcessMetaData metadata) { - return AbstractNodeVisitor.buildProducerAction(parseClassOrInterfaceType(SWFProduceEventAction.class.getCanonicalName()), TriggerMetaData.of(node), metadata) + return AbstractNodeVisitor.buildProducerAction(parseClassOrInterfaceType(SWFProduceEventAction.class.getCanonicalName()), TriggerMetaData.of(node, (String) node.getMetaData() + .get(MAPPING_VARIABLE_INPUT)), metadata) .addArgument(new StringLiteralExpr(exprLang)) .addArgument(data != null ? new StringLiteralExpr().setString(data) : new NullLiteralExpr()); }