Skip to content

Commit 082fafc

Browse files
Fix issue with json variable aggregation update
1 parent c555cdc commit 082fafc

10 files changed

Lines changed: 462 additions & 2 deletions

‎modules/flowable-cmmn-engine-configurator/src/main/java/org/flowable/cmmn/engine/configurator/impl/process/DefaultProcessInstanceService.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ public boolean isHistoryEnabledForProcessInstance(String processInstanceId) {
165165
return processEngineConfiguration.getHistoryConfigurationSettings().isHistoryEnabled();
166166
}
167167

168+
@Override
169+
public String getRootProcessInstanceId(String processInstanceId) {
170+
ExecutionEntity execution = processEngineConfiguration.getExecutionEntityManager().findById(processInstanceId);
171+
if (execution == null) {
172+
return processInstanceId;
173+
}
174+
String rootProcessInstanceId = execution.getRootProcessInstanceId();
175+
return rootProcessInstanceId != null ? rootProcessInstanceId : processInstanceId;
176+
}
177+
168178
@Override
169179
public void deleteProcessInstance(String processInstanceId) {
170180
processEngineConfiguration.getCommandExecutor().execute(commandContext -> {

‎modules/flowable-cmmn-engine-configurator/src/test/java/org/flowable/cmmn/test/BpmnVariableAggregationCmmnHistoryTest.java‎

Lines changed: 292 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definitions id="definition"
3+
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:flowable="http://flowable.org/bpmn"
6+
targetNamespace="Examples">
7+
8+
<process id="myProcess">
9+
10+
<startEvent id="theStart" />
11+
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="miTasks" />
12+
13+
<userTask id="miTasks" name="Review">
14+
<multiInstanceLoopCharacteristics isSequential="false">
15+
<extensionElements>
16+
<flowable:variableAggregation target="reviews">
17+
<variable source="approved" target="approved" />
18+
<variable source="description" target="description" />
19+
</flowable:variableAggregation>
20+
</extensionElements>
21+
<loopCardinality>3</loopCardinality>
22+
</multiInstanceLoopCharacteristics>
23+
</userTask>
24+
25+
<sequenceFlow id="flow2" sourceRef="miTasks" targetRef="afterTask" />
26+
<userTask id="afterTask" name="After" />
27+
28+
<sequenceFlow id="flow3" sourceRef="afterTask" targetRef="theEnd" />
29+
<endEvent id="theEnd" />
30+
31+
</process>
32+
33+
</definitions>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definitions xmlns="http://www.omg.org/spec/CMMN/20151109/MODEL"
3+
xmlns:flowable="http://flowable.org/cmmn"
4+
targetNamespace="http://flowable.org/cmmn">
5+
<case id="aggregationCase">
6+
<casePlanModel id="casePlanModel1" name="Aggregation case">
7+
<planItem id="planItemProcessTask1" definitionRef="processTask1" />
8+
<processTask id="processTask1" name="Run MI process">
9+
<processRefExpression>myProcess</processRefExpression>
10+
</processTask>
11+
</casePlanModel>
12+
</case>
13+
</definitions>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definitions id="definition"
3+
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:flowable="http://flowable.org/bpmn"
6+
targetNamespace="Examples">
7+
8+
<process id="outerProcess" isExecutable="true">
9+
<startEvent id="theStart" />
10+
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="callInner" />
11+
<callActivity id="callInner" calledElement="myProcess" />
12+
<sequenceFlow id="flow2" sourceRef="callInner" targetRef="theEnd" />
13+
<endEvent id="theEnd" />
14+
</process>
15+
16+
</definitions>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definitions id="definition"
3+
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:flowable="http://flowable.org/bpmn"
6+
targetNamespace="Examples">
7+
8+
<process id="rootProcessWithCaseTask" isExecutable="true">
9+
<startEvent id="theStart" />
10+
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="caseTask" />
11+
<serviceTask id="caseTask" flowable:type="case" flowable:caseDefinitionKey="subAggregationCase" />
12+
<sequenceFlow id="flow2" sourceRef="caseTask" targetRef="theEnd" />
13+
<endEvent id="theEnd" />
14+
</process>
15+
16+
</definitions>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definitions xmlns="http://www.omg.org/spec/CMMN/20151109/MODEL"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:flowable="http://flowable.org/cmmn"
5+
targetNamespace="http://flowable.org/cmmn">
6+
<case id="subAggregationCase">
7+
<casePlanModel id="subCasePlanModel" name="Sub aggregation case">
8+
<planItem id="planItemReview" name="Review" definitionRef="reviewTask">
9+
<itemControl>
10+
<repetitionRule flowable:ignoreCounterVariable="true">
11+
<extensionElements>
12+
<flowable:variableAggregation target="reviews">
13+
<variable source="approved" target="approved" />
14+
<variable source="description" target="description" />
15+
</flowable:variableAggregation>
16+
</extensionElements>
17+
<condition><![CDATA[${repetitionCounter < 3}]]></condition>
18+
</repetitionRule>
19+
</itemControl>
20+
</planItem>
21+
<humanTask id="reviewTask" name="Review" />
22+
</casePlanModel>
23+
</case>
24+
</definitions>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definitions xmlns="http://www.omg.org/spec/CMMN/20151109/MODEL"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:flowable="http://flowable.org/cmmn"
5+
targetNamespace="http://flowable.org/cmmn">
6+
<case id="transitiveCase">
7+
<casePlanModel id="transitiveCasePlanModel" name="Transitive case">
8+
<planItem id="planItemOuterProcess" definitionRef="outerProcessTask" />
9+
<processTask id="outerProcessTask" name="Run outer process">
10+
<processRefExpression>outerProcess</processRefExpression>
11+
</processTask>
12+
</casePlanModel>
13+
</case>
14+
</definitions>

‎modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/DefaultCmmnHistoryConfigurationSettings.java‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
package org.flowable.cmmn.engine.impl.history;
1414

15+
import java.util.List;
16+
1517
import org.apache.commons.lang3.StringUtils;
1618
import org.flowable.cmmn.api.repository.CaseDefinition;
1719
import org.flowable.cmmn.engine.CmmnEngineConfiguration;
@@ -25,6 +27,7 @@
2527
import org.flowable.cmmn.model.ExtensionElement;
2628
import org.flowable.cmmn.model.PlanItem;
2729
import org.flowable.cmmn.model.PlanItemDefinition;
30+
import org.flowable.common.engine.api.constant.ReferenceTypes;
2831
import org.flowable.common.engine.api.scope.ScopeTypes;
2932
import org.flowable.common.engine.impl.history.HistoryLevel;
3033
import org.flowable.entitylink.service.impl.persistence.entity.EntityLinkEntity;
@@ -218,12 +221,41 @@ protected boolean hasTaskHistoryLevel(HistoryLevel historyLevel) {
218221
public boolean isHistoryEnabledForVariableInstance(VariableInstanceEntity variableInstanceEntity) {
219222
String caseDefinitionId = null;
220223
if (isEnableCaseDefinitionHistoryLevel() && variableInstanceEntity.getScopeId() != null) {
221-
CaseInstanceEntity caseInstance = cmmnEngineConfiguration.getCaseInstanceEntityManager().findById(variableInstanceEntity.getScopeId());
222-
caseDefinitionId = caseInstance.getCaseDefinitionId();
224+
caseDefinitionId = getCaseDefinitionId(variableInstanceEntity);
223225
}
224226
return isHistoryLevelAtLeast(HistoryLevel.AUDIT, caseDefinitionId);
225227
}
226228

229+
protected String getCaseDefinitionId(VariableInstanceEntity variableInstanceEntity) {
230+
String scopeId = variableInstanceEntity.getScopeId();
231+
232+
// A case (or case sub-scope) variable stores the case instance id as its scopeId.
233+
CaseInstanceEntity caseInstance = cmmnEngineConfiguration.getCaseInstanceEntityManager().findById(scopeId);
234+
if (caseInstance != null) {
235+
return caseInstance.getCaseDefinitionId();
236+
}
237+
238+
// The scopeId is not a case instance id. This happens for a variable that belongs to a process running
239+
// under a case, e.g. a BPMN multi-instance variable-aggregation variable whose scopeId is the process
240+
// instance id (see BpmnAggregation). The process may itself be nested under the case through one or more
241+
// BPMN call activities, so resolve the root process instance of the call hierarchy - that is the process
242+
// a CMMN process task started directly - and use the plan item instance that started it (its referenceId
243+
// is that root process instance id) to determine the owning case definition.
244+
ProcessInstanceService processInstanceService = cmmnEngineConfiguration.getProcessInstanceService();
245+
if (processInstanceService != null) {
246+
String rootProcessInstanceId = processInstanceService.getRootProcessInstanceId(scopeId);
247+
List<PlanItemInstanceEntity> planItemInstances = cmmnEngineConfiguration.getPlanItemInstanceEntityManager()
248+
.findByReferenceId(rootProcessInstanceId);
249+
for (PlanItemInstanceEntity planItemInstance : planItemInstances) {
250+
if (ReferenceTypes.PLAN_ITEM_CHILD_PROCESS.equals(planItemInstance.getReferenceType())) {
251+
return planItemInstance.getCaseDefinitionId();
252+
}
253+
}
254+
}
255+
256+
return null;
257+
}
258+
227259
@Override
228260
public boolean isHistoryEnabledForIdentityLink(IdentityLinkEntity identityLinkEntity) {
229261
String caseDefinitionId = getCaseDefinitionId(identityLinkEntity);

‎modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/process/ProcessInstanceService.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,14 @@ String resolveProcessDefinitionId(String processDefinitionKey, String tenantId,
9090
*/
9191
boolean isHistoryEnabledForProcessInstance(String processInstanceId);
9292

93+
/**
94+
* Returns the id of the root process instance of the call hierarchy the given process instance belongs to.
95+
* For a top-level process instance this is the process instance id itself; for a process instance started
96+
* through one or more BPMN call activities it is the outermost process instance. Used to resolve the owning
97+
* case of a variable that belongs to a process nested under a case.
98+
*/
99+
default String getRootProcessInstanceId(String processInstanceId) {
100+
return processInstanceId;
101+
}
102+
93103
}

0 commit comments

Comments
 (0)