From 1245094077747c3d0a4ded2212ac307d082628c2 Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Mon, 6 Oct 2025 15:40:48 +0200 Subject: [PATCH 01/11] refactor topology infos and create new endpoint Signed-off-by: Etienne LESOT --- .../network/map/NetworkMapController.java | 10 ++ .../FeederBayInfos.java | 2 +- .../definition/topology/TopologyInfos.java | 47 ++++++ .../voltagelevel/VoltageLevelFormInfos.java | 24 --- .../dto/mapper/VoltageLevelInfosMapper.java | 133 +---------------- .../network/map/dto/utils/TopologyUtils.java | 117 +++++++++++++++ .../map/services/NetworkMapService.java | 11 ++ .../network/map/NetworkMapControllerTest.java | 16 +- src/test/resources/substations-form-data.json | 109 ++------------ src/test/resources/topology-info.json | 46 ++++++ .../voltage-level-form-data-feederbays.json | 9 -- .../resources/voltage-level-form-data.json | 45 +----- ...vel-non-symmetrical-busbars-form-data.json | 14 +- .../resources/voltage-levels-form-data.json | 141 +++++------------- 14 files changed, 306 insertions(+), 418 deletions(-) rename src/main/java/org/gridsuite/network/map/dto/definition/{voltagelevel => topology}/FeederBayInfos.java (90%) create mode 100644 src/main/java/org/gridsuite/network/map/dto/definition/topology/TopologyInfos.java create mode 100644 src/main/java/org/gridsuite/network/map/dto/utils/TopologyUtils.java create mode 100644 src/test/resources/topology-info.json diff --git a/src/main/java/org/gridsuite/network/map/NetworkMapController.java b/src/main/java/org/gridsuite/network/map/NetworkMapController.java index b85a6d90..7f341b79 100644 --- a/src/main/java/org/gridsuite/network/map/NetworkMapController.java +++ b/src/main/java/org/gridsuite/network/map/NetworkMapController.java @@ -16,6 +16,7 @@ import lombok.AllArgsConstructor; import org.gridsuite.network.map.dto.*; 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; import org.springframework.context.annotation.ComponentScan; import org.springframework.web.bind.annotation.*; @@ -98,6 +99,15 @@ public List getVoltageLevelSwitches(@Parameter(description = "Netwo return networkMapService.getVoltageLevelSwitches(networkUuid, voltageLevelId, variantId); } + @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Get topology description for a voltage level") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "topology description")}) + 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); + } + @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/substation-id", produces = APPLICATION_JSON_VALUE) @Operation(summary = "Get substation ID for a voltage level") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "substation ID for a voltage level")}) diff --git a/src/main/java/org/gridsuite/network/map/dto/definition/voltagelevel/FeederBayInfos.java b/src/main/java/org/gridsuite/network/map/dto/definition/topology/FeederBayInfos.java similarity index 90% rename from src/main/java/org/gridsuite/network/map/dto/definition/voltagelevel/FeederBayInfos.java rename to src/main/java/org/gridsuite/network/map/dto/definition/topology/FeederBayInfos.java index 0a22a6ca..b268c116 100644 --- a/src/main/java/org/gridsuite/network/map/dto/definition/voltagelevel/FeederBayInfos.java +++ b/src/main/java/org/gridsuite/network/map/dto/definition/topology/FeederBayInfos.java @@ -4,7 +4,7 @@ * 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.voltagelevel; +package org.gridsuite.network.map.dto.definition.topology; import com.powsybl.iidm.network.TwoSides; import org.gridsuite.network.map.dto.definition.extension.ConnectablePositionInfos; 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 new file mode 100644 index 00000000..e5be6f07 --- /dev/null +++ b/src/main/java/org/gridsuite/network/map/dto/definition/topology/TopologyInfos.java @@ -0,0 +1,47 @@ +/** + * 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 com.powsybl.iidm.network.SwitchKind; +import com.powsybl.iidm.network.TopologyKind; +import lombok.Getter; +import lombok.experimental.SuperBuilder; + +import java.util.List; +import java.util.Map; + +/** + * @author Etienne Lesot + */ +@SuperBuilder +@Getter +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; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private List switchKinds; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private Boolean isRetrievedBusbarSections; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private Boolean isBusbarSectionPositionFound; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private Map> busBarSectionInfos; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private Map> feederBaysInfos; +} 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 9ede0d8b..2700df97 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,15 +7,12 @@ 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.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.Map; import java.util.Optional; /** @@ -41,25 +38,4 @@ public class VoltageLevelFormInfos extends ElementInfosWithProperties { @JsonInclude(JsonInclude.Include.NON_ABSENT) private Optional identifiableShortCircuit; - - @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 isRetrievedBusbarSections; - - @JsonInclude(JsonInclude.Include.NON_NULL) - private Boolean isBusbarSectionPositionFound; - - @JsonInclude(JsonInclude.Include.NON_NULL) - private Map> busBarSectionInfos; - - @JsonInclude(JsonInclude.Include.NON_NULL) - private Map> feederBaysInfos; } 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 3ef42b09..47e58977 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,25 +6,17 @@ */ package org.gridsuite.network.map.dto.mapper; -import com.powsybl.iidm.network.*; -import com.powsybl.iidm.network.extensions.BusbarSectionPosition; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; +import com.powsybl.iidm.network.Identifiable; +import com.powsybl.iidm.network.Substation; +import com.powsybl.iidm.network.VoltageLevel; import org.gridsuite.network.map.dto.ElementInfos; import org.gridsuite.network.map.dto.InfoTypeParameters; -import org.gridsuite.network.map.dto.definition.busbarsection.BusBarSectionFormInfos; -import org.gridsuite.network.map.dto.definition.voltagelevel.FeederBayInfos; import org.gridsuite.network.map.dto.definition.voltagelevel.VoltageLevelFormInfos; import org.gridsuite.network.map.dto.definition.voltagelevel.VoltageLevelMapInfos; import org.gridsuite.network.map.dto.definition.voltagelevel.VoltageLevelTabInfos; import org.gridsuite.network.map.dto.utils.ElementUtils; import org.gridsuite.network.map.dto.utils.ExtensionUtils; -import java.util.*; -import java.util.stream.Collectors; - -import static com.powsybl.iidm.network.Terminal.getConnectableSide; import static org.gridsuite.network.map.dto.utils.ElementUtils.*; /** @@ -44,53 +36,9 @@ public static ElementInfos toData(Identifiable identifiable, InfoTypeParamete }; } - private static VoltageLevelTopologyInfos getTopologyInfos(VoltageLevel voltageLevel) { - Map nbSectionsPerBusbar = new HashMap<>(); - List busbarSectionInfos = new ArrayList<>(); - 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; - break; - } - int busbarIndex = extension.getBusbarIndex(); - int sectionIndex = extension.getSectionIndex(); - maxBusbarIndex = Math.max(maxBusbarIndex, busbarIndex); - maxSectionIndex = Math.max(maxSectionIndex, sectionIndex); - nbSectionsPerBusbar.merge(busbarIndex, 1, Integer::sum); - busbarSectionInfos.add(BusBarSectionFormInfos.builder() - .id(bbs.getId()) - .vertPos(sectionIndex) - .horizPos(busbarIndex) - .build()); - } - VoltageLevelTopologyInfos voltageLevelTopologyInfos = createDefaultTopologyInfosBuilder().build(); - if (!busbarSectionPositionFound) { - return voltageLevelTopologyInfos; - } - - voltageLevelTopologyInfos.setBusbarSections(busbarSectionInfos); - voltageLevelTopologyInfos.setBusbarSectionPositionFound(true); - - boolean isSymmetrical = maxBusbarIndex == 1 || - nbSectionsPerBusbar.values().stream().distinct().count() == 1 - && nbSectionsPerBusbar.values().stream().findFirst().orElse(0).equals(maxSectionIndex); - - if (isSymmetrical) { - voltageLevelTopologyInfos.setBusbarCount(maxBusbarIndex); - voltageLevelTopologyInfos.setSectionCount(maxSectionIndex); - voltageLevelTopologyInfos.setRetrievedBusbarSections(true); - voltageLevelTopologyInfos.setSwitchKinds(Collections.nCopies(maxSectionIndex - 1, SwitchKind.DISCONNECTOR)); - } - return voltageLevelTopologyInfos; - } - static VoltageLevelFormInfos toFormInfos(Identifiable identifiable) { VoltageLevel voltageLevel = (VoltageLevel) identifiable; - VoltageLevelFormInfos.VoltageLevelFormInfosBuilder builder = VoltageLevelFormInfos.builder() + return VoltageLevelFormInfos.builder() .name(voltageLevel.getOptionalName().orElse(null)) .id(voltageLevel.getId()) .topologyKind(voltageLevel.getTopologyKind()) @@ -98,44 +46,9 @@ static VoltageLevelFormInfos toFormInfos(Identifiable identifiable) { .nominalV(voltageLevel.getNominalV()) .lowVoltageLimit(Double.isNaN(voltageLevel.getLowVoltageLimit()) ? null : voltageLevel.getLowVoltageLimit()) .highVoltageLimit(Double.isNaN(voltageLevel.getHighVoltageLimit()) ? null : voltageLevel.getHighVoltageLimit()) - .properties(getProperties(voltageLevel)); - - if (voltageLevel.getTopologyKind().equals(TopologyKind.NODE_BREAKER)) { - VoltageLevelTopologyInfos vlTopologyInfos = getTopologyInfos(voltageLevel); - builder.busbarCount(vlTopologyInfos.getBusbarCount()); - builder.sectionCount(vlTopologyInfos.getSectionCount()); - builder.switchKinds(vlTopologyInfos.getSwitchKinds()); - builder.isRetrievedBusbarSections(vlTopologyInfos.isRetrievedBusbarSections()); - builder.isBusbarSectionPositionFound(vlTopologyInfos.isBusbarSectionPositionFound()); - builder.busBarSectionInfos(vlTopologyInfos.getBusBarSectionInfosGrouped()); - builder.feederBaysInfos(getFeederBaysInfos(voltageLevel)); - } - - builder.identifiableShortCircuit(ExtensionUtils.toIdentifiableShortCircuit(voltageLevel)); - - return builder.build(); - } - - private static Map> getFeederBaysInfos(VoltageLevel voltageLevel) { - Map> feederBayInfos = new HashMap<>(); - String currentVoltageLevelId = voltageLevel.getId(); - voltageLevel.getConnectableStream() - .filter(connectable -> !(connectable instanceof BusbarSection)) - .forEach(connectable -> { - List connections = new ArrayList<>(); - for (Object obj : connectable.getTerminals()) { - Terminal terminal = (Terminal) obj; - if (terminal.getVoltageLevel().getId().equals(currentVoltageLevelId)) { - connections.add(new FeederBayInfos( - getBusOrBusbarSection(terminal), - getConnectablePosition(connectable, FeederSide.from(getConnectableSide(terminal))), - getConnectableSide(terminal).map(ThreeSides::toTwoSides).orElse(null) - )); - } - } - feederBayInfos.put(connectable.getId(), connections); - }); - return feederBayInfos; + .properties(getProperties(voltageLevel)) + .identifiableShortCircuit(ExtensionUtils.toIdentifiableShortCircuit(voltageLevel)) + .build(); } static VoltageLevelMapInfos toMapInfos(Identifiable identifiable) { @@ -165,36 +78,4 @@ static VoltageLevelTabInfos toTabInfos(Identifiable identifiable) { return builder.build(); } - - private static VoltageLevelTopologyInfos.VoltageLevelTopologyInfosBuilder createDefaultTopologyInfosBuilder() { - return VoltageLevelTopologyInfos.builder() - .busbarCount(1).sectionCount(1).isRetrievedBusbarSections(false) - .switchKinds(List.of()).busbarSections(List.of()).isBusbarSectionPositionFound(false); - } - - @Builder - @Getter - @Setter - public static class VoltageLevelTopologyInfos { - private List busbarSections; - private boolean isRetrievedBusbarSections; // true if busbar sections are symmetrical - private boolean isBusbarSectionPositionFound; - private int busbarCount; - private int sectionCount; - private List switchKinds; - - public Map> getBusBarSectionInfosGrouped() { - return busbarSections.stream() - .collect(Collectors.groupingBy( - section -> String.valueOf(section.getHorizPos()), - Collectors.collectingAndThen( - Collectors.toList(), - list -> list.stream() - .sorted(Comparator.comparing(BusBarSectionFormInfos::getVertPos)) - .map(BusBarSectionFormInfos::getId) - .toList() - ) - )); - } - } } 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 new file mode 100644 index 00000000..556fc45a --- /dev/null +++ b/src/main/java/org/gridsuite/network/map/dto/utils/TopologyUtils.java @@ -0,0 +1,117 @@ +/** + * 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.utils; + +import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.extensions.BusbarSectionPosition; +import org.gridsuite.network.map.dto.definition.busbarsection.BusBarSectionFormInfos; +import org.gridsuite.network.map.dto.definition.topology.FeederBayInfos; +import org.gridsuite.network.map.dto.definition.topology.TopologyInfos; + +import java.util.*; +import java.util.stream.Collectors; + +import static com.powsybl.iidm.network.Terminal.getConnectableSide; +import static org.gridsuite.network.map.dto.utils.ElementUtils.getBusOrBusbarSection; +import static org.gridsuite.network.map.dto.utils.ElementUtils.getConnectablePosition; + +/** + * @author Etienne Lesot + */ +public final class TopologyUtils { + + private TopologyUtils() { + } + + public static TopologyInfos getTopologyInfos(VoltageLevel voltageLevel) { + Map nbSectionsPerBusbar = new HashMap<>(); + List busbarSectionInfos = new ArrayList<>(); + 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; + break; + } + int busbarIndex = extension.getBusbarIndex(); + int sectionIndex = extension.getSectionIndex(); + maxBusbarIndex = Math.max(maxBusbarIndex, busbarIndex); + maxSectionIndex = Math.max(maxSectionIndex, sectionIndex); + nbSectionsPerBusbar.merge(busbarIndex, 1, Integer::sum); + busbarSectionInfos.add(BusBarSectionFormInfos.builder() + .id(bbs.getId()) + .vertPos(sectionIndex) + .horizPos(busbarIndex) + .build()); + } + TopologyInfos.TopologyInfosBuilder voltageLevelTopologyInfos = createDefaultTopologyInfosBuilder(); + if (!busbarSectionPositionFound) { + return voltageLevelTopologyInfos.build(); + } + + voltageLevelTopologyInfos.busBarSectionInfos(busbarSectionInfos.stream() + .collect(Collectors.groupingBy( + section -> String.valueOf(section.getHorizPos()), + Collectors.collectingAndThen( + Collectors.toList(), + list -> list.stream() + .sorted(Comparator.comparing(BusBarSectionFormInfos::getVertPos)) + .map(BusBarSectionFormInfos::getId) + .toList() + ) + ))); + voltageLevelTopologyInfos.isBusbarSectionPositionFound(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.isRetrievedBusbarSections(true); + voltageLevelTopologyInfos.switchKinds(Collections.nCopies(maxSectionIndex - 1, SwitchKind.DISCONNECTOR)); + } + voltageLevelTopologyInfos.feederBaysInfos(getFeederBaysInfos(voltageLevel)); + return voltageLevelTopologyInfos.build(); + } + + public static Map> getFeederBaysInfos(VoltageLevel voltageLevel) { + Map> feederBayInfos = new HashMap<>(); + String currentVoltageLevelId = voltageLevel.getId(); + voltageLevel.getConnectableStream() + .filter(connectable -> !(connectable instanceof BusbarSection)) + .forEach(connectable -> { + List connections = new ArrayList<>(); + for (Object obj : connectable.getTerminals()) { + Terminal terminal = (Terminal) obj; + if (terminal.getVoltageLevel().getId().equals(currentVoltageLevelId)) { + connections.add(new FeederBayInfos( + getBusOrBusbarSection(terminal), + getConnectablePosition(connectable, ElementUtils.FeederSide.from(getConnectableSide(terminal))), + getConnectableSide(terminal).map(ThreeSides::toTwoSides).orElse(null) + )); + } + } + feederBayInfos.put(connectable.getId(), connections); + }); + return feederBayInfos; + } + + private static TopologyInfos.TopologyInfosBuilder createDefaultTopologyInfosBuilder() { + return TopologyInfos.builder() + .busbarCount(1) + .sectionCount(1) + .isRetrievedBusbarSections(false) + .switchKinds(List.of()) + .busBarSectionInfos(Map.of()) + .isBusbarSectionPositionFound(false) + .topologyKind(TopologyKind.NODE_BREAKER); + } +} 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 95a26f6b..9b178805 100644 --- a/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java +++ b/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java @@ -14,8 +14,10 @@ import lombok.AllArgsConstructor; import org.gridsuite.network.map.dto.*; 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; import org.gridsuite.network.map.dto.mapper.HvdcInfosMapper; +import org.gridsuite.network.map.dto.utils.TopologyUtils; import org.springframework.context.annotation.ComponentScan; import org.springframework.http.HttpStatus; import org.springframework.lang.NonNull; @@ -136,6 +138,15 @@ public List getVoltageLevelSwitches(UUID networkUuid, String voltag return switchInfosList; } + public TopologyInfos getVoltageLevelTopology(UUID networkUuid, String voltageLevelId, String variantId) { + Network network = getNetwork(networkUuid, PreloadingStrategy.NONE, variantId); + VoltageLevel voltageLevel = network.getVoltageLevel(voltageLevelId); + if (voltageLevel.getTopologyKind().equals(TopologyKind.NODE_BREAKER)) { + return TopologyUtils.getTopologyInfos(voltageLevel); + } + return TopologyInfos.builder().topologyKind(TopologyKind.BUS_BREAKER).build(); + } + public String getVoltageLevelSubstationID(UUID networkUuid, String voltageLevelId, String variantId) { Network network = getNetwork(networkUuid, PreloadingStrategy.NONE, variantId); return network.getVoltageLevel(voltageLevelId).getSubstation().map(Substation::getId).orElse(null); diff --git a/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java b/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java index 734fdb7a..4ed5a486 100644 --- a/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java +++ b/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java @@ -1417,6 +1417,15 @@ 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) + ) + .andExpect(status().isOk()) + .andReturn(); + 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 { MvcResult res = mvc.perform(get("/v1/networks/{networkUuid}/elements/{elementId}", networkUuid, elementId) .queryParam(QUERY_PARAM_VARIANT_ID, variantId) @@ -1425,7 +1434,6 @@ private void succeedingTestForElementInfosWithElementId(UUID networkUuid, String ) .andExpect(status().isOk()) .andReturn(); - JSONAssert.assertEquals(expectedJson, res.getResponse().getContentAsString(), JSONCompareMode.NON_EXTENSIBLE); } @@ -1494,7 +1502,6 @@ private void succeedingTestForElementsInfos(UUID networkUuid, String variantId, ) .andExpect(status().isOk()) .andReturn(); - JSONAssert.assertEquals(expectedJson, mvcResult.getResponse().getContentAsString(), JSONCompareMode.NON_EXTENSIBLE); } @@ -2318,11 +2325,12 @@ void shouldReturnVoltageLevelFormData() throws Exception { @Test void shouldReturnVoltageLevelFormDataWithFeederBaysInfos() throws Exception { - succeedingTestForElementInfosWithElementId(NETWORK_UUID, null, ElementType.VOLTAGE_LEVEL, InfoType.FORM, "VLGEN5", resourceToString("/voltage-level-form-data-feederbays.json")); + succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN5", resourceToString("/voltage-level-form-data-feederbays.json")); + succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", resourceToString("/topology-info.json")); } @Test - void shouldReturnVotlageLevelNonSymmetricalBusbarsFormData() throws Exception { + void shouldReturnVoltageLevelNonSymmetricalBusbarsFormData() throws Exception { succeedingTestForElementInfosWithElementId(NETWORK_UUID, null, ElementType.VOLTAGE_LEVEL, InfoType.FORM, "VLGEN5", resourceToString("/voltage-level-non-symmetrical-busbars-form-data.json")); succeedingTestForElementInfosWithElementId(NETWORK_UUID, VARIANT_ID, ElementType.VOLTAGE_LEVEL, InfoType.FORM, "VLGEN5", resourceToString("/voltage-level-non-symmetrical-busbars-form-data.json")); } diff --git a/src/test/resources/substations-form-data.json b/src/test/resources/substations-form-data.json index 8aae64fe..4559fe6a 100644 --- a/src/test/resources/substations-form-data.json +++ b/src/test/resources/substations-form-data.json @@ -1,9 +1,4 @@ [ - { - "id": "P0", - "country": "FR", - "voltageLevels": [] - }, { "id": "P1", "name": "P1_Name", @@ -14,18 +9,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" } }, { @@ -36,12 +31,12 @@ }, { "id": "VLNEW2", - "topologyKind": "BUS_BREAKER", - "substationId": "P1", - "nominalV": 225.0, "properties": { "Country": "FR" - } + }, + "topologyKind": "BUS_BREAKER", + "substationId": "P1", + "nominalV": 225.0 } ] }, @@ -62,6 +57,11 @@ } ] }, + { + "id": "P0", + "country": "FR", + "voltageLevels": [] + }, { "id": "P3", "properties": { @@ -97,46 +97,7 @@ "id": "VLGEN4", "topologyKind": "NODE_BREAKER", "substationId": "P4", - "nominalV": 24.0, - "busbarCount": 1, - "sectionCount": 2, - "switchKinds": ["DISCONNECTOR"], - "isRetrievedBusbarSections": true, - "isBusbarSectionPositionFound": true, - "busBarSectionInfos" : { - "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": null, - "connectablePositionInfos": { - "connectionDirection": null - }, - "connectionSide": null - } - ] - } + "nominalV": 24.0 } ] }, @@ -154,26 +115,7 @@ "identifiableShortCircuit": { "ipMin": 0.0, "ipMax": 100.0 - }, - "busbarCount": 1, - "sectionCount": 1, - "switchKinds": [], - "isRetrievedBusbarSections": false, - "isBusbarSectionPositionFound": true, - "busBarSectionInfos" : { - "1" : [ "NGEN5"], - "2" : [ "NGEN5_2_1", "NGEN5_2_2"] - }, - "busBarSectionInfos": { - "1": [ - "NGEN5" - ], - "2": [ - "NGEN5_2_1", - "NGEN5_2_2" - ] - }, - "feederBaysInfos": {} + } }, { "id": "VLGEN7", @@ -181,26 +123,7 @@ "substationId": "P5", "nominalV": 24.0, "lowVoltageLimit": 20.0, - "highVoltageLimit": 30.0, - "busbarCount": 1, - "sectionCount": 1, - "switchKinds": [], - "isRetrievedBusbarSections": false, - "isBusbarSectionPositionFound": false, - "busBarSectionInfos": {}, - "feederBaysInfos": { - "LINE7": [ - { - "busbarSectionId": "NGEN7", - "connectablePositionInfos": { - "connectionDirection": "TOP", - "connectionPosition": 3, - "connectionName": "LINE7_Side_VLGEN8" - }, - "connectionSide": "TWO" - } - ] - } + "highVoltageLimit": 30.0 } ] } diff --git a/src/test/resources/topology-info.json b/src/test/resources/topology-info.json new file mode 100644 index 00000000..29070e50 --- /dev/null +++ b/src/test/resources/topology-info.json @@ -0,0 +1,46 @@ +{ + "topologyKind": "NODE_BREAKER", + "busbarCount": 1, + "sectionCount": 2, + "switchKinds": [ + "DISCONNECTOR" + ], + "isRetrievedBusbarSections": true, + "isBusbarSectionPositionFound": true, + "busBarSectionInfos": { + "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": null, + "connectablePositionInfos": { + "connectionDirection": null + }, + "connectionSide": null + } + ] + } +} \ 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 index 5c2833b7..979d27ff 100644 --- a/src/test/resources/voltage-level-form-data-feederbays.json +++ b/src/test/resources/voltage-level-form-data-feederbays.json @@ -1,14 +1,5 @@ { - "id": "VLGEN5", "topologyKind": "NODE_BREAKER", - "substationId": "P5", - "nominalV": 24.0, - "lowVoltageLimit": 20.0, - "highVoltageLimit": 30.0, - "identifiableShortCircuit": { - "ipMin": 0.0, - "ipMax": 100.0 - }, "busbarCount": 1, "sectionCount": 1, "switchKinds": [], diff --git a/src/test/resources/voltage-level-form-data.json b/src/test/resources/voltage-level-form-data.json index 6f4837ff..42d3d322 100644 --- a/src/test/resources/voltage-level-form-data.json +++ b/src/test/resources/voltage-level-form-data.json @@ -1,45 +1,6 @@ { "id": "VLGEN4", - "substationId": "P4", - "nominalV": 24.0, "topologyKind": "NODE_BREAKER", - "busbarCount": 1, - "sectionCount": 2, - "switchKinds": ["DISCONNECTOR"], - "isRetrievedBusbarSections": true, - "isBusbarSectionPositionFound": true, - "busBarSectionInfos" : { - "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": null, - "connectablePositionInfos": { - "connectionDirection": null - }, - "connectionSide": null - } - ] - } -} + "substationId": "P4", + "nominalV": 24.0 +} \ 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 655749e4..fa5a8bee 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,15 +8,5 @@ "identifiableShortCircuit": { "ipMin": 0.0, "ipMax": 100.0 - }, - "busbarCount": 1, - "sectionCount": 1, - "switchKinds": [], - "isRetrievedBusbarSections": false, - "isBusbarSectionPositionFound": true, - "busBarSectionInfos" : { - "1" : [ "NGEN5"], - "2" : [ "NGEN5_2_1","NGEN5_2_2"] - }, - "feederBaysInfos": {} -} + } +} \ 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 c65df911..ad6a4979 100644 --- a/src/test/resources/voltage-levels-form-data.json +++ b/src/test/resources/voltage-levels-form-data.json @@ -1,111 +1,74 @@ [ - { - "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, - "topologyKind": "BUS_BREAKER" + "nominalV": 380.0 }, { "id": "VLHV2", + "topologyKind": "BUS_BREAKER", "substationId": "P2", - "nominalV": 380.0, - "topologyKind": "BUS_BREAKER" + "nominalV": 380.0 }, { "id": "VLLOAD", + "topologyKind": "BUS_BREAKER", "substationId": "P2", - "nominalV": 150.0, - "topologyKind": "BUS_BREAKER" + "nominalV": 150.0 }, { "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, - "topologyKind": "BUS_BREAKER" + "nominalV": 24.0 + }, + { + "id": "VLGEN6", + "topologyKind": "BUS_BREAKER", + "substationId": "P6", + "nominalV": 24.0 + }, + { + "id": "VL", + "name": "VL", + "topologyKind": "BUS_BREAKER", + "nominalV": 24.0 }, { "id": "VLGEN4", - "substationId": "P4", - "nominalV": 24.0, "topologyKind": "NODE_BREAKER", - "busbarCount": 1, - "sectionCount": 2, - "switchKinds": ["DISCONNECTOR"], - "isRetrievedBusbarSections": true, - "isBusbarSectionPositionFound": true, - "busBarSectionInfos" : { - "1" : [ "NGEN4" ] - }, - "busBarSectionInfos": { - "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": null, - "connectablePositionInfos": { - "connectionDirection": null - }, - "connectionSide": null - } - ] - } + "substationId": "P4", + "nominalV": 24.0 }, { "id": "VLGEN5", + "topologyKind": "NODE_BREAKER", "substationId": "P5", "nominalV": 24.0, "lowVoltageLimit": 20.0, @@ -113,24 +76,7 @@ "identifiableShortCircuit": { "ipMin": 0.0, "ipMax": 100.0 - }, - "topologyKind": "NODE_BREAKER", - "busbarCount": 1, - "sectionCount": 1, - "switchKinds": [], - "isRetrievedBusbarSections": false, - "isBusbarSectionPositionFound": true, - "busBarSectionInfos" : { - "1" : [ "NGEN5"], - "2" : [ "NGEN5_2_1", "NGEN5_2_2" ] - }, - "feederBaysInfos": {} - }, - { - "id": "VLGEN6", - "topologyKind": "BUS_BREAKER", - "substationId": "P6", - "nominalV": 24.0 + } }, { "id": "VLGEN7", @@ -138,25 +84,6 @@ "substationId": "P5", "nominalV": 24.0, "lowVoltageLimit": 20.0, - "highVoltageLimit": 30.0, - "busbarCount": 1, - "sectionCount": 1, - "switchKinds": [], - "isRetrievedBusbarSections": false, - "isBusbarSectionPositionFound": false, - "busBarSectionInfos": {}, - "feederBaysInfos": { - "LINE7": [ - { - "busbarSectionId": "NGEN7", - "connectablePositionInfos": { - "connectionDirection": "TOP", - "connectionPosition": 3, - "connectionName": "LINE7_Side_VLGEN8" - }, - "connectionSide": "TWO" - } - ] - } + "highVoltageLimit": 30.0 } ] \ No newline at end of file From fb3beed95512d6aa0c84136305863f65a5e36aa4 Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Tue, 14 Oct 2025 14:48:37 +0200 Subject: [PATCH 02/11] fix Signed-off-by: Etienne LESOT --- src/test/resources/topology-info.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/topology-info.json b/src/test/resources/topology-info.json index 29070e50..d406c99a 100644 --- a/src/test/resources/topology-info.json +++ b/src/test/resources/topology-info.json @@ -35,7 +35,7 @@ ], "SHUNT_NON_LINEAR": [ { - "busbarSectionId": null, + "busbarSectionId": "NGEN4", "connectablePositionInfos": { "connectionDirection": null }, From c62e9e27856d5e4ec6dc3cb8afe1724b728589c4 Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Tue, 14 Oct 2025 15:01:23 +0200 Subject: [PATCH 03/11] review Signed-off-by: Etienne LESOT --- .../gridsuite/network/map/NetworkMapController.java | 4 ++-- .../map/dto/definition/topology/TopologyInfos.java | 6 +++--- .../network/map/dto/utils/TopologyUtils.java | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/gridsuite/network/map/NetworkMapController.java b/src/main/java/org/gridsuite/network/map/NetworkMapController.java index 7f341b79..58655760 100644 --- a/src/main/java/org/gridsuite/network/map/NetworkMapController.java +++ b/src/main/java/org/gridsuite/network/map/NetworkMapController.java @@ -100,8 +100,8 @@ public List getVoltageLevelSwitches(@Parameter(description = "Netwo } @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Get topology description for a voltage level") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "topology description")}) + @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) { 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 e5be6f07..23012d59 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 @@ -34,13 +34,13 @@ public class TopologyInfos { private List switchKinds; @JsonInclude(JsonInclude.Include.NON_NULL) - private Boolean isRetrievedBusbarSections; + private Boolean isSymmetrical; @JsonInclude(JsonInclude.Include.NON_NULL) - private Boolean isBusbarSectionPositionFound; + private Boolean isBusbarSectionPositionExtensionFound; @JsonInclude(JsonInclude.Include.NON_NULL) - private Map> busBarSectionInfos; + private Map> busBarSectionsInfos; @JsonInclude(JsonInclude.Include.NON_NULL) private Map> feederBaysInfos; 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 556fc45a..14edead4 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 @@ -55,7 +55,7 @@ public static TopologyInfos getTopologyInfos(VoltageLevel voltageLevel) { return voltageLevelTopologyInfos.build(); } - voltageLevelTopologyInfos.busBarSectionInfos(busbarSectionInfos.stream() + voltageLevelTopologyInfos.busBarSectionsInfos(busbarSectionInfos.stream() .collect(Collectors.groupingBy( section -> String.valueOf(section.getHorizPos()), Collectors.collectingAndThen( @@ -66,7 +66,7 @@ public static TopologyInfos getTopologyInfos(VoltageLevel voltageLevel) { .toList() ) ))); - voltageLevelTopologyInfos.isBusbarSectionPositionFound(true); + voltageLevelTopologyInfos.isBusbarSectionPositionExtensionFound(true); boolean isSymmetrical = maxBusbarIndex == 1 || nbSectionsPerBusbar.values().stream().distinct().count() == 1 @@ -75,7 +75,7 @@ public static TopologyInfos getTopologyInfos(VoltageLevel voltageLevel) { if (isSymmetrical) { voltageLevelTopologyInfos.busbarCount(maxBusbarIndex); voltageLevelTopologyInfos.sectionCount(maxSectionIndex); - voltageLevelTopologyInfos.isRetrievedBusbarSections(true); + voltageLevelTopologyInfos.isSymmetrical(true); voltageLevelTopologyInfos.switchKinds(Collections.nCopies(maxSectionIndex - 1, SwitchKind.DISCONNECTOR)); } voltageLevelTopologyInfos.feederBaysInfos(getFeederBaysInfos(voltageLevel)); @@ -108,10 +108,10 @@ public static Map> getFeederBaysInfos(VoltageLevel return TopologyInfos.builder() .busbarCount(1) .sectionCount(1) - .isRetrievedBusbarSections(false) + .isSymmetrical(false) .switchKinds(List.of()) - .busBarSectionInfos(Map.of()) - .isBusbarSectionPositionFound(false) + .busBarSectionsInfos(Map.of()) + .isBusbarSectionPositionExtensionFound(false) .topologyKind(TopologyKind.NODE_BREAKER); } } From a55c930e807063847bba380f2606a02b4f691fad Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Tue, 14 Oct 2025 15:09:51 +0200 Subject: [PATCH 04/11] fix Signed-off-by: Etienne LESOT --- src/test/resources/topology-info.json | 6 +++--- src/test/resources/voltage-level-form-data-feederbays.json | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/resources/topology-info.json b/src/test/resources/topology-info.json index d406c99a..ec122c51 100644 --- a/src/test/resources/topology-info.json +++ b/src/test/resources/topology-info.json @@ -5,9 +5,9 @@ "switchKinds": [ "DISCONNECTOR" ], - "isRetrievedBusbarSections": true, - "isBusbarSectionPositionFound": true, - "busBarSectionInfos": { + "isSymmetrical": true, + "isBusbarSectionPositionExtensionFound": true, + "busBarSectionsInfos": { "1": [ "NGEN4" ] diff --git a/src/test/resources/voltage-level-form-data-feederbays.json b/src/test/resources/voltage-level-form-data-feederbays.json index 979d27ff..92f900f3 100644 --- a/src/test/resources/voltage-level-form-data-feederbays.json +++ b/src/test/resources/voltage-level-form-data-feederbays.json @@ -3,9 +3,9 @@ "busbarCount": 1, "sectionCount": 1, "switchKinds": [], - "isRetrievedBusbarSections": false, - "isBusbarSectionPositionFound": true, - "busBarSectionInfos": { + "isSymmetrical": false, + "isBusbarSectionPositionExtensionFound": true, + "busBarSectionsInfos": { "1": [ "NGEN5" ], From d8a599f745ea0ecdee0f1bc0a221aec12b58b9dc Mon Sep 17 00:00:00 2001 From: Ghazoua Rhili Date: Wed, 29 Oct 2025 09:29:22 +0100 Subject: [PATCH 05/11] GRH suggestion voltage level refacto (#303) voltage level form refacto --- .../network/map/NetworkMapController.java | 39 ++++++--- .../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 | 62 ++++++++------ .../map/services/NetworkMapService.java | 28 +++---- .../network/map/NetworkMapControllerTest.java | 32 ++++---- .../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 ++++----- .../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 +++++++++++-------- 18 files changed, 347 insertions(+), 214 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%) create mode 100644 src/test/resources/busbar-sections-all-data.json rename src/test/resources/{topology-info.json => feeder-bays-data.json} (73%) 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 58655760..1efcb588 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; @@ -23,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; /** @@ -90,22 +94,31 @@ 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-switches", produces = APPLICATION_JSON_VALUE) + @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) { + return networkMapService.getVoltageLevelTopology(networkUuid, voltageLevelId, variantId, SWITCHES); + } + + @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology-feeder_bays", produces = APPLICATION_JSON_VALUE) + @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) { + return networkMapService.getVoltageLevelTopology(networkUuid, voltageLevelId, variantId, FEEDER_BAYS); } - @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, + @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology-busbar_sections", produces = APPLICATION_JSON_VALUE) + @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) { - return networkMapService.getVoltageLevelTopology(networkUuid, voltageLevelId, 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/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..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 @@ -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 busBarSectionsInfos = getVoltageLevelBusBarSectionsInfos(voltageLevel); + voltageLevelFormInfos.setBusbarCount(busBarSectionsInfos.getBusbarCount()); + voltageLevelFormInfos.setSectionCount(busBarSectionsInfos.getSectionCount()); + voltageLevelFormInfos.setSwitchKinds(busBarSectionsInfos.getSwitchKinds()); + voltageLevelFormInfos.setIsSymmetrical(busBarSectionsInfos.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..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 @@ -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,35 @@ */ 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 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 +68,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 +80,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 +115,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..026de14f 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,16 @@ 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, TopologyUtils.TopologyFilterType 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(); + 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.builder().topologyKind(TopologyKind.BUS_BREAKER).build(); + return topologyInfos; } public String getVoltageLevelSubstationID(UUID networkUuid, String voltageLevelId, String variantId) { diff --git a/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java b/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java index 11098064..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; @@ -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,10 +1422,9 @@ 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, 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, res.getResponse().getContentAsString(), JSONCompareMode.NON_EXTENSIBLE); @@ -2327,9 +2327,19 @@ 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", "busbar_sections", resourceToString("/busbar-sections-all-data.json")); + } + + @Test + void shouldReturnVoltageLevelFeederBaysFormInfos() throws Exception { + succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", "feeder_bays", resourceToString("/feeder-bays-data.json")); + } + + @Test + void shouldReturnVoltageLevelSwitchesFormInfos() throws Exception { + succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", "switches", resourceToString("/switches-data.json")); + succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, VARIANT_ID, "VLGEN4", "switches", resourceToString("/switches-data-in-variant.json")); } @Test @@ -2370,12 +2380,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/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 c6763f8b5cff97faa10304fcdd8d130b3aa03225 Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Wed, 29 Oct 2025 09:51:23 +0100 Subject: [PATCH 06/11] code review remarks --- .../definition/topology/BusBarSectionsInfos.java | 14 ++++++++++++-- src/test/resources/busbar-sections-all-data.json | 2 -- 2 files changed, 12 insertions(+), 4 deletions(-) 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 index 85ebae56..755a8724 100644 --- 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 @@ -7,10 +7,11 @@ 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 org.gridsuite.network.map.dto.definition.voltagelevel.VoltageLevelFormInfos; import java.util.List; import java.util.Map; @@ -21,7 +22,16 @@ @SuperBuilder @Getter @Setter -public class BusBarSectionsInfos extends VoltageLevelFormInfos { +public class BusBarSectionsInfos { + + @JsonInclude(JsonInclude.Include.NON_NULL) + private TopologyKind topologyKind; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private List switchKinds; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private Boolean isSymmetrical; @JsonInclude(JsonInclude.Include.NON_NULL) Boolean isBusbarSectionPositionFound; diff --git a/src/test/resources/busbar-sections-all-data.json b/src/test/resources/busbar-sections-all-data.json index a1642f92..7d1a16b3 100644 --- a/src/test/resources/busbar-sections-all-data.json +++ b/src/test/resources/busbar-sections-all-data.json @@ -1,12 +1,10 @@ { "busBarSectionsInfos": { - "id": null, "topologyKind": "NODE_BREAKER", "switchKinds": [ "DISCONNECTOR" ], "isSymmetrical": true, - "nominalV": 0.0, "isBusbarSectionPositionFound": true, "busBarSections": { "1": [ From 3de5ce58a989285f2c227b485636f07c3e8201c7 Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Wed, 29 Oct 2025 13:25:27 +0100 Subject: [PATCH 07/11] refactor Signed-off-by: Etienne LESOT --- .../network/map/NetworkMapController.java | 45 ++++++++++--------- .../CreateVoltageLevelSectionInfos.java | 23 ++++++++++ ...a => MoveVoltageLevelFeederBaysInfos.java} | 8 +--- ...VoltageLevelTopologyModificationInfos.java | 25 +++++++++++ .../network/map/dto/utils/TopologyUtils.java | 15 ------- .../map/services/NetworkMapService.java | 33 ++++++++++---- .../network/map/NetworkMapControllerTest.java | 29 +++++++++--- src/test/resources/feeder-bays-data.json | 13 ++++++ 8 files changed, 133 insertions(+), 58 deletions(-) create mode 100644 src/main/java/org/gridsuite/network/map/dto/definition/topology/CreateVoltageLevelSectionInfos.java rename src/main/java/org/gridsuite/network/map/dto/definition/topology/{TopologyInfos.java => MoveVoltageLevelFeederBaysInfos.java} (86%) create mode 100644 src/main/java/org/gridsuite/network/map/dto/definition/topology/VoltageLevelTopologyModificationInfos.java diff --git a/src/main/java/org/gridsuite/network/map/NetworkMapController.java b/src/main/java/org/gridsuite/network/map/NetworkMapController.java index 1efcb588..67554bd7 100644 --- a/src/main/java/org/gridsuite/network/map/NetworkMapController.java +++ b/src/main/java/org/gridsuite/network/map/NetworkMapController.java @@ -19,14 +19,15 @@ 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.definition.topology.CreateVoltageLevelSectionInfos; +import org.gridsuite.network.map.dto.definition.topology.MoveVoltageLevelFeederBaysInfos; +import org.gridsuite.network.map.dto.definition.topology.VoltageLevelTopologyModificationInfos; import org.gridsuite.network.map.services.NetworkMapService; import org.springframework.context.annotation.ComponentScan; import org.springframework.web.bind.annotation.*; import java.util.*; -import static org.gridsuite.network.map.dto.utils.TopologyUtils.TopologyFilterType.*; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; /** @@ -94,31 +95,31 @@ public List getVoltageLevelBusesOrBusBarSections(@Parameter(descri return networkMapService.getVoltageLevelBusesOrBusbarSections(networkUuid, voltageLevelId, variantId); } - @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology-switches", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Get switches voltage level topology description") + @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/move-feeder-bays", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "") @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) { - return networkMapService.getVoltageLevelTopology(networkUuid, voltageLevelId, variantId, SWITCHES); + public MoveVoltageLevelFeederBaysInfos getMoveVoltageLevelFeederBaysInfos(@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.getMoveVoltageLevelFeederBaysInfos(networkUuid, voltageLevelId, variantId); } - @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology-feeder_bays", produces = APPLICATION_JSON_VALUE) - @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) { - return networkMapService.getVoltageLevelTopology(networkUuid, voltageLevelId, variantId, FEEDER_BAYS); + @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/create-voltage-level-section", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "")}) + public CreateVoltageLevelSectionInfos getCreateVoltageLevelSectionInfos(@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.getCreateVoltageLevelSectionInfos(networkUuid, voltageLevelId, variantId); } - @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology-busbar_sections", produces = APPLICATION_JSON_VALUE) - @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) { - return networkMapService.getVoltageLevelTopology(networkUuid, voltageLevelId, variantId, BUSBAR_SECTIONS); + @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/voltage-level-topology-modification", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "")}) + public VoltageLevelTopologyModificationInfos getVoltageLevelTopologyModificationInfos(@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.getVoltageLevelTopologyModificationInfos(networkUuid, voltageLevelId, variantId); } @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/CreateVoltageLevelSectionInfos.java b/src/main/java/org/gridsuite/network/map/dto/definition/topology/CreateVoltageLevelSectionInfos.java new file mode 100644 index 00000000..1e712c42 --- /dev/null +++ b/src/main/java/org/gridsuite/network/map/dto/definition/topology/CreateVoltageLevelSectionInfos.java @@ -0,0 +1,23 @@ +/** + * 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; + +/** + * @author Etienne Lesot + */ +@SuperBuilder +@Getter +@Setter +public class CreateVoltageLevelSectionInfos { + @JsonInclude(JsonInclude.Include.NON_NULL) + private BusBarSectionsInfos busBarSectionsInfos; +} 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/MoveVoltageLevelFeederBaysInfos.java similarity index 86% rename from src/main/java/org/gridsuite/network/map/dto/definition/topology/TopologyInfos.java rename to src/main/java/org/gridsuite/network/map/dto/definition/topology/MoveVoltageLevelFeederBaysInfos.java index 866ca532..aa45a01c 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/MoveVoltageLevelFeederBaysInfos.java @@ -20,14 +20,10 @@ @SuperBuilder @Getter @Setter -public class TopologyInfos { - - @JsonInclude(JsonInclude.Include.NON_NULL) - private BusBarSectionsInfos busBarSectionsInfos; +public class MoveVoltageLevelFeederBaysInfos { @JsonInclude(JsonInclude.Include.NON_NULL) private Map> feederBaysInfos; - @JsonInclude(JsonInclude.Include.NON_NULL) - private List switchesInfos; + private BusBarSectionsInfos busBarSectionsInfos; } diff --git a/src/main/java/org/gridsuite/network/map/dto/definition/topology/VoltageLevelTopologyModificationInfos.java b/src/main/java/org/gridsuite/network/map/dto/definition/topology/VoltageLevelTopologyModificationInfos.java new file mode 100644 index 00000000..1e2d5c53 --- /dev/null +++ b/src/main/java/org/gridsuite/network/map/dto/definition/topology/VoltageLevelTopologyModificationInfos.java @@ -0,0 +1,25 @@ +/** + * 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 java.util.List; + +/** + * @author Etienne Lesot + */ +@SuperBuilder +@Getter +@Setter +public class VoltageLevelTopologyModificationInfos { + @JsonInclude(JsonInclude.Include.NON_NULL) + private List switchesInfos; +} 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 b8f6e69b..0419d7dd 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,7 +8,6 @@ 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; @@ -26,20 +25,6 @@ */ public final class 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; - } - } - private TopologyUtils() { } public static BusBarSectionsInfos getBusBarSectionsInfos(VoltageLevel voltageLevel) { 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 026de14f..7fd28a77 100644 --- a/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java +++ b/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java @@ -17,7 +17,9 @@ 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.definition.topology.CreateVoltageLevelSectionInfos; +import org.gridsuite.network.map.dto.definition.topology.MoveVoltageLevelFeederBaysInfos; +import org.gridsuite.network.map.dto.definition.topology.VoltageLevelTopologyModificationInfos; import org.gridsuite.network.map.dto.mapper.ElementInfosMapper; import org.gridsuite.network.map.dto.mapper.HvdcInfosMapper; import org.gridsuite.network.map.dto.utils.TopologyUtils; @@ -129,16 +131,29 @@ public List getVoltageLevelBusesOrBusbarSections(UUID networkUuid, }; } - public TopologyInfos getVoltageLevelTopology(UUID networkUuid, String voltageLevelId, String variantId, TopologyUtils.TopologyFilterType filter) { + public CreateVoltageLevelSectionInfos getCreateVoltageLevelSectionInfos(UUID networkUuid, String voltageLevelId, String variantId) { Network network = getNetwork(networkUuid, PreloadingStrategy.NONE, variantId); VoltageLevel voltageLevel = network.getVoltageLevel(voltageLevelId); - TopologyInfos topologyInfos = TopologyInfos.builder().build(); - 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; + CreateVoltageLevelSectionInfos.CreateVoltageLevelSectionInfosBuilder builder = CreateVoltageLevelSectionInfos.builder(); + builder.busBarSectionsInfos(TopologyUtils.getBusBarSectionsInfos(voltageLevel)); + return builder.build(); + } + + public MoveVoltageLevelFeederBaysInfos getMoveVoltageLevelFeederBaysInfos(UUID networkUuid, String voltageLevelId, String variantId) { + Network network = getNetwork(networkUuid, PreloadingStrategy.NONE, variantId); + VoltageLevel voltageLevel = network.getVoltageLevel(voltageLevelId); + MoveVoltageLevelFeederBaysInfos.MoveVoltageLevelFeederBaysInfosBuilder builder = MoveVoltageLevelFeederBaysInfos.builder(); + builder.feederBaysInfos(TopologyUtils.getFeederBaysInfos(voltageLevel)); + builder.busBarSectionsInfos(TopologyUtils.getBusBarSectionsInfos(voltageLevel)); + return builder.build(); + } + + public VoltageLevelTopologyModificationInfos getVoltageLevelTopologyModificationInfos(UUID networkUuid, String voltageLevelId, String variantId) { + Network network = getNetwork(networkUuid, PreloadingStrategy.NONE, variantId); + VoltageLevel voltageLevel = network.getVoltageLevel(voltageLevelId); + VoltageLevelTopologyModificationInfos.VoltageLevelTopologyModificationInfosBuilder builder = VoltageLevelTopologyModificationInfos.builder(); + builder.switchesInfos(TopologyUtils.getSwitchesInfos(voltageLevel.getId(), network)); + return builder.build(); } public String getVoltageLevelSubstationID(UUID networkUuid, String voltageLevelId, String variantId) { diff --git a/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java b/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java index bed7c973..bab115a5 100644 --- a/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java +++ b/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java @@ -1422,8 +1422,25 @@ 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 filters, String expectedJson) throws Exception { - MvcResult res = mvc.perform(get("/v1/networks/{networkUuid}/voltage-levels/{voltageLevelId}/topology-{filters}", networkUuid, voltageLevelId, filters) + private void succeedingTestGettingMoveFeederBaysInfos(UUID networkUuid, String variantId, String voltageLevelId, String expectedJson) throws Exception { + MvcResult res = mvc.perform(get("/v1/networks/{networkUuid}/voltage-levels/{voltageLevelId}/move-feeder-bays", networkUuid, voltageLevelId) + .queryParam(QUERY_PARAM_VARIANT_ID, variantId)) + .andExpect(status().isOk()) + .andReturn(); + System.out.println(res.getResponse().getContentAsString()); + JSONAssert.assertEquals(expectedJson, res.getResponse().getContentAsString(), JSONCompareMode.NON_EXTENSIBLE); + } + + private void succeedingTestGettingCreateVoltageLevelSectionInfos(UUID networkUuid, String variantId, String voltageLevelId, String expectedJson) throws Exception { + MvcResult res = mvc.perform(get("/v1/networks/{networkUuid}/voltage-levels/{voltageLevelId}/create-voltage-level-section", networkUuid, voltageLevelId) + .queryParam(QUERY_PARAM_VARIANT_ID, variantId)) + .andExpect(status().isOk()) + .andReturn(); + JSONAssert.assertEquals(expectedJson, res.getResponse().getContentAsString(), JSONCompareMode.NON_EXTENSIBLE); + } + + private void succeedingTestGettingVoltageLevelTopologyModificationInfos(UUID networkUuid, String variantId, String voltageLevelId, String expectedJson) throws Exception { + MvcResult res = mvc.perform(get("/v1/networks/{networkUuid}/voltage-levels/{voltageLevelId}/voltage-level-topology-modification", networkUuid, voltageLevelId) .queryParam(QUERY_PARAM_VARIANT_ID, variantId)) .andExpect(status().isOk()) .andReturn(); @@ -2328,18 +2345,18 @@ void shouldReturnVoltageLevelFormData() throws Exception { @Test void shouldReturnVoltageLevelBusbarSectionsFormInfos() throws Exception { - succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", "busbar_sections", resourceToString("/busbar-sections-all-data.json")); + succeedingTestGettingCreateVoltageLevelSectionInfos(NETWORK_UUID, null, "VLGEN4", resourceToString("/busbar-sections-all-data.json")); } @Test void shouldReturnVoltageLevelFeederBaysFormInfos() throws Exception { - succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", "feeder_bays", resourceToString("/feeder-bays-data.json")); + succeedingTestGettingMoveFeederBaysInfos(NETWORK_UUID, null, "VLGEN4", resourceToString("/feeder-bays-data.json")); } @Test void shouldReturnVoltageLevelSwitchesFormInfos() throws Exception { - succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, null, "VLGEN4", "switches", resourceToString("/switches-data.json")); - succeedingTestForTopologyInfosWithElementId(NETWORK_UUID, VARIANT_ID, "VLGEN4", "switches", resourceToString("/switches-data-in-variant.json")); + succeedingTestGettingVoltageLevelTopologyModificationInfos(NETWORK_UUID, null, "VLGEN4", resourceToString("/switches-data.json")); + succeedingTestGettingVoltageLevelTopologyModificationInfos(NETWORK_UUID, VARIANT_ID, "VLGEN4", resourceToString("/switches-data-in-variant.json")); } @Test diff --git a/src/test/resources/feeder-bays-data.json b/src/test/resources/feeder-bays-data.json index 09cc37bc..2cd0dd45 100644 --- a/src/test/resources/feeder-bays-data.json +++ b/src/test/resources/feeder-bays-data.json @@ -29,5 +29,18 @@ "connectionSide": null } ] + }, + "busBarSectionsInfos": { + "topologyKind": "NODE_BREAKER", + "switchKinds": [ + "DISCONNECTOR" + ], + "isSymmetrical": true, + "isBusbarSectionPositionFound": true, + "busBarSections": { + "1": [ + "NGEN4" + ] + } } } \ No newline at end of file From f7af20074137aa3588c034b703bcf27e198265ed Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Wed, 29 Oct 2025 13:52:41 +0100 Subject: [PATCH 08/11] add description for controller Signed-off-by: Etienne LESOT --- .../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 67554bd7..c509a1a8 100644 --- a/src/main/java/org/gridsuite/network/map/NetworkMapController.java +++ b/src/main/java/org/gridsuite/network/map/NetworkMapController.java @@ -96,8 +96,8 @@ public List getVoltageLevelBusesOrBusBarSections(@Parameter(descri } @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/move-feeder-bays", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Network switches topology information retrieved")}) + @Operation(summary = "get all information needed for MoveFeederBays modification") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "MoveFeederBays information retrieved")}) public MoveVoltageLevelFeederBaysInfos getMoveVoltageLevelFeederBaysInfos(@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) { @@ -105,8 +105,8 @@ public MoveVoltageLevelFeederBaysInfos getMoveVoltageLevelFeederBaysInfos(@Param } @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/create-voltage-level-section", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "")}) + @Operation(summary = "get all information needed for CreateVoltageLevelSection modification") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "CreateVoltageLevelSection information retrieved")}) public CreateVoltageLevelSectionInfos getCreateVoltageLevelSectionInfos(@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) { @@ -114,8 +114,8 @@ public CreateVoltageLevelSectionInfos getCreateVoltageLevelSectionInfos(@Paramet } @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/voltage-level-topology-modification", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "")}) + @Operation(summary = "get all information needed for voltageLevelTopologyoModification") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "voltageLevelTopologyModification information retrieved")}) public VoltageLevelTopologyModificationInfos getVoltageLevelTopologyModificationInfos(@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 ad8cb5dfb796fd0da8d3cad02a0905637e7c5048 Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Wed, 29 Oct 2025 15:04:43 +0100 Subject: [PATCH 09/11] review Signed-off-by: Etienne LESOT --- .../network/map/NetworkMapController.java | 46 +++++++++---------- .../CreateVoltageLevelSectionInfos.java | 23 ---------- ...ava => FeederBaysBusBarSectionsInfos.java} | 2 +- ...VoltageLevelTopologyModificationInfos.java | 25 ---------- .../map/services/NetworkMapService.java | 22 ++++----- .../network/map/NetworkMapControllerTest.java | 22 +++++---- .../resources/busbar-sections-all-data.json | 22 ++++----- .../resources/switches-data-in-variant.json | 38 ++++++++------- src/test/resources/switches-data.json | 38 ++++++++------- 9 files changed, 91 insertions(+), 147 deletions(-) delete mode 100644 src/main/java/org/gridsuite/network/map/dto/definition/topology/CreateVoltageLevelSectionInfos.java rename src/main/java/org/gridsuite/network/map/dto/definition/topology/{MoveVoltageLevelFeederBaysInfos.java => FeederBaysBusBarSectionsInfos.java} (94%) delete mode 100644 src/main/java/org/gridsuite/network/map/dto/definition/topology/VoltageLevelTopologyModificationInfos.java diff --git a/src/main/java/org/gridsuite/network/map/NetworkMapController.java b/src/main/java/org/gridsuite/network/map/NetworkMapController.java index c509a1a8..9b28dbec 100644 --- a/src/main/java/org/gridsuite/network/map/NetworkMapController.java +++ b/src/main/java/org/gridsuite/network/map/NetworkMapController.java @@ -19,9 +19,9 @@ 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.CreateVoltageLevelSectionInfos; -import org.gridsuite.network.map.dto.definition.topology.MoveVoltageLevelFeederBaysInfos; -import org.gridsuite.network.map.dto.definition.topology.VoltageLevelTopologyModificationInfos; +import org.gridsuite.network.map.dto.definition.topology.BusBarSectionsInfos; +import org.gridsuite.network.map.dto.definition.topology.FeederBaysBusBarSectionsInfos; +import org.gridsuite.network.map.dto.definition.topology.SwitchInfos; import org.gridsuite.network.map.services.NetworkMapService; import org.springframework.context.annotation.ComponentScan; import org.springframework.web.bind.annotation.*; @@ -95,31 +95,31 @@ public List getVoltageLevelBusesOrBusBarSections(@Parameter(descri return networkMapService.getVoltageLevelBusesOrBusbarSections(networkUuid, voltageLevelId, variantId); } - @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/move-feeder-bays", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "get all information needed for MoveFeederBays modification") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "MoveFeederBays information retrieved")}) - public MoveVoltageLevelFeederBaysInfos getMoveVoltageLevelFeederBaysInfos(@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) { + @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/feeder-bays-and-bus-bar-sections", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "get feeder bays and bus bar sections information") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = " feeder bays and bus bar sections information retrieved")}) + public FeederBaysBusBarSectionsInfos getMoveVoltageLevelFeederBaysInfos(@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.getMoveVoltageLevelFeederBaysInfos(networkUuid, voltageLevelId, variantId); } - @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/create-voltage-level-section", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "get all information needed for CreateVoltageLevelSection modification") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "CreateVoltageLevelSection information retrieved")}) - public CreateVoltageLevelSectionInfos getCreateVoltageLevelSectionInfos(@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.getCreateVoltageLevelSectionInfos(networkUuid, voltageLevelId, variantId); + @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/bus-bar-sections", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "get bus bar sections information") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "bus bar sections information retrieved")}) + public BusBarSectionsInfos getBusBarSectionsInfos(@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.getBusBarSectionsInfos(networkUuid, voltageLevelId, variantId); } - @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/voltage-level-topology-modification", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "get all information needed for voltageLevelTopologyoModification") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "voltageLevelTopologyModification information retrieved")}) - public VoltageLevelTopologyModificationInfos getVoltageLevelTopologyModificationInfos(@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.getVoltageLevelTopologyModificationInfos(networkUuid, voltageLevelId, variantId); + @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/switches", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "get switches information") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "switches information retrieved")}) + public List getSwitchInfos(@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.getSwitchInfos(networkUuid, voltageLevelId, variantId); } @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/CreateVoltageLevelSectionInfos.java b/src/main/java/org/gridsuite/network/map/dto/definition/topology/CreateVoltageLevelSectionInfos.java deleted file mode 100644 index 1e712c42..00000000 --- a/src/main/java/org/gridsuite/network/map/dto/definition/topology/CreateVoltageLevelSectionInfos.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * 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; - -/** - * @author Etienne Lesot - */ -@SuperBuilder -@Getter -@Setter -public class CreateVoltageLevelSectionInfos { - @JsonInclude(JsonInclude.Include.NON_NULL) - private BusBarSectionsInfos busBarSectionsInfos; -} diff --git a/src/main/java/org/gridsuite/network/map/dto/definition/topology/MoveVoltageLevelFeederBaysInfos.java b/src/main/java/org/gridsuite/network/map/dto/definition/topology/FeederBaysBusBarSectionsInfos.java similarity index 94% rename from src/main/java/org/gridsuite/network/map/dto/definition/topology/MoveVoltageLevelFeederBaysInfos.java rename to src/main/java/org/gridsuite/network/map/dto/definition/topology/FeederBaysBusBarSectionsInfos.java index aa45a01c..9ac645c0 100644 --- a/src/main/java/org/gridsuite/network/map/dto/definition/topology/MoveVoltageLevelFeederBaysInfos.java +++ b/src/main/java/org/gridsuite/network/map/dto/definition/topology/FeederBaysBusBarSectionsInfos.java @@ -20,7 +20,7 @@ @SuperBuilder @Getter @Setter -public class MoveVoltageLevelFeederBaysInfos { +public class FeederBaysBusBarSectionsInfos { @JsonInclude(JsonInclude.Include.NON_NULL) private Map> feederBaysInfos; diff --git a/src/main/java/org/gridsuite/network/map/dto/definition/topology/VoltageLevelTopologyModificationInfos.java b/src/main/java/org/gridsuite/network/map/dto/definition/topology/VoltageLevelTopologyModificationInfos.java deleted file mode 100644 index 1e2d5c53..00000000 --- a/src/main/java/org/gridsuite/network/map/dto/definition/topology/VoltageLevelTopologyModificationInfos.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * 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 java.util.List; - -/** - * @author Etienne Lesot - */ -@SuperBuilder -@Getter -@Setter -public class VoltageLevelTopologyModificationInfos { - @JsonInclude(JsonInclude.Include.NON_NULL) - private List switchesInfos; -} 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 7fd28a77..85e07563 100644 --- a/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java +++ b/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java @@ -17,9 +17,9 @@ 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.CreateVoltageLevelSectionInfos; -import org.gridsuite.network.map.dto.definition.topology.MoveVoltageLevelFeederBaysInfos; -import org.gridsuite.network.map.dto.definition.topology.VoltageLevelTopologyModificationInfos; +import org.gridsuite.network.map.dto.definition.topology.BusBarSectionsInfos; +import org.gridsuite.network.map.dto.definition.topology.FeederBaysBusBarSectionsInfos; +import org.gridsuite.network.map.dto.definition.topology.SwitchInfos; import org.gridsuite.network.map.dto.mapper.ElementInfosMapper; import org.gridsuite.network.map.dto.mapper.HvdcInfosMapper; import org.gridsuite.network.map.dto.utils.TopologyUtils; @@ -131,29 +131,25 @@ public List getVoltageLevelBusesOrBusbarSections(UUID networkUuid, }; } - public CreateVoltageLevelSectionInfos getCreateVoltageLevelSectionInfos(UUID networkUuid, String voltageLevelId, String variantId) { + public BusBarSectionsInfos getBusBarSectionsInfos(UUID networkUuid, String voltageLevelId, String variantId) { Network network = getNetwork(networkUuid, PreloadingStrategy.NONE, variantId); VoltageLevel voltageLevel = network.getVoltageLevel(voltageLevelId); - CreateVoltageLevelSectionInfos.CreateVoltageLevelSectionInfosBuilder builder = CreateVoltageLevelSectionInfos.builder(); - builder.busBarSectionsInfos(TopologyUtils.getBusBarSectionsInfos(voltageLevel)); - return builder.build(); + return TopologyUtils.getBusBarSectionsInfos(voltageLevel); } - public MoveVoltageLevelFeederBaysInfos getMoveVoltageLevelFeederBaysInfos(UUID networkUuid, String voltageLevelId, String variantId) { + public FeederBaysBusBarSectionsInfos getMoveVoltageLevelFeederBaysInfos(UUID networkUuid, String voltageLevelId, String variantId) { Network network = getNetwork(networkUuid, PreloadingStrategy.NONE, variantId); VoltageLevel voltageLevel = network.getVoltageLevel(voltageLevelId); - MoveVoltageLevelFeederBaysInfos.MoveVoltageLevelFeederBaysInfosBuilder builder = MoveVoltageLevelFeederBaysInfos.builder(); + FeederBaysBusBarSectionsInfos.FeederBaysBusBarSectionsInfosBuilder builder = FeederBaysBusBarSectionsInfos.builder(); builder.feederBaysInfos(TopologyUtils.getFeederBaysInfos(voltageLevel)); builder.busBarSectionsInfos(TopologyUtils.getBusBarSectionsInfos(voltageLevel)); return builder.build(); } - public VoltageLevelTopologyModificationInfos getVoltageLevelTopologyModificationInfos(UUID networkUuid, String voltageLevelId, String variantId) { + public List getSwitchInfos(UUID networkUuid, String voltageLevelId, String variantId) { Network network = getNetwork(networkUuid, PreloadingStrategy.NONE, variantId); VoltageLevel voltageLevel = network.getVoltageLevel(voltageLevelId); - VoltageLevelTopologyModificationInfos.VoltageLevelTopologyModificationInfosBuilder builder = VoltageLevelTopologyModificationInfos.builder(); - builder.switchesInfos(TopologyUtils.getSwitchesInfos(voltageLevel.getId(), network)); - return builder.build(); + return TopologyUtils.getSwitchesInfos(voltageLevel.getId(), network); } public String getVoltageLevelSubstationID(UUID networkUuid, String voltageLevelId, String variantId) { diff --git a/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java b/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java index 1b6b36a7..8e86b350 100644 --- a/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java +++ b/src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java @@ -1422,8 +1422,8 @@ private static String resourceToString(String resource) throws IOException { return new String(ByteStreams.toByteArray(NetworkMapControllerTest.class.getResourceAsStream(resource)), StandardCharsets.UTF_8); } - private void succeedingTestGettingMoveFeederBaysInfos(UUID networkUuid, String variantId, String voltageLevelId, String expectedJson) throws Exception { - MvcResult res = mvc.perform(get("/v1/networks/{networkUuid}/voltage-levels/{voltageLevelId}/move-feeder-bays", networkUuid, voltageLevelId) + private void succeedingTestGettingFeederBaysAndBusBarSectionsInfos(UUID networkUuid, String variantId, String voltageLevelId, String expectedJson) throws Exception { + MvcResult res = mvc.perform(get("/v1/networks/{networkUuid}/voltage-levels/{voltageLevelId}/feeder-bays-and-bus-bar-sections", networkUuid, voltageLevelId) .queryParam(QUERY_PARAM_VARIANT_ID, variantId)) .andExpect(status().isOk()) .andReturn(); @@ -1431,19 +1431,21 @@ private void succeedingTestGettingMoveFeederBaysInfos(UUID networkUuid, String v JSONAssert.assertEquals(expectedJson, res.getResponse().getContentAsString(), JSONCompareMode.NON_EXTENSIBLE); } - private void succeedingTestGettingCreateVoltageLevelSectionInfos(UUID networkUuid, String variantId, String voltageLevelId, String expectedJson) throws Exception { - MvcResult res = mvc.perform(get("/v1/networks/{networkUuid}/voltage-levels/{voltageLevelId}/create-voltage-level-section", networkUuid, voltageLevelId) + private void succeedingTestGettingBusBarSectionsInfos(UUID networkUuid, String variantId, String voltageLevelId, String expectedJson) throws Exception { + MvcResult res = mvc.perform(get("/v1/networks/{networkUuid}/voltage-levels/{voltageLevelId}/bus-bar-sections", networkUuid, voltageLevelId) .queryParam(QUERY_PARAM_VARIANT_ID, variantId)) .andExpect(status().isOk()) .andReturn(); + System.out.println(res.getResponse().getContentAsString()); JSONAssert.assertEquals(expectedJson, res.getResponse().getContentAsString(), JSONCompareMode.NON_EXTENSIBLE); } - private void succeedingTestGettingVoltageLevelTopologyModificationInfos(UUID networkUuid, String variantId, String voltageLevelId, String expectedJson) throws Exception { - MvcResult res = mvc.perform(get("/v1/networks/{networkUuid}/voltage-levels/{voltageLevelId}/voltage-level-topology-modification", networkUuid, voltageLevelId) + private void succeedingTestGettingSwitchesInfos(UUID networkUuid, String variantId, String voltageLevelId, String expectedJson) throws Exception { + MvcResult res = mvc.perform(get("/v1/networks/{networkUuid}/voltage-levels/{voltageLevelId}/switches", networkUuid, voltageLevelId) .queryParam(QUERY_PARAM_VARIANT_ID, variantId)) .andExpect(status().isOk()) .andReturn(); + System.out.println(res.getResponse().getContentAsString()); JSONAssert.assertEquals(expectedJson, res.getResponse().getContentAsString(), JSONCompareMode.NON_EXTENSIBLE); } @@ -2345,18 +2347,18 @@ void shouldReturnVoltageLevelFormData() throws Exception { @Test void shouldReturnVoltageLevelBusbarSectionsFormInfos() throws Exception { - succeedingTestGettingCreateVoltageLevelSectionInfos(NETWORK_UUID, null, "VLGEN4", resourceToString("/busbar-sections-all-data.json")); + succeedingTestGettingBusBarSectionsInfos(NETWORK_UUID, null, "VLGEN4", resourceToString("/busbar-sections-all-data.json")); } @Test void shouldReturnVoltageLevelFeederBaysFormInfos() throws Exception { - succeedingTestGettingMoveFeederBaysInfos(NETWORK_UUID, null, "VLGEN4", resourceToString("/feeder-bays-data.json")); + succeedingTestGettingFeederBaysAndBusBarSectionsInfos(NETWORK_UUID, null, "VLGEN4", resourceToString("/feeder-bays-data.json")); } @Test void shouldReturnVoltageLevelSwitchesFormInfos() throws Exception { - succeedingTestGettingVoltageLevelTopologyModificationInfos(NETWORK_UUID, null, "VLGEN4", resourceToString("/switches-data.json")); - succeedingTestGettingVoltageLevelTopologyModificationInfos(NETWORK_UUID, VARIANT_ID, "VLGEN4", resourceToString("/switches-data-in-variant.json")); + succeedingTestGettingSwitchesInfos(NETWORK_UUID, null, "VLGEN4", resourceToString("/switches-data.json")); + succeedingTestGettingSwitchesInfos(NETWORK_UUID, VARIANT_ID, "VLGEN4", resourceToString("/switches-data-in-variant.json")); } @Test diff --git a/src/test/resources/busbar-sections-all-data.json b/src/test/resources/busbar-sections-all-data.json index 7d1a16b3..e4fbda2b 100644 --- a/src/test/resources/busbar-sections-all-data.json +++ b/src/test/resources/busbar-sections-all-data.json @@ -1,15 +1,13 @@ { - "busBarSectionsInfos": { - "topologyKind": "NODE_BREAKER", - "switchKinds": [ - "DISCONNECTOR" - ], - "isSymmetrical": true, - "isBusbarSectionPositionFound": true, - "busBarSections": { - "1": [ - "NGEN4" - ] - } + "topologyKind": "NODE_BREAKER", + "switchKinds": [ + "DISCONNECTOR" + ], + "isSymmetrical": true, + "isBusbarSectionPositionFound": true, + "busBarSections": { + "1": [ + "NGEN4" + ] } } \ No newline at end of file diff --git a/src/test/resources/switches-data-in-variant.json b/src/test/resources/switches-data-in-variant.json index b37bb644..1f8363ee 100644 --- a/src/test/resources/switches-data-in-variant.json +++ b/src/test/resources/switches-data-in-variant.json @@ -1,20 +1,18 @@ -{ - "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 +[ + { + "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 94e337c5..af40ffad 100644 --- a/src/test/resources/switches-data.json +++ b/src/test/resources/switches-data.json @@ -1,20 +1,18 @@ -{ - "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 +[ + { + "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 149e9e28c6806b682f4086423959c96c9badecab Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Wed, 29 Oct 2025 16:33:01 +0100 Subject: [PATCH 10/11] refactor Signed-off-by: Etienne LESOT --- .../gridsuite/network/map/NetworkMapController.java | 10 +++++----- .../dto/definition/topology/BusBarSectionsInfos.java | 4 ---- .../gridsuite/network/map/dto/utils/TopologyUtils.java | 1 - src/test/resources/busbar-sections-all-data.json | 3 --- src/test/resources/feeder-bays-data.json | 3 --- 5 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/gridsuite/network/map/NetworkMapController.java b/src/main/java/org/gridsuite/network/map/NetworkMapController.java index 9b28dbec..7882aa91 100644 --- a/src/main/java/org/gridsuite/network/map/NetworkMapController.java +++ b/src/main/java/org/gridsuite/network/map/NetworkMapController.java @@ -114,11 +114,11 @@ public BusBarSectionsInfos getBusBarSectionsInfos(@Parameter(description = "Netw } @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/switches", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "get switches information") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "switches information retrieved")}) - public List getSwitchInfos(@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) { + @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.getSwitchInfos(networkUuid, voltageLevelId, variantId); } 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 index 755a8724..d1a4c5f0 100644 --- 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 @@ -7,7 +7,6 @@ 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; @@ -27,9 +26,6 @@ public class BusBarSectionsInfos { @JsonInclude(JsonInclude.Include.NON_NULL) private TopologyKind topologyKind; - @JsonInclude(JsonInclude.Include.NON_NULL) - private List switchKinds; - @JsonInclude(JsonInclude.Include.NON_NULL) private Boolean isSymmetrical; 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 0419d7dd..21ee36c4 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 @@ -72,7 +72,6 @@ public static BusBarSectionsInfos getBusBarSectionsInfos(VoltageLevel voltageLev if (isSymmetrical) { busBarSectionsInfos.setIsSymmetrical(true); - busBarSectionsInfos.setSwitchKinds(Collections.nCopies(maxSectionIndex - 1, SwitchKind.DISCONNECTOR)); } busBarSectionsInfos.setTopologyKind(voltageLevel.getTopologyKind()); return busBarSectionsInfos; diff --git a/src/test/resources/busbar-sections-all-data.json b/src/test/resources/busbar-sections-all-data.json index e4fbda2b..a9cd3d53 100644 --- a/src/test/resources/busbar-sections-all-data.json +++ b/src/test/resources/busbar-sections-all-data.json @@ -1,8 +1,5 @@ { "topologyKind": "NODE_BREAKER", - "switchKinds": [ - "DISCONNECTOR" - ], "isSymmetrical": true, "isBusbarSectionPositionFound": true, "busBarSections": { diff --git a/src/test/resources/feeder-bays-data.json b/src/test/resources/feeder-bays-data.json index 2cd0dd45..8e455f6d 100644 --- a/src/test/resources/feeder-bays-data.json +++ b/src/test/resources/feeder-bays-data.json @@ -32,9 +32,6 @@ }, "busBarSectionsInfos": { "topologyKind": "NODE_BREAKER", - "switchKinds": [ - "DISCONNECTOR" - ], "isSymmetrical": true, "isBusbarSectionPositionFound": true, "busBarSections": { From 6069b539531231a0808ddd0dbb45c3d093368770 Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Tue, 4 Nov 2025 15:30:26 +0100 Subject: [PATCH 11/11] review Signed-off-by: Etienne LESOT --- .../network/map/NetworkMapController.java | 8 +-- .../dto/mapper/VoltageLevelInfosMapper.java | 58 +++++++++++-------- .../map/services/NetworkMapService.java | 2 +- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/gridsuite/network/map/NetworkMapController.java b/src/main/java/org/gridsuite/network/map/NetworkMapController.java index 7882aa91..11dc0566 100644 --- a/src/main/java/org/gridsuite/network/map/NetworkMapController.java +++ b/src/main/java/org/gridsuite/network/map/NetworkMapController.java @@ -98,10 +98,10 @@ public List getVoltageLevelBusesOrBusBarSections(@Parameter(descri @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/feeder-bays-and-bus-bar-sections", produces = APPLICATION_JSON_VALUE) @Operation(summary = "get feeder bays and bus bar sections information") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = " feeder bays and bus bar sections information retrieved")}) - public FeederBaysBusBarSectionsInfos getMoveVoltageLevelFeederBaysInfos(@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.getMoveVoltageLevelFeederBaysInfos(networkUuid, voltageLevelId, variantId); + public FeederBaysBusBarSectionsInfos getFeederBaysInfos(@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.getFeederBaysInfos(networkUuid, voltageLevelId, variantId); } @GetMapping(value = "/networks/{networkUuid}/voltage-levels/{voltageLevelId}/bus-bar-sections", produces = APPLICATION_JSON_VALUE) 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 7cd3aff1..518104c1 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 @@ -8,6 +8,8 @@ import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.BusbarSectionPosition; +import lombok.Builder; +import lombok.Getter; import org.gridsuite.network.map.dto.ElementInfos; import org.gridsuite.network.map.dto.InfoTypeParameters; import org.gridsuite.network.map.dto.definition.voltagelevel.VoltageLevelFormInfos; @@ -18,9 +20,10 @@ import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; -import static com.powsybl.iidm.network.TopologyKind.NODE_BREAKER; +import static org.gridsuite.network.map.dto.mapper.VoltageLevelInfosMapper.TopologyInfos.setDefaultBuilder; import static org.gridsuite.network.map.dto.utils.ElementUtils.*; /** @@ -54,11 +57,11 @@ static VoltageLevelFormInfos toFormInfos(Identifiable identifiable) { .identifiableShortCircuit(ExtensionUtils.toIdentifiableShortCircuit(voltageLevel)) .build(); if (voltageLevel.getTopologyKind().equals(TopologyKind.NODE_BREAKER)) { - VoltageLevelFormInfos busBarSectionsInfos = getVoltageLevelBusBarSectionsInfos(voltageLevel); - voltageLevelFormInfos.setBusbarCount(busBarSectionsInfos.getBusbarCount()); - voltageLevelFormInfos.setSectionCount(busBarSectionsInfos.getSectionCount()); - voltageLevelFormInfos.setSwitchKinds(busBarSectionsInfos.getSwitchKinds()); - voltageLevelFormInfos.setIsSymmetrical(busBarSectionsInfos.getIsSymmetrical()); + TopologyInfos topologyInfos = getVoltageLevelBusBarSectionsInfos(voltageLevel); + voltageLevelFormInfos.setBusbarCount(topologyInfos.getBusbarCount()); + voltageLevelFormInfos.setSectionCount(topologyInfos.getSectionCount()); + voltageLevelFormInfos.setSwitchKinds(topologyInfos.getSwitchKinds()); + voltageLevelFormInfos.setIsSymmetrical(topologyInfos.getIsSymmetrical()); } return voltageLevelFormInfos; } @@ -76,7 +79,7 @@ static VoltageLevelMapInfos toMapInfos(Identifiable identifiable) { static VoltageLevelTabInfos toTabInfos(Identifiable identifiable) { VoltageLevel voltageLevel = (VoltageLevel) identifiable; - VoltageLevelTabInfos.VoltageLevelTabInfosBuilder builder = VoltageLevelTabInfos.builder() + VoltageLevelTabInfos.VoltageLevelTabInfosBuilder builder = VoltageLevelTabInfos.builder() .id(voltageLevel.getId()) .name(voltageLevel.getOptionalName().orElse(null)) .substationId(voltageLevel.getSubstation().map(Substation::getId).orElse(null)) @@ -91,20 +94,34 @@ static VoltageLevelTabInfos toTabInfos(Identifiable identifiable) { return builder.build(); } - public static VoltageLevelFormInfos getVoltageLevelBusBarSectionsInfos(VoltageLevel voltageLevel) { + @Builder + @Getter + public static class TopologyInfos { + private Integer busbarCount; + + private Integer sectionCount; + + private List switchKinds; + + private Boolean isSymmetrical; + + public static TopologyInfos.TopologyInfosBuilder setDefaultBuilder() { + return TopologyInfos.builder().busbarCount(1) + .sectionCount(1) + .switchKinds(Collections.emptyList()) + .isSymmetrical(false); + } + } + + public static TopologyInfos getVoltageLevelBusBarSectionsInfos(VoltageLevel voltageLevel) { Map nbSectionsPerBusbar = new HashMap<>(); + TopologyInfos.TopologyInfosBuilder builder = setDefaultBuilder(); 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(); + return builder.build(); } int busbarIndex = extension.getBusbarIndex(); int sectionIndex = extension.getSectionIndex(); @@ -118,19 +135,12 @@ public static VoltageLevelFormInfos getVoltageLevelBusBarSectionsInfos(VoltageLe && nbSectionsPerBusbar.values().stream().findFirst().orElse(0).equals(maxSectionIndex); if (isSymmetrical) { - return VoltageLevelFormInfos.builder() - .busbarCount(maxBusbarIndex) + return 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(); + return builder.build(); } } 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 85e07563..4a19ce11 100644 --- a/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java +++ b/src/main/java/org/gridsuite/network/map/services/NetworkMapService.java @@ -137,7 +137,7 @@ public BusBarSectionsInfos getBusBarSectionsInfos(UUID networkUuid, String volta return TopologyUtils.getBusBarSectionsInfos(voltageLevel); } - public FeederBaysBusBarSectionsInfos getMoveVoltageLevelFeederBaysInfos(UUID networkUuid, String voltageLevelId, String variantId) { + public FeederBaysBusBarSectionsInfos getFeederBaysInfos(UUID networkUuid, String voltageLevelId, String variantId) { Network network = getNetwork(networkUuid, PreloadingStrategy.NONE, variantId); VoltageLevel voltageLevel = network.getVoltageLevel(voltageLevelId); FeederBaysBusBarSectionsInfos.FeederBaysBusBarSectionsInfosBuilder builder = FeederBaysBusBarSectionsInfos.builder();