From 2fb3ed600514fdcf8b80d32dd3cd97ac4a93dca1 Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Mon, 20 Oct 2025 14:29:40 +0200 Subject: [PATCH 1/5] refacto vl topo suggestion --- .../network/map/NetworkMapController.java | 19 ++--- .../topology/BusBarSectionsInfos.java | 32 ++++++++ .../topology}/SwitchInfos.java | 3 +- .../definition/topology/TopologyInfos.java | 24 ++---- .../voltagelevel/VoltageLevelFormInfos.java | 16 ++++ .../dto/mapper/VoltageLevelInfosMapper.java | 63 +++++++++++++- .../network/map/dto/utils/TopologyUtils.java | 82 +++++++++++++------ .../map/services/NetworkMapService.java | 33 ++++---- 8 files changed, 193 insertions(+), 79 deletions(-) create mode 100644 src/main/java/org/gridsuite/network/map/dto/definition/topology/BusBarSectionsInfos.java rename src/main/java/org/gridsuite/network/map/dto/{ => definition/topology}/SwitchInfos.java (81%) diff --git a/src/main/java/org/gridsuite/network/map/NetworkMapController.java b/src/main/java/org/gridsuite/network/map/NetworkMapController.java index 58655760..018adc3e 100644 --- a/src/main/java/org/gridsuite/network/map/NetworkMapController.java +++ b/src/main/java/org/gridsuite/network/map/NetworkMapController.java @@ -14,7 +14,10 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.AllArgsConstructor; -import org.gridsuite.network.map.dto.*; +import org.gridsuite.network.map.dto.AllElementsInfos; +import org.gridsuite.network.map.dto.ElementInfos; +import org.gridsuite.network.map.dto.ElementType; +import org.gridsuite.network.map.dto.InfoTypeParameters; import org.gridsuite.network.map.dto.definition.hvdc.HvdcShuntCompensatorsInfos; import org.gridsuite.network.map.dto.definition.topology.TopologyInfos; import org.gridsuite.network.map.services.NetworkMapService; @@ -90,22 +93,14 @@ public List getVoltageLevelBusesOrBusBarSections(@Parameter(descri return networkMapService.getVoltageLevelBusesOrBusbarSections(networkUuid, voltageLevelId, variantId); } - @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/switches", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Get switches description for a voltage level") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Switches description")}) - public List getVoltageLevelSwitches(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid, - @Parameter(description = "Voltage level id") @PathVariable("voltageLevelId") String voltageLevelId, - @Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId) { - return networkMapService.getVoltageLevelSwitches(networkUuid, voltageLevelId, variantId); - } - @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology", produces = APPLICATION_JSON_VALUE) @Operation(summary = "Get the voltage level topology description") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Network topology information retrieved")}) public TopologyInfos getVoltageLevelTopology(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid, @Parameter(description = "Voltage level id") @PathVariable("voltageLevelId") String voltageLevelId, - @Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId) { - return networkMapService.getVoltageLevelTopology(networkUuid, voltageLevelId, variantId); + @Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId, + @Parameter(description = "Filters : switches, feeder_bays, busbar_sections") @RequestParam(name = "filter") Optional> filter) { + return networkMapService.getVoltageLevelTopology(networkUuid, voltageLevelId, variantId, filter.orElseGet(List::of)); } @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/substation-id", produces = APPLICATION_JSON_VALUE) diff --git a/src/main/java/org/gridsuite/network/map/dto/definition/topology/BusBarSectionsInfos.java b/src/main/java/org/gridsuite/network/map/dto/definition/topology/BusBarSectionsInfos.java new file mode 100644 index 00000000..85ebae56 --- /dev/null +++ b/src/main/java/org/gridsuite/network/map/dto/definition/topology/BusBarSectionsInfos.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2025, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.network.map.dto.definition.topology; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.SuperBuilder; +import org.gridsuite.network.map.dto.definition.voltagelevel.VoltageLevelFormInfos; + +import java.util.List; +import java.util.Map; + +/** + * @author Rehili Ghazwa + */ +@SuperBuilder +@Getter +@Setter +public class BusBarSectionsInfos extends VoltageLevelFormInfos { + + @JsonInclude(JsonInclude.Include.NON_NULL) + Boolean isBusbarSectionPositionFound; + + @JsonInclude(JsonInclude.Include.NON_NULL) + Map> busBarSections; +} + diff --git a/src/main/java/org/gridsuite/network/map/dto/SwitchInfos.java b/src/main/java/org/gridsuite/network/map/dto/definition/topology/SwitchInfos.java similarity index 81% rename from src/main/java/org/gridsuite/network/map/dto/SwitchInfos.java rename to src/main/java/org/gridsuite/network/map/dto/definition/topology/SwitchInfos.java index 9015b6cd..4afa16eb 100644 --- a/src/main/java/org/gridsuite/network/map/dto/SwitchInfos.java +++ b/src/main/java/org/gridsuite/network/map/dto/definition/topology/SwitchInfos.java @@ -4,10 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.network.map.dto; +package org.gridsuite.network.map.dto.definition.topology; import lombok.Getter; import lombok.experimental.SuperBuilder; +import org.gridsuite.network.map.dto.ElementInfos; /** * @author Rehili Ghazwa diff --git a/src/main/java/org/gridsuite/network/map/dto/definition/topology/TopologyInfos.java b/src/main/java/org/gridsuite/network/map/dto/definition/topology/TopologyInfos.java index 23012d59..866ca532 100644 --- a/src/main/java/org/gridsuite/network/map/dto/definition/topology/TopologyInfos.java +++ b/src/main/java/org/gridsuite/network/map/dto/definition/topology/TopologyInfos.java @@ -7,9 +7,8 @@ package org.gridsuite.network.map.dto.definition.topology; import com.fasterxml.jackson.annotation.JsonInclude; -import com.powsybl.iidm.network.SwitchKind; -import com.powsybl.iidm.network.TopologyKind; import lombok.Getter; +import lombok.Setter; import lombok.experimental.SuperBuilder; import java.util.List; @@ -20,28 +19,15 @@ */ @SuperBuilder @Getter +@Setter public class TopologyInfos { - @JsonInclude(JsonInclude.Include.NON_NULL) - private TopologyKind topologyKind; - - @JsonInclude(JsonInclude.Include.NON_NULL) - private Integer busbarCount; @JsonInclude(JsonInclude.Include.NON_NULL) - private Integer sectionCount; + private BusBarSectionsInfos busBarSectionsInfos; @JsonInclude(JsonInclude.Include.NON_NULL) - private List switchKinds; - - @JsonInclude(JsonInclude.Include.NON_NULL) - private Boolean isSymmetrical; - - @JsonInclude(JsonInclude.Include.NON_NULL) - private Boolean isBusbarSectionPositionExtensionFound; - - @JsonInclude(JsonInclude.Include.NON_NULL) - private Map> busBarSectionsInfos; + private Map> feederBaysInfos; @JsonInclude(JsonInclude.Include.NON_NULL) - private Map> feederBaysInfos; + private List switchesInfos; } diff --git a/src/main/java/org/gridsuite/network/map/dto/definition/voltagelevel/VoltageLevelFormInfos.java b/src/main/java/org/gridsuite/network/map/dto/definition/voltagelevel/VoltageLevelFormInfos.java index 2700df97..ef7ce9ad 100644 --- a/src/main/java/org/gridsuite/network/map/dto/definition/voltagelevel/VoltageLevelFormInfos.java +++ b/src/main/java/org/gridsuite/network/map/dto/definition/voltagelevel/VoltageLevelFormInfos.java @@ -7,12 +7,15 @@ package org.gridsuite.network.map.dto.definition.voltagelevel; import com.fasterxml.jackson.annotation.JsonInclude; +import com.powsybl.iidm.network.SwitchKind; import com.powsybl.iidm.network.TopologyKind; import lombok.Getter; +import lombok.Setter; import lombok.experimental.SuperBuilder; import org.gridsuite.network.map.dto.ElementInfosWithProperties; import org.gridsuite.network.map.dto.definition.extension.IdentifiableShortCircuitInfos; +import java.util.List; import java.util.Optional; /** @@ -20,11 +23,24 @@ */ @SuperBuilder @Getter +@Setter public class VoltageLevelFormInfos extends ElementInfosWithProperties { @JsonInclude(JsonInclude.Include.NON_NULL) private TopologyKind topologyKind; + @JsonInclude(JsonInclude.Include.NON_NULL) + private Integer busbarCount; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private Integer sectionCount; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private List switchKinds; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private Boolean isSymmetrical; + @JsonInclude(JsonInclude.Include.NON_NULL) private String substationId; diff --git a/src/main/java/org/gridsuite/network/map/dto/mapper/VoltageLevelInfosMapper.java b/src/main/java/org/gridsuite/network/map/dto/mapper/VoltageLevelInfosMapper.java index 411a7c05..1c688c48 100644 --- a/src/main/java/org/gridsuite/network/map/dto/mapper/VoltageLevelInfosMapper.java +++ b/src/main/java/org/gridsuite/network/map/dto/mapper/VoltageLevelInfosMapper.java @@ -6,9 +6,8 @@ */ package org.gridsuite.network.map.dto.mapper; -import com.powsybl.iidm.network.Identifiable; -import com.powsybl.iidm.network.Substation; -import com.powsybl.iidm.network.VoltageLevel; +import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.extensions.BusbarSectionPosition; import org.gridsuite.network.map.dto.ElementInfos; import org.gridsuite.network.map.dto.InfoTypeParameters; import org.gridsuite.network.map.dto.definition.voltagelevel.VoltageLevelFormInfos; @@ -17,6 +16,11 @@ import org.gridsuite.network.map.dto.utils.ElementUtils; import org.gridsuite.network.map.dto.utils.ExtensionUtils; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static com.powsybl.iidm.network.TopologyKind.NODE_BREAKER; import static org.gridsuite.network.map.dto.utils.ElementUtils.*; /** @@ -38,7 +42,7 @@ public static ElementInfos toData(Identifiable identifiable, InfoTypeParamete static VoltageLevelFormInfos toFormInfos(Identifiable identifiable) { VoltageLevel voltageLevel = (VoltageLevel) identifiable; - return VoltageLevelFormInfos.builder() + VoltageLevelFormInfos voltageLevelFormInfos = VoltageLevelFormInfos.builder() .name(voltageLevel.getOptionalName().orElse(null)) .id(voltageLevel.getId()) .topologyKind(voltageLevel.getTopologyKind()) @@ -49,6 +53,14 @@ static VoltageLevelFormInfos toFormInfos(Identifiable identifiable) { .properties(getProperties(voltageLevel)) .identifiableShortCircuit(ExtensionUtils.toIdentifiableShortCircuit(voltageLevel)) .build(); + if (voltageLevel.getTopologyKind().equals(TopologyKind.NODE_BREAKER)) { + VoltageLevelFormInfos barSectionsInfos = getVoltageLevelBusBarSectionsInfos(voltageLevel); + voltageLevelFormInfos.setBusbarCount(barSectionsInfos.getBusbarCount()); + voltageLevelFormInfos.setSectionCount(barSectionsInfos.getSectionCount()); + voltageLevelFormInfos.setSwitchKinds(barSectionsInfos.getSwitchKinds()); + voltageLevelFormInfos.setIsSymmetrical(barSectionsInfos.getIsSymmetrical()); + } + return voltageLevelFormInfos; } static VoltageLevelMapInfos toMapInfos(Identifiable identifiable) { @@ -78,4 +90,47 @@ static VoltageLevelTabInfos toTabInfos(Identifiable identifiable) { return builder.build(); } + + public static VoltageLevelFormInfos getVoltageLevelBusBarSectionsInfos(VoltageLevel voltageLevel) { + Map nbSectionsPerBusbar = new HashMap<>(); + int maxBusbarIndex = 1; + int maxSectionIndex = 1; + for (BusbarSection bbs : voltageLevel.getNodeBreakerView().getBusbarSections()) { + var extension = bbs.getExtension(BusbarSectionPosition.class); + if (extension == null) { + return VoltageLevelFormInfos.builder() + .busbarCount(1) + .sectionCount(1) + .topologyKind(NODE_BREAKER) + .switchKinds(Collections.emptyList()) + .isSymmetrical(false) + .build(); + } + int busbarIndex = extension.getBusbarIndex(); + int sectionIndex = extension.getSectionIndex(); + maxBusbarIndex = Math.max(maxBusbarIndex, busbarIndex); + maxSectionIndex = Math.max(maxSectionIndex, sectionIndex); + nbSectionsPerBusbar.merge(busbarIndex, 1, Integer::sum); + } + + boolean isSymmetrical = maxBusbarIndex == 1 || + nbSectionsPerBusbar.values().stream().distinct().count() == 1 + && nbSectionsPerBusbar.values().stream().findFirst().orElse(0).equals(maxSectionIndex); + + if (isSymmetrical) { + return VoltageLevelFormInfos.builder() + .busbarCount(maxBusbarIndex) + .sectionCount(maxSectionIndex) + .switchKinds(Collections.nCopies(maxSectionIndex - 1, SwitchKind.DISCONNECTOR)) + .isSymmetrical(true) + .build(); + } + return VoltageLevelFormInfos.builder() + .busbarCount(1) + .sectionCount(1) + .topologyKind(NODE_BREAKER) + .switchKinds(Collections.emptyList()) + .isSymmetrical(false) + .build(); + } } diff --git a/src/main/java/org/gridsuite/network/map/dto/utils/TopologyUtils.java b/src/main/java/org/gridsuite/network/map/dto/utils/TopologyUtils.java index 14edead4..b63c71c2 100644 --- a/src/main/java/org/gridsuite/network/map/dto/utils/TopologyUtils.java +++ b/src/main/java/org/gridsuite/network/map/dto/utils/TopologyUtils.java @@ -8,9 +8,11 @@ import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.BusbarSectionPosition; +import lombok.Getter; import org.gridsuite.network.map.dto.definition.busbarsection.BusBarSectionFormInfos; +import org.gridsuite.network.map.dto.definition.topology.BusBarSectionsInfos; import org.gridsuite.network.map.dto.definition.topology.FeederBayInfos; -import org.gridsuite.network.map.dto.definition.topology.TopologyInfos; +import org.gridsuite.network.map.dto.definition.topology.SwitchInfos; import java.util.*; import java.util.stream.Collectors; @@ -24,19 +26,55 @@ */ public final class TopologyUtils { - private TopologyUtils() { + @Getter + public enum TopologyFilterType { + + SWITCHES("switches"), + FEEDER_BAYS("feeder_bays"), + BUSBAR_SECTIONS("busbar_sections"); + + private final String value; + + TopologyFilterType(String value) { + this.value = value; + } + + public static Set fromList(List filters) { + Set result = new HashSet<>(); + if (filters == null || filters.isEmpty()) { + return result; + } + for (String filter : filters) { + String trimmedValue = filter.trim(); + if (trimmedValue.isEmpty()) { + continue; + } + for (TopologyFilterType type : TopologyFilterType.values()) { + if (type.value.equalsIgnoreCase(trimmedValue)) { + result.add(type); + break; + } + } + } + return result; + } } - public static TopologyInfos getTopologyInfos(VoltageLevel voltageLevel) { + private TopologyUtils() { } + + public static BusBarSectionsInfos getBusBarSectionsInfos(VoltageLevel voltageLevel) { Map nbSectionsPerBusbar = new HashMap<>(); List busbarSectionInfos = new ArrayList<>(); + BusBarSectionsInfos busBarSectionsInfos = BusBarSectionsInfos.builder() + .isBusbarSectionPositionFound(true) + .isSymmetrical(false) + .build(); int maxBusbarIndex = 1; int maxSectionIndex = 1; - boolean busbarSectionPositionFound = true; for (BusbarSection bbs : voltageLevel.getNodeBreakerView().getBusbarSections()) { var extension = bbs.getExtension(BusbarSectionPosition.class); if (extension == null) { - busbarSectionPositionFound = false; + busBarSectionsInfos.setIsBusbarSectionPositionFound(false); break; } int busbarIndex = extension.getBusbarIndex(); @@ -50,12 +88,8 @@ public static TopologyInfos getTopologyInfos(VoltageLevel voltageLevel) { .horizPos(busbarIndex) .build()); } - TopologyInfos.TopologyInfosBuilder voltageLevelTopologyInfos = createDefaultTopologyInfosBuilder(); - if (!busbarSectionPositionFound) { - return voltageLevelTopologyInfos.build(); - } - voltageLevelTopologyInfos.busBarSectionsInfos(busbarSectionInfos.stream() + busBarSectionsInfos.setBusBarSections(busbarSectionInfos.stream() .collect(Collectors.groupingBy( section -> String.valueOf(section.getHorizPos()), Collectors.collectingAndThen( @@ -66,20 +100,17 @@ public static TopologyInfos getTopologyInfos(VoltageLevel voltageLevel) { .toList() ) ))); - voltageLevelTopologyInfos.isBusbarSectionPositionExtensionFound(true); boolean isSymmetrical = maxBusbarIndex == 1 || nbSectionsPerBusbar.values().stream().distinct().count() == 1 && nbSectionsPerBusbar.values().stream().findFirst().orElse(0).equals(maxSectionIndex); if (isSymmetrical) { - voltageLevelTopologyInfos.busbarCount(maxBusbarIndex); - voltageLevelTopologyInfos.sectionCount(maxSectionIndex); - voltageLevelTopologyInfos.isSymmetrical(true); - voltageLevelTopologyInfos.switchKinds(Collections.nCopies(maxSectionIndex - 1, SwitchKind.DISCONNECTOR)); + busBarSectionsInfos.setIsSymmetrical(true); + busBarSectionsInfos.setSwitchKinds(Collections.nCopies(maxSectionIndex - 1, SwitchKind.DISCONNECTOR)); } - voltageLevelTopologyInfos.feederBaysInfos(getFeederBaysInfos(voltageLevel)); - return voltageLevelTopologyInfos.build(); + busBarSectionsInfos.setTopologyKind(voltageLevel.getTopologyKind()); + return busBarSectionsInfos; } public static Map> getFeederBaysInfos(VoltageLevel voltageLevel) { @@ -104,14 +135,13 @@ public static Map> getFeederBaysInfos(VoltageLevel return feederBayInfos; } - private static TopologyInfos.TopologyInfosBuilder createDefaultTopologyInfosBuilder() { - return TopologyInfos.builder() - .busbarCount(1) - .sectionCount(1) - .isSymmetrical(false) - .switchKinds(List.of()) - .busBarSectionsInfos(Map.of()) - .isBusbarSectionPositionExtensionFound(false) - .topologyKind(TopologyKind.NODE_BREAKER); + public static List getSwitchesInfos(String voltageLevelId, Network network) { + List switchInfosList = new ArrayList<>(); + network.getVoltageLevel(voltageLevelId).getSwitches().forEach(sw -> + switchInfosList.add(SwitchInfos.builder() + .id(sw.getId()) + .open(sw.isOpen()) + .build())); + return switchInfosList; } } diff --git a/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java b/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java index 9b178805..618f7048 100644 --- a/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java +++ b/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java @@ -12,7 +12,10 @@ import com.powsybl.network.store.client.NetworkStoreService; import com.powsybl.network.store.client.PreloadingStrategy; import lombok.AllArgsConstructor; -import org.gridsuite.network.map.dto.*; +import org.gridsuite.network.map.dto.AllElementsInfos; +import org.gridsuite.network.map.dto.ElementInfos; +import org.gridsuite.network.map.dto.ElementType; +import org.gridsuite.network.map.dto.InfoTypeParameters; import org.gridsuite.network.map.dto.definition.hvdc.HvdcShuntCompensatorsInfos; import org.gridsuite.network.map.dto.definition.topology.TopologyInfos; import org.gridsuite.network.map.dto.mapper.ElementInfosMapper; @@ -126,25 +129,21 @@ public List getVoltageLevelBusesOrBusbarSections(UUID networkUuid, }; } - public List getVoltageLevelSwitches(UUID networkUuid, String voltageLevelId, String variantId) { - Network network = getNetwork(networkUuid, PreloadingStrategy.NONE, variantId); - - List switchInfosList = new ArrayList<>(); - network.getVoltageLevel(voltageLevelId).getSwitches().forEach(sw -> - switchInfosList.add(SwitchInfos.builder() - .id(sw.getId()) - .open(sw.isOpen()) - .build())); - return switchInfosList; - } - - public TopologyInfos getVoltageLevelTopology(UUID networkUuid, String voltageLevelId, String variantId) { + public TopologyInfos getVoltageLevelTopology(UUID networkUuid, String voltageLevelId, String variantId, List filter) { + Set filters = TopologyUtils.TopologyFilterType.fromList(filter); Network network = getNetwork(networkUuid, PreloadingStrategy.NONE, variantId); VoltageLevel voltageLevel = network.getVoltageLevel(voltageLevelId); - if (voltageLevel.getTopologyKind().equals(TopologyKind.NODE_BREAKER)) { - return TopologyUtils.getTopologyInfos(voltageLevel); + TopologyInfos topologyInfos = TopologyInfos.builder().build(); + if (filters.contains(TopologyUtils.TopologyFilterType.SWITCHES)) { + topologyInfos.setSwitchesInfos(TopologyUtils.getSwitchesInfos(voltageLevelId, network)); + } + if (filters.contains(TopologyUtils.TopologyFilterType.FEEDER_BAYS)) { + topologyInfos.setFeederBaysInfos(TopologyUtils.getFeederBaysInfos(voltageLevel)); + } + if (filters.contains(TopologyUtils.TopologyFilterType.BUSBAR_SECTIONS)) { + topologyInfos.setBusBarSectionsInfos(TopologyUtils.getBusBarSectionsInfos(voltageLevel)); } - return TopologyInfos.builder().topologyKind(TopologyKind.BUS_BREAKER).build(); + return topologyInfos; } public String getVoltageLevelSubstationID(UUID networkUuid, String voltageLevelId, String variantId) { From beb670e021cd4fb46df05c56c0da0780ad84f4be Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Mon, 20 Oct 2025 17:16:53 +0200 Subject: [PATCH 2/5] add TU --- .../network/map/NetworkMapController.java | 4 +- .../network/map/NetworkMapControllerTest.java | 45 ++++++++--- .../resources/busbar-sections-all-data.json | 17 ++++ ...pology-info.json => feeder-bays-data.json} | 13 --- src/test/resources/substations-form-data.json | 44 ++++++---- .../resources/switches-data-in-variant.json | 38 ++++----- src/test/resources/switches-data.json | 38 ++++----- src/test/resources/topology-form-data.json | 66 +++++++++++++++ .../voltage-level-form-data-feederbays.json | 18 ----- .../resources/voltage-level-form-data.json | 8 +- ...vel-non-symmetrical-busbars-form-data.json | 6 +- .../resources/voltage-levels-form-data.json | 80 +++++++++++-------- 12 files changed, 242 insertions(+), 135 deletions(-) create mode 100644 src/test/resources/busbar-sections-all-data.json rename src/test/resources/{topology-info.json => feeder-bays-data.json} (73%) create mode 100644 src/test/resources/topology-form-data.json delete mode 100644 src/test/resources/voltage-level-form-data-feederbays.json diff --git a/src/main/java/org/gridsuite/network/map/NetworkMapController.java b/src/main/java/org/gridsuite/network/map/NetworkMapController.java index 018adc3e..2ac9ba94 100644 --- a/src/main/java/org/gridsuite/network/map/NetworkMapController.java +++ b/src/main/java/org/gridsuite/network/map/NetworkMapController.java @@ -99,8 +99,8 @@ public List getVoltageLevelBusesOrBusBarSections(@Parameter(descri public TopologyInfos getVoltageLevelTopology(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid, @Parameter(description = "Voltage level id") @PathVariable("voltageLevelId") String voltageLevelId, @Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId, - @Parameter(description = "Filters : switches, feeder_bays, busbar_sections") @RequestParam(name = "filter") Optional> filter) { - return networkMapService.getVoltageLevelTopology(networkUuid, voltageLevelId, variantId, filter.orElseGet(List::of)); + @Parameter(description = "Filters : switches, feeder_bays, busbar_sections") @RequestParam(name = "filters") List filters) { + return networkMapService.getVoltageLevelTopology(networkUuid, voltageLevelId, variantId, filters); } @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/substation-id", produces = APPLICATION_JSON_VALUE) diff --git a/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java b/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java index 11098064..f1e9b456 100644 --- a/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java +++ b/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java @@ -78,6 +78,7 @@ public class NetworkMapControllerTest { public static final String QUERY_PARAM_LOAD_REGULATING_TERMINALS = "loadRegulatingTerminals"; public static final String QUERY_PARAM_LOAD_NETWORK_COMPONENTS = "loadNetworkComponents"; public static final String QUERY_PARAM_NOMINAL_VOLTAGES = "nominalVoltages"; + public static final String QUERY_PARAM_FILTERS = "filters"; @Autowired private MockMvc mvc; @@ -1421,13 +1422,22 @@ private static String resourceToString(String resource) throws IOException { return new String(ByteStreams.toByteArray(NetworkMapControllerTest.class.getResourceAsStream(resource)), StandardCharsets.UTF_8); } - private void succeedingTestForTopologyInfosWithElementId(UUID networkUuid, String variantId, String voltageLevelId, String expectedJson) throws Exception { - MvcResult res = mvc.perform(get("/v1/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology", networkUuid, voltageLevelId) - .queryParam(QUERY_PARAM_VARIANT_ID, variantId) + private void succeedingTestForTopologyInfosWithElementId(UUID networkUuid, String variantId, String voltageLevelId, List filters, String expectedJson) throws Exception { + LinkedMultiValueMap queryParams = new LinkedMultiValueMap<>(); + queryParams.add(QUERY_PARAM_VARIANT_ID, variantId); + if (filters != null && !filters.isEmpty()) { + List filtersStr = filters.stream() + .map(String::valueOf) + .toList(); + queryParams.addAll(QUERY_PARAM_FILTERS, filtersStr); + } + MvcResult mvcResult = mvc.perform(get("/v1/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology", networkUuid, voltageLevelId) + .queryParams(queryParams) + .content(objectMapper.writeValueAsString(filters)) ) .andExpect(status().isOk()) .andReturn(); - JSONAssert.assertEquals(expectedJson, res.getResponse().getContentAsString(), JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(expectedJson, mvcResult.getResponse().getContentAsString(), JSONCompareMode.NON_EXTENSIBLE); } private void succeedingTestForElementInfosWithElementId(UUID networkUuid, String variantId, ElementType elementType, InfoType infoType, String elementId, String expectedJson) throws Exception { @@ -2327,9 +2337,24 @@ void shouldReturnVoltageLevelFormData() throws Exception { } @Test - void shouldReturnVoltageLevelFormDataWithFeederBaysInfos() throws Exception { - succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN5", resourceToString("/voltage-level-form-data-feederbays.json")); - succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", resourceToString("/topology-info.json")); + void shouldReturnVoltageLevelBusbarSectionsFormInfos() throws Exception { + succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", List.of("busbar_sections"), resourceToString("/busbar-sections-all-data.json")); + } + + @Test + void shouldReturnVoltageLevelFeederBaysFormInfos() throws Exception { + succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", List.of("feeder_bays"), resourceToString("/feeder-bays-data.json")); + } + + @Test + void shouldReturnVoltageLevelSwitchesFormInfos() throws Exception { + succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", List.of("switches"), resourceToString("/switches-data.json")); + succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, VARIANT_ID, "VLGEN4", List.of("switches"), resourceToString("/switches-data-in-variant.json")); + } + + @Test + void shouldReturnVoltageLevelTopologyFormInfos() throws Exception { + succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", List.of("feeder_bays, busbar_sections, switches"), resourceToString("/topology-form-data.json")); } @Test @@ -2370,12 +2395,6 @@ void shouldReturnAnErrorInsteadOfBusbarSectionMapData() throws Exception { failingBusOrBusbarSectionTest("busbar-sections", NETWORK_UUID, "VLGEN4", VARIANT_ID_NOT_FOUND); } - @Test - void shouldReturnSwitchesData() throws Exception { - succeedingEquipmentsTest("switches", NETWORK_UUID, "VLGEN4", null, resourceToString("/switches-data.json")); - succeedingEquipmentsTest("switches", NETWORK_UUID, "VLGEN4", VARIANT_ID, resourceToString("/switches-data-in-variant.json")); - } - @Test void shouldReturnHvdcShuntCompensatorMapData() throws Exception { succeedingHvdcWithShuntCompensatorsTest(NETWORK_UUID, "HVDC1", null, resourceToString("/hvdc-line-with-shunt-compensators-map-data.json")); diff --git a/src/test/resources/busbar-sections-all-data.json b/src/test/resources/busbar-sections-all-data.json new file mode 100644 index 00000000..a1642f92 --- /dev/null +++ b/src/test/resources/busbar-sections-all-data.json @@ -0,0 +1,17 @@ +{ + "busBarSectionsInfos": { + "id": null, + "topologyKind": "NODE_BREAKER", + "switchKinds": [ + "DISCONNECTOR" + ], + "isSymmetrical": true, + "nominalV": 0.0, + "isBusbarSectionPositionFound": true, + "busBarSections": { + "1": [ + "NGEN4" + ] + } + } +} \ No newline at end of file diff --git a/src/test/resources/topology-info.json b/src/test/resources/feeder-bays-data.json similarity index 73% rename from src/test/resources/topology-info.json rename to src/test/resources/feeder-bays-data.json index ec122c51..09cc37bc 100644 --- a/src/test/resources/topology-info.json +++ b/src/test/resources/feeder-bays-data.json @@ -1,17 +1,4 @@ { - "topologyKind": "NODE_BREAKER", - "busbarCount": 1, - "sectionCount": 2, - "switchKinds": [ - "DISCONNECTOR" - ], - "isSymmetrical": true, - "isBusbarSectionPositionExtensionFound": true, - "busBarSectionsInfos": { - "1": [ - "NGEN4" - ] - }, "feederBaysInfos": { "SHUNT_VLNB": [ { diff --git a/src/test/resources/substations-form-data.json b/src/test/resources/substations-form-data.json index 4559fe6a..f6e08a97 100644 --- a/src/test/resources/substations-form-data.json +++ b/src/test/resources/substations-form-data.json @@ -1,4 +1,9 @@ [ + { + "id": "P0", + "country": "FR", + "voltageLevels": [] + }, { "id": "P1", "name": "P1_Name", @@ -9,18 +14,18 @@ "voltageLevels": [ { "id": "VLGEN", - "name": "VLGEN_Name", - "properties": { - "Country": "FR" - }, "topologyKind": "BUS_BREAKER", "substationId": "P1", "nominalV": 24.0, + "name": "VLGEN_Name", "lowVoltageLimit": 200.0, "highVoltageLimit": 400.0, "identifiableShortCircuit": { "ipMin": 10.0, "ipMax": 120.0 + }, + "properties": { + "Country": "FR" } }, { @@ -31,12 +36,12 @@ }, { "id": "VLNEW2", - "properties": { - "Country": "FR" - }, "topologyKind": "BUS_BREAKER", "substationId": "P1", - "nominalV": 225.0 + "nominalV": 225.0, + "properties": { + "Country": "FR" + } } ] }, @@ -57,11 +62,6 @@ } ] }, - { - "id": "P0", - "country": "FR", - "voltageLevels": [] - }, { "id": "P3", "properties": { @@ -97,7 +97,11 @@ "id": "VLGEN4", "topologyKind": "NODE_BREAKER", "substationId": "P4", - "nominalV": 24.0 + "nominalV": 24.0, + "busbarCount": 1, + "sectionCount": 2, + "switchKinds": ["DISCONNECTOR"], + "isSymmetrical": true } ] }, @@ -115,7 +119,11 @@ "identifiableShortCircuit": { "ipMin": 0.0, "ipMax": 100.0 - } + }, + "busbarCount": 1, + "sectionCount": 1, + "switchKinds": [], + "isSymmetrical": false }, { "id": "VLGEN7", @@ -123,7 +131,11 @@ "substationId": "P5", "nominalV": 24.0, "lowVoltageLimit": 20.0, - "highVoltageLimit": 30.0 + "highVoltageLimit": 30.0, + "busbarCount": 1, + "sectionCount": 1, + "switchKinds": [], + "isSymmetrical": false } ] } diff --git a/src/test/resources/switches-data-in-variant.json b/src/test/resources/switches-data-in-variant.json index 1f8363ee..b37bb644 100644 --- a/src/test/resources/switches-data-in-variant.json +++ b/src/test/resources/switches-data-in-variant.json @@ -1,18 +1,20 @@ -[ - { - "id": "VL4_BBS_SHUNT_DISCONNECTOR", - "open": false - }, - { - "id": "VL4_SHUNT_BREAKER", - "open": true - }, - { - "id": "b4", - "open": false - }, - { - "id": "br11", - "open": false - } -] \ No newline at end of file +{ + "switchesInfos": [ + { + "id": "VL4_BBS_SHUNT_DISCONNECTOR", + "open": false + }, + { + "id": "VL4_SHUNT_BREAKER", + "open": true + }, + { + "id": "b4", + "open": false + }, + { + "id": "br11", + "open": false + } + ] +} \ No newline at end of file diff --git a/src/test/resources/switches-data.json b/src/test/resources/switches-data.json index af40ffad..94e337c5 100644 --- a/src/test/resources/switches-data.json +++ b/src/test/resources/switches-data.json @@ -1,18 +1,20 @@ -[ - { - "id": "VL4_BBS_SHUNT_DISCONNECTOR", - "open": false - }, - { - "id": "VL4_SHUNT_BREAKER", - "open": false - }, - { - "id": "b4", - "open": false - }, - { - "id": "br11", - "open": false - } -] \ No newline at end of file +{ + "switchesInfos": [ + { + "id": "VL4_BBS_SHUNT_DISCONNECTOR", + "open": false + }, + { + "id": "VL4_SHUNT_BREAKER", + "open": false + }, + { + "id": "b4", + "open": false + }, + { + "id": "br11", + "open": false + } + ] +} \ No newline at end of file diff --git a/src/test/resources/topology-form-data.json b/src/test/resources/topology-form-data.json new file mode 100644 index 00000000..08def126 --- /dev/null +++ b/src/test/resources/topology-form-data.json @@ -0,0 +1,66 @@ +{ + "busBarSectionsInfos": { + "id": null, + "topologyKind": "NODE_BREAKER", + "switchKinds": [ + "DISCONNECTOR" + ], + "isSymmetrical": true, + "nominalV": 0.0, + "isBusbarSectionPositionFound": true, + "busBarSections": { + "1": [ + "NGEN4" + ] + } + }, + "feederBaysInfos": { + "SHUNT_VLNB": [ + { + "busbarSectionId": "NGEN4", + "connectablePositionInfos": { + "connectionDirection": null + }, + "connectionSide": null + } + ], + "LINE7": [ + { + "busbarSectionId": "NGEN4", + "connectablePositionInfos": { + "connectionDirection": "BOTTOM", + "connectionPosition": 5, + "connectionName": "LINE7_Side_VLGEN4" + }, + "connectionSide": "ONE" + } + ], + "SHUNT_NON_LINEAR": [ + { + "busbarSectionId": "NGEN4", + "connectablePositionInfos": { + "connectionDirection": null + }, + "connectionSide": null + } + ] + }, + "switchesInfos": [ + { + "id": "VL4_BBS_SHUNT_DISCONNECTOR", + "open": false + }, + { + "id": "VL4_SHUNT_BREAKER", + "open": false + }, + { + "id": "b4", + "open": false + }, + { + "id": "br11", + "open": false + } + ] +} \ No newline at end of file diff --git a/src/test/resources/voltage-level-form-data-feederbays.json b/src/test/resources/voltage-level-form-data-feederbays.json deleted file mode 100644 index 92f900f3..00000000 --- a/src/test/resources/voltage-level-form-data-feederbays.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "topologyKind": "NODE_BREAKER", - "busbarCount": 1, - "sectionCount": 1, - "switchKinds": [], - "isSymmetrical": false, - "isBusbarSectionPositionExtensionFound": true, - "busBarSectionsInfos": { - "1": [ - "NGEN5" - ], - "2": [ - "NGEN5_2_1", - "NGEN5_2_2" - ] - }, - "feederBaysInfos": {} -} \ No newline at end of file diff --git a/src/test/resources/voltage-level-form-data.json b/src/test/resources/voltage-level-form-data.json index 42d3d322..94e15227 100644 --- a/src/test/resources/voltage-level-form-data.json +++ b/src/test/resources/voltage-level-form-data.json @@ -1,6 +1,10 @@ { "id": "VLGEN4", - "topologyKind": "NODE_BREAKER", "substationId": "P4", - "nominalV": 24.0 + "nominalV": 24.0, + "topologyKind": "NODE_BREAKER", + "busbarCount": 1, + "sectionCount": 2, + "switchKinds": ["DISCONNECTOR"], + "isSymmetrical": true } \ No newline at end of file diff --git a/src/test/resources/voltage-level-non-symmetrical-busbars-form-data.json b/src/test/resources/voltage-level-non-symmetrical-busbars-form-data.json index fa5a8bee..e37e3f7a 100644 --- a/src/test/resources/voltage-level-non-symmetrical-busbars-form-data.json +++ b/src/test/resources/voltage-level-non-symmetrical-busbars-form-data.json @@ -8,5 +8,9 @@ "identifiableShortCircuit": { "ipMin": 0.0, "ipMax": 100.0 - } + }, + "busbarCount": 1, + "sectionCount": 1, + "switchKinds": [], + "isSymmetrical": false } \ No newline at end of file diff --git a/src/test/resources/voltage-levels-form-data.json b/src/test/resources/voltage-levels-form-data.json index ad6a4979..acb0a9da 100644 --- a/src/test/resources/voltage-levels-form-data.json +++ b/src/test/resources/voltage-levels-form-data.json @@ -1,74 +1,71 @@ [ + { + "id": "VL", + "name":"VL", + "nominalV": 24.0, + "topologyKind": "BUS_BREAKER" + }, { "id": "VLGEN", - "name": "VLGEN_Name", - "properties": { - "Country": "FR" - }, - "topologyKind": "BUS_BREAKER", "substationId": "P1", "nominalV": 24.0, + "topologyKind": "BUS_BREAKER", + "name": "VLGEN_Name", "lowVoltageLimit": 200.0, "highVoltageLimit": 400.0, "identifiableShortCircuit": { "ipMin": 10.0, "ipMax": 120.0 + }, + "properties": { + "Country": "FR" } }, { "id": "VLHV1", - "topologyKind": "BUS_BREAKER", "substationId": "P1", - "nominalV": 380.0 + "nominalV": 380.0, + "topologyKind": "BUS_BREAKER" }, { "id": "VLHV2", - "topologyKind": "BUS_BREAKER", "substationId": "P2", - "nominalV": 380.0 + "nominalV": 380.0, + "topologyKind": "BUS_BREAKER" }, { "id": "VLLOAD", - "topologyKind": "BUS_BREAKER", "substationId": "P2", - "nominalV": 150.0 + "nominalV": 150.0, + "topologyKind": "BUS_BREAKER" }, { "id": "VLNEW2", + "substationId": "P1", + "nominalV": 225.0, + "topologyKind": "BUS_BREAKER", "properties": { "Country": "FR" - }, - "topologyKind": "BUS_BREAKER", - "substationId": "P1", - "nominalV": 225.0 + } }, { "id": "VLGEN3", - "topologyKind": "BUS_BREAKER", "substationId": "P3", - "nominalV": 24.0 - }, - { - "id": "VLGEN6", - "topologyKind": "BUS_BREAKER", - "substationId": "P6", - "nominalV": 24.0 - }, - { - "id": "VL", - "name": "VL", - "topologyKind": "BUS_BREAKER", - "nominalV": 24.0 + "nominalV": 24.0, + "topologyKind": "BUS_BREAKER" }, { "id": "VLGEN4", - "topologyKind": "NODE_BREAKER", "substationId": "P4", - "nominalV": 24.0 + "nominalV": 24.0, + "topologyKind": "NODE_BREAKER", + "busbarCount": 1, + "sectionCount": 2, + "switchKinds": ["DISCONNECTOR"], + "isSymmetrical": true }, { "id": "VLGEN5", - "topologyKind": "NODE_BREAKER", "substationId": "P5", "nominalV": 24.0, "lowVoltageLimit": 20.0, @@ -76,7 +73,18 @@ "identifiableShortCircuit": { "ipMin": 0.0, "ipMax": 100.0 - } + }, + "topologyKind": "NODE_BREAKER", + "busbarCount": 1, + "sectionCount": 1, + "switchKinds": [], + "isSymmetrical": false + }, + { + "id": "VLGEN6", + "topologyKind": "BUS_BREAKER", + "substationId": "P6", + "nominalV": 24.0 }, { "id": "VLGEN7", @@ -84,6 +92,10 @@ "substationId": "P5", "nominalV": 24.0, "lowVoltageLimit": 20.0, - "highVoltageLimit": 30.0 + "highVoltageLimit": 30.0, + "busbarCount": 1, + "sectionCount": 1, + "switchKinds": [], + "isSymmetrical": false } ] \ No newline at end of file From 33c7c24269f60ba49f48f66a29847387630fade3 Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Mon, 20 Oct 2025 23:45:35 +0200 Subject: [PATCH 3/5] clean code --- .../network/map/NetworkMapController.java | 28 ++++++-- .../map/services/NetworkMapService.java | 15 ++--- .../network/map/NetworkMapControllerTest.java | 33 +++------- src/test/resources/topology-form-data.json | 66 ------------------- 4 files changed, 37 insertions(+), 105 deletions(-) delete mode 100644 src/test/resources/topology-form-data.json diff --git a/src/main/java/org/gridsuite/network/map/NetworkMapController.java b/src/main/java/org/gridsuite/network/map/NetworkMapController.java index 2ac9ba94..72cc957b 100644 --- a/src/main/java/org/gridsuite/network/map/NetworkMapController.java +++ b/src/main/java/org/gridsuite/network/map/NetworkMapController.java @@ -26,6 +26,7 @@ import java.util.*; +import static org.gridsuite.network.map.dto.utils.TopologyUtils.TopologyFilterType.*; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; /** @@ -93,14 +94,31 @@ public List getVoltageLevelBusesOrBusBarSections(@Parameter(descri return networkMapService.getVoltageLevelBusesOrBusbarSections(networkUuid, voltageLevelId, variantId); } - @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology", produces = APPLICATION_JSON_VALUE) + @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology-switches", produces = APPLICATION_JSON_VALUE) @Operation(summary = "Get the voltage level topology description") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Network topology information retrieved")}) - public TopologyInfos getVoltageLevelTopology(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid, + public TopologyInfos getVoltageLevelTopologySwitches(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid, @Parameter(description = "Voltage level id") @PathVariable("voltageLevelId") String voltageLevelId, - @Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId, - @Parameter(description = "Filters : switches, feeder_bays, busbar_sections") @RequestParam(name = "filters") List filters) { - return networkMapService.getVoltageLevelTopology(networkUuid, voltageLevelId, variantId, filters); + @Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId) { + return networkMapService.getVoltageLevelTopology(networkUuid, voltageLevelId, variantId, SWITCHES); + } + + @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology-feeder_bays", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Get the voltage level topology description") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Network topology information retrieved")}) + public TopologyInfos getVoltageLevelTopologyFeederBays(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid, + @Parameter(description = "Voltage level id") @PathVariable("voltageLevelId") String voltageLevelId, + @Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId) { + return networkMapService.getVoltageLevelTopology(networkUuid, voltageLevelId, variantId, FEEDER_BAYS); + } + + @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology-busbar_sections", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Get the voltage level topology description") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Network topology information retrieved")}) + public TopologyInfos getVoltageLevelTopologyBusbarSections(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid, + @Parameter(description = "Voltage level id") @PathVariable("voltageLevelId") String voltageLevelId, + @Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId) { + return networkMapService.getVoltageLevelTopology(networkUuid, voltageLevelId, variantId, BUSBAR_SECTIONS); } @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/substation-id", produces = APPLICATION_JSON_VALUE) diff --git a/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java b/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java index 618f7048..026de14f 100644 --- a/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java +++ b/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java @@ -129,19 +129,14 @@ public List getVoltageLevelBusesOrBusbarSections(UUID networkUuid, }; } - public TopologyInfos getVoltageLevelTopology(UUID networkUuid, String voltageLevelId, String variantId, List filter) { - Set filters = TopologyUtils.TopologyFilterType.fromList(filter); + public TopologyInfos getVoltageLevelTopology(UUID networkUuid, String voltageLevelId, String variantId, TopologyUtils.TopologyFilterType filter) { Network network = getNetwork(networkUuid, PreloadingStrategy.NONE, variantId); VoltageLevel voltageLevel = network.getVoltageLevel(voltageLevelId); TopologyInfos topologyInfos = TopologyInfos.builder().build(); - if (filters.contains(TopologyUtils.TopologyFilterType.SWITCHES)) { - topologyInfos.setSwitchesInfos(TopologyUtils.getSwitchesInfos(voltageLevelId, network)); - } - if (filters.contains(TopologyUtils.TopologyFilterType.FEEDER_BAYS)) { - topologyInfos.setFeederBaysInfos(TopologyUtils.getFeederBaysInfos(voltageLevel)); - } - if (filters.contains(TopologyUtils.TopologyFilterType.BUSBAR_SECTIONS)) { - topologyInfos.setBusBarSectionsInfos(TopologyUtils.getBusBarSectionsInfos(voltageLevel)); + switch (filter) { + case SWITCHES -> topologyInfos.setSwitchesInfos(TopologyUtils.getSwitchesInfos(voltageLevelId, network)); + case FEEDER_BAYS -> topologyInfos.setFeederBaysInfos(TopologyUtils.getFeederBaysInfos(voltageLevel)); + case BUSBAR_SECTIONS -> topologyInfos.setBusBarSectionsInfos(TopologyUtils.getBusBarSectionsInfos(voltageLevel)); } return topologyInfos; } diff --git a/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java b/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java index f1e9b456..bed7c973 100644 --- a/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java +++ b/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java @@ -18,8 +18,8 @@ import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl; import org.gridsuite.network.map.dto.ElementInfos.InfoType; import org.gridsuite.network.map.dto.ElementType; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -1422,22 +1422,12 @@ private static String resourceToString(String resource) throws IOException { return new String(ByteStreams.toByteArray(NetworkMapControllerTest.class.getResourceAsStream(resource)), StandardCharsets.UTF_8); } - private void succeedingTestForTopologyInfosWithElementId(UUID networkUuid, String variantId, String voltageLevelId, List filters, String expectedJson) throws Exception { - LinkedMultiValueMap queryParams = new LinkedMultiValueMap<>(); - queryParams.add(QUERY_PARAM_VARIANT_ID, variantId); - if (filters != null && !filters.isEmpty()) { - List filtersStr = filters.stream() - .map(String::valueOf) - .toList(); - queryParams.addAll(QUERY_PARAM_FILTERS, filtersStr); - } - MvcResult mvcResult = mvc.perform(get("/v1/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology", networkUuid, voltageLevelId) - .queryParams(queryParams) - .content(objectMapper.writeValueAsString(filters)) - ) + private void succeedingTestForTopologyInfosWithElementId(UUID networkUuid, String variantId, String voltageLevelId, String filters, String expectedJson) throws Exception { + MvcResult res = mvc.perform(get("/v1/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology-{filters}", networkUuid, voltageLevelId, filters) + .queryParam(QUERY_PARAM_VARIANT_ID, variantId)) .andExpect(status().isOk()) .andReturn(); - JSONAssert.assertEquals(expectedJson, mvcResult.getResponse().getContentAsString(), JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(expectedJson, res.getResponse().getContentAsString(), JSONCompareMode.NON_EXTENSIBLE); } private void succeedingTestForElementInfosWithElementId(UUID networkUuid, String variantId, ElementType elementType, InfoType infoType, String elementId, String expectedJson) throws Exception { @@ -2338,23 +2328,18 @@ void shouldReturnVoltageLevelFormData() throws Exception { @Test void shouldReturnVoltageLevelBusbarSectionsFormInfos() throws Exception { - succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", List.of("busbar_sections"), resourceToString("/busbar-sections-all-data.json")); + succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", "busbar_sections", resourceToString("/busbar-sections-all-data.json")); } @Test void shouldReturnVoltageLevelFeederBaysFormInfos() throws Exception { - succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", List.of("feeder_bays"), resourceToString("/feeder-bays-data.json")); + succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", "feeder_bays", resourceToString("/feeder-bays-data.json")); } @Test void shouldReturnVoltageLevelSwitchesFormInfos() throws Exception { - succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", List.of("switches"), resourceToString("/switches-data.json")); - succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, VARIANT_ID, "VLGEN4", List.of("switches"), resourceToString("/switches-data-in-variant.json")); - } - - @Test - void shouldReturnVoltageLevelTopologyFormInfos() throws Exception { - succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", List.of("feeder_bays, busbar_sections, switches"), resourceToString("/topology-form-data.json")); + succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", "switches", resourceToString("/switches-data.json")); + succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, VARIANT_ID, "VLGEN4", "switches", resourceToString("/switches-data-in-variant.json")); } @Test diff --git a/src/test/resources/topology-form-data.json b/src/test/resources/topology-form-data.json deleted file mode 100644 index 08def126..00000000 --- a/src/test/resources/topology-form-data.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "busBarSectionsInfos": { - "id": null, - "topologyKind": "NODE_BREAKER", - "switchKinds": [ - "DISCONNECTOR" - ], - "isSymmetrical": true, - "nominalV": 0.0, - "isBusbarSectionPositionFound": true, - "busBarSections": { - "1": [ - "NGEN4" - ] - } - }, - "feederBaysInfos": { - "SHUNT_VLNB": [ - { - "busbarSectionId": "NGEN4", - "connectablePositionInfos": { - "connectionDirection": null - }, - "connectionSide": null - } - ], - "LINE7": [ - { - "busbarSectionId": "NGEN4", - "connectablePositionInfos": { - "connectionDirection": "BOTTOM", - "connectionPosition": 5, - "connectionName": "LINE7_Side_VLGEN4" - }, - "connectionSide": "ONE" - } - ], - "SHUNT_NON_LINEAR": [ - { - "busbarSectionId": "NGEN4", - "connectablePositionInfos": { - "connectionDirection": null - }, - "connectionSide": null - } - ] - }, - "switchesInfos": [ - { - "id": "VL4_BBS_SHUNT_DISCONNECTOR", - "open": false - }, - { - "id": "VL4_SHUNT_BREAKER", - "open": false - }, - { - "id": "b4", - "open": false - }, - { - "id": "br11", - "open": false - } - ] -} \ No newline at end of file From d6d9cf59b7746f8e88f2565f85112a7021bfed7e Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Tue, 21 Oct 2025 09:00:32 +0200 Subject: [PATCH 4/5] clean code --- .../gridsuite/network/map/NetworkMapController.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gridsuite/network/map/NetworkMapController.java b/src/main/java/org/gridsuite/network/map/NetworkMapController.java index 72cc957b..1efcb588 100644 --- a/src/main/java/org/gridsuite/network/map/NetworkMapController.java +++ b/src/main/java/org/gridsuite/network/map/NetworkMapController.java @@ -95,8 +95,8 @@ public List getVoltageLevelBusesOrBusBarSections(@Parameter(descri } @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology-switches", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Get the voltage level topology description") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Network topology information retrieved")}) + @Operation(summary = "Get switches voltage level topology description") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Network switches topology information retrieved")}) public TopologyInfos getVoltageLevelTopologySwitches(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid, @Parameter(description = "Voltage level id") @PathVariable("voltageLevelId") String voltageLevelId, @Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId) { @@ -104,8 +104,8 @@ public TopologyInfos getVoltageLevelTopologySwitches(@Parameter(description = "N } @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology-feeder_bays", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Get the voltage level topology description") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Network topology information retrieved")}) + @Operation(summary = "Get feeder bays voltage level topology description") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Network feeder bays topology information retrieved")}) public TopologyInfos getVoltageLevelTopologyFeederBays(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid, @Parameter(description = "Voltage level id") @PathVariable("voltageLevelId") String voltageLevelId, @Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId) { @@ -113,8 +113,8 @@ public TopologyInfos getVoltageLevelTopologyFeederBays(@Parameter(description = } @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology-busbar_sections", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Get the voltage level topology description") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Network topology information retrieved")}) + @Operation(summary = "Get busbar sections voltage level topology description") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Network busbar sections topology information retrieved")}) public TopologyInfos getVoltageLevelTopologyBusbarSections(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid, @Parameter(description = "Voltage level id") @PathVariable("voltageLevelId") String voltageLevelId, @Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId) { From ca828422ca012dcbdfb26a906cfe5b559b5ce0d6 Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Tue, 21 Oct 2025 09:07:23 +0200 Subject: [PATCH 5/5] code review remarks --- .../dto/mapper/VoltageLevelInfosMapper.java | 10 +++++----- .../network/map/dto/utils/TopologyUtils.java | 20 ------------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/gridsuite/network/map/dto/mapper/VoltageLevelInfosMapper.java b/src/main/java/org/gridsuite/network/map/dto/mapper/VoltageLevelInfosMapper.java index 1c688c48..7cd3aff1 100644 --- a/src/main/java/org/gridsuite/network/map/dto/mapper/VoltageLevelInfosMapper.java +++ b/src/main/java/org/gridsuite/network/map/dto/mapper/VoltageLevelInfosMapper.java @@ -54,11 +54,11 @@ static VoltageLevelFormInfos toFormInfos(Identifiable identifiable) { .identifiableShortCircuit(ExtensionUtils.toIdentifiableShortCircuit(voltageLevel)) .build(); if (voltageLevel.getTopologyKind().equals(TopologyKind.NODE_BREAKER)) { - VoltageLevelFormInfos barSectionsInfos = getVoltageLevelBusBarSectionsInfos(voltageLevel); - voltageLevelFormInfos.setBusbarCount(barSectionsInfos.getBusbarCount()); - voltageLevelFormInfos.setSectionCount(barSectionsInfos.getSectionCount()); - voltageLevelFormInfos.setSwitchKinds(barSectionsInfos.getSwitchKinds()); - voltageLevelFormInfos.setIsSymmetrical(barSectionsInfos.getIsSymmetrical()); + VoltageLevelFormInfos busBarSectionsInfos = getVoltageLevelBusBarSectionsInfos(voltageLevel); + voltageLevelFormInfos.setBusbarCount(busBarSectionsInfos.getBusbarCount()); + voltageLevelFormInfos.setSectionCount(busBarSectionsInfos.getSectionCount()); + voltageLevelFormInfos.setSwitchKinds(busBarSectionsInfos.getSwitchKinds()); + voltageLevelFormInfos.setIsSymmetrical(busBarSectionsInfos.getIsSymmetrical()); } return voltageLevelFormInfos; } diff --git a/src/main/java/org/gridsuite/network/map/dto/utils/TopologyUtils.java b/src/main/java/org/gridsuite/network/map/dto/utils/TopologyUtils.java index b63c71c2..b8f6e69b 100644 --- a/src/main/java/org/gridsuite/network/map/dto/utils/TopologyUtils.java +++ b/src/main/java/org/gridsuite/network/map/dto/utils/TopologyUtils.java @@ -38,26 +38,6 @@ public enum TopologyFilterType { TopologyFilterType(String value) { this.value = value; } - - public static Set fromList(List filters) { - Set result = new HashSet<>(); - if (filters == null || filters.isEmpty()) { - return result; - } - for (String filter : filters) { - String trimmedValue = filter.trim(); - if (trimmedValue.isEmpty()) { - continue; - } - for (TopologyFilterType type : TopologyFilterType.values()) { - if (type.value.equalsIgnoreCase(trimmedValue)) { - result.add(type); - break; - } - } - } - return result; - } } private TopologyUtils() { }