Skip to content

Commit

Permalink
Evaluate completer variable name in CMMN
Browse files Browse the repository at this point in the history
  • Loading branch information
Stoeoeoe authored and jbarrez committed Jun 8, 2023
1 parent 5a0a3c8 commit 2ff3f04
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,13 @@ public void onStateTransition(CommandContext commandContext, DelegatePlanItemIns
}
} else if (PlanItemTransition.COMPLETE.equals(transition)) {
if (humanTask.getTaskCompleterVariableName() != null) {
String taskCompleterVariableName = humanTask.getTaskCompleterVariableName();

ExpressionManager expressionManager = CommandContextUtil.getExpressionManager(commandContext);
Expression expression = expressionManager.createExpression(humanTask.getTaskCompleterVariableName());
String completerVariableName = (String) expression.getValue(planItemInstance);
String completer = Authentication.getAuthenticatedUserId();
planItemInstance.setVariable(taskCompleterVariableName, completer);

planItemInstance.setVariable(completerVariableName, completer);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ public void testHumanTaskCompleterVariableName() {

CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder()
.caseDefinitionKey("myCase")
.variable("dynamicVariable", "myDynamicVariable")
.start();

// Normal string
Expand All @@ -440,8 +441,16 @@ public void testHumanTaskCompleterVariableName() {
Task secondTask = cmmnTaskService.createTaskQuery().caseInstanceId(caseInstance.getId()).taskDefinitionKey("task2").singleResult();
assertThat(secondTask).isNotNull();
cmmnTaskService.complete(secondTask.getId());
Object completerTask2 = cmmnRuntimeService.getVariable(caseInstance.getId(), "completerTask2");
String completerTask2 = (String)cmmnRuntimeService.getVariable(caseInstance.getId(), "completerTask2");
assertThat(completerTask2).isNull();

// Expression
Authentication.setAuthenticatedUserId("DynamicDoe");
Task thirdTask = cmmnTaskService.createTaskQuery().caseInstanceId(caseInstance.getId()).taskDefinitionKey("task3").singleResult();
assertThat(thirdTask).isNotNull();
cmmnTaskService.complete(thirdTask.getId());
String completerTask3 = (String)cmmnRuntimeService.getVariable(caseInstance.getId(), "myDynamicVariable");
assertThat(completerTask3).isEqualTo("DynamicDoe");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@

<planItem id="planItem1" name="Task One" definitionRef="task1" />
<planItem id="planItem2" name="Task Two" definitionRef="task2" />
<planItem id="planItem3" name="Task Three" definitionRef="task3" />
<planItem id="planItem4" name="Dummy Task" definitionRef="task4" />

<humanTask id="task1" name="Task One" flowable:taskCompleterVariableName="completerTask1" />
<humanTask id="task2" name="Task Two" flowable:taskCompleterVariableName="completerTask2" />

<humanTask id="task3" name="Task Three" flowable:taskCompleterVariableName="${dynamicVariable}" />
<humanTask id="task4" name="Dummy Task" />
</casePlanModel>
</case>

Expand Down

0 comments on commit 2ff3f04

Please sign in to comment.