From 1abce8b73f6683356d46313f47ef16efc5d74c0f Mon Sep 17 00:00:00 2001 From: YenguiSeddik <101111441+YenguiSeddik@users.noreply.github.com> Date: Fri, 24 Nov 2023 11:16:47 +0100 Subject: [PATCH 1/3] Add equipments to modif by formula (#379) Signed-off-by: Seddik Yengui --- .../dto/formula/ReferenceFieldOrValue.java | 7 + .../dto/formula/equipmentfield/LoadField.java | 35 +++ .../equipmentfield/VoltageLevelField.java | 60 +++++ .../modifications/ByFormulaModification.java | 6 + .../AbstractByFormulaModificationTest.java | 4 +- .../LoadByFormulaModificationTest.java | 104 +++++++++ ...VoltageLevelByFormulaModificationTest.java | 215 ++++++++++++++++++ 7 files changed, 429 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/LoadField.java create mode 100644 src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/VoltageLevelField.java create mode 100644 src/test/java/org/gridsuite/modification/server/modifications/LoadByFormulaModificationTest.java create mode 100644 src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelByFormulaModificationTest.java diff --git a/src/main/java/org/gridsuite/modification/server/dto/formula/ReferenceFieldOrValue.java b/src/main/java/org/gridsuite/modification/server/dto/formula/ReferenceFieldOrValue.java index 2b67b40d1..a7d2ea60e 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/formula/ReferenceFieldOrValue.java +++ b/src/main/java/org/gridsuite/modification/server/dto/formula/ReferenceFieldOrValue.java @@ -11,7 +11,9 @@ import com.powsybl.iidm.network.Generator; import com.powsybl.iidm.network.Identifiable; import com.powsybl.iidm.network.IdentifiableType; +import com.powsybl.iidm.network.Load; import com.powsybl.iidm.network.ShuntCompensator; +import com.powsybl.iidm.network.VoltageLevel; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -20,7 +22,10 @@ import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.formula.equipmentfield.BatteryField; import org.gridsuite.modification.server.dto.formula.equipmentfield.GeneratorField; +import org.gridsuite.modification.server.dto.formula.equipmentfield.LoadField; import org.gridsuite.modification.server.dto.formula.equipmentfield.ShuntCompensatorField; +import org.gridsuite.modification.server.dto.formula.equipmentfield.VoltageLevelField; + /** * @author Seddik Yengui @@ -51,6 +56,8 @@ public Double getRefOrValue(Identifiable identifiable) { case GENERATOR -> GeneratorField.getReferenceValue((Generator) identifiable, equipmentField); case BATTERY -> BatteryField.getReferenceValue((Battery) identifiable, equipmentField); case SHUNT_COMPENSATOR -> ShuntCompensatorField.getReferenceValue((ShuntCompensator) identifiable, equipmentField); + case VOLTAGE_LEVEL -> VoltageLevelField.getReferenceValue((VoltageLevel) identifiable, equipmentField); + case LOAD -> LoadField.getReferenceValue((Load) identifiable, equipmentField); default -> throw new NetworkModificationException(NetworkModificationException.Type.BY_FORMULA_MODIFICATION_ERROR, String.format("Unsupported equipment type : %s", identifiableType.name())); }; diff --git a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/LoadField.java b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/LoadField.java new file mode 100644 index 000000000..2743186a6 --- /dev/null +++ b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/LoadField.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2023, 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 org.gridsuite.modification.server.dto.formula.equipmentfield; + +import com.powsybl.iidm.network.Load; + +/** + * @author Seddik Yengui + */ + +public enum LoadField { + ACTIVE_POWER, + REACTIVE_POWER; + + public static Double getReferenceValue(Load load, String loadField) { + LoadField field = LoadField.valueOf(loadField); + return switch (field) { + case ACTIVE_POWER -> load.getP0(); + case REACTIVE_POWER -> load.getQ0(); + }; + } + + public static void setNewValue(Load load, String loadField, Double newValue) { + LoadField field = LoadField.valueOf(loadField); + switch (field) { + case ACTIVE_POWER -> load.setP0(newValue); + case REACTIVE_POWER -> load.setQ0(newValue); + } + } +} diff --git a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/VoltageLevelField.java b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/VoltageLevelField.java new file mode 100644 index 000000000..a1fc1d644 --- /dev/null +++ b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/VoltageLevelField.java @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2023, 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 org.gridsuite.modification.server.dto.formula.equipmentfield; + +import com.powsybl.iidm.network.VoltageLevel; +import com.powsybl.iidm.network.extensions.IdentifiableShortCircuit; +import com.powsybl.iidm.network.extensions.IdentifiableShortCircuitAdder; + +/** + * @author Seddik Yengui + */ + +public enum VoltageLevelField { + NOMINAL_VOLTAGE, + LOW_VOLTAGE_LIMIT, + HIGH_VOLTAGE_LIMIT, + LOW_SHORT_CIRCUIT_CURRENT_LIMIT, + HIGH_SHORT_CIRCUIT_CURRENT_LIMIT; + + public static Double getReferenceValue(VoltageLevel voltageLevel, String voltageLevelField) { + IdentifiableShortCircuit identifiableShortCircuit = voltageLevel.getExtension(IdentifiableShortCircuit.class); + VoltageLevelField field = VoltageLevelField.valueOf(voltageLevelField); + return switch (field) { + case NOMINAL_VOLTAGE -> voltageLevel.getNominalV(); + case LOW_VOLTAGE_LIMIT -> voltageLevel.getLowVoltageLimit(); + case HIGH_VOLTAGE_LIMIT -> voltageLevel.getHighVoltageLimit(); + case LOW_SHORT_CIRCUIT_CURRENT_LIMIT -> identifiableShortCircuit == null ? null : identifiableShortCircuit.getIpMin(); + case HIGH_SHORT_CIRCUIT_CURRENT_LIMIT -> identifiableShortCircuit == null ? null : identifiableShortCircuit.getIpMax(); + }; + } + + public static void setNewValue(VoltageLevel voltageLevel, String voltageLevelField, Double newValue) { + IdentifiableShortCircuit identifiableShortCircuit = voltageLevel.getExtension(IdentifiableShortCircuit.class); + VoltageLevelField field = VoltageLevelField.valueOf(voltageLevelField); + switch (field) { + case NOMINAL_VOLTAGE -> voltageLevel.setNominalV(newValue); + case LOW_VOLTAGE_LIMIT -> voltageLevel.setLowVoltageLimit(newValue); + case HIGH_VOLTAGE_LIMIT -> voltageLevel.setHighVoltageLimit(newValue); + case LOW_SHORT_CIRCUIT_CURRENT_LIMIT -> { + IdentifiableShortCircuitAdder adder = voltageLevel.newExtension(IdentifiableShortCircuitAdder.class).withIpMin(newValue); + if (identifiableShortCircuit != null) { + adder.withIpMax(identifiableShortCircuit.getIpMax()); + } + adder.add(); + } + case HIGH_SHORT_CIRCUIT_CURRENT_LIMIT -> { + IdentifiableShortCircuitAdder adder = voltageLevel.newExtension(IdentifiableShortCircuitAdder.class).withIpMax(newValue); + if (identifiableShortCircuit != null) { + adder.withIpMin(identifiableShortCircuit.getIpMin()); + } + adder.add(); + } + } + } +} diff --git a/src/main/java/org/gridsuite/modification/server/modifications/ByFormulaModification.java b/src/main/java/org/gridsuite/modification/server/modifications/ByFormulaModification.java index 94bbde685..6e8a62a61 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ByFormulaModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ByFormulaModification.java @@ -13,8 +13,10 @@ import com.powsybl.iidm.network.Battery; import com.powsybl.iidm.network.Generator; import com.powsybl.iidm.network.Identifiable; +import com.powsybl.iidm.network.Load; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.ShuntCompensator; +import com.powsybl.iidm.network.VoltageLevel; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.ByFormulaModificationInfos; import org.gridsuite.modification.server.dto.FilterEquipments; @@ -23,7 +25,9 @@ import org.gridsuite.modification.server.dto.formula.Operator; import org.gridsuite.modification.server.dto.formula.equipmentfield.BatteryField; import org.gridsuite.modification.server.dto.formula.equipmentfield.GeneratorField; +import org.gridsuite.modification.server.dto.formula.equipmentfield.LoadField; import org.gridsuite.modification.server.dto.formula.equipmentfield.ShuntCompensatorField; +import org.gridsuite.modification.server.dto.formula.equipmentfield.VoltageLevelField; import org.gridsuite.modification.server.service.FilterService; import org.jetbrains.annotations.Nullable; import org.springframework.util.CollectionUtils; @@ -155,6 +159,8 @@ private void applyFormula(Network network, case GENERATOR -> GeneratorField.setNewValue((Generator) identifiable, formulaInfos.getEditedField(), newValue); case BATTERY -> BatteryField.setNewValue((Battery) identifiable, formulaInfos.getEditedField(), newValue); case SHUNT_COMPENSATOR -> ShuntCompensatorField.setNewValue((ShuntCompensator) identifiable, formulaInfos.getEditedField(), newValue); + case VOLTAGE_LEVEL -> VoltageLevelField.setNewValue((VoltageLevel) identifiable, formulaInfos.getEditedField(), newValue); + case LOAD -> LoadField.setNewValue((Load) identifiable, formulaInfos.getEditedField(), newValue); default -> throw new NetworkModificationException(NetworkModificationException.Type.BY_FORMULA_MODIFICATION_ERROR, "Unsupported equipment"); } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/AbstractByFormulaModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/AbstractByFormulaModificationTest.java index 5bb167667..81c010149 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/AbstractByFormulaModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/AbstractByFormulaModificationTest.java @@ -110,7 +110,7 @@ protected void checkCreateWithError(List formulaInfos) throws Exce @Override public void testCreate() throws Exception { List filters = getTestFilters(); - UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath(getNetworkUuid(), true) + "(.+,){4}.*")) + UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath(getNetworkUuid(), true) + ".{2,}")) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(filters)) .withHeader("Content-Type", "application/json"))).getId(); @@ -125,7 +125,7 @@ public void testCreate() throws Exception { public void testCopy() throws Exception { List filters = getTestFilters(); - UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath(getNetworkUuid(), true) + "(.+,){4}.*")) + UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath(getNetworkUuid(), true) + ".{2,}")) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(filters)) .withHeader("Content-Type", "application/json"))).getId(); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LoadByFormulaModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LoadByFormulaModificationTest.java new file mode 100644 index 000000000..1ee9a4170 --- /dev/null +++ b/src/test/java/org/gridsuite/modification/server/modifications/LoadByFormulaModificationTest.java @@ -0,0 +1,104 @@ +/** + * Copyright (c) 2023, 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 org.gridsuite.modification.server.modifications; + +import com.powsybl.iidm.network.IdentifiableType; +import org.gridsuite.modification.server.dto.FilterEquipments; +import org.gridsuite.modification.server.dto.IdentifiableAttributes; +import org.gridsuite.modification.server.dto.formula.FormulaInfos; +import org.gridsuite.modification.server.dto.formula.Operator; +import org.gridsuite.modification.server.dto.formula.ReferenceFieldOrValue; +import org.gridsuite.modification.server.dto.formula.equipmentfield.LoadField; + +import java.util.List; + +import static org.gridsuite.modification.server.utils.NetworkUtil.createLoad; +import static org.junit.Assert.assertEquals; + +/** + * @author Seddik Yengui + */ + +public class LoadByFormulaModificationTest extends AbstractByFormulaModificationTest { + private static final String LOAD_ID_1 = "load1"; + private static final String LOAD_ID_2 = "load2"; + private static final String LOAD_ID_3 = "load3"; + private static final String LOAD_ID_4 = "load4"; + + @Override + protected void createEquipments() { + createLoad(getNetwork().getVoltageLevel("v1"), LOAD_ID_1, "load1", 100, 100, 120, null, 5, null); + createLoad(getNetwork().getVoltageLevel("v2"), LOAD_ID_2, "load2", 200, 80, 90, null, 5, null); + createLoad(getNetwork().getVoltageLevel("v3"), LOAD_ID_3, "load3", 300, 100, 70, null, 5, null); + createLoad(getNetwork().getVoltageLevel("v4"), LOAD_ID_4, "load4", 400, 50, 150, null, 5, null); + } + + @Override + protected List getTestFilters() { + IdentifiableAttributes load1 = getIdentifiableAttributes(LOAD_ID_1, 1.0); + IdentifiableAttributes load2 = getIdentifiableAttributes(LOAD_ID_2, 2.0); + IdentifiableAttributes load3 = getIdentifiableAttributes(LOAD_ID_3, 2.0); + IdentifiableAttributes load4 = getIdentifiableAttributes(LOAD_ID_4, 5.0); + + FilterEquipments filter1 = getFilterEquipments(FILTER_ID_1, "filter1", List.of(load1, load2), List.of()); + FilterEquipments filter2 = getFilterEquipments(FILTER_ID_2, "filter2", List.of(load3, load4), List.of()); + + return List.of(filter1, filter2); + } + + @Override + protected List getFormulaInfos() { + FormulaInfos formulaInfos1 = getFormulaInfo(LoadField.ACTIVE_POWER.name(), + List.of(filter1), + Operator.ADDITION, + ReferenceFieldOrValue.builder().equipmentField(LoadField.ACTIVE_POWER.name()).build(), + ReferenceFieldOrValue.builder().value(25.).build() + ); + + FormulaInfos formulaInfos2 = getFormulaInfo(LoadField.REACTIVE_POWER.name(), + List.of(filter2), + Operator.MULTIPLICATION, + ReferenceFieldOrValue.builder().equipmentField(LoadField.REACTIVE_POWER.name()).build(), + ReferenceFieldOrValue.builder().value(2.5).build() + ); + return List.of(formulaInfos1, formulaInfos2); + } + + @Override + protected List getUpdatedFormulaInfos() { + FormulaInfos formulaInfos1 = getFormulaInfo(LoadField.ACTIVE_POWER.name(), + List.of(filter1), + Operator.PERCENTAGE, + ReferenceFieldOrValue.builder().value(200.).build(), + ReferenceFieldOrValue.builder().equipmentField(LoadField.ACTIVE_POWER.name()).build() + ); + + return List.of(formulaInfos1); + } + + @Override + protected IdentifiableType getIdentifiableType() { + return IdentifiableType.LOAD; + } + + @Override + protected void assertAfterNetworkModificationCreation() { + assertEquals(125, getNetwork().getLoad(LOAD_ID_1).getP0(), 0); + assertEquals(105, getNetwork().getLoad(LOAD_ID_2).getP0(), 0); + assertEquals(175, getNetwork().getLoad(LOAD_ID_3).getQ0(), 0); + assertEquals(375, getNetwork().getLoad(LOAD_ID_4).getQ0(), 0); + } + + @Override + protected void assertAfterNetworkModificationDeletion() { + assertEquals(100, getNetwork().getLoad(LOAD_ID_1).getP0(), 0); + assertEquals(80, getNetwork().getLoad(LOAD_ID_2).getP0(), 0); + assertEquals(70, getNetwork().getLoad(LOAD_ID_3).getQ0(), 0); + assertEquals(150, getNetwork().getLoad(LOAD_ID_4).getQ0(), 0); + } +} diff --git a/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelByFormulaModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelByFormulaModificationTest.java new file mode 100644 index 000000000..22ddabe86 --- /dev/null +++ b/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelByFormulaModificationTest.java @@ -0,0 +1,215 @@ +/** + * Copyright (c) 2023, 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 org.gridsuite.modification.server.modifications; + +import com.powsybl.iidm.network.IdentifiableType; +import com.powsybl.iidm.network.VoltageLevel; +import com.powsybl.iidm.network.extensions.IdentifiableShortCircuit; +import com.powsybl.iidm.network.extensions.IdentifiableShortCircuitAdder; +import org.gridsuite.modification.server.dto.FilterEquipments; +import org.gridsuite.modification.server.dto.IdentifiableAttributes; +import org.gridsuite.modification.server.dto.formula.FormulaInfos; +import org.gridsuite.modification.server.dto.formula.Operator; +import org.gridsuite.modification.server.dto.formula.ReferenceFieldOrValue; +import org.gridsuite.modification.server.dto.formula.equipmentfield.VoltageLevelField; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * @author Seddik Yengui + */ + +public class VoltageLevelByFormulaModificationTest extends AbstractByFormulaModificationTest { + private static final String VOLTAGE_LEVEL_ID_1 = "v1"; + private static final String VOLTAGE_LEVEL_ID_2 = "v2"; + private static final String VOLTAGE_LEVEL_ID_3 = "v3"; + private static final String VOLTAGE_LEVEL_ID_4 = "v4"; + private static final String VOLTAGE_LEVEL_ID_5 = "v5"; + private static final String VOLTAGE_LEVEL_ID_6 = "v6"; + + @Override + protected void createEquipments() { + getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_1).setNominalV(400) + .setHighVoltageLimit(200) + .setLowVoltageLimit(100) + .newExtension(IdentifiableShortCircuitAdder.class).withIpMin(10).withIpMax(120).add(); + + getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_2).setNominalV(150) + .setLowVoltageLimit(100) + .setHighVoltageLimit(1000) + .newExtension(IdentifiableShortCircuitAdder.class).withIpMin(10).withIpMax(120).add(); + + getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_3).setNominalV(70) + .setLowVoltageLimit(50) + .setHighVoltageLimit(250) + .newExtension(IdentifiableShortCircuitAdder.class).withIpMin(50).withIpMax(150).add(); + + getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_4).setNominalV(100) + .setLowVoltageLimit(70) + .setHighVoltageLimit(300) + .newExtension(IdentifiableShortCircuitAdder.class).withIpMin(10).withIpMax(100).add(); + + getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_5).setNominalV(210) + .setLowVoltageLimit(10) + .setHighVoltageLimit(500) + .newExtension(IdentifiableShortCircuitAdder.class).withIpMin(25).withIpMax(75).add(); + + getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_6).setNominalV(750) + .setHighVoltageLimit(1000) + .setLowVoltageLimit(90) + .newExtension(IdentifiableShortCircuitAdder.class).withIpMin(100).withIpMax(200).add(); + } + + @Override + protected List getTestFilters() { + IdentifiableAttributes voltageLevel1 = getIdentifiableAttributes(VOLTAGE_LEVEL_ID_1, 1.0); + IdentifiableAttributes voltageLevel2 = getIdentifiableAttributes(VOLTAGE_LEVEL_ID_2, 2.0); + IdentifiableAttributes voltageLevel3 = getIdentifiableAttributes(VOLTAGE_LEVEL_ID_3, 2.0); + IdentifiableAttributes voltageLevel4 = getIdentifiableAttributes(VOLTAGE_LEVEL_ID_4, 5.0); + IdentifiableAttributes voltageLevel5 = getIdentifiableAttributes(VOLTAGE_LEVEL_ID_5, 6.0); + IdentifiableAttributes voltageLevel6 = getIdentifiableAttributes(VOLTAGE_LEVEL_ID_6, 7.0); + + FilterEquipments filter1 = getFilterEquipments(FILTER_ID_1, "filter1", List.of(voltageLevel1, voltageLevel2), List.of()); + FilterEquipments filter2 = getFilterEquipments(FILTER_ID_2, "filter2", List.of(voltageLevel3, voltageLevel4), List.of()); + FilterEquipments filter3 = getFilterEquipments(FILTER_ID_3, "filter3", List.of(voltageLevel5, voltageLevel6), List.of()); + FilterEquipments filter4 = getFilterEquipments(FILTER_ID_4, "filter4", List.of(voltageLevel2, voltageLevel5), List.of()); + FilterEquipments filter5 = getFilterEquipments(FILTER_ID_5, "filter5", List.of(voltageLevel4, voltageLevel6), List.of()); + + return List.of(filter1, filter2, filter3, filter4, filter5); + } + + @Override + protected List getFormulaInfos() { + FormulaInfos formulaInfos1 = getFormulaInfo(VoltageLevelField.LOW_VOLTAGE_LIMIT.name(), + List.of(filter1, filter2), + Operator.ADDITION, + ReferenceFieldOrValue.builder().equipmentField(VoltageLevelField.LOW_VOLTAGE_LIMIT.name()).build(), + ReferenceFieldOrValue.builder().value(10.).build() + ); + + FormulaInfos formulaInfos2 = getFormulaInfo(VoltageLevelField.HIGH_VOLTAGE_LIMIT.name(), + List.of(filter3), + Operator.MULTIPLICATION, + ReferenceFieldOrValue.builder().equipmentField(VoltageLevelField.HIGH_VOLTAGE_LIMIT.name()).build(), + ReferenceFieldOrValue.builder().value(2.).build() + ); + + FormulaInfos formulaInfos3 = getFormulaInfo(VoltageLevelField.NOMINAL_VOLTAGE.name(), + List.of(filter4), + Operator.PERCENTAGE, + ReferenceFieldOrValue.builder().value(150.).build(), + ReferenceFieldOrValue.builder().equipmentField(VoltageLevelField.LOW_VOLTAGE_LIMIT.name()).build() + ); + + FormulaInfos formulaInfos4 = getFormulaInfo(VoltageLevelField.LOW_SHORT_CIRCUIT_CURRENT_LIMIT.name(), + List.of(filter5), + Operator.DIVISION, + ReferenceFieldOrValue.builder().equipmentField(VoltageLevelField.LOW_SHORT_CIRCUIT_CURRENT_LIMIT.name()).build(), + ReferenceFieldOrValue.builder().value(2.).build() + ); + + FormulaInfos formulaInfos5 = getFormulaInfo(VoltageLevelField.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT.name(), + List.of(filter4, filter5), + Operator.SUBTRACTION, + ReferenceFieldOrValue.builder().equipmentField(VoltageLevelField.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT.name()).build(), + ReferenceFieldOrValue.builder().value(5.).build() + ); + + return List.of(formulaInfos1, formulaInfos2, formulaInfos3, formulaInfos4, formulaInfos5); + } + + @Override + protected List getUpdatedFormulaInfos() { + FormulaInfos formulaInfos1 = getFormulaInfo(VoltageLevelField.LOW_VOLTAGE_LIMIT.name(), + List.of(filter1, filter2), + Operator.ADDITION, + ReferenceFieldOrValue.builder().equipmentField(VoltageLevelField.LOW_VOLTAGE_LIMIT.name()).build(), + ReferenceFieldOrValue.builder().value(5.).build() + ); + + FormulaInfos formulaInfos2 = getFormulaInfo(VoltageLevelField.HIGH_VOLTAGE_LIMIT.name(), + List.of(filter3), + Operator.MULTIPLICATION, + ReferenceFieldOrValue.builder().equipmentField(VoltageLevelField.HIGH_VOLTAGE_LIMIT.name()).build(), + ReferenceFieldOrValue.builder().value(1.5).build() + ); + + FormulaInfos formulaInfos3 = getFormulaInfo(VoltageLevelField.NOMINAL_VOLTAGE.name(), + List.of(filter4), + Operator.PERCENTAGE, + ReferenceFieldOrValue.builder().value(150.).build(), + ReferenceFieldOrValue.builder().equipmentField(VoltageLevelField.LOW_VOLTAGE_LIMIT.name()).build() + ); + + return List.of(formulaInfos1, formulaInfos2, formulaInfos3); + } + + @Override + protected IdentifiableType getIdentifiableType() { + return IdentifiableType.VOLTAGE_LEVEL; + } + + @Override + protected void assertAfterNetworkModificationCreation() { + assertEquals(110, getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_1).getLowVoltageLimit(), 0); + assertEquals(110, getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_2).getLowVoltageLimit(), 0); + assertEquals(60, getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_3).getLowVoltageLimit(), 0); + + VoltageLevel voltageLevel4 = getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_4); + IdentifiableShortCircuit identifiableShortCircuit4 = voltageLevel4.getExtension(IdentifiableShortCircuit.class); + assertNotNull(identifiableShortCircuit4); + assertEquals(80, voltageLevel4.getLowVoltageLimit(), 0); + assertEquals(5, identifiableShortCircuit4.getIpMin(), 0); + assertEquals(95, identifiableShortCircuit4.getIpMax(), 0); + + VoltageLevel voltageLevel5 = getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_5); + IdentifiableShortCircuit identifiableShortCircuit5 = voltageLevel5.getExtension(IdentifiableShortCircuit.class); + assertNotNull(identifiableShortCircuit5); + assertEquals(1000, voltageLevel5.getHighVoltageLimit(), 0); + assertEquals(15, voltageLevel5.getNominalV(), 0); + assertEquals(70, identifiableShortCircuit5.getIpMax(), 0); + + VoltageLevel voltageLevel6 = getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_6); + IdentifiableShortCircuit identifiableShortCircuit6 = voltageLevel6.getExtension(IdentifiableShortCircuit.class); + assertNotNull(identifiableShortCircuit6); + assertEquals(2000, voltageLevel6.getHighVoltageLimit(), 0); + assertEquals(50, identifiableShortCircuit6.getIpMin(), 0); + assertEquals(195, identifiableShortCircuit6.getIpMax(), 0); + } + + @Override + protected void assertAfterNetworkModificationDeletion() { + assertEquals(100, getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_1).getLowVoltageLimit(), 0); + assertEquals(100, getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_2).getLowVoltageLimit(), 0); + assertEquals(250, getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_3).getHighVoltageLimit(), 0); + + VoltageLevel voltageLevel4 = getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_4); + IdentifiableShortCircuit identifiableShortCircuit4 = voltageLevel4.getExtension(IdentifiableShortCircuit.class); + assertNotNull(identifiableShortCircuit4); + assertEquals(300, voltageLevel4.getHighVoltageLimit(), 0); + assertEquals(10, identifiableShortCircuit4.getIpMin(), 0); + assertEquals(100, identifiableShortCircuit4.getIpMax(), 0); + + VoltageLevel voltageLevel5 = getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_5); + IdentifiableShortCircuit identifiableShortCircuit5 = voltageLevel5.getExtension(IdentifiableShortCircuit.class); + assertNotNull(identifiableShortCircuit5); + assertEquals(500, voltageLevel5.getHighVoltageLimit(), 0); + assertEquals(210, voltageLevel5.getNominalV(), 0); + assertEquals(75, identifiableShortCircuit5.getIpMax(), 0); + + VoltageLevel voltageLevel6 = getNetwork().getVoltageLevel(VOLTAGE_LEVEL_ID_6); + IdentifiableShortCircuit identifiableShortCircuit6 = voltageLevel6.getExtension(IdentifiableShortCircuit.class); + assertNotNull(identifiableShortCircuit6); + assertEquals(1000, voltageLevel6.getHighVoltageLimit(), 0); + assertEquals(100, identifiableShortCircuit6.getIpMin(), 0); + assertEquals(200, identifiableShortCircuit6.getIpMax(), 0); + } +} From b19f5d2fa6815f1484cf45b1291809d41fdc271c Mon Sep 17 00:00:00 2001 From: Slimane Amar <63394973+SlimaneAmar@users.noreply.github.com> Date: Fri, 24 Nov 2023 13:01:20 +0100 Subject: [PATCH 2/3] Remove the id automatically generated to have a unique index for ELS (#382) Signed-off-by: Slimane AMAR --- .../elasticsearch/BasicEquipmentInfos.java | 12 +++++++++- .../elasticsearch/EquipmentInfosService.java | 2 -- .../service/EquipmentInfosServiceTests.java | 22 +++++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gridsuite/modification/server/dto/elasticsearch/BasicEquipmentInfos.java b/src/main/java/org/gridsuite/modification/server/dto/elasticsearch/BasicEquipmentInfos.java index e1d46a85f..f2a289a5c 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/elasticsearch/BasicEquipmentInfos.java +++ b/src/main/java/org/gridsuite/modification/server/dto/elasticsearch/BasicEquipmentInfos.java @@ -8,6 +8,7 @@ import lombok.*; import lombok.experimental.SuperBuilder; +import org.springframework.data.annotation.AccessType; import org.springframework.data.annotation.Id; import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.FieldType; @@ -27,7 +28,16 @@ @EqualsAndHashCode public class BasicEquipmentInfos { @Id - private String uniqueId; + @AccessType(AccessType.Type.PROPERTY) + @SuppressWarnings("unused") + public String getUniqueId() { + return networkUuid + "_" + variantId + "_" + id; + } + + @SuppressWarnings("unused") + public void setUniqueId(String uniqueId) { + // No setter because it a composite value + } @MultiField( mainField = @Field(name = "equipmentId", type = FieldType.Text), diff --git a/src/main/java/org/gridsuite/modification/server/elasticsearch/EquipmentInfosService.java b/src/main/java/org/gridsuite/modification/server/elasticsearch/EquipmentInfosService.java index 8809e4df7..d883a74dc 100644 --- a/src/main/java/org/gridsuite/modification/server/elasticsearch/EquipmentInfosService.java +++ b/src/main/java/org/gridsuite/modification/server/elasticsearch/EquipmentInfosService.java @@ -65,7 +65,6 @@ public void cloneVariantModifications(@NonNull UUID networkUuid, @NonNull String addAllEquipmentInfos( equipmentInfosRepository.findAllByNetworkUuidAndVariantId(networkUuid, variantToCloneId).stream() .map(equipmentInfos -> { - equipmentInfos.setUniqueId(null); equipmentInfos.setVariantId(variantId); return equipmentInfos; }) @@ -74,7 +73,6 @@ public void cloneVariantModifications(@NonNull UUID networkUuid, @NonNull String addAllTombstonedEquipmentInfos( tombstonedEquipmentInfosRepository.findAllByNetworkUuidAndVariantId(networkUuid, variantToCloneId).stream() .map(tombstonedEquipmentInfos -> { - tombstonedEquipmentInfos.setUniqueId(null); tombstonedEquipmentInfos.setVariantId(variantId); return tombstonedEquipmentInfos; }) diff --git a/src/test/java/org/gridsuite/modification/server/service/EquipmentInfosServiceTests.java b/src/test/java/org/gridsuite/modification/server/service/EquipmentInfosServiceTests.java index 1d180073c..9ea8e4e7e 100644 --- a/src/test/java/org/gridsuite/modification/server/service/EquipmentInfosServiceTests.java +++ b/src/test/java/org/gridsuite/modification/server/service/EquipmentInfosServiceTests.java @@ -74,8 +74,26 @@ public void testAddDeleteEquipmentInfos() { .substations(Set.of(SubstationInfos.builder().id("s1").name("s1").build())) .build(); equipmentInfosService.addAllEquipmentInfos(List.of(equipmentInfos)); - assertNotNull(equipmentInfosRepository.findAllByNetworkUuidAndVariantId(NETWORK_UUID, VARIANT_NAME_1).get(0)); - assertEquals(equipmentInfos, equipmentInfosRepository.findAllByNetworkUuidAndVariantId(NETWORK_UUID, VARIANT_NAME_1).get(0)); + List infosDB = equipmentInfosRepository.findAllByNetworkUuidAndVariantId(NETWORK_UUID, VARIANT_NAME_1); + assertEquals(1, infosDB.size()); + assertEquals(equipmentInfos, infosDB.get(0)); + assertEquals(equipmentInfos.getNetworkUuid() + "_" + equipmentInfos.getVariantId() + "_" + equipmentInfos.getId(), infosDB.get(0).getUniqueId()); + + // Change name but uniqueIds are same + equipmentInfos = EquipmentInfos.builder() + .networkUuid(NETWORK_UUID) + .id("id1") + .variantId(VARIANT_NAME_1) + .name("newName") + .type(IdentifiableType.LOAD.name()) + .voltageLevels(Set.of(VoltageLevelInfos.builder().id("vl1").name("vl1").build())) + .substations(Set.of(SubstationInfos.builder().id("s1").name("s1").build())) + .build(); + equipmentInfosService.addAllEquipmentInfos(List.of(equipmentInfos)); + infosDB = equipmentInfosRepository.findAllByNetworkUuidAndVariantId(NETWORK_UUID, VARIANT_NAME_1); + assertEquals(1, infosDB.size()); + assertEquals(equipmentInfos, infosDB.get(0)); + assertEquals(equipmentInfos.getNetworkUuid() + "_" + equipmentInfos.getVariantId() + "_" + equipmentInfos.getId(), infosDB.get(0).getUniqueId()); equipmentInfosRepository.deleteByIdInAndNetworkUuidAndVariantId(List.of(equipmentInfos.getId()), NETWORK_UUID, VARIANT_NAME_1); assertEquals(0, equipmentInfosRepository.findAllByNetworkUuidAndVariantId(NETWORK_UUID, VARIANT_NAME_1).size()); From 0777d9c6a92d28bd5aadb16c7c302ff4222a8b56 Mon Sep 17 00:00:00 2001 From: dbraquart <107846716+dbraquart@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:43:25 +0100 Subject: [PATCH 3/3] fix issue about subreporter uniqueness (#384) Signed-off-by: David BRAQUART --- .../gridsuite/modification/server/dto/LineCreationInfos.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gridsuite/modification/server/dto/LineCreationInfos.java b/src/main/java/org/gridsuite/modification/server/dto/LineCreationInfos.java index 28307c5cb..704495c99 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/LineCreationInfos.java +++ b/src/main/java/org/gridsuite/modification/server/dto/LineCreationInfos.java @@ -58,6 +58,6 @@ public AbstractModification toModification() { @Override public Reporter createSubReporter(ReporterModel reporter) { - return reporter.createSubReporter(getType().name(), "Creation of line " + getEquipmentId()); + return reporter.createSubReporter(getType().name(), "Creation of line ${lineId}", "lineId", getEquipmentId()); } }