From beb5d0f684e63d6650371031e53c666b8ac863b8 Mon Sep 17 00:00:00 2001
From: Francisco Javier Tirado Sarti
<65240126+fjtirado@users.noreply.github.com>
Date: Wed, 28 Feb 2024 10:21:03 +0100
Subject: [PATCH] [Fix #3415] Allow constant values in user task assignments
(#3416)
* [Fix #3415] Allow constant values in user task assignments
* [Fix #3415] Gonzalos comments
---
.../ActivityGenerationModelTest.java | 1 +
.../src/test/resources/BPMN2-UserTask.bpmn2 | 194 +++++++++++++-----
.../canonical/UserTaskModelMetaData.java | 29 ++-
.../core/context/variable/Variable.java | 7 +-
4 files changed, 153 insertions(+), 78 deletions(-)
diff --git a/jbpm/jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/canonical/ActivityGenerationModelTest.java b/jbpm/jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/canonical/ActivityGenerationModelTest.java
index ef979162bbf..55eda0b45ef 100644
--- a/jbpm/jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/canonical/ActivityGenerationModelTest.java
+++ b/jbpm/jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/canonical/ActivityGenerationModelTest.java
@@ -151,6 +151,7 @@ public void testUserTaskProcess() throws Exception {
KogitoWorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
+ assertThat(workItem.getParameter("fixedValue")).isEqualTo("pepe");
processInstance.completeWorkItem(workItem.getStringId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
}
diff --git a/jbpm/jbpm-bpmn2/src/test/resources/BPMN2-UserTask.bpmn2 b/jbpm/jbpm-bpmn2/src/test/resources/BPMN2-UserTask.bpmn2
index 85e40725b68..8ec23a6c65f 100755
--- a/jbpm/jbpm-bpmn2/src/test/resources/BPMN2-UserTask.bpmn2
+++ b/jbpm/jbpm-bpmn2/src/test/resources/BPMN2-UserTask.bpmn2
@@ -1,64 +1,146 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- john
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ _1-_2
+
+
+
+
+
+
+
+ _1-_2
+ _2-_3
+
+
+
+
+
+ _2_TaskNameInputX
+ _2_fixedValueInputX
+ _2_SkippableInputX
+
+
+
+ _2_TaskNameInputX
+
+
+
+
+
+
+ _2_fixedValueInputX
+
+
+
+
+
+
+ _2_SkippableInputX
+
+
+
+
+
+
+
+ john
+
+
+
+
+
+
+
+
+
+ _2-_3
+
+
+
-
-
-
+
+
+
-
-
+
+
-
-
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ _1aP80Le_EDyttMyrW6hRzg
+ _1aP80Le_EDyttMyrW6hRzg
+
+
\ No newline at end of file
diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/UserTaskModelMetaData.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/UserTaskModelMetaData.java
index 7f8de5e2ac9..e2134e0e02d 100644
--- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/UserTaskModelMetaData.java
+++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/UserTaskModelMetaData.java
@@ -24,10 +24,10 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
-import java.util.regex.Matcher;
import org.jbpm.process.core.context.variable.Variable;
import org.jbpm.process.core.context.variable.VariableScope;
+import org.jbpm.process.core.datatype.DataType;
import org.jbpm.process.core.datatype.DataTypeResolver;
import org.jbpm.util.PatternConstants;
import org.jbpm.workflow.core.node.HumanTaskNode;
@@ -199,13 +199,12 @@ private CompilationUnit compilationUnitInput() {
.orElse(processVariableScope.findVariable(entry.getValue()));
if (variable == null) {
- Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(entry.getValue());
- if (matcher.find()) {
- variable = new Variable();
- variable.setName(entry.getKey());
- variable.setType(DataTypeResolver.fromType(inputTypes.get(entry.getKey()), Thread.currentThread().getContextClassLoader()));
- } else {
- throw new IllegalStateException("Task " + humanTaskNode.getName() + " (input) " + entry.getKey() + " reference not existing variable " + entry.getValue());
+ variable = new Variable();
+ variable.setName(entry.getKey());
+ DataType type = DataTypeResolver.fromType(inputTypes.get(entry.getKey()), Thread.currentThread().getContextClassLoader());
+ variable.setType(type);
+ if (!PatternConstants.PARAMETER_MATCHER.matcher(entry.getValue()).find()) {
+ variable.setValue(type.readValue(entry.getValue()));
}
}
@@ -313,14 +312,12 @@ private CompilationUnit compilationUnitOutput() {
.orElse(processVariableScope.findVariable(entry.getValue()));
if (variable == null) {
- // check if given mapping is an expression
- Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(entry.getValue());
- if (matcher.find()) {
- variable = new Variable();
- variable.setName(entry.getKey());
- variable.setType(DataTypeResolver.fromType(outputTypes.get(entry.getKey()), Thread.currentThread().getContextClassLoader()));
- } else {
- throw new IllegalStateException("Task " + humanTaskNode.getName() + " (output) " + entry.getKey() + " reference not existing variable " + entry.getValue());
+ variable = new Variable();
+ variable.setName(entry.getKey());
+ DataType type = DataTypeResolver.fromType(outputTypes.get(entry.getKey()), Thread.currentThread().getContextClassLoader());
+ variable.setType(type);
+ if (!PatternConstants.PARAMETER_MATCHER.matcher(entry.getValue()).find()) {
+ variable.setValue(type.readValue(entry.getValue()));
}
}
diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/context/variable/Variable.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/context/variable/Variable.java
index e33a97a6daf..f70815a0445 100755
--- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/context/variable/Variable.java
+++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/context/variable/Variable.java
@@ -128,12 +128,7 @@ public void setValue(final Object value) {
if (this.type.verifyDataType(value)) {
this.value = value;
} else {
- final StringBuilder sb = new StringBuilder();
- sb.append("Value <");
- sb.append(value);
- sb.append("> is not valid for datatype: ");
- sb.append(this.type);
- throw new IllegalArgumentException(sb.toString());
+ throw new IllegalArgumentException("Value <" + value + "> of datatype: " + value.getClass() + " is not valid for datatype: " + type.getObjectClass());
}
}