From 23c0cb50355524fa1652234cfc240c68cb88f325 Mon Sep 17 00:00:00 2001 From: Tobias Metzke Date: Fri, 24 Jan 2020 11:20:34 +0100 Subject: [PATCH] feat(engine+rest): add query filter for failed activity id related to CAM-11274 --- .../dto/history/HistoricIncidentQueryDto.java | 9 ++++++ .../rest/dto/runtime/IncidentQueryDto.java | 9 ++++++ .../rest/IncidentRestServiceQueryTest.java | 16 ++++++++-- .../HistoricIncidentRestServiceQueryTest.java | 16 ++++++++-- .../engine/history/HistoricIncidentQuery.java | 3 ++ .../impl/HistoricIncidentQueryImpl.java | 12 ++++++- .../bpm/engine/impl/IncidentQueryImpl.java | 7 ++++- .../bpm/engine/runtime/IncidentQuery.java | 3 ++ .../impl/mapping/entity/HistoricIncident.xml | 3 ++ .../engine/impl/mapping/entity/Incident.xml | 3 ++ .../test/api/runtime/IncidentQueryTest.java | 23 ++++++++++++++ .../history/HistoricIncidentQueryTest.java | 31 +++++++++++++++++++ 12 files changed, 129 insertions(+), 6 deletions(-) diff --git a/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/dto/history/HistoricIncidentQueryDto.java b/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/dto/history/HistoricIncidentQueryDto.java index 56c4ab31a54..b0378982072 100644 --- a/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/dto/history/HistoricIncidentQueryDto.java +++ b/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/dto/history/HistoricIncidentQueryDto.java @@ -84,6 +84,7 @@ public class HistoricIncidentQueryDto extends AbstractQueryDto{ protected String processInstanceId; protected String executionId; protected String activityId; + protected String failedActivityId; protected String causeIncidentId; protected String rootCauseIncidentId; protected String configuration; @@ -127,6 +128,11 @@ public void setActivityId(String activityId) { this.activityId = activityId; } + @CamundaQueryParam("failedActivityId") + public void setFailedActivityId(String activityId) { + this.failedActivityId = activityId; + } + @CamundaQueryParam("causeIncidentId") public void setCauseIncidentId(String causeIncidentId) { this.causeIncidentId = causeIncidentId; @@ -189,6 +195,9 @@ protected void applyFilters(IncidentQuery query) { if (activityId != null) { query.activityId(activityId); } + if (failedActivityId != null) { + query.failedActivityId(failedActivityId); + } if (causeIncidentId != null) { query.causeIncidentId(causeIncidentId); } diff --git a/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/IncidentRestServiceQueryTest.java b/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/IncidentRestServiceQueryTest.java index 167e0b79945..a25592a6038 100644 --- a/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/IncidentRestServiceQueryTest.java +++ b/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/IncidentRestServiceQueryTest.java @@ -464,11 +464,23 @@ public void testQueryByActivityId() { String activityId = MockProvider.EXAMPLE_INCIDENT_ACTIVITY_ID; given() - .queryParam("activityId", activityId) + .queryParam("activityId", activityId) + .then().expect().statusCode(Status.OK.getStatusCode()) + .when().get(INCIDENT_QUERY_URL); + + verify(mockedQuery).activityId(activityId); + } + + @Test + public void testQueryByFailedActivityId() { + String activityId = MockProvider.EXAMPLE_INCIDENT_FAILED_ACTIVITY_ID; + + given() + .queryParam("failedActivityId", activityId) .then().expect().statusCode(Status.OK.getStatusCode()) .when().get(INCIDENT_QUERY_URL); - verify(mockedQuery).activityId(activityId); + verify(mockedQuery).failedActivityId(activityId); } @Test diff --git a/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/history/HistoricIncidentRestServiceQueryTest.java b/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/history/HistoricIncidentRestServiceQueryTest.java index 27300b4acdd..0b4aa676f59 100644 --- a/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/history/HistoricIncidentRestServiceQueryTest.java +++ b/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/history/HistoricIncidentRestServiceQueryTest.java @@ -497,11 +497,23 @@ public void testQueryByActivityId() { String activityId = MockProvider.EXAMPLE_HIST_INCIDENT_ACTIVITY_ID; given() - .queryParam("activityId", activityId) + .queryParam("activityId", activityId) + .then().expect().statusCode(Status.OK.getStatusCode()) + .when().get(HISTORY_INCIDENT_QUERY_URL); + + verify(mockedQuery).activityId(activityId); + } + + @Test + public void testQueryByFailedActivityId() { + String activityId = MockProvider.EXAMPLE_HIST_INCIDENT_FAILED_ACTIVITY_ID; + + given() + .queryParam("failedActivityId", activityId) .then().expect().statusCode(Status.OK.getStatusCode()) .when().get(HISTORY_INCIDENT_QUERY_URL); - verify(mockedQuery).activityId(activityId); + verify(mockedQuery).failedActivityId(activityId); } @Test diff --git a/engine/src/main/java/org/camunda/bpm/engine/history/HistoricIncidentQuery.java b/engine/src/main/java/org/camunda/bpm/engine/history/HistoricIncidentQuery.java index 30e87970e76..1b291ece2e3 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/history/HistoricIncidentQuery.java +++ b/engine/src/main/java/org/camunda/bpm/engine/history/HistoricIncidentQuery.java @@ -48,6 +48,9 @@ public interface HistoricIncidentQuery extends Query im protected String incidentMessage; protected String executionId; protected String activityId; + protected String failedActivityId; protected String processInstanceId; protected String processDefinitionId; protected String[] processDefinitionKeys; @@ -80,6 +80,11 @@ public IncidentQuery activityId(String activityId) { return this; } + public IncidentQuery failedActivityId(String activityId) { + this.failedActivityId = activityId; + return this; + } + public IncidentQuery processInstanceId(String processInstanceId) { this.processInstanceId = processInstanceId; return this; diff --git a/engine/src/main/java/org/camunda/bpm/engine/runtime/IncidentQuery.java b/engine/src/main/java/org/camunda/bpm/engine/runtime/IncidentQuery.java index 61765a3a9b6..f8bd7d36f7d 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/runtime/IncidentQuery.java +++ b/engine/src/main/java/org/camunda/bpm/engine/runtime/IncidentQuery.java @@ -47,6 +47,9 @@ public interface IncidentQuery extends Query { /** Only select incidents which contain an activity with the given id. **/ IncidentQuery activityId(String activityId); + /** Only select incidents which were created due to a failure at an activity with the given id. **/ + IncidentQuery failedActivityId(String activityId); + /** Only select incidents which contain the id of the cause incident. **/ IncidentQuery causeIncidentId(String causeIncidentId); diff --git a/engine/src/main/resources/org/camunda/bpm/engine/impl/mapping/entity/HistoricIncident.xml b/engine/src/main/resources/org/camunda/bpm/engine/impl/mapping/entity/HistoricIncident.xml index 056934ff912..b13b986c42f 100644 --- a/engine/src/main/resources/org/camunda/bpm/engine/impl/mapping/entity/HistoricIncident.xml +++ b/engine/src/main/resources/org/camunda/bpm/engine/impl/mapping/entity/HistoricIncident.xml @@ -313,6 +313,9 @@ and RES.ACTIVITY_ID_ = #{activityId} + + and RES.FAILED_ACTIVITY_ID_ = #{failedActivityId} + and RES.PROC_INST_ID_ = #{processInstanceId} diff --git a/engine/src/main/resources/org/camunda/bpm/engine/impl/mapping/entity/Incident.xml b/engine/src/main/resources/org/camunda/bpm/engine/impl/mapping/entity/Incident.xml index bc2ffdd11fa..77117e68b02 100644 --- a/engine/src/main/resources/org/camunda/bpm/engine/impl/mapping/entity/Incident.xml +++ b/engine/src/main/resources/org/camunda/bpm/engine/impl/mapping/entity/Incident.xml @@ -152,6 +152,9 @@ and RES.ACTIVITY_ID_ = #{activityId} + + and RES.FAILED_ACTIVITY_ID_ = #{failedActivityId} + and RES.PROC_INST_ID_ = #{processInstanceId} diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/IncidentQueryTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/IncidentQueryTest.java index 55dbf4af3bd..7f569e1f786 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/IncidentQueryTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/IncidentQueryTest.java @@ -340,6 +340,29 @@ public void testQueryByInvalidActivityId() { assertNull(incident); } + @Test + public void testQueryByFailedActivityId() { + IncidentQuery query = runtimeService.createIncidentQuery().failedActivityId("task"); + assertEquals(4, query.count()); + + List incidents = query.list(); + assertFalse(incidents.isEmpty()); + assertEquals(4, incidents.size()); + } + + @Test + public void testQueryByInvalidFailedActivityId() { + IncidentQuery query = runtimeService.createIncidentQuery().failedActivityId("invalid"); + + assertEquals(0, query.count()); + + List incidents = query.list(); + assertTrue(incidents.isEmpty()); + + Incident incident = query.singleResult(); + assertNull(incident); + } + @Test public void testQueryByConfiguration() { String jobId = managementService.createJobQuery().processInstanceId(processInstanceIds.get(0)).singleResult().getId(); diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/history/HistoricIncidentQueryTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/history/HistoricIncidentQueryTest.java index bd3d6aee965..fabb9e8721e 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/history/HistoricIncidentQueryTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/history/HistoricIncidentQueryTest.java @@ -315,7 +315,10 @@ public void testQueryByActivityId() { } @Test + @Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneFailingServiceProcess.bpmn20.xml"}) public void testQueryByInvalidActivityId() { + startProcessInstance(PROCESS_DEFINITION_KEY); + HistoricIncidentQuery query = historyService.createHistoricIncidentQuery(); assertEquals(0, query.activityId("invalid").list().size()); @@ -327,6 +330,34 @@ public void testQueryByInvalidActivityId() { } catch (ProcessEngineException e) { } } + @Test + @Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneFailingServiceProcess.bpmn20.xml"}) + public void testQueryByFailedActivityId() { + startProcessInstance(PROCESS_DEFINITION_KEY); + + HistoricIncidentQuery query = historyService.createHistoricIncidentQuery() + .failedActivityId("theServiceTask"); + + assertEquals(1, query.list().size()); + assertEquals(1, query.count()); + } + + @Test + @Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneFailingServiceProcess.bpmn20.xml"}) + public void testQueryByFailedInvalidActivityId() { + startProcessInstance(PROCESS_DEFINITION_KEY); + + HistoricIncidentQuery query = historyService.createHistoricIncidentQuery(); + + assertEquals(0, query.failedActivityId("invalid").list().size()); + assertEquals(0, query.failedActivityId("invalid").count()); + + try { + query.failedActivityId(null); + fail("It was possible to set a null value as failedActivityId."); + } catch (ProcessEngineException e) { } + } + @Test @Deployment(resources={"org/camunda/bpm/engine/test/history/HistoricIncidentQueryTest.testQueryByCauseIncidentId.bpmn20.xml", "org/camunda/bpm/engine/test/api/runtime/oneFailingServiceProcess.bpmn20.xml"})