Skip to content

Commit

Permalink
Add support for case definition keys in case instance and historic ca…
Browse files Browse the repository at this point in the history
…se instance REST queries: FLW-4766
  • Loading branch information
tijsrademakers committed Aug 23, 2023
1 parent f8363ec commit cd6ca22
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ protected DataResponse<HistoricCaseInstanceResponse> getQueryResponse(HistoricCa
if (queryRequest.getCaseDefinitionKey() != null) {
query.caseDefinitionKey(queryRequest.getCaseDefinitionKey());
}
if (queryRequest.getCaseDefinitionKeys() != null && !queryRequest.getCaseDefinitionKeys().isEmpty()) {
query.caseDefinitionKeys(queryRequest.getCaseDefinitionKeys());
}
if (queryRequest.getCaseDefinitionId() != null) {
query.caseDefinitionId(queryRequest.getCaseDefinitionId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class HistoricCaseInstanceQueryRequest extends PaginateRequest {
private List<String> caseInstanceIds;
private String caseDefinitionId;
private String caseDefinitionKey;
private Set<String> caseDefinitionKeys;
private String caseDefinitionCategory;
private String caseDefinitionName;
private String caseBusinessKey;
Expand Down Expand Up @@ -97,6 +98,14 @@ public void setCaseDefinitionKey(String caseDefinitionKey) {
this.caseDefinitionKey = caseDefinitionKey;
}

public Set<String> getCaseDefinitionKeys() {
return caseDefinitionKeys;
}

public void setCaseDefinitionKeys(Set<String> caseDefinitionKeys) {
this.caseDefinitionKeys = caseDefinitionKeys;
}

public String getCaseDefinitionCategory() {
return caseDefinitionCategory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ protected DataResponse<CaseInstanceResponse> getQueryResponse(CaseInstanceQueryR
if (queryRequest.getCaseDefinitionKey() != null) {
query.caseDefinitionKey(queryRequest.getCaseDefinitionKey());
}
if (queryRequest.getCaseDefinitionKeys() != null && !queryRequest.getCaseDefinitionKeys().isEmpty()) {
query.caseDefinitionKeys(queryRequest.getCaseDefinitionKeys());
}
if (queryRequest.getCaseDefinitionId() != null) {
query.caseDefinitionId(queryRequest.getCaseDefinitionId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class CaseInstanceQueryRequest extends PaginateRequest {
private String caseInstanceId;
private String caseDefinitionId;
private String caseDefinitionKey;
private Set<String> caseDefinitionKeys;
private String caseDefinitionCategory;
private String caseDefinitionName;
private String caseBusinessKey;
Expand Down Expand Up @@ -92,6 +93,14 @@ public void setCaseDefinitionKey(String caseDefinitionKey) {
this.caseDefinitionKey = caseDefinitionKey;
}

public Set<String> getCaseDefinitionKeys() {
return caseDefinitionKeys;
}

public void setCaseDefinitionKeys(Set<String> caseDefinitionKeys) {
this.caseDefinitionKeys = caseDefinitionKeys;
}

public String getCaseDefinitionCategory() {
return caseDefinitionCategory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,78 @@ public void testQueryCaseInstancesByWithoutCallbackId() throws Exception {
+ "}");

}

@CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn",
"org/flowable/cmmn/rest/service/api/repository/twoHumanTaskCase.cmmn" })
public void testQueryHistoricCaseInstancesByCaseDefinitionKeys() throws Exception {
CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("myCase").start();
CaseInstance caseInstance2 = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("myCase").start();
CaseInstance caseInstance3 = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();

ObjectNode requestNode = objectMapper.createObjectNode();
ArrayNode itemArrayNode = requestNode.putArray("caseDefinitionKeys");
itemArrayNode.add("myCase");

String url = CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_HISTORIC_CASE_INSTANCE_QUERY);
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url);
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK);

JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
JsonNode dataNode = rootNode.get("data");
assertThatJson(dataNode)
.when(Option.IGNORING_EXTRA_FIELDS)
.isEqualTo("["
+ " {"
+ " id: '" + caseInstance.getId() + "'"
+ " },"
+ " {"
+ " id: '" + caseInstance2.getId() + "'"
+ " }"
+ "]");

requestNode = objectMapper.createObjectNode();
itemArrayNode = requestNode.putArray("caseDefinitionKeys");
itemArrayNode.add("myCase");
itemArrayNode.add("oneHumanTaskCase");

url = CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_HISTORIC_CASE_INSTANCE_QUERY);
httpPost = new HttpPost(SERVER_URL_PREFIX + url);
httpPost.setEntity(new StringEntity(requestNode.toString()));
response = executeRequest(httpPost, HttpStatus.SC_OK);

rootNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
dataNode = rootNode.get("data");
assertThatJson(dataNode)
.when(Option.IGNORING_EXTRA_FIELDS)
.isEqualTo("["
+ " {"
+ " id: '" + caseInstance.getId() + "'"
+ " },"
+ " {"
+ " id: '" + caseInstance2.getId() + "'"
+ " },"
+ " {"
+ " id: '" + caseInstance3.getId() + "'"
+ " }"
+ "]");

requestNode = objectMapper.createObjectNode();
itemArrayNode = requestNode.putArray("caseDefinitionKeys");
itemArrayNode.add("notExisting");

url = CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_HISTORIC_CASE_INSTANCE_QUERY);
httpPost = new HttpPost(SERVER_URL_PREFIX + url);
httpPost.setEntity(new StringEntity(requestNode.toString()));
response = executeRequest(httpPost, HttpStatus.SC_OK);

rootNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
dataNode = rootNode.get("data");

assertThatJson(dataNode)
.isEqualTo("[]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,78 @@ public void testQueryCaseInstancesByActivePlanItemDefinitionIds() throws Excepti
+ " }"
+ "]");
}

@CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn",
"org/flowable/cmmn/rest/service/api/repository/twoHumanTaskCase.cmmn" })
public void testQueryCaseInstancesByCaseDefinitionKeys() throws Exception {
CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("myCase").start();
CaseInstance caseInstance2 = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("myCase").start();
CaseInstance caseInstance3 = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();

ObjectNode requestNode = objectMapper.createObjectNode();
ArrayNode itemArrayNode = requestNode.putArray("caseDefinitionKeys");
itemArrayNode.add("myCase");

String url = CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_CASE_INSTANCE_QUERY);
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url);
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK);

JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
JsonNode dataNode = rootNode.get("data");
assertThatJson(dataNode)
.when(Option.IGNORING_EXTRA_FIELDS)
.isEqualTo("["
+ " {"
+ " id: '" + caseInstance.getId() + "'"
+ " },"
+ " {"
+ " id: '" + caseInstance2.getId() + "'"
+ " }"
+ "]");

requestNode = objectMapper.createObjectNode();
itemArrayNode = requestNode.putArray("caseDefinitionKeys");
itemArrayNode.add("myCase");
itemArrayNode.add("oneHumanTaskCase");

url = CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_CASE_INSTANCE_QUERY);
httpPost = new HttpPost(SERVER_URL_PREFIX + url);
httpPost.setEntity(new StringEntity(requestNode.toString()));
response = executeRequest(httpPost, HttpStatus.SC_OK);

rootNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
dataNode = rootNode.get("data");
assertThatJson(dataNode)
.when(Option.IGNORING_EXTRA_FIELDS)
.isEqualTo("["
+ " {"
+ " id: '" + caseInstance.getId() + "'"
+ " },"
+ " {"
+ " id: '" + caseInstance2.getId() + "'"
+ " },"
+ " {"
+ " id: '" + caseInstance3.getId() + "'"
+ " }"
+ "]");

requestNode = objectMapper.createObjectNode();
itemArrayNode = requestNode.putArray("caseDefinitionKeys");
itemArrayNode.add("notExisting");

url = CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_CASE_INSTANCE_QUERY);
httpPost = new HttpPost(SERVER_URL_PREFIX + url);
httpPost.setEntity(new StringEntity(requestNode.toString()));
response = executeRequest(httpPost, HttpStatus.SC_OK);

rootNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
dataNode = rootNode.get("data");

assertThatJson(dataNode)
.isEqualTo("[]");
}
}

0 comments on commit cd6ca22

Please sign in to comment.