Skip to content

Commit 01005c9

Browse files
authored
get filter enum values (#86)
Signed-off-by: Rehili Ghazwa <[email protected]>
1 parent 9b144e5 commit 01005c9

File tree

5 files changed

+61
-7
lines changed

5 files changed

+61
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,18 @@ public ResponseEntity<Void> stop(@Parameter(description = "Result UUID") @PathVa
165165
return ResponseEntity.ok().build();
166166
}
167167

168-
@GetMapping(value = "/fault-types", produces = APPLICATION_JSON_VALUE)
168+
@GetMapping(value = "/results/{resultUuid}/fault-types", produces = APPLICATION_JSON_VALUE)
169169
@Operation(summary = "Get list of fault types")
170170
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The list of fault types")})
171-
public ResponseEntity<FaultType[]> getFaultTypes() {
172-
return ResponseEntity.ok().body(FaultType.values());
171+
public ResponseEntity<List<FaultType>> getFaultTypes(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
172+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(shortCircuitService.getFaultTypes(resultUuid));
173173
}
174174

175-
@GetMapping(value = "/limit-violation-types", produces = APPLICATION_JSON_VALUE)
175+
@GetMapping(value = "/results/{resultUuid}/limit-violation-types", produces = APPLICATION_JSON_VALUE)
176176
@Operation(summary = "Get list of limit violation types")
177-
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The list of limit violation types")})
178-
public ResponseEntity<List<LimitViolationType>> getLimitTypes() {
179-
return ResponseEntity.ok().body(List.of(LimitViolationType.LOW_SHORT_CIRCUIT_CURRENT, LimitViolationType.HIGH_SHORT_CIRCUIT_CURRENT));
177+
@ApiResponses(@ApiResponse(responseCode = "200", description = "The list of limit violation types"))
178+
public ResponseEntity<List<LimitViolationType>> getLimitTypes(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
179+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(shortCircuitService.getLimitTypes(resultUuid));
180180
}
181181

182182
}

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

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

9+
import com.powsybl.security.LimitViolationType;
10+
import com.powsybl.shortcircuit.Fault;
911
import org.gridsuite.shortcircuit.server.entities.FaultResultEntity;
1012
import org.springframework.data.jpa.domain.Specification;
1113
import org.springframework.data.jpa.repository.*;
@@ -55,4 +57,14 @@ public interface FaultResultRepository extends JpaRepository<FaultResultEntity,
5557
interface EntityId {
5658
UUID getFaultResultUuid();
5759
}
60+
61+
@Query(value = " SELECT DISTINCT limit_Type FROM fault_result_entity " +
62+
" where result_result_uuid = :resultUuid AND limit_Type not like ''" +
63+
"order by limit_Type", nativeQuery = true)
64+
List<LimitViolationType> findLimitTypes(UUID resultUuid);
65+
66+
@Query(value = " SELECT DISTINCT fault_Type FROM fault_result_entity " +
67+
" where result_result_uuid = :resultUuid AND fault_Type not like ''" +
68+
"order by fault_Type", nativeQuery = true)
69+
List<Fault.FaultType> findFaultTypes(UUID resultUuid);
5870
}

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

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

9+
import com.powsybl.security.LimitViolationType;
910
import com.powsybl.shortcircuit.*;
1011
import lombok.extern.slf4j.Slf4j;
1112
import org.gridsuite.shortcircuit.server.dto.FaultResultsMode;
@@ -166,6 +167,18 @@ public void insertStatus(List<UUID> resultUuids, String status) {
166167
.map(uuid -> toStatusEntity(uuid, status)).toList());
167168
}
168169

170+
@Transactional(readOnly = true)
171+
public List<LimitViolationType> findLimitTypes(UUID resultUuid) {
172+
Objects.requireNonNull(resultUuid);
173+
return faultResultRepository.findLimitTypes(resultUuid);
174+
}
175+
176+
@Transactional(readOnly = true)
177+
public List<Fault.FaultType> findFaultTypes(UUID resultUuid) {
178+
Objects.requireNonNull(resultUuid);
179+
return faultResultRepository.findFaultTypes(resultUuid);
180+
}
181+
169182
@Transactional
170183
public void insert(UUID resultUuid, ShortCircuitAnalysisResult result, ShortCircuitRunContext runContext, String status) {
171184
Objects.requireNonNull(resultUuid);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package org.gridsuite.shortcircuit.server.service;
88

99
import com.fasterxml.jackson.databind.ObjectMapper;
10+
import com.powsybl.security.LimitViolationType;
1011
import com.powsybl.ws.commons.LogUtils;
1112
import com.univocity.parsers.csv.CsvWriter;
1213
import com.univocity.parsers.csv.CsvWriterSettings;
@@ -312,4 +313,12 @@ public void setStatus(List<UUID> resultUuids, String status) {
312313
public void stop(UUID resultUuid, String receiver) {
313314
notificationService.sendCancelMessage(new ShortCircuitCancelContext(resultUuid, receiver).toMessage());
314315
}
316+
317+
public List<LimitViolationType> getLimitTypes(UUID resultUuid) {
318+
return resultRepository.findLimitTypes(resultUuid);
319+
}
320+
321+
public List<com.powsybl.shortcircuit.Fault.FaultType> getFaultTypes(UUID resultUuid) {
322+
return resultRepository.findFaultTypes(resultUuid);
323+
}
315324
}

src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,26 @@ public void testStatus() {
738738
assertEquals(ShortCircuitAnalysisStatus.NOT_DONE.name(), result.getResponse().getContentAsString());
739739
}
740740

741+
@SneakyThrows
742+
@Test
743+
public void testGetFaultTypes() {
744+
MvcResult result = mockMvc.perform(get(
745+
"/" + VERSION + "/results/{resultUuid}/fault-types", RESULT_UUID))
746+
.andExpect(status().isOk())
747+
.andReturn();
748+
assertEquals("[]", result.getResponse().getContentAsString());
749+
}
750+
751+
@SneakyThrows
752+
@Test
753+
public void testGetLimitTypes() {
754+
MvcResult result = mockMvc.perform(get(
755+
"/" + VERSION + "/results/{resultUuid}/limit-violation-types", RESULT_UUID))
756+
.andExpect(status().isOk())
757+
.andReturn();
758+
assertEquals("[]", result.getResponse().getContentAsString());
759+
}
760+
741761
@SneakyThrows
742762
@Test
743763
public void runWithReportTest() {

0 commit comments

Comments
 (0)