From 0c28e4d096eadebde1b6ea6a50a7ab386ccf7de2 Mon Sep 17 00:00:00 2001 From: Franck LECUYER Date: Tue, 17 Sep 2024 14:12:26 +0200 Subject: [PATCH] Add begin/end connect/disconnect notifications in TerminalImpl connect/disconnect Remove some bus changing notifications Remove double call to opening/closing switches Fix bad return value of getConnectingSwitches method in TerminalImpl Signed-off-by: Franck LECUYER --- .../BranchToInjectionAttributesAdapter.java | 4 -- .../network/store/iidm/impl/TerminalImpl.java | 39 +++++++------------ ...ansformerToInjectionAttributesAdapter.java | 2 - .../impl/tck/ConnectionNotificationTest.java | 9 ----- 4 files changed, 15 insertions(+), 39 deletions(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BranchToInjectionAttributesAdapter.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BranchToInjectionAttributesAdapter.java index 9aa2ac0b5..98864175f 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BranchToInjectionAttributesAdapter.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BranchToInjectionAttributesAdapter.java @@ -63,13 +63,9 @@ public String getBus() { @Override public void setBus(String bus) { if (side1) { - String oldValue = attributes.getBus1(); attributes.setBus1(bus); - branch.notifyUpdate("bus1", oldValue, bus, true); } else { - String oldValue = attributes.getBus2(); attributes.setBus2(bus); - branch.notifyUpdate("bus2", oldValue, bus, true); } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java index 31a52ee4f..16e74c415 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java @@ -19,16 +19,11 @@ import java.util.function.Predicate; import java.util.stream.Collectors; -import static com.powsybl.network.store.iidm.impl.ConnectDisconnectUtil.closeSwitches; -import static com.powsybl.network.store.iidm.impl.ConnectDisconnectUtil.openSwitches; - /** * @author Geoffroy Jamgotchian */ public class TerminalImpl implements Terminal, Validable { - private static final Set CONNECTABLE_WITH_SIDES_TYPES = Set.of(IdentifiableType.LINE, IdentifiableType.TWO_WINDINGS_TRANSFORMER, IdentifiableType.THREE_WINDINGS_TRANSFORMER); - private final NetworkObjectIndex index; private final Connectable connectable; @@ -230,7 +225,7 @@ boolean getConnectingSwitches(Predicate isSwitchOperable, Set isTypeSwitchToOperate) { return false; } - // The switches are now closed - closeSwitches(index, switchesToClose); - return true; } @@ -261,12 +253,8 @@ protected void connectBusBreaker() { a.setBus(a.getConnectableBus()); // Notification to the listeners - index.notifyUpdate(getConnectable(), "connected", index.getNetwork().getVariantManager().getWorkingVariantId(), false, true); - - // Notification for branches (with sides) is made in the injection attributes adapters (setBus) - if (!CONNECTABLE_WITH_SIDES_TYPES.contains(getConnectable().getType())) { - index.notifyUpdate(getConnectable(), "bus", null, a.getConnectableBus()); - } + String side = Terminal.getConnectableSide(this).map(s -> Integer.toString(s.getNum())).orElse(""); + index.notifyUpdate(getConnectable(), "connected" + side, index.getNetwork().getVariantManager().getWorkingVariantId(), false, true); }); } @@ -284,6 +272,8 @@ public boolean connect(Predicate isTypeSwitchToOperate) { try { Resource voltageLevelResource = getVoltageLevelResource(); VoltageLevelAttributes voltageLevelAttributes = voltageLevelResource.getAttributes(); + boolean connectedBefore = isConnected(); + index.notifyUpdate(getConnectable(), "beginConnect", index.getNetwork().getVariantManager().getWorkingVariantId(), connectedBefore, null); if (isNodeBeakerTopologyKind()) { if (connectNodeBreaker(isTypeSwitchToOperate)) { done = true; @@ -296,6 +286,9 @@ public boolean connect(Predicate isTypeSwitchToOperate) { } } + boolean connectedAfter = isConnected(); + index.notifyUpdate(getConnectable(), "endConnect", index.getNetwork().getVariantManager().getWorkingVariantId(), null, connectedAfter); + if (done) { // to invalidate calculated buses voltageLevelAttributes.setCalculatedBusesValid(false); @@ -402,9 +395,6 @@ private boolean disconnectNodeBreaker(Predicate isSwitchOpenable) { return false; } - // The switches are now opened - openSwitches(index, switchesToOpen); - return true; } @@ -416,12 +406,8 @@ protected boolean disconnectBusBreaker() { a.setBus(null); // Notification to the listeners - index.notifyUpdate(getConnectable(), "connected", index.getNetwork().getVariantManager().getWorkingVariantId(), true, false); - - // Notification for branches (with sides) is made in the injection attributes adapters (setBus) - if (!CONNECTABLE_WITH_SIDES_TYPES.contains(getConnectable().getType())) { - index.notifyUpdate(getConnectable(), "bus", a.getConnectableBus(), null); - } + String side = Terminal.getConnectableSide(this).map(s -> Integer.toString(s.getNum())).orElse(""); + index.notifyUpdate(getConnectable(), "connected" + side, index.getNetwork().getVariantManager().getWorkingVariantId(), true, false); }); return true; } @@ -442,6 +428,8 @@ public boolean disconnect(Predicate isSwitchOpenable) { try { Resource voltageLevelResource = getVoltageLevelResource(); VoltageLevelAttributes voltageLevelAttributes = voltageLevelResource.getAttributes(); + boolean disconnectedBefore = !isConnected(); + index.notifyUpdate(getConnectable(), "beginDisconnect", index.getNetwork().getVariantManager().getWorkingVariantId(), disconnectedBefore, null); if (isNodeBeakerTopologyKind()) { if (disconnectNodeBreaker(isSwitchOpenable)) { done = true; @@ -452,6 +440,9 @@ public boolean disconnect(Predicate isSwitchOpenable) { } } + boolean disconnectedAfter = !isConnected(); + index.notifyUpdate(getConnectable(), "endDisconnect", index.getNetwork().getVariantManager().getWorkingVariantId(), null, disconnectedAfter); + if (done) { // to invalidate calculated buses voltageLevelAttributes.setCalculatedBusesValid(false); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerToInjectionAttributesAdapter.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerToInjectionAttributesAdapter.java index c2e548fea..0053eafe1 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerToInjectionAttributesAdapter.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerToInjectionAttributesAdapter.java @@ -68,9 +68,7 @@ public String getBus() { @Override public void setBus(String bus) { - String oldValue = getLegAttributes().getBus(); getLegAttributes().setBus(bus); - leg.notifyUpdate("bus", oldValue, bus); } @Override diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/ConnectionNotificationTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/ConnectionNotificationTest.java index 8de4a54ea..6f5b5e51a 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/ConnectionNotificationTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/ConnectionNotificationTest.java @@ -12,13 +12,4 @@ * @author Franck Lecuyer */ public class ConnectionNotificationTest extends AbstractConnectionNotificationTest { - @Override - public void busBreakerTest() { - // FIXME remove this test when we have the same update notifications as the core impl when disconnecting terminals : beginDisconnect and endDisconnect - } - - @Override - public void nodeBreakerTest() { - // FIXME remove this test when we have the same update notifications as the core impl when disconnecting terminals : beginDisconnect and endDisconnect - } }