From 4d0a22b0ff7415743ced7ae345b3029b3a702cc5 Mon Sep 17 00:00:00 2001 From: Simon Amport <10498683+amporsim@users.noreply.github.com> Date: Mon, 18 Sep 2023 09:34:06 +0200 Subject: [PATCH] Expose filtering by caseDefinitionIds (#3730) --- .../cmmn/api/runtime/CaseInstanceQuery.java | 1 + .../impl/runtime/CaseInstanceQueryImpl.java | 14 ++++++++ .../runtime/CaseInstanceQueryImplTest.java | 34 +++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/modules/flowable-cmmn-api/src/main/java/org/flowable/cmmn/api/runtime/CaseInstanceQuery.java b/modules/flowable-cmmn-api/src/main/java/org/flowable/cmmn/api/runtime/CaseInstanceQuery.java index 97e64692fef..ee767bb2e00 100644 --- a/modules/flowable-cmmn-api/src/main/java/org/flowable/cmmn/api/runtime/CaseInstanceQuery.java +++ b/modules/flowable-cmmn-api/src/main/java/org/flowable/cmmn/api/runtime/CaseInstanceQuery.java @@ -27,6 +27,7 @@ public interface CaseInstanceQuery extends Query caseDefinitionKeys); CaseInstanceQuery caseDefinitionId(String caseDefinitionId); + CaseInstanceQuery caseDefinitionIds(Set caseDefinitionIds); CaseInstanceQuery caseDefinitionCategory(String caseDefinitionCategory); CaseInstanceQuery caseDefinitionName(String caseDefinitionName); CaseInstanceQuery caseDefinitionVersion(Integer caseDefinitionVersion); diff --git a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/runtime/CaseInstanceQueryImpl.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/runtime/CaseInstanceQueryImpl.java index 9830c227425..987a487b7e1 100644 --- a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/runtime/CaseInstanceQueryImpl.java +++ b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/runtime/CaseInstanceQueryImpl.java @@ -125,6 +125,20 @@ public CaseInstanceQueryImpl caseDefinitionId(String caseDefinitionId) { return this; } + @Override + public CaseInstanceQueryImpl caseDefinitionIds(Set caseDefinitionIds) { + if (caseDefinitionIds == null) { + throw new FlowableIllegalArgumentException("Case definition ids is null"); + } + + if (inOrStatement) { + this.currentOrQueryObject.caseDefinitionIds = caseDefinitionIds; + } else { + this.caseDefinitionIds = caseDefinitionIds; + } + return this; + } + @Override public CaseInstanceQueryImpl caseDefinitionKey(String caseDefinitionKey) { if (caseDefinitionKey == null) { diff --git a/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/runtime/CaseInstanceQueryImplTest.java b/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/runtime/CaseInstanceQueryImplTest.java index a45d579e38f..4131bf960d4 100644 --- a/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/runtime/CaseInstanceQueryImplTest.java +++ b/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/runtime/CaseInstanceQueryImplTest.java @@ -62,6 +62,7 @@ public void createCase() { this.deploymentId = addDeploymentForAutoCleanup(cmmnRepositoryService.createDeployment() .addClasspathResource("org/flowable/cmmn/test/runtime/CaseTaskTest.testBasicBlocking.cmmn") .addClasspathResource("org/flowable/cmmn/test/runtime/oneTaskCase.cmmn") + .addClasspathResource("org/flowable/cmmn/test/runtime/oneHumanTaskCase.cmmn") .deploy()); cmmnRuntimeService.createCaseInstanceBuilder() @@ -206,6 +207,39 @@ public void getCaseInstanceByCaseDefinitionId() { .singleResult().getId()).isEqualTo(caseInstance.getId()); } + @Test + public void getCaseInstanceByCaseDefinitionIds() { + CaseInstance caseInstance1 = cmmnRuntimeService.createCaseInstanceBuilder() + .caseDefinitionKey("oneTaskCase") + .start(); + + CaseInstance caseInstance2 = cmmnRuntimeService.createCaseInstanceBuilder() + .caseDefinitionKey("oneHumanTaskCase") + .start(); + + assertThat(cmmnRuntimeService.createCaseInstanceQuery() + .caseDefinitionIds(Set.of(caseInstance1.getCaseDefinitionId(), caseInstance2.getCaseDefinitionId())) + .list()) + .extracting(CaseInstance::getId) + .containsExactlyInAnyOrder(caseInstance1.getId(), caseInstance2.getId()); + + assertThat(cmmnRuntimeService.createCaseInstanceQuery() + .caseDefinitionIds(Set.of(caseInstance1.getCaseDefinitionId(), caseInstance2.getCaseDefinitionId())) + .caseInstanceId(caseInstance1.getId()) + .list()) + .extracting(CaseInstance::getId) + .containsExactlyInAnyOrder(caseInstance1.getId()); + + assertThat(cmmnRuntimeService.createCaseInstanceQuery() + .or() + .caseDefinitionIds(Set.of(caseInstance1.getCaseDefinitionId(), caseInstance2.getCaseDefinitionId())) + .caseInstanceId("undefinedId") + .endOr() + .list()) + .extracting(CaseInstance::getId) + .containsExactlyInAnyOrder(caseInstance1.getId(), caseInstance2.getId()); + } + @Test public void getCaseInstanceByCaseDefinitionVersion() { cmmnRuntimeService.createCaseInstanceBuilder()