diff --git a/src/main/java/org/gridsuite/modification/dto/LineAttachToVoltageLevelInfos.java b/src/main/java/org/gridsuite/modification/dto/LineAttachToVoltageLevelInfos.java index cd3a5f8e..99b03ff2 100644 --- a/src/main/java/org/gridsuite/modification/dto/LineAttachToVoltageLevelInfos.java +++ b/src/main/java/org/gridsuite/modification/dto/LineAttachToVoltageLevelInfos.java @@ -42,6 +42,9 @@ public class LineAttachToVoltageLevelInfos extends ModificationInfos { @Schema(description = "attachment point name") private String attachmentPointName; + @Schema(description = "details about attachment point, may be null") + private VoltageLevelCreationInfos attachmentPointDetailInformation; + @Schema(description = "possible new voltage level to create before inserting it, may be null") private VoltageLevelCreationInfos mayNewVoltageLevelInfos; diff --git a/src/main/java/org/gridsuite/modification/modifications/LineAttachToVoltageLevel.java b/src/main/java/org/gridsuite/modification/modifications/LineAttachToVoltageLevel.java index 0a6ef16d..c8277b5e 100644 --- a/src/main/java/org/gridsuite/modification/modifications/LineAttachToVoltageLevel.java +++ b/src/main/java/org/gridsuite/modification/modifications/LineAttachToVoltageLevel.java @@ -10,11 +10,15 @@ import com.powsybl.iidm.modification.topology.CreateLineOnLine; import com.powsybl.iidm.modification.topology.CreateLineOnLineBuilder; import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.extensions.IdentifiableShortCircuitAdder; +import groovyjarjarantlr4.v4.runtime.misc.NotNull; import org.gridsuite.modification.NetworkModificationException; import org.gridsuite.modification.dto.LineAttachToVoltageLevelInfos; import org.gridsuite.modification.dto.LineCreationInfos; +import org.gridsuite.modification.dto.SubstationCreationInfos; import org.gridsuite.modification.dto.VoltageLevelCreationInfos; import org.gridsuite.modification.utils.ModificationUtils; +import org.gridsuite.modification.utils.PropertiesUtils; import static org.gridsuite.modification.NetworkModificationException.Type.*; @@ -58,6 +62,9 @@ public void apply(Network network, ReportNode subReportNode) { VoltageLevelCreationInfos mayNewVL = modificationInfos.getMayNewVoltageLevelInfos(); if (mayNewVL != null) { ModificationUtils.getInstance().createVoltageLevel(mayNewVL, subReportNode, network); + // properties + VoltageLevel voltageLevel = network.getVoltageLevel(mayNewVL.getEquipmentId()); + PropertiesUtils.applyProperties(voltageLevel, null, mayNewVL.getProperties(), null); } LineCreationInfos attachmentLineInfos = modificationInfos.getAttachmentLine(); @@ -70,14 +77,16 @@ public void apply(Network network, ReportNode subReportNode) { .setB1(ModificationUtils.getInstance().zeroIfNull(attachmentLineInfos.getB1())) .setG2(ModificationUtils.getInstance().zeroIfNull(attachmentLineInfos.getG2())) .setB2(ModificationUtils.getInstance().zeroIfNull(attachmentLineInfos.getB2())); - + String newSubstationId = modificationInfos.getAttachmentPointDetailInformation() != null ? + modificationInfos.getAttachmentPointDetailInformation().getSubstationCreation().getEquipmentId() : + modificationInfos.getAttachmentPointId() + "_substation"; CreateLineOnLine algo = new CreateLineOnLineBuilder() .withPositionPercent(modificationInfos.getPercent()) .withBusbarSectionOrBusId(modificationInfos.getBbsOrBusId()) .withFictitiousVoltageLevelId(modificationInfos.getAttachmentPointId()) .withFictitiousVoltageLevelName(modificationInfos.getAttachmentPointName()) .withCreateFictitiousSubstation(true) - .withFictitiousSubstationId(modificationInfos.getAttachmentPointId() + "_substation") + .withFictitiousSubstationId(newSubstationId) .withLine1Id(modificationInfos.getNewLine1Id()) .withLine1Name(modificationInfos.getNewLine1Name()) .withLine2Id(modificationInfos.getNewLine2Id()) @@ -87,6 +96,46 @@ public void apply(Network network, ReportNode subReportNode) { .build(); algo.apply(network, true, subReportNode); + // override attachment point + if (modificationInfos.getAttachmentPointDetailInformation() != null) { + // override voltage level + updateAttachmentVoltageLevel(network, modificationInfos.getAttachmentPointDetailInformation()); + } + } + + private void updateAttachmentVoltageLevel(Network network, @NotNull VoltageLevelCreationInfos attachmentPointDetailInformation) { + VoltageLevel voltageLevel = network.getVoltageLevel(modificationInfos.getAttachmentPointId()); + if (attachmentPointDetailInformation.getHighVoltageLimit() != null) { + voltageLevel.setHighVoltageLimit(attachmentPointDetailInformation.getHighVoltageLimit()); + } + if (attachmentPointDetailInformation.getLowVoltageLimit() != null) { + voltageLevel.setLowVoltageLimit(attachmentPointDetailInformation.getLowVoltageLimit()); + } + if (attachmentPointDetailInformation.getIpMax() != null || attachmentPointDetailInformation.getIpMin() != null) { + IdentifiableShortCircuitAdder adder = voltageLevel.newExtension(IdentifiableShortCircuitAdder.class); + if (attachmentPointDetailInformation.getIpMax() != null) { + adder.withIpMax(attachmentPointDetailInformation.getIpMax()); + } + if (attachmentPointDetailInformation.getIpMin() != null) { + adder.withIpMin(attachmentPointDetailInformation.getIpMin()); + } + adder.add(); + } + PropertiesUtils.applyProperties(voltageLevel, attachmentPointDetailInformation.getProperties()); + // override substation + SubstationCreationInfos substationCreationInfos = attachmentPointDetailInformation.getSubstationCreation(); + updateAttachmentSubstation(network, substationCreationInfos); + } + + private void updateAttachmentSubstation(Network network, @NotNull SubstationCreationInfos substationCreationInfos) { + final Substation substation = network.getSubstation(substationCreationInfos.getEquipmentId()); + if (substationCreationInfos.getEquipmentName() != null) { + substation.setName(substationCreationInfos.getEquipmentName()); + } + if (substationCreationInfos.getCountry() != null) { + substation.setCountry(substationCreationInfos.getCountry()); + } + PropertiesUtils.applyProperties(substation, substationCreationInfos.getProperties()); } @Override diff --git a/src/main/java/org/gridsuite/modification/utils/PropertiesUtils.java b/src/main/java/org/gridsuite/modification/utils/PropertiesUtils.java index 497b1416..1ec78138 100644 --- a/src/main/java/org/gridsuite/modification/utils/PropertiesUtils.java +++ b/src/main/java/org/gridsuite/modification/utils/PropertiesUtils.java @@ -21,6 +21,10 @@ private PropertiesUtils() { // Should not be instantiated } + public static void applyProperties(Identifiable identifiable, @Nullable List properties) { + applyProperties(identifiable, null, properties, null); + } + public static void applyProperties(Identifiable identifiable, ReportNode subReportNode, @Nullable List properties, String propertiesLabelKey) { List reportNodes = new ArrayList<>(); Optional.ofNullable(properties).ifPresent(props -> @@ -29,7 +33,7 @@ public static void applyProperties(Identifiable identifiable, ReportNode subR .ifPresent(reportNodes::add) ) ); - if (!reportNodes.isEmpty()) { + if (subReportNode != null && !reportNodes.isEmpty()) { ModificationUtils.getInstance().reportModifications(subReportNode, reportNodes, propertiesLabelKey); } } diff --git a/src/test/java/org/gridsuite/modification/modifications/LineAttachToNewVoltageLevelTest.java b/src/test/java/org/gridsuite/modification/modifications/LineAttachToNewVoltageLevelTest.java index b4087dfe..dbb07c3a 100644 --- a/src/test/java/org/gridsuite/modification/modifications/LineAttachToNewVoltageLevelTest.java +++ b/src/test/java/org/gridsuite/modification/modifications/LineAttachToNewVoltageLevelTest.java @@ -7,14 +7,12 @@ package org.gridsuite.modification.modifications; import com.fasterxml.jackson.core.type.TypeReference; -import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.SwitchKind; +import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.extensions.IdentifiableShortCircuit; import org.gridsuite.modification.dto.*; import org.gridsuite.modification.utils.NetworkCreation; -import java.util.Arrays; -import java.util.Map; -import java.util.UUID; +import java.util.*; import static org.junit.jupiter.api.Assertions.*; @@ -32,6 +30,35 @@ private static LineCreationInfos getAttachmentLine() { .build(); } + private static VoltageLevelCreationInfos getAttachmentPoint() { + return VoltageLevelCreationInfos.builder() + .equipmentId("AttPointId") + .stashed(false) + .nominalV(0) + .substationCreation(SubstationCreationInfos.builder().stashed(false) + .equipmentId("attachmentPointSubstation") + .equipmentName("attachmentPointSubstationName") + .country(Country.FR) + .properties(List.of(FreePropertyInfos.builder() + .added(true) + .name("substationProp") + .value("valueSubstation") + .build())) + .build()) + .lowVoltageLimit(50.0) + .highVoltageLimit(100.0) + .ipMin(5.0) + .ipMax(20.0) + .busbarCount(1) + .sectionCount(1) + .properties(List.of(FreePropertyInfos.builder() + .added(true) + .name("voltageLevelProp") + .value("valueVoltageLevel") + .build())) + .build(); + } + private static VoltageLevelCreationInfos getNewVoltageLevel() { return VoltageLevelCreationInfos.builder() .stashed(false) @@ -45,8 +72,13 @@ private static VoltageLevelCreationInfos getNewVoltageLevel() { .ipMax(10.0) .busbarCount(2) .sectionCount(2) - .switchKinds(Arrays.asList(SwitchKind.BREAKER)) - .couplingDevices(Arrays.asList(CouplingDeviceInfos.builder().busbarSectionId1("1A").busbarSectionId2("1B").build())) + .switchKinds(List.of(SwitchKind.BREAKER)) + .couplingDevices(Collections.singletonList(CouplingDeviceInfos.builder().busbarSectionId1("1A").busbarSectionId2("1B").build())) + .properties(List.of(FreePropertyInfos.builder() + .added(true) + .name("newVoltageLevelProp") + .value("newVoltageLevelValue") + .build())) .build(); } @@ -63,6 +95,7 @@ protected ModificationInfos buildModification() { .percent(20.0) .attachmentPointId("AttPointId") .attachmentPointName("attPointName") + .attachmentPointDetailInformation(getAttachmentPoint()) .mayNewVoltageLevelInfos(getNewVoltageLevel()) // create another new VL .existingVoltageLevelId(null) .bbsOrBusId("1.A") @@ -81,9 +114,37 @@ protected void assertAfterNetworkModificationApplication() { assertNotNull(getNetwork().getLine("nl1")); assertNotNull(getNetwork().getLine("nl2")); assertNotNull(getNetwork().getVoltageLevel("AttPointId")); - assertNotNull(getNetwork().getVoltageLevel("newVoltageLevel")); + + VoltageLevel newVoltageLevel = getNetwork().getVoltageLevel("newVoltageLevel"); + assertNotNull(newVoltageLevel); + assertEquals("newVoltageLevelValue", newVoltageLevel.getProperty("newVoltageLevelProp")); + // replaced line is gone assertNull(getNetwork().getLine("line3")); + + // attachment point substation + Substation attachmentPointSubstation = getNetwork().getSubstation("attachmentPointSubstation"); + assertNotNull(attachmentPointSubstation); + assertTrue(attachmentPointSubstation.getOptionalName().isPresent()); + assertEquals("attachmentPointSubstationName", attachmentPointSubstation.getOptionalName().get()); + assertEquals("valueSubstation", attachmentPointSubstation.getProperty("substationProp")); + assertTrue(attachmentPointSubstation.getCountry().isPresent()); + assertEquals(Country.FR, attachmentPointSubstation.getCountry().get()); + assertTrue(attachmentPointSubstation.isFictitious()); + + // attachment point voltage level + VoltageLevel attachmentPointVoltageLevel = getNetwork().getVoltageLevel("AttPointId"); + assertNotNull(attachmentPointVoltageLevel); + assertEquals("valueVoltageLevel", attachmentPointVoltageLevel.getProperty("voltageLevelProp")); + assertEquals(380.0, attachmentPointVoltageLevel.getNominalV(), 0.001); + assertEquals(50.0, attachmentPointVoltageLevel.getLowVoltageLimit(), 0.001); + assertEquals(100.0, attachmentPointVoltageLevel.getHighVoltageLimit(), 0.001); + assertTrue(attachmentPointVoltageLevel.isFictitious()); + + IdentifiableShortCircuit identifiableShortCircuit = attachmentPointVoltageLevel.getExtension(IdentifiableShortCircuit.class); + assertNotNull(identifiableShortCircuit); + assertEquals(5.0, identifiableShortCircuit.getIpMin(), 0.001); + assertEquals(20.0, identifiableShortCircuit.getIpMax(), 0.001); } @Override diff --git a/src/test/java/org/gridsuite/modification/modifications/LineAttachToVoltageLevelTest.java b/src/test/java/org/gridsuite/modification/modifications/LineAttachToVoltageLevelTest.java index 04be80f2..99da1239 100644 --- a/src/test/java/org/gridsuite/modification/modifications/LineAttachToVoltageLevelTest.java +++ b/src/test/java/org/gridsuite/modification/modifications/LineAttachToVoltageLevelTest.java @@ -13,9 +13,8 @@ import org.gridsuite.modification.dto.*; import org.gridsuite.modification.utils.NetworkCreation; import org.junit.jupiter.api.Test; -import java.util.Arrays; -import java.util.Map; -import java.util.UUID; + +import java.util.*; import static org.gridsuite.modification.NetworkModificationException.Type.*; import static org.junit.jupiter.api.Assertions.*; @@ -47,8 +46,8 @@ private static VoltageLevelCreationInfos getNewVoltageLevel() { .ipMax(10.0) .busbarCount(2) .sectionCount(2) - .switchKinds(Arrays.asList(SwitchKind.BREAKER)) - .couplingDevices(Arrays.asList(CouplingDeviceInfos.builder().busbarSectionId1("bbs.nw").busbarSectionId2("bbs.ne").build())) + .switchKinds(List.of(SwitchKind.BREAKER)) + .couplingDevices(Collections.singletonList(CouplingDeviceInfos.builder().busbarSectionId1("bbs.nw").busbarSectionId2("bbs.ne").build())) .build(); }