From 32eafdf3f7139f90544ce451c63dfe954d176094 Mon Sep 17 00:00:00 2001 From: "Mannuru, ReddyKishore" Date: Tue, 11 Feb 2025 15:24:20 -0700 Subject: [PATCH] Update historic incident api to include root cause incident message --- .../templates/paths/history/incident/get.ftl | 6 ++- .../rest/dto/history/HistoricIncidentDto.java | 6 +++ .../bpm/engine/rest/helper/MockProvider.java | 15 ++++++++ .../HistoricIncidentRestServiceQueryTest.java | 37 +++++++++++++++++++ .../bpm/engine/history/HistoricIncident.java | 5 +++ .../event/HistoricIncidentEventEntity.java | 9 +++++ .../impl/mapping/entity/HistoricIncident.xml | 15 +++++++- 7 files changed, 89 insertions(+), 4 deletions(-) diff --git a/engine-rest/engine-rest-openapi/src/main/templates/paths/history/incident/get.ftl b/engine-rest/engine-rest-openapi/src/main/templates/paths/history/incident/get.ftl index 1a082e69a0d..2186330680d 100644 --- a/engine-rest/engine-rest-openapi/src/main/templates/paths/history/incident/get.ftl +++ b/engine-rest/engine-rest-openapi/src/main/templates/paths/history/incident/get.ftl @@ -58,7 +58,8 @@ "resolved": false, "removalTime": null, "rootProcessInstanceId": "aRootProcessInstanceId", - "annotation": "an annotation" + "annotation": "an annotation", + "rootCauseIncidentMessage": "aRootCauseIncidentMessage" }, { "id": "anIncidentId", @@ -81,7 +82,8 @@ "resolved": true, "removalTime": "2018-02-10T14:33:19.000+0200", "rootProcessInstanceId": "aRootProcessInstanceId", - "annotation": "another annotation" + "annotation": "another annotation", + "rootCauseIncidentMessage": "anotherRootCauseIncidentMessage" } ] }'] diff --git a/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/dto/history/HistoricIncidentDto.java b/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/dto/history/HistoricIncidentDto.java index 1f2753b25fc..745c66f50aa 100644 --- a/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/dto/history/HistoricIncidentDto.java +++ b/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/dto/history/HistoricIncidentDto.java @@ -49,6 +49,7 @@ public class HistoricIncidentDto { protected Boolean deleted; protected Boolean resolved; protected String annotation; + protected String rootCauseIncidentMessage; public String getId() { return id; @@ -142,6 +143,10 @@ public String getAnnotation() { return annotation; } + public String getRootCauseIncidentMessage() { + return rootCauseIncidentMessage; + } + public static HistoricIncidentDto fromHistoricIncident(HistoricIncident historicIncident) { HistoricIncidentDto dto = new HistoricIncidentDto(); @@ -168,6 +173,7 @@ public static HistoricIncidentDto fromHistoricIncident(HistoricIncident historic dto.removalTime = historicIncident.getRemovalTime(); dto.rootProcessInstanceId = historicIncident.getRootProcessInstanceId(); dto.annotation = historicIncident.getAnnotation(); + dto.rootCauseIncidentMessage = historicIncident.getRootCauseIncidentMessage(); return dto; } diff --git a/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/helper/MockProvider.java b/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/helper/MockProvider.java index 09d82eb3018..78a8f658f11 100644 --- a/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/helper/MockProvider.java +++ b/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/helper/MockProvider.java @@ -742,6 +742,7 @@ public abstract class MockProvider { public static final String EXAMPLE_HIST_INCIDENT_PROC_DEF_KEY = "aProcDefKey"; public static final String EXAMPLE_HIST_INCIDENT_ROOT_PROC_INST_ID = "aRootProcInstId"; public static final String EXAMPLE_HIST_INCIDENT_CAUSE_INCIDENT_ID = "aCauseIncidentId"; + public static final String EXAMPLE_HIST_ROOT_CAUSE_INCIDENT_MSG = "aRootCauseIncidentMessage"; public static final String EXAMPLE_HIST_INCIDENT_ROOT_CAUSE_INCIDENT_ID = "aRootCauseIncidentId"; public static final String EXAMPLE_HIST_INCIDENT_CONFIGURATION = "aConfiguration"; public static final String EXAMPLE_HIST_INCIDENT_HISTORY_CONFIGURATION = "aHistoryConfiguration"; @@ -2636,6 +2637,19 @@ public static HistoricIncident createMockHistoricIncident() { return createMockHistoricIncident(EXAMPLE_TENANT_ID); } + public static HistoricIncident createMockHistoricIncidentWithoutRootCauseIncidentMessage() { + HistoricIncident incident = createMockHistoricIncident(EXAMPLE_TENANT_ID); + when(incident.getRootCauseIncidentMessage()).thenReturn(null); + return incident; + } + + public static List createMockHistoricIncidentsWithoutRootCauseIncidentMessage() { + List entries = new ArrayList<>(); + entries.add(createMockHistoricIncidentWithoutRootCauseIncidentMessage()); + return entries; + } + + public static HistoricIncident createMockHistoricIncident(String tenantId) { HistoricIncident incident = mock(HistoricIncident.class); @@ -2661,6 +2675,7 @@ public static HistoricIncident createMockHistoricIncident(String tenantId) { when(incident.getRemovalTime()).thenReturn(DateTimeUtil.parseDate(EXAMPLE_HIST_INCIDENT_REMOVAL_TIME)); when(incident.getRootProcessInstanceId()).thenReturn(EXAMPLE_HIST_INCIDENT_ROOT_PROC_INST_ID); when(incident.getAnnotation()).thenReturn(EXAMPLE_USER_OPERATION_ANNOTATION); + when(incident.getRootCauseIncidentMessage()).thenReturn(EXAMPLE_HIST_ROOT_CAUSE_INCIDENT_MSG); return incident; } 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 29209c8810d..4f5f1ed0fe3 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 @@ -390,6 +390,7 @@ public void testSimpleHistoricTaskInstanceQuery() { Date returnedRemovalTime = DateTimeUtil.parseDate(from(content).getString("[0].removalTime")); String returnedRootProcessInstanceId = from(content).getString("[0].rootProcessInstanceId"); String returnedAnnotation = from(content).getString("[0].annotation"); + String returnedRootCauseIncidentMessage = from(content).getString("[0].rootCauseIncidentMessage"); Assert.assertEquals(MockProvider.EXAMPLE_HIST_INCIDENT_ID, returnedId); Assert.assertEquals(MockProvider.EXAMPLE_HIST_INCIDENT_PROC_INST_ID, returnedProcessInstanceId); @@ -413,6 +414,7 @@ public void testSimpleHistoricTaskInstanceQuery() { Assert.assertEquals(DateTimeUtil.parseDate(MockProvider.EXAMPLE_HIST_INCIDENT_REMOVAL_TIME), returnedRemovalTime); Assert.assertEquals(MockProvider.EXAMPLE_HIST_INCIDENT_ROOT_PROC_INST_ID, returnedRootProcessInstanceId); Assert.assertEquals(MockProvider.EXAMPLE_USER_OPERATION_ANNOTATION, returnedAnnotation); + Assert.assertEquals(MockProvider.EXAMPLE_HIST_ROOT_CAUSE_INCIDENT_MSG, returnedRootCauseIncidentMessage); } @@ -723,4 +725,39 @@ public void testQueryByJobDefinitionIds() { verify(mockedQuery).list(); } + @Test + public void testIncidentWithRootCauseIncidentMessage() { + Response response = given() + .then().expect() + .statusCode(Status.OK.getStatusCode()) + .when() + .get(HISTORY_INCIDENT_QUERY_URL); + + verify(mockedQuery).list(); + + String content = response.asString(); + List incidents = from(content).getList(""); + assertThat(incidents).hasSize(1); + + assertThat(from(content).getString("[0].rootCauseIncidentMessage")).isEqualTo(MockProvider.EXAMPLE_HIST_ROOT_CAUSE_INCIDENT_MSG); + } + + @Test + public void testIncidentWithoutRootCauseIncidentMessage() { + mockedQuery = setUpMockHistoricIncidentQuery(MockProvider.createMockHistoricIncidentsWithoutRootCauseIncidentMessage()); + Response response = given() + .then().expect() + .statusCode(Status.OK.getStatusCode()) + .when() + .get(HISTORY_INCIDENT_QUERY_URL); + + verify(mockedQuery).list(); + + String content = response.asString(); + List incidents = from(content).getList(""); + assertThat(incidents).hasSize(1); + + assertThat(from(content).getString("[0].rootCauseIncidentMessage")).isNull(); + } + } diff --git a/engine/src/main/java/org/camunda/bpm/engine/history/HistoricIncident.java b/engine/src/main/java/org/camunda/bpm/engine/history/HistoricIncident.java index a3519084f96..b9d10c18cac 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/history/HistoricIncident.java +++ b/engine/src/main/java/org/camunda/bpm/engine/history/HistoricIncident.java @@ -160,4 +160,9 @@ public interface HistoricIncident { * Returns the annotation of this incident */ String getAnnotation(); + + /** + * Returns the incident message of the root incident + */ + String getRootCauseIncidentMessage(); } diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/history/event/HistoricIncidentEventEntity.java b/engine/src/main/java/org/camunda/bpm/engine/impl/history/event/HistoricIncidentEventEntity.java index 481697b9506..52f9c0f0e68 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/history/event/HistoricIncidentEventEntity.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/history/event/HistoricIncidentEventEntity.java @@ -42,6 +42,7 @@ public class HistoricIncidentEventEntity extends HistoryEvent { protected String historyConfiguration; protected String failedActivityId; protected String annotation; + protected String rootCauseIncidentMessage; public Date getCreateTime() { return createTime; @@ -171,4 +172,12 @@ public void setAnnotation(String annotation) { this.annotation = annotation; } + public String getRootCauseIncidentMessage() { + return rootCauseIncidentMessage; + } + + public void setRootCauseIncidentMessage(String rootCauseIncidentMessage) { + this.rootCauseIncidentMessage = rootCauseIncidentMessage; + } + } 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 60d142b4bbf..487b1934322 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 @@ -388,16 +388,21 @@ + + + + - + ${limitBefore} - select ${distinct} RES.* + select ${distinct} RES.*, ROOT_INCIDENT.INCIDENT_MSG_ as ROOT_CAUSE_INCIDENT_MESSAGE_ ${limitBetween} ${orderBy} @@ -405,6 +410,7 @@