Skip to content

Commit 030e143

Browse files
authored
Add endpoint to return icc of voltage level for a specific result (#171)
Signed-off-by: LE SAULNIER Kevin <[email protected]>
1 parent 248ba9d commit 030e143

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

src/main/java/org/gridsuite/shortcircuit/server/ShortCircuitController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.net.URLDecoder;
3030
import java.nio.charset.StandardCharsets;
3131
import java.util.List;
32+
import java.util.Map;
3233
import java.util.Optional;
3334
import java.util.UUID;
3435

@@ -78,6 +79,14 @@ public ResponseEntity<ShortCircuitAnalysisResult> getResult(@Parameter(descripti
7879
: ResponseEntity.notFound().build();
7980
}
8081

82+
@GetMapping(value = "/results/{resultUuid}/fault_results/icc", produces = APPLICATION_JSON_VALUE)
83+
@Operation(summary = "Get a map from fault results for a given short circuit analysis result and a specific voltage level")
84+
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The map busId -> ICC is returned")})
85+
public ResponseEntity<Map<String, Double>> getResult(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid,
86+
@Parameter(description = "Voltage level ID to filter on") @RequestParam(value = "voltageLevelId")String voltageLevelId) {
87+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(shortCircuitService.getBasicResultForSpecificEquipment(resultUuid, voltageLevelId));
88+
}
89+
8190
@PostMapping(value = "/results/{resultUuid}/csv", produces = APPLICATION_OCTET_STREAM_VALUE)
8291
@Operation(summary = "Get a short circuit analysis csv result from the database")
8392
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The short circuit analysis csv export"),

src/main/java/org/gridsuite/shortcircuit/server/repositories/FaultResultRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public interface FaultResultRepository extends JpaRepository<FaultResultEntity,
3636
@Query(value = "SELECT faultResultUuid FROM FaultResultEntity WHERE result.resultUuid = ?1")
3737
Set<UUID> findAllFaultResultUuidsByShortCircuitResultUuid(UUID resultUuid);
3838

39+
List<FaultResultEntity> findAllByResultResultUuidAndFaultVoltageLevelId(UUID resultUuid, String voltageLevelId);
40+
3941
// From: https://www.baeldung.com/spring-data-jpa-deleteby
4042
// "The @Query method creates a single SQL query against the database. By comparison, the deleteBy methods execute a read query, then delete each of the items one by one."
4143
// As we need here to delete thousands of fault results, using native SQL query was required for having decent performance.

src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitAnalysisResultService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,10 @@ private Pageable addDefaultSort(Pageable pageable, String defaultSortColumn) {
446446
return pageable;
447447
}
448448

449+
public List<FaultResultEntity> getFaultResultByVoltageLevelId(UUID resultUuid, String voltageLevelId) {
450+
return faultResultRepository.findAllByResultResultUuidAndFaultVoltageLevelId(resultUuid, voltageLevelId);
451+
}
452+
449453
@Override
450454
@Transactional
451455
public void saveDebugFileLocation(UUID resultUuid, String debugFilePath) {

src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ public ShortCircuitAnalysisResult getResult(UUID resultUuid, FaultResultsMode mo
340340
return null;
341341
}
342342

343+
public Map<String, Double> getBasicResultForSpecificEquipment(UUID resultUuid, String voltageLevelId) {
344+
return resultService.getFaultResultByVoltageLevelId(resultUuid, voltageLevelId).stream().collect(Collectors.toMap(fr -> fr.getFault().getElementId(), FaultResultEntity::getCurrent));
345+
}
346+
343347
@Transactional(readOnly = true)
344348
public Page<FaultResult> getFaultResultsPage(UUID rootNetworkUuid,
345349
String variantId,

0 commit comments

Comments
 (0)