Skip to content

Commit

Permalink
[Fix apache#3415] Allow constant values in user task assignments (apa…
Browse files Browse the repository at this point in the history
…che#3416)

* [Fix apache#3415] Allow constant values in user task assignments

* [Fix apache#3415] Gonzalos comments
  • Loading branch information
fjtirado authored and rgdoliveira committed Mar 11, 2024
1 parent 6dcb24c commit beb5d0f
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
194 changes: 138 additions & 56 deletions jbpm/jbpm-bpmn2/src/test/resources/BPMN2-UserTask.bpmn2
Original file line number Diff line number Diff line change
@@ -1,64 +1,146 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="Definition"
targetNamespace="http://www.example.org/MinimalExample"
typeLanguage="http://www.java.com/javaTypes"
expressionLanguage="http://www.mvel.org/2.0"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
xmlns:tns="http://www.jboss.org/drools">

<itemDefinition id="_sItem" structureRef="String" />
<process processType="Private" isExecutable="true" id="UserTask" name="User Task" >
<property id="s" itemSubjectRef="_sItem"/>
<!-- nodes -->
<startEvent id="_1" name="StartProcess" />
<userTask id="_2" name="Hello" >
<ioSpecification>
<inputSet>
</inputSet>
<outputSet>
</outputSet>
</ioSpecification>
<potentialOwner>
<resourceAssignmentExpression>
<formalExpression>john</formalExpression>
</resourceAssignmentExpression>
</potentialOwner>
</userTask>
<endEvent id="_3" name="EndProcess" >
<terminateEventDefinition/>
</endEvent>

<!-- connections -->
<sequenceFlow id="_1-_2" sourceRef="_1" targetRef="_2" />
<sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3" />

</process>

<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:bpsim="http://www.bpsim.org/schemas/1.0" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:drools="http://www.jboss.org/drools" id="_1aP80Le_EDyttMyrW6hRzg" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd http://www.jboss.org/drools drools.xsd http://www.bpsim.org/schemas/1.0 bpsim.xsd http://www.omg.org/spec/DD/20100524/DC DC.xsd http://www.omg.org/spec/DD/20100524/DI DI.xsd " exporter="jBPM Process Modeler" exporterVersion="2.0" targetNamespace="http://www.omg.org/bpmn20">
<bpmn2:itemDefinition id="_sItem" structureRef="String"/>
<bpmn2:itemDefinition id="__2_SkippableInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__2_PriorityInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__2_CommentInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__2_DescriptionInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__2_CreatedByInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__2_TaskNameInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__2_GroupIdInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__2_ContentInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__2_NotStartedReassignInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__2_NotCompletedReassignInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__2_NotStartedNotifyInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__2_NotCompletedNotifyInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__2_fixedValueInputXItem" structureRef="String"/>
<bpmn2:collaboration id="_D7750A25-5E14-45E3-A2DA-93F7E305C4AB" name="Default Collaboration">
<bpmn2:participant id="_BACF0FB2-F397-4F2D-9041-5D68D40E6875" name="Pool Participant" processRef="BPMN2_UserTask"/>
</bpmn2:collaboration>
<bpmn2:process id="UserTask" isExecutable="true" processType="Private" name="User Task">
<bpmn2:property id="s" itemSubjectRef="_sItem" name="s"/>
<bpmn2:sequenceFlow id="_1-_2" sourceRef="_1" targetRef="_2"/>
<bpmn2:sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3"/>
<bpmn2:startEvent id="_1" name="StartProcess">
<bpmn2:extensionElements>
<drools:metaData name="elementname">
<drools:metaValue><![CDATA[StartProcess]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
<bpmn2:outgoing>_1-_2</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:userTask id="_2" name="Hello">
<bpmn2:extensionElements>
<drools:metaData name="elementname">
<drools:metaValue><![CDATA[Hello]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
<bpmn2:incoming>_1-_2</bpmn2:incoming>
<bpmn2:outgoing>_2-_3</bpmn2:outgoing>
<bpmn2:ioSpecification>
<bpmn2:dataInput id="_2_TaskNameInputX" drools:dtype="Object" itemSubjectRef="__2_TaskNameInputXItem" name="TaskName"/>
<bpmn2:dataInput id="_2_fixedValueInputX" drools:dtype="String" itemSubjectRef="__2_fixedValueInputXItem" name="fixedValue"/>
<bpmn2:dataInput id="_2_SkippableInputX" drools:dtype="Object" itemSubjectRef="__2_SkippableInputXItem" name="Skippable"/>
<bpmn2:inputSet>
<bpmn2:dataInputRefs>_2_TaskNameInputX</bpmn2:dataInputRefs>
<bpmn2:dataInputRefs>_2_fixedValueInputX</bpmn2:dataInputRefs>
<bpmn2:dataInputRefs>_2_SkippableInputX</bpmn2:dataInputRefs>
</bpmn2:inputSet>
</bpmn2:ioSpecification>
<bpmn2:dataInputAssociation>
<bpmn2:targetRef>_2_TaskNameInputX</bpmn2:targetRef>
<bpmn2:assignment>
<bpmn2:from xsi:type="bpmn2:tFormalExpression"><![CDATA[Task]]></bpmn2:from>
<bpmn2:to xsi:type="bpmn2:tFormalExpression"><![CDATA[_2_TaskNameInputX]]></bpmn2:to>
</bpmn2:assignment>
</bpmn2:dataInputAssociation>
<bpmn2:dataInputAssociation>
<bpmn2:targetRef>_2_fixedValueInputX</bpmn2:targetRef>
<bpmn2:assignment>
<bpmn2:from xsi:type="bpmn2:tFormalExpression"><![CDATA[pepe]]></bpmn2:from>
<bpmn2:to xsi:type="bpmn2:tFormalExpression"><![CDATA[_2_fixedValueInputX]]></bpmn2:to>
</bpmn2:assignment>
</bpmn2:dataInputAssociation>
<bpmn2:dataInputAssociation>
<bpmn2:targetRef>_2_SkippableInputX</bpmn2:targetRef>
<bpmn2:assignment>
<bpmn2:from xsi:type="bpmn2:tFormalExpression"><![CDATA[false]]></bpmn2:from>
<bpmn2:to xsi:type="bpmn2:tFormalExpression"><![CDATA[_2_SkippableInputX]]></bpmn2:to>
</bpmn2:assignment>
</bpmn2:dataInputAssociation>
<bpmn2:potentialOwner id="_1aVcYLe_EDyttMyrW6hRzg">
<bpmn2:resourceAssignmentExpression id="_1aVcYbe_EDyttMyrW6hRzg">
<bpmn2:formalExpression>john</bpmn2:formalExpression>
</bpmn2:resourceAssignmentExpression>
</bpmn2:potentialOwner>
</bpmn2:userTask>
<bpmn2:endEvent id="_3" name="EndProcess">
<bpmn2:extensionElements>
<drools:metaData name="elementname">
<drools:metaValue><![CDATA[EndProcess]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
<bpmn2:incoming>_2-_3</bpmn2:incoming>
<bpmn2:terminateEventDefinition/>
</bpmn2:endEvent>
</bpmn2:process>
<bpmndi:BPMNDiagram>
<bpmndi:BPMNPlane bpmnElement="UserTask" >
<bpmndi:BPMNShape bpmnElement="_1" >
<dc:Bounds x="16" y="16" width="48" height="48" />
<bpmndi:BPMNPlane bpmnElement="BPMN2_UserTask">
<bpmndi:BPMNShape id="shape__3" bpmnElement="_3">
<dc:Bounds height="56" width="56" x="228" y="16"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_2" >
<dc:Bounds x="96" y="16" width="100" height="48" />
<bpmndi:BPMNShape id="shape__2" bpmnElement="_2">
<dc:Bounds height="48" width="100" x="96" y="16"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_3" >
<dc:Bounds x="228" y="16" width="48" height="48" />
<bpmndi:BPMNShape id="shape__1" bpmnElement="_1">
<dc:Bounds height="56" width="56" x="16" y="16"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="_1-_2" >
<di:waypoint x="40" y="40" />
<di:waypoint x="146" y="40" />
<bpmndi:BPMNEdge id="edge_shape__2_to_shape__3" bpmnElement="_2-_3">
<di:waypoint x="146" y="40"/>
<di:waypoint x="252" y="40"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_2-_3" >
<di:waypoint x="146" y="40" />
<di:waypoint x="252" y="40" />
<bpmndi:BPMNEdge id="edge_shape__1_to_shape__2" bpmnElement="_1-_2">
<di:waypoint x="40" y="40"/>
<di:waypoint x="146" y="40"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>

</definitions>
<bpmn2:relationship type="BPSimData">
<bpmn2:extensionElements>
<bpsim:BPSimData>
<bpsim:Scenario id="default" name="Simulationscenario">
<bpsim:ScenarioParameters/>
<bpsim:ElementParameters elementRef="_2">
<bpsim:TimeParameters>
<bpsim:ProcessingTime>
<bpsim:NormalDistribution mean="0" standardDeviation="0"/>
</bpsim:ProcessingTime>
</bpsim:TimeParameters>
<bpsim:ResourceParameters>
<bpsim:Availability>
<bpsim:FloatingParameter value="0"/>
</bpsim:Availability>
<bpsim:Quantity>
<bpsim:FloatingParameter value="0"/>
</bpsim:Quantity>
</bpsim:ResourceParameters>
<bpsim:CostParameters>
<bpsim:UnitCost>
<bpsim:FloatingParameter value="0"/>
</bpsim:UnitCost>
</bpsim:CostParameters>
</bpsim:ElementParameters>
<bpsim:ElementParameters elementRef="_1">
<bpsim:TimeParameters>
<bpsim:ProcessingTime>
<bpsim:NormalDistribution mean="0" standardDeviation="0"/>
</bpsim:ProcessingTime>
</bpsim:TimeParameters>
</bpsim:ElementParameters>
</bpsim:Scenario>
</bpsim:BPSimData>
</bpmn2:extensionElements>
<bpmn2:source>_1aP80Le_EDyttMyrW6hRzg</bpmn2:source>
<bpmn2:target>_1aP80Le_EDyttMyrW6hRzg</bpmn2:target>
</bpmn2:relationship>
</bpmn2:definitions>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
}

Expand Down Expand Up @@ -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()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down

0 comments on commit beb5d0f

Please sign in to comment.