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 93d771f0caa..7a16ef7380e 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 @@ -409,7 +409,7 @@ protected DataDefinition getVariableDataSpec(Parser parser, String propertyIdRef return null; } Variable variable = var.get(); - return new DataDefinition(variable.getId(), variable.getName(), variable.getType().getStringType()); + return new DataDefinition(variable.getId(), variable.getName(), variable); } protected ItemDefinition getStructureRef(Parser parser, String id) { @@ -630,10 +630,9 @@ private String cleanUp(String expression) { } private DataDefinition toDataExpression(String expression) { - DataDefinition dataSpec = new DataDefinition(UUID.randomUUID().toString(), "EXPRESSION (" + expression + ")", null); + DataDefinition dataSpec = new DataDefinition(UUID.randomUUID().toString(), "EXPRESSION (" + expression + ")", (String) null); dataSpec.setExpression(expression); return dataSpec; - } private boolean isExpr(String mvelExpression) { 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 e3429dcdbb4..27595fe2e74 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 @@ -25,6 +25,7 @@ import java.util.stream.Collectors; import org.jbpm.process.builder.action.ActionCompilerRegistry; +import org.jbpm.process.builder.transformation.DataTransformerCompilerRegistry; import org.jbpm.process.core.ContextContainer; import org.jbpm.process.core.context.variable.Mappable; import org.jbpm.process.core.context.variable.Variable; @@ -69,6 +70,7 @@ import com.github.javaparser.ast.type.WildcardType; import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; +import static java.util.Collections.singletonList; import static org.drools.util.StringUtils.ucFirst; import static org.jbpm.ruleflow.core.Metadata.CUSTOM_AUTO_START; import static org.jbpm.ruleflow.core.Metadata.HIDDEN; @@ -230,7 +232,7 @@ protected Expression buildDataAssociationExpression(DataAssociation dataAssociat DataDefinition targetExpr = dataAssociation.getTarget(); Transformation transformation = dataAssociation.getTransformation(); List assignments = dataAssociation.getAssignments(); - return toDataAssociation(toDataDef(sourceExpr), toDataDef(targetExpr), toAssignmentExpr(assignments), toTransformation(transformation)); + return toDataAssociation(toDataDef(sourceExpr), toDataDef(targetExpr), toAssignmentExpr(assignments), toTransformation(sourceExpr, singletonList(targetExpr), transformation)); } private Expression toAssignmentExpr(List assignments) { @@ -250,15 +252,15 @@ private Expression toAssignmentExpr(List assignments) { return new MethodCallExpr(null, "java.util.Arrays.asList", NodeList.nodeList(expressions)); } - protected Expression toTransformation(Transformation transformation) { + protected Expression toTransformation(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 source = new StringLiteralExpr(transformation.getSource()); + 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, source)); + return new ObjectCreationExpr(null, clazz, NodeList.nodeList(lang, expression, compiledExpression)); } 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 new file mode 100644 index 00000000000..0e85a0b0b0a --- /dev/null +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompiler.java @@ -0,0 +1,39 @@ +/* + * 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 new file mode 100755 index 00000000000..54f506da76e --- /dev/null +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompilerRegistry.java @@ -0,0 +1,72 @@ +/* + * 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 new file mode 100644 index 00000000000..377076b3466 --- /dev/null +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DefaultDataTransformerCompiler.java @@ -0,0 +1,57 @@ +/* + * 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 new file mode 100644 index 00000000000..d2dc13c0521 --- /dev/null +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/JavaDataTransformerCompiler.java @@ -0,0 +1,65 @@ +/* + * 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 java.util.Map; + +import org.jbpm.workflow.core.impl.DataDefinition; +import org.jbpm.workflow.core.node.Transformation; + +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.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 + BlockStmt body = StaticJavaParser.parseBlock("{" + transformation.getExpression() + "}"); + 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(Map.class.getName()), "parameters")), body, true); + ClassOrInterfaceType type = StaticJavaParser.parseClassOrInterfaceType("java.util.function.Function"); + return new CastExpr(type, lambda); + } + +} diff --git a/jbpm/jbpm-flow-builder/src/main/resources/META-INF/services/org.jbpm.process.builder.transformation.DataTransformerCompiler b/jbpm/jbpm-flow-builder/src/main/resources/META-INF/services/org.jbpm.process.builder.transformation.DataTransformerCompiler new file mode 100644 index 00000000000..598412f6119 --- /dev/null +++ b/jbpm/jbpm-flow-builder/src/main/resources/META-INF/services/org.jbpm.process.builder.transformation.DataTransformerCompiler @@ -0,0 +1,2 @@ +org.jbpm.process.builder.transformation.DefaultDataTransformerCompiler +org.jbpm.process.builder.transformation.JavaDataTransformerCompiler \ No newline at end of file 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 index 97f4349bbe9..5cd596786e4 100755 --- 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 @@ -21,6 +21,7 @@ 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; @@ -46,6 +47,7 @@ public class DataTransformerRegistry { 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() { 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 new file mode 100644 index 00000000000..daefaf43cc9 --- /dev/null +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/JavaDataTransformer.java @@ -0,0 +1,39 @@ +/* + * 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/workflow/core/impl/DataDefinition.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/DataDefinition.java index e36b7a940da..0b96a2a73c2 100644 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/DataDefinition.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/DataDefinition.java @@ -21,6 +21,8 @@ import java.io.Serializable; import java.util.UUID; +import org.jbpm.process.core.context.variable.Variable; + public class DataDefinition implements Serializable { private static final long serialVersionUID = -1819075545956349183L; @@ -30,6 +32,8 @@ public class DataDefinition implements Serializable { private String type; private String expression; + private Variable variable; + public DataDefinition(String expression) { this.id = UUID.randomUUID().toString(); this.label = "EXPRESSION - (" + expression + ")"; @@ -48,6 +52,12 @@ public DataDefinition(String id, String label, String type) { this(id, label, type, null); } + public DataDefinition(String id, String label, Variable variable) { + this.id = id; + this.label = label != null && !label.isEmpty() ? label : id; + this.variable = variable; + } + public String getId() { return id; } @@ -65,6 +75,9 @@ public void setExpression(String expression) { } public String getType() { + if (variable != null) { + return variable.getType().getStringType(); + } return type; } @@ -128,7 +141,7 @@ public boolean equals(Object obj) { if (type == null) { if (other.type != null) return false; - } else if (!type.equals(other.type)) + } else if (!getType().equals(other.getType())) return false; return true; } 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 d49b3a30f84..97533ec90a0 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 @@ -24,20 +24,18 @@ public class Transformation implements Serializable { private static final long serialVersionUID = 1641905060375832661L; - private String source; private String language; private String expression; private Object compiledExpression; public Transformation(String lang, String expression) { - this.language = lang; - this.expression = expression; + this(lang, expression, null); } - public Transformation(String lang, String expression, String source) { + public Transformation(String lang, String expression, Object compiledExpression) { this.language = lang; this.expression = expression; - this.source = source; + this.compiledExpression = compiledExpression; } public String getLanguage() { @@ -64,12 +62,4 @@ public void setCompiledExpression(Object compliedExpression) { this.compiledExpression = compliedExpression; } - public String getSource() { - return source; - } - - public void setSource(String source) { - this.source = source; - } - } diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/activity/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/activity/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn new file mode 100755 index 00000000000..abf5d076e7a --- /dev/null +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/activity/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn @@ -0,0 +1,175 @@ + + + + + + + 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 + return 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-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java index 4d4a7242530..f5d2dd08227 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 @@ -28,8 +28,12 @@ import java.util.Set; 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.IntermediateThrowEventSignalModel; +import org.jbpm.bpmn2.intermediate.IntermediateThrowEventSignalProcess; import org.jbpm.bpmn2.objects.Person; import org.jbpm.bpmn2.objects.TestWorkItemHandler; import org.jbpm.bpmn2.test.RequirePersistence; @@ -39,6 +43,7 @@ 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.ProcessTestHelper; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.kie.api.command.ExecutableCommand; @@ -47,6 +52,7 @@ 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.internal.process.event.DefaultKogitoProcessEventListener; import org.kie.kogito.internal.process.event.KogitoProcessEventListener; import org.kie.kogito.internal.process.runtime.KogitoNodeInstance; @@ -58,6 +64,7 @@ import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance; import org.kie.kogito.process.EventDescription; import org.kie.kogito.process.NamedDataType; +import org.kie.kogito.process.ProcessInstance; import org.kie.kogito.process.workitems.InternalKogitoWorkItem; import static org.assertj.core.api.Assertions.assertThat; @@ -1794,27 +1801,20 @@ public void testSignalIntermediateThrowEventWithTransformation() throws Exceptio } @Test - @Disabled("Transfomer has been disabled") public void testSignalBoundaryEventWithTransformation() throws Exception { - kruntime = createKogitoProcessRuntime( - "BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn", - "BPMN2-IntermediateThrowEventSignal.bpmn2"); - - TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - handler); - - Map params = new HashMap<>(); - params.put("x", "john"); - KogitoProcessInstance processInstance = kruntime.startProcess("BoundarySignalOnTask"); - - KogitoProcessInstance processInstance2 = kruntime.startProcess("SignalIntermediateEvent", params); - assertProcessInstanceFinished(processInstance2, kruntime); - - assertProcessInstanceFinished(processInstance, kruntime); - - String var = getProcessVarValue(processInstance, "x"); - assertThat(var).isEqualTo("JOHN"); + Application application = ProcessTestHelper.newApplication(); + org.kie.kogito.process.Process processBoundary = BoundarySignalEventOnTaskWithTransformationProcess.newProcess(application); + org.kie.kogito.process.Process processIntermediate = IntermediateThrowEventSignalProcess.newProcess(application); + + ProcessInstance instanceBoundary = processBoundary.createInstance(processBoundary.createModel()); + instanceBoundary.start(); + IntermediateThrowEventSignalModel modelIntermediate = processIntermediate.createModel(); + modelIntermediate.setX("john"); + ProcessInstance instanceIntermediate = processIntermediate.createInstance(modelIntermediate); + instanceIntermediate.start(); + assertThat(instanceIntermediate).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(instanceBoundary).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(instanceBoundary.variables().getX()).isEqualTo("JOHN"); } @Test diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/pom.xml b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/pom.xml index 3a159e40323..39420a95e30 100644 --- a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/pom.xml +++ b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/pom.xml @@ -96,6 +96,11 @@ google-collections test + + org.slf4j + slf4j-simple + test + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn similarity index 99% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn rename to jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn index 8c88dc39add..d6eb0a8cb47 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn +++ b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn @@ -80,7 +80,7 @@ SequenceFlow_5 - + _4_Output x