From 80a1fac569d9cce04988e01b80e5a51abe1be233 Mon Sep 17 00:00:00 2001 From: Ghazoua Rehili Date: Fri, 18 Oct 2024 15:27:56 +0200 Subject: [PATCH 1/2] =?UTF-8?q?retreive=20busBarSectionId=20and=20VoltageI?= =?UTF-8?q?d=20not=20set=20in=20modification=20connec=E2=80=A6=20(#546)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: REHILI Ghazwa --- .../BusbarSectionFinderTraverser.java | 49 ++++ .../modifications/ModificationUtils.java | 218 ++++++++++-------- .../GeneratorModificationTest.java | 24 ++ .../modifications/LineModificationTest.java | 18 ++ ...woWindingsTransformerModificationTest.java | 2 +- 5 files changed, 213 insertions(+), 98 deletions(-) create mode 100644 src/main/java/org/gridsuite/modification/server/modifications/BusbarSectionFinderTraverser.java diff --git a/src/main/java/org/gridsuite/modification/server/modifications/BusbarSectionFinderTraverser.java b/src/main/java/org/gridsuite/modification/server/modifications/BusbarSectionFinderTraverser.java new file mode 100644 index 000000000..82efbedcc --- /dev/null +++ b/src/main/java/org/gridsuite/modification/server/modifications/BusbarSectionFinderTraverser.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2024, 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.modification.server.modifications; + +import com.powsybl.iidm.network.IdentifiableType; +import com.powsybl.iidm.network.Switch; +import com.powsybl.iidm.network.Terminal; +import com.powsybl.math.graph.TraverseResult; + +/** + * @author Slimane Amar + */ +// FIXME : to remove when this class is available in network-store +public class BusbarSectionFinderTraverser implements Terminal.TopologyTraverser { + + private final boolean onlyConnectedBbs; + + private String firstTraversedBbsId; + + public BusbarSectionFinderTraverser(boolean onlyConnectedBbs) { + this.onlyConnectedBbs = onlyConnectedBbs; + } + + @Override + public TraverseResult traverse(Terminal terminal, boolean connected) { + if (terminal.getConnectable().getType() == IdentifiableType.BUSBAR_SECTION) { + firstTraversedBbsId = terminal.getConnectable().getId(); + return TraverseResult.TERMINATE_TRAVERSER; + } + return TraverseResult.CONTINUE; + } + + @Override + public TraverseResult traverse(Switch aSwitch) { + if (onlyConnectedBbs && aSwitch.isOpen()) { + return TraverseResult.TERMINATE_PATH; + } + return TraverseResult.CONTINUE; + } + + public String getFirstTraversedBbsId() { + return firstTraversedBbsId; + } +} + diff --git a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java index a2f5a4833..05c81b1ec 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java @@ -13,6 +13,7 @@ import com.powsybl.iidm.modification.topology.*; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.*; +import com.powsybl.math.graph.TraversalType; import com.powsybl.network.store.iidm.impl.MinMaxReactiveLimitsImpl; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; @@ -57,6 +58,12 @@ public final class ModificationUtils { public static final String CONNECTION_POSITION_FIELD_NAME = "Connection position"; public static final String NOT_EXIST_IN_NETWORK = " does not exist in network"; + public enum FeederSide { + INJECTION_SINGLE_SIDE, + BRANCH_SIDE_ONE, + BRANCH_SIDE_TWO + } + private ModificationUtils() { } @@ -615,10 +622,7 @@ public ReportNode modifyInjectionConnectivityAttributes(ConnectablePosition c InjectionModificationInfos modificationInfos, ReportNode connectivityReports) { List reports = new ArrayList<>(); - if (isVoltageOrBusbarIdMissing(modificationInfos.getVoltageLevelId(), modificationInfos.getBusOrBusbarSectionId(), modificationInfos.getEquipmentId(), reports)) { - return reports.get(0); - } - processConnectivityPosition(connectablePosition, connectablePositionAdder, modificationInfos, injection.getNetwork(), reports, false); + processConnectivityPosition(connectablePosition, connectablePositionAdder, modificationInfos, injection.getNetwork(), reports); modifyConnection(modificationInfos.getTerminalConnected(), injection, injection.getTerminal(), reports); return reportModifications(connectivityReports, reports, "ConnectivityModified", CONNECTIVITY); @@ -630,136 +634,122 @@ public ReportNode modifyBranchConnectivityAttributes(ConnectablePosition conn BranchModificationInfos modificationInfos, ReportNode connectivityReports) { List reports = new ArrayList<>(); - if (isVoltageOrBusbarIdMissing(modificationInfos.getVoltageLevelId1(), modificationInfos.getBusOrBusbarSectionId1(), modificationInfos.getEquipmentId(), reports) || - isVoltageOrBusbarIdMissing(modificationInfos.getVoltageLevelId2(), modificationInfos.getBusOrBusbarSectionId2(), modificationInfos.getEquipmentId(), reports)) { - return reports.get(0); - } - - processConnectivityPosition(connectablePosition, connectablePositionAdder, modificationInfos, branch.getNetwork(), reports, true); + processConnectivityPosition(connectablePosition, connectablePositionAdder, modificationInfos, branch.getNetwork(), reports); modifyConnection(modificationInfos.getTerminal1Connected(), branch, branch.getTerminal1(), reports); modifyConnection(modificationInfos.getTerminal2Connected(), branch, branch.getTerminal2(), reports); return reportModifications(connectivityReports, reports, "ConnectivityModified", CONNECTIVITY); } - private boolean isVoltageOrBusbarIdMissing(AttributeModification voltageLevelId, AttributeModification busbarSectionId, String equipmentId, List reports) { - if (voltageLevelId == null || busbarSectionId == null) { - reports.add(ReportNode.newRootReportNode() - .withMessageTemplate("VoltageLevelOrBusbarSectionNotFound", - "Voltage level id or Bus bar section id of equipment id=${id} not found") - .withUntypedValue("id", equipmentId) - .withSeverity(TypedValue.WARN_SEVERITY) - .build()); - return true; - } - return false; - } - private void processConnectivityPosition(ConnectablePosition connectablePosition, ConnectablePositionAdder connectablePositionAdder, BasicEquipmentModificationInfos modificationInfos, Network network, - List reports, - boolean isBranch) { + List reports) { if (connectablePosition != null) { - modifyExistingConnectivityPosition(connectablePosition, modificationInfos, reports, isBranch); + modifyExistingConnectivityPosition(connectablePosition, modificationInfos, reports); } else { - createNewConnectivityPosition(connectablePositionAdder, modificationInfos, network, reports, isBranch); + createNewConnectivityPosition(connectablePositionAdder, modificationInfos, network, reports); } } private void modifyExistingConnectivityPosition(ConnectablePosition connectablePosition, BasicEquipmentModificationInfos modificationInfos, - List reports, - boolean isBranch) { - if (isBranch) { - modifyConnectablePosition(connectablePosition.getFeeder1(), modificationInfos, reports, 1); - modifyConnectablePosition(connectablePosition.getFeeder2(), modificationInfos, reports, 2); - } else { - modifyConnectablePosition(connectablePosition.getFeeder(), modificationInfos, reports, 0); + List reports) { + if (modificationInfos instanceof BranchModificationInfos) { + modifyConnectablePosition(connectablePosition.getFeeder1(), modificationInfos, reports, FeederSide.BRANCH_SIDE_ONE); + modifyConnectablePosition(connectablePosition.getFeeder2(), modificationInfos, reports, FeederSide.BRANCH_SIDE_TWO); + } else if (modificationInfos instanceof InjectionModificationInfos) { + modifyConnectablePosition(connectablePosition.getFeeder(), modificationInfos, reports, FeederSide.INJECTION_SINGLE_SIDE); } } private void createNewConnectivityPosition(ConnectablePositionAdder adder, BasicEquipmentModificationInfos modificationInfos, Network network, - List reports, - boolean isBranch) { - if (isBranch) { - ConnectablePositionAdder.FeederAdder feederAdder1 = adder.newFeeder1(); - ConnectablePositionAdder.FeederAdder feederAdder2 = adder.newFeeder2(); - addConnectablePosition(adder, feederAdder1, modificationInfos, network, reports, 1); - addConnectablePosition(adder, feederAdder2, modificationInfos, network, reports, 2); - } else { - ConnectablePositionAdder.FeederAdder feederAdder = adder.newFeeder(); - addConnectablePosition(adder, feederAdder, modificationInfos, network, reports, 0); + List reports) { + if (modificationInfos instanceof BranchModificationInfos) { + addConnectablePosition(adder, modificationInfos, network, reports, FeederSide.BRANCH_SIDE_ONE); + addConnectablePosition(adder, modificationInfos, network, reports, FeederSide.BRANCH_SIDE_TWO); + } else if (modificationInfos instanceof InjectionModificationInfos) { + addConnectablePosition(adder, modificationInfos, network, reports, FeederSide.INJECTION_SINGLE_SIDE); } } private void modifyConnectablePosition(ConnectablePosition.Feeder feeder, BasicEquipmentModificationInfos modificationInfos, List reports, - int feederNumber) { - applyModifications(feeder, modificationInfos, reports, feederNumber); + FeederSide feederSide) { + applyModifications(feeder, modificationInfos, reports, feederSide); } private void applyModifications(ConnectablePosition.Feeder feeder, BasicEquipmentModificationInfos modificationInfos, List reports, - int feederNumber) { + FeederSide feederSide) { ReportNode connectionNameReport = applyElementaryModificationsAndReturnReport(feeder::setName, feeder.getName()::get, - getConnectionName(modificationInfos, feederNumber), - getConnectionNameField(feederNumber)); + getConnectionName(modificationInfos, feederSide), + getConnectionNameField(feederSide)); if (connectionNameReport != null) { reports.add(connectionNameReport); } ReportNode connectionDirectionReport = applyElementaryModificationsAndReturnReport(feeder::setDirection, feeder::getDirection, - getConnectionDirection(modificationInfos, feederNumber), - getConnectionDirectionField(feederNumber)); + getConnectionDirection(modificationInfos, feederSide), + getConnectionDirectionField(feederSide)); if (connectionDirectionReport != null) { reports.add(connectionDirectionReport); } ReportNode connectionPositionReport = applyElementaryModificationsAndReturnReport(feeder::setOrder, feeder.getOrder()::get, - getConnectionPosition(modificationInfos, feederNumber), - getConnectionPositionField(feederNumber)); + getConnectionPosition(modificationInfos, feederSide), + getConnectionPositionField(feederSide)); if (connectionPositionReport != null) { reports.add(connectionPositionReport); } } private void addConnectablePosition(ConnectablePositionAdder adder, - ConnectablePositionAdder.FeederAdder feeder, BasicEquipmentModificationInfos modificationInfos, Network network, List reports, - int feederNumber) { - AttributeModification connectionName = getConnectionName(modificationInfos, feederNumber); - AttributeModification connectionDirection = getConnectionDirection(modificationInfos, feederNumber); - AttributeModification connectionPosition = getConnectionPosition(modificationInfos, feederNumber); + FeederSide feederSide) { + AttributeModification connectionName = getConnectionName(modificationInfos, feederSide); + AttributeModification connectionDirection = getConnectionDirection(modificationInfos, feederSide); + AttributeModification connectionPosition = getConnectionPosition(modificationInfos, feederSide); + if (Objects.isNull(connectionName) && Objects.isNull(connectionDirection) && Objects.isNull(connectionPosition)) { + return; + } AttributeModification equipmentId = getEquipmentId(modificationInfos); - AttributeModification voltageLevelId = getVoltageLevelId(modificationInfos, feederNumber); - AttributeModification busOrBusbarSectionId = getBusOrBusbarSectionId(modificationInfos, feederNumber); - int position = getPosition(connectionPosition, busOrBusbarSectionId, network, voltageLevelId); - + AttributeModification voltageLevelId = getVoltageLevelId(modificationInfos, feederSide); + AttributeModification busOrBusbarSectionId = getBusOrBusbarSectionId(modificationInfos, feederSide); + int position = getPosition(connectionPosition, busOrBusbarSectionId, voltageLevelId, equipmentId, feederSide, network); + ConnectablePositionAdder.FeederAdder feeder; + switch (feederSide) { + case INJECTION_SINGLE_SIDE -> feeder = adder.newFeeder(); + case BRANCH_SIDE_ONE -> feeder = adder.newFeeder1(); + case BRANCH_SIDE_TWO -> feeder = adder.newFeeder2(); + default -> { + return; + } + } ReportNode connectionNameReport = applyConnectablePositionAttribute( feeder::withName, connectionName, equipmentId, reports, - getConnectionNameField(feederNumber), connectionDirection, connectionPosition + getConnectionNameField(feederSide), connectionDirection, connectionPosition ); ReportNode connectionDirectionReport = applyConnectablePositionAttribute( feeder::withDirection, connectionDirection, new AttributeModification<>(ConnectablePosition.Direction.UNDEFINED, OperationType.SET), - reports, getConnectionDirectionField(feederNumber), + reports, getConnectionDirectionField(feederSide), connectionName, connectionPosition ); ReportNode connectionPositionReport = applyConnectablePositionAttribute( feeder::withOrder, connectionPosition, new AttributeModification<>(position, OperationType.SET), - reports, getConnectionPositionField(feederNumber), + reports, getConnectionPositionField(feederSide), connectionName, connectionDirection ); @@ -791,35 +781,38 @@ private boolean isAnyAttributesNonNull(AttributeModification... attributes) { return Arrays.stream(attributes).anyMatch(Objects::nonNull); } - private T getConnectionDetail(BasicEquipmentModificationInfos modificationInfos, int feederNumber, + private T getConnectionDetail(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide, Function branchFunc1, Function branchFunc2, Function injectionFunc) { if (modificationInfos instanceof BranchModificationInfos branchInfo) { - return feederNumber == 1 ? branchFunc1.apply(branchInfo) : branchFunc2.apply(branchInfo); + if (Objects.requireNonNull(feederSide) == FeederSide.BRANCH_SIDE_ONE) { + return branchFunc1.apply(branchInfo); + } else if (feederSide == FeederSide.BRANCH_SIDE_TWO) { + return branchFunc2.apply(branchInfo); + } } else if (modificationInfos instanceof InjectionModificationInfos injectionInfo) { return injectionFunc.apply(injectionInfo); } return null; } - private String getConnectionFieldName(int feederNumber, String baseFieldName) { - return switch (feederNumber) { - case 0 -> baseFieldName; - case 1 -> baseFieldName + " 1"; - case 2 -> baseFieldName + " 2"; - default -> ""; + private String getConnectionFieldName(FeederSide feederSide, String baseFieldName) { + return switch (feederSide) { + case INJECTION_SINGLE_SIDE -> baseFieldName; + case BRANCH_SIDE_ONE -> baseFieldName + " 1"; + case BRANCH_SIDE_TWO -> baseFieldName + " 2"; }; } - private AttributeModification getVoltageLevelId(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getVoltageLevelId(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getVoltageLevelId1, BranchModificationInfos::getVoltageLevelId2, InjectionModificationInfos::getVoltageLevelId); } - private AttributeModification getBusOrBusbarSectionId(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getBusOrBusbarSectionId(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getBusOrBusbarSectionId1, BranchModificationInfos::getBusOrBusbarSectionId2, InjectionModificationInfos::getBusOrBusbarSectionId); } @@ -828,46 +821,77 @@ private AttributeModification getEquipmentId(BasicEquipmentModificationI return AttributeModification.toAttributeModification(modificationInfos.getEquipmentId(), OperationType.SET); } - private AttributeModification getConnectionName(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getConnectionName(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getConnectionName1, BranchModificationInfos::getConnectionName2, InjectionModificationInfos::getConnectionName); } - private String getConnectionNameField(int feederNumber) { - return getConnectionFieldName(feederNumber, CONNECTION_NAME_FIELD_NAME); + private String getConnectionNameField(FeederSide feederSide) { + return getConnectionFieldName(feederSide, CONNECTION_NAME_FIELD_NAME); } - private String getConnectionDirectionField(int feederNumber) { - return getConnectionFieldName(feederNumber, CONNECTION_DIRECTION_FIELD_NAME); + private String getConnectionDirectionField(FeederSide feederSide) { + return getConnectionFieldName(feederSide, CONNECTION_DIRECTION_FIELD_NAME); } - private String getConnectionPositionField(int feederNumber) { - return getConnectionFieldName(feederNumber, CONNECTION_POSITION_FIELD_NAME); + private String getConnectionPositionField(FeederSide feederSide) { + return getConnectionFieldName(feederSide, CONNECTION_POSITION_FIELD_NAME); } - private AttributeModification getConnectionDirection(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getConnectionDirection(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getConnectionDirection1, BranchModificationInfos::getConnectionDirection2, InjectionModificationInfos::getConnectionDirection); } - private AttributeModification getConnectionPosition(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getConnectionPosition(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getConnectionPosition1, BranchModificationInfos::getConnectionPosition2, InjectionModificationInfos::getConnectionPosition); } + private String getBusOrBusbarSection(Terminal terminal) { + String busOrBusbarSectionId; + if (terminal.getVoltageLevel().getTopologyKind().equals(TopologyKind.BUS_BREAKER)) { + if (terminal.isConnected()) { + busOrBusbarSectionId = terminal.getBusBreakerView().getBus().getId(); + } else { + busOrBusbarSectionId = terminal.getBusBreakerView().getConnectableBus().getId(); + } + } else { + busOrBusbarSectionId = getBusbarSectionId(terminal); + } + return busOrBusbarSectionId; + } + + private String getBusbarSectionId(Terminal terminal) { + BusbarSectionFinderTraverser connectedBusbarSectionFinder = new BusbarSectionFinderTraverser(terminal.isConnected()); + terminal.traverse(connectedBusbarSectionFinder, TraversalType.BREADTH_FIRST); + return connectedBusbarSectionFinder.getFirstTraversedBbsId(); + } + private int getPosition(AttributeModification connectionPosition, AttributeModification busOrBusbarSectionId, - Network network, - AttributeModification voltageLevelId) { - return getPosition( - connectionPosition == null ? null : connectionPosition.getValue(), - busOrBusbarSectionId == null ? null : busOrBusbarSectionId.getValue(), - network, - getVoltageLevel(network, voltageLevelId == null ? null : voltageLevelId.getValue()) - ); + AttributeModification voltageLevelId, + AttributeModification equipmentId, + FeederSide feederSide, + Network network) { + String equipmentValue = equipmentId.getValue(); + Terminal selectedTerminal = null; + switch (feederSide) { + case INJECTION_SINGLE_SIDE -> selectedTerminal = network.getIdentifiable(equipmentValue) instanceof Injection injection ? injection.getTerminal() : null; + case BRANCH_SIDE_ONE -> selectedTerminal = network.getIdentifiable(equipmentValue) instanceof Branch branch ? branch.getTerminal1() : null; + case BRANCH_SIDE_TWO -> selectedTerminal = network.getIdentifiable(equipmentValue) instanceof Branch branch ? branch.getTerminal2() : null; + } + String voltageLevel = (voltageLevelId != null && voltageLevelId.getValue() != null) + ? voltageLevelId.getValue() + : Optional.ofNullable(selectedTerminal).map(terminal -> terminal.getVoltageLevel().getId()).orElse(null); + String busOrBusbarSection = (busOrBusbarSectionId != null && busOrBusbarSectionId.getValue() != null) + ? busOrBusbarSectionId.getValue() + : Optional.ofNullable(selectedTerminal).map(this::getBusOrBusbarSection).orElse(null); + Integer connectionPositionValue = (connectionPosition != null) ? connectionPosition.getValue() : null; + return getPosition(connectionPositionValue, busOrBusbarSection, network, getVoltageLevel(network, voltageLevel)); } private void modifyConnection(AttributeModification terminalConnected, Identifiable equipment, Terminal terminal, List reports) { diff --git a/src/test/java/org/gridsuite/modification/server/modifications/GeneratorModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/GeneratorModificationTest.java index b9841d3f3..b110a1070 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/GeneratorModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/GeneratorModificationTest.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.ActivePowerControl; +import com.powsybl.iidm.network.extensions.ConnectablePosition; import com.powsybl.iidm.network.extensions.GeneratorShortCircuit; import com.powsybl.iidm.network.extensions.GeneratorStartup; import lombok.SneakyThrows; @@ -24,6 +25,8 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.IntStream; +import static org.gridsuite.modification.server.utils.NetworkUtil.*; +import static org.gridsuite.modification.server.utils.NetworkUtil.createGeneratorOnBus; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; import static org.junit.Assert.assertNull; @@ -50,6 +53,9 @@ protected ModificationInfos buildModification() { .equipmentName(new AttributeModification<>("newV1Generator", OperationType.SET)) .voltageLevelId(new AttributeModification<>("v2", OperationType.SET)) .busOrBusbarSectionId(new AttributeModification<>("1B", OperationType.SET)) + .connectionName(new AttributeModification<>("idGenerator", OperationType.SET)) + .connectionPosition(new AttributeModification<>(1, OperationType.SET)) + .connectionDirection(new AttributeModification<>(ConnectablePosition.Direction.TOP, OperationType.SET)) .targetP(new AttributeModification<>(80.0, OperationType.SET)) .targetQ(new AttributeModification<>(40.0, OperationType.SET)) .targetV(new AttributeModification<>(48.0, OperationType.SET)) @@ -445,6 +451,24 @@ public void testUnsetAttributes() throws Exception { } + @Test + public void changeGeneratorOnBusBreakerWithoutBusBarSection() throws Exception { + VoltageLevel v1 = createVoltageLevel(getNetwork().getSubstation("s1"), "v11", "v32", TopologyKind.BUS_BREAKER, 380.0); + createBusBarSection(getNetwork().getVoltageLevel("v1"), "1.7", "1.7", 0); + createBus(v1, "bus111", "bus111"); + createGeneratorOnBus(v1, "idGenerator1", "bus111", 42.1, 1.0); + GeneratorModificationInfos generatorModificationInfos = GeneratorModificationInfos.builder() + .stashed(false) + .equipmentId("idGenerator1") + .connectionPosition(new AttributeModification<>(1, OperationType.SET)) + .build(); + String generatorModificationInfosJson = mapper.writeValueAsString(generatorModificationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(generatorModificationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + generatorModificationInfos = (GeneratorModificationInfos) modificationRepository.getModifications(getGroupId(), false, true).get(0); + assertEquals(1, generatorModificationInfos.getConnectionPosition().getValue()); + } + @Override @SneakyThrows protected void testCreationModificationMessage(ModificationInfos modificationInfos) { diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java index 109581464..e5288c4f4 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java @@ -445,4 +445,22 @@ public void changeLineConnectablePosition() throws Exception { assertEquals(1, createdModification.getConnectionPosition2().getValue()); } + + @Test + public void changeLineConnectablePositionWithoutBusBarSection() throws Exception { + LineModificationInfos lineModificationInfos = LineModificationInfos.builder() + .stashed(false) + .equipmentId("line3") + .equipmentName(new AttributeModification<>("LineModified", OperationType.SET)) + .connectionName1(new AttributeModification<>("line3", OperationType.SET)) + .connectionName2(new AttributeModification<>("line3", OperationType.SET)) + .build(); + String modificationInfosJson = mapper.writeValueAsString(lineModificationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(modificationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + LineModificationInfos createdModification = (LineModificationInfos) modificationRepository.getModifications(getGroupId(), false, true).get(0); + assertEquals("line3", createdModification.getConnectionName1().getValue()); + assertEquals("line3", createdModification.getConnectionName2().getValue()); + + } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java index efd3a20a0..c395fafd1 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java @@ -602,7 +602,7 @@ public void testChangeConnectionStatus() { changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.ONE, true, true, null); changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.ONE, true, false, null); changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.TWO, true, true, null); - changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.TWO, true, false, "Could not disconnect equipment 'trf2' on side TWO"); + changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.TWO, true, false, "Could not disconnect equipment 'trf2'"); } @SneakyThrows From c3eae6504af0a6c11d3451053100c318d3ba3405 Mon Sep 17 00:00:00 2001 From: Ghazoua Rehili Date: Fri, 18 Oct 2024 17:07:02 +0200 Subject: [PATCH 2/2] add reporting for limits and setpoints modification cspr (#550) Signed-off-by: REHILI Ghazwa --- .../StaticVarCompensatorCreation.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java index bc99bbaa3..105ca92c9 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java @@ -125,7 +125,7 @@ private void addExtensionsToStaticVarCompensator(StaticVarCompensatorCreationInf } reportInjectionCreationConnectivity(staticVarCompensatorCreationInfos, subReportNode); - createStaticVarCompensatorVoltageRegulation(staticVarCompensatorCreationInfos, staticVarCompensator, voltageLevel, subReportNode); + createStaticVarCompensatorLimitsAndSetpoints(staticVarCompensatorCreationInfos, staticVarCompensator, voltageLevel, subReportNode); reportStaticVarCompensatorStandbyAutomaton(staticVarCompensatorCreationInfos, staticVarCompensator, subReportNode); } @@ -195,13 +195,18 @@ private void createStaticVarCompensatorInBusBreaker(VoltageLevel voltageLevel, S addExtensionsToStaticVarCompensator(staticVarCompensatorCreationInfos, staticVarCompensator, voltageLevel, subReportNode); } - private void createStaticVarCompensatorVoltageRegulation(StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos, - StaticVarCompensator staticVarCompensator, VoltageLevel voltageLevel, ReportNode subReportNode) { + private void createStaticVarCompensatorLimitsAndSetpoints(StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos, + StaticVarCompensator staticVarCompensator, VoltageLevel voltageLevel, ReportNode subReportNode) { List voltageReports = new ArrayList<>(); + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMinSusceptance(), "Susceptance min")); + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMaxSusceptance(), "Susceptance max")); + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMinQAtNominalV(), "Q min at nominal voltage")); + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMaxQAtNominalV(), "Q max at nominal voltage")); + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getVoltageSetpoint(), "Voltage set point")); + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getReactivePowerSetpoint(), "Reactive power set point")); voltageReports.add(ModificationUtils.getInstance() .createEnabledDisabledReport("VoltageRegulationOn", modificationInfos.getVoltageRegulationType() == VoltageRegulationType.DISTANT && modificationInfos.getRegulationMode() == StaticVarCompensator.RegulationMode.VOLTAGE)); - voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getVoltageSetpoint(), "Voltage set point")); if (staticVarCompensatorCreationInfos.getRegulatingTerminalVlId() != null && staticVarCompensatorCreationInfos.getRegulatingTerminalId() != null && staticVarCompensatorCreationInfos.getRegulatingTerminalType() != null) { Terminal terminal = ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(), @@ -212,7 +217,7 @@ private void createStaticVarCompensatorVoltageRegulation(StaticVarCompensatorCre updateCompensatorRegulatingTerminal(staticVarCompensatorCreationInfos, staticVarCompensator, terminal, voltageReports); } } - ModificationUtils.getInstance().reportModifications(subReportNode, voltageReports, "VoltageRegulationCreated", "Voltage regulation"); + ModificationUtils.getInstance().reportModifications(subReportNode, voltageReports, "LimitsAndSetpointsCreated", "Limits and Setpoints"); } private void updateCompensatorRegulatingTerminal(StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos, StaticVarCompensator staticVarCompensator,