From 6a36137120e635832cb8e327050cf1610a170673 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Mon, 27 Nov 2023 16:19:26 +0100 Subject: [PATCH 01/27] Adaptat Signed-off-by: Nicolas Rol --- .../client/BufferedNetworkStoreClient.java | 16 +- .../network/store/client/RestClientImpl.java | 12 +- .../store/client/RestNetworkStoreClient.java | 8 +- .../client/RestNetworkStoreClientTest.java | 28 +- network-store-iidm-impl/pom.xml | 4 + .../store/iidm/impl/AbstractBranchImpl.java | 150 +++----- .../store/iidm/impl/AbstractTopology.java | 141 +++---- .../network/store/iidm/impl/BaseBus.java | 16 +- .../iidm/impl/CachedNetworkStoreClient.java | 10 +- .../store/iidm/impl/CalculatedBus.java | 4 +- .../iidm/impl/DanglingLineBoundaryImpl.java | 8 +- .../powsybl/network/store/iidm/impl/Edge.java | 8 +- .../network/store/iidm/impl/HvdcLineImpl.java | 15 +- .../store/iidm/impl/NetworkFactoryImpl.java | 4 +- .../network/store/iidm/impl/NetworkImpl.java | 27 +- .../store/iidm/impl/SwitchPathValidator.java | 34 ++ .../network/store/iidm/impl/TerminalImpl.java | 353 ++++++++++-------- .../store/iidm/impl/TerminalRefUtils.java | 4 +- .../impl/ThreeWindingsTransformerImpl.java | 164 ++++++-- ...ansformerToInjectionAttributesAdapter.java | 6 +- .../network/store/iidm/impl/TieLineImpl.java | 54 +-- .../store/iidm/impl/VoltageLevelImpl.java | 28 +- .../impl/extensions/CgmesControlAreaImpl.java | 2 +- .../network/store/iidm/impl/BoundaryTest.java | 2 +- .../store/iidm/impl/CreateNetworksUtil.java | 34 +- .../network/store/iidm/impl/LineTest.java | 68 ++-- .../iidm/impl/tck/CurrentLimitsTest.java | 15 + .../store/iidm/impl/tck/MergeNetworkTest.java | 10 +- network-store-model/pom.xml | 9 +- .../network/store/model/LimitHolder.java | 37 +- .../store/model/NetworkAttributes.java | 8 +- .../ThreeWindingsTransformerAttributes.java | 4 +- .../network/store/model/ResourceTest.java | 20 +- pom.xml | 8 + 34 files changed, 739 insertions(+), 572 deletions(-) create mode 100644 network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchPathValidator.java diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedNetworkStoreClient.java index 77625b6d8..feb1025a2 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedNetworkStoreClient.java @@ -6,19 +6,23 @@ */ package com.powsybl.network.store.client; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.joda.JodaModule; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.google.common.base.Stopwatch; import com.powsybl.commons.json.JsonUtil; import com.powsybl.network.store.client.util.ExecutorUtil; import com.powsybl.network.store.iidm.impl.AbstractForwardingNetworkStoreClient; -import com.powsybl.network.store.model.AttributeFilter; import com.powsybl.network.store.iidm.impl.NetworkCollectionIndex; import com.powsybl.network.store.model.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.UUID; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -562,8 +566,10 @@ private static void cloneBuffer(NetworkCollec public void cloneNetwork(UUID networkUuid, int sourceVariantNum, int targetVariantNum, String targetVariantId) { delegate.cloneNetwork(networkUuid, sourceVariantNum, targetVariantNum, targetVariantId); - var objectMapper = JsonUtil.createObjectMapper(); - objectMapper.registerModule(new JodaModule()); + var objectMapper = JsonUtil.createObjectMapper() + .registerModule(new JavaTimeModule()) + .configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false) + .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); //can't use allBuffers because of generics compile error... cloneBuffer(switchResourcesToFlush, networkUuid, sourceVariantNum, targetVariantNum, objectMapper); diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java index d4fe3e319..b8515c232 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java @@ -6,9 +6,12 @@ */ package com.powsybl.network.store.client; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.joda.JodaModule; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.powsybl.commons.PowsyblException; +import com.powsybl.commons.json.JsonUtil; import com.powsybl.network.store.model.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.client.RestTemplateBuilder; @@ -45,9 +48,10 @@ public static RestTemplateBuilder createRestTemplateBuilder(String baseUri) { } private static ObjectMapper createObjectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JodaModule()); - return objectMapper; + return JsonUtil.createObjectMapper() + .registerModule(new JavaTimeModule()) + .configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false) + .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); } private static MappingJackson2HttpMessageConverter createMapping() { diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java index c1391a83e..7bde64d98 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java @@ -7,11 +7,15 @@ package com.powsybl.network.store.client; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.joda.JodaModule; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; import com.powsybl.commons.PowsyblException; +import com.powsybl.commons.json.JsonUtil; import com.powsybl.network.store.model.AttributeFilter; import com.powsybl.network.store.iidm.impl.NetworkStoreClient; import com.powsybl.network.store.model.*; @@ -47,7 +51,9 @@ public RestNetworkStoreClient(RestClient restClient) { public RestNetworkStoreClient(RestClient restClient, ObjectMapper objectMapper) { this.restClient = Objects.requireNonNull(restClient); this.objectMapper = Objects.requireNonNull(objectMapper); - objectMapper.registerModule(new JodaModule()); + objectMapper.registerModule(new JavaTimeModule()) + .configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false) + .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); } diff --git a/network-store-client/src/test/java/com/powsybl/network/store/client/RestNetworkStoreClientTest.java b/network-store-client/src/test/java/com/powsybl/network/store/client/RestNetworkStoreClientTest.java index a5612fbd1..5644a52b3 100644 --- a/network-store-client/src/test/java/com/powsybl/network/store/client/RestNetworkStoreClientTest.java +++ b/network-store-client/src/test/java/com/powsybl/network/store/client/RestNetworkStoreClientTest.java @@ -7,16 +7,15 @@ package com.powsybl.network.store.client; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.joda.JodaModule; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.google.common.collect.ImmutableList; import com.powsybl.commons.PowsyblException; import com.powsybl.iidm.network.*; import com.powsybl.network.store.model.*; -import com.powsybl.network.store.model.ErrorObject; - import org.hamcrest.Matchers; -import org.joda.time.DateTime; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -28,23 +27,20 @@ import org.springframework.test.web.client.MockRestServiceServer; import java.io.IOException; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.Assert.assertNotNull; -import static org.springframework.http.HttpMethod.GET; -import static org.springframework.http.HttpMethod.PUT; -import static org.springframework.http.HttpMethod.POST; +import static org.springframework.http.HttpMethod.*; import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; import static org.springframework.test.web.client.response.MockRestResponseCreators.withBadRequest; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; /** * @author Geoffroy Jamgotchian @@ -65,17 +61,19 @@ public class RestNetworkStoreClientTest { @Autowired private ObjectMapper objectMapper; - private UUID networkUuid = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); + private final UUID networkUuid = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); @Before public void setUp() throws IOException { - objectMapper.registerModule(new JodaModule()); + objectMapper.registerModule(new JavaTimeModule()) + .configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false) + .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); Resource n1 = Resource.networkBuilder() .id("n1") .attributes(NetworkAttributes.builder() .uuid(networkUuid) .variantId(VariantManagerConstants.INITIAL_VARIANT_ID) - .caseDate(DateTime.parse("2015-01-01T00:00:00.000Z")) + .caseDate(ZonedDateTime.parse("2015-01-01T00:00:00.000Z")) .build()) .build(); @@ -85,7 +83,7 @@ public void setUp() throws IOException { .attributes(NetworkAttributes.builder() .uuid(clonedNetworkUuid) .variantId(VariantManagerConstants.INITIAL_VARIANT_ID) - .caseDate(DateTime.parse("2015-01-01T00:00:00.000Z")) + .caseDate(ZonedDateTime.parse("2015-01-01T00:00:00.000Z")) .build()) .build(); diff --git a/network-store-iidm-impl/pom.xml b/network-store-iidm-impl/pom.xml index fda7c2814..04cfae489 100644 --- a/network-store-iidm-impl/pom.xml +++ b/network-store-iidm-impl/pom.xml @@ -27,6 +27,10 @@ + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + com.powsybl powsybl-entsoe-util diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchImpl.java index c991521a5..8baef9429 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchImpl.java @@ -23,7 +23,7 @@ * @author Etienne Homer */ public abstract class AbstractBranchImpl & Connectable, U extends BranchAttributes> extends AbstractIdentifiableImpl - implements Branch, Connectable, LimitsOwner { + implements Branch, Connectable, LimitsOwner { private final TerminalImpl terminal1; @@ -53,7 +53,7 @@ public TerminalImpl getTerminal2() { } @Override - public Terminal getTerminal(Branch.Side side) { + public Terminal getTerminal(TwoSides side) { switch (side) { case ONE: return terminal1; @@ -77,11 +77,11 @@ public Terminal getTerminal(String voltageLevelId) { } @Override - public Branch.Side getSide(Terminal terminal) { + public TwoSides getSide(Terminal terminal) { if (terminal == terminal1) { - return Branch.Side.ONE; + return TwoSides.ONE; } else if (terminal == terminal2) { - return Branch.Side.TWO; + return TwoSides.TWO; } else { throw new AssertionError(); } @@ -96,15 +96,15 @@ public void notifyUpdate(String attribute, Object oldValue, Object newValue, boo } @Override - public void setCurrentLimits(Branch.Side side, LimitsAttributes currentLimits) { + public void setCurrentLimits(TwoSides side, LimitsAttributes currentLimits) { var resource = getResource(); - if (side == Branch.Side.ONE) { + if (side == TwoSides.ONE) { LimitsAttributes oldCurrentLimits = resource.getAttributes().getCurrentLimits1(); if (currentLimits != oldCurrentLimits) { updateResource(res -> res.getAttributes().setCurrentLimits1(currentLimits)); index.notifyUpdate(this, "currentLimits1", oldCurrentLimits, currentLimits); } - } else if (side == Branch.Side.TWO) { + } else if (side == TwoSides.TWO) { LimitsAttributes oldCurrentLimits = resource.getAttributes().getCurrentLimits2(); if (currentLimits != oldCurrentLimits) { updateResource(res -> res.getAttributes().setCurrentLimits2(currentLimits)); @@ -120,38 +120,34 @@ public AbstractIdentifiableImpl getIdentifiable() { @Override public CurrentLimitsAdder newCurrentLimits1() { - return new CurrentLimitsAdderImpl<>(Branch.Side.ONE, this); + return new CurrentLimitsAdderImpl<>(TwoSides.ONE, this); } @Override public CurrentLimitsAdder newCurrentLimits2() { - return new CurrentLimitsAdderImpl<>(Branch.Side.TWO, this); + return new CurrentLimitsAdderImpl<>(TwoSides.TWO, this); } @Override public ApparentPowerLimitsAdder newApparentPowerLimits1() { - return new ApparentPowerLimitsAdderImpl<>(Branch.Side.ONE, this); + return new ApparentPowerLimitsAdderImpl<>(TwoSides.ONE, this); } @Override public ApparentPowerLimitsAdder newApparentPowerLimits2() { - return new ApparentPowerLimitsAdderImpl<>(Side.TWO, this); + return new ApparentPowerLimitsAdderImpl<>(TwoSides.TWO, this); } @Override - public ApparentPowerLimits getNullableApparentPowerLimits(Side side) { - switch (side) { - case ONE: - return getNullableApparentPowerLimits1(); - case TWO: - return getNullableApparentPowerLimits2(); - default: - throw new IllegalStateException(); - } + public ApparentPowerLimits getNullableApparentPowerLimits(TwoSides side) { + return switch (side) { + case ONE -> getNullableApparentPowerLimits1(); + case TWO -> getNullableApparentPowerLimits2(); + }; } @Override - public Optional getApparentPowerLimits(Side side) { + public Optional getApparentPowerLimits(TwoSides side) { return Optional.ofNullable(getNullableApparentPowerLimits(side)); } @@ -182,15 +178,15 @@ public Optional getApparentPowerLimits2() { } @Override - public void setApparentPowerLimits(Branch.Side side, LimitsAttributes apparentPowerLimitsAttributes) { + public void setApparentPowerLimits(TwoSides side, LimitsAttributes apparentPowerLimitsAttributes) { var resource = getResource(); - if (side == Branch.Side.ONE) { + if (side == TwoSides.ONE) { LimitsAttributes oldApparentPowerLimits = resource.getAttributes().getApparentPowerLimits1(); if (apparentPowerLimitsAttributes != oldApparentPowerLimits) { updateResource(res -> res.getAttributes().setApparentPowerLimits1(apparentPowerLimitsAttributes)); index.notifyUpdate(this, "apparentPowerLimits1", oldApparentPowerLimits, apparentPowerLimitsAttributes); } - } else if (side == Branch.Side.TWO) { + } else if (side == TwoSides.TWO) { LimitsAttributes oldApparentPowerLimits = resource.getAttributes().getApparentPowerLimits2(); if (apparentPowerLimitsAttributes != oldApparentPowerLimits) { updateResource(res -> res.getAttributes().setApparentPowerLimits2(apparentPowerLimitsAttributes)); @@ -201,28 +197,24 @@ public void setApparentPowerLimits(Branch.Side side, LimitsAttributes apparentPo @Override public ActivePowerLimitsAdder newActivePowerLimits1() { - return new ActivePowerLimitsAdderImpl<>(Branch.Side.ONE, this); + return new ActivePowerLimitsAdderImpl<>(TwoSides.ONE, this); } @Override public ActivePowerLimitsAdder newActivePowerLimits2() { - return new ActivePowerLimitsAdderImpl<>(Side.TWO, this); + return new ActivePowerLimitsAdderImpl<>(TwoSides.TWO, this); } @Override - public ActivePowerLimits getNullableActivePowerLimits(Side side) { - switch (side) { - case ONE: - return getNullableActivePowerLimits1(); - case TWO: - return getNullableActivePowerLimits2(); - default: - throw new IllegalStateException(); - } + public ActivePowerLimits getNullableActivePowerLimits(TwoSides side) { + return switch (side) { + case ONE -> getNullableActivePowerLimits1(); + case TWO -> getNullableActivePowerLimits2(); + }; } @Override - public Optional getActivePowerLimits(Side side) { + public Optional getActivePowerLimits(TwoSides side) { return Optional.ofNullable(getNullableActivePowerLimits(side)); } @@ -253,15 +245,15 @@ public Optional getActivePowerLimits2() { } @Override - public void setActivePowerLimits(Branch.Side side, LimitsAttributes activePowerLimitsAttributes) { + public void setActivePowerLimits(TwoSides side, LimitsAttributes activePowerLimitsAttributes) { var resource = getResource(); - if (side == Branch.Side.ONE) { + if (side == TwoSides.ONE) { LimitsAttributes oldActivePowerLimits = resource.getAttributes().getActivePowerLimits1(); if (activePowerLimitsAttributes != oldActivePowerLimits) { updateResource(res -> res.getAttributes().setActivePowerLimits1(activePowerLimitsAttributes)); index.notifyUpdate(this, "apparentPowerLimits1", oldActivePowerLimits, activePowerLimitsAttributes); } - } else if (side == Branch.Side.TWO) { + } else if (side == TwoSides.TWO) { LimitsAttributes oldActivePowerLimits = resource.getAttributes().getActivePowerLimits2(); if (activePowerLimitsAttributes != oldActivePowerLimits) { updateResource(res -> res.getAttributes().setActivePowerLimits2(activePowerLimitsAttributes)); @@ -271,19 +263,15 @@ public void setActivePowerLimits(Branch.Side side, LimitsAttributes activePowerL } @Override - public CurrentLimits getNullableCurrentLimits(Side side) { - switch (side) { - case ONE: - return getNullableCurrentLimits1(); - case TWO: - return getNullableCurrentLimits2(); - default: - throw new IllegalStateException(); - } + public CurrentLimits getNullableCurrentLimits(TwoSides side) { + return switch (side) { + case ONE -> getNullableCurrentLimits1(); + case TWO -> getNullableCurrentLimits2(); + }; } @Override - public Optional getCurrentLimits(Branch.Side side) { + public Optional getCurrentLimits(TwoSides side) { return Optional.ofNullable(getNullableCurrentLimits(side)); } @@ -325,34 +313,30 @@ public boolean isOverloaded(float limitReduction) { @Override public int getOverloadDuration() { - Branch.Overload o1 = checkTemporaryLimits1(LimitType.CURRENT); - Branch.Overload o2 = checkTemporaryLimits2(LimitType.CURRENT); + Overload o1 = checkTemporaryLimits1(LimitType.CURRENT); + Overload o2 = checkTemporaryLimits2(LimitType.CURRENT); int duration1 = o1 != null ? o1.getTemporaryLimit().getAcceptableDuration() : Integer.MAX_VALUE; int duration2 = o2 != null ? o2.getTemporaryLimit().getAcceptableDuration() : Integer.MAX_VALUE; return Math.min(duration1, duration2); } @Override - public Overload checkTemporaryLimits(Side side, LimitType type) { + public Overload checkTemporaryLimits(TwoSides side, LimitType type) { return this.checkTemporaryLimits(side, 1.0F, type); } @Override - public Overload checkTemporaryLimits(Side side, float limitReduction, LimitType type) { + public Overload checkTemporaryLimits(TwoSides side, float limitReduction, LimitType type) { Objects.requireNonNull(side); - switch (side) { - case ONE: - return this.checkTemporaryLimits1(limitReduction, type); - case TWO: - return this.checkTemporaryLimits2(limitReduction, type); - default: - throw new AssertionError(); - } + return switch (side) { + case ONE -> this.checkTemporaryLimits1(limitReduction, type); + case TWO -> this.checkTemporaryLimits2(limitReduction, type); + }; } @Override public Overload checkTemporaryLimits1(float limitReduction, LimitType type) { - return LimitViolationUtils.checkTemporaryLimits(this, Side.ONE, limitReduction, this.getValueForLimit(this.getTerminal1(), type), type); + return LimitViolationUtils.checkTemporaryLimits(this, TwoSides.ONE, limitReduction, this.getValueForLimit(this.getTerminal1(), type), type); } @Override @@ -362,7 +346,7 @@ public Overload checkTemporaryLimits1(LimitType type) { @Override public Overload checkTemporaryLimits2(float limitReduction, LimitType type) { - return LimitViolationUtils.checkTemporaryLimits(this, Side.TWO, limitReduction, this.getValueForLimit(this.getTerminal2(), type), type); + return LimitViolationUtils.checkTemporaryLimits(this, TwoSides.TWO, limitReduction, this.getValueForLimit(this.getTerminal2(), type), type); } @Override @@ -371,28 +355,22 @@ public Overload checkTemporaryLimits2(LimitType type) { } @Override - public boolean checkPermanentLimit(Side side, float limitReduction, LimitType type) { + public boolean checkPermanentLimit(TwoSides side, float limitReduction, LimitType type) { Objects.requireNonNull(side); - switch (side) { - case ONE: - return checkPermanentLimit1(limitReduction, type); - - case TWO: - return checkPermanentLimit2(limitReduction, type); - - default: - throw new AssertionError(); - } + return switch (side) { + case ONE -> checkPermanentLimit1(limitReduction, type); + case TWO -> checkPermanentLimit2(limitReduction, type); + }; } @Override - public boolean checkPermanentLimit(Side side, LimitType type) { + public boolean checkPermanentLimit(TwoSides side, LimitType type) { return checkPermanentLimit(side, 1f, type); } @Override public boolean checkPermanentLimit1(float limitReduction, LimitType type) { - return LimitViolationUtils.checkPermanentLimit(this, Side.ONE, limitReduction, getValueForLimit(getTerminal1(), type), type); + return LimitViolationUtils.checkPermanentLimit(this, TwoSides.ONE, limitReduction, getValueForLimit(getTerminal1(), type), type); } @Override @@ -402,7 +380,7 @@ public boolean checkPermanentLimit1(LimitType type) { @Override public boolean checkPermanentLimit2(float limitReduction, LimitType type) { - return LimitViolationUtils.checkPermanentLimit(this, Side.TWO, limitReduction, getValueForLimit(getTerminal2(), type), type); + return LimitViolationUtils.checkPermanentLimit(this, TwoSides.TWO, limitReduction, getValueForLimit(getTerminal2(), type), type); } @Override @@ -411,17 +389,13 @@ public boolean checkPermanentLimit2(LimitType type) { } public double getValueForLimit(Terminal t, LimitType type) { - switch (type) { - case ACTIVE_POWER: - return t.getP(); - case APPARENT_POWER: - return Math.sqrt(t.getP() * t.getP() + t.getQ() * t.getQ()); - case CURRENT: - return t.getI(); - case VOLTAGE: - default: + return switch (type) { + case ACTIVE_POWER -> t.getP(); + case APPARENT_POWER -> Math.sqrt(t.getP() * t.getP() + t.getQ() * t.getQ()); + case CURRENT -> t.getI(); + default -> throw new UnsupportedOperationException(String.format("Getting %s limits is not supported.", type.name())); - } + }; } private > E createConnectablePositionExtension() { diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTopology.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTopology.java index 507fc7a46..858d602b5 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTopology.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTopology.java @@ -11,7 +11,7 @@ import com.powsybl.network.store.model.*; import org.jgrapht.Graph; import org.jgrapht.alg.connectivity.ConnectivityInspector; -import org.jgrapht.graph.Pseudograph; +import org.jgrapht.graph.DirectedPseudograph; import java.util.*; import java.util.stream.Collectors; @@ -54,29 +54,13 @@ protected void count(Set nodesOrBusesConnected, Map> vertices private void count(Vertex vertex) { switch (vertex.getConnectableType()) { - case LINE: - case TWO_WINDINGS_TRANSFORMER: - case THREE_WINDINGS_TRANSFORMER: - case HVDC_CONVERTER_STATION: - case DANGLING_LINE: + case LINE, TWO_WINDINGS_TRANSFORMER, THREE_WINDINGS_TRANSFORMER, HVDC_CONVERTER_STATION, DANGLING_LINE -> { branchCount++; feederCount++; - break; - - case LOAD: - case GENERATOR: - case BATTERY: - case SHUNT_COMPENSATOR: - case STATIC_VAR_COMPENSATOR: - feederCount++; - break; - - case BUSBAR_SECTION: - busbarSectionCount++; - break; - - default: - throw new IllegalStateException(); + } + case LOAD, GENERATOR, BATTERY, SHUNT_COMPENSATOR, STATIC_VAR_COMPENSATOR -> feederCount++; + case BUSBAR_SECTION -> busbarSectionCount++; + default -> throw new IllegalStateException(); } } } @@ -84,33 +68,16 @@ private void count(Vertex vertex) { protected abstract T getInjectionNodeOrBus(Resource resource); private Vertex createVertexFromInjection(Resource resource) { - IdentifiableType connectableType; - switch (resource.getType()) { - case LOAD: - connectableType = IdentifiableType.LOAD; - break; - case GENERATOR: - connectableType = IdentifiableType.GENERATOR; - break; - case BATTERY: - connectableType = IdentifiableType.BATTERY; - break; - case SHUNT_COMPENSATOR: - connectableType = IdentifiableType.SHUNT_COMPENSATOR; - break; - case VSC_CONVERTER_STATION: - case LCC_CONVERTER_STATION: - connectableType = IdentifiableType.HVDC_CONVERTER_STATION; - break; - case STATIC_VAR_COMPENSATOR: - connectableType = IdentifiableType.STATIC_VAR_COMPENSATOR; - break; - case DANGLING_LINE: - connectableType = IdentifiableType.DANGLING_LINE; - break; - default: - throw new IllegalStateException("Resource is not an injection: " + resource.getType()); - } + IdentifiableType connectableType = switch (resource.getType()) { + case LOAD -> IdentifiableType.LOAD; + case GENERATOR -> IdentifiableType.GENERATOR; + case BATTERY -> IdentifiableType.BATTERY; + case SHUNT_COMPENSATOR -> IdentifiableType.SHUNT_COMPENSATOR; + case VSC_CONVERTER_STATION, LCC_CONVERTER_STATION -> IdentifiableType.HVDC_CONVERTER_STATION; + case STATIC_VAR_COMPENSATOR -> IdentifiableType.STATIC_VAR_COMPENSATOR; + case DANGLING_LINE -> IdentifiableType.DANGLING_LINE; + default -> throw new IllegalStateException("Resource is not an injection: " + resource.getType()); + }; T nodeOrBus = getInjectionNodeOrBus(resource); return nodeOrBus == null ? null : createVertex(resource.getId(), connectableType, nodeOrBus, null); } @@ -121,27 +88,21 @@ private Vertex createVertexFromInjection(Resourc private List createVertextFromBranch(Resource resource, Resource voltageLevelResource) { List vertices = new ArrayList<>(2); - IdentifiableType connectableType; - switch (resource.getType()) { - case LINE: - connectableType = IdentifiableType.LINE; - break; - case TWO_WINDINGS_TRANSFORMER: - connectableType = IdentifiableType.TWO_WINDINGS_TRANSFORMER; - break; - default: - throw new IllegalStateException("Resource is not a branch: " + resource.getType()); - } + IdentifiableType connectableType = switch (resource.getType()) { + case LINE -> IdentifiableType.LINE; + case TWO_WINDINGS_TRANSFORMER -> IdentifiableType.TWO_WINDINGS_TRANSFORMER; + default -> throw new IllegalStateException("Resource is not a branch: " + resource.getType()); + }; if (voltageLevelResource.getId().equals(resource.getAttributes().getVoltageLevelId1())) { T nodeOrBus = getBranchNodeOrBus1(resource); if (nodeOrBus != null) { - vertices.add(createVertex(resource.getId(), connectableType, nodeOrBus, Branch.Side.ONE.name())); + vertices.add(createVertex(resource.getId(), connectableType, nodeOrBus, TwoSides.ONE.name())); } } if (voltageLevelResource.getId().equals(resource.getAttributes().getVoltageLevelId2())) { T nodeOrBus = getBranchNodeOrBus2(resource); if (nodeOrBus != null) { - vertices.add(createVertex(resource.getId(), connectableType, nodeOrBus, Branch.Side.TWO.name())); + vertices.add(createVertex(resource.getId(), connectableType, nodeOrBus, TwoSides.TWO.name())); } } return vertices; @@ -158,19 +119,19 @@ private List createVertexFrom3wt(Resource buildGraph(NetworkObjectIndex index, Resource buildGraph(NetworkObjectIndex index, Resource voltageLevelResource, boolean includeOpenSwitches, boolean includeRetainSwitches, Map> verticesByNodeOrBus) { - Graph graph = new Pseudograph<>(Edge.class); + Graph graph = new DirectedPseudograph<>(Edge.class); List vertices = new ArrayList<>(); buildGraph(index, voltageLevelResource, includeOpenSwitches, includeRetainSwitches, graph, vertices); verticesByNodeOrBus.putAll(vertices.stream().collect(Collectors.groupingBy(this::getNodeOrBus))); @@ -284,6 +245,7 @@ protected void buildEdges(NetworkObjectIndex index, Resource + index.getBusbarSection(vertex.getId()).orElseThrow(IllegalStateException::new).getTerminal(); + case LINE -> + index.getLine(vertex.getId()).orElseThrow(IllegalStateException::new).getTerminal(TwoSides.valueOf(vertex.getSide())); + case TWO_WINDINGS_TRANSFORMER -> + index.getTwoWindingsTransformer(vertex.getId()).orElseThrow(IllegalStateException::new).getTerminal(TwoSides.valueOf(vertex.getSide())); + case THREE_WINDINGS_TRANSFORMER -> + index.getThreeWindingsTransformer(vertex.getId()).orElseThrow(IllegalStateException::new).getTerminal(ThreeSides.valueOf(vertex.getSide())); + case GENERATOR -> index.getGenerator(vertex.getId()).orElseThrow(IllegalStateException::new).getTerminal(); + case BATTERY -> index.getBattery(vertex.getId()).orElseThrow(IllegalStateException::new).getTerminal(); + case LOAD -> index.getLoad(vertex.getId()).orElseThrow(IllegalStateException::new).getTerminal(); + case SHUNT_COMPENSATOR -> + index.getShuntCompensator(vertex.getId()).orElseThrow(IllegalStateException::new).getTerminal(); + case DANGLING_LINE -> + index.getDanglingLine(vertex.getId()).orElseThrow(IllegalStateException::new).getTerminal(); + case STATIC_VAR_COMPENSATOR -> + index.getStaticVarCompensator(vertex.getId()).orElseThrow(IllegalStateException::new).getTerminal(); + case HVDC_CONVERTER_STATION -> + index.getHvdcConverterStation(vertex.getId()).orElseThrow(IllegalStateException::new).getTerminal(); + default -> throw new IllegalStateException("Connectable type not supported: " + vertex.getConnectableType()); - } + }; } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BaseBus.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BaseBus.java index 0257cb539..8991533e7 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BaseBus.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BaseBus.java @@ -119,8 +119,8 @@ private void visitEquipments(Iterable terminals, TopologyVis case LINE: Line line = (Line) connectable; - visitor.visitLine(line, line.getTerminal1() == terminal ? Branch.Side.ONE - : Branch.Side.TWO); + visitor.visitLine(line, line.getTerminal1() == terminal ? TwoSides.ONE + : TwoSides.TWO); break; case GENERATOR: @@ -139,19 +139,19 @@ private void visitEquipments(Iterable terminals, TopologyVis TwoWindingsTransformer twt = (TwoWindingsTransformer) connectable; visitor.visitTwoWindingsTransformer(twt, twt.getTerminal1() == terminal - ? Branch.Side.ONE - : Branch.Side.TWO); + ? TwoSides.ONE + : TwoSides.TWO); break; case THREE_WINDINGS_TRANSFORMER: ThreeWindingsTransformer thwt = (ThreeWindingsTransformer) connectable; - ThreeWindingsTransformer.Side side; + ThreeSides side; if (thwt.getLeg1().getTerminal() == terminal) { - side = ThreeWindingsTransformer.Side.ONE; + side = ThreeSides.ONE; } else if (thwt.getLeg2().getTerminal() == terminal) { - side = ThreeWindingsTransformer.Side.TWO; + side = ThreeSides.TWO; } else { - side = ThreeWindingsTransformer.Side.THREE; + side = ThreeSides.THREE; } visitor.visitThreeWindingsTransformer(thwt, side); break; diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CachedNetworkStoreClient.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CachedNetworkStoreClient.java index 8fa37f8ff..06eb07ff2 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CachedNetworkStoreClient.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CachedNetworkStoreClient.java @@ -6,8 +6,10 @@ */ package com.powsybl.network.store.iidm.impl; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.joda.JodaModule; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.powsybl.commons.json.JsonUtil; import com.powsybl.network.store.model.*; @@ -225,8 +227,10 @@ private static void cloneCollection(NetworkCo public void cloneNetwork(UUID networkUuid, int sourceVariantNum, int targetVariantNum, String targetVariantId) { delegate.cloneNetwork(networkUuid, sourceVariantNum, targetVariantNum, targetVariantId); - var objectMapper = JsonUtil.createObjectMapper(); - objectMapper.registerModule(new JodaModule()); + var objectMapper = JsonUtil.createObjectMapper() + .registerModule(new JavaTimeModule()) + .configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false) + .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); // clone each collection and re-assign variant number and id cloneCollection(switchesCache, networkUuid, sourceVariantNum, targetVariantNum, objectMapper); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CalculatedBus.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CalculatedBus.java index 43e4752e7..40a42c5fd 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CalculatedBus.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CalculatedBus.java @@ -212,9 +212,9 @@ public Collection getConnectedTerminals() { switch (c.getType()) { case LINE: case TWO_WINDINGS_TRANSFORMER: - return ((AbstractBranchImpl) c).getTerminal(Branch.Side.valueOf(v.getSide())); + return ((AbstractBranchImpl) c).getTerminal(TwoSides.valueOf(v.getSide())); case THREE_WINDINGS_TRANSFORMER: - return ((ThreeWindingsTransformerImpl) c).getTerminal(ThreeWindingsTransformer.Side.valueOf(v.getSide())); + return ((ThreeWindingsTransformerImpl) c).getTerminal(ThreeSides.valueOf(v.getSide())); default: return c.getTerminals().get(0); } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/DanglingLineBoundaryImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/DanglingLineBoundaryImpl.java index a44b6c7df..f0fcc19d1 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/DanglingLineBoundaryImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/DanglingLineBoundaryImpl.java @@ -22,7 +22,7 @@ public double getV() { } Terminal t = parent.getTerminal(); Bus b = t.getBusView().getBus(); - return new SV(t.getP(), t.getQ(), BaseBus.getV(b), BaseBus.getAngle(b), Branch.Side.ONE).otherSideU(parent, true); + return new SV(t.getP(), t.getQ(), BaseBus.getV(b), BaseBus.getAngle(b), TwoSides.ONE).otherSideU(parent, true); } @Override @@ -33,7 +33,7 @@ public double getAngle() { } Terminal t = parent.getTerminal(); Bus b = t.getBusView().getBus(); - return new SV(t.getP(), t.getQ(), BaseBus.getV(b), BaseBus.getAngle(b), Branch.Side.ONE).otherSideA(parent, true); + return new SV(t.getP(), t.getQ(), BaseBus.getV(b), BaseBus.getAngle(b), TwoSides.ONE).otherSideA(parent, true); } @Override @@ -43,7 +43,7 @@ public double getP() { } Terminal t = parent.getTerminal(); Bus b = t.getBusView().getBus(); - return new SV(t.getP(), t.getQ(), BaseBus.getV(b), BaseBus.getAngle(b), Branch.Side.ONE).otherSideP(parent, true); + return new SV(t.getP(), t.getQ(), BaseBus.getV(b), BaseBus.getAngle(b), TwoSides.ONE).otherSideP(parent, true); } @Override @@ -53,7 +53,7 @@ public double getQ() { } Terminal t = parent.getTerminal(); Bus b = t.getBusView().getBus(); - return new SV(t.getP(), t.getQ(), BaseBus.getV(b), BaseBus.getAngle(b), Branch.Side.ONE).otherSideQ(parent, true); + return new SV(t.getP(), t.getQ(), BaseBus.getV(b), BaseBus.getAngle(b), TwoSides.ONE).otherSideQ(parent, true); } @Override diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/Edge.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/Edge.java index 1ca9f25ec..bf776299e 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/Edge.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/Edge.java @@ -7,13 +7,16 @@ package com.powsybl.network.store.iidm.impl; import com.powsybl.network.store.model.NodeBreakerBiConnectable; +import lombok.Getter; +import org.jgrapht.graph.DefaultWeightedEdge; import java.util.Objects; /** * @author Geoffroy Jamgotchian */ -public class Edge { +@Getter +public class Edge extends DefaultWeightedEdge { private final NodeBreakerBiConnectable biConnectable; @@ -21,7 +24,4 @@ public Edge(NodeBreakerBiConnectable biConnectable) { this.biConnectable = Objects.requireNonNull(biConnectable); } - public NodeBreakerBiConnectable getBiConnectable() { - return biConnectable; - } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/HvdcLineImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/HvdcLineImpl.java index b742c7503..f3055c24c 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/HvdcLineImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/HvdcLineImpl.java @@ -9,6 +9,7 @@ import com.powsybl.commons.extensions.Extension; import com.powsybl.iidm.network.HvdcConverterStation; import com.powsybl.iidm.network.HvdcLine; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.iidm.network.ValidationUtil; import com.powsybl.iidm.network.extensions.HvdcAngleDroopActivePowerControl; import com.powsybl.iidm.network.extensions.HvdcOperatorActivePowerRange; @@ -57,15 +58,11 @@ public void remove() { } @Override - public HvdcConverterStation getConverterStation(Side side) { - switch (side) { - case ONE: - return getConverterStation1(); - case TWO: - return getConverterStation2(); - default: - throw new IllegalStateException("Unknown side: " + side); - } + public HvdcConverterStation getConverterStation(TwoSides side) { + return switch (side) { + case ONE -> getConverterStation1(); + case TWO -> getConverterStation2(); + }; } @Override diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkFactoryImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkFactoryImpl.java index 0baf99c03..a33b96641 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkFactoryImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkFactoryImpl.java @@ -11,8 +11,8 @@ import com.powsybl.iidm.network.VariantManagerConstants; import com.powsybl.network.store.model.NetworkAttributes; import com.powsybl.network.store.model.Resource; -import org.joda.time.DateTime; +import java.time.ZonedDateTime; import java.util.Collections; import java.util.Objects; import java.util.UUID; @@ -43,7 +43,7 @@ public Network createNetwork(String id, String sourceFormat) { .attributes(NetworkAttributes.builder() .uuid(networkUuid) .variantId(VariantManagerConstants.INITIAL_VARIANT_ID) - .caseDate(DateTime.now()) + .caseDate(ZonedDateTime.now()) .forecastDistance(0) .sourceFormat(sourceFormat) .build()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java index eb6819710..9fd0fc5a8 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java @@ -12,9 +12,8 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.commons.extensions.Extension; import com.powsybl.iidm.network.*; -import com.powsybl.cgmes.extensions.BaseVoltageMapping; +import com.powsybl.iidm.network.util.Networks; import com.powsybl.network.store.iidm.impl.extensions.BaseVoltageMappingImpl; -import com.powsybl.network.store.model.BaseVoltageMappingAttributes; import com.powsybl.network.store.iidm.impl.extensions.CgmesControlAreasImpl; import com.powsybl.network.store.iidm.impl.extensions.CgmesSshMetadataImpl; import com.powsybl.network.store.iidm.impl.extensions.CgmesSvMetadataImpl; @@ -23,8 +22,8 @@ import org.jgrapht.Graph; import org.jgrapht.alg.connectivity.ConnectivityInspector; import org.jgrapht.graph.Pseudograph; -import org.joda.time.DateTime; +import java.time.ZonedDateTime; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -45,6 +44,8 @@ public class NetworkImpl extends AbstractIdentifiableImpl listeners = new ArrayList<>(); + private AbstractReporterContext reporterContext; + public NetworkImpl(NetworkStoreClient storeClient, Resource resource) { super(new NetworkObjectIndex(storeClient), resource); index.setNetwork(this); @@ -188,12 +189,12 @@ public ContainerType getContainerType() { } @Override - public DateTime getCaseDate() { + public ZonedDateTime getCaseDate() { return getResource().getAttributes().getCaseDate(); } @Override - public Network setCaseDate(DateTime date) { + public Network setCaseDate(ZonedDateTime date) { ValidationUtil.checkCaseDate(this, date); updateResource(res -> res.getAttributes().setCaseDate(date)); return this; @@ -221,6 +222,16 @@ public VariantManagerImpl getVariantManager() { return new VariantManagerImpl(index); } + @Override + public void allowReporterContextMultiThreadAccess(boolean allow) { + this.reporterContext = Networks.allowReporterContextMultiThreadAccess(this.reporterContext, allow); + } + + @Override + public ReporterContext getReporterContext() { + return this.reporterContext; + } + // country @Override @@ -838,19 +849,19 @@ private void update(ComponentType componentType, boolean isBusView) { bus.visitConnectedEquipments(new DefaultTopologyVisitor() { @Override - public void visitLine(Line line, Branch.Side side) { + public void visitLine(Line line, TwoSides side) { graph.addVertex(line); graph.addEdge(bus, line, new Object()); } @Override - public void visitTwoWindingsTransformer(TwoWindingsTransformer transformer, Branch.Side side) { + public void visitTwoWindingsTransformer(TwoWindingsTransformer transformer, TwoSides side) { graph.addVertex(transformer); graph.addEdge(bus, transformer, new Object()); } @Override - public void visitThreeWindingsTransformer(ThreeWindingsTransformer transformer, ThreeWindingsTransformer.Side side) { + public void visitThreeWindingsTransformer(ThreeWindingsTransformer transformer, ThreeSides side) { graph.addVertex(transformer); graph.addEdge(bus, transformer, new Object()); } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchPathValidator.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchPathValidator.java new file mode 100644 index 000000000..0ed19ab3c --- /dev/null +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchPathValidator.java @@ -0,0 +1,34 @@ +package com.powsybl.network.store.iidm.impl; + +import com.powsybl.iidm.network.Switch; +import com.powsybl.network.store.model.SwitchAttributes; +import org.jgrapht.GraphPath; +import org.jgrapht.alg.shortestpath.PathValidator; + +import java.util.Optional; +import java.util.function.Predicate; + +public class SwitchPathValidator implements PathValidator { + + private final Predicate isSwitchValidInGraph; + private final NetworkObjectIndex index; + + public SwitchPathValidator(Predicate isSwitchValidInGraph, NetworkObjectIndex index) { + this.isSwitchValidInGraph = isSwitchValidInGraph; + this.index = index; + } + + @Override + public boolean isValidPath(GraphPath graphPath, Edge edge) { + + if (edge.getBiConnectable() instanceof SwitchAttributes switchAttributes) { + + // Get the switch behind the switchAttributes + Optional sw = index.getSwitch(switchAttributes.getResource().getId()); + + // The path is valid if the switch can be operated + return sw.isPresent() && isSwitchValidInGraph.test(sw.get()); + } + return 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 bd624af27..5faf4f264 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 @@ -8,16 +8,15 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.util.SwitchPredicates; import com.powsybl.math.graph.TraversalType; import com.powsybl.math.graph.TraverseResult; import com.powsybl.network.store.model.*; import org.jgrapht.Graph; -import org.jgrapht.alg.connectivity.ConnectivityInspector; -import org.jgrapht.alg.flow.EdmondsKarpMFImpl; -import org.jgrapht.alg.interfaces.MinimumSTCutAlgorithm; +import org.jgrapht.GraphPath; +import org.jgrapht.alg.shortestpath.AllDirectedPaths; import org.jgrapht.graph.AsSubgraph; -import org.jgrapht.graph.Pseudograph; -import org.jgrapht.traverse.BreadthFirstIterator; +import org.jgrapht.graph.AsWeightedGraph; import java.util.*; import java.util.function.Function; @@ -146,203 +145,255 @@ private Resource getVoltageLevelResource() { private Set getBusbarSectionNodes(Resource voltageLevelResource) { return index.getStoreClient().getVoltageLevelBusbarSections(index.getNetwork().getUuid(), index.getWorkingVariantNum(), voltageLevelResource.getId()) - .stream().map(resource -> resource.getAttributes().getNode()) - .collect(Collectors.toSet()); + .stream().map(resource -> resource.getAttributes().getNode()) + .collect(Collectors.toSet()); } private static Graph filterSwitches(Graph graph, Predicate filter) { return new AsSubgraph<>(graph, null, graph.edgeSet() - .stream() - .filter(edge -> { - if (edge.getBiConnectable() instanceof SwitchAttributes) { - SwitchAttributes switchAttributes = (SwitchAttributes) edge.getBiConnectable(); - return filter.test(switchAttributes); - } - return true; - }) - .collect(Collectors.toSet())); + .stream() + .filter(edge -> { + if (edge.getBiConnectable() instanceof SwitchAttributes switchAttributes) { + return filter.test(switchAttributes); + } + return true; + }) + .collect(Collectors.toSet())); } - private boolean connectNodeBreaker(Resource voltageLevelResource) { + private double computeEdgeWeight(Edge edge, Predicate openOperableSwitch) { + if (edge.getBiConnectable() instanceof SwitchAttributes switchAttributes) { + // Get the switch behind the switchAttributes + Optional sw = index.getSwitch(switchAttributes.getResource().getId()); + + // THe weight is 1 if the switch is operable and open, else 0 + return sw.isPresent() && openOperableSwitch.test(sw.get()) ? 1d : 0d; + } else { + return 0d; + } + } + + private boolean connectNodeBreaker(Resource voltageLevelResource, Predicate isTypeSwitchToOperate) { boolean done = false; + // Predicates useful + Predicate openOperableSwitch = SwitchPredicates.IS_OPEN.and(isTypeSwitchToOperate); + + // Full graph of the network Graph graph = NodeBreakerTopology.INSTANCE.buildGraph(index, voltageLevelResource, true, true); + AsWeightedGraph weightedGraph = new AsWeightedGraph<>(graph, + edge -> computeEdgeWeight(edge, openOperableSwitch), + true, + false); + + // Node of the present terminal (start of the paths) + int node = getAttributes().getNode(); + + // Nodes of the busbar sections (end of the paths) Set busbarSectionNodes = getBusbarSectionNodes(voltageLevelResource); - // exclude open disconnectors and open fictitious breakers to be able to calculate a shortest path without this - // elements that are not allowed to be closed - Predicate isOpenDisconnector = switchAttributes -> switchAttributes.getKind() != SwitchKind.BREAKER && switchAttributes.isOpen(); - Predicate isOpenFictitiousBreaker = switchAttributes -> switchAttributes.getKind() == SwitchKind.BREAKER && switchAttributes.isOpen() && switchAttributes.isFictitious(); - Graph filteredGraph = filterSwitches(graph, isOpenDisconnector.negate().or(isOpenFictitiousBreaker.negate())); + // Path validator: an edge can be added if it is closed or if the allows to operate it + SwitchPathValidator switchPathValidator = new SwitchPathValidator(SwitchPredicates.IS_OPEN.negate().or(isTypeSwitchToOperate), index); + + // Find all paths from the source to the targets + AllDirectedPaths allDirectedPaths = new AllDirectedPaths<>(weightedGraph, switchPathValidator); + List> allPaths = allDirectedPaths.getAllPaths(Set.of(node), busbarSectionNodes, true, null); + // Sort the paths by weight then by length + allPaths.sort(Comparator.comparingDouble((GraphPath path) -> path.getWeight()).thenComparingInt(GraphPath::getLength)); + + // Close the shortest path Set closedSwitches = new HashSet<>(); - BreadthFirstIterator it = new BreadthFirstIterator<>(filteredGraph, getAttributes().getNode()); - while (it.hasNext()) { - int node = it.next(); - if (busbarSectionNodes.contains(node)) { - // close all switches along spanning tree path - for (Integer parentNode = node; parentNode != null; parentNode = it.getParent(parentNode)) { - Edge edge = it.getSpanningTreeEdge(parentNode); - if (edge != null && edge.getBiConnectable() instanceof SwitchAttributes) { - SwitchAttributes switchAttributes = (SwitchAttributes) edge.getBiConnectable(); - if (switchAttributes.getKind() == SwitchKind.BREAKER && switchAttributes.isOpen()) { - switchAttributes.setOpen(false); - index.updateSwitchResource(switchAttributes.getResource()); - closedSwitches.add(switchAttributes.getResource().getId()); - done = true; - } + if (!allPaths.isEmpty()) { + // the shortest path is the best + GraphPath shortestPath = allPaths.get(0); + + // close all open operable switches on the path + shortestPath.getEdgeList().stream() + .filter(edge -> { + if (edge.getBiConnectable() instanceof SwitchAttributes switchAttributes) { + // Get the switch behind the switchAttributes + Optional sw = index.getSwitch(switchAttributes.getResource().getId()); + + // THe weight is 1 if the switch is operable and open, else 0 + return sw.isPresent() && openOperableSwitch.test(sw.get()); + } else { + return false; } - } - // we just need to process shortest path so we can skip the others - break; - } + }) + .forEach(edge -> { + if (edge.getBiConnectable() instanceof SwitchAttributes switchAttributes) { + switchAttributes.setOpen(false); + index.updateSwitchResource(switchAttributes.getResource()); + closedSwitches.add(switchAttributes.getResource().getId()); + } + }); + done = true; } + // Notify update closedSwitches.forEach(switchId -> index.notifyUpdate(index.getSwitch(switchId).orElseThrow(), "open", true, false)); return done; } @Override - public boolean connect() { + public boolean connect(Predicate isTypeSwitchToOperate) { boolean done = false; - Resource voltageLevelResource = getVoltageLevelResource(); - VoltageLevelAttributes voltageLevelAttributes = voltageLevelResource.getAttributes(); - if (isNodeBeakerTopologyKind()) { - if (connectNodeBreaker(voltageLevelResource)) { - done = true; - } - } else { // TopologyKind.BUS_BREAKER - var attributes = getAttributes(); - if (attributes.getBus() == null) { - getAbstractIdentifiable().updateResource(r -> { - var a = getAttributes(r); - a.setBus(a.getConnectableBus()); - // 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()); - } - }); - done = true; + try { + Resource voltageLevelResource = getVoltageLevelResource(); + VoltageLevelAttributes voltageLevelAttributes = voltageLevelResource.getAttributes(); + if (isNodeBeakerTopologyKind()) { + if (connectNodeBreaker(voltageLevelResource, isTypeSwitchToOperate)) { + done = true; + } + } else { // TopologyKind.BUS_BREAKER + var attributes = getAttributes(); + if (attributes.getBus() == null) { + getAbstractIdentifiable().updateResource(r -> { + var a = getAttributes(r); + a.setBus(a.getConnectableBus()); + // 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()); + } + }); + done = true; + } } - } - if (done) { - // to invalidate calculated buses - voltageLevelAttributes.setCalculatedBusesValid(false); - index.updateVoltageLevelResource(voltageLevelResource); + if (done) { + // to invalidate calculated buses + voltageLevelAttributes.setCalculatedBusesValid(false); + index.updateVoltageLevelResource(voltageLevelResource); + } + } catch (PowsyblException exception) { + if (exception.getMessage().contains("Object has been removed in current variant")) { + throw new PowsyblException("Cannot modify removed equipment", exception); + } else { + throw exception; + } } return done; } - private boolean disconnectNodeBreaker(Resource voltageLevelResource) { - boolean done = false; + @Override + public boolean connect() { + return connect(SwitchPredicates.IS_NONFICTIONAL_BREAKER); + } - // create a graph with only closed switches - Graph graph = NodeBreakerTopology.INSTANCE.buildGraph(index, voltageLevelResource, false, true); + /** + * Add the first openable switch in the given path to the set of switches to open + * @param path the path to open + * @param isSwitchOpenable predicate used to know if a switch can be opened + * @param switchesToOpen set of switches to be opened + * @return true if the path has been opened, else false + */ + boolean identifySwitchToOpenPath(GraphPath path, Predicate isSwitchOpenable, Set switchesToOpen) { + for (Edge edge : path.getEdgeList()) { + if (edge.getBiConnectable() instanceof SwitchAttributes switchAttributes) { + // Get the switch behind the switchAttributes + Optional sw = index.getSwitch(switchAttributes.getResource().getId()); + + // Test if the switch can be opened according to the predicate + if (sw.isPresent() && isSwitchOpenable.test(sw.get())) { + switchesToOpen.add(switchAttributes); + return true; + } + } + } + return false; + } + + private boolean disconnectNodeBreaker(Resource voltageLevelResource, Predicate isSwitchOpenable) { + // Full graph of the network + Graph graph = NodeBreakerTopology.INSTANCE.buildGraph(index, voltageLevelResource, true, true); + + // Node of the present terminal (start of the paths) + int node = getAttributes().getNode(); + + // Nodes of the busbar sections (end of the paths) Set busbarSectionNodes = getBusbarSectionNodes(voltageLevelResource); - // inspect connectivity of graph without its non fictitious breakers to check if disconnection is possible - Predicate isSwitchOpenable = switchAttributes -> switchAttributes.getKind() == SwitchKind.BREAKER && !switchAttributes.isFictitious() && !switchAttributes.isOpen(); - ConnectivityInspector connectivityInspector - = new ConnectivityInspector<>(filterSwitches(graph, isSwitchOpenable.negate())); + // Find all paths from the source to the targets + AllDirectedPaths allDirectedPaths = new AllDirectedPaths<>(graph); + List> allPaths = allDirectedPaths.getAllPaths(Set.of(node), busbarSectionNodes, true, null); - List> connectedSets = connectivityInspector.connectedSets(); - if (connectedSets.size() == 1) { - // it means that terminal is connected to a busbar section through disconnectors only - // so there is no way to disconnect the terminal - } else { - // build an aggregated graph where we only keep breakers - int aggregatedNodeCount = 0; - Graph breakerOnlyGraph = new Pseudograph<>(Edge.class); - Map nodeToAggregatedNode = new HashMap<>(); - - for (Set connectedSet : connectedSets) { - breakerOnlyGraph.addVertex(aggregatedNodeCount); - for (int node : connectedSet) { - nodeToAggregatedNode.put(node, aggregatedNodeCount); - } - aggregatedNodeCount++; - } - for (Edge edge : graph.edgeSet()) { - if (edge.getBiConnectable() instanceof SwitchAttributes) { - SwitchAttributes switchAttributes = (SwitchAttributes) edge.getBiConnectable(); - if (isSwitchOpenable.test(switchAttributes)) { - int node1 = graph.getEdgeSource(edge); - int node2 = graph.getEdgeTarget(edge); - int aggregatedNode1 = nodeToAggregatedNode.get(node1); - int aggregatedNode2 = nodeToAggregatedNode.get(node2); - breakerOnlyGraph.addEdge(aggregatedNode1, aggregatedNode2, edge); - } - } - } + // Set of switches that are to be opened + Set switchesToOpen = new HashSet<>(allPaths.size()); - Set openedSwitches = new HashSet<>(); - // find minimal cuts from terminal to each of the busbar section in the aggregated breaker only graph - // so that we can open the minimal number of breaker to disconnect the terminal - MinimumSTCutAlgorithm minCutAlgo = new EdmondsKarpMFImpl<>(breakerOnlyGraph); - for (int busbarSectionNode : busbarSectionNodes) { - int aggregatedNode = nodeToAggregatedNode.get(getAttributes().getNode()); - int busbarSectionAggregatedNode = nodeToAggregatedNode.get(busbarSectionNode); - // if that terminal is connected to a busbar section through disconnectors only or that terminal is a busbar section - // so there is no way to disconnect the terminal - if (aggregatedNode == busbarSectionAggregatedNode) { - continue; - } - minCutAlgo.calculateMinCut(aggregatedNode, busbarSectionAggregatedNode); - for (Edge edge : minCutAlgo.getCutEdges()) { - if (edge.getBiConnectable() instanceof SwitchAttributes) { - SwitchAttributes switchAttributes = (SwitchAttributes) edge.getBiConnectable(); - switchAttributes.setOpen(true); - index.updateSwitchResource(switchAttributes.getResource()); - openedSwitches.add(switchAttributes.getResource().getId()); - done = true; - } - } + // Each path is visited and for each, the first openable switch found is added in the set of switches to open + for (GraphPath path : allPaths) { + // Identify the first openable switch on the path + if (!identifySwitchToOpenPath(path, isSwitchOpenable, switchesToOpen)) { + // If no such switch was found, return false immediately + return false; } - - openedSwitches.forEach(switchId -> index.notifyUpdate(index.getSwitch(switchId).orElseThrow(), "open", false, true)); } - return done; + // The switches are now opened + Set openedSwitches = new HashSet<>(); + switchesToOpen.forEach(switchAttributes -> { + switchAttributes.setOpen(true); + index.updateSwitchResource(switchAttributes.getResource()); + openedSwitches.add(switchAttributes.getResource().getId()); + }); + + // Notify update + openedSwitches.forEach(switchId -> index.notifyUpdate(index.getSwitch(switchId).orElseThrow(), "open", false, true)); + + return true; } @Override - public boolean disconnect() { + public boolean disconnect(Predicate isSwitchOpenable) { boolean done = false; - Resource voltageLevelResource = getVoltageLevelResource(); - VoltageLevelAttributes voltageLevelAttributes = voltageLevelResource.getAttributes(); - if (isNodeBeakerTopologyKind()) { - if (disconnectNodeBreaker(voltageLevelResource)) { - done = true; - } - } else { // TopologyKind.BUS_BREAKER - var attributes = getAttributes(); - if (attributes.getBus() != null) { - getAbstractIdentifiable().updateResource(r -> { - var a = getAttributes(r); - a.setBus(null); - // 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); - } - }); - done = true; + try { + Resource voltageLevelResource = getVoltageLevelResource(); + VoltageLevelAttributes voltageLevelAttributes = voltageLevelResource.getAttributes(); + if (isNodeBeakerTopologyKind()) { + if (disconnectNodeBreaker(voltageLevelResource, isSwitchOpenable)) { + done = true; + } + } else { // TopologyKind.BUS_BREAKER + var attributes = getAttributes(); + if (attributes.getBus() != null) { + getAbstractIdentifiable().updateResource(r -> { + var a = getAttributes(r); + a.setBus(null); + // 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); + } + }); + done = true; + } } - } - if (done) { - // to invalidate calculated buses - voltageLevelAttributes.setCalculatedBusesValid(false); - index.updateVoltageLevelResource(voltageLevelResource); + if (done) { + // to invalidate calculated buses + voltageLevelAttributes.setCalculatedBusesValid(false); + index.updateVoltageLevelResource(voltageLevelResource); + } + } catch (PowsyblException exception) { + if (exception.getMessage().contains("Object has been removed in current variant")) { + throw new PowsyblException("Cannot modify removed equipment", exception); + } else { + throw exception; + } } return done; } + @Override + public boolean disconnect() { + return disconnect(SwitchPredicates.IS_CLOSED_BREAKER); + } + @Override public boolean isConnected() { if (isNodeBeakerTopologyKind()) { diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalRefUtils.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalRefUtils.java index c4ec997ff..8ca238958 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalRefUtils.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalRefUtils.java @@ -27,10 +27,10 @@ public static Terminal getTerminal(NetworkObjectIndex index, TerminalRefAttribut if (identifiable instanceof Injection) { return ((Injection) identifiable).getTerminal(); } else if (identifiable instanceof Branch) { - return ((Branch) identifiable).getTerminal(Branch.Side.valueOf(side)); + return ((Branch) identifiable).getTerminal(TwoSides.valueOf(side)); } else if (identifiable instanceof ThreeWindingsTransformer) { ThreeWindingsTransformer twt = (ThreeWindingsTransformer) identifiable; - return twt.getTerminal(ThreeWindingsTransformer.Side.valueOf(side)); + return twt.getTerminal(ThreeSides.valueOf(side)); } else { throw new AssertionError("Unexpected Identifiable instance: " + identifiable.getClass()); } 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 1f5551194..2d3a273e1 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 @@ -12,6 +12,7 @@ import com.powsybl.iidm.network.extensions.BranchStatus; import com.powsybl.iidm.network.extensions.ConnectablePosition; import com.powsybl.iidm.network.extensions.ThreeWindingsTransformerPhaseAngleClock; +import com.powsybl.iidm.network.util.LimitViolationUtils; import com.powsybl.network.store.iidm.impl.extensions.BranchStatusImpl; import com.powsybl.network.store.iidm.impl.extensions.CgmesTapChangersImpl; import com.powsybl.network.store.iidm.impl.extensions.ThreeWindingsTransformerPhaseAngleClockImpl; @@ -63,15 +64,12 @@ protected String getLegAttribute() { @Override public TerminalImpl getTerminal() { var attributes = getLegAttributes(); - if (attributes.getLegNumber() == 1) { - return transformer.terminal1; - } else if (attributes.getLegNumber() == 2) { - return transformer.terminal2; - } else if (attributes.getLegNumber() == 3) { - return transformer.terminal3; - } else { - throw new AssertionError(); - } + return switch (attributes.getLegNumber()) { + case 1 -> transformer.terminal1; + case 2 -> transformer.terminal2; + case 3 -> transformer.terminal3; + default -> throw new AssertionError(); + }; } @Override @@ -290,6 +288,16 @@ public Leg setRatedS(double ratedS) { return this; } + @Override + public ThreeSides getSide() { + return ThreeSides.valueOf(getLegAttributes().getLegNumber()); + } + + @Override + public Optional getLimits(LimitType limitType) { + return Optional.empty(); + } + @Override public String getMessageHeader() { return "3 windings transformer leg" + getLegAttributes().getLegNumber() + " '" + transformer.getId() + "': "; @@ -334,9 +342,9 @@ public void notifyUpdate(String attribute, Object oldValue, Object newValue) { 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(), Side.ONE)); - terminal2 = new TerminalImpl<>(index, this, r -> new ThreeWindingsTransformerToInjectionAttributesAdapter(leg2, r.getAttributes(), Side.TWO)); - terminal3 = new TerminalImpl<>(index, this, r -> new ThreeWindingsTransformerToInjectionAttributesAdapter(leg3, r.getAttributes(), Side.THREE)); + 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)); } static ThreeWindingsTransformerImpl create(NetworkObjectIndex index, Resource resource) { @@ -344,32 +352,25 @@ static ThreeWindingsTransformerImpl create(NetworkObjectIndex index, Resource leg1.getTerminal(); + case TWO -> leg2.getTerminal(); + case THREE -> leg3.getTerminal(); + default -> throw new AssertionError(); + }; } @Override - public Side getSide(Terminal terminal) { + public ThreeSides getSide(Terminal terminal) { Objects.requireNonNull(terminal); if (leg1.getTerminal() == terminal) { - return Side.ONE; + return ThreeSides.ONE; } else if (leg2.getTerminal() == terminal) { - return Side.TWO; + return ThreeSides.TWO; } else if (leg3.getTerminal() == terminal) { - return Side.THREE; + return ThreeSides.THREE; } else { throw new AssertionError("The terminal is not connected to this three windings transformer"); } @@ -400,6 +401,109 @@ public double getRatedU0() { return getResource().getAttributes().getRatedU0(); } + @Override + public boolean isOverloaded() { + return isOverloaded(1.0f); + } + + @Override + public boolean isOverloaded(float limitReduction) { + return checkPermanentLimit1(limitReduction, LimitType.CURRENT) + || checkPermanentLimit2(limitReduction, LimitType.CURRENT) + || checkPermanentLimit3(limitReduction, LimitType.CURRENT); + } + + @Override + public int getOverloadDuration() { + Overload o1 = checkTemporaryLimits1(LimitType.CURRENT); + Overload o2 = checkTemporaryLimits2(LimitType.CURRENT); + Overload o3 = checkTemporaryLimits3(LimitType.CURRENT); + int duration1 = o1 != null ? o1.getTemporaryLimit().getAcceptableDuration() : Integer.MAX_VALUE; + int duration2 = o2 != null ? o2.getTemporaryLimit().getAcceptableDuration() : Integer.MAX_VALUE; + int duration3 = o3 != null ? o3.getTemporaryLimit().getAcceptableDuration() : Integer.MAX_VALUE; + return Math.min(Math.min(duration1, duration2), duration3); + } + + @Override + public boolean checkPermanentLimit(ThreeSides side, float limitReduction, LimitType limitType) { + return LimitViolationUtils.checkPermanentLimit(this, side, limitReduction, limitType); + } + + @Override + public boolean checkPermanentLimit(ThreeSides side, LimitType limitType) { + return checkPermanentLimit(side, 1f, limitType); + } + + @Override + public boolean checkPermanentLimit1(float limitReduction, LimitType limitType) { + return checkPermanentLimit(ThreeSides.ONE, limitReduction, limitType); + } + + @Override + public boolean checkPermanentLimit1(LimitType type) { + return checkPermanentLimit1(1f, type); + } + + @Override + public boolean checkPermanentLimit2(float limitReduction, LimitType type) { + return checkPermanentLimit(ThreeSides.TWO, limitReduction, type); + } + + @Override + public boolean checkPermanentLimit2(LimitType type) { + return checkPermanentLimit2(1f, type); + } + + @Override + public boolean checkPermanentLimit3(float limitReduction, LimitType type) { + return checkPermanentLimit(ThreeSides.THREE, limitReduction, type); + } + + @Override + public boolean checkPermanentLimit3(LimitType type) { + return checkPermanentLimit3(1f, type); + } + + @Override + public Overload checkTemporaryLimits(ThreeSides side, float limitReduction, LimitType type) { + return LimitViolationUtils.checkTemporaryLimits(this, side, limitReduction, type); + } + + @Override + public Overload checkTemporaryLimits(ThreeSides side, LimitType type) { + return checkTemporaryLimits(side, 1f, type); + } + + @Override + public Overload checkTemporaryLimits1(float limitReduction, LimitType type) { + return checkTemporaryLimits(ThreeSides.ONE, limitReduction, type); + } + + @Override + public Overload checkTemporaryLimits1(LimitType type) { + return checkTemporaryLimits1(1f, type); + } + + @Override + public Overload checkTemporaryLimits2(float limitReduction, LimitType type) { + return checkTemporaryLimits(ThreeSides.TWO, limitReduction, type); + } + + @Override + public Overload checkTemporaryLimits2(LimitType type) { + return checkTemporaryLimits2(1f, type); + } + + @Override + public Overload checkTemporaryLimits3(float limitReduction, LimitType type) { + return checkTemporaryLimits(ThreeSides.THREE, limitReduction, type); + } + + @Override + public Overload checkTemporaryLimits3(LimitType type) { + return checkTemporaryLimits3(1f, type); + } + @Override public List getTerminals() { return Arrays.asList(terminal1, terminal2, terminal3); 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 9b7a0684b..cc5545f48 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 @@ -6,7 +6,7 @@ */ package com.powsybl.network.store.iidm.impl; -import com.powsybl.iidm.network.ThreeWindingsTransformer; +import com.powsybl.iidm.network.ThreeSides; import com.powsybl.network.store.model.*; import java.util.Map; @@ -22,9 +22,9 @@ public class ThreeWindingsTransformerToInjectionAttributesAdapter implements Inj private final ThreeWindingsTransformerAttributes attributes; - private final ThreeWindingsTransformer.Side side; + private final ThreeSides side; - public ThreeWindingsTransformerToInjectionAttributesAdapter(ThreeWindingsTransformerImpl.LegImpl leg, ThreeWindingsTransformerAttributes attributes, ThreeWindingsTransformer.Side side) { + public ThreeWindingsTransformerToInjectionAttributesAdapter(ThreeWindingsTransformerImpl.LegImpl leg, ThreeWindingsTransformerAttributes attributes, ThreeSides side) { this.leg = Objects.requireNonNull(leg); this.attributes = attributes; this.side = side; diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java index dfeeeb768..baf713f43 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java @@ -42,8 +42,8 @@ public DanglingLineImpl getDanglingLine2() { } @Override - public DanglingLine getDanglingLine(Branch.Side side) { - if (Branch.Side.ONE == side) { + public DanglingLine getDanglingLine(TwoSides side) { + if (TwoSides.ONE == side) { return getDanglingLine1(); } else { return getDanglingLine2(); @@ -141,9 +141,9 @@ public Terminal getTerminal2() { } @Override - public Terminal getTerminal(Side side) { + public Terminal getTerminal(TwoSides side) { Objects.requireNonNull(side); - if (Side.ONE == side) { + if (TwoSides.ONE == side) { return getDanglingLine1().getTerminal(); } else { return getDanglingLine2().getTerminal(); @@ -155,7 +155,7 @@ public Terminal getTerminal(String voltageLevelId) { return getTerminal(voltageLevelId, getTerminal1(), getTerminal2()); } - public Side getSide(Terminal terminal) { + public TwoSides getSide(Terminal terminal) { return getSide(terminal, getTerminal1(), getTerminal2()); } @@ -260,17 +260,17 @@ public ActivePowerLimitsAdder newActivePowerLimits2() { } @Override - public Optional getCurrentLimits(Side side) { + public Optional getCurrentLimits(TwoSides side) { return getFromSide(side, this::getCurrentLimits1, this::getCurrentLimits2); } @Override - public Optional getActivePowerLimits(Side side) { + public Optional getActivePowerLimits(TwoSides side) { return getFromSide(side, this::getActivePowerLimits1, this::getActivePowerLimits2); } @Override - public Optional getApparentPowerLimits(Side side) { + public Optional getApparentPowerLimits(TwoSides side) { return getFromSide(side, this::getApparentPowerLimits1, this::getApparentPowerLimits2); } @@ -290,20 +290,20 @@ public int getOverloadDuration() { } @Override - public boolean checkPermanentLimit(Side side, float limitReduction, LimitType type) { + public boolean checkPermanentLimit(TwoSides side, float limitReduction, LimitType type) { return getFromSide(side, () -> checkPermanentLimit1(limitReduction, type), () -> checkPermanentLimit2(limitReduction, type)); } @Override - public boolean checkPermanentLimit(Side side, LimitType type) { + public boolean checkPermanentLimit(TwoSides side, LimitType type) { return checkPermanentLimit(side, 1f, type); } @Override public boolean checkPermanentLimit1(float limitReduction, LimitType type) { - return LimitViolationUtils.checkPermanentLimit(this, Side.ONE, limitReduction, getValueForLimit(getTerminal1(), type), type); + return LimitViolationUtils.checkPermanentLimit(this, TwoSides.ONE, limitReduction, getValueForLimit(getTerminal1(), type), type); } @Override @@ -313,7 +313,7 @@ public boolean checkPermanentLimit1(LimitType type) { @Override public boolean checkPermanentLimit2(float limitReduction, LimitType type) { - return LimitViolationUtils.checkPermanentLimit(this, Side.TWO, limitReduction, getValueForLimit(getTerminal2(), type), type); + return LimitViolationUtils.checkPermanentLimit(this, TwoSides.TWO, limitReduction, getValueForLimit(getTerminal2(), type), type); } @Override @@ -322,34 +322,34 @@ public boolean checkPermanentLimit2(LimitType type) { } @Override - public Branch.Overload checkTemporaryLimits(Side side, float limitReduction, LimitType type) { + public Overload checkTemporaryLimits(TwoSides side, float limitReduction, LimitType type) { return getFromSide(side, () -> checkTemporaryLimits1(limitReduction, type), () -> checkTemporaryLimits2(limitReduction, type)); } @Override - public Branch.Overload checkTemporaryLimits(Side side, LimitType type) { + public Overload checkTemporaryLimits(TwoSides side, LimitType type) { return checkTemporaryLimits(side, 1f, type); } @Override - public Branch.Overload checkTemporaryLimits1(float limitReduction, LimitType type) { - return LimitViolationUtils.checkTemporaryLimits(this, Side.ONE, limitReduction, getValueForLimit(getTerminal1(), type), type); + public Overload checkTemporaryLimits1(float limitReduction, LimitType type) { + return LimitViolationUtils.checkTemporaryLimits(this, TwoSides.ONE, limitReduction, getValueForLimit(getTerminal1(), type), type); } @Override - public Branch.Overload checkTemporaryLimits1(LimitType type) { + public Overload checkTemporaryLimits1(LimitType type) { return checkTemporaryLimits1(1f, type); } @Override - public Branch.Overload checkTemporaryLimits2(float limitReduction, LimitType type) { - return LimitViolationUtils.checkTemporaryLimits(this, Side.TWO, limitReduction, getValueForLimit(getTerminal2(), type), type); + public Overload checkTemporaryLimits2(float limitReduction, LimitType type) { + return LimitViolationUtils.checkTemporaryLimits(this, TwoSides.TWO, limitReduction, getValueForLimit(getTerminal2(), type), type); } @Override - public Branch.Overload checkTemporaryLimits2(LimitType type) { + public Overload checkTemporaryLimits2(LimitType type) { return checkTemporaryLimits2(1f, type); } @@ -382,28 +382,28 @@ static Terminal getTerminal(String voltageLevelId, Terminal terminal1, Terminal } } - public static Branch.Side getSide(Terminal terminal, Terminal terminal1, Terminal terminal2) { + public static TwoSides getSide(Terminal terminal, Terminal terminal1, Terminal terminal2) { Objects.requireNonNull(terminal); if (terminal1 == terminal) { - return Branch.Side.ONE; + return TwoSides.ONE; } else if (terminal2 == terminal) { - return Branch.Side.TWO; + return TwoSides.TWO; } else { throw new IllegalStateException("The terminal is not connected to this branch"); } } - static T getFromSide(Branch.Side side, Supplier getter1, Supplier getter2) { + static T getFromSide(TwoSides side, Supplier getter1, Supplier getter2) { Objects.requireNonNull(side); - if (side == Branch.Side.ONE) { + if (side == TwoSides.ONE) { return getter1.get(); - } else if (side == Branch.Side.TWO) { + } else if (side == TwoSides.TWO) { return getter2.get(); } throw new IllegalStateException("Unexpected side: " + side); } - static int getOverloadDuration(Branch.Overload o1, Branch.Overload o2) { + static int getOverloadDuration(Overload o1, Overload o2) { int duration1 = o1 != null ? o1.getTemporaryLimit().getAcceptableDuration() : Integer.MAX_VALUE; int duration2 = o2 != null ? o2.getTemporaryLimit().getAcceptableDuration() : Integer.MAX_VALUE; return Math.min(duration1, duration2); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VoltageLevelImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VoltageLevelImpl.java index 0293d3b9d..e02fdf9fc 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VoltageLevelImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VoltageLevelImpl.java @@ -506,30 +506,30 @@ public void visitEquipments(TopologyVisitor visitor) { visitor.visitHvdcConverterStation(station); } for (TwoWindingsTransformer twt : index.getTwoWindingsTransformers(resource.getId())) { - if (twt.getTerminal(Branch.Side.ONE).getVoltageLevel().getId().equals(resource.getId())) { - visitor.visitTwoWindingsTransformer(twt, Branch.Side.ONE); + if (twt.getTerminal(TwoSides.ONE).getVoltageLevel().getId().equals(resource.getId())) { + visitor.visitTwoWindingsTransformer(twt, TwoSides.ONE); } - if (twt.getTerminal(Branch.Side.TWO).getVoltageLevel().getId().equals(resource.getId())) { - visitor.visitTwoWindingsTransformer(twt, Branch.Side.TWO); + if (twt.getTerminal(TwoSides.TWO).getVoltageLevel().getId().equals(resource.getId())) { + visitor.visitTwoWindingsTransformer(twt, TwoSides.TWO); } } for (ThreeWindingsTransformer twt : index.getThreeWindingsTransformers(resource.getId())) { - if (twt.getTerminal(ThreeWindingsTransformer.Side.ONE).getVoltageLevel().getId().equals(resource.getId())) { - visitor.visitThreeWindingsTransformer(twt, ThreeWindingsTransformer.Side.ONE); + if (twt.getTerminal(ThreeSides.ONE).getVoltageLevel().getId().equals(resource.getId())) { + visitor.visitThreeWindingsTransformer(twt, ThreeSides.ONE); } - if (twt.getTerminal(ThreeWindingsTransformer.Side.TWO).getVoltageLevel().getId().equals(resource.getId())) { - visitor.visitThreeWindingsTransformer(twt, ThreeWindingsTransformer.Side.TWO); + if (twt.getTerminal(ThreeSides.TWO).getVoltageLevel().getId().equals(resource.getId())) { + visitor.visitThreeWindingsTransformer(twt, ThreeSides.TWO); } - if (twt.getTerminal(ThreeWindingsTransformer.Side.THREE).getVoltageLevel().getId().equals(resource.getId())) { - visitor.visitThreeWindingsTransformer(twt, ThreeWindingsTransformer.Side.THREE); + if (twt.getTerminal(ThreeSides.THREE).getVoltageLevel().getId().equals(resource.getId())) { + visitor.visitThreeWindingsTransformer(twt, ThreeSides.THREE); } } for (Line line : index.getLines(resource.getId())) { - if (line.getTerminal(Branch.Side.ONE).getVoltageLevel().getId().equals(resource.getId())) { - visitor.visitLine(line, Branch.Side.ONE); + if (line.getTerminal(TwoSides.ONE).getVoltageLevel().getId().equals(resource.getId())) { + visitor.visitLine(line, TwoSides.ONE); } - if (line.getTerminal(Branch.Side.TWO).getVoltageLevel().getId().equals(resource.getId())) { - visitor.visitLine(line, Branch.Side.TWO); + if (line.getTerminal(TwoSides.TWO).getVoltageLevel().getId().equals(resource.getId())) { + visitor.visitLine(line, TwoSides.TWO); } } for (DanglingLine danglingLine : getDanglingLines()) { diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/CgmesControlAreaImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/CgmesControlAreaImpl.java index a0b02178e..250173d5a 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/CgmesControlAreaImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/CgmesControlAreaImpl.java @@ -65,7 +65,7 @@ public static Boundary getTerminalBoundary(Terminal terminal) { return ((DanglingLine) terminal.getConnectable()).getBoundary(); } else if (terminal.getConnectable() instanceof TieLine) { TieLine tieLine = (TieLine) terminal.getConnectable(); - Branch.Side side = terminal == tieLine.getDanglingLine1().getTerminal() ? Branch.Side.ONE : Branch.Side.TWO; + TwoSides side = terminal == tieLine.getDanglingLine1().getTerminal() ? TwoSides.ONE : TwoSides.TWO; return tieLine.getDanglingLine(side).getBoundary(); } else { throw new IllegalStateException("Unexpected boundary component: " + terminal.getConnectable().getType()); diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/BoundaryTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/BoundaryTest.java index 6d3448572..fd6dcb54d 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/BoundaryTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/BoundaryTest.java @@ -67,6 +67,6 @@ public void tieLineTest() { assertEquals(430.1, boundary2.getV(), EPS1); assertEquals(0.1, boundary2.getAngle(), EPS2); //assertSame(tieLine.getDanglingLine2(), boundary2.getConnectable()); - //assertEquals(Branch.Side.TWO, boundary2.getSide()); + //assertEquals(TwoSides.TWO, boundary2.getSide()); } } diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CreateNetworksUtil.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CreateNetworksUtil.java index 0b4bab05d..21ec35b6b 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CreateNetworksUtil.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CreateNetworksUtil.java @@ -73,7 +73,7 @@ private static VoltageLevel addVoltageLevel(Substation s, String id, TopologyKin static void connectAllTerminalsVoltageLevel(VoltageLevel vl) { vl.getConnectableStream() - .map(c -> c.getTerminals()) + .map(Connectable::getTerminals) .flatMap(List::stream) .filter(t -> t.getVoltageLevel().getId().equals(vl.getId())) .forEach(Terminal::connect); @@ -81,7 +81,7 @@ static void connectAllTerminalsVoltageLevel(VoltageLevel vl) { static void disconnectAllTerminalsVoltageLevel(VoltageLevel vl) { vl.getConnectableStream() - .map(c -> c.getTerminals()) + .map(Connectable::getTerminals) .flatMap(List::stream) .filter(t -> t.getVoltageLevel().getId().equals(vl.getId())) .forEach(Terminal::disconnect); @@ -96,17 +96,17 @@ public void visitBusbarSection(BusbarSection section) { } @Override - public void visitLine(Line line, Branch.Side side) { + public void visitLine(Line line, TwoSides side) { visited.add(line.getId()); } @Override - public void visitTwoWindingsTransformer(TwoWindingsTransformer transformer, Branch.Side side) { + public void visitTwoWindingsTransformer(TwoWindingsTransformer transformer, TwoSides side) { visited.add(transformer.getId()); } @Override - public void visitThreeWindingsTransformer(ThreeWindingsTransformer transformer, ThreeWindingsTransformer.Side side) { + public void visitThreeWindingsTransformer(ThreeWindingsTransformer transformer, ThreeSides side) { visited.add(transformer.getId()); } @@ -426,10 +426,10 @@ private static Network createNetwokWithMultipleEquipments(TopologyKind topologyK .setRatedU2(90) .add(); - twoWindingsTransformer.getTerminal(TwoWindingsTransformer.Side.ONE).setP(375); - twoWindingsTransformer.getTerminal(TwoWindingsTransformer.Side.TWO).setP(225); - twoWindingsTransformer.getTerminal(TwoWindingsTransformer.Side.ONE).setQ(48); - twoWindingsTransformer.getTerminal(TwoWindingsTransformer.Side.TWO).setQ(28); + twoWindingsTransformer.getTerminal(TwoSides.ONE).setP(375); + twoWindingsTransformer.getTerminal(TwoSides.TWO).setP(225); + twoWindingsTransformer.getTerminal(TwoSides.ONE).setQ(48); + twoWindingsTransformer.getTerminal(TwoSides.TWO).setQ(28); ThreeWindingsTransformerAdder threeWindingsTransformerAdder = s2.newThreeWindingsTransformer(); @@ -465,12 +465,12 @@ private static Network createNetwokWithMultipleEquipments(TopologyKind topologyK .setName("Three windings transformer 1") .setRatedU0(234) .add(); - threeWindingsTransformer.getTerminal(ThreeWindingsTransformer.Side.ONE).setP(375); - threeWindingsTransformer.getTerminal(ThreeWindingsTransformer.Side.TWO).setP(225); - threeWindingsTransformer.getTerminal(ThreeWindingsTransformer.Side.THREE).setP(200); - threeWindingsTransformer.getTerminal(ThreeWindingsTransformer.Side.ONE).setQ(48); - threeWindingsTransformer.getTerminal(ThreeWindingsTransformer.Side.TWO).setQ(28); - threeWindingsTransformer.getTerminal(ThreeWindingsTransformer.Side.THREE).setQ(18); + threeWindingsTransformer.getTerminal(ThreeSides.ONE).setP(375); + threeWindingsTransformer.getTerminal(ThreeSides.TWO).setP(225); + threeWindingsTransformer.getTerminal(ThreeSides.THREE).setP(200); + threeWindingsTransformer.getTerminal(ThreeSides.ONE).setQ(48); + threeWindingsTransformer.getTerminal(ThreeSides.TWO).setQ(28); + threeWindingsTransformer.getTerminal(ThreeSides.THREE).setQ(18); threeWindingsTransformer.getLeg1().newPhaseTapChanger() .setLowTapPosition(0) @@ -478,7 +478,7 @@ private static Network createNetwokWithMultipleEquipments(TopologyKind topologyK .setRegulating(true) .setRegulationMode(PhaseTapChanger.RegulationMode.CURRENT_LIMITER) .setRegulationValue(25) - .setRegulationTerminal(threeWindingsTransformer.getTerminal(ThreeWindingsTransformer.Side.ONE)) + .setRegulationTerminal(threeWindingsTransformer.getTerminal(ThreeSides.ONE)) .setTargetDeadband(22) .beginStep() .setAlpha(-10) @@ -509,7 +509,7 @@ private static Network createNetwokWithMultipleEquipments(TopologyKind topologyK .setLowTapPosition(0) .setTapPosition(0) .setRegulating(false) - .setRegulationTerminal(threeWindingsTransformer.getTerminal(ThreeWindingsTransformer.Side.ONE)) + .setRegulationTerminal(threeWindingsTransformer.getTerminal(ThreeSides.ONE)) .setTargetDeadband(22) .setTargetV(220) .beginStep() diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/LineTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/LineTest.java index 794c100f6..0a7437a4b 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/LineTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/LineTest.java @@ -43,29 +43,29 @@ public void isOverloadedTest() { assertFalse(l1.isOverloaded()); l1.getTerminal1().setP(400); - l1.setCurrentLimits(Branch.Side.ONE, new LimitsAttributes(40, null)); + l1.setCurrentLimits(TwoSides.ONE, new LimitsAttributes(40, null)); assertTrue(l1.getNullableCurrentLimits1().getTemporaryLimits().isEmpty()); assertTrue(l1.isOverloaded()); TreeMap temporaryLimits = new TreeMap<>(); temporaryLimits.put(5, TemporaryLimitAttributes.builder().name("TempLimit5").value(1000).acceptableDuration(5).fictitious(false).build()); - l1.setCurrentLimits(Branch.Side.ONE, new LimitsAttributes(40, temporaryLimits)); - l1.setCurrentLimits(Branch.Side.TWO, new LimitsAttributes(40, temporaryLimits)); + l1.setCurrentLimits(TwoSides.ONE, new LimitsAttributes(40, temporaryLimits)); + l1.setCurrentLimits(TwoSides.TWO, new LimitsAttributes(40, temporaryLimits)); assertEquals(5, l1.getOverloadDuration()); - assertTrue(l1.checkPermanentLimit(Branch.Side.ONE, LimitType.CURRENT)); + assertTrue(l1.checkPermanentLimit(TwoSides.ONE, LimitType.CURRENT)); assertTrue(l1.checkPermanentLimit1(LimitType.CURRENT)); - assertFalse(l1.checkPermanentLimit(Branch.Side.TWO, LimitType.CURRENT)); + assertFalse(l1.checkPermanentLimit(TwoSides.TWO, LimitType.CURRENT)); assertFalse(l1.checkPermanentLimit2(LimitType.CURRENT)); - assertFalse(l1.checkPermanentLimit(Branch.Side.ONE, LimitType.APPARENT_POWER)); - assertFalse(l1.checkPermanentLimit(Branch.Side.TWO, LimitType.ACTIVE_POWER)); - assertThrows(UnsupportedOperationException.class, () -> l1.checkPermanentLimit(Branch.Side.TWO, LimitType.VOLTAGE)); + assertFalse(l1.checkPermanentLimit(TwoSides.ONE, LimitType.APPARENT_POWER)); + assertFalse(l1.checkPermanentLimit(TwoSides.TWO, LimitType.ACTIVE_POWER)); + assertThrows(UnsupportedOperationException.class, () -> l1.checkPermanentLimit(TwoSides.TWO, LimitType.VOLTAGE)); - Branch.Overload overload = l1.checkTemporaryLimits(Branch.Side.ONE, LimitType.CURRENT); + Overload overload = l1.checkTemporaryLimits(TwoSides.ONE, LimitType.CURRENT); assertEquals("TempLimit5", overload.getTemporaryLimit().getName()); assertEquals(40.0, overload.getPreviousLimit(), 0); assertEquals(5, overload.getTemporaryLimit().getAcceptableDuration()); - assertNull(l1.checkTemporaryLimits(Branch.Side.TWO, LimitType.CURRENT)); + assertNull(l1.checkTemporaryLimits(TwoSides.TWO, LimitType.CURRENT)); temporaryLimits.put(5, TemporaryLimitAttributes.builder().name("TempLimit5").value(20).acceptableDuration(5).fictitious(false).build()); assertEquals(Integer.MAX_VALUE, l1.getOverloadDuration()); @@ -157,8 +157,8 @@ public void testTieLine() { DanglingLine dl2 = tieLine.getDanglingLine2(); assertNotNull(dl1); assertNotNull(dl2); - assertEquals(dl1.getId(), tieLine.getDanglingLine(Branch.Side.ONE).getId()); - assertEquals(dl2.getId(), tieLine.getDanglingLine(Branch.Side.TWO).getId()); + assertEquals(dl1.getId(), tieLine.getDanglingLine(TwoSides.ONE).getId()); + assertEquals(dl2.getId(), tieLine.getDanglingLine(TwoSides.TWO).getId()); assertEquals(dl1.getId(), tieLine.getDanglingLine(dl1.getTerminal().getVoltageLevel().getId()).getId()); assertEquals(dl2.getId(), tieLine.getDanglingLine(dl2.getTerminal().getVoltageLevel().getId()).getId()); assertNull(tieLine.getDanglingLine("null")); @@ -228,14 +228,14 @@ public void testTieLineTerminals() { assertNotNull(tieLine.getTerminal2()); assertSame(tieLine.getTerminal2(), dl2.getTerminal()); - assertSame(tieLine.getTerminal(Branch.Side.ONE), dl1.getTerminal()); - assertSame(tieLine.getTerminal(Branch.Side.TWO), dl2.getTerminal()); + assertSame(tieLine.getTerminal(TwoSides.ONE), dl1.getTerminal()); + assertSame(tieLine.getTerminal(TwoSides.TWO), dl2.getTerminal()); assertSame(tieLine.getTerminal(dl1.getTerminal().getVoltageLevel().getId()), dl1.getTerminal()); assertSame(tieLine.getTerminal(dl2.getTerminal().getVoltageLevel().getId()), dl2.getTerminal()); - assertEquals(Branch.Side.ONE, tieLine.getSide(dl1.getTerminal())); - assertEquals(Branch.Side.TWO, tieLine.getSide(dl2.getTerminal())); + assertEquals(TwoSides.ONE, tieLine.getSide(dl1.getTerminal())); + assertEquals(TwoSides.TWO, tieLine.getSide(dl2.getTerminal())); String vlId1 = dl1.getTerminal().getVoltageLevel().getId(); Terminal t1 = dl1.getTerminal(); @@ -268,12 +268,12 @@ public void testTieLineLimits() { assertEquals(tieLine.getCurrentLimits2().isPresent(), dl2.getCurrentLimits().isPresent()); assertEquals(tieLine.getActivePowerLimits2().isPresent(), dl2.getActivePowerLimits().isPresent()); assertEquals(tieLine.getApparentPowerLimits2().isPresent(), dl2.getApparentPowerLimits().isPresent()); - assertEquals(tieLine.getCurrentLimits(Branch.Side.ONE).isPresent(), dl1.getCurrentLimits().isPresent()); - assertEquals(tieLine.getActivePowerLimits(Branch.Side.ONE).isPresent(), dl1.getActivePowerLimits().isPresent()); - assertEquals(tieLine.getApparentPowerLimits(Branch.Side.ONE).isPresent(), dl1.getApparentPowerLimits().isPresent()); - assertEquals(tieLine.getCurrentLimits(Branch.Side.TWO).isPresent(), dl2.getCurrentLimits().isPresent()); - assertEquals(tieLine.getActivePowerLimits(Branch.Side.TWO).isPresent(), dl2.getActivePowerLimits().isPresent()); - assertEquals(tieLine.getApparentPowerLimits(Branch.Side.TWO).isPresent(), dl2.getApparentPowerLimits().isPresent()); + assertEquals(tieLine.getCurrentLimits(TwoSides.ONE).isPresent(), dl1.getCurrentLimits().isPresent()); + assertEquals(tieLine.getActivePowerLimits(TwoSides.ONE).isPresent(), dl1.getActivePowerLimits().isPresent()); + assertEquals(tieLine.getApparentPowerLimits(TwoSides.ONE).isPresent(), dl1.getApparentPowerLimits().isPresent()); + assertEquals(tieLine.getCurrentLimits(TwoSides.TWO).isPresent(), dl2.getCurrentLimits().isPresent()); + assertEquals(tieLine.getActivePowerLimits(TwoSides.TWO).isPresent(), dl2.getActivePowerLimits().isPresent()); + assertEquals(tieLine.getApparentPowerLimits(TwoSides.TWO).isPresent(), dl2.getApparentPowerLimits().isPresent()); assertEquals(tieLine.getOperationalLimits1().size(), dl1.getOperationalLimits().size()); assertEquals(tieLine.getOperationalLimits2().size(), dl2.getOperationalLimits().size()); @@ -371,25 +371,25 @@ public void testTieLineLimitsCheck() { TieLine tieLine = network.getTieLine("b18cd1aa-7808-49b9-a7cf-605eaf07b006 + e8acf6b6-99cb-45ad-b8dc-16c7866a4ddc"); tieLine.getCurrentLimits1().get().getPermanentLimit(); - assertFalse(tieLine.checkPermanentLimit(Branch.Side.ONE, 2.0f, LimitType.CURRENT)); - assertFalse(tieLine.checkPermanentLimit(Branch.Side.TWO, 2.0f, LimitType.CURRENT)); - assertFalse(tieLine.checkPermanentLimit(Branch.Side.ONE, LimitType.CURRENT)); - assertFalse(tieLine.checkPermanentLimit(Branch.Side.TWO, LimitType.CURRENT)); + assertFalse(tieLine.checkPermanentLimit(TwoSides.ONE, 2.0f, LimitType.CURRENT)); + assertFalse(tieLine.checkPermanentLimit(TwoSides.TWO, 2.0f, LimitType.CURRENT)); + assertFalse(tieLine.checkPermanentLimit(TwoSides.ONE, LimitType.CURRENT)); + assertFalse(tieLine.checkPermanentLimit(TwoSides.TWO, LimitType.CURRENT)); tieLine.newActivePowerLimits1().setPermanentLimit(10.0).add(); tieLine.newActivePowerLimits2().setPermanentLimit(10.0).add(); - assertFalse(tieLine.checkPermanentLimit(Branch.Side.ONE, 2.0f, LimitType.ACTIVE_POWER)); - assertFalse(tieLine.checkPermanentLimit(Branch.Side.TWO, 2.0f, LimitType.ACTIVE_POWER)); - assertFalse(tieLine.checkPermanentLimit(Branch.Side.ONE, LimitType.ACTIVE_POWER)); - assertFalse(tieLine.checkPermanentLimit(Branch.Side.TWO, LimitType.ACTIVE_POWER)); + assertFalse(tieLine.checkPermanentLimit(TwoSides.ONE, 2.0f, LimitType.ACTIVE_POWER)); + assertFalse(tieLine.checkPermanentLimit(TwoSides.TWO, 2.0f, LimitType.ACTIVE_POWER)); + assertFalse(tieLine.checkPermanentLimit(TwoSides.ONE, LimitType.ACTIVE_POWER)); + assertFalse(tieLine.checkPermanentLimit(TwoSides.TWO, LimitType.ACTIVE_POWER)); tieLine.newApparentPowerLimits1().setPermanentLimit(10.0).add(); tieLine.newApparentPowerLimits2().setPermanentLimit(10.0).add(); - assertFalse(tieLine.checkPermanentLimit(Branch.Side.ONE, 2.0f, LimitType.APPARENT_POWER)); - assertFalse(tieLine.checkPermanentLimit(Branch.Side.TWO, 2.0f, LimitType.APPARENT_POWER)); - assertFalse(tieLine.checkPermanentLimit(Branch.Side.ONE, LimitType.APPARENT_POWER)); - assertFalse(tieLine.checkPermanentLimit(Branch.Side.TWO, LimitType.APPARENT_POWER)); + assertFalse(tieLine.checkPermanentLimit(TwoSides.ONE, 2.0f, LimitType.APPARENT_POWER)); + assertFalse(tieLine.checkPermanentLimit(TwoSides.TWO, 2.0f, LimitType.APPARENT_POWER)); + assertFalse(tieLine.checkPermanentLimit(TwoSides.ONE, LimitType.APPARENT_POWER)); + assertFalse(tieLine.checkPermanentLimit(TwoSides.TWO, LimitType.APPARENT_POWER)); } } diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/CurrentLimitsTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/CurrentLimitsTest.java index cd42e7339..57935fd8c 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/CurrentLimitsTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/CurrentLimitsTest.java @@ -17,6 +17,21 @@ public void test() { // FIXME } + @Override + public void testForThreeWindingsTransformerLeg1() { + // FIXME + } + + @Override + public void testForThreeWindingsTransformerLeg2() { + // FIXME + } + + @Override + public void testForThreeWindingsTransformerLeg3() { + // FIXME + } + @Override public void testLimitWithoutTempLimit() { // FIXME diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java index 9180029fd..39fb9f3c3 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java @@ -105,27 +105,27 @@ public void testValidationLevelWhenMerging2Ssh() { } @Test - void failMergeOnlyOneNetwork() { + public void failMergeOnlyOneNetwork() { // FIXME } @Test - void failMergeOnSubnetworks() { + public void failMergeOnSubnetworks() { // FIXME } @Test - void failMergeSubnetworks() { + public void failMergeSubnetworks() { // FIXME } @Test - void failMergeContainingSubnetworks() { + public void failMergeContainingSubnetworks() { // FIXME } @Test - void testNoEmptyAdditionalSubnetworkIsCreated() { + public void testNoEmptyAdditionalSubnetworkIsCreated() { // FIXME } diff --git a/network-store-model/pom.xml b/network-store-model/pom.xml index d80e782d8..c687d375b 100644 --- a/network-store-model/pom.xml +++ b/network-store-model/pom.xml @@ -38,10 +38,6 @@ - - joda-time - joda-time - org.projectlombok lombok @@ -93,6 +89,11 @@ ${slf4j.version} test + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + test + diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/LimitHolder.java b/network-store-model/src/main/java/com/powsybl/network/store/model/LimitHolder.java index ec25cd14b..8d962bee5 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/LimitHolder.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/LimitHolder.java @@ -22,19 +22,12 @@ public interface LimitHolder { String EXCEPTION_UNKNOWN_TEMPORARY_LIMIT_TYPE = "Unknown temporary limit type"; default LimitsAttributes getLimits(LimitType type, int side) { - switch (type) { - case CURRENT: - return getCurrentLimits(side); - - case APPARENT_POWER: - return getApparentPowerLimits(side); - - case ACTIVE_POWER: - return getActivePowerLimits(side); - - default: - throw new IllegalArgumentException(EXCEPTION_UNKNOWN_TEMPORARY_LIMIT_TYPE); - } + return switch (type) { + case CURRENT -> getCurrentLimits(side); + case APPARENT_POWER -> getApparentPowerLimits(side); + case ACTIVE_POWER -> getActivePowerLimits(side); + default -> throw new IllegalArgumentException(EXCEPTION_UNKNOWN_TEMPORARY_LIMIT_TYPE); + }; } LimitsAttributes getCurrentLimits(int side); @@ -45,20 +38,10 @@ default LimitsAttributes getLimits(LimitType type, int side) { default void setLimits(LimitType type, int side, LimitsAttributes limits) { switch (type) { - case CURRENT: - setCurrentLimits(side, limits); - break; - - case APPARENT_POWER: - setApparentPowerLimits(side, limits); - break; - - case ACTIVE_POWER: - setActivePowerLimits(side, limits); - break; - - default: - throw new IllegalArgumentException(EXCEPTION_UNKNOWN_TEMPORARY_LIMIT_TYPE); + case CURRENT -> setCurrentLimits(side, limits); + case APPARENT_POWER -> setApparentPowerLimits(side, limits); + case ACTIVE_POWER -> setActivePowerLimits(side, limits); + default -> throw new IllegalArgumentException(EXCEPTION_UNKNOWN_TEMPORARY_LIMIT_TYPE); } } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/NetworkAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/NetworkAttributes.java index 0f6cc963b..c16d47167 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/NetworkAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/NetworkAttributes.java @@ -8,9 +8,11 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; -import org.joda.time.DateTime; -import java.util.*; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Set; +import java.util.UUID; /** * @author Geoffroy Jamgotchian @@ -50,7 +52,7 @@ public class NetworkAttributes extends AbstractAttributes implements Identifiabl @Schema(description = "Network date", required = true) @Builder.Default - private DateTime caseDate = new DateTime(); + private ZonedDateTime caseDate = ZonedDateTime.now(); @Schema(description = "Forecast distance") @Builder.Default diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java index 2a69589b1..23892002c 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java @@ -12,7 +12,9 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; -import java.util.*; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * @author Nicolas Noir diff --git a/network-store-model/src/test/java/com/powsybl/network/store/model/ResourceTest.java b/network-store-model/src/test/java/com/powsybl/network/store/model/ResourceTest.java index b3a069c1f..530951881 100644 --- a/network-store-model/src/test/java/com/powsybl/network/store/model/ResourceTest.java +++ b/network-store-model/src/test/java/com/powsybl/network/store/model/ResourceTest.java @@ -8,14 +8,16 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.joda.JodaModule; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.powsybl.commons.json.JsonUtil; import com.powsybl.iidm.network.*; -import org.joda.time.DateTime; import org.junit.Test; import java.io.IOException; +import java.time.ZonedDateTime; import java.util.Arrays; import java.util.UUID; @@ -32,17 +34,19 @@ public void networkTest() throws IOException { Resource resource = Resource.networkBuilder().id("foo") .attributes(NetworkAttributes.builder() .uuid(UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4")) - .caseDate(DateTime.parse("2015-01-01T00:00:00.000Z")) + .caseDate(ZonedDateTime.parse("2015-01-01T00:00:00.000Z")) .build()) .build(); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JodaModule()); + ObjectMapper objectMapper = new ObjectMapper() + .registerModule(new JavaTimeModule()) + .configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false) + .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); String json = objectMapper.writeValueAsString(resource); assertEquals("{\"type\":\"NETWORK\",\"id\":\"foo\",\"variantNum\":0,\"attributes\":{\"uuid\":\"7928181c-7977-4592-ba19-88027e4254e4\",\"fictitious\":false,\"caseDate\":1420070400000,\"forecastDistance\":0,\"connectedComponentsValid\":false,\"synchronousComponentsValid\":false}}", json); Resource resource2 = objectMapper.readValue(json, new TypeReference>() { }); assertNotNull(resource2); assertEquals("foo", resource2.getId()); - assertEquals(DateTime.parse("2015-01-01T00:00:00.000Z"), resource2.getAttributes().getCaseDate()); + assertEquals(ZonedDateTime.parse("2015-01-01T00:00:00.000Z"), resource2.getAttributes().getCaseDate()); assertEquals(0, resource2.getAttributes().getForecastDistance()); assertNull(resource2.getAttributes().getSourceFormat()); } @@ -434,7 +438,7 @@ public void danglingLine() throws JsonProcessingException { assertTrue(Double.isNaN(resourceDanglingLine.getAttributes().getQ())); ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JodaModule()); + objectMapper.registerModule(new JavaTimeModule()); String json = objectMapper.writeValueAsString(resourceDanglingLine); Resource resource2 = objectMapper.readValue(json, new TypeReference>() { }); @@ -457,7 +461,7 @@ public void tieLine() throws JsonProcessingException { .build(); ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JodaModule()); + objectMapper.registerModule(new JavaTimeModule()); String json = objectMapper.writeValueAsString(resourceTieLine); Resource resource2 = objectMapper.readValue(json, new TypeReference>() { }); diff --git a/pom.xml b/pom.xml index 70b5eafba..75a0af6be 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,7 @@ 3.1.2 3.9 2023.3.2 + 6.1.0-SNAPSHOT 1.7.0 2.0.4 1.4.5 @@ -70,6 +71,13 @@ + + com.powsybl + powsybl-core + ${powsybl-core.version} + pom + import + From 0b58a195c6cc9cc4b47f2d2e7d8ca52853b23ae6 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Mon, 27 Nov 2023 18:11:10 +0100 Subject: [PATCH 02/27] correct tests + swap switchAttributes with switchImpl, double edges for internalconnections Signed-off-by: Nicolas Rol --- .../store/iidm/impl/NodeBreakerTopology.java | 1 + .../network/store/iidm/impl/TerminalImpl.java | 14 +- ...reakerDisconnectionDiamondPathBugTest.java | 145 ------------------ .../iidm/impl/NodeBreakerTerminalTest.java | 42 ----- ...reakerDisconnectionDiamondPathBugTest.java | 21 +++ 5 files changed, 29 insertions(+), 194 deletions(-) delete mode 100644 network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NodeBreakerDisconnectionDiamondPathBugTest.java create mode 100644 network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/NodeBreakerDisconnectionDiamondPathBugTest.java diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NodeBreakerTopology.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NodeBreakerTopology.java index d6caac214..23169a86c 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NodeBreakerTopology.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NodeBreakerTopology.java @@ -122,6 +122,7 @@ protected void buildEdges(NetworkObjectIndex index, Resource path, Predicate isSwitchOpenable, Set switchesToOpen) { + boolean identifySwitchToOpenPath(GraphPath path, Predicate isSwitchOpenable, Set switchesToOpen) { for (Edge edge : path.getEdgeList()) { if (edge.getBiConnectable() instanceof SwitchAttributes switchAttributes) { // Get the switch behind the switchAttributes @@ -299,7 +299,7 @@ boolean identifySwitchToOpenPath(GraphPath path, Predicate voltageLe List> allPaths = allDirectedPaths.getAllPaths(Set.of(node), busbarSectionNodes, true, null); // Set of switches that are to be opened - Set switchesToOpen = new HashSet<>(allPaths.size()); + Set switchesToOpen = new HashSet<>(allPaths.size()); // Each path is visited and for each, the first openable switch found is added in the set of switches to open for (GraphPath path : allPaths) { @@ -335,10 +335,10 @@ private boolean disconnectNodeBreaker(Resource voltageLe // The switches are now opened Set openedSwitches = new HashSet<>(); - switchesToOpen.forEach(switchAttributes -> { - switchAttributes.setOpen(true); - index.updateSwitchResource(switchAttributes.getResource()); - openedSwitches.add(switchAttributes.getResource().getId()); + switchesToOpen.forEach(switchImpl -> { + switchImpl.setOpen(true); + index.updateSwitchResource(switchImpl.getResource()); + openedSwitches.add(switchImpl.getResource().getId()); }); // Notify update diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NodeBreakerDisconnectionDiamondPathBugTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NodeBreakerDisconnectionDiamondPathBugTest.java deleted file mode 100644 index 00f843fb5..000000000 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NodeBreakerDisconnectionDiamondPathBugTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * Copyright (c) 2020, 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 com.powsybl.network.store.iidm.impl; - -import com.powsybl.iidm.network.*; -import org.junit.Test; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * @author Geoffroy Jamgotchian - */ -public class NodeBreakerDisconnectionDiamondPathBugTest { - - /** - * L - * | - * ---1--- - * | | - * BR1 BR2 - * | | - * ---0--- BBS1 - */ - private Network createNetwork() { - Network network = Network.create("test", "test"); - Substation s = network.newSubstation() - .setId("S") - .setCountry(Country.FR) - .add(); - VoltageLevel vl = s.newVoltageLevel() - .setId("VL") - .setNominalV(400.0) - .setTopologyKind(TopologyKind.NODE_BREAKER) - .add(); - vl.getNodeBreakerView().newBusbarSection() - .setId("BBS1") - .setNode(0) - .add(); - vl.newLoad() - .setId("L") - .setNode(1) - .setP0(1) - .setQ0(1) - .add(); - vl.getNodeBreakerView().newBreaker() - .setId("BR1") - .setNode1(1) - .setNode2(0) - .setOpen(false) - .add(); - vl.getNodeBreakerView().newBreaker() - .setId("BR2") - .setNode1(1) - .setNode2(0) - .setOpen(false) - .add(); - return network; - } - - /** - * L - * | - * 2 |------- - * | | - * ------- | - * | | D1 - * BR1 D2 | - * | | | - * ---1--- | - * | | - * BR2 | - * | | - * ---0------- BBS1 - */ - private Network createNetwork2() { - Network network = Network.create("test", "test"); - Substation s = network.newSubstation() - .setId("S") - .setCountry(Country.FR) - .add(); - VoltageLevel vl = s.newVoltageLevel() - .setId("VL") - .setNominalV(400.0) - .setTopologyKind(TopologyKind.NODE_BREAKER) - .add(); - vl.getNodeBreakerView().newBusbarSection() - .setId("BBS1") - .setNode(0) - .add(); - vl.newLoad() - .setId("L") - .setNode(2) - .setP0(1) - .setQ0(1) - .add(); - vl.getNodeBreakerView().newBreaker() - .setId("BR1") - .setNode1(1) - .setNode2(2) - .setOpen(false) - .add(); - vl.getNodeBreakerView().newDisconnector() - .setId("D2") - .setNode1(1) - .setNode2(2) - .setOpen(false) - .add(); - vl.getNodeBreakerView().newBreaker() - .setId("BR2") - .setNode1(1) - .setNode2(0) - .setOpen(false) - .add(); - vl.getNodeBreakerView().newDisconnector() - .setId("D1") - .setNode1(0) - .setNode2(2) - .setOpen(false) - .add(); - return network; - } - - @Test - public void testDisconnect() { - Network network = createNetwork(); - Load l = network.getLoad("L"); - assertTrue(l.getTerminal().isConnected()); - assertTrue(l.getTerminal().disconnect()); - assertFalse(l.getTerminal().isConnected()); - } - - @Test - public void testDisconnect2() { - Network network = createNetwork2(); - Load l = network.getLoad("L"); - assertTrue(l.getTerminal().isConnected()); - assertFalse(l.getTerminal().disconnect()); - assertTrue(l.getTerminal().isConnected()); // because of D1 which is not openable - } -} diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NodeBreakerTerminalTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NodeBreakerTerminalTest.java index 02447a9e6..a1ffebc24 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NodeBreakerTerminalTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NodeBreakerTerminalTest.java @@ -21,48 +21,6 @@ */ public class NodeBreakerTerminalTest { - @Test - public void connectDisconnectRemove() { - var test = new AbstractNodeBreakerTest() { - }; - Network network; - try { - Method createNetwork = AbstractNodeBreakerTest.class.getDeclaredMethod("createNetwork"); - createNetwork.setAccessible(true); - network = (Network) createNetwork.invoke(test); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - throw new PowsyblException(e); - } - - VoltageLevel.NodeBreakerView topo = network.getVoltageLevel("VL").getNodeBreakerView(); - Load l = network.getLoad("L"); - Generator g = network.getGenerator("G"); - - // generator is connected, load is disconnected - assertTrue(topo.getOptionalTerminal(2).isPresent()); - assertTrue(topo.getOptionalTerminal(3).isPresent()); - assertNotNull(g.getTerminal().getBusView().getBus()); - assertNull(l.getTerminal().getBusView().getBus()); - assertTrue(g.getTerminal().isConnected()); - assertFalse(l.getTerminal().isConnected()); - - // connect the load - assertTrue(l.getTerminal().connect()); - - // check load is connected - assertTrue(topo.getOptionalTerminal(2).isPresent()); - assertNotNull(l.getTerminal().getBusView().getBus()); - assertTrue(l.getTerminal().isConnected()); - - // disconnect the generator - g.getTerminal().disconnect(); - - // check generator is disconnected - assertTrue(topo.getOptionalTerminal(3).isPresent()); - assertNull(g.getTerminal().getBusView().getBus()); - assertFalse(g.getTerminal().isConnected()); - } - @Test public void testBusView() { Network network = CreateNetworksUtil.createNodeBreakerNetworkWithLine(); diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/NodeBreakerDisconnectionDiamondPathBugTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/NodeBreakerDisconnectionDiamondPathBugTest.java new file mode 100644 index 000000000..5c39e2f93 --- /dev/null +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/NodeBreakerDisconnectionDiamondPathBugTest.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2020, 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 com.powsybl.network.store.iidm.impl.tck; + +import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.tck.AbstractNodeBreakerDisconnectionDiamondPathBugTest; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * @author Geoffroy Jamgotchian + */ +public class NodeBreakerDisconnectionDiamondPathBugTest extends AbstractNodeBreakerDisconnectionDiamondPathBugTest { + +} From e6e118650dd7609929cac10d962b58c9bf1c51f1 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 29 Nov 2023 10:41:43 +0100 Subject: [PATCH 03/27] Add notification to listeners + delete unused dependency + fix tests + replaced switch by java17 enhanced switch Signed-off-by: Nicolas Rol --- .../store/client/RestNetworkStoreClient.java | 170 ++++++++++-------- .../network/store/iidm/impl/TerminalImpl.java | 38 ++-- .../iidm/impl/NodeBreakerTerminalTest.java | 8 +- ...reakerDisconnectionDiamondPathBugTest.java | 5 - network-store-model/pom.xml | 4 - 5 files changed, 117 insertions(+), 108 deletions(-) diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java index 7bde64d98..d82a382df 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java @@ -10,13 +10,10 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.datatype.joda.JodaModule; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; import com.powsybl.commons.PowsyblException; -import com.powsybl.commons.json.JsonUtil; -import com.powsybl.network.store.model.AttributeFilter; import com.powsybl.network.store.iidm.impl.NetworkStoreClient; import com.powsybl.network.store.model.*; import org.slf4j.Logger; @@ -39,6 +36,23 @@ public class RestNetworkStoreClient implements NetworkStoreClient { private static final Logger LOGGER = LoggerFactory.getLogger(RestNetworkStoreClient.class); private static final int RESOURCES_CREATION_CHUNK_SIZE = 1000; + private static final String STR_NETWORK = "network"; + private static final String URL_NETWORK_UUID = "/networks/{networkUuid}"; + private static final String STR_SUBSTATION = "substation"; + private static final String STR_VOLTAGE_LEVEL = "voltage level"; + private static final String STR_BUSBAR_SECTION = "busbar section"; + private static final String STR_SWITCH = "switch"; + private static final String STR_GENERATOR = "generator"; + private static final String STR_BATTERY = "battery"; + private static final String STR_SHUNT_COMPENSATOR = "shunt compensator"; + private static final String STR_VSC_CONVERTER_STATION = "VSC converter station"; + private static final String STR_LCC_CONVERTER_STATION = "LCC converter station"; + private static final String STR_STATIC_VAR_COMPENSATOR = "static var compensator"; + private static final String STR_TWO_WINDINGS_TRANSFORMER = "2 windings transformer"; + private static final String STR_THREE_WINDINGS_TRANSFORMER = "3 windings transformer"; + private static final String STR_DANGLING_LINE = "dangling line"; + private static final String STR_HVDC_LINE = "hvdc line"; + private static final String STR_TIE_LINE = "tie line"; private final RestClient restClient; @@ -154,24 +168,24 @@ public List getNetworksInfos() { @Override public void createNetworks(List> networkResources) { - create("network", "/networks", networkResources); + create(STR_NETWORK, "/networks", networkResources); } @Override public List getVariantsInfos(UUID networkUuid) { - return restClient.get("/networks/{networkUuid}", new ParameterizedTypeReference<>() { + return restClient.get(URL_NETWORK_UUID, new ParameterizedTypeReference<>() { }, networkUuid); } @Override public Optional> getNetwork(UUID networkUuid, int variantNum) { - return get("network", "/networks/{networkUuid}/{variantNum}", networkUuid, variantNum); + return get(STR_NETWORK, "/networks/{networkUuid}/{variantNum}", networkUuid, variantNum); } @Override public void deleteNetwork(UUID networkUuid) { LOGGER.info("Removing network {}", networkUuid); - restClient.delete("/networks/{networkUuid}", networkUuid); + restClient.delete(URL_NETWORK_UUID, networkUuid); } @Override @@ -183,7 +197,7 @@ public void deleteNetwork(UUID networkUuid, int variantNum) { @Override public void updateNetworks(List> networkResources, AttributeFilter attributeFilter) { for (Resource networkResource : networkResources) { - updateAll("network", "/networks/{networkUuid}", Collections.singletonList(networkResource), attributeFilter, networkResource.getAttributes().getUuid()); + updateAll(STR_NETWORK, URL_NETWORK_UUID, Collections.singletonList(networkResource), attributeFilter, networkResource.getAttributes().getUuid()); } } @@ -228,22 +242,22 @@ public void cloneNetwork(UUID targetNetworkUuid, UUID sourceNetworkUuid, List> substationResources) { - create("substation", "/networks/{networkUuid}/substations", substationResources, networkUuid); + create(STR_SUBSTATION, "/networks/{networkUuid}/substations", substationResources, networkUuid); } @Override public List> getSubstations(UUID networkUuid, int variantNum) { - return getAll("substation", "/networks/{networkUuid}/{variantNum}/substations", networkUuid, variantNum); + return getAll(STR_SUBSTATION, "/networks/{networkUuid}/{variantNum}/substations", networkUuid, variantNum); } @Override public Optional> getSubstation(UUID networkUuid, int variantNum, String substationId) { - return get("substation", "/networks/{networkUuid}/{variantNum}/substations/{substationId}", networkUuid, variantNum, substationId); + return get(STR_SUBSTATION, "/networks/{networkUuid}/{variantNum}/substations/{substationId}", networkUuid, variantNum, substationId); } @Override public void updateSubstations(UUID networkUuid, List> substationResources, AttributeFilter attributeFilter) { - updateAll("substation", "/networks/{networkUuid}/substations", substationResources, attributeFilter, networkUuid); + updateAll(STR_SUBSTATION, "/networks/{networkUuid}/substations", substationResources, attributeFilter, networkUuid); } public void removeSubstations(UUID networkUuid, int variantNum, List substationsId) { @@ -254,27 +268,27 @@ public void removeSubstations(UUID networkUuid, int variantNum, List sub @Override public void createVoltageLevels(UUID networkUuid, List> voltageLevelResources) { - create("voltage level", "/networks/{networkUuid}/voltage-levels", voltageLevelResources, networkUuid); + create(STR_VOLTAGE_LEVEL, "/networks/{networkUuid}/voltage-levels", voltageLevelResources, networkUuid); } @Override public Optional> getVoltageLevel(UUID networkUuid, int variantNum, String voltageLevelId) { - return get("voltage level", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}", networkUuid, variantNum, voltageLevelId); + return get(STR_VOLTAGE_LEVEL, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}", networkUuid, variantNum, voltageLevelId); } @Override public List> getVoltageLevels(UUID networkUuid, int variantNum) { - return getAll("voltage level", "/networks/{networkUuid}/{variantNum}/voltage-levels", networkUuid, variantNum); + return getAll(STR_VOLTAGE_LEVEL, "/networks/{networkUuid}/{variantNum}/voltage-levels", networkUuid, variantNum); } @Override public List> getVoltageLevelsInSubstation(UUID networkUuid, int variantNum, String substationId) { - return getAll("voltage level", "/networks/{networkUuid}/{variantNum}/substations/{substationId}/voltage-levels", networkUuid, variantNum, substationId); + return getAll(STR_VOLTAGE_LEVEL, "/networks/{networkUuid}/{variantNum}/substations/{substationId}/voltage-levels", networkUuid, variantNum, substationId); } @Override public void updateVoltageLevels(UUID networkUuid, List> voltageLevelsResources, AttributeFilter attributeFilter) { - updateAll("voltage level", "/networks/{networkUuid}/voltage-levels", voltageLevelsResources, attributeFilter, networkUuid); + updateAll(STR_VOLTAGE_LEVEL, "/networks/{networkUuid}/voltage-levels", voltageLevelsResources, attributeFilter, networkUuid); } @Override @@ -284,7 +298,7 @@ public void removeVoltageLevels(UUID networkUuid, int variantNum, List v @Override public List> getVoltageLevelBusbarSections(UUID networkUuid, int variantNum, String voltageLevelId) { - return getAll("busbar section", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/busbar-sections", networkUuid, variantNum, voltageLevelId); + return getAll(STR_BUSBAR_SECTION, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/busbar-sections", networkUuid, variantNum, voltageLevelId); } @Override @@ -294,12 +308,12 @@ public void removeBusBarSections(UUID networkUuid, int variantNum, List @Override public List> getVoltageLevelSwitches(UUID networkUuid, int variantNum, String voltageLevelId) { - return getAll("switch", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/switches", networkUuid, variantNum, voltageLevelId); + return getAll(STR_SWITCH, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/switches", networkUuid, variantNum, voltageLevelId); } @Override public List> getVoltageLevelGenerators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getAll("generator", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/generators", networkUuid, variantNum, voltageLevelId); + return getAll(STR_GENERATOR, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/generators", networkUuid, variantNum, voltageLevelId); } @Override @@ -309,7 +323,7 @@ public void removeGenerators(UUID networkUuid, int variantNum, List gene @Override public List> getVoltageLevelBatteries(UUID networkUuid, int variantNum, String voltageLevelId) { - return getAll("battery", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/batteries", networkUuid, variantNum, voltageLevelId); + return getAll(STR_BATTERY, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/batteries", networkUuid, variantNum, voltageLevelId); } @Override @@ -324,7 +338,7 @@ public List> getVoltageLevelLoads(UUID networkUuid, int @Override public List> getVoltageLevelShuntCompensators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getAll("shunt compensator", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/shunt-compensators", networkUuid, variantNum, voltageLevelId); + return getAll(STR_SHUNT_COMPENSATOR, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/shunt-compensators", networkUuid, variantNum, voltageLevelId); } @Override @@ -334,7 +348,7 @@ public void removeShuntCompensators(UUID networkUuid, int variantNum, List> getVoltageLevelVscConverterStations(UUID networkUuid, int variantNum, String voltageLevelId) { - return getAll("VSC converter station", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/vsc-converter-stations", networkUuid, variantNum, voltageLevelId); + return getAll(STR_VSC_CONVERTER_STATION, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/vsc-converter-stations", networkUuid, variantNum, voltageLevelId); } @Override @@ -344,7 +358,7 @@ public void removeVscConverterStations(UUID networkUuid, int variantNum, List> getVoltageLevelStaticVarCompensators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getAll("static var compensator", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/static-var-compensators", networkUuid, variantNum, voltageLevelId); + return getAll(STR_STATIC_VAR_COMPENSATOR, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/static-var-compensators", networkUuid, variantNum, voltageLevelId); } @Override @@ -354,7 +368,7 @@ public void removeStaticVarCompensators(UUID networkUuid, int variantNum, List> getVoltageLevelLccConverterStations(UUID networkUuid, int variantNum, String voltageLevelId) { - return getAll("LCC converter station", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/lcc-converter-stations", networkUuid, variantNum, voltageLevelId); + return getAll(STR_LCC_CONVERTER_STATION, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/lcc-converter-stations", networkUuid, variantNum, voltageLevelId); } @Override @@ -364,7 +378,7 @@ public void removeLccConverterStations(UUID networkUuid, int variantNum, List> getVoltageLevelTwoWindingsTransformers(UUID networkUuid, int variantNum, String voltageLevelId) { - return getAll("2 windings transformer", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/2-windings-transformers", networkUuid, variantNum, voltageLevelId); + return getAll(STR_TWO_WINDINGS_TRANSFORMER, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/2-windings-transformers", networkUuid, variantNum, voltageLevelId); } @Override @@ -374,7 +388,7 @@ public void removeTwoWindingsTransformers(UUID networkUuid, int variantNum, List @Override public List> getVoltageLevelThreeWindingsTransformers(UUID networkUuid, int variantNum, String voltageLevelId) { - return getAll("3 windings transformer", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/3-windings-transformers", networkUuid, variantNum, voltageLevelId); + return getAll(STR_THREE_WINDINGS_TRANSFORMER, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/3-windings-transformers", networkUuid, variantNum, voltageLevelId); } @Override @@ -394,24 +408,24 @@ public void removeLines(UUID networkUuid, int variantNum, List linesId) @Override public List> getVoltageLevelDanglingLines(UUID networkUuid, int variantNum, String voltageLevelId) { - return getAll("dangling line", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/dangling-lines", networkUuid, variantNum, voltageLevelId); + return getAll(STR_DANGLING_LINE, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/dangling-lines", networkUuid, variantNum, voltageLevelId); } // switch @Override public void createSwitches(UUID networkUuid, List> switchResources) { - create("switch", "/networks/{networkUuid}/switches", switchResources, networkUuid); + create(STR_SWITCH, "/networks/{networkUuid}/switches", switchResources, networkUuid); } @Override public List> getSwitches(UUID networkUuid, int variantNum) { - return getAll("switch", "/networks/{networkUuid}/{variantNum}/switches", networkUuid, variantNum); + return getAll(STR_SWITCH, "/networks/{networkUuid}/{variantNum}/switches", networkUuid, variantNum); } @Override public Optional> getSwitch(UUID networkUuid, int variantNum, String switchId) { - return get("switch", "/networks/{networkUuid}/{variantNum}/switches/{switchId}", networkUuid, variantNum, switchId); + return get(STR_SWITCH, "/networks/{networkUuid}/{variantNum}/switches/{switchId}", networkUuid, variantNum, switchId); } @Override @@ -428,22 +442,22 @@ public void removeSwitches(UUID networkUuid, int variantNum, List switch @Override public void createBusbarSections(UUID networkUuid, List> busbarSectionResources) { - create("busbar section", "/networks/{networkUuid}/busbar-sections", busbarSectionResources, networkUuid); + create(STR_BUSBAR_SECTION, "/networks/{networkUuid}/busbar-sections", busbarSectionResources, networkUuid); } @Override public List> getBusbarSections(UUID networkUuid, int variantNum) { - return getAll("busbar section", "/networks/{networkUuid}/{variantNum}/busbar-sections", networkUuid, variantNum); + return getAll(STR_BUSBAR_SECTION, "/networks/{networkUuid}/{variantNum}/busbar-sections", networkUuid, variantNum); } @Override public Optional> getBusbarSection(UUID networkUuid, int variantNum, String busbarSectionId) { - return get("busbar section", "/networks/{networkUuid}/{variantNum}/busbar-sections/{busbarSectionId}", networkUuid, variantNum, busbarSectionId); + return get(STR_BUSBAR_SECTION, "/networks/{networkUuid}/{variantNum}/busbar-sections/{busbarSectionId}", networkUuid, variantNum, busbarSectionId); } @Override public void updateBusbarSections(UUID networkUuid, List> busbarSectionResources, AttributeFilter attributeFilter) { - updateAll("busbar section", "/networks/{networkUuid}/busbar-sections", busbarSectionResources, attributeFilter, networkUuid); + updateAll(STR_BUSBAR_SECTION, "/networks/{networkUuid}/busbar-sections", busbarSectionResources, attributeFilter, networkUuid); } // load @@ -477,88 +491,88 @@ public void removeLoads(UUID networkUuid, int variantNum, List loadsId) @Override public void createGenerators(UUID networkUuid, List> generatorResources) { - create("generator", "/networks/{networkUuid}/generators", generatorResources, networkUuid); + create(STR_GENERATOR, "/networks/{networkUuid}/generators", generatorResources, networkUuid); } @Override public List> getGenerators(UUID networkUuid, int variantNum) { - return getAll("generator", "/networks/{networkUuid}/{variantNum}/generators", networkUuid, variantNum); + return getAll(STR_GENERATOR, "/networks/{networkUuid}/{variantNum}/generators", networkUuid, variantNum); } @Override public Optional> getGenerator(UUID networkUuid, int variantNum, String generatorId) { - return get("generator", "/networks/{networkUuid}/{variantNum}/generators/{generatorId}", networkUuid, variantNum, generatorId); + return get(STR_GENERATOR, "/networks/{networkUuid}/{variantNum}/generators/{generatorId}", networkUuid, variantNum, generatorId); } @Override public void updateGenerators(UUID networkUuid, List> generatorResources, AttributeFilter attributeFilter) { - updateAll("generator", "/networks/{networkUuid}/generators", generatorResources, attributeFilter, networkUuid); + updateAll(STR_GENERATOR, "/networks/{networkUuid}/generators", generatorResources, attributeFilter, networkUuid); } // battery @Override public void createBatteries(UUID networkUuid, List> batteryResources) { - create("battery", "/networks/{networkUuid}/batteries", batteryResources, networkUuid); + create(STR_BATTERY, "/networks/{networkUuid}/batteries", batteryResources, networkUuid); } @Override public List> getBatteries(UUID networkUuid, int variantNum) { - return getAll("battery", "/networks/{networkUuid}/{variantNum}/batteries", networkUuid, variantNum); + return getAll(STR_BATTERY, "/networks/{networkUuid}/{variantNum}/batteries", networkUuid, variantNum); } @Override public Optional> getBattery(UUID networkUuid, int variantNum, String batteryId) { - return get("battery", "/networks/{networkUuid}/{variantNum}/batteries/{batteryId}", networkUuid, variantNum, batteryId); + return get(STR_BATTERY, "/networks/{networkUuid}/{variantNum}/batteries/{batteryId}", networkUuid, variantNum, batteryId); } @Override public void updateBatteries(UUID networkUuid, List> batteryResources, AttributeFilter attributeFilter) { - updateAll("battery", "/networks/{networkUuid}/batteries", batteryResources, attributeFilter, networkUuid); + updateAll(STR_BATTERY, "/networks/{networkUuid}/batteries", batteryResources, attributeFilter, networkUuid); } // 2 windings transformer @Override public void createTwoWindingsTransformers(UUID networkUuid, List> twoWindingsTransformerResources) { - create("2 windings transformer", "/networks/{networkUuid}/2-windings-transformers", twoWindingsTransformerResources, networkUuid); + create(STR_TWO_WINDINGS_TRANSFORMER, "/networks/{networkUuid}/2-windings-transformers", twoWindingsTransformerResources, networkUuid); } @Override public List> getTwoWindingsTransformers(UUID networkUuid, int variantNum) { - return getAll("2 windings transformer", "/networks/{networkUuid}/{variantNum}/2-windings-transformers", networkUuid, variantNum); + return getAll(STR_TWO_WINDINGS_TRANSFORMER, "/networks/{networkUuid}/{variantNum}/2-windings-transformers", networkUuid, variantNum); } @Override public Optional> getTwoWindingsTransformer(UUID networkUuid, int variantNum, String twoWindingsTransformerId) { - return get("2 windings transformer", "/networks/{networkUuid}/{variantNum}/2-windings-transformers/{twoWindingsTransformerId}", networkUuid, variantNum, twoWindingsTransformerId); + return get(STR_TWO_WINDINGS_TRANSFORMER, "/networks/{networkUuid}/{variantNum}/2-windings-transformers/{twoWindingsTransformerId}", networkUuid, variantNum, twoWindingsTransformerId); } @Override public void updateTwoWindingsTransformers(UUID networkUuid, List> twoWindingsTransformerResources, AttributeFilter attributeFilter) { - updateAll("2 windings transformer", "/networks/{networkUuid}/2-windings-transformers", twoWindingsTransformerResources, attributeFilter, networkUuid); + updateAll(STR_TWO_WINDINGS_TRANSFORMER, "/networks/{networkUuid}/2-windings-transformers", twoWindingsTransformerResources, attributeFilter, networkUuid); } // 3 windings transformer @Override public void createThreeWindingsTransformers(UUID networkUuid, List> threeWindingsTransformerResources) { - create("3 windings transformer", "/networks/{networkUuid}/3-windings-transformers", threeWindingsTransformerResources, networkUuid); + create(STR_THREE_WINDINGS_TRANSFORMER, "/networks/{networkUuid}/3-windings-transformers", threeWindingsTransformerResources, networkUuid); } @Override public List> getThreeWindingsTransformers(UUID networkUuid, int variantNum) { - return getAll("3 windings transformer", "/networks/{networkUuid}/{variantNum}/3-windings-transformers", networkUuid, variantNum); + return getAll(STR_THREE_WINDINGS_TRANSFORMER, "/networks/{networkUuid}/{variantNum}/3-windings-transformers", networkUuid, variantNum); } @Override public Optional> getThreeWindingsTransformer(UUID networkUuid, int variantNum, String threeWindingsTransformerId) { - return get("3 windings transformer", "/networks/{networkUuid}/{variantNum}/3-windings-transformers/{threeWindingsTransformerId}", networkUuid, variantNum, threeWindingsTransformerId); + return get(STR_THREE_WINDINGS_TRANSFORMER, "/networks/{networkUuid}/{variantNum}/3-windings-transformers/{threeWindingsTransformerId}", networkUuid, variantNum, threeWindingsTransformerId); } @Override public void updateThreeWindingsTransformers(UUID networkUuid, List> threeWindingsTransformerResources, AttributeFilter attributeFilter) { - updateAll("3 windings transformer", "/networks/{networkUuid}/3-windings-transformers", threeWindingsTransformerResources, attributeFilter, networkUuid); + updateAll(STR_THREE_WINDINGS_TRANSFORMER, "/networks/{networkUuid}/3-windings-transformers", threeWindingsTransformerResources, attributeFilter, networkUuid); } // line @@ -587,78 +601,78 @@ public void updateLines(UUID networkUuid, List> lineRes @Override public void createShuntCompensators(UUID networkUuid, List> shuntCompensatorResources) { - create("shunt compensator", "/networks/{networkUuid}/shunt-compensators", shuntCompensatorResources, networkUuid); + create(STR_SHUNT_COMPENSATOR, "/networks/{networkUuid}/shunt-compensators", shuntCompensatorResources, networkUuid); } @Override public List> getShuntCompensators(UUID networkUuid, int variantNum) { - return getAll("shunt compensator", "/networks/{networkUuid}/{variantNum}/shunt-compensators", networkUuid, variantNum); + return getAll(STR_SHUNT_COMPENSATOR, "/networks/{networkUuid}/{variantNum}/shunt-compensators", networkUuid, variantNum); } @Override public Optional> getShuntCompensator(UUID networkUuid, int variantNum, String shuntCompensatorId) { - return get("shunt compensator", "/networks/{networkUuid}/{variantNum}/shunt-compensators/{shuntCompensatorId}", networkUuid, variantNum, shuntCompensatorId); + return get(STR_SHUNT_COMPENSATOR, "/networks/{networkUuid}/{variantNum}/shunt-compensators/{shuntCompensatorId}", networkUuid, variantNum, shuntCompensatorId); } @Override public void updateShuntCompensators(UUID networkUuid, List> shuntCompensatorResources, AttributeFilter attributeFilter) { - updateAll("shunt compensator", "/networks/{networkUuid}/shunt-compensators", shuntCompensatorResources, attributeFilter, networkUuid); + updateAll(STR_SHUNT_COMPENSATOR, "/networks/{networkUuid}/shunt-compensators", shuntCompensatorResources, attributeFilter, networkUuid); } // VSC converter station @Override public void createVscConverterStations(UUID networkUuid, List> vscConverterStationResources) { - create("VSC converter station", "/networks/{networkUuid}/vsc-converter-stations", vscConverterStationResources, networkUuid); + create(STR_VSC_CONVERTER_STATION, "/networks/{networkUuid}/vsc-converter-stations", vscConverterStationResources, networkUuid); } @Override public List> getVscConverterStations(UUID networkUuid, int variantNum) { - return getAll("VSC converter station", "/networks/{networkUuid}/{variantNum}/vsc-converter-stations", networkUuid, variantNum); + return getAll(STR_VSC_CONVERTER_STATION, "/networks/{networkUuid}/{variantNum}/vsc-converter-stations", networkUuid, variantNum); } @Override public Optional> getVscConverterStation(UUID networkUuid, int variantNum, String vscConverterStationId) { - return get("VSC converter station", "/networks/{networkUuid}/{variantNum}/vsc-converter-stations/{vscConverterStationId}", networkUuid, variantNum, vscConverterStationId); + return get(STR_VSC_CONVERTER_STATION, "/networks/{networkUuid}/{variantNum}/vsc-converter-stations/{vscConverterStationId}", networkUuid, variantNum, vscConverterStationId); } @Override public void updateVscConverterStations(UUID networkUuid, List> vscConverterStationResources, AttributeFilter attributeFilter) { - updateAll("VSC converter station", "/networks/{networkUuid}/vsc-converter-stations", vscConverterStationResources, attributeFilter, networkUuid); + updateAll(STR_VSC_CONVERTER_STATION, "/networks/{networkUuid}/vsc-converter-stations", vscConverterStationResources, attributeFilter, networkUuid); } // LCC converter station @Override public void createLccConverterStations(UUID networkUuid, List> lccConverterStationResources) { - create("LCC converter station", "/networks/{networkUuid}/lcc-converter-stations", lccConverterStationResources, networkUuid); + create(STR_LCC_CONVERTER_STATION, "/networks/{networkUuid}/lcc-converter-stations", lccConverterStationResources, networkUuid); } @Override public List> getLccConverterStations(UUID networkUuid, int variantNum) { - return getAll("LCC converter station", "/networks/{networkUuid}/{variantNum}/lcc-converter-stations", networkUuid, variantNum); + return getAll(STR_LCC_CONVERTER_STATION, "/networks/{networkUuid}/{variantNum}/lcc-converter-stations", networkUuid, variantNum); } @Override public Optional> getLccConverterStation(UUID networkUuid, int variantNum, String lccConverterStationId) { - return get("LCC converter station", "/networks/{networkUuid}/{variantNum}/lcc-converter-stations/{vscConverterStationId}", networkUuid, variantNum, lccConverterStationId); + return get(STR_LCC_CONVERTER_STATION, "/networks/{networkUuid}/{variantNum}/lcc-converter-stations/{vscConverterStationId}", networkUuid, variantNum, lccConverterStationId); } @Override public void updateLccConverterStations(UUID networkUuid, List> lccConverterStationResources, AttributeFilter attributeFilter) { - updateAll("LCC converter station", "/networks/{networkUuid}/lcc-converter-stations", lccConverterStationResources, attributeFilter, networkUuid); + updateAll(STR_LCC_CONVERTER_STATION, "/networks/{networkUuid}/lcc-converter-stations", lccConverterStationResources, attributeFilter, networkUuid); } // SVC @Override public void createStaticVarCompensators(UUID networkUuid, List> staticVarCompensatorResources) { - create("static var compensator", "/networks/{networkUuid}/static-var-compensators", staticVarCompensatorResources, networkUuid); + create(STR_STATIC_VAR_COMPENSATOR, "/networks/{networkUuid}/static-var-compensators", staticVarCompensatorResources, networkUuid); } @Override public List> getStaticVarCompensators(UUID networkUuid, int variantNum) { - return getAll("static var compensator", "/networks/{networkUuid}/{variantNum}/static-var-compensators", networkUuid, variantNum); + return getAll(STR_STATIC_VAR_COMPENSATOR, "/networks/{networkUuid}/{variantNum}/static-var-compensators", networkUuid, variantNum); } @Override @@ -668,24 +682,24 @@ public Optional> getStaticVarCompensato @Override public void updateStaticVarCompensators(UUID networkUuid, List> staticVarCompensatorResources, AttributeFilter attributeFilter) { - updateAll("static var compensator", "/networks/{networkUuid}/static-var-compensators", staticVarCompensatorResources, attributeFilter, networkUuid); + updateAll(STR_STATIC_VAR_COMPENSATOR, "/networks/{networkUuid}/static-var-compensators", staticVarCompensatorResources, attributeFilter, networkUuid); } // HVDC line @Override public void createHvdcLines(UUID networkUuid, List> hvdcLineResources) { - create("hvdc line", "/networks/{networkUuid}/hvdc-lines", hvdcLineResources, networkUuid); + create(STR_HVDC_LINE, "/networks/{networkUuid}/hvdc-lines", hvdcLineResources, networkUuid); } @Override public List> getHvdcLines(UUID networkUuid, int variantNum) { - return getAll("hvdc line", "/networks/{networkUuid}/{variantNum}/hvdc-lines", networkUuid, variantNum); + return getAll(STR_HVDC_LINE, "/networks/{networkUuid}/{variantNum}/hvdc-lines", networkUuid, variantNum); } @Override public Optional> getHvdcLine(UUID networkUuid, int variantNum, String hvdcLineId) { - return get("hvdc line", "/networks/{networkUuid}/{variantNum}/hvdc-lines/{hvdcLineId}", networkUuid, variantNum, hvdcLineId); + return get(STR_HVDC_LINE, "/networks/{networkUuid}/{variantNum}/hvdc-lines/{hvdcLineId}", networkUuid, variantNum, hvdcLineId); } @Override @@ -695,24 +709,24 @@ public void removeHvdcLines(UUID networkUuid, int variantNum, List hvdcL @Override public void updateHvdcLines(UUID networkUuid, List> hvdcLineResources, AttributeFilter attributeFilter) { - updateAll("hvdc line", "/networks/{networkUuid}/hvdc-lines", hvdcLineResources, attributeFilter, networkUuid); + updateAll(STR_HVDC_LINE, "/networks/{networkUuid}/hvdc-lines", hvdcLineResources, attributeFilter, networkUuid); } // Dangling line @Override public void createDanglingLines(UUID networkUuid, List> danglingLineResources) { - create("dangling line", "/networks/{networkUuid}/dangling-lines", danglingLineResources, networkUuid); + create(STR_DANGLING_LINE, "/networks/{networkUuid}/dangling-lines", danglingLineResources, networkUuid); } @Override public List> getDanglingLines(UUID networkUuid, int variantNum) { - return getAll("dangling line", "/networks/{networkUuid}/{variantNum}/dangling-lines", networkUuid, variantNum); + return getAll(STR_DANGLING_LINE, "/networks/{networkUuid}/{variantNum}/dangling-lines", networkUuid, variantNum); } @Override public Optional> getDanglingLine(UUID networkUuid, int variantNum, String danglingLineId) { - return get("dangling line", "/networks/{networkUuid}/{variantNum}/dangling-lines/{danglingLineId}", networkUuid, variantNum, danglingLineId); + return get(STR_DANGLING_LINE, "/networks/{networkUuid}/{variantNum}/dangling-lines/{danglingLineId}", networkUuid, variantNum, danglingLineId); } @Override @@ -722,7 +736,7 @@ public void removeDanglingLines(UUID networkUuid, int variantNum, List d @Override public void updateDanglingLines(UUID networkUuid, List> danglingLineResources, AttributeFilter attributeFilter) { - updateAll("dangling line", "/networks/{networkUuid}/dangling-lines", danglingLineResources, attributeFilter, networkUuid); + updateAll(STR_DANGLING_LINE, "/networks/{networkUuid}/dangling-lines", danglingLineResources, attributeFilter, networkUuid); } //ConfiguredBus @@ -759,17 +773,17 @@ public void removeConfiguredBuses(UUID networkUuid, int variantNum, List @Override public void createTieLines(UUID networkUuid, List> tieLineResources) { - create("tie line", "/networks/{networkUuid}/tie-lines", tieLineResources, networkUuid); + create(STR_TIE_LINE, "/networks/{networkUuid}/tie-lines", tieLineResources, networkUuid); } @Override public List> getTieLines(UUID networkUuid, int variantNum) { - return getAll("tie line", "/networks/{networkUuid}/{variantNum}/tie-lines", networkUuid, variantNum); + return getAll(STR_TIE_LINE, "/networks/{networkUuid}/{variantNum}/tie-lines", networkUuid, variantNum); } @Override public Optional> getTieLine(UUID networkUuid, int variantNum, String tieLineId) { - return get("tie line", "/networks/{networkUuid}/{variantNum}/tie-lines/{tieLineId}", networkUuid, variantNum, tieLineId); + return get(STR_TIE_LINE, "/networks/{networkUuid}/{variantNum}/tie-lines/{tieLineId}", networkUuid, variantNum, tieLineId); } @Override @@ -779,7 +793,7 @@ public void removeTieLines(UUID networkUuid, int variantNum, List tieLin @Override public void updateTieLines(UUID networkUuid, List> tieLineResources, AttributeFilter attributeFilter) { - updateAll("tie line", "/networks/{networkUuid}/tie-lines", tieLineResources, attributeFilter, networkUuid); + updateAll(STR_TIE_LINE, "/networks/{networkUuid}/tie-lines", tieLineResources, attributeFilter, networkUuid); } @Override 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 97f355f41..0af881424 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 @@ -254,6 +254,10 @@ public boolean connect(Predicate isTypeSwitchToOperate) { getAbstractIdentifiable().updateResource(r -> { var a = getAttributes(r); 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()); @@ -286,9 +290,10 @@ public boolean connect() { /** * Add the first openable switch in the given path to the set of switches to open - * @param path the path to open + * + * @param path the path to open * @param isSwitchOpenable predicate used to know if a switch can be opened - * @param switchesToOpen set of switches to be opened + * @param switchesToOpen set of switches to be opened * @return true if the path has been opened, else false */ boolean identifySwitchToOpenPath(GraphPath path, Predicate isSwitchOpenable, Set switchesToOpen) { @@ -361,9 +366,13 @@ public boolean disconnect(Predicate isSwitchOpenable) { } else { // TopologyKind.BUS_BREAKER var attributes = getAttributes(); if (attributes.getBus() != null) { - getAbstractIdentifiable().updateResource(r -> { - var a = getAttributes(r); + getAbstractIdentifiable().updateResource(resource -> { + var a = getAttributes(resource); 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); @@ -448,20 +457,18 @@ boolean traverse(Terminal.TopologyTraverser traverser, Set traversedTe } TopologyKind topologyKind = getTopologyKind(); - switch (topologyKind) { - case NODE_BREAKER: - return ((NodeBreakerViewImpl) voltageLevel.getNodeBreakerView()).traverseFromTerminal(this, traverser, traversedTerminals, traversalType); - case BUS_BREAKER: - return ((BusBreakerViewImpl) voltageLevel.getBusBreakerView()).traverseFromTerminal(this, traverser, traversedTerminals, traversalType); - default: - throw new IllegalStateException("Unknown topology kind: " + topologyKind); - } + return switch (topologyKind) { + case NODE_BREAKER -> + ((NodeBreakerViewImpl) voltageLevel.getNodeBreakerView()).traverseFromTerminal(this, traverser, traversedTerminals, traversalType); + case BUS_BREAKER -> + ((BusBreakerViewImpl) voltageLevel.getBusBreakerView()).traverseFromTerminal(this, traverser, traversedTerminals, traversalType); + default -> throw new IllegalStateException("Unknown topology kind: " + topologyKind); + }; } Set getOtherSideTerminals() { Set otherTerminals = new HashSet<>(); - if (getConnectable() instanceof Branch) { - Branch branch = (Branch) getConnectable(); + if (getConnectable() instanceof Branch branch) { if (branch.getTerminal1() == this) { otherTerminals.add(branch.getTerminal2()); } else if (branch.getTerminal2() == this) { @@ -469,8 +476,7 @@ Set getOtherSideTerminals() { } else { throw new AssertionError(); } - } else if (getConnectable() instanceof ThreeWindingsTransformer) { - ThreeWindingsTransformer ttc = (ThreeWindingsTransformer) getConnectable(); + } else if (getConnectable() instanceof ThreeWindingsTransformer ttc) { if (ttc.getLeg1().getTerminal() == this) { otherTerminals.add(ttc.getLeg2().getTerminal()); otherTerminals.add(ttc.getLeg3().getTerminal()); diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NodeBreakerTerminalTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NodeBreakerTerminalTest.java index a1ffebc24..d270526ea 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NodeBreakerTerminalTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NodeBreakerTerminalTest.java @@ -7,13 +7,11 @@ package com.powsybl.network.store.iidm.impl; import com.powsybl.commons.PowsyblException; -import com.powsybl.iidm.network.*; -import com.powsybl.iidm.network.tck.AbstractNodeBreakerTest; +import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.Terminal; +import com.powsybl.iidm.network.VoltageLevel; import org.junit.Test; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - import static org.junit.Assert.*; /** diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/NodeBreakerDisconnectionDiamondPathBugTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/NodeBreakerDisconnectionDiamondPathBugTest.java index 5c39e2f93..2341bb413 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/NodeBreakerDisconnectionDiamondPathBugTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/NodeBreakerDisconnectionDiamondPathBugTest.java @@ -6,12 +6,7 @@ */ package com.powsybl.network.store.iidm.impl.tck; -import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.tck.AbstractNodeBreakerDisconnectionDiamondPathBugTest; -import org.junit.Test; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; /** * @author Geoffroy Jamgotchian diff --git a/network-store-model/pom.xml b/network-store-model/pom.xml index c687d375b..5ceba41c4 100644 --- a/network-store-model/pom.xml +++ b/network-store-model/pom.xml @@ -47,10 +47,6 @@ com.fasterxml.jackson.core jackson-databind - - com.fasterxml.jackson.datatype - jackson-datatype-joda - io.swagger.core.v3 swagger-annotations-jakarta From 1a06637a0b6e08626a6266f0f76685dc87384c19 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Thu, 30 Nov 2023 14:52:39 +0100 Subject: [PATCH 04/27] added javadoc Signed-off-by: Nicolas Rol --- .../network/store/iidm/impl/TerminalImpl.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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 0af881424..39eb4b446 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 @@ -237,6 +237,13 @@ private boolean connectNodeBreaker(Resource voltageLevel return done; } + /** + * Try to connect the terminal.
+ * Depends on the working variant. + * @param isTypeSwitchToOperate Predicate telling if a switch is considered operable. Examples of predicates are available in the class {@link SwitchPredicates} + * @return true if terminal has been connected, false otherwise + * @see VariantManager + */ @Override public boolean connect(Predicate isTypeSwitchToOperate) { boolean done = false; @@ -283,6 +290,13 @@ public boolean connect(Predicate isTypeSwitchToOperate) { return done; } + /** + * Try to connect the terminal, using by default the {@link SwitchPredicates} IS_NONFICTIONAL_BREAKER.
+ * Depends on the working variant. + * @param isTypeSwitchToOperate Predicate telling if a switch is considered operable. Examples of predicates are available in the class {@link SwitchPredicates} + * @return true if terminal has been connected, false otherwise + * @see VariantManager + */ @Override public boolean connect() { return connect(SwitchPredicates.IS_NONFICTIONAL_BREAKER); @@ -352,6 +366,13 @@ private boolean disconnectNodeBreaker(Resource voltageLe return true; } + /** + * Disconnect the terminal.
+ * Depends on the working variant. + * @param isSwitchOpenable Predicate telling if a switch is considered openable. Examples of predicates are available in the class {@link SwitchPredicates} + * @return true if terminal has been disconnected, false otherwise + * @see VariantManager + */ @Override public boolean disconnect(Predicate isSwitchOpenable) { boolean done = false; @@ -398,6 +419,13 @@ public boolean disconnect(Predicate isSwitchOpenable) { return done; } + + /** + * Disconnect the terminal, using by default the {@link SwitchPredicates} IS_CLOSED_BREAKER.
+ * Depends on the working variant. + * @return true if terminal has been disconnected, false otherwise + * @see VariantManager + */ @Override public boolean disconnect() { return disconnect(SwitchPredicates.IS_CLOSED_BREAKER); From 2cf7713fafe130b0a6d3568991c74675d8b8ce15 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Thu, 30 Nov 2023 14:53:32 +0100 Subject: [PATCH 05/27] added javadoc Signed-off-by: Nicolas Rol --- .../java/com/powsybl/network/store/iidm/impl/TerminalImpl.java | 1 - 1 file changed, 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 39eb4b446..b03c1464d 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 @@ -293,7 +293,6 @@ public boolean connect(Predicate isTypeSwitchToOperate) { /** * Try to connect the terminal, using by default the {@link SwitchPredicates} IS_NONFICTIONAL_BREAKER.
* Depends on the working variant. - * @param isTypeSwitchToOperate Predicate telling if a switch is considered operable. Examples of predicates are available in the class {@link SwitchPredicates} * @return true if terminal has been connected, false otherwise * @see VariantManager */ From 58e2063bc6661352507e3c6ff8213a6b57f2e9c3 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Thu, 30 Nov 2023 14:54:50 +0100 Subject: [PATCH 06/27] fix Signed-off-by: Nicolas Rol --- .../java/com/powsybl/network/store/iidm/impl/TerminalImpl.java | 1 - 1 file changed, 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 b03c1464d..750888d11 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 @@ -418,7 +418,6 @@ public boolean disconnect(Predicate isSwitchOpenable) { return done; } - /** * Disconnect the terminal, using by default the {@link SwitchPredicates} IS_CLOSED_BREAKER.
* Depends on the working variant. From dee1cfc472ac1844c0fafe5b9dfa612b5f5bec87 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Thu, 30 Nov 2023 14:56:04 +0100 Subject: [PATCH 07/27] delete unused method Signed-off-by: Nicolas Rol --- .../network/store/iidm/impl/TerminalImpl.java | 12 ------------ 1 file changed, 12 deletions(-) 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 750888d11..94b21148a 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 @@ -149,18 +149,6 @@ private Set getBusbarSectionNodes(Resource volt .collect(Collectors.toSet()); } - private static Graph filterSwitches(Graph graph, Predicate filter) { - return new AsSubgraph<>(graph, null, graph.edgeSet() - .stream() - .filter(edge -> { - if (edge.getBiConnectable() instanceof SwitchAttributes switchAttributes) { - return filter.test(switchAttributes); - } - return true; - }) - .collect(Collectors.toSet())); - } - private double computeEdgeWeight(Edge edge, Predicate openOperableSwitch) { if (edge.getBiConnectable() instanceof SwitchAttributes switchAttributes) { // Get the switch behind the switchAttributes From 0608922512b003fa1ee100417ee272f516aca20f Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Thu, 30 Nov 2023 14:57:44 +0100 Subject: [PATCH 08/27] fix imports Signed-off-by: Nicolas Rol --- .../java/com/powsybl/network/store/iidm/impl/TerminalImpl.java | 1 - 1 file changed, 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 94b21148a..873c4b015 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 @@ -15,7 +15,6 @@ import org.jgrapht.Graph; import org.jgrapht.GraphPath; import org.jgrapht.alg.shortestpath.AllDirectedPaths; -import org.jgrapht.graph.AsSubgraph; import org.jgrapht.graph.AsWeightedGraph; import java.util.*; From 1cfe1d17d880f1dd0db6fa4857ffa79e4b7fa1f0 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 6 Dec 2023 13:53:10 +0100 Subject: [PATCH 09/27] replaced BranchStatus with OperatingStatus + delete duplicated dependency Signed-off-by: Nicolas Rol --- .../store/iidm/impl/AbstractBranchImpl.java | 22 ++--- .../impl/ThreeWindingsTransformerImpl.java | 22 ++--- ...mpl.java => OperatingStatusAdderImpl.java} | 24 ++--- ... => OperatingStatusAdderImplProvider.java} | 14 +-- ...atusImpl.java => OperatingStatusImpl.java} | 14 +-- .../iidm/impl/BranchStatusExtensionTest.java | 94 ------------------- .../impl/OperatingStatusExtensionTest.java | 94 +++++++++++++++++++ .../network/store/model/BranchAttributes.java | 2 +- .../network/store/model/LineAttributes.java | 2 +- ...Holder.java => OperatingStatusHolder.java} | 6 +- .../ThreeWindingsTransformerAttributes.java | 4 +- .../TwoWindingsTransformerAttributes.java | 2 +- .../network/store/model/ResourceTest.java | 12 +-- .../store/model/TapChangerParentTest.java | 4 +- pom.xml | 11 +-- 15 files changed, 159 insertions(+), 168 deletions(-) rename network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/{BranchStatusAdderImpl.java => OperatingStatusAdderImpl.java} (52%) rename network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/{BranchStatusAdderImplProvider.java => OperatingStatusAdderImplProvider.java} (61%) rename network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/{BranchStatusImpl.java => OperatingStatusImpl.java} (60%) delete mode 100644 network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/BranchStatusExtensionTest.java create mode 100644 network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/OperatingStatusExtensionTest.java rename network-store-model/src/main/java/com/powsybl/network/store/model/{BranchStatusHolder.java => OperatingStatusHolder.java} (75%) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchImpl.java index 8baef9429..33c954b01 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchImpl.java @@ -8,10 +8,10 @@ import com.powsybl.commons.extensions.Extension; import com.powsybl.iidm.network.*; -import com.powsybl.iidm.network.extensions.BranchStatus; +import com.powsybl.iidm.network.extensions.OperatingStatus; import com.powsybl.iidm.network.extensions.ConnectablePosition; import com.powsybl.iidm.network.util.LimitViolationUtils; -import com.powsybl.network.store.iidm.impl.extensions.BranchStatusImpl; +import com.powsybl.network.store.iidm.impl.extensions.OperatingStatusImpl; import com.powsybl.network.store.model.BranchAttributes; import com.powsybl.network.store.model.LimitsAttributes; import com.powsybl.network.store.model.Resource; @@ -411,11 +411,11 @@ private > E createConnectablePositionExtension() { return extension; } - private > E createBranchStatusExtension() { + private > E createOperatingStatusExtension() { E extension = null; - String branchStatus = getResource().getAttributes().getBranchStatus(); - if (branchStatus != null) { - extension = (E) new BranchStatusImpl(getBranch()); + String operatingStatus = getResource().getAttributes().getOperatingStatus(); + if (operatingStatus != null) { + extension = (E) new OperatingStatusImpl(getBranch()); } return extension; } @@ -425,8 +425,8 @@ public > E getExtension(Class type) { E extension; if (type == ConnectablePosition.class) { extension = createConnectablePositionExtension(); - } else if (type == BranchStatus.class) { - extension = createBranchStatusExtension(); + } else if (type == OperatingStatus.class) { + extension = createOperatingStatusExtension(); } else { extension = super.getExtension(type); } @@ -438,8 +438,8 @@ public > E getExtensionByName(String name) { E extension; if (name.equals("position")) { extension = createConnectablePositionExtension(); - } else if (name.equals("branchStatus")) { - extension = createBranchStatusExtension(); + } else if (name.equals("operatingStatus")) { + extension = createOperatingStatusExtension(); } else { extension = super.getExtensionByName(name); } @@ -453,7 +453,7 @@ public > Collection getExtensions() { if (extension != null) { extensions.add(extension); } - extension = createBranchStatusExtension(); + extension = createOperatingStatusExtension(); if (extension != null) { extensions.add(extension); } 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 2d3a273e1..046a300df 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 @@ -9,11 +9,11 @@ import com.powsybl.cgmes.extensions.CgmesTapChangers; import com.powsybl.commons.extensions.Extension; import com.powsybl.iidm.network.*; -import com.powsybl.iidm.network.extensions.BranchStatus; +import com.powsybl.iidm.network.extensions.OperatingStatus; import com.powsybl.iidm.network.extensions.ConnectablePosition; import com.powsybl.iidm.network.extensions.ThreeWindingsTransformerPhaseAngleClock; import com.powsybl.iidm.network.util.LimitViolationUtils; -import com.powsybl.network.store.iidm.impl.extensions.BranchStatusImpl; +import com.powsybl.network.store.iidm.impl.extensions.OperatingStatusImpl; import com.powsybl.network.store.iidm.impl.extensions.CgmesTapChangersImpl; import com.powsybl.network.store.iidm.impl.extensions.ThreeWindingsTransformerPhaseAngleClockImpl; import com.powsybl.network.store.model.*; @@ -544,12 +544,12 @@ private > E createConnectablePosit return extension; } - private > E createBranchStatusExtension() { + private > E createOperatingStatusExtension() { E extension = null; var resource = getResource(); - String branchStatus = resource.getAttributes().getBranchStatus(); - if (branchStatus != null) { - extension = (E) new BranchStatusImpl(this); + String operatingStatus = resource.getAttributes().getOperatingStatus(); + if (operatingStatus != null) { + extension = (E) new OperatingStatusImpl(this); } return extension; } @@ -561,8 +561,8 @@ public > E getExtension(Class> E getExtensionByName(Stri extension = createConnectablePositionExtension(); } else if (name.equals(ThreeWindingsTransformerPhaseAngleClock.NAME)) { extension = createPhaseAngleClock(); - } else if (name.equals(BranchStatus.NAME)) { - extension = createBranchStatusExtension(); + } else if (name.equals(OperatingStatus.NAME)) { + extension = createOperatingStatusExtension(); } else if (name.equals(CgmesTapChangers.NAME)) { extension = createCgmesTapChangers(); } else { @@ -600,7 +600,7 @@ public > Collection getExtensio if (extension != null) { result.add(extension); } - extension = createBranchStatusExtension(); + extension = createOperatingStatusExtension(); if (extension != null) { result.add(extension); } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/BranchStatusAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java similarity index 52% rename from network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/BranchStatusAdderImpl.java rename to network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java index c7cfa39fb..46a093e1b 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/BranchStatusAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java @@ -8,38 +8,38 @@ import com.powsybl.commons.extensions.AbstractExtensionAdder; import com.powsybl.iidm.network.Connectable; -import com.powsybl.iidm.network.extensions.BranchStatus; -import com.powsybl.iidm.network.extensions.BranchStatusAdder; +import com.powsybl.iidm.network.extensions.OperatingStatus; +import com.powsybl.iidm.network.extensions.OperatingStatusAdder; import com.powsybl.network.store.iidm.impl.AbstractIdentifiableImpl; -import com.powsybl.network.store.model.BranchStatusHolder; +import com.powsybl.network.store.model.OperatingStatusHolder; import java.util.Objects; /** * @author Nicolas Noir */ -public class BranchStatusAdderImpl> - extends AbstractExtensionAdder> implements BranchStatusAdder { +public class OperatingStatusAdderImpl> + extends AbstractExtensionAdder> implements OperatingStatusAdder { - private BranchStatus.Status status = BranchStatus.Status.IN_OPERATION; + private OperatingStatus.Status status = OperatingStatus.Status.IN_OPERATION; - protected BranchStatusAdderImpl(C extendable) { + protected OperatingStatusAdderImpl(C extendable) { super(extendable); } @Override - protected BranchStatus createExtension(C extendable) { + protected OperatingStatus createExtension(C extendable) { ((AbstractIdentifiableImpl) extendable).updateResource(res -> { - if (!(res.getAttributes() instanceof BranchStatusHolder)) { + if (!(res.getAttributes() instanceof OperatingStatusHolder)) { throw new IllegalStateException("Not a branch status holder"); } - ((BranchStatusHolder) res.getAttributes()).setBranchStatus(status.name()); + ((OperatingStatusHolder) res.getAttributes()).setOperatingStatus(status.name()); }); - return new BranchStatusImpl<>(extendable); + return new OperatingStatusImpl<>(extendable); } @Override - public BranchStatusAdder withStatus(BranchStatus.Status status) { + public OperatingStatusAdder withStatus(OperatingStatus.Status status) { this.status = Objects.requireNonNull(status); return this; } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/BranchStatusAdderImplProvider.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImplProvider.java similarity index 61% rename from network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/BranchStatusAdderImplProvider.java rename to network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImplProvider.java index d0865e3b6..830c2fecb 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/BranchStatusAdderImplProvider.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImplProvider.java @@ -9,14 +9,14 @@ import com.google.auto.service.AutoService; import com.powsybl.commons.extensions.ExtensionAdderProvider; import com.powsybl.iidm.network.Connectable; -import com.powsybl.iidm.network.extensions.BranchStatus; +import com.powsybl.iidm.network.extensions.OperatingStatus; /** * @author Nicolas Noir */ @AutoService(ExtensionAdderProvider.class) -public class BranchStatusAdderImplProvider> implements - ExtensionAdderProvider, BranchStatusAdderImpl> { +public class OperatingStatusAdderImplProvider> implements + ExtensionAdderProvider, OperatingStatusAdderImpl> { @Override public String getImplementationName() { @@ -24,13 +24,13 @@ public String getImplementationName() { } @Override - public Class getAdderClass() { - return BranchStatusAdderImpl.class; + public Class getAdderClass() { + return OperatingStatusAdderImpl.class; } @Override - public BranchStatusAdderImpl newAdder(C connectable) { - return new BranchStatusAdderImpl<>(connectable); + public OperatingStatusAdderImpl newAdder(C connectable) { + return new OperatingStatusAdderImpl<>(connectable); } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/BranchStatusImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusImpl.java similarity index 60% rename from network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/BranchStatusImpl.java rename to network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusImpl.java index 5c77304c9..b7cbb9aa0 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/BranchStatusImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusImpl.java @@ -8,28 +8,28 @@ import com.powsybl.commons.extensions.AbstractExtension; import com.powsybl.iidm.network.Connectable; -import com.powsybl.iidm.network.extensions.BranchStatus; +import com.powsybl.iidm.network.extensions.OperatingStatus; import com.powsybl.network.store.iidm.impl.AbstractIdentifiableImpl; -import com.powsybl.network.store.model.BranchStatusHolder; +import com.powsybl.network.store.model.OperatingStatusHolder; /** * @author Nicolas Noir */ -public class BranchStatusImpl> extends AbstractExtension implements BranchStatus { +public class OperatingStatusImpl> extends AbstractExtension implements OperatingStatus { - public BranchStatusImpl(C connectable) { + public OperatingStatusImpl(C connectable) { super(connectable); } @Override public Status getStatus() { var resource = ((AbstractIdentifiableImpl) getExtendable()).getResource(); - return Status.valueOf(((BranchStatusHolder) resource.getAttributes()).getBranchStatus()); + return Status.valueOf(((OperatingStatusHolder) resource.getAttributes()).getOperatingStatus()); } @Override - public BranchStatus setStatus(Status status) { - ((AbstractIdentifiableImpl) getExtendable()).updateResource(res -> ((BranchStatusHolder) res.getAttributes()).setBranchStatus(status.name())); + public OperatingStatus setStatus(Status status) { + ((AbstractIdentifiableImpl) getExtendable()).updateResource(res -> ((OperatingStatusHolder) res.getAttributes()).setOperatingStatus(status.name())); return this; } } diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/BranchStatusExtensionTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/BranchStatusExtensionTest.java deleted file mode 100644 index c67598185..000000000 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/BranchStatusExtensionTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * Copyright (c) 2021, 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 com.powsybl.network.store.iidm.impl; - -import com.powsybl.iidm.network.Line; -import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.ThreeWindingsTransformer; -import com.powsybl.iidm.network.TwoWindingsTransformer; -import com.powsybl.iidm.network.extensions.BranchStatus; -import com.powsybl.iidm.network.extensions.BranchStatusAdder; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * @author Nicolas Noir - */ -public class BranchStatusExtensionTest { - - @Test - public void testLineBranchStatusExtension() { - Network network = CreateNetworksUtil.createNodeBreakerNetwokWithMultipleEquipments(); - - Line line = network.getLine("LINE1"); - assertNotNull(line); - - assertNull(line.getExtension(BranchStatus.class)); - assertNull(line.getExtensionByName("branchStatus")); - assertEquals(0, line.getExtensions().size()); - - assertThrows(NullPointerException.class, () -> line.newExtension(BranchStatusAdder.class).withStatus(null).add()); - line.newExtension(BranchStatusAdder.class).withStatus(BranchStatus.Status.PLANNED_OUTAGE).add(); - - BranchStatus brs = line.getExtension(BranchStatus.class); - assertNotNull(brs); - assertEquals(BranchStatus.Status.PLANNED_OUTAGE, brs.getStatus()); - - brs = line.getExtensionByName("branchStatus"); - assertNotNull(brs); - assertEquals(BranchStatus.Status.PLANNED_OUTAGE, brs.getStatus()); - - assertEquals(1, line.getExtensions().size()); - } - - @Test - public void testTwoWindingsTransformerBranchStatusExtension() { - Network network = CreateNetworksUtil.createNodeBreakerNetwokWithMultipleEquipments(); - - TwoWindingsTransformer twt = network.getTwoWindingsTransformer("TwoWT1"); - assertNotNull(twt); - - assertNull(twt.getExtension(BranchStatus.class)); - assertEquals(0, twt.getExtensions().size()); - - assertThrows(NullPointerException.class, () -> twt.newExtension(BranchStatusAdder.class).withStatus(null).add()); - twt.newExtension(BranchStatusAdder.class).withStatus(BranchStatus.Status.FORCED_OUTAGE).add(); - - BranchStatus brs = twt.getExtension(BranchStatus.class); - assertNotNull(brs); - assertEquals(BranchStatus.Status.FORCED_OUTAGE, brs.getStatus()); - brs = twt.getExtensionByName("branchStatus"); - assertNotNull(brs); - assertEquals(BranchStatus.Status.FORCED_OUTAGE, brs.getStatus()); - - assertEquals(1, twt.getExtensions().size()); - } - - @Test - public void testThreeWindingsTransformerBranchStatusExtension() { - Network network = CreateNetworksUtil.createNodeBreakerNetwokWithMultipleEquipments(); - - ThreeWindingsTransformer twt = network.getThreeWindingsTransformer("TWT1"); - assertNotNull(twt); - - assertNull(twt.getExtension(BranchStatus.class)); - assertEquals(0, twt.getExtensions().size()); - - assertThrows(NullPointerException.class, () -> twt.newExtension(BranchStatusAdder.class).withStatus(null).add()); - twt.newExtension(BranchStatusAdder.class).withStatus(BranchStatus.Status.IN_OPERATION).add(); - - BranchStatus brs = twt.getExtension(BranchStatus.class); - assertNotNull(brs); - assertEquals(BranchStatus.Status.IN_OPERATION, brs.getStatus()); - brs = twt.getExtensionByName("branchStatus"); - assertNotNull(brs); - assertEquals(BranchStatus.Status.IN_OPERATION, brs.getStatus()); - - assertEquals(1, twt.getExtensions().size()); - } -} diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/OperatingStatusExtensionTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/OperatingStatusExtensionTest.java new file mode 100644 index 000000000..6dba33591 --- /dev/null +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/OperatingStatusExtensionTest.java @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2021, 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 com.powsybl.network.store.iidm.impl; + +import com.powsybl.iidm.network.Line; +import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.ThreeWindingsTransformer; +import com.powsybl.iidm.network.TwoWindingsTransformer; +import com.powsybl.iidm.network.extensions.OperatingStatusAdder; +import com.powsybl.iidm.network.extensions.OperatingStatus; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * @author Nicolas Noir + */ +public class OperatingStatusExtensionTest { + + @Test + public void testLineOperatingStatusExtension() { + Network network = CreateNetworksUtil.createNodeBreakerNetwokWithMultipleEquipments(); + + Line line = network.getLine("LINE1"); + assertNotNull(line); + + assertNull(line.getExtension(OperatingStatus.class)); + assertNull(line.getExtensionByName("operatingStatus")); + assertEquals(0, line.getExtensions().size()); + + assertThrows(NullPointerException.class, () -> line.newExtension(OperatingStatusAdder.class).withStatus(null).add()); + line.newExtension(OperatingStatusAdder.class).withStatus(OperatingStatus.Status.PLANNED_OUTAGE).add(); + + OperatingStatus brs = line.getExtension(OperatingStatus.class); + assertNotNull(brs); + assertEquals(OperatingStatus.Status.PLANNED_OUTAGE, brs.getStatus()); + + brs = line.getExtensionByName("operatingStatus"); + assertNotNull(brs); + assertEquals(OperatingStatus.Status.PLANNED_OUTAGE, brs.getStatus()); + + assertEquals(1, line.getExtensions().size()); + } + + @Test + public void testTwoWindingsTransformerOperatingStatusExtension() { + Network network = CreateNetworksUtil.createNodeBreakerNetwokWithMultipleEquipments(); + + TwoWindingsTransformer twt = network.getTwoWindingsTransformer("TwoWT1"); + assertNotNull(twt); + + assertNull(twt.getExtension(OperatingStatus.class)); + assertEquals(0, twt.getExtensions().size()); + + assertThrows(NullPointerException.class, () -> twt.newExtension(OperatingStatusAdder.class).withStatus(null).add()); + twt.newExtension(OperatingStatusAdder.class).withStatus(OperatingStatus.Status.FORCED_OUTAGE).add(); + + OperatingStatus brs = twt.getExtension(OperatingStatus.class); + assertNotNull(brs); + assertEquals(OperatingStatus.Status.FORCED_OUTAGE, brs.getStatus()); + brs = twt.getExtensionByName("operatingStatus"); + assertNotNull(brs); + assertEquals(OperatingStatus.Status.FORCED_OUTAGE, brs.getStatus()); + + assertEquals(1, twt.getExtensions().size()); + } + + @Test + public void testThreeWindingsTransformerOperatingStatusExtension() { + Network network = CreateNetworksUtil.createNodeBreakerNetwokWithMultipleEquipments(); + + ThreeWindingsTransformer twt = network.getThreeWindingsTransformer("TWT1"); + assertNotNull(twt); + + assertNull(twt.getExtension(OperatingStatus.class)); + assertEquals(0, twt.getExtensions().size()); + + assertThrows(NullPointerException.class, () -> twt.newExtension(OperatingStatusAdder.class).withStatus(null).add()); + twt.newExtension(OperatingStatusAdder.class).withStatus(OperatingStatus.Status.IN_OPERATION).add(); + + OperatingStatus brs = twt.getExtension(OperatingStatus.class); + assertNotNull(brs); + assertEquals(OperatingStatus.Status.IN_OPERATION, brs.getStatus()); + brs = twt.getExtensionByName("operatingStatus"); + assertNotNull(brs); + assertEquals(OperatingStatus.Status.IN_OPERATION, brs.getStatus()); + + assertEquals(1, twt.getExtensions().size()); + } +} diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/BranchAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/BranchAttributes.java index 6c8876f51..fbc9095f2 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/BranchAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/BranchAttributes.java @@ -16,7 +16,7 @@ /** * @author Geoffroy Jamgotchian */ -public interface BranchAttributes extends IdentifiableAttributes, Contained, LimitHolder, BranchStatusHolder { +public interface BranchAttributes extends IdentifiableAttributes, Contained, LimitHolder, OperatingStatusHolder { String getVoltageLevelId1(); diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java index 1cc624c2e..f0440c647 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java @@ -123,5 +123,5 @@ public class LineAttributes extends AbstractAttributes implements BranchAttribut private LimitsAttributes activePowerLimits2; @Schema(description = "Branch status") - private String branchStatus; + private String operatingStatus; } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/BranchStatusHolder.java b/network-store-model/src/main/java/com/powsybl/network/store/model/OperatingStatusHolder.java similarity index 75% rename from network-store-model/src/main/java/com/powsybl/network/store/model/BranchStatusHolder.java rename to network-store-model/src/main/java/com/powsybl/network/store/model/OperatingStatusHolder.java index 6c3a814f3..3b7b436cb 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/BranchStatusHolder.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/OperatingStatusHolder.java @@ -9,9 +9,9 @@ /** * @author Geoffroy Jamgotchian */ -public interface BranchStatusHolder { +public interface OperatingStatusHolder { - String getBranchStatus(); + String getOperatingStatus(); - void setBranchStatus(String branchStatus); + void setOperatingStatus(String operatingStatus); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java index 23892002c..bf1ab115c 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java @@ -25,7 +25,7 @@ @AllArgsConstructor @Builder @Schema(description = "Three windings transformer attributes") -public class ThreeWindingsTransformerAttributes extends AbstractAttributes implements IdentifiableAttributes, Contained, TransformerAttributes, LimitHolder, BranchStatusHolder { +public class ThreeWindingsTransformerAttributes extends AbstractAttributes implements IdentifiableAttributes, Contained, TransformerAttributes, LimitHolder, OperatingStatusHolder { @Schema(description = "3 windings transformer name") private String name; @@ -92,7 +92,7 @@ public class ThreeWindingsTransformerAttributes extends AbstractAttributes imple private ThreeWindingsTransformerPhaseAngleClockAttributes phaseAngleClock; @Schema(description = "Branch status") - private String branchStatus; + private String operatingStatus; @Schema(description = "CGMES tap changer attributes list") private List cgmesTapChangerAttributesList; diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/TwoWindingsTransformerAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/TwoWindingsTransformerAttributes.java index f84a501d5..2950ec9bd 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/TwoWindingsTransformerAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/TwoWindingsTransformerAttributes.java @@ -133,7 +133,7 @@ public class TwoWindingsTransformerAttributes extends AbstractAttributes impleme private LimitsAttributes activePowerLimits2; @Schema(description = "Branch status") - private String branchStatus; + private String operatingStatus; @Schema(description = "CGMES tap changer attributes list") private List cgmesTapChangerAttributesList; diff --git a/network-store-model/src/test/java/com/powsybl/network/store/model/ResourceTest.java b/network-store-model/src/test/java/com/powsybl/network/store/model/ResourceTest.java index 530951881..20d86419f 100644 --- a/network-store-model/src/test/java/com/powsybl/network/store/model/ResourceTest.java +++ b/network-store-model/src/test/java/com/powsybl/network/store/model/ResourceTest.java @@ -153,7 +153,7 @@ public void lineTest() { .b1(1) .g2(1) .b2(1) - .branchStatus("IN_OPERATION") + .operatingStatus("IN_OPERATION") .build()) .build(); @@ -167,7 +167,7 @@ public void lineTest() { resourceLine.getAttributes().setP1(100.0); assertEquals(100.0, resourceLine.getAttributes().getP1(), 0); - assertEquals("IN_OPERATION", resourceLine.getAttributes().getBranchStatus()); + assertEquals("IN_OPERATION", resourceLine.getAttributes().getOperatingStatus()); } @Test @@ -188,7 +188,7 @@ public void twoWindingsTransormer() { .g(1) .ratedU1(1.) .ratedU2(1.) - .branchStatus("IN_OPERATION") + .operatingStatus("IN_OPERATION") .build()) .build(); @@ -202,7 +202,7 @@ public void twoWindingsTransormer() { resourceTransformer.getAttributes().setP1(100.0); assertEquals(100.0, resourceTransformer.getAttributes().getP1(), 0); - assertEquals("IN_OPERATION", resourceTransformer.getAttributes().getBranchStatus()); + assertEquals("IN_OPERATION", resourceTransformer.getAttributes().getOperatingStatus()); } @Test @@ -212,7 +212,7 @@ public void threeWindingsTransormer() throws IOException { .attributes(ThreeWindingsTransformerAttributes.builder() .name("id3WT") .ratedU0(1) - .branchStatus("IN_OPERATION") + .operatingStatus("IN_OPERATION") .build()) .build(); @@ -233,7 +233,7 @@ public void threeWindingsTransormer() throws IOException { assertEquals(500., resourceTransformer.getAttributes().getQ2(), 0); assertEquals(700., resourceTransformer.getAttributes().getP3(), 0); - assertEquals("IN_OPERATION", resourceTransformer.getAttributes().getBranchStatus()); + assertEquals("IN_OPERATION", resourceTransformer.getAttributes().getOperatingStatus()); } @Test diff --git a/network-store-model/src/test/java/com/powsybl/network/store/model/TapChangerParentTest.java b/network-store-model/src/test/java/com/powsybl/network/store/model/TapChangerParentTest.java index 87dacbdd9..9a95e475c 100644 --- a/network-store-model/src/test/java/com/powsybl/network/store/model/TapChangerParentTest.java +++ b/network-store-model/src/test/java/com/powsybl/network/store/model/TapChangerParentTest.java @@ -104,7 +104,7 @@ public void twoWindingsTransformertapChangerAttributesTest() { .g(1) .ratedU1(1.) .ratedU2(1.) - .branchStatus("IN_OPERATION") + .operatingStatus("IN_OPERATION") .phaseTapChangerAttributes(PhaseTapChangerAttributes.builder() .lowTapPosition(1) .regulating(true) @@ -170,7 +170,7 @@ public void threeWindingsTransformertapChangerAttributesTest() { .attributes(ThreeWindingsTransformerAttributes.builder() .name("id3WT") .ratedU0(1) - .branchStatus("IN_OPERATION") + .operatingStatus("IN_OPERATION") .leg1(LegAttributes.builder() .phaseTapChangerAttributes(PhaseTapChangerAttributes.builder() .lowTapPosition(1) diff --git a/pom.xml b/pom.xml index 75a0af6be..820ec43ae 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,7 @@ 3.1.2 3.9 2023.3.2 - 6.1.0-SNAPSHOT + 6.1.0 1.7.0 2.0.4 1.4.5 @@ -126,15 +126,6 @@
- - - - org.projectlombok - lombok - provided - - - From 0916e730fd61b15ad2ec14bfad1d46631d67487c Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 29 Nov 2023 10:43:26 +0100 Subject: [PATCH 10/27] replaced switch by java17 enhanced switch Signed-off-by: Nicolas Rol --- .../store/client/NetworkStoreService.java | 16 +-- .../client/PreloadingNetworkStoreClient.java | 77 +++------- .../store/iidm/impl/AbstractBranchImpl.java | 12 +- .../network/store/iidm/impl/BaseBus.java | 110 ++++---------- .../store/iidm/impl/CalculatedBus.java | 16 +-- .../store/iidm/impl/NetworkObjectIndex.java | 119 +++++----------- .../network/store/iidm/impl/TerminalImpl.java | 1 - .../impl/ThreeWindingsTransformerImpl.java | 1 - ...ansformerToInjectionAttributesAdapter.java | 109 +++++--------- .../network/store/iidm/impl/TieLineImpl.java | 16 +-- .../store/model/ResourceDeserializer.java | 134 ++++++------------ 11 files changed, 189 insertions(+), 422 deletions(-) diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkStoreService.java b/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkStoreService.java index fe064ddab..d0a3d7695 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkStoreService.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkStoreService.java @@ -96,16 +96,12 @@ private static NetworkStoreClient createStoreClient(RestClient restClient, Prelo Objects.requireNonNull(preloadingStrategy); LOGGER.info("Preloading strategy: {}", preloadingStrategy); var cachedClient = new CachedNetworkStoreClient(new BufferedNetworkStoreClient(new RestNetworkStoreClient(restClient), executorService)); - switch (preloadingStrategy) { - case NONE: - return cachedClient; - case COLLECTION: - return new PreloadingNetworkStoreClient(cachedClient, false, executorService); - case ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW: - return new PreloadingNetworkStoreClient(cachedClient, true, executorService); - default: - throw new IllegalStateException("Unknown preloading strategy: " + preloadingStrategy); - } + return switch (preloadingStrategy) { + case NONE -> cachedClient; + case COLLECTION -> new PreloadingNetworkStoreClient(cachedClient, false, executorService); + case ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW -> + new PreloadingNetworkStoreClient(cachedClient, true, executorService); + }; } public NetworkFactory getNetworkFactory() { diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingNetworkStoreClient.java index 0c03cf18d..125a3f201 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingNetworkStoreClient.java @@ -65,62 +65,27 @@ public PreloadingNetworkStoreClient(CachedNetworkStoreClient delegate, boolean a private void loadToCache(ResourceType resourceType, UUID networkUuid, int variantNum) { switch (resourceType) { - case SUBSTATION: - delegate.getSubstations(networkUuid, variantNum); - break; - case VOLTAGE_LEVEL: - delegate.getVoltageLevels(networkUuid, variantNum); - break; - case LOAD: - delegate.getLoads(networkUuid, variantNum); - break; - case GENERATOR: - delegate.getGenerators(networkUuid, variantNum); - break; - case BATTERY: - delegate.getBatteries(networkUuid, variantNum); - break; - case SHUNT_COMPENSATOR: - delegate.getShuntCompensators(networkUuid, variantNum); - break; - case VSC_CONVERTER_STATION: - delegate.getVscConverterStations(networkUuid, variantNum); - break; - case LCC_CONVERTER_STATION: - delegate.getLccConverterStations(networkUuid, variantNum); - break; - case STATIC_VAR_COMPENSATOR: - delegate.getStaticVarCompensators(networkUuid, variantNum); - break; - case BUSBAR_SECTION: - delegate.getBusbarSections(networkUuid, variantNum); - break; - case SWITCH: - delegate.getSwitches(networkUuid, variantNum); - break; - case TWO_WINDINGS_TRANSFORMER: - delegate.getTwoWindingsTransformers(networkUuid, variantNum); - break; - case THREE_WINDINGS_TRANSFORMER: - delegate.getThreeWindingsTransformers(networkUuid, variantNum); - break; - case LINE: - delegate.getLines(networkUuid, variantNum); - break; - case HVDC_LINE: - delegate.getHvdcLines(networkUuid, variantNum); - break; - case DANGLING_LINE: - delegate.getDanglingLines(networkUuid, variantNum); - break; - case CONFIGURED_BUS: - delegate.getConfiguredBuses(networkUuid, variantNum); - break; - case TIE_LINE: - delegate.getTieLines(networkUuid, variantNum); - break; - default: - break; + case SUBSTATION -> delegate.getSubstations(networkUuid, variantNum); + case VOLTAGE_LEVEL -> delegate.getVoltageLevels(networkUuid, variantNum); + case LOAD -> delegate.getLoads(networkUuid, variantNum); + case GENERATOR -> delegate.getGenerators(networkUuid, variantNum); + case BATTERY -> delegate.getBatteries(networkUuid, variantNum); + case SHUNT_COMPENSATOR -> delegate.getShuntCompensators(networkUuid, variantNum); + case VSC_CONVERTER_STATION -> delegate.getVscConverterStations(networkUuid, variantNum); + case LCC_CONVERTER_STATION -> delegate.getLccConverterStations(networkUuid, variantNum); + case STATIC_VAR_COMPENSATOR -> delegate.getStaticVarCompensators(networkUuid, variantNum); + case BUSBAR_SECTION -> delegate.getBusbarSections(networkUuid, variantNum); + case SWITCH -> delegate.getSwitches(networkUuid, variantNum); + case TWO_WINDINGS_TRANSFORMER -> delegate.getTwoWindingsTransformers(networkUuid, variantNum); + case THREE_WINDINGS_TRANSFORMER -> delegate.getThreeWindingsTransformers(networkUuid, variantNum); + case LINE -> delegate.getLines(networkUuid, variantNum); + case HVDC_LINE -> delegate.getHvdcLines(networkUuid, variantNum); + case DANGLING_LINE -> delegate.getDanglingLines(networkUuid, variantNum); + case CONFIGURED_BUS -> delegate.getConfiguredBuses(networkUuid, variantNum); + case TIE_LINE -> delegate.getTieLines(networkUuid, variantNum); + default -> { + // Do nothing + } } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchImpl.java index 33c954b01..b391d449b 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchImpl.java @@ -54,14 +54,10 @@ public TerminalImpl getTerminal2() { @Override public Terminal getTerminal(TwoSides side) { - switch (side) { - case ONE: - return terminal1; - case TWO: - return terminal2; - default: - throw new UnsupportedOperationException(); - } + return switch (side) { + case ONE -> terminal1; + case TWO -> terminal2; + }; } @Override diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BaseBus.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BaseBus.java index 8991533e7..9b39d2266 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BaseBus.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BaseBus.java @@ -50,25 +50,15 @@ default double getP() { for (Terminal terminal : getConnectedTerminals()) { Connectable connectable = terminal.getConnectable(); switch (connectable.getType()) { - case BUSBAR_SECTION: - case SHUNT_COMPENSATOR: - case STATIC_VAR_COMPENSATOR: - case LINE: - case TWO_WINDINGS_TRANSFORMER: - case THREE_WINDINGS_TRANSFORMER: - case DANGLING_LINE: - // skip - break; - case GENERATOR: - case BATTERY: - case LOAD: - case HVDC_CONVERTER_STATION: + case BUSBAR_SECTION, SHUNT_COMPENSATOR, STATIC_VAR_COMPENSATOR, LINE, TWO_WINDINGS_TRANSFORMER, THREE_WINDINGS_TRANSFORMER, DANGLING_LINE -> { + // Do nothing + } + case GENERATOR, BATTERY, LOAD, HVDC_CONVERTER_STATION -> { if (!Double.isNaN(terminal.getP())) { p += terminal.getP(); } - break; - default: - throw new AssertionError(); + } + default -> throw new AssertionError(); } } return p; @@ -83,25 +73,15 @@ default double getQ() { for (Terminal terminal : getConnectedTerminals()) { Connectable connectable = terminal.getConnectable(); switch (connectable.getType()) { - case BUSBAR_SECTION: - case LINE: - case TWO_WINDINGS_TRANSFORMER: - case THREE_WINDINGS_TRANSFORMER: - case DANGLING_LINE: - // skip - break; - case GENERATOR: - case BATTERY: - case LOAD: - case SHUNT_COMPENSATOR: - case STATIC_VAR_COMPENSATOR: - case HVDC_CONVERTER_STATION: + case BUSBAR_SECTION, LINE, TWO_WINDINGS_TRANSFORMER, THREE_WINDINGS_TRANSFORMER, DANGLING_LINE -> { + // Do nothing + } + case GENERATOR, BATTERY, LOAD, SHUNT_COMPENSATOR, STATIC_VAR_COMPENSATOR, HVDC_CONVERTER_STATION -> { if (!Double.isNaN(terminal.getQ())) { q += terminal.getQ(); } - break; - default: - throw new AssertionError(); + } + default -> throw new AssertionError(); } } return q; @@ -113,37 +93,23 @@ private void visitEquipments(Iterable terminals, TopologyVis for (Terminal terminal : terminals) { Connectable connectable = terminal.getConnectable(); switch (connectable.getType()) { - case BUSBAR_SECTION: - visitor.visitBusbarSection((BusbarSection) connectable); - break; - - case LINE: + case BUSBAR_SECTION -> visitor.visitBusbarSection((BusbarSection) connectable); + case LINE -> { Line line = (Line) connectable; visitor.visitLine(line, line.getTerminal1() == terminal ? TwoSides.ONE - : TwoSides.TWO); - break; - - case GENERATOR: - visitor.visitGenerator((Generator) connectable); - break; - - case BATTERY: - visitor.visitBattery((Battery) connectable); - break; - - case SHUNT_COMPENSATOR: - visitor.visitShuntCompensator((ShuntCompensator) connectable); - break; - - case TWO_WINDINGS_TRANSFORMER: + : TwoSides.TWO); + } + case GENERATOR -> visitor.visitGenerator((Generator) connectable); + case BATTERY -> visitor.visitBattery((Battery) connectable); + case SHUNT_COMPENSATOR -> visitor.visitShuntCompensator((ShuntCompensator) connectable); + case TWO_WINDINGS_TRANSFORMER -> { TwoWindingsTransformer twt = (TwoWindingsTransformer) connectable; visitor.visitTwoWindingsTransformer(twt, - twt.getTerminal1() == terminal - ? TwoSides.ONE - : TwoSides.TWO); - break; - - case THREE_WINDINGS_TRANSFORMER: + twt.getTerminal1() == terminal + ? TwoSides.ONE + : TwoSides.TWO); + } + case THREE_WINDINGS_TRANSFORMER -> { ThreeWindingsTransformer thwt = (ThreeWindingsTransformer) connectable; ThreeSides side; if (thwt.getLeg1().getTerminal() == terminal) { @@ -154,26 +120,12 @@ private void visitEquipments(Iterable terminals, TopologyVis side = ThreeSides.THREE; } visitor.visitThreeWindingsTransformer(thwt, side); - break; - - case LOAD: - visitor.visitLoad((Load) connectable); - break; - - case DANGLING_LINE: - visitor.visitDanglingLine((DanglingLine) connectable); - break; - - case STATIC_VAR_COMPENSATOR: - visitor.visitStaticVarCompensator((StaticVarCompensator) connectable); - break; - - case HVDC_CONVERTER_STATION: - visitor.visitHvdcConverterStation((HvdcConverterStation) connectable); - break; - - default: - throw new AssertionError(); + } + case LOAD -> visitor.visitLoad((Load) connectable); + case DANGLING_LINE -> visitor.visitDanglingLine((DanglingLine) connectable); + case STATIC_VAR_COMPENSATOR -> visitor.visitStaticVarCompensator((StaticVarCompensator) connectable); + case HVDC_CONVERTER_STATION -> visitor.visitHvdcConverterStation((HvdcConverterStation) connectable); + default -> throw new AssertionError(); } } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CalculatedBus.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CalculatedBus.java index 40a42c5fd..e919611f9 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CalculatedBus.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CalculatedBus.java @@ -209,15 +209,13 @@ public Collection getConnectedTerminals() { return getAttributes().getVertices().stream() .map(v -> { Connectable c = index.getConnectable(v.getId(), v.getConnectableType()); - switch (c.getType()) { - case LINE: - case TWO_WINDINGS_TRANSFORMER: - return ((AbstractBranchImpl) c).getTerminal(TwoSides.valueOf(v.getSide())); - case THREE_WINDINGS_TRANSFORMER: - return ((ThreeWindingsTransformerImpl) c).getTerminal(ThreeSides.valueOf(v.getSide())); - default: - return c.getTerminals().get(0); - } + return switch (c.getType()) { + case LINE, TWO_WINDINGS_TRANSFORMER -> + ((AbstractBranchImpl) c).getTerminal(TwoSides.valueOf(v.getSide())); + case THREE_WINDINGS_TRANSFORMER -> + ((ThreeWindingsTransformerImpl) c).getTerminal(ThreeSides.valueOf(v.getSide())); + default -> c.getTerminals().get(0); + }; }) .collect(Collectors.toList()); } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkObjectIndex.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkObjectIndex.java index 98178e3f2..271e95c6b 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkObjectIndex.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkObjectIndex.java @@ -937,32 +937,20 @@ public Collection> getIdentifiables() { } public Connectable getConnectable(String connectableId, IdentifiableType connectableType) { - switch (connectableType) { - case BUSBAR_SECTION: - return getBusbarSection(connectableId).orElse(null); - case LINE: - return getLine(connectableId).orElse(null); - case TWO_WINDINGS_TRANSFORMER: - return getTwoWindingsTransformer(connectableId).orElse(null); - case THREE_WINDINGS_TRANSFORMER: - return getThreeWindingsTransformer(connectableId).orElse(null); - case GENERATOR: - return getGenerator(connectableId).orElse(null); - case BATTERY: - return getBattery(connectableId).orElse(null); - case LOAD: - return getLoad(connectableId).orElse(null); - case SHUNT_COMPENSATOR: - return getShuntCompensator(connectableId).orElse(null); - case DANGLING_LINE: - return getDanglingLine(connectableId).orElse(null); - case STATIC_VAR_COMPENSATOR: - return getStaticVarCompensator(connectableId).orElse(null); - case HVDC_CONVERTER_STATION: - return getHvdcConverterStation(connectableId).orElse(null); - default: - throw new IllegalStateException("Unexpected connectable type:" + connectableType); - } + return switch (connectableType) { + case BUSBAR_SECTION -> getBusbarSection(connectableId).orElse(null); + case LINE -> getLine(connectableId).orElse(null); + case TWO_WINDINGS_TRANSFORMER -> getTwoWindingsTransformer(connectableId).orElse(null); + case THREE_WINDINGS_TRANSFORMER -> getThreeWindingsTransformer(connectableId).orElse(null); + case GENERATOR -> getGenerator(connectableId).orElse(null); + case BATTERY -> getBattery(connectableId).orElse(null); + case LOAD -> getLoad(connectableId).orElse(null); + case SHUNT_COMPENSATOR -> getShuntCompensator(connectableId).orElse(null); + case DANGLING_LINE -> getDanglingLine(connectableId).orElse(null); + case STATIC_VAR_COMPENSATOR -> getStaticVarCompensator(connectableId).orElse(null); + case HVDC_CONVERTER_STATION -> getHvdcConverterStation(connectableId).orElse(null); + default -> throw new IllegalStateException("Unexpected connectable type:" + connectableType); + }; } public Branch getBranch(String branchId) { @@ -1053,65 +1041,26 @@ boolean contains(String id) { @SuppressWarnings("unchecked") void updateResource(Resource resource, AttributeFilter attributeFilter) { switch (resource.getType()) { - case NETWORK: - updateNetworkResource((Resource) resource, attributeFilter); - break; - case SUBSTATION: - updateSubstationResource((Resource) resource, attributeFilter); - break; - case VOLTAGE_LEVEL: - updateVoltageLevelResource((Resource) resource, attributeFilter); - break; - case LOAD: - updateLoadResource((Resource) resource, attributeFilter); - break; - case GENERATOR: - updateGeneratorResource((Resource) resource, attributeFilter); - break; - case BATTERY: - updateBatteryResource((Resource) resource, attributeFilter); - break; - case SHUNT_COMPENSATOR: - updateShuntCompensatorResource((Resource) resource, attributeFilter); - break; - case VSC_CONVERTER_STATION: - updateVscConverterStationResource((Resource) resource, attributeFilter); - break; - case LCC_CONVERTER_STATION: - updateLccConverterStationResource((Resource) resource, attributeFilter); - break; - case STATIC_VAR_COMPENSATOR: - updateStaticVarCompensatorResource((Resource) resource, attributeFilter); - break; - case BUSBAR_SECTION: - updateBusbarSectionResource((Resource) resource, attributeFilter); - break; - case SWITCH: - updateSwitchResource((Resource) resource, attributeFilter); - break; - case TWO_WINDINGS_TRANSFORMER: - updateTwoWindingsTransformerResource((Resource) resource, attributeFilter); - break; - case THREE_WINDINGS_TRANSFORMER: - updateThreeWindingsTransformerResource((Resource) resource, attributeFilter); - break; - case LINE: - updateLineResource((Resource) resource, attributeFilter); - break; - case HVDC_LINE: - updateHvdcLineResource((Resource) resource, attributeFilter); - break; - case DANGLING_LINE: - updateDanglingLineResource((Resource) resource, attributeFilter); - break; - case CONFIGURED_BUS: - updateConfiguredBusResource((Resource) resource, attributeFilter); - break; - case TIE_LINE: - updateTieLineResource((Resource) resource, attributeFilter); - break; - default: - throw new IllegalStateException("Unknown resource type: " + resource.getType()); + case NETWORK -> updateNetworkResource((Resource) resource, attributeFilter); + case SUBSTATION -> updateSubstationResource((Resource) resource, attributeFilter); + case VOLTAGE_LEVEL -> updateVoltageLevelResource((Resource) resource, attributeFilter); + case LOAD -> updateLoadResource((Resource) resource, attributeFilter); + case GENERATOR -> updateGeneratorResource((Resource) resource, attributeFilter); + case BATTERY -> updateBatteryResource((Resource) resource, attributeFilter); + case SHUNT_COMPENSATOR -> updateShuntCompensatorResource((Resource) resource, attributeFilter); + case VSC_CONVERTER_STATION -> updateVscConverterStationResource((Resource) resource, attributeFilter); + case LCC_CONVERTER_STATION -> updateLccConverterStationResource((Resource) resource, attributeFilter); + case STATIC_VAR_COMPENSATOR -> updateStaticVarCompensatorResource((Resource) resource, attributeFilter); + case BUSBAR_SECTION -> updateBusbarSectionResource((Resource) resource, attributeFilter); + case SWITCH -> updateSwitchResource((Resource) resource, attributeFilter); + case TWO_WINDINGS_TRANSFORMER -> updateTwoWindingsTransformerResource((Resource) resource, attributeFilter); + case THREE_WINDINGS_TRANSFORMER -> updateThreeWindingsTransformerResource((Resource) resource, attributeFilter); + case LINE -> updateLineResource((Resource) resource, attributeFilter); + case HVDC_LINE -> updateHvdcLineResource((Resource) resource, attributeFilter); + case DANGLING_LINE -> updateDanglingLineResource((Resource) resource, attributeFilter); + case CONFIGURED_BUS -> updateConfiguredBusResource((Resource) resource, attributeFilter); + case TIE_LINE -> updateTieLineResource((Resource) resource, attributeFilter); + default -> throw new IllegalStateException("Unknown resource type: " + resource.getType()); } } 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 873c4b015..2f9c3105d 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 @@ -475,7 +475,6 @@ boolean traverse(Terminal.TopologyTraverser traverser, Set traversedTe ((NodeBreakerViewImpl) voltageLevel.getNodeBreakerView()).traverseFromTerminal(this, traverser, traversedTerminals, traversalType); case BUS_BREAKER -> ((BusBreakerViewImpl) voltageLevel.getBusBreakerView()).traverseFromTerminal(this, traverser, traversedTerminals, traversalType); - default -> throw new IllegalStateException("Unknown topology kind: " + topologyKind); }; } 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 046a300df..8191ed548 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 @@ -357,7 +357,6 @@ public Terminal getTerminal(ThreeSides side) { case ONE -> leg1.getTerminal(); case TWO -> leg2.getTerminal(); case THREE -> leg3.getTerminal(); - default -> throw new AssertionError(); }; } 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 cc5545f48..f1321b49e 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 @@ -35,16 +35,12 @@ private IllegalStateException createUnknownSideException() { } private LegAttributes getLegAttributes() { - switch (side) { - case ONE: - return attributes.getLeg1(); - case TWO: - return attributes.getLeg2(); - case THREE: - return attributes.getLeg3(); - default: - throw createUnknownSideException(); - } + return switch (side) { + case ONE -> attributes.getLeg1(); + case TWO -> attributes.getLeg2(); + case THREE -> attributes.getLeg3(); + default -> throw createUnknownSideException(); + }; } @Override @@ -121,94 +117,61 @@ public String getConnectableBus() { @Override public double getP() { - switch (side) { - case ONE: - return attributes.getP1(); - case TWO: - return attributes.getP2(); - case THREE: - return attributes.getP3(); - default: - throw createUnknownSideException(); - } + return switch (side) { + case ONE -> attributes.getP1(); + case TWO -> attributes.getP2(); + case THREE -> attributes.getP3(); + default -> throw createUnknownSideException(); + }; } @Override public void setP(double p) { switch (side) { - case ONE: - attributes.setP1(p); - break; - case TWO: - attributes.setP2(p); - break; - case THREE: - attributes.setP3(p); - break; - default: - throw createUnknownSideException(); + case ONE -> attributes.setP1(p); + case TWO -> attributes.setP2(p); + case THREE -> attributes.setP3(p); + default -> throw createUnknownSideException(); } } @Override public double getQ() { - switch (side) { - case ONE: - return attributes.getQ1(); - case TWO: - return attributes.getQ2(); - case THREE: - return attributes.getQ3(); - default: - throw createUnknownSideException(); - } + return switch (side) { + case ONE -> attributes.getQ1(); + case TWO -> attributes.getQ2(); + case THREE -> attributes.getQ3(); + default -> throw createUnknownSideException(); + }; } @Override public void setQ(double q) { switch (side) { - case ONE: - attributes.setQ1(q); - break; - case TWO: - attributes.setQ2(q); - break; - case THREE: - attributes.setQ3(q); - break; - default: - throw createUnknownSideException(); + case ONE -> attributes.setQ1(q); + case TWO -> attributes.setQ2(q); + case THREE -> attributes.setQ3(q); + default -> throw createUnknownSideException(); } } @Override public ConnectablePositionAttributes getPosition() { - switch (side) { - case ONE: - return attributes.getPosition1(); - case TWO: - return attributes.getPosition2(); - case THREE: - return attributes.getPosition3(); - default: - throw createUnknownSideException(); - } + return switch (side) { + case ONE -> attributes.getPosition1(); + case TWO -> attributes.getPosition2(); + case THREE -> attributes.getPosition3(); + default -> throw createUnknownSideException(); + }; } @Override public void setPosition(ConnectablePositionAttributes position) { switch (side) { - case ONE: - attributes.setPosition1(position); - break; - case TWO: - attributes.setPosition2(position); - break; - case THREE: - attributes.setPosition3(position); - break; - default: - throw createUnknownSideException(); + case ONE -> attributes.setPosition1(position); + case TWO -> attributes.setPosition2(position); + case THREE -> attributes.setPosition3(position); + default -> throw createUnknownSideException(); } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java index baf713f43..edf741c2c 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java @@ -354,17 +354,13 @@ public Overload checkTemporaryLimits2(LimitType type) { } public double getValueForLimit(Terminal t, LimitType type) { - switch (type) { - case ACTIVE_POWER: - return t.getP(); - case APPARENT_POWER: - return Math.sqrt(t.getP() * t.getP() + t.getQ() * t.getQ()); - case CURRENT: - return t.getI(); - case VOLTAGE: - default: + return switch (type) { + case ACTIVE_POWER -> t.getP(); + case APPARENT_POWER -> Math.sqrt(t.getP() * t.getP() + t.getQ() * t.getQ()); + case CURRENT -> t.getI(); + default -> throw new UnsupportedOperationException(String.format("Getting %s limits is not supported.", type.name())); - } + }; } static Terminal getTerminal(String voltageLevelId, Terminal terminal1, Terminal terminal2) { diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/ResourceDeserializer.java b/network-store-model/src/main/java/com/powsybl/network/store/model/ResourceDeserializer.java index 1a64162b2..e355f1b6c 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/ResourceDeserializer.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/ResourceDeserializer.java @@ -26,82 +26,43 @@ public ResourceDeserializer() { private static Class getTypeClass(ResourceType type, AttributeFilter filter) { Objects.requireNonNull(type); if (filter == null) { - switch (type) { - case NETWORK: - return NetworkAttributes.class; - case SUBSTATION: - return SubstationAttributes.class; - case VOLTAGE_LEVEL: - return VoltageLevelAttributes.class; - case LOAD: - return LoadAttributes.class; - case GENERATOR: - return GeneratorAttributes.class; - case BATTERY: - return BatteryAttributes.class; - case VSC_CONVERTER_STATION: - return VscConverterStationAttributes.class; - case LCC_CONVERTER_STATION: - return LccConverterStationAttributes.class; - case SHUNT_COMPENSATOR: - return ShuntCompensatorAttributes.class; - case STATIC_VAR_COMPENSATOR: - return StaticVarCompensatorAttributes.class; - case BUSBAR_SECTION: - return BusbarSectionAttributes.class; - case SWITCH: - return SwitchAttributes.class; - case TWO_WINDINGS_TRANSFORMER: - return TwoWindingsTransformerAttributes.class; - case THREE_WINDINGS_TRANSFORMER: - return ThreeWindingsTransformerAttributes.class; - case LINE: - return LineAttributes.class; - case HVDC_LINE: - return HvdcLineAttributes.class; - case DANGLING_LINE: - return DanglingLineAttributes.class; - case CONFIGURED_BUS: - return ConfiguredBusAttributes.class; - case TIE_LINE: - return TieLineAttributes.class; - default: - throw new IllegalStateException("Unknown resource type: " + type); - } + return switch (type) { + case NETWORK -> NetworkAttributes.class; + case SUBSTATION -> SubstationAttributes.class; + case VOLTAGE_LEVEL -> VoltageLevelAttributes.class; + case LOAD -> LoadAttributes.class; + case GENERATOR -> GeneratorAttributes.class; + case BATTERY -> BatteryAttributes.class; + case VSC_CONVERTER_STATION -> VscConverterStationAttributes.class; + case LCC_CONVERTER_STATION -> LccConverterStationAttributes.class; + case SHUNT_COMPENSATOR -> ShuntCompensatorAttributes.class; + case STATIC_VAR_COMPENSATOR -> StaticVarCompensatorAttributes.class; + case BUSBAR_SECTION -> BusbarSectionAttributes.class; + case SWITCH -> SwitchAttributes.class; + case TWO_WINDINGS_TRANSFORMER -> TwoWindingsTransformerAttributes.class; + case THREE_WINDINGS_TRANSFORMER -> ThreeWindingsTransformerAttributes.class; + case LINE -> LineAttributes.class; + case HVDC_LINE -> HvdcLineAttributes.class; + case DANGLING_LINE -> DanglingLineAttributes.class; + case CONFIGURED_BUS -> ConfiguredBusAttributes.class; + case TIE_LINE -> TieLineAttributes.class; + }; } else { if (filter == AttributeFilter.SV) { - switch (type) { - case NETWORK: - return NetworkAttributes.class; - case SUBSTATION: - return SubstationAttributes.class; - case VOLTAGE_LEVEL: - return VoltageLevelSvAttributes.class; - case LOAD: - case GENERATOR: - case BATTERY: - case VSC_CONVERTER_STATION: - case LCC_CONVERTER_STATION: - case SHUNT_COMPENSATOR: - case STATIC_VAR_COMPENSATOR: - case DANGLING_LINE: - return InjectionSvAttributes.class; - case BUSBAR_SECTION: - return BusbarSectionAttributes.class; - case SWITCH: - return SwitchAttributes.class; - case TWO_WINDINGS_TRANSFORMER: - case LINE: - return BranchSvAttributes.class; - case THREE_WINDINGS_TRANSFORMER: - return ThreeWindingsTransformerSvAttributes.class; - case HVDC_LINE: - return HvdcLineAttributes.class; - case CONFIGURED_BUS: - return ConfiguredBusAttributes.class; - default: - throw new IllegalStateException("Unknown resource type: " + type); - } + return switch (type) { + case NETWORK -> NetworkAttributes.class; + case SUBSTATION -> SubstationAttributes.class; + case VOLTAGE_LEVEL -> VoltageLevelSvAttributes.class; + case LOAD, GENERATOR, BATTERY, VSC_CONVERTER_STATION, LCC_CONVERTER_STATION, SHUNT_COMPENSATOR, STATIC_VAR_COMPENSATOR, DANGLING_LINE -> + InjectionSvAttributes.class; + case BUSBAR_SECTION -> BusbarSectionAttributes.class; + case SWITCH -> SwitchAttributes.class; + case TWO_WINDINGS_TRANSFORMER, LINE -> BranchSvAttributes.class; + case THREE_WINDINGS_TRANSFORMER -> ThreeWindingsTransformerSvAttributes.class; + case HVDC_LINE -> HvdcLineAttributes.class; + case CONFIGURED_BUS -> ConfiguredBusAttributes.class; + default -> throw new IllegalStateException("Unknown resource type: " + type); + }; } else { throw new IllegalStateException("Unknown attribute filter: " + filter); } @@ -121,24 +82,17 @@ public Resource deserialize(JsonParser parser, DeserializationContext ctxt) thro if (token == JsonToken.FIELD_NAME) { String fieldName = parser.getCurrentName(); switch (fieldName) { - case "type": - type = ResourceType.valueOf(parser.nextTextValue()); - break; - case "id": - id = parser.nextTextValue(); - break; - case "variantNum": - variantNum = parser.nextIntValue(-1); - break; - case "filter": - filter = AttributeFilter.valueOf(parser.nextTextValue()); - break; - case "attributes": + case "type" -> type = ResourceType.valueOf(parser.nextTextValue()); + case "id" -> id = parser.nextTextValue(); + case "variantNum" -> variantNum = parser.nextIntValue(-1); + case "filter" -> filter = AttributeFilter.valueOf(parser.nextTextValue()); + case "attributes" -> { parser.nextValue(); attributes = parser.readValueAs(getTypeClass(type, filter)); - break; - default: - break; + } + default -> { + // Do nothing + } } } else if (token == JsonToken.END_OBJECT) { break; From 8c501f479af41097277e7e2fcc31edd31007631e Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 29 Nov 2023 10:43:26 +0100 Subject: [PATCH 11/27] bump to powsybl-core 6.1.1 and powsybl-dependencies 2023.4.0 + add missing author and licence Signed-off-by: Nicolas Rol --- .../network/store/iidm/impl/SwitchPathValidator.java | 10 ++++++++++ pom.xml | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchPathValidator.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchPathValidator.java index 0ed19ab3c..9df017d95 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchPathValidator.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchPathValidator.java @@ -1,3 +1,10 @@ +/* + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ package com.powsybl.network.store.iidm.impl; import com.powsybl.iidm.network.Switch; @@ -8,6 +15,9 @@ import java.util.Optional; import java.util.function.Predicate; +/** + * @author Nicolas Rol {@literal } + */ public class SwitchPathValidator implements PathValidator { private final Predicate isSwitchValidInGraph; diff --git a/pom.xml b/pom.xml index 820ec43ae..e0530c2b9 100644 --- a/pom.xml +++ b/pom.xml @@ -49,8 +49,8 @@ 3.1.2 3.9 - 2023.3.2 - 6.1.0 + 2023.4.0 + 6.1.1 1.7.0 2.0.4 1.4.5 From 268afcd3aed4459599ee25496bb9ae7dfaf65cd9 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 10 Jan 2024 18:09:44 +0100 Subject: [PATCH 12/27] deleted redundant import of powsybl-core + fixed description for consistency + swapped annotation from @Test to @Override Signed-off-by: Nicolas Rol --- .../network/store/iidm/impl/tck/MergeNetworkTest.java | 10 +++++----- .../model/ThreeWindingsTransformerAttributes.java | 2 +- .../store/model/TwoWindingsTransformerAttributes.java | 2 +- pom.xml | 8 -------- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java index 39fb9f3c3..b659a9de4 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java @@ -104,27 +104,27 @@ public void testValidationLevelWhenMerging2Ssh() { // FIXME } - @Test + @Override public void failMergeOnlyOneNetwork() { // FIXME } - @Test + @Override public void failMergeOnSubnetworks() { // FIXME } - @Test + @Override public void failMergeSubnetworks() { // FIXME } - @Test + @Override public void failMergeContainingSubnetworks() { // FIXME } - @Test + @Override public void testNoEmptyAdditionalSubnetworkIsCreated() { // FIXME } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java index bf1ab115c..c99a815e0 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java @@ -91,7 +91,7 @@ public class ThreeWindingsTransformerAttributes extends AbstractAttributes imple @Schema(description = "Phase angle clock for leg 2 and 3") private ThreeWindingsTransformerPhaseAngleClockAttributes phaseAngleClock; - @Schema(description = "Branch status") + @Schema(description = "Operating status") private String operatingStatus; @Schema(description = "CGMES tap changer attributes list") diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/TwoWindingsTransformerAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/TwoWindingsTransformerAttributes.java index 2950ec9bd..ecc5b995f 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/TwoWindingsTransformerAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/TwoWindingsTransformerAttributes.java @@ -132,7 +132,7 @@ public class TwoWindingsTransformerAttributes extends AbstractAttributes impleme @Schema(description = "Active power limit side 2") private LimitsAttributes activePowerLimits2; - @Schema(description = "Branch status") + @Schema(description = "Operating status") private String operatingStatus; @Schema(description = "CGMES tap changer attributes list") diff --git a/pom.xml b/pom.xml index f2cbad998..15bab5e89 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,6 @@ 3.1.2 3.9 2023.4.0 - 6.1.1 1.7.0 2.0.4 1.4.5 @@ -71,13 +70,6 @@ - - com.powsybl - powsybl-core - ${powsybl-core.version} - pom - import - From 6b9e1f190eaa6fed78fc74beaf02c92862736bde Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 10 Jan 2024 18:12:53 +0100 Subject: [PATCH 13/27] typo Signed-off-by: Nicolas Rol --- .../java/com/powsybl/network/store/iidm/impl/TerminalImpl.java | 2 +- 1 file changed, 1 insertion(+), 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 2f9c3105d..ba9d61113 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 @@ -202,7 +202,7 @@ private boolean connectNodeBreaker(Resource voltageLevel // Get the switch behind the switchAttributes Optional sw = index.getSwitch(switchAttributes.getResource().getId()); - // THe weight is 1 if the switch is operable and open, else 0 + // The weight is 1 if the switch is operable and open, else 0 return sw.isPresent() && openOperableSwitch.test(sw.get()); } else { return false; From 10d487ae5bfd4e64b194f36f63a53a609c17b776 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 10 Jan 2024 18:22:56 +0100 Subject: [PATCH 14/27] extracted method isSwitchOperableAndPresent to avoid duplication Signed-off-by: Nicolas Rol --- .../network/store/iidm/impl/TerminalImpl.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) 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 ba9d61113..afb945f9d 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 @@ -149,14 +149,18 @@ private Set getBusbarSectionNodes(Resource volt } private double computeEdgeWeight(Edge edge, Predicate openOperableSwitch) { + return isSwitchOperableAndPresent(edge, openOperableSwitch) ? 1d : 0d; + } + + private boolean isSwitchOperableAndPresent(Edge edge, Predicate openOperableSwitch) { if (edge.getBiConnectable() instanceof SwitchAttributes switchAttributes) { // Get the switch behind the switchAttributes Optional sw = index.getSwitch(switchAttributes.getResource().getId()); // THe weight is 1 if the switch is operable and open, else 0 - return sw.isPresent() && openOperableSwitch.test(sw.get()) ? 1d : 0d; + return sw.isPresent() && openOperableSwitch.test(sw.get()); } else { - return 0d; + return false; } } @@ -197,17 +201,7 @@ private boolean connectNodeBreaker(Resource voltageLevel // close all open operable switches on the path shortestPath.getEdgeList().stream() - .filter(edge -> { - if (edge.getBiConnectable() instanceof SwitchAttributes switchAttributes) { - // Get the switch behind the switchAttributes - Optional sw = index.getSwitch(switchAttributes.getResource().getId()); - - // The weight is 1 if the switch is operable and open, else 0 - return sw.isPresent() && openOperableSwitch.test(sw.get()); - } else { - return false; - } - }) + .filter(edge -> isSwitchOperableAndPresent(edge, openOperableSwitch)) .forEach(edge -> { if (edge.getBiConnectable() instanceof SwitchAttributes switchAttributes) { switchAttributes.setOpen(false); From 9b697a950f0ba5c60ff0013daf05e6403d0fc95f Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 10 Jan 2024 18:30:38 +0100 Subject: [PATCH 15/27] change variable name from limitType to type for consistency Signed-off-by: Nicolas Rol --- .../iidm/impl/ThreeWindingsTransformerImpl.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 8191ed548..6d18a668a 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 @@ -424,18 +424,18 @@ public int getOverloadDuration() { } @Override - public boolean checkPermanentLimit(ThreeSides side, float limitReduction, LimitType limitType) { - return LimitViolationUtils.checkPermanentLimit(this, side, limitReduction, limitType); + public boolean checkPermanentLimit(ThreeSides side, float limitReduction, LimitType type) { + return LimitViolationUtils.checkPermanentLimit(this, side, limitReduction, type); } @Override - public boolean checkPermanentLimit(ThreeSides side, LimitType limitType) { - return checkPermanentLimit(side, 1f, limitType); + public boolean checkPermanentLimit(ThreeSides side, LimitType type) { + return checkPermanentLimit(side, 1f, type); } @Override - public boolean checkPermanentLimit1(float limitReduction, LimitType limitType) { - return checkPermanentLimit(ThreeSides.ONE, limitReduction, limitType); + public boolean checkPermanentLimit1(float limitReduction, LimitType type) { + return checkPermanentLimit(ThreeSides.ONE, limitReduction, type); } @Override From 254328adbde79d0fec7391fad584bc2d5528b642 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 10 Jan 2024 18:39:23 +0100 Subject: [PATCH 16/27] error message changed for consistency Signed-off-by: Nicolas Rol --- .../store/iidm/impl/extensions/OperatingStatusAdderImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java index 46a093e1b..c641dd10c 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java @@ -31,7 +31,7 @@ protected OperatingStatusAdderImpl(C extendable) { protected OperatingStatus createExtension(C extendable) { ((AbstractIdentifiableImpl) extendable).updateResource(res -> { if (!(res.getAttributes() instanceof OperatingStatusHolder)) { - throw new IllegalStateException("Not a branch status holder"); + throw new IllegalStateException("Not an operating status holder"); } ((OperatingStatusHolder) res.getAttributes()).setOperatingStatus(status.name()); }); From c5f66eff336c5fc3161e10f15ad990b44c70837a Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 10 Jan 2024 18:41:27 +0100 Subject: [PATCH 17/27] removed unused import Signed-off-by: Nicolas Rol --- .../java/com/powsybl/network/store/model/LineAttributes.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java index f0440c647..9dbe7dd93 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java @@ -9,7 +9,8 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; -import java.util.*; +import java.util.Map; +import java.util.Set; /** * @author Geoffroy Jamgotchian From 9ca08c2fcde885ccba28804f194771a06f062c53 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 10 Jan 2024 18:42:46 +0100 Subject: [PATCH 18/27] removed unused import Signed-off-by: Nicolas Rol --- .../powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java index b659a9de4..306a03daa 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java @@ -7,7 +7,6 @@ package com.powsybl.network.store.iidm.impl.tck; import com.powsybl.iidm.network.tck.AbstractMergeNetworkTest; -import org.junit.jupiter.api.Test; /** * @author Geoffroy Jamgotchian From 896f7093ee04aa7af3bff0bcb47757702dc3dc62 Mon Sep 17 00:00:00 2001 From: Nicolas Rol <135979730+rolnico@users.noreply.github.com> Date: Thu, 11 Jan 2024 17:22:39 +0100 Subject: [PATCH 19/27] initialise reportercontext Co-authored-by: Antoine Bouhours <123802855+antoinebhs@users.noreply.github.com> Signed-off-by: Nicolas Rol <135979730+rolnico@users.noreply.github.com> --- .../java/com/powsybl/network/store/iidm/impl/NetworkImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java index 9fd0fc5a8..2647a8f59 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java @@ -48,6 +48,7 @@ public class NetworkImpl extends AbstractIdentifiableImpl resource) { super(new NetworkObjectIndex(storeClient), resource); + this.reporterContext = new SimpleReporterContext(); index.setNetwork(this); } From 0625c8f31640929ba2bb819cd194724bdf589a17 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 24 Jan 2024 10:13:03 +0100 Subject: [PATCH 20/27] changed createObjectMapper Signed-off-by: Nicolas Rol --- .../com/powsybl/network/store/client/RestClientImpl.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java index b8515c232..1449f5e81 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java @@ -6,12 +6,8 @@ */ package com.powsybl.network.store.client; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.powsybl.commons.PowsyblException; -import com.powsybl.commons.json.JsonUtil; import com.powsybl.network.store.model.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.client.RestTemplateBuilder; @@ -48,10 +44,7 @@ public static RestTemplateBuilder createRestTemplateBuilder(String baseUri) { } private static ObjectMapper createObjectMapper() { - return JsonUtil.createObjectMapper() - .registerModule(new JavaTimeModule()) - .configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false) - .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); + return new ObjectMapper(); } private static MappingJackson2HttpMessageConverter createMapping() { From bcb9a6136c3ec9df4c023088c5aae2a815fec49f Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 24 Jan 2024 10:19:51 +0100 Subject: [PATCH 21/27] update powsybl-dependency to 2023.4.1 Signed-off-by: Nicolas Rol --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 15bab5e89..fdd046b56 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ 3.1.2 3.9 - 2023.4.0 + 2023.4.1 1.7.0 2.0.4 1.4.5 From f615e463286194952fba1d9c26b9a78eaf77f612 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 24 Jan 2024 10:21:12 +0100 Subject: [PATCH 22/27] changed description Signed-off-by: Nicolas Rol --- .../java/com/powsybl/network/store/model/LineAttributes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java index 9dbe7dd93..07562bfe2 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java @@ -123,6 +123,6 @@ public class LineAttributes extends AbstractAttributes implements BranchAttribut @Schema(description = "Active power limit side 2") private LimitsAttributes activePowerLimits2; - @Schema(description = "Branch status") + @Schema(description = "Operating status") private String operatingStatus; } From 335765843711b2fcd037056526e22fb33563d449 Mon Sep 17 00:00:00 2001 From: Nicolas Rol <135979730+rolnico@users.noreply.github.com> Date: Wed, 24 Jan 2024 11:07:33 +0100 Subject: [PATCH 23/27] Extends Idenfiable instead of Connectable Co-authored-by: Antoine Bouhours <123802855+antoinebhs@users.noreply.github.com> Signed-off-by: Nicolas Rol <135979730+rolnico@users.noreply.github.com> --- .../store/iidm/impl/extensions/OperatingStatusAdderImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java index c641dd10c..fb4f373de 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java @@ -18,7 +18,7 @@ /** * @author Nicolas Noir */ -public class OperatingStatusAdderImpl> +public class OperatingStatusAdderImpl> extends AbstractExtensionAdder> implements OperatingStatusAdder { private OperatingStatus.Status status = OperatingStatus.Status.IN_OPERATION; From 1c848c3b52ef31360a72e599aa43ef87218a9022 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 24 Jan 2024 11:40:18 +0100 Subject: [PATCH 24/27] added JavaTimeModule back to objectMapper Signed-off-by: Nicolas Rol --- .../com/powsybl/network/store/client/RestClientImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java index 1449f5e81..41bc31600 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java @@ -7,6 +7,7 @@ package com.powsybl.network.store.client; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.powsybl.commons.PowsyblException; import com.powsybl.network.store.model.*; import org.springframework.beans.factory.annotation.Autowired; @@ -44,7 +45,9 @@ public static RestTemplateBuilder createRestTemplateBuilder(String baseUri) { } private static ObjectMapper createObjectMapper() { - return new ObjectMapper(); + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JavaTimeModule()); + return objectMapper; } private static MappingJackson2HttpMessageConverter createMapping() { From 6b015b6c4932b3964ddee330864b7b294a6a4bca Mon Sep 17 00:00:00 2001 From: Nicolas Rol <135979730+rolnico@users.noreply.github.com> Date: Wed, 24 Jan 2024 11:44:18 +0100 Subject: [PATCH 25/27] Apply suggestions from code review Co-authored-by: Antoine Bouhours <123802855+antoinebhs@users.noreply.github.com> Signed-off-by: Nicolas Rol <135979730+rolnico@users.noreply.github.com> --- .../iidm/impl/extensions/OperatingStatusAdderImpl.java | 6 +++--- .../impl/extensions/OperatingStatusAdderImplProvider.java | 8 ++++---- .../store/iidm/impl/extensions/OperatingStatusImpl.java | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java index fb4f373de..acbe16ea9 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java @@ -19,16 +19,16 @@ * @author Nicolas Noir */ public class OperatingStatusAdderImpl> - extends AbstractExtensionAdder> implements OperatingStatusAdder { + extends AbstractExtensionAdder> implements OperatingStatusAdder { private OperatingStatus.Status status = OperatingStatus.Status.IN_OPERATION; - protected OperatingStatusAdderImpl(C extendable) { + protected OperatingStatusAdderImpl(I identifiable) { super(extendable); } @Override - protected OperatingStatus createExtension(C extendable) { + protected OperatingStatus createExtension(I identifiable) { ((AbstractIdentifiableImpl) extendable).updateResource(res -> { if (!(res.getAttributes() instanceof OperatingStatusHolder)) { throw new IllegalStateException("Not an operating status holder"); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImplProvider.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImplProvider.java index 830c2fecb..c2addadd1 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImplProvider.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImplProvider.java @@ -15,8 +15,8 @@ * @author Nicolas Noir */ @AutoService(ExtensionAdderProvider.class) -public class OperatingStatusAdderImplProvider> implements - ExtensionAdderProvider, OperatingStatusAdderImpl> { +public class OperatingStatusAdderImplProvider> implements + ExtensionAdderProvider, OperatingStatusAdderImpl> { @Override public String getImplementationName() { @@ -29,8 +29,8 @@ public Class getAdderClass() { } @Override - public OperatingStatusAdderImpl newAdder(C connectable) { - return new OperatingStatusAdderImpl<>(connectable); + public OperatingStatusAdderImpl newAdder(I identifiable) { + return new OperatingStatusAdderImpl<>(identifiable); } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusImpl.java index b7cbb9aa0..cbb631e31 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusImpl.java @@ -15,9 +15,9 @@ /** * @author Nicolas Noir */ -public class OperatingStatusImpl> extends AbstractExtension implements OperatingStatus { +public class OperatingStatusImpl> extends AbstractExtension implements OperatingStatus { - public OperatingStatusImpl(C connectable) { + public OperatingStatusImpl(I identifiable) { super(connectable); } From a481862dab51bb289b6b0a477ba2a0d4fb9626d2 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 24 Jan 2024 14:06:39 +0100 Subject: [PATCH 26/27] corrections Signed-off-by: Nicolas Rol --- .../iidm/impl/extensions/OperatingStatusAdderImpl.java | 10 +++++----- .../extensions/OperatingStatusAdderImplProvider.java | 4 ++-- .../iidm/impl/extensions/OperatingStatusImpl.java | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java index acbe16ea9..0fd0c8b7b 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImpl.java @@ -7,7 +7,7 @@ package com.powsybl.network.store.iidm.impl.extensions; import com.powsybl.commons.extensions.AbstractExtensionAdder; -import com.powsybl.iidm.network.Connectable; +import com.powsybl.iidm.network.Identifiable; import com.powsybl.iidm.network.extensions.OperatingStatus; import com.powsybl.iidm.network.extensions.OperatingStatusAdder; import com.powsybl.network.store.iidm.impl.AbstractIdentifiableImpl; @@ -24,22 +24,22 @@ public class OperatingStatusAdderImpl> private OperatingStatus.Status status = OperatingStatus.Status.IN_OPERATION; protected OperatingStatusAdderImpl(I identifiable) { - super(extendable); + super(identifiable); } @Override protected OperatingStatus createExtension(I identifiable) { - ((AbstractIdentifiableImpl) extendable).updateResource(res -> { + ((AbstractIdentifiableImpl) identifiable).updateResource(res -> { if (!(res.getAttributes() instanceof OperatingStatusHolder)) { throw new IllegalStateException("Not an operating status holder"); } ((OperatingStatusHolder) res.getAttributes()).setOperatingStatus(status.name()); }); - return new OperatingStatusImpl<>(extendable); + return new OperatingStatusImpl<>(identifiable); } @Override - public OperatingStatusAdder withStatus(OperatingStatus.Status status) { + public OperatingStatusAdder withStatus(OperatingStatus.Status status) { this.status = Objects.requireNonNull(status); return this; } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImplProvider.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImplProvider.java index c2addadd1..a97b02584 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImplProvider.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusAdderImplProvider.java @@ -8,7 +8,7 @@ import com.google.auto.service.AutoService; import com.powsybl.commons.extensions.ExtensionAdderProvider; -import com.powsybl.iidm.network.Connectable; +import com.powsybl.iidm.network.Identifiable; import com.powsybl.iidm.network.extensions.OperatingStatus; /** @@ -29,7 +29,7 @@ public Class getAdderClass() { } @Override - public OperatingStatusAdderImpl newAdder(I identifiable) { + public OperatingStatusAdderImpl newAdder(I identifiable) { return new OperatingStatusAdderImpl<>(identifiable); } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusImpl.java index cbb631e31..f5a617862 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/OperatingStatusImpl.java @@ -7,7 +7,7 @@ package com.powsybl.network.store.iidm.impl.extensions; import com.powsybl.commons.extensions.AbstractExtension; -import com.powsybl.iidm.network.Connectable; +import com.powsybl.iidm.network.Identifiable; import com.powsybl.iidm.network.extensions.OperatingStatus; import com.powsybl.network.store.iidm.impl.AbstractIdentifiableImpl; import com.powsybl.network.store.model.OperatingStatusHolder; @@ -18,7 +18,7 @@ public class OperatingStatusImpl> extends AbstractExtension implements OperatingStatus { public OperatingStatusImpl(I identifiable) { - super(connectable); + super(identifiable); } @Override @@ -28,7 +28,7 @@ public Status getStatus() { } @Override - public OperatingStatus setStatus(Status status) { + public OperatingStatus setStatus(Status status) { ((AbstractIdentifiableImpl) getExtendable()).updateResource(res -> ((OperatingStatusHolder) res.getAttributes()).setOperatingStatus(status.name())); return this; } From 9d9bc998950ec6a69e483141a39480d265f947a5 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 24 Jan 2024 15:42:52 +0100 Subject: [PATCH 27/27] corrections continued Signed-off-by: Nicolas Rol --- .../com/powsybl/network/store/client/RestClientImpl.java | 6 +++++- .../com/powsybl/network/store/iidm/impl/TerminalImpl.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java index 41bc31600..ac2128775 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java @@ -6,7 +6,9 @@ */ package com.powsybl.network.store.client; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.powsybl.commons.PowsyblException; import com.powsybl.network.store.model.*; @@ -46,7 +48,9 @@ public static RestTemplateBuilder createRestTemplateBuilder(String baseUri) { private static ObjectMapper createObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JavaTimeModule()); + objectMapper.registerModule(new JavaTimeModule()) + .configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false) + .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); return objectMapper; } 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 afb945f9d..01b460f06 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 @@ -191,7 +191,7 @@ private boolean connectNodeBreaker(Resource voltageLevel List> allPaths = allDirectedPaths.getAllPaths(Set.of(node), busbarSectionNodes, true, null); // Sort the paths by weight then by length - allPaths.sort(Comparator.comparingDouble((GraphPath path) -> path.getWeight()).thenComparingInt(GraphPath::getLength)); + allPaths.sort(Comparator.comparingDouble(GraphPath::getWeight).thenComparingInt(GraphPath::getLength)); // Close the shortest path Set closedSwitches = new HashSet<>();