Skip to content

Commit

Permalink
Remove hack when creating and deleting reports (#66)
Browse files Browse the repository at this point in the history
Signed-off-by: Ayoub LABIDI <[email protected]>
  • Loading branch information
ayolab authored Sep 24, 2024
1 parent 685f849 commit 42cbc3e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ protected R run(C runContext, UUID resultUuid, AtomicReference<ReportNode> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 42cbc3e

Please sign in to comment.