Skip to content

Commit

Permalink
Add endpoint to retreive aggregated severities (#104)
Browse files Browse the repository at this point in the history
Signed-off-by: Ayoub LABIDI <[email protected]>
  • Loading branch information
ayolab authored Jan 7, 2025
1 parent d3061a1 commit c514f2d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public ResponseEntity<Report> getReport(@PathVariable("id") UUID id,
}
}

@GetMapping(value = "/reports/{id}/aggregated-severities", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get the severities of the report")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The severities of the report")})
public ResponseEntity<Set<String>> getReportAggregatedSeverities(@PathVariable("id") UUID id) {
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(service.getReportAggregatedSeverities(id));
}

@GetMapping(value = "/reports/{id}/logs", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get the messages, severity and the parent id contained in the report")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The list of message (severity and parent id) of the reporter and its subreporters"),
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/gridsuite/report/server/ReportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ public List<ReportLog> getReportLogs(UUID rootReportNodeId, @Nullable Set<String
.orElse(Collections.emptyList());
}

public Set<String> getReportAggregatedSeverities(UUID reportId) {
return reportNodeRepository.findById(reportId)
.map(entity -> reportNodeRepository.findDistinctSeveritiesByRootNodeIdAndOrder(
Optional.ofNullable(entity.getRootNode()).map(ReportNodeEntity::getId).orElse(entity.getId()),
entity.getOrder(),
entity.getEndOrder()))
.orElse(Collections.emptySet());
}

public Report getEmptyReport(@NonNull UUID id, @NonNull String defaultName) {
Report emptyReport = new Report();
emptyReport.setId(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ AND UPPER(rn.message) LIKE UPPER(:message)
""")
List<ReportProjection> findAllReportsByRootNodeIdAndOrderAndMessage(UUID rootNodeId, int orderAfter, int orderBefore, String message);

@Query("""
SELECT DISTINCT rn.severity
FROM ReportNodeEntity rn
WHERE
rn.rootNode.id = :rootNodeId
AND rn.order BETWEEN :orderAfter AND :orderBefore
""")
Set<String> findDistinctSeveritiesByRootNodeIdAndOrder(UUID rootNodeId, int orderAfter, int orderBefore);

@Query("""
SELECT new org.gridsuite.report.server.entities.ReportProjection(
rn.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,17 @@ public void testDeleteReport() throws Exception {
assertReportsAreEqualIgnoringIds(result, toString(DEFAULT_EMPTY_REPORT1));
}

@Test
public void testGetReportAggregatedSeverities() throws Exception {
String testReport1 = toString(REPORT_ONE);
insertReport(REPORT_UUID, testReport1);
MvcResult result = mvc.perform(get(URL_TEMPLATE + "/reports/" + REPORT_UUID + "/aggregated-severities"))
.andExpect(status().isOk())
.andReturn();
Set<String> severities = objectMapper.readValue(result.getResponse().getContentAsString(), new TypeReference<>() { });
assertEquals(Set.of("TRACE", "ERROR", "UNKNOWN", "INFO"), severities);
}

private void testImported(String report1Id, String reportConcat2) throws Exception {
MvcResult result = mvc.perform(get(URL_TEMPLATE + "/reports/" + report1Id + "?severityLevels=INFO&severityLevels=TRACE&severityLevels=ERROR"))
.andExpect(status().isOk())
Expand Down

0 comments on commit c514f2d

Please sign in to comment.