Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.apache.commons.lang3.StringUtils;
import org.flowable.cmmn.api.CallbackTypes;
import org.flowable.cmmn.api.CmmnRuntimeService;
import org.flowable.cmmn.api.repository.CaseDefinition;
import org.flowable.cmmn.api.runtime.CaseInstance;
import org.flowable.cmmn.api.runtime.CaseInstanceBuilder;
import org.flowable.cmmn.api.runtime.CaseInstanceState;
Expand Down Expand Up @@ -51,21 +52,16 @@ public String generateNewCaseInstanceId() {
}

@Override
public String startCaseInstanceByKey(String caseDefinitionKey, String predefinedCaseInstanceId, String caseInstanceName, String businessKey,
String executionId,
String tenantId, boolean fallbackToDefaultTenant, String parentDeploymentId, Map<String, Object> inParametersMap) {

public String startCaseInstance(String caseDefinitionId, String predefinedCaseInstanceId, String caseInstanceName, String businessKey,
String executionId, String tenantId, Map<String, Object> inParametersMap) {

CaseInstanceBuilder caseInstanceBuilder = cmmnEngineConfiguration.getCmmnRuntimeService().createCaseInstanceBuilder();
caseInstanceBuilder.caseDefinitionKey(caseDefinitionKey);
caseInstanceBuilder.caseDefinitionId(caseDefinitionId);

if (parentDeploymentId != null) {
caseInstanceBuilder.caseDefinitionParentDeploymentId(parentDeploymentId);
}

if (predefinedCaseInstanceId != null) {
caseInstanceBuilder.predefinedCaseInstanceId(predefinedCaseInstanceId);
}

if (tenantId != null) {
caseInstanceBuilder.tenantId(tenantId);
caseInstanceBuilder.overrideCaseDefinitionTenantId(tenantId);
Expand All @@ -80,18 +76,14 @@ public String startCaseInstanceByKey(String caseDefinitionKey, String predefined
caseInstanceBuilder.variable(target, inParametersMap.get(target));
}

if (fallbackToDefaultTenant) {
caseInstanceBuilder.fallbackToDefaultTenant();
}

if (businessKey != null) {
caseInstanceBuilder.businessKey(businessKey);
}

if (caseInstanceName != null) {
caseInstanceBuilder.name(caseInstanceName);
}

CaseInstance caseInstance = caseInstanceBuilder.start();
return caseInstance.getId();
}
Expand Down Expand Up @@ -142,6 +134,20 @@ public void deleteCaseInstancesForExecutionId(String executionId) {
}
}

@Override
public String resolveCaseDefinitionId(String caseDefinitionKey, String tenantId,
boolean fallbackToDefaultTenant, String parentDeploymentId) {
CaseDefinition caseDefinition = cmmnEngineConfiguration.getCaseInstanceHelper()
.resolveCaseDefinition(caseDefinitionKey, tenantId,
fallbackToDefaultTenant || cmmnEngineConfiguration.isFallbackToDefaultTenant(), parentDeploymentId);
return caseDefinition.getId();
}

@Override
public boolean isHistoryEnabledForCaseDefinitionId(String caseDefinitionId) {
return cmmnEngineConfiguration.getCmmnHistoryConfigurationSettings().isHistoryEnabled(caseDefinitionId);
}

@Override
public void deleteCaseInstanceWithoutAgenda(String caseInstanceId) {
cmmnEngineConfiguration.getCommandExecutor().execute(commandContext -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.flowable.engine.impl.persistence.entity.BpmnEngineEntityConstants;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.engine.runtime.ProcessInstanceBuilder;
import org.flowable.form.api.FormInfo;
Expand Down Expand Up @@ -56,30 +57,27 @@ public String generateNewProcessInstanceId() {
}

@Override
public String startProcessInstanceByKey(String processDefinitionKey, String predefinedProcessInstanceId, String stageInstanceId,
String tenantId, Boolean fallbackToDefaultTenant, String parentDeploymentId, Map<String, Object> inParametersMap, String businessKey,
public String startProcessInstance(String processDefinitionId, String predefinedProcessInstanceId, String stageInstanceId,
String tenantId, Map<String, Object> inParametersMap, String businessKey,
Map<String, Object> variableFormVariables, FormInfo variableFormInfo, String variableFormOutcome) {
return startProcessInstanceByKey(processDefinitionKey, predefinedProcessInstanceId, null, stageInstanceId, tenantId, fallbackToDefaultTenant,
parentDeploymentId, inParametersMap, businessKey, variableFormVariables, variableFormInfo, variableFormOutcome);

return startProcessInstance(processDefinitionId, predefinedProcessInstanceId, null, stageInstanceId, tenantId,
inParametersMap, businessKey, variableFormVariables, variableFormInfo, variableFormOutcome);
}

@Override
public String startProcessInstanceByKey(String processDefinitionKey, String predefinedProcessInstanceId, String planItemInstanceId, String stageInstanceId,
String tenantId, Boolean fallbackToDefaultTenant, String parentDeploymentId, Map<String, Object> inParametersMap, String businessKey,
public String startProcessInstance(String processDefinitionId, String predefinedProcessInstanceId, String planItemInstanceId, String stageInstanceId,
String tenantId, Map<String, Object> inParametersMap, String businessKey,
Map<String, Object> variableFormVariables, FormInfo variableFormInfo, String variableFormOutcome) {

ProcessInstanceBuilder processInstanceBuilder = processEngineConfiguration.getRuntimeService().createProcessInstanceBuilder();
processInstanceBuilder.processDefinitionKey(processDefinitionKey);
processInstanceBuilder.processDefinitionId(processDefinitionId);

if (tenantId != null) {
processInstanceBuilder.tenantId(tenantId);
processInstanceBuilder.overrideProcessDefinitionTenantId(tenantId);
}

if (parentDeploymentId != null) {
processInstanceBuilder.processDefinitionParentDeploymentId(parentDeploymentId);
}

processInstanceBuilder.predefineProcessInstanceId(predefinedProcessInstanceId);

if (planItemInstanceId != null) {
Expand All @@ -91,10 +89,6 @@ public String startProcessInstanceByKey(String processDefinitionKey, String pred
processInstanceBuilder.variable(target, inParametersMap.get(target));
}

if (fallbackToDefaultTenant != null && fallbackToDefaultTenant) {
processInstanceBuilder.fallbackToDefaultTenant();
}

if (businessKey != null) {
processInstanceBuilder.businessKey(businessKey);
}
Expand Down Expand Up @@ -146,6 +140,21 @@ public List<IOParameter> getOutputParametersOfCaseTask(String executionId) {
return cmmnParameters;
}

@Override
public String resolveProcessDefinitionId(String processDefinitionKey, String tenantId,
Boolean fallbackToDefaultTenant, String parentDeploymentId) {
ProcessDefinition processDefinition = processEngineConfiguration.getProcessInstanceHelper()
.resolveProcessDefinition(processDefinitionKey, tenantId,
Boolean.TRUE.equals(fallbackToDefaultTenant) || processEngineConfiguration.isFallbackToDefaultTenant(),
parentDeploymentId, processEngineConfiguration);
return processDefinition.getId();
}

@Override
public boolean isHistoryEnabledForProcessDefinitionId(String processDefinitionId) {
return processEngineConfiguration.getHistoryConfigurationSettings().isHistoryEnabled(processDefinitionId);
}

@Override
public void deleteProcessInstance(String processInstanceId) {
processEngineConfiguration.getCommandExecutor().execute(commandContext -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.cmmn.test;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;

import org.flowable.cmmn.api.repository.CmmnDeployment;
import org.flowable.cmmn.api.runtime.CaseInstance;
import org.flowable.common.engine.api.scope.ScopeTypes;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.entitylink.api.EntityLink;
import org.flowable.entitylink.api.history.HistoricEntityLink;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Tests that historic entity links are not created when the child sub-instance has history level NONE,
* even when the parent has history enabled.
*/
public class EntityLinkHistoryLevelTest extends AbstractProcessEngineIntegrationTest {

@BeforeEach
public void enableDefinitionHistoryLevel() {
processEngineConfiguration.setEnableProcessDefinitionHistoryLevel(true);
cmmnEngineConfiguration.setEnableCaseDefinitionHistoryLevel(true);
}

@AfterEach
public void disableDefinitionHistoryLevel() {
processEngineConfiguration.setEnableProcessDefinitionHistoryLevel(false);
cmmnEngineConfiguration.setEnableCaseDefinitionHistoryLevel(false);
}

@Test
public void testBpmnParentWithCmmnChildHistoryNone() {
CmmnDeployment cmmnDeployment = cmmnRepositoryService.createDeployment()
.addClasspathResource("org/flowable/cmmn/test/EntityLinkHistoryLevelTest.oneHumanTaskCaseHistoryNone.cmmn")
.deploy();
Deployment bpmnDeployment = processEngineRepositoryService.createDeployment()
.addClasspathResource("org/flowable/cmmn/test/EntityLinkHistoryLevelTest.caseTaskProcessHistoryNoneChild.bpmn20.xml")
.deploy();

try {
ProcessInstance processInstance = processEngineRuntimeService.startProcessInstanceByKey("caseTaskHistoryNoneChild");

// The case task should have started a child case instance
CaseInstance childCaseInstance = cmmnRuntimeService.createCaseInstanceQuery().singleResult();
assertThat(childCaseInstance).isNotNull();

// Runtime entity links should exist (parent process -> child case)
List<EntityLink> entityLinks = processEngineRuntimeService.getEntityLinkChildrenForProcessInstance(processInstance.getId());
assertThat(entityLinks).isNotEmpty();
assertThat(entityLinks)
.anyMatch(el -> ScopeTypes.CMMN.equals(el.getReferenceScopeType())
&& childCaseInstance.getId().equals(el.getReferenceScopeId()));

// Historic entity link to the child CMMN case should NOT exist because the child case has historyLevel=none
List<HistoricEntityLink> historicEntityLinks = processEngineHistoryService
.getHistoricEntityLinkChildrenForProcessInstance(processInstance.getId());
assertThat(historicEntityLinks)
.noneMatch(el -> ScopeTypes.CMMN.equals(el.getReferenceScopeType())
&& childCaseInstance.getId().equals(el.getReferenceScopeId()));

} finally {
cmmnRepositoryService.deleteDeployment(cmmnDeployment.getId(), true);
processEngineRepositoryService.deleteDeployment(bpmnDeployment.getId(), true);
}
}

@Test
public void testCmmnParentWithBpmnChildHistoryNone() {
CmmnDeployment cmmnDeployment = cmmnRepositoryService.createDeployment()
.addClasspathResource("org/flowable/cmmn/test/EntityLinkHistoryLevelTest.processTaskCaseHistoryNoneChild.cmmn")
.deploy();
Deployment bpmnDeployment = processEngineRepositoryService.createDeployment()
.addClasspathResource("org/flowable/cmmn/test/EntityLinkHistoryLevelTest.oneTaskProcessHistoryNone.bpmn20.xml")
.deploy();

try {
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder()
.caseDefinitionKey("processTaskCase")
.start();

// The process task should have started a child process instance
ProcessInstance childProcessInstance = processEngineRuntimeService.createProcessInstanceQuery().singleResult();
assertThat(childProcessInstance).isNotNull();

// Runtime entity links should exist (parent case -> child process)
List<EntityLink> entityLinks = cmmnRuntimeService.getEntityLinkChildrenForCaseInstance(caseInstance.getId());
assertThat(entityLinks).isNotEmpty();
assertThat(entityLinks)
.anyMatch(el -> ScopeTypes.BPMN.equals(el.getReferenceScopeType())
&& childProcessInstance.getId().equals(el.getReferenceScopeId()));

// Historic entity link to the child BPMN process should NOT exist because the child process has historyLevel=none
List<HistoricEntityLink> historicEntityLinks = cmmnHistoryService
.getHistoricEntityLinkChildrenForCaseInstance(caseInstance.getId());
assertThat(historicEntityLinks)
.noneMatch(el -> ScopeTypes.BPMN.equals(el.getReferenceScopeType())
&& childProcessInstance.getId().equals(el.getReferenceScopeId()));

} finally {
cmmnRepositoryService.deleteDeployment(cmmnDeployment.getId(), true);
processEngineRepositoryService.deleteDeployment(bpmnDeployment.getId(), true);
}
}

@Test
public void testBpmnParentWithBpmnChildHistoryNone() {
Deployment childDeployment = processEngineRepositoryService.createDeployment()
.addClasspathResource("org/flowable/cmmn/test/EntityLinkHistoryLevelTest.oneTaskProcessHistoryNone.bpmn20.xml")
.deploy();
Deployment parentDeployment = processEngineRepositoryService.createDeployment()
.addClasspathResource("org/flowable/cmmn/test/EntityLinkHistoryLevelTest.callActivityProcessHistoryNoneChild.bpmn20.xml")
.deploy();

try {
ProcessInstance processInstance = processEngineRuntimeService.startProcessInstanceByKey("callActivityHistoryNoneChild");

// The call activity should have started a child process instance
ProcessInstance childProcessInstance = processEngineRuntimeService.createProcessInstanceQuery()
.superProcessInstanceId(processInstance.getId())
.singleResult();
assertThat(childProcessInstance).isNotNull();

// Runtime entity links should exist (parent process -> child process)
List<EntityLink> entityLinks = processEngineRuntimeService.getEntityLinkChildrenForProcessInstance(processInstance.getId());
assertThat(entityLinks).isNotEmpty();
assertThat(entityLinks)
.anyMatch(el -> ScopeTypes.BPMN.equals(el.getReferenceScopeType())
&& childProcessInstance.getId().equals(el.getReferenceScopeId()));

// Historic entity link to the child BPMN process should NOT exist because the child process has historyLevel=none
List<HistoricEntityLink> historicEntityLinks = processEngineHistoryService
.getHistoricEntityLinkChildrenForProcessInstance(processInstance.getId());
assertThat(historicEntityLinks)
.noneMatch(el -> ScopeTypes.BPMN.equals(el.getReferenceScopeType())
&& childProcessInstance.getId().equals(el.getReferenceScopeId()));

} finally {
processEngineRepositoryService.deleteDeployment(parentDeployment.getId(), true);
processEngineRepositoryService.deleteDeployment(childDeployment.getId(), true);
}
}

@Test
public void testCmmnParentWithCmmnChildHistoryNone() {
CmmnDeployment childDeployment = cmmnRepositoryService.createDeployment()
.addClasspathResource("org/flowable/cmmn/test/EntityLinkHistoryLevelTest.oneHumanTaskCaseHistoryNone.cmmn")
.deploy();
CmmnDeployment parentDeployment = cmmnRepositoryService.createDeployment()
.addClasspathResource("org/flowable/cmmn/test/EntityLinkHistoryLevelTest.caseTaskCaseHistoryNoneChild.cmmn")
.deploy();

try {
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder()
.caseDefinitionKey("caseTaskCaseHistoryNoneChild")
.start();

// The case task should have started a child case instance
CaseInstance childCaseInstance = cmmnRuntimeService.createCaseInstanceQuery()
.caseInstanceParentId(caseInstance.getId())
.singleResult();
assertThat(childCaseInstance).isNotNull();

// Runtime entity links should exist (parent case -> child case)
List<EntityLink> entityLinks = cmmnRuntimeService.getEntityLinkChildrenForCaseInstance(caseInstance.getId());
assertThat(entityLinks).isNotEmpty();
assertThat(entityLinks)
.anyMatch(el -> ScopeTypes.CMMN.equals(el.getReferenceScopeType())
&& childCaseInstance.getId().equals(el.getReferenceScopeId()));

// Historic entity link to the child CMMN case should NOT exist because the child case has historyLevel=none
List<HistoricEntityLink> historicEntityLinks = cmmnHistoryService
.getHistoricEntityLinkChildrenForCaseInstance(caseInstance.getId());
assertThat(historicEntityLinks)
.noneMatch(el -> ScopeTypes.CMMN.equals(el.getReferenceScopeType())
&& childCaseInstance.getId().equals(el.getReferenceScopeId()));

} finally {
cmmnRepositoryService.deleteDeployment(parentDeployment.getId(), true);
cmmnRepositoryService.deleteDeployment(childDeployment.getId(), true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:flowable="http://flowable.org/bpmn"
targetNamespace="http://flowable.org/bpmn">
<process id="callActivityHistoryNoneChild">
<startEvent id="theStart" />
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="callActivity" />
<callActivity id="callActivity" calledElement="oneTaskHistoryNone" />
<sequenceFlow id="flow2" sourceRef="callActivity" targetRef="afterCallActivity" />
<userTask id="afterCallActivity" name="After call activity" />
<sequenceFlow id="flow3" sourceRef="afterCallActivity" targetRef="theEnd" />
<endEvent id="theEnd" />
</process>
</definitions>
Loading