Skip to content

Commit

Permalink
Allow exit criterion on non blocking task to prevent loss on case mod…
Browse files Browse the repository at this point in the history
…el import
  • Loading branch information
tijsrademakers committed Aug 28, 2024
1 parent 51c7631 commit d4d26c8
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

import org.apache.commons.lang3.StringUtils;
import org.flowable.cmmn.converter.exception.XMLException;
import org.flowable.cmmn.converter.export.AssociationExport;
import org.flowable.cmmn.converter.export.CaseExport;
Expand Down Expand Up @@ -71,7 +70,6 @@
import org.flowable.cmmn.model.Sentry;
import org.flowable.cmmn.model.SentryOnPart;
import org.flowable.cmmn.model.Stage;
import org.flowable.cmmn.model.Task;
import org.flowable.cmmn.model.TextAnnotation;
import org.flowable.cmmn.model.TimerEventListener;
import org.flowable.common.engine.api.FlowableException;
Expand Down Expand Up @@ -528,20 +526,7 @@ protected void procesPlanItem(CmmnModel cmmnModel, PlanItem planItem, PlanItemDe
}

if (!planItem.getExitCriteria().isEmpty()) {
boolean exitCriteriaAllowed = true;
if (planItemDefinition instanceof Task) {
Task task = (Task) planItemDefinition;
if (!task.isBlocking() && StringUtils.isEmpty(task.getBlockingExpression())) {
exitCriteriaAllowed = false;
}
}

if (exitCriteriaAllowed) {
resolveExitCriteriaSentry(planItem);
} else {
LOGGER.warn("Ignoring exit criteria on plan item {}", planItem.getId());
planItem.getExitCriteria().clear();
}
resolveExitCriteriaSentry(planItem);
}

if (planItemDefinition instanceof Stage) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* 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.test.cmmn.converter;

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

import org.flowable.cmmn.model.CmmnModel;
import org.flowable.cmmn.model.HumanTask;
import org.flowable.cmmn.model.PlanItem;
import org.flowable.cmmn.model.PlanItemDefinition;
import org.flowable.test.cmmn.converter.util.CmmnXmlConverterTest;

public class HumanTaskWithEntryAndExitCriterionCmmnXmlConverterTest {

@CmmnXmlConverterTest("org/flowable/test/cmmn/converter/humanTaskWithEntryAndExitCriterion.cmmn")
public void validateModel(CmmnModel cmmnModel) {
assertThat(cmmnModel).isNotNull();

PlanItemDefinition itemDefinition = cmmnModel.findPlanItemDefinition("task1");

assertThat(itemDefinition).isInstanceOf(HumanTask.class);
PlanItem planItem = cmmnModel.findPlanItem("planItem1");
assertThat(planItem.getEntryCriteria()).hasSize(1);
assertThat(planItem.getExitCriteria()).hasSize(1);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/CMMN/20151109/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flowable="http://flowable.org/cmmn" xmlns:cmmndi="http://www.omg.org/spec/CMMN/20151109/CMMNDI" xmlns:dc="http://www.omg.org/spec/CMMN/20151109/DC" xmlns:di="http://www.omg.org/spec/CMMN/20151109/DI" xmlns:design="http://flowable.org/design" targetNamespace="http://flowable.org/cmmn" design:palette="flowable-engage-case-palette">
<case id="test">
<casePlanModel id="onecaseplanmodel1">
<planItem id="planItemexpandedStage1" name="Stage 1" definitionRef="expandedStage1"></planItem>
<stage id="expandedStage1" name="Stage 1">
<planItem id="planItem1" definitionRef="task1">
<itemControl>
<extensionElements>
<flowable:completionNeutralRule></flowable:completionNeutralRule>
</extensionElements>
<repetitionRule flowable:counterVariable="repetitionCounter" flowable:maxInstanceCount="1">
<extensionElements></extensionElements>
</repetitionRule>
<manualActivationRule></manualActivationRule>
</itemControl>
<entryCriterion id="entryCriterion5" sentryRef="sentryentryCriterion5"></entryCriterion>
<exitCriterion id="exitCriterion1" sentryRef="sentryexitCriterion1"></exitCriterion>
</planItem>
<sentry id="sentryentryCriterion5" />
<sentry id="sentryexitCriterion1" />
<humanTask id="task1" isBlocking="false" />
</stage>
</casePlanModel>
</case>
</definitions>
Original file line number Diff line number Diff line change
Expand Up @@ -596,4 +596,28 @@ public Void execute(CommandContext commandContext) {
cmmnEngineConfiguration.getJobServiceConfiguration().setJobHandlers(existingJobHandlers);
}
}

@Test
@CmmnDeployment
public void testTaskNonBlockingWithEntryAndExitCriterion() {
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder()
.caseDefinitionKey("myCase")
.start();

assertThat(cmmnRuntimeService.createPlanItemInstanceQuery().caseInstanceId(caseInstance.getId()).planItemDefinitionId("task1").list()).hasSize(1);
assertThat(cmmnRuntimeService.createPlanItemInstanceQuery().caseInstanceId(caseInstance.getId())
.planItemDefinitionId("task1")
.planItemInstanceStateEnabled().list()).hasSize(1);

cmmnRuntimeService.startPlanItemInstance(cmmnRuntimeService.createPlanItemInstanceQuery().caseInstanceId(caseInstance.getId())
.planItemDefinitionId("task1")
.planItemInstanceStateEnabled().singleResult().getId());

assertThat(cmmnRuntimeService.createPlanItemInstanceQuery().caseInstanceId(caseInstance.getId())
.planItemDefinitionId("task1")
.planItemInstanceStateActive().list()).hasSize(0);

assertThat(cmmnTaskService.createTaskQuery().caseInstanceId(caseInstance.getId()).list()).hasSize(0);
assertThat(cmmnRuntimeService.createCaseInstanceQuery().count()).isZero();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/CMMN/20151109/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flowable="http://flowable.org/cmmn" xmlns:cmmndi="http://www.omg.org/spec/CMMN/20151109/CMMNDI" xmlns:dc="http://www.omg.org/spec/CMMN/20151109/DC" xmlns:di="http://www.omg.org/spec/CMMN/20151109/DI" xmlns:design="http://flowable.org/design" targetNamespace="http://flowable.org/cmmn" design:palette="flowable-engage-case-palette">
<case id="myCase">
<casePlanModel id="onecaseplanmodel1">
<planItem id="planItemexpandedStage1" name="Stage 1" definitionRef="expandedStage1"></planItem>
<stage id="expandedStage1" name="Stage 1">
<planItem id="planItem1" definitionRef="task1">
<itemControl>
<manualActivationRule></manualActivationRule>
</itemControl>
<entryCriterion id="entryCriterion5" sentryRef="sentryentryCriterion5"></entryCriterion>
<exitCriterion id="exitCriterion1" sentryRef="sentryexitCriterion1"></exitCriterion>
</planItem>
<sentry id="sentryentryCriterion5" />
<sentry id="sentryexitCriterion1">
<ifPart>
<condition>${false}</condition>
</ifPart>
</sentry>
<humanTask id="task1" isBlocking="false" />
</stage>
</casePlanModel>
</case>
</definitions>

0 comments on commit d4d26c8

Please sign in to comment.