Skip to content

Commit

Permalink
added expression resolver for activity name
Browse files Browse the repository at this point in the history
  • Loading branch information
WelschChristopher committed Jan 15, 2024
1 parent d190b4d commit db3efa7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import java.util.Map;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.FlowNode;
import org.flowable.bpmn.model.SequenceFlow;
import org.flowable.common.engine.api.delegate.Expression;
import org.flowable.common.engine.impl.cfg.IdGenerator;
import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.engine.impl.ActivityInstanceQueryImpl;
Expand Down Expand Up @@ -350,7 +352,13 @@ protected ActivityInstanceEntity createActivityInstanceEntity(ExecutionEntity ex
}

if (execution.getCurrentFlowElement() != null) {
activityInstanceEntity.setActivityName(execution.getCurrentFlowElement().getName());
if (StringUtils.isNotEmpty(execution.getCurrentFlowElement().getName())) {
Expression activityNameExpression = CommandContextUtil.getProcessEngineConfiguration().getExpressionManager()
.createExpression(execution.getCurrentFlowElement().getName());
activityInstanceEntity.setActivityName(activityNameExpression.getValue(execution).toString());
} else {
activityInstanceEntity.setActivityName(execution.getCurrentFlowElement().getName());
}
activityInstanceEntity.setActivityType(parseActivityType(execution.getCurrentFlowElement()));
}
Date now = getClock().getCurrentTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,4 +520,14 @@ public void upgradeFromHistoryToRuntimeActivities_changeOwner() {
assertProcessEnded(processInstance.getId());
}

@Test
@Deployment(resources = { "org/flowable/engine/test/api/oneTaskProcessWithExpression.bpmn20.xml" })
public void testActivityNameIsResolved() {
ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder().processDefinitionKey("oneTaskProcess")
.variable("testVar", "someTestValue").start();
ActivityInstance taskActivity = runtimeService.createActivityInstanceQuery().activityId("theTask").processInstanceId(processInstance.getId())
.singleResult();
assertThat(taskActivity.getActivityName()).isEqualTo("someTestValue");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:activiti="http://activiti.org/bpmn"
targetNamespace="ExamplesCategory">

<process id="oneTaskProcess" name="The One Task Process">
<documentation>This is a process for testing purposes</documentation>

<startEvent id="theStart" />
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="theTask" />
<userTask id="theTask" name="${testVar}" />
<sequenceFlow id="flow2" sourceRef="theTask" targetRef="theEnd" />
<endEvent id="theEnd" />

</process>

</definitions>

0 comments on commit db3efa7

Please sign in to comment.