From 42cbc3e74d5a436bab65c3d0bf6401392e8ca707 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI <117761394+ayolab@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:22:18 +0200 Subject: [PATCH] Remove hack when creating and deleting reports (#66) Signed-off-by: Ayoub LABIDI --- .../computation/service/AbstractWorkerService.java | 4 ++-- .../ws/commons/computation/service/ReportService.java | 4 +--- .../ws/commons/computation/service/ReportServiceTest.java | 8 ++++---- 3 files changed, 7 insertions(+), 9 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 74f0777..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 @@ -203,13 +203,13 @@ 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, () -> reportService.deleteReport(runContext.getReportInfos().reportUuid())); } 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..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; @@ -69,11 +68,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(); 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..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,19 +71,19 @@ 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, "MockReportType")); + assertThatNoException().isThrownBy(() -> reportService.deleteReport(REPORT_UUID)); } @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, "MockReportType")).isInstanceOf(RestClientException.class); + assertThatThrownBy(() -> reportService.deleteReport(REPORT_ERROR_UUID)).isInstanceOf(RestClientException.class); } }