From 02b38b2bc1cde6346c30f36d0544a7cd92360863 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Fri, 6 Sep 2024 11:30:21 +0200 Subject: [PATCH 1/3] Remove hack when creating and deleting reports Signed-off-by: Ayoub LABIDI --- .../computation/service/AbstractWorkerService.java | 10 ++++++++-- .../ws/commons/computation/service/ReportService.java | 4 +--- .../commons/computation/service/ReportServiceTest.java | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java b/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java index acb8ef9..3b162ef 100644 --- a/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java +++ b/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java @@ -193,13 +193,19 @@ protected R run(C runContext, UUID resultUuid, AtomicReference rootR if (runContext.getReportInfos() != null && runContext.getReportInfos().reportUuid() != null) { final String reportType = runContext.getReportInfos().computationType(); - String rootReporterId = runContext.getReportInfos().reporterId() == null ? reportType : runContext.getReportInfos().reporterId() + "@" + reportType; + String rootReporterId = runContext.getReportInfos().reporterId(); rootReporter.set(ReportNode.newRootReportNode().withMessageTemplate(rootReporterId, rootReporterId).build()); reportNode = rootReporter.get().newReportNode().withMessageTemplate(reportType, reportType + (provider != null ? " (" + provider + ")" : "")) .withUntypedValue("providerToUse", Objects.requireNonNullElse(provider, "")).add(); // Delete any previous computation logs observer.observe("report.delete", - runContext, () -> reportService.deleteReport(runContext.getReportInfos().reportUuid(), reportType)); + runContext, () -> { + try { + reportService.deleteReport(runContext.getReportInfos().reportUuid()); + } catch (Exception e) { + LOGGER.error("Failed to delete report", e); + } + }); } runContext.setReportNode(reportNode); diff --git a/src/main/java/com/powsybl/ws/commons/computation/service/ReportService.java b/src/main/java/com/powsybl/ws/commons/computation/service/ReportService.java index 92c9c2d..13535e3 100644 --- a/src/main/java/com/powsybl/ws/commons/computation/service/ReportService.java +++ b/src/main/java/com/powsybl/ws/commons/computation/service/ReportService.java @@ -69,12 +69,10 @@ public void sendReport(UUID reportUuid, ReportNode reportNode) { } } - public void deleteReport(UUID reportUuid, String reportType) { + public void deleteReport(UUID reportUuid) { Objects.requireNonNull(reportUuid); var path = UriComponentsBuilder.fromPath("{reportUuid}") - .queryParam(QUERY_PARAM_REPORT_TYPE_FILTER, reportType) - .queryParam(QUERY_PARAM_REPORT_THROW_ERROR, false) .buildAndExpand(reportUuid) .toUriString(); var headers = new HttpHeaders(); diff --git a/src/test/java/com/powsybl/ws/commons/computation/service/ReportServiceTest.java b/src/test/java/com/powsybl/ws/commons/computation/service/ReportServiceTest.java index 5457dcd..1fd5329 100644 --- a/src/test/java/com/powsybl/ws/commons/computation/service/ReportServiceTest.java +++ b/src/test/java/com/powsybl/ws/commons/computation/service/ReportServiceTest.java @@ -74,7 +74,7 @@ void testDeleteReport() { .andExpect(MockRestRequestMatchers.requestTo("http://report-server/v1/reports/" + REPORT_UUID + "?reportTypeFilter=MockReportType&errorOnReportNotFound=false")) .andExpect(MockRestRequestMatchers.content().bytes(new byte[0])) .andRespond(MockRestResponseCreators.withSuccess()); - assertThatNoException().isThrownBy(() -> reportService.deleteReport(REPORT_UUID, "MockReportType")); + assertThatNoException().isThrownBy(() -> reportService.deleteReport(REPORT_UUID)); } @Test @@ -83,7 +83,7 @@ void testDeleteReportFailed() { .andExpect(MockRestRequestMatchers.requestTo("http://report-server/v1/reports/" + REPORT_ERROR_UUID + "?reportTypeFilter=MockReportType&errorOnReportNotFound=false")) .andExpect(MockRestRequestMatchers.content().bytes(new byte[0])) .andRespond(MockRestResponseCreators.withServerError()); - assertThatThrownBy(() -> reportService.deleteReport(REPORT_ERROR_UUID, "MockReportType")).isInstanceOf(RestClientException.class); + assertThatThrownBy(() -> reportService.deleteReport(REPORT_ERROR_UUID)).isInstanceOf(RestClientException.class); } } From d19c7814ba37baf965151f2a4e769d5812913b02 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Fri, 6 Sep 2024 16:55:47 +0200 Subject: [PATCH 2/3] Fix tests Signed-off-by: Ayoub LABIDI --- .../powsybl/ws/commons/computation/service/ReportService.java | 2 +- .../ws/commons/computation/service/ReportServiceTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/powsybl/ws/commons/computation/service/ReportService.java b/src/main/java/com/powsybl/ws/commons/computation/service/ReportService.java index 13535e3..6d71675 100644 --- a/src/main/java/com/powsybl/ws/commons/computation/service/ReportService.java +++ b/src/main/java/com/powsybl/ws/commons/computation/service/ReportService.java @@ -31,7 +31,6 @@ public class ReportService { static final String REPORT_API_VERSION = "v1"; private static final String DELIMITER = "/"; - private static final String QUERY_PARAM_REPORT_TYPE_FILTER = "reportTypeFilter"; private static final String QUERY_PARAM_REPORT_THROW_ERROR = "errorOnReportNotFound"; @Setter private String reportServerBaseUri; @@ -73,6 +72,7 @@ public void deleteReport(UUID reportUuid) { Objects.requireNonNull(reportUuid); var path = UriComponentsBuilder.fromPath("{reportUuid}") + .queryParam(QUERY_PARAM_REPORT_THROW_ERROR, false) .buildAndExpand(reportUuid) .toUriString(); var headers = new HttpHeaders(); diff --git a/src/test/java/com/powsybl/ws/commons/computation/service/ReportServiceTest.java b/src/test/java/com/powsybl/ws/commons/computation/service/ReportServiceTest.java index 1fd5329..0b58082 100644 --- a/src/test/java/com/powsybl/ws/commons/computation/service/ReportServiceTest.java +++ b/src/test/java/com/powsybl/ws/commons/computation/service/ReportServiceTest.java @@ -71,7 +71,7 @@ void testSendReportFailed() { @Test void testDeleteReport() { server.expect(MockRestRequestMatchers.method(HttpMethod.DELETE)) - .andExpect(MockRestRequestMatchers.requestTo("http://report-server/v1/reports/" + REPORT_UUID + "?reportTypeFilter=MockReportType&errorOnReportNotFound=false")) + .andExpect(MockRestRequestMatchers.requestTo("http://report-server/v1/reports/" + REPORT_UUID + "?errorOnReportNotFound=false")) .andExpect(MockRestRequestMatchers.content().bytes(new byte[0])) .andRespond(MockRestResponseCreators.withSuccess()); assertThatNoException().isThrownBy(() -> reportService.deleteReport(REPORT_UUID)); @@ -80,7 +80,7 @@ void testDeleteReport() { @Test void testDeleteReportFailed() { server.expect(MockRestRequestMatchers.method(HttpMethod.DELETE)) - .andExpect(MockRestRequestMatchers.requestTo("http://report-server/v1/reports/" + REPORT_ERROR_UUID + "?reportTypeFilter=MockReportType&errorOnReportNotFound=false")) + .andExpect(MockRestRequestMatchers.requestTo("http://report-server/v1/reports/" + REPORT_ERROR_UUID + "?errorOnReportNotFound=false")) .andExpect(MockRestRequestMatchers.content().bytes(new byte[0])) .andRespond(MockRestResponseCreators.withServerError()); assertThatThrownBy(() -> reportService.deleteReport(REPORT_ERROR_UUID)).isInstanceOf(RestClientException.class); From 89807f11192455c834d4a5bcf1e7c9357c31c265 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Mon, 23 Sep 2024 21:42:02 +0200 Subject: [PATCH 3/3] Requested changes Signed-off-by: Ayoub LABIDI --- .../computation/service/AbstractWorkerService.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java b/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java index 4b7aa85..3bd1155 100644 --- a/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java +++ b/src/main/java/com/powsybl/ws/commons/computation/service/AbstractWorkerService.java @@ -209,13 +209,7 @@ protected R run(C runContext, UUID resultUuid, AtomicReference rootR .withUntypedValue("providerToUse", Objects.requireNonNullElse(provider, "")).add(); // Delete any previous computation logs observer.observe("report.delete", - runContext, () -> { - try { - reportService.deleteReport(runContext.getReportInfos().reportUuid()); - } catch (Exception e) { - LOGGER.error("Failed to delete report", e); - } - }); + runContext, () -> reportService.deleteReport(runContext.getReportInfos().reportUuid())); } runContext.setReportNode(reportNode);