From 0c28e4d096eadebde1b6ea6a50a7ab386ccf7de2 Mon Sep 17 00:00:00 2001 From: Franck LECUYER Date: Tue, 17 Sep 2024 14:12:26 +0200 Subject: [PATCH 1/3] 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 - } } From 9a482830e83ae6089fd7d02175fe9ec34302a53f Mon Sep 17 00:00:00 2001 From: Franck LECUYER Date: Tue, 17 Sep 2024 14:26:09 +0200 Subject: [PATCH 2/3] Fix sonar issue (remove useless 'leg' field in ThreeWindingsTransformerToInjectionAttributesAdapter class) Signed-off-by: Franck LECUYER --- .../store/iidm/impl/ThreeWindingsTransformerImpl.java | 6 +++--- ...ndingsTransformerToInjectionAttributesAdapter.java | 11 +---------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerImpl.java index caff7c25a..72191777e 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerImpl.java @@ -439,9 +439,9 @@ public void cancelSelectedOperationalLimitsGroup() { leg2 = new LegImpl(this, ThreeWindingsTransformerAttributes::getLeg2, index); leg3 = new LegImpl(this, ThreeWindingsTransformerAttributes::getLeg3, index); - terminal1 = new TerminalImpl<>(index, this, r -> new ThreeWindingsTransformerToInjectionAttributesAdapter(leg1, r.getAttributes(), ThreeSides.ONE)); - terminal2 = new TerminalImpl<>(index, this, r -> new ThreeWindingsTransformerToInjectionAttributesAdapter(leg2, r.getAttributes(), ThreeSides.TWO)); - terminal3 = new TerminalImpl<>(index, this, r -> new ThreeWindingsTransformerToInjectionAttributesAdapter(leg3, r.getAttributes(), ThreeSides.THREE)); + terminal1 = new TerminalImpl<>(index, this, r -> new ThreeWindingsTransformerToInjectionAttributesAdapter(r.getAttributes(), ThreeSides.ONE)); + terminal2 = new TerminalImpl<>(index, this, r -> new ThreeWindingsTransformerToInjectionAttributesAdapter(r.getAttributes(), ThreeSides.TWO)); + terminal3 = new TerminalImpl<>(index, this, r -> new ThreeWindingsTransformerToInjectionAttributesAdapter(r.getAttributes(), ThreeSides.THREE)); } static ThreeWindingsTransformerImpl create(NetworkObjectIndex index, Resource resource) { 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 0053eafe1..c1227b8ea 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 @@ -11,20 +11,15 @@ import com.powsybl.network.store.model.LegAttributes; import com.powsybl.network.store.model.ThreeWindingsTransformerAttributes; -import java.util.Objects; - /** * @author Geoffroy Jamgotchian */ public class ThreeWindingsTransformerToInjectionAttributesAdapter extends AbstractIdentifiableToInjectionAttributesAdapter { - private final ThreeWindingsTransformerImpl.LegImpl leg; - private final ThreeSides side; - public ThreeWindingsTransformerToInjectionAttributesAdapter(ThreeWindingsTransformerImpl.LegImpl leg, ThreeWindingsTransformerAttributes attributes, ThreeSides side) { + public ThreeWindingsTransformerToInjectionAttributesAdapter(ThreeWindingsTransformerAttributes attributes, ThreeSides side) { super(attributes); - this.leg = Objects.requireNonNull(leg); this.side = side; } @@ -37,7 +32,6 @@ private LegAttributes getLegAttributes() { case ONE -> attributes.getLeg1(); case TWO -> attributes.getLeg2(); case THREE -> attributes.getLeg3(); - default -> throw createUnknownSideException(); }; } @@ -87,7 +81,6 @@ public double getP() { case ONE -> attributes.getP1(); case TWO -> attributes.getP2(); case THREE -> attributes.getP3(); - default -> throw createUnknownSideException(); }; } @@ -107,7 +100,6 @@ public double getQ() { case ONE -> attributes.getQ1(); case TWO -> attributes.getQ2(); case THREE -> attributes.getQ3(); - default -> throw createUnknownSideException(); }; } @@ -127,7 +119,6 @@ public ConnectablePositionAttributes getPosition() { case ONE -> attributes.getPosition1(); case TWO -> attributes.getPosition2(); case THREE -> attributes.getPosition3(); - default -> throw createUnknownSideException(); }; } From 7f579798ef4ea280accf84f60d5bf4f114043701 Mon Sep 17 00:00:00 2001 From: Franck LECUYER Date: Thu, 26 Sep 2024 14:09:33 +0200 Subject: [PATCH 3/3] Add early check on terminal already connected Signed-off-by: Franck LECUYER --- .../com/powsybl/network/store/iidm/impl/TerminalImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 16e74c415..565595f82 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 @@ -225,7 +225,7 @@ boolean getConnectingSwitches(Predicate isSwitchOperable, Set isTypeSwitchToOperate) { // Set of switches that are to be closed Set switchesToClose = new HashSet<>(); + if (isConnected()) { + return false; + } + // Get the list of switches to open if (getConnectingSwitches(isTypeSwitchToOperate, switchesToClose)) { // Open the switches