From 51ff55e18b475a1fbbfe2cc3d91770163df13e72 Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Fri, 18 Oct 2024 15:46:12 +0200 Subject: [PATCH] fix all Signed-off-by: Etienne LESOT --- .../iidm/impl/AbstractInjectionImpl.java | 6 +++- .../BranchToInjectionAttributesAdapter.java | 15 +++++++- .../impl/BusbarSectionToInjectionAdapter.java | 16 +++++++++ .../store/iidm/impl/NetworkObjectIndex.java | 35 +++++++++++++++++++ .../store/iidm/impl/RegulatingPoint.java | 31 +++++++++++++--- .../network/store/iidm/impl/TerminalImpl.java | 26 +++++--------- .../store/iidm/impl/TerminalRefUtils.java | 33 +++++++++++------ ...ansformerToInjectionAttributesAdapter.java | 15 ++++++++ .../model/AbstractIdentifiableAttributes.java | 6 +--- .../store/model/BatteryAttributes.java | 7 ++++ .../store/model/DanglingLineAttributes.java | 4 +++ .../store/model/GeneratorAttributes.java | 7 ++++ .../network/store/model/GroundAttributes.java | 7 ++++ .../store/model/IdentifiableAttributes.java | 5 --- .../store/model/InjectionAttributes.java | 5 +++ .../model/LccConverterStationAttributes.java | 7 ++++ .../network/store/model/LoadAttributes.java | 7 ++++ .../model/RegulationPointAttributes.java | 2 +- .../model/ShuntCompensatorAttributes.java | 7 ++++ .../model/StaticVarCompensatorAttributes.java | 7 ++++ .../model/VscConverterStationAttributes.java | 7 ++++ .../store/model/TopLevelDocumentTest.java | 15 +++++--- 22 files changed, 219 insertions(+), 51 deletions(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractInjectionImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractInjectionImpl.java index a6dc9e4aa..9bb9eaa40 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractInjectionImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractInjectionImpl.java @@ -63,7 +63,7 @@ protected void setRegTerminal(Terminal regulatingTerminal) { if (regulatingTerminal instanceof TerminalImpl) { regulatingPoint.setRegulatingTerminal((TerminalImpl) regulatingTerminal); } else { - regulatingPoint.setRegulatingTerminalAsLocalTerminal(); + regulatingPoint.setRegulatingTerminalAsLocalTerminalAndRemoveRegulation(); } } @@ -107,4 +107,8 @@ public > Collection getExtensions() { public List getTerminals(ThreeSides side) { return (side == null || side.equals(ThreeSides.ONE)) ? Collections.singletonList(terminal) : Collections.emptyList(); } + + public RegulatingPoint getRegulatingPoint() { + return regulatingPoint; + } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BranchToInjectionAttributesAdapter.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BranchToInjectionAttributesAdapter.java index 98864175f..9b2f42338 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BranchToInjectionAttributesAdapter.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BranchToInjectionAttributesAdapter.java @@ -9,7 +9,10 @@ import com.powsybl.iidm.network.Branch; import com.powsybl.network.store.model.BranchAttributes; import com.powsybl.network.store.model.ConnectablePositionAttributes; +import com.powsybl.network.store.model.ResourceType; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; /** @@ -18,7 +21,7 @@ public class BranchToInjectionAttributesAdapter extends AbstractIdentifiableToInjectionAttributesAdapter { private final AbstractBranchImpl, ? extends BranchAttributes> branch; - + private Map regulatingEquipments = new HashMap<>(); private final boolean side1; public BranchToInjectionAttributesAdapter(AbstractBranchImpl, ? extends BranchAttributes> branch, BranchAttributes attributes, boolean side1) { @@ -132,4 +135,14 @@ public void setPosition(ConnectablePositionAttributes position) { attributes.setPosition2(position); } } + + @Override + public Map getRegulatingEquipments() { + return regulatingEquipments; + } + + @Override + public void setRegulatingEquipments(Map regulatingEquipments) { + this.regulatingEquipments = regulatingEquipments; + } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionToInjectionAdapter.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionToInjectionAdapter.java index 95e6787b2..b7927e798 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionToInjectionAdapter.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionToInjectionAdapter.java @@ -8,12 +8,18 @@ import com.powsybl.network.store.model.BusbarSectionAttributes; import com.powsybl.network.store.model.ConnectablePositionAttributes; +import com.powsybl.network.store.model.ResourceType; + +import java.util.HashMap; +import java.util.Map; /** * @author Geoffroy Jamgotchian */ public class BusbarSectionToInjectionAdapter extends AbstractIdentifiableToInjectionAttributesAdapter { + private Map regulatingEquipments = new HashMap<>(); + public BusbarSectionToInjectionAdapter(BusbarSectionAttributes attributes) { super(attributes); } @@ -87,4 +93,14 @@ public ConnectablePositionAttributes getPosition() { public void setPosition(ConnectablePositionAttributes position) { throw new AssertionError(); } + + @Override + public Map getRegulatingEquipments() { + return regulatingEquipments; + } + + @Override + public void setRegulatingEquipments(Map regulatingEquipments) { + this.regulatingEquipments = regulatingEquipments; + } } 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 ca0ebb1bc..5bec92abd 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 @@ -1067,6 +1067,41 @@ public Identifiable getIdentifiable(String id) { return null; } + public AbstractInjectionImpl getRegulatingEquipment(String id, ResourceType resourceType) { + return switch (resourceType) { + case STATIC_VAR_COMPENSATOR -> getStaticVarCompensator(id).orElse(null); + case GENERATOR -> getGenerator(id).orElse(null); + case VSC_CONVERTER_STATION -> getVscConverterStation(id).orElse(null); + case SHUNT_COMPENSATOR -> getShuntCompensator(id).orElse(null); + default -> throw new PowsyblException(String.format("equipement : %s of type %s does not regulate", id, resourceType)); + }; + } + + public AbstractIdentifiableImpl getIdentifiable(String id, ResourceType resourceType) { + return switch (resourceType) { + case LOAD -> getLoad(id).orElse(null); + case STATIC_VAR_COMPENSATOR -> getStaticVarCompensator(id).orElse(null); + case LINE -> getLine(id).orElse(null); + case BATTERY -> getBattery(id).orElse(null); + case GENERATOR -> getGenerator(id).orElse(null); + case BUSBAR_SECTION -> getBusbarSection(id).orElse(null); + case TWO_WINDINGS_TRANSFORMER -> getTwoWindingsTransformer(id).orElse(null); + case THREE_WINDINGS_TRANSFORMER -> getThreeWindingsTransformer(id).orElse(null); + case VSC_CONVERTER_STATION -> getVscConverterStation(id).orElse(null); + case SHUNT_COMPENSATOR -> getShuntCompensator(id).orElse(null); + case VOLTAGE_LEVEL -> getVoltageLevel(id).orElse(null); + case DANGLING_LINE -> getDanglingLine(id).orElse(null); + case SUBSTATION -> getSubstation(id).orElse(null); + case LCC_CONVERTER_STATION -> getLccConverterStation(id).orElse(null); + case SWITCH -> getSwitch(id).orElse(null); + case HVDC_LINE -> getHvdcLine(id).orElse(null); + case GROUND -> getGround(id).orElse(null); + case CONFIGURED_BUS -> getConfiguredBus(id).orElse(null); + case TIE_LINE -> getTieLine(id).orElse(null); + case NETWORK -> throw new PowsyblException("the identifiable asked can not be the network"); + }; + } + public void removeDanglingLine(String danglingLineId) { danglingLineCache.remove(danglingLineId); } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RegulatingPoint.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RegulatingPoint.java index 8db58683c..c42f3db20 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RegulatingPoint.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RegulatingPoint.java @@ -44,8 +44,11 @@ public Terminal getRegulatingTerminal() { } public void setRegulatingTerminal(TerminalImpl regulatingTerminal) { - TerminalImpl oldRegulatingTerminal = (TerminalImpl) TerminalRefUtils.getTerminal(index, getAttributes().getRegulatingTerminal()); - oldRegulatingTerminal.removeRegulatingPoint(this); + TerminalImpl oldRegulatingTerminal = (TerminalImpl) TerminalRefUtils.getTerminal(index, + getAttributes().getRegulatingTerminal(), getAttributes().getRegulatingResourceType()); + if (oldRegulatingTerminal != null) { + oldRegulatingTerminal.removeRegulatingPoint(this); + } regulatingTerminal.addNewRegulatingPoint(this); identifiable.updateResource(res -> getAttributes((Resource) res) .setRegulatingTerminal(TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal))); @@ -53,6 +56,15 @@ public void setRegulatingTerminal(TerminalImpl regulatingTerminal) { .setRegulatingResourceType(ResourceType.convert(regulatingTerminal.getConnectable().getType()))); } + public void setRegulatingTerminalAsLocalTerminalAndRemoveRegulation() { + TerminalImpl oldRegulatingTerminal = (TerminalImpl) TerminalRefUtils.getTerminal(index, + getAttributes().getRegulatingTerminal(), getAttributes().getRegulatingResourceType()); + if (oldRegulatingTerminal != null) { + oldRegulatingTerminal.removeRegulatingPoint(this); + } + setRegulatingTerminalAsLocalTerminal(); + } + public void setRegulatingTerminalAsLocalTerminal() { identifiable.updateResource(res -> getAttributes((Resource) res).setRegulatingTerminal(getAttributes().getLocalTerminal())); identifiable.updateResource(res -> getAttributes((Resource) res).setRegulatingResourceType(getAttributes().getResourceType())); @@ -63,8 +75,11 @@ public void setRegulationMode(String regulationModeOrdinal) { } public void removeRegulation() { - Terminal localTerminal = TerminalRefUtils.getTerminal(index, getAttributes().getLocalTerminal()); - Terminal regulatingTerminal = TerminalRefUtils.getTerminal(index, getAttributes().getRegulatingTerminal()); + TerminalImpl localTerminal = (TerminalImpl) TerminalRefUtils.getTerminal(index, + getAttributes().getLocalTerminal(), getAttributes().getResourceType()); + Terminal regulatingTerminal = TerminalRefUtils.getTerminal(index, getAttributes().getRegulatingTerminal(), + getAttributes().getRegulatingResourceType()); + // set local terminal as regulating terminal setRegulatingTerminalAsLocalTerminal(); // if localTerminal or regulatingTerminal is not connected then the bus is null if (localTerminal.isConnected() && regulatingTerminal.isConnected() && !localTerminal.getBusView().getBus().equals(regulatingTerminal.getBusView().getBus())) { @@ -82,4 +97,12 @@ void remove() { TerminalImpl regulatingTerminal = (TerminalImpl) TerminalRefUtils.getTerminal(index, getAttributes().getRegulatingTerminal()); regulatingTerminal.removeRegulatingPoint(this); } + + public String getRegulatingEquipmentId() { + return getAttributes().getRegulatedEquipmentId(); + } + + public ResourceType getRegulatingEquipmentType() { + return getAttributes().getResourceType(); + } } 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 ac566ce46..be9a9cb00 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 @@ -36,8 +36,6 @@ public class TerminalImpl implements Terminal, private final TerminalBusViewImpl busView; - private final List regulated = new ArrayList<>(); - public TerminalImpl(NetworkObjectIndex index, Connectable connectable, Function, InjectionAttributes> attributesGetter) { this.index = index; this.connectable = connectable; @@ -45,18 +43,6 @@ public TerminalImpl(NetworkObjectIndex index, Connectable connectable, Functi nodeBreakerView = new TerminalNodeBreakerViewImpl<>(index, connectable, attributesGetter); busBreakerView = new TerminalBusBreakerViewImpl<>(index, connectable, attributesGetter); busView = new TerminalBusViewImpl<>(index, connectable, attributesGetter); - setRegulated(); - } - - private void setRegulated() { - if (getAttributes().getRegulatingEquipments() != null) { - getAttributes().getRegulatingEquipments() - .forEach(regulatingEquipment -> { - // get identifiable create stack overflow error - regulated.add(new RegulatingPoint(index, (AbstractIdentifiableImpl) index.getIdentifiable(regulatingEquipment), - AbstractIdentifiableAttributes.class::cast)); - }); - } } private TopologyKind getTopologyKind() { @@ -587,15 +573,19 @@ public ThreeSides getSide() { } public void addNewRegulatingPoint(RegulatingPoint regulatingPoint) { - regulated.add(regulatingPoint); + getAttributes().getRegulatingEquipments() + .put(regulatingPoint.getRegulatingEquipmentId(), regulatingPoint.getRegulatingEquipmentType()); } public void removeRegulatingPoint(RegulatingPoint regulatingPoint) { - regulated.remove(regulatingPoint); + getAttributes().getRegulatingEquipments() + .remove(regulatingPoint.getRegulatingEquipmentId()); } public void removeAsRegulatingPoint() { - regulated.forEach(RegulatingPoint::removeRegulation); - regulated.clear(); + getAttributes().getRegulatingEquipments().forEach((regulatingEquipmentId, resourceType) -> + index.getRegulatingEquipment(regulatingEquipmentId, resourceType) + .getRegulatingPoint().removeRegulation()); + getAttributes().getRegulatingEquipments().clear(); } } 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 8ca238958..aeeb93f4c 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 @@ -7,6 +7,7 @@ package com.powsybl.network.store.iidm.impl; import com.powsybl.iidm.network.*; +import com.powsybl.network.store.model.ResourceType; import com.powsybl.network.store.model.TerminalRefAttributes; /** @@ -18,18 +19,30 @@ private TerminalRefUtils() { } public static Terminal getTerminal(NetworkObjectIndex index, TerminalRefAttributes terminalRefAttributes) { + return getTerminal(index, terminalRefAttributes, null); + } + + public static Terminal getTerminal(NetworkObjectIndex index, TerminalRefAttributes terminalRefAttributes, ResourceType resourceType) { if (terminalRefAttributes == null) { return null; } - Identifiable identifiable = index.getIdentifiable(terminalRefAttributes.getConnectableId()); + Identifiable identifiable; + if (resourceType == null) { + identifiable = index.getIdentifiable(terminalRefAttributes.getConnectableId()); + } else { + identifiable = index.getIdentifiable(terminalRefAttributes.getConnectableId(), resourceType); + } + if (identifiable == null) { + return null; + } + String side = terminalRefAttributes.getSide(); - if (identifiable instanceof Injection) { - return ((Injection) identifiable).getTerminal(); - } else if (identifiable instanceof Branch) { - return ((Branch) identifiable).getTerminal(TwoSides.valueOf(side)); - } else if (identifiable instanceof ThreeWindingsTransformer) { - ThreeWindingsTransformer twt = (ThreeWindingsTransformer) identifiable; + if (identifiable instanceof Injection injection) { + return injection.getTerminal(); + } else if (identifiable instanceof Branch branch) { + return branch.getTerminal(TwoSides.valueOf(side)); + } else if (identifiable instanceof ThreeWindingsTransformer twt) { return twt.getTerminal(ThreeSides.valueOf(side)); } else { throw new AssertionError("Unexpected Identifiable instance: " + identifiable.getClass()); @@ -39,11 +52,9 @@ public static Terminal getTerminal(NetworkObjectIndex index, TerminalRefAttribut private static String getSide(Terminal terminal) { String side = null; if (terminal.getConnectable().getTerminals().size() > 1) { - if (terminal.getConnectable() instanceof Branch) { - Branch branch = (Branch) terminal.getConnectable(); + if (terminal.getConnectable() instanceof Branch branch) { side = branch.getSide(terminal).name(); - } else if (terminal.getConnectable() instanceof ThreeWindingsTransformer) { - ThreeWindingsTransformer twt = (ThreeWindingsTransformer) terminal.getConnectable(); + } else if (terminal.getConnectable() instanceof ThreeWindingsTransformer twt) { side = twt.getSide(terminal).name(); } else { throw new AssertionError("Unexpected connectable instance: " + terminal.getConnectable().getClass()); 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 c1227b8ea..b2e5decb6 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 @@ -9,14 +9,19 @@ import com.powsybl.iidm.network.ThreeSides; import com.powsybl.network.store.model.ConnectablePositionAttributes; import com.powsybl.network.store.model.LegAttributes; +import com.powsybl.network.store.model.ResourceType; import com.powsybl.network.store.model.ThreeWindingsTransformerAttributes; +import java.util.HashMap; +import java.util.Map; + /** * @author Geoffroy Jamgotchian */ public class ThreeWindingsTransformerToInjectionAttributesAdapter extends AbstractIdentifiableToInjectionAttributesAdapter { private final ThreeSides side; + private Map regulatingEquipments = new HashMap<>(); public ThreeWindingsTransformerToInjectionAttributesAdapter(ThreeWindingsTransformerAttributes attributes, ThreeSides side) { super(attributes); @@ -131,4 +136,14 @@ public void setPosition(ConnectablePositionAttributes position) { default -> throw createUnknownSideException(); } } + + @Override + public Map getRegulatingEquipments() { + return regulatingEquipments; + } + + @Override + public void setRegulatingEquipments(Map regulatingEquipments) { + this.regulatingEquipments = regulatingEquipments; + } } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/AbstractIdentifiableAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/AbstractIdentifiableAttributes.java index 47d880bc9..6a6be20f7 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/AbstractIdentifiableAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/AbstractIdentifiableAttributes.java @@ -14,7 +14,6 @@ import lombok.experimental.SuperBuilder; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Set; @@ -43,13 +42,10 @@ public abstract class AbstractIdentifiableAttributes extends AbstractAttributes @Schema(description = "Alias by type") private Map aliasByType; - @Schema(description = "Extension attributes") @Builder.Default + @Schema(description = "Extension attributes") private Map extensionAttributes = new HashMap<>(); @Schema(description = "regulation info") private RegulationPointAttributes regulationPoint; - - @Schema(description = "regulatingEquipments") - private List regulatingEquipments; } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/BatteryAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/BatteryAttributes.java index 9e216bf8d..2070a4275 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/BatteryAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/BatteryAttributes.java @@ -10,6 +10,9 @@ import lombok.*; import lombok.experimental.SuperBuilder; +import java.util.HashMap; +import java.util.Map; + /** * @author Nicolas Noir */ @@ -58,4 +61,8 @@ public class BatteryAttributes extends AbstractIdentifiableAttributes implements @Schema(description = "reactiveLimits") private ReactiveLimitsAttributes reactiveLimits; + + @Builder.Default + @Schema(description = "regulatingEquipments") + private Map regulatingEquipments = new HashMap<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/DanglingLineAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/DanglingLineAttributes.java index aeefec18a..3a1ecedc5 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/DanglingLineAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/DanglingLineAttributes.java @@ -84,6 +84,10 @@ public class DanglingLineAttributes extends AbstractIdentifiableAttributes imple @Schema(description = "Tie line ID in case of a paired dangling line") private String tieLineId; + @Builder.Default + @Schema(description = "regulatingEquipments") + private Map regulatingEquipments = new HashMap<>(); + @Override @JsonIgnore public List getSideList() { diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/GeneratorAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/GeneratorAttributes.java index e36c726b7..b9bd6fee3 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/GeneratorAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/GeneratorAttributes.java @@ -11,6 +11,9 @@ import lombok.*; import lombok.experimental.SuperBuilder; +import java.util.HashMap; +import java.util.Map; + /** * @author Geoffroy Jamgotchian */ @@ -86,4 +89,8 @@ public class GeneratorAttributes extends AbstractIdentifiableAttributes implemen @Schema(description = "Condenser") private boolean condenser; + + @Builder.Default + @Schema(description = "regulatingEquipments") + private Map regulatingEquipments = new HashMap<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/GroundAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/GroundAttributes.java index a4b12d995..7c4a89ace 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/GroundAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/GroundAttributes.java @@ -10,6 +10,9 @@ import lombok.*; import lombok.experimental.SuperBuilder; +import java.util.HashMap; +import java.util.Map; + /** * @author Ayoub LABIDI */ @@ -43,4 +46,8 @@ public class GroundAttributes extends AbstractIdentifiableAttributes implements @Schema(description = "Connectable position (for substation diagram)") private ConnectablePositionAttributes position; + + @Builder.Default + @Schema(description = "regulatingEquipments") + private Map regulatingEquipments = new HashMap<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/IdentifiableAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/IdentifiableAttributes.java index ba1f18915..395a5e979 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/IdentifiableAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/IdentifiableAttributes.java @@ -8,8 +8,6 @@ import com.fasterxml.jackson.annotation.JsonInclude; -import java.util.Collections; -import java.util.List; import java.util.Map; import java.util.Set; @@ -47,7 +45,4 @@ default Attributes filter(AttributeFilter filter) { void setExtensionAttributes(Map extensionAttributes); - default List getRegulatingEquipments() { - return Collections.emptyList(); - } } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/InjectionAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/InjectionAttributes.java index ba72590f2..8482dbe40 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/InjectionAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/InjectionAttributes.java @@ -10,6 +10,7 @@ import com.powsybl.commons.PowsyblException; import java.util.Collections; +import java.util.Map; import java.util.Set; /** @@ -50,6 +51,10 @@ default Set getContainerIds() { return Collections.singleton(getVoltageLevelId()); } + Map getRegulatingEquipments(); + + void setRegulatingEquipments(Map regulatingEquipments); + @JsonIgnore @Override default Attributes filter(AttributeFilter filter) { diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/LccConverterStationAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/LccConverterStationAttributes.java index 315593851..8e90696f5 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/LccConverterStationAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/LccConverterStationAttributes.java @@ -10,6 +10,9 @@ import lombok.*; import lombok.experimental.SuperBuilder; +import java.util.HashMap; +import java.util.Map; + /** * @author Nicolas Noir */ @@ -50,4 +53,8 @@ public class LccConverterStationAttributes extends AbstractIdentifiableAttribute @Schema(description = "Connectable position (for substation diagram)") private ConnectablePositionAttributes position; + + @Builder.Default + @Schema(description = "regulatingEquipments") + private Map regulatingEquipments = new HashMap<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/LoadAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/LoadAttributes.java index b8e52412c..967f13393 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/LoadAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/LoadAttributes.java @@ -11,6 +11,9 @@ import lombok.*; import lombok.experimental.SuperBuilder; +import java.util.HashMap; +import java.util.Map; + /** * @author Geoffroy Jamgotchian */ @@ -56,4 +59,8 @@ public class LoadAttributes extends AbstractIdentifiableAttributes implements In @Schema(description = "Connectable position (for substation diagram)") private ConnectablePositionAttributes position; + + @Builder.Default + @Schema(description = "regulatingEquipments") + private Map regulatingEquipments = new HashMap<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/RegulationPointAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/RegulationPointAttributes.java index 1f1412f90..436f16a2a 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/RegulationPointAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/RegulationPointAttributes.java @@ -37,6 +37,6 @@ public class RegulationPointAttributes extends AbstractAttributes implements Att @Schema(description = "Regulation mode ordinal") private String regulationMode; - @Schema(description = "Resource type") + @Schema(description = "Regulated equipment resource type") private ResourceType regulatingResourceType; } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/ShuntCompensatorAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/ShuntCompensatorAttributes.java index 552c382fa..79f08e185 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/ShuntCompensatorAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/ShuntCompensatorAttributes.java @@ -10,6 +10,9 @@ import lombok.*; import lombok.experimental.SuperBuilder; +import java.util.HashMap; +import java.util.Map; + /** * @author Geoffroy Jamgotchian */ @@ -58,4 +61,8 @@ public class ShuntCompensatorAttributes extends AbstractIdentifiableAttributes i @Schema(description = "targetDeadband") private double targetDeadband; + + @Builder.Default + @Schema(description = "regulatingEquipments") + private Map regulatingEquipments = new HashMap<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/StaticVarCompensatorAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/StaticVarCompensatorAttributes.java index d6f917295..53cd653d7 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/StaticVarCompensatorAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/StaticVarCompensatorAttributes.java @@ -10,6 +10,9 @@ import lombok.*; import lombok.experimental.SuperBuilder; +import java.util.HashMap; +import java.util.Map; + /** * @author Geoffroy Jamgotchian */ @@ -61,4 +64,8 @@ public class StaticVarCompensatorAttributes extends AbstractIdentifiableAttribut @Schema(description = "Standby automaton") private StandbyAutomatonAttributes standbyAutomaton; + + @Builder.Default + @Schema(description = "regulatingEquipments") + private Map regulatingEquipments = new HashMap<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/VscConverterStationAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/VscConverterStationAttributes.java index 5e5b7cc98..f599709b6 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/VscConverterStationAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/VscConverterStationAttributes.java @@ -10,6 +10,9 @@ import lombok.*; import lombok.experimental.SuperBuilder; +import java.util.HashMap; +import java.util.Map; + /** * @author Geoffroy Jamgotchian */ @@ -59,4 +62,8 @@ public class VscConverterStationAttributes extends AbstractIdentifiableAttribute @Schema(description = "Connectable position (for substation diagram)") private ConnectablePositionAttributes position; + + @Builder.Default + @Schema(description = "regulatingEquipments") + private Map regulatingEquipments = new HashMap<>(); } diff --git a/network-store-model/src/test/java/com/powsybl/network/store/model/TopLevelDocumentTest.java b/network-store-model/src/test/java/com/powsybl/network/store/model/TopLevelDocumentTest.java index 674b06d4f..9a42957ad 100644 --- a/network-store-model/src/test/java/com/powsybl/network/store/model/TopLevelDocumentTest.java +++ b/network-store-model/src/test/java/com/powsybl/network/store/model/TopLevelDocumentTest.java @@ -15,8 +15,10 @@ import org.junit.Test; import java.io.IOException; -import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import static com.powsybl.network.store.model.ResourceType.GENERATOR; import static org.junit.Assert.assertEquals; /** @@ -92,8 +94,11 @@ public void testMeta() throws IOException { public void testGenerator() throws IOException { TerminalRefAttributes regulatedTerminalAttributes = TerminalRefAttributes.builder().side("ONE").connectableId("idEq").build(); - RegulationPointAttributes regulationPointAttributes = new RegulationPointAttributes("gen1", ResourceType.GENERATOR, - new TerminalRefAttributes("gen1", null), regulatedTerminalAttributes, null, ResourceType.GENERATOR); + RegulationPointAttributes regulationPointAttributes = new RegulationPointAttributes("gen1", GENERATOR, + new TerminalRefAttributes("gen1", null), regulatedTerminalAttributes, null, GENERATOR); + Map regEquipments = new HashMap<>(); + regEquipments.put("gen1", GENERATOR); + regEquipments.put("gen2", GENERATOR); GeneratorAttributes generatorAttributes = GeneratorAttributes .builder() .voltageLevelId("vl1") @@ -107,7 +112,7 @@ public void testGenerator() throws IOException { .targetP(3) .targetV(4) .regulationPoint(regulationPointAttributes) - .regulatingEquipments(Arrays.asList("gen1", "gen2")) + .regulatingEquipments(regEquipments) .build(); Resource resourceGenerator = Resource.generatorBuilder() @@ -118,7 +123,7 @@ public void testGenerator() throws IOException { TopLevelDocument document = TopLevelDocument.of(resourceGenerator); ObjectMapper objectMapper = JsonUtil.createObjectMapper(); String json = objectMapper.writeValueAsString(document); - String jsonRef = "{\"data\":[{\"type\":\"GENERATOR\",\"id\":\"gen1\",\"variantNum\":0,\"attributes\":{\"name\":\"name\",\"fictitious\":false,\"extensionAttributes\":{},\"regulationPoint\":{\"regulatedEquipmentId\":\"gen1\",\"resourceType\":\"GENERATOR\",\"localTerminal\":{\"connectableId\":\"gen1\"},\"regulatingTerminal\":{\"connectableId\":\"idEq\",\"side\":\"ONE\"},\"regulationMode\":null,\"regulatingResourceType\":\"GENERATOR\"},\"regulatingEquipments\":[\"gen1\",\"gen2\"],\"voltageLevelId\":\"vl1\",\"node\":1,\"bus\":\"bus1\",\"energySource\":\"HYDRO\",\"minP\":2.0,\"maxP\":1.0,\"voltageRegulatorOn\":false,\"targetP\":3.0,\"targetQ\":0.0,\"targetV\":4.0,\"ratedS\":0.0,\"p\":NaN,\"q\":NaN,\"condenser\":false}}],\"meta\":{}}"; + String jsonRef = "{\"data\":[{\"type\":\"GENERATOR\",\"id\":\"gen1\",\"variantNum\":0,\"attributes\":{\"name\":\"name\",\"fictitious\":false,\"extensionAttributes\":{},\"regulationPoint\":{\"regulatedEquipmentId\":\"gen1\",\"resourceType\":\"GENERATOR\",\"localTerminal\":{\"connectableId\":\"gen1\"},\"regulatingTerminal\":{\"connectableId\":\"idEq\",\"side\":\"ONE\"},\"regulationMode\":null,\"regulatingResourceType\":\"GENERATOR\"},\"voltageLevelId\":\"vl1\",\"node\":1,\"bus\":\"bus1\",\"energySource\":\"HYDRO\",\"minP\":2.0,\"maxP\":1.0,\"voltageRegulatorOn\":false,\"targetP\":3.0,\"targetQ\":0.0,\"targetV\":4.0,\"ratedS\":0.0,\"p\":NaN,\"q\":NaN,\"condenser\":false,\"regulatingEquipments\":{\"gen1\":\"GENERATOR\",\"gen2\":\"GENERATOR\"}}}],\"meta\":{}}"; assertEquals(jsonRef, json); TopLevelDocument document2 = objectMapper.readValue(json, TopLevelDocument.class); assertEquals(resourceGenerator, document2.getData().get(0));