Skip to content

Commit 65899ad

Browse files
authored
Add new enum for each calculation tab and fix computation stats enum (#133)
Signed-off-by: LE SAULNIER Kevin <[email protected]>
1 parent 1c0c8da commit 65899ad

File tree

6 files changed

+138
-47
lines changed

6 files changed

+138
-47
lines changed

src/main/java/org/gridsuite/securityanalysis/server/SecurityAnalysisController.java

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -249,24 +249,38 @@ public ResponseEntity<String> getDefaultProvider() {
249249
return ResponseEntity.ok().body(securityAnalysisService.getDefaultProvider());
250250
}
251251

252-
@GetMapping(value = "/results/{resultUuid}/limit-types", produces = APPLICATION_JSON_VALUE)
253-
@Operation(summary = "Get the list of limit types values")
254-
@ApiResponses(@ApiResponse(responseCode = "200", description = "List of limit types values by result"))
255-
public ResponseEntity<List<LimitViolationType>> getLimitTypes(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
256-
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(securityAnalysisService.getLimitTypes(resultUuid));
252+
@GetMapping(value = "/results/{resultUuid}/n-limit-types", produces = APPLICATION_JSON_VALUE)
253+
@Operation(summary = "Get the list of limit types values - N results")
254+
@ApiResponses(@ApiResponse(responseCode = "200", description = "List of limit types values by result - N results"))
255+
public ResponseEntity<List<LimitViolationType>> getNResultLimitTypes(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
256+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(securityAnalysisService.getNResultLimitTypes(resultUuid));
257257
}
258258

259-
@GetMapping(value = "/results/{resultUuid}/branch-sides", produces = APPLICATION_JSON_VALUE)
260-
@Operation(summary = "Get the list of branch sides values")
261-
@ApiResponses(@ApiResponse(responseCode = "200", description = "List of branch sides values by result"))
262-
public ResponseEntity<List<ThreeSides>> getBranchSides(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
263-
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(securityAnalysisService.getBranchSides(resultUuid));
259+
@GetMapping(value = "/results/{resultUuid}/nmk-limit-types", produces = APPLICATION_JSON_VALUE)
260+
@Operation(summary = "Get the list of limit types values - NmK results")
261+
@ApiResponses(@ApiResponse(responseCode = "200", description = "List of limit types values by result - NmK results"))
262+
public ResponseEntity<List<LimitViolationType>> getNmKResultLimitTypes(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
263+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(securityAnalysisService.getNmKResultLimitTypes(resultUuid));
264264
}
265265

266-
@GetMapping(value = "/results/{resultUuid}/computation-status", produces = APPLICATION_JSON_VALUE)
267-
@Operation(summary = "Get the list of computation status values")
268-
@ApiResponses(@ApiResponse(responseCode = "200", description = "List of computation status values by result"))
269-
public ResponseEntity<List<com.powsybl.loadflow.LoadFlowResult.ComponentResult.Status>> getComputationStatus(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
270-
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(securityAnalysisService.getComputationStatus(resultUuid));
266+
@GetMapping(value = "/results/{resultUuid}/n-branch-sides", produces = APPLICATION_JSON_VALUE)
267+
@Operation(summary = "Get the list of branch sides values - N results")
268+
@ApiResponses(@ApiResponse(responseCode = "200", description = "List of branch sides values by result - N results"))
269+
public ResponseEntity<List<ThreeSides>> getNResultBranchSides(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
270+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(securityAnalysisService.getNResultBranchSides(resultUuid));
271+
}
272+
273+
@GetMapping(value = "/results/{resultUuid}/nmk-branch-sides", produces = APPLICATION_JSON_VALUE)
274+
@Operation(summary = "Get the list of branch sides values - NmK results")
275+
@ApiResponses(@ApiResponse(responseCode = "200", description = "List of branch sides values by result - NmK results"))
276+
public ResponseEntity<List<ThreeSides>> getNmKResultBranchSides(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
277+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(securityAnalysisService.getNmKResultBranchSides(resultUuid));
278+
}
279+
280+
@GetMapping(value = "/results/{resultUuid}/nmk-computation-status", produces = APPLICATION_JSON_VALUE)
281+
@Operation(summary = "Get the list of computation status values - NmK results")
282+
@ApiResponses(@ApiResponse(responseCode = "200", description = "List of computation status values by result - NmK results"))
283+
public ResponseEntity<List<com.powsybl.loadflow.LoadFlowResult.ComponentResult.Status>> getNmKResultComputationStatus(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
284+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(securityAnalysisService.getNmKComputationStatus(resultUuid));
271285
}
272286
}

src/main/java/org/gridsuite/securityanalysis/server/repositories/ContingencyRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public interface ContingencyRepository extends JpaRepository<ContingencyEntity,
4848
void deleteAllContingencyElementsByContingencyUuidIn(Set<UUID> uuids);
4949

5050
@Query(value = "SELECT distinct c.status from ContingencyEntity as c " +
51-
"where c.uuid = :resultUuid AND c.status != ''" +
51+
"where c.result.id = :resultUuid AND c.status != ''" +
5252
"order by c.status")
5353
List<LoadFlowResult.ComponentResult.Status> findComputingStatus(UUID resultUuid);
5454

src/main/java/org/gridsuite/securityanalysis/server/repositories/PreContingencyLimitViolationRepository.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
package org.gridsuite.securityanalysis.server.repositories;
88

9+
import com.powsybl.iidm.network.ThreeSides;
10+
import com.powsybl.security.LimitViolationType;
911
import org.gridsuite.securityanalysis.server.entities.PreContingencyLimitViolationEntity;
1012
import org.springframework.data.domain.Sort;
1113
import org.springframework.data.jpa.domain.Specification;
@@ -24,4 +26,14 @@ public interface PreContingencyLimitViolationRepository extends JpaRepository<Pr
2426
@Modifying
2527
@Query(value = "DELETE FROM pre_contingency_limit_violation WHERE result_id = ?1", nativeQuery = true)
2628
void deleteAllByResultId(UUID resultId);
29+
30+
@Query(value = "SELECT distinct pc.limitType from PreContingencyLimitViolationEntity as pc " +
31+
"where pc.subjectLimitViolation.result.id = :resultUuid AND pc.limitType != ''" +
32+
"order by pc.limitType")
33+
List<LimitViolationType> findLimitTypes(UUID resultUuid);
34+
35+
@Query(value = "SELECT distinct pc.side from PreContingencyLimitViolationEntity as pc " +
36+
"where pc.subjectLimitViolation.result.id = :resultUuid AND pc.side != ''" +
37+
"order by pc.side")
38+
List<ThreeSides> findBranchSides(UUID resultUuid);
2739
}

src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisResultService.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,19 +357,31 @@ public Page<SubjectLimitViolationEntity> findSubjectLimitViolationsPage(UUID res
357357
}
358358

359359
@Transactional(readOnly = true)
360-
public List<LimitViolationType> findLimitTypes(UUID resultUuid) {
360+
public List<LimitViolationType> findNResultLimitTypes(UUID resultUuid) {
361+
Objects.requireNonNull(resultUuid);
362+
return preContingencyLimitViolationRepository.findLimitTypes(resultUuid);
363+
}
364+
365+
@Transactional(readOnly = true)
366+
public List<LimitViolationType> findNmKResultLimitTypes(UUID resultUuid) {
361367
Objects.requireNonNull(resultUuid);
362368
return contingencyLimitViolationRepository.findLimitTypes(resultUuid);
363369
}
364370

365371
@Transactional(readOnly = true)
366-
public List<ThreeSides> findBranchSides(UUID resultUuid) {
372+
public List<ThreeSides> findNResultBranchSides(UUID resultUuid) {
373+
Objects.requireNonNull(resultUuid);
374+
return preContingencyLimitViolationRepository.findBranchSides(resultUuid);
375+
}
376+
377+
@Transactional(readOnly = true)
378+
public List<ThreeSides> findNmKResultBranchSides(UUID resultUuid) {
367379
Objects.requireNonNull(resultUuid);
368380
return contingencyLimitViolationRepository.findBranchSides(resultUuid);
369381
}
370382

371383
@Transactional(readOnly = true)
372-
public List<com.powsybl.loadflow.LoadFlowResult.ComponentResult.Status> findComputingStatus(UUID resultUuid) {
384+
public List<com.powsybl.loadflow.LoadFlowResult.ComponentResult.Status> findNmKComputingStatus(UUID resultUuid) {
373385
Objects.requireNonNull(resultUuid);
374386
return contingencyRepository.findComputingStatus(resultUuid);
375387
}

src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisService.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,27 @@ public UUID runAndSaveResult(SecurityAnalysisRunContext runContext) {
4949

5050
public List<String> getProviders() {
5151
return SecurityAnalysisProvider.findAll().stream()
52-
.map(SecurityAnalysisProvider::getName)
53-
.toList();
52+
.map(SecurityAnalysisProvider::getName)
53+
.toList();
5454
}
5555

56-
public List<LimitViolationType> getLimitTypes(UUID resultUuid) {
57-
return resultService.findLimitTypes(resultUuid);
56+
public List<LimitViolationType> getNResultLimitTypes(UUID resultUuid) {
57+
return resultService.findNResultLimitTypes(resultUuid);
5858
}
5959

60-
public List<ThreeSides> getBranchSides(UUID resultUuid) {
61-
return resultService.findBranchSides(resultUuid);
60+
public List<LimitViolationType> getNmKResultLimitTypes(UUID resultUuid) {
61+
return resultService.findNmKResultLimitTypes(resultUuid);
6262
}
6363

64-
public List<com.powsybl.loadflow.LoadFlowResult.ComponentResult.Status> getComputationStatus(UUID resultUuid) {
65-
return resultService.findComputingStatus(resultUuid);
64+
public List<ThreeSides> getNResultBranchSides(UUID resultUuid) {
65+
return resultService.findNResultBranchSides(resultUuid);
66+
}
67+
68+
public List<ThreeSides> getNmKResultBranchSides(UUID resultUuid) {
69+
return resultService.findNmKResultBranchSides(resultUuid);
70+
}
71+
72+
public List<com.powsybl.loadflow.LoadFlowResult.ComponentResult.Status> getNmKComputationStatus(UUID resultUuid) {
73+
return resultService.findNmKComputingStatus(resultUuid);
6674
}
6775
}

src/test/java/org/gridsuite/securityanalysis/server/SecurityAnalysisControllerTest.java

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ public void runAndSaveTest() throws Exception {
347347
content().contentType(MediaType.APPLICATION_JSON));
348348

349349
assertFiltredResultN();
350+
checkNResultEnumFilters(RESULT_UUID);
350351

351352
mockMvc.perform(get("/" + VERSION + "/results/" + RESULT_UUID + "/nmk-contingencies-result/paged"))
352353
.andExpectAll(
@@ -358,6 +359,8 @@ public void runAndSaveTest() throws Exception {
358359
status().isOk(),
359360
content().contentType(MediaType.APPLICATION_JSON));
360361

362+
checkNmKResultEnumFilters(RESULT_UUID);
363+
361364
// should throw not found if result does not exist
362365
assertResultNotFound(OTHER_RESULT_UUID);
363366

@@ -463,32 +466,74 @@ private void assertFiltredResultN() throws Exception {
463466
List<PreContingencyLimitViolationResultDTO> preContingencyResult = mapper.readValue(resultAsString, new TypeReference<>() {
464467
});
465468
assertEquals(1, preContingencyResult.size());
469+
}
466470

467-
mvcResult = mockMvc.perform(get("/" + VERSION + "/results/{resultUuid}/limit-types", RESULT_UUID))
468-
.andExpectAll(
469-
status().isOk(),
470-
content().contentType(MediaType.APPLICATION_JSON)
471-
).andReturn();
471+
private void checkNResultEnumFilters(UUID resultUuid) throws Exception {
472+
473+
MvcResult mvcResult = mockMvc.perform(get("/" + VERSION + "/results/" + resultUuid + "/n-result"))
474+
.andExpectAll(
475+
status().isOk(),
476+
content().contentType(MediaType.APPLICATION_JSON)).andReturn();
477+
478+
List<PreContingencyLimitViolationResultDTO> nResults = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() {
479+
});
480+
481+
List<LimitViolationType> expectedLimitTypes = nResults.stream().map(result -> result.getLimitViolation().getLimitType()).distinct().toList();
482+
mvcResult = mockMvc.perform(get("/" + VERSION + "/results/{resultUuid}/n-limit-types", resultUuid))
483+
.andExpectAll(
484+
status().isOk(),
485+
content().contentType(MediaType.APPLICATION_JSON)
486+
).andReturn();
472487
List<LimitViolationType> limitTypes = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
473-
assertEquals(2, limitTypes.size());
474-
assertFalse(limitTypes.contains(LimitViolationType.HIGH_SHORT_CIRCUIT_CURRENT));
488+
Assertions.assertThat(limitTypes).hasSameElementsAs(expectedLimitTypes);
475489

476-
mvcResult = mockMvc.perform(get("/" + VERSION + "/results/{resultUuid}/branch-sides", RESULT_UUID))
477-
.andExpectAll(
478-
status().isOk(),
479-
content().contentType(MediaType.APPLICATION_JSON)
480-
).andReturn();
490+
List<ThreeSides> expectedSides = nResults.stream().map(result -> result.getLimitViolation().getSide()).distinct().filter(side -> side != null).toList();
491+
mvcResult = mockMvc.perform(get("/" + VERSION + "/results/{resultUuid}/n-branch-sides", resultUuid))
492+
.andExpectAll(
493+
status().isOk(),
494+
content().contentType(MediaType.APPLICATION_JSON)
495+
).andReturn();
481496
List<ThreeSides> sides = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
482-
assertEquals(1, sides.size());
483-
assertTrue(sides.contains(ThreeSides.ONE));
497+
Assertions.assertThat(sides).hasSameElementsAs(expectedSides);
498+
}
484499

485-
mvcResult = mockMvc.perform(get("/" + VERSION + "/results/{resultUuid}/computation-status", RESULT_UUID))
486-
.andExpectAll(
487-
status().isOk(),
488-
content().contentType(MediaType.APPLICATION_JSON)
489-
).andReturn();
500+
private void checkNmKResultEnumFilters(UUID resultUuid) throws Exception {
501+
// getting 100 elements here because we want to fetch all test datas to check fetched filters belongs to fetched results
502+
MvcResult mvcResult = mockMvc.perform(get("/" + VERSION + "/results/" + RESULT_UUID + "/nmk-contingencies-result/paged?size=100"))
503+
.andExpectAll(
504+
status().isOk(),
505+
content().contentType(MediaType.APPLICATION_JSON)).andReturn();
506+
// getting paged result as list
507+
JsonNode resultsJsonNode = mapper.readTree(mvcResult.getResponse().getContentAsString());
508+
ObjectReader resultsObjectReader = mapper.readerFor(new TypeReference<List<ContingencyResultDTO>>() { });
509+
List<ContingencyResultDTO> nmkResult = resultsObjectReader.readValue(resultsJsonNode.get("content"));
510+
511+
List<LimitViolationType> expectedLimitTypes = nmkResult.stream().map(ContingencyResultDTO::getSubjectLimitViolations).flatMap(subjectLimitViolationDTOS -> subjectLimitViolationDTOS.stream().map(slm -> slm.getLimitViolation().getLimitType())).distinct().toList();
512+
mvcResult = mockMvc.perform(get("/" + VERSION + "/results/{resultUuid}/nmk-limit-types", resultUuid))
513+
.andExpectAll(
514+
status().isOk(),
515+
content().contentType(MediaType.APPLICATION_JSON)
516+
).andReturn();
517+
List<LimitViolationType> limitTypes = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
518+
Assertions.assertThat(limitTypes).hasSameElementsAs(expectedLimitTypes);
519+
520+
List<ThreeSides> expectedSides = nmkResult.stream().map(ContingencyResultDTO::getSubjectLimitViolations).flatMap(subjectLimitViolationDTOS -> subjectLimitViolationDTOS.stream().map(slm -> slm.getLimitViolation().getSide())).filter(Objects::nonNull).distinct().toList();
521+
mvcResult = mockMvc.perform(get("/" + VERSION + "/results/{resultUuid}/nmk-branch-sides", resultUuid))
522+
.andExpectAll(
523+
status().isOk(),
524+
content().contentType(MediaType.APPLICATION_JSON)
525+
).andReturn();
526+
List<ThreeSides> sides = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
527+
Assertions.assertThat(sides).hasSameElementsAs(expectedSides);
528+
529+
List<LoadFlowResult.ComponentResult.Status> expectedStatus = nmkResult.stream().map(result -> LoadFlowResult.ComponentResult.Status.valueOf(result.getContingency().getStatus())).distinct().toList();
530+
mvcResult = mockMvc.perform(get("/" + VERSION + "/results/{resultUuid}/nmk-computation-status", resultUuid))
531+
.andExpectAll(
532+
status().isOk(),
533+
content().contentType(MediaType.APPLICATION_JSON)
534+
).andReturn();
490535
List<LoadFlowResult.ComponentResult.Status> status = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
491-
assertEquals(0, status.size());
536+
Assertions.assertThat(status).hasSameElementsAs(expectedStatus);
492537
}
493538

494539
@Test

0 commit comments

Comments
 (0)