Skip to content

Commit 6881004

Browse files
committed
Expose query by case instance IDs for GET cmmn-history/historic-case-instances
This aligns the GET with the POST cmmn-query/historic-case-instances Query
1 parent 492a6b7 commit 6881004

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/history/caze/HistoricCaseInstanceCollectionResource.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class HistoricCaseInstanceCollectionResource extends HistoricCaseInstance
4646
@ApiOperation(value = "List of historic case instances", tags = { "History Case" }, nickname = "listHistoricCaseInstances")
4747
@ApiImplicitParams({
4848
@ApiImplicitParam(name = "caseInstanceId", dataType = "string", value = "An id of the historic case instance.", paramType = "query"),
49+
@ApiImplicitParam(name = "caseInstanceIds", dataType = "string", value = "Only return historic case instances with the given comma-separated ids.", paramType = "query"),
4950
@ApiImplicitParam(name = "caseDefinitionKey", dataType = "string", value = "The case definition key of the historic case instance.", paramType = "query"),
5051
@ApiImplicitParam(name = "caseDefinitionKeyLike", dataType = "string", value = "Only return historic case instances like the given case definition key.", paramType = "query"),
5152
@ApiImplicitParam(name = "caseDefinitionKeyLikeIgnoreCase", dataType = "string", value = "Only return historic case instances like the given case definition key, ignoring case.", paramType = "query"),
@@ -104,6 +105,10 @@ public DataResponse<HistoricCaseInstanceResponse> getHistoricCasenstances(@ApiPa
104105
queryRequest.setCaseInstanceId(allRequestParams.get("caseInstanceId"));
105106
}
106107

108+
if (allRequestParams.get("caseInstanceIds") != null) {
109+
queryRequest.setCaseInstanceIds(RequestUtil.parseToList(allRequestParams.get("caseInstanceIds")));
110+
}
111+
107112
if (allRequestParams.get("caseDefinitionKey") != null) {
108113
queryRequest.setCaseDefinitionKey(allRequestParams.get("caseDefinitionKey"));
109114
}

modules/flowable-cmmn-rest/src/test/java/org/flowable/cmmn/rest/service/api/history/HistoricCaseInstanceCollectionResourceTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,22 @@ public void testQueryByParentScopeId() throws IOException {
585585
}
586586

587587

588+
@CmmnDeployment(resources = "org/flowable/cmmn/rest/service/api/runtime/oneTaskCase.cmmn")
589+
public void testQueryByCaseInstanceIds() throws IOException {
590+
CaseInstance caseInstance1 = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneTaskCase").start();
591+
CaseInstance caseInstance2 = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneTaskCase").start();
592+
CaseInstance caseInstance3 = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneTaskCase").start();
593+
594+
String url = CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_HISTORIC_CASE_INSTANCES);
595+
assertResultsPresentInDataResponse(url, caseInstance1.getId(), caseInstance2.getId(), caseInstance3.getId());
596+
597+
url = CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_HISTORIC_CASE_INSTANCES) + "?caseInstanceIds=" + caseInstance1.getId() + "," + caseInstance3.getId();
598+
assertResultsPresentInDataResponse(url, caseInstance1.getId(), caseInstance3.getId());
599+
600+
url = CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_HISTORIC_CASE_INSTANCES) + "?caseInstanceIds=dummy1,dummy2";
601+
assertEmptyResultsPresentInDataResponse(url);
602+
}
603+
588604
private void assertVariablesPresentInPostDataResponse(String url, String queryParameters, String caseInstanceId, Map<String, Object> expectedVariables)
589605
throws IOException {
590606

modules/flowable-cmmn-rest/src/test/java/org/flowable/cmmn/rest/service/api/history/HistoricCaseInstanceQueryResourceTest.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,4 +538,67 @@ public void testQueryHistoricCaseInstancesByCaseDefinitionKeys() throws Exceptio
538538
assertThatJson(dataNode)
539539
.isEqualTo("[]");
540540
}
541+
542+
@CmmnDeployment(resources = "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn")
543+
public void testQueryHistoricCaseInstancesByCaseInstanceIds() throws Exception {
544+
CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();
545+
CaseInstance caseInstance2 = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();
546+
CaseInstance caseInstance3 = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();
547+
548+
ObjectNode requestNode = objectMapper.createObjectNode();
549+
550+
String url = CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_HISTORIC_CASE_INSTANCE_QUERY);
551+
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url);
552+
httpPost.setEntity(new StringEntity(requestNode.toString()));
553+
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK);
554+
555+
JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
556+
closeResponse(response);
557+
assertThatJson(rootNode)
558+
.when(Option.IGNORING_EXTRA_FIELDS)
559+
.inPath("data")
560+
.isEqualTo("""
561+
[
562+
{ id: '%s' },
563+
{ id: '%s' },
564+
{ id: '%s' }
565+
]
566+
""".formatted(caseInstance.getId(), caseInstance2.getId(), caseInstance3.getId()));
567+
568+
requestNode = objectMapper.createObjectNode();
569+
ArrayNode itemArrayNode = requestNode.putArray("caseInstanceIds");
570+
itemArrayNode.add(caseInstance.getId());
571+
itemArrayNode.add(caseInstance3.getId());
572+
573+
httpPost = new HttpPost(SERVER_URL_PREFIX + url);
574+
httpPost.setEntity(new StringEntity(requestNode.toString()));
575+
response = executeRequest(httpPost, HttpStatus.SC_OK);
576+
577+
rootNode = objectMapper.readTree(response.getEntity().getContent());
578+
closeResponse(response);
579+
assertThatJson(rootNode)
580+
.when(Option.IGNORING_EXTRA_FIELDS)
581+
.inPath("data")
582+
.isEqualTo("""
583+
[
584+
{ id: '%s' },
585+
{ id: '%s' }
586+
]
587+
""".formatted(caseInstance.getId(), caseInstance3.getId()));
588+
589+
requestNode = objectMapper.createObjectNode();
590+
itemArrayNode = requestNode.putArray("caseInstanceIds");
591+
itemArrayNode.add("notExisting");
592+
593+
httpPost = new HttpPost(SERVER_URL_PREFIX + url);
594+
httpPost.setEntity(new StringEntity(requestNode.toString()));
595+
response = executeRequest(httpPost, HttpStatus.SC_OK);
596+
597+
rootNode = objectMapper.readTree(response.getEntity().getContent());
598+
closeResponse(response);
599+
600+
assertThatJson(rootNode)
601+
.inPath("data")
602+
.isEqualTo("[]");
603+
}
541604
}

0 commit comments

Comments
 (0)