From 0aa2200a1679e1f72dadc35a2beb18afc0c9b1cd Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Wed, 4 Dec 2024 15:56:41 +0100 Subject: [PATCH 1/9] move regulating from regulating equipment to regulatingPoint Signed-off-by: Etienne LESOT --- .../network/store/server/Mappings.java | 3 -- .../store/server/NetworkStoreRepository.java | 8 ++++- .../network/store/server/QueryCatalog.java | 17 ++++++----- .../changesets/changelog_20241204T110000Z.xml | 20 +++++++++++++ ...ng_to_regulationPoint_20241204T110000Z.sql | 29 +++++++++++++++++++ .../db/changelog/db.changelog-master.yaml | 4 +++ pom.xml | 20 ++++++++++++- 7 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 network-store-server/src/main/resources/db/changelog/changesets/changelog_20241204T110000Z.xml create mode 100644 network-store-server/src/main/resources/db/changelog/changesets/move_regulating_to_regulationPoint_20241204T110000Z.sql diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java b/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java index fa18d393..5ba26ae6 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java @@ -216,7 +216,6 @@ private void createGeneratorMappings() { generatorMappings.addColumnMapping("p", new ColumnMapping<>(Double.class, GeneratorAttributes::getP, GeneratorAttributes::setP)); generatorMappings.addColumnMapping("q", new ColumnMapping<>(Double.class, GeneratorAttributes::getQ, GeneratorAttributes::setQ)); generatorMappings.addColumnMapping(FICTITIOUS, new ColumnMapping<>(Boolean.class, GeneratorAttributes::isFictitious, GeneratorAttributes::setFictitious)); - generatorMappings.addColumnMapping(VOLTAGE_REGULATOR_ON, new ColumnMapping<>(Boolean.class, GeneratorAttributes::isVoltageRegulatorOn, GeneratorAttributes::setVoltageRegulatorOn)); generatorMappings.addColumnMapping("targetP", new ColumnMapping<>(Double.class, GeneratorAttributes::getTargetP, GeneratorAttributes::setTargetP)); generatorMappings.addColumnMapping("targetQ", new ColumnMapping<>(Double.class, GeneratorAttributes::getTargetQ, GeneratorAttributes::setTargetQ)); generatorMappings.addColumnMapping("targetV", new ColumnMapping<>(Double.class, GeneratorAttributes::getTargetV, GeneratorAttributes::setTargetV)); @@ -483,7 +482,6 @@ private void createShuntCompensatorMappings() { shuntCompensatorMappings.addColumnMapping("p", new ColumnMapping<>(Double.class, ShuntCompensatorAttributes::getP, ShuntCompensatorAttributes::setP)); shuntCompensatorMappings.addColumnMapping("q", new ColumnMapping<>(Double.class, ShuntCompensatorAttributes::getQ, ShuntCompensatorAttributes::setQ)); shuntCompensatorMappings.addColumnMapping(FICTITIOUS, new ColumnMapping<>(Boolean.class, ShuntCompensatorAttributes::isFictitious, ShuntCompensatorAttributes::setFictitious)); - shuntCompensatorMappings.addColumnMapping(VOLTAGE_REGULATOR_ON, new ColumnMapping<>(Boolean.class, ShuntCompensatorAttributes::isVoltageRegulatorOn, ShuntCompensatorAttributes::setVoltageRegulatorOn)); shuntCompensatorMappings.addColumnMapping("targetV", new ColumnMapping<>(Double.class, ShuntCompensatorAttributes::getTargetV, ShuntCompensatorAttributes::setTargetV)); shuntCompensatorMappings.addColumnMapping("targetDeadband", new ColumnMapping<>(Double.class, ShuntCompensatorAttributes::getTargetDeadband, ShuntCompensatorAttributes::setTargetDeadband)); shuntCompensatorMappings.addColumnMapping("linearModel", new ColumnMapping<>(ShuntCompensatorModelAttributes.class, (ShuntCompensatorAttributes attributes) -> @@ -517,7 +515,6 @@ private void createVscConverterStationMappings() { vscConverterStationMappings.addColumnMapping(VOLTAGE_LEVEL_ID, new ColumnMapping<>(String.class, VscConverterStationAttributes::getVoltageLevelId, VscConverterStationAttributes::setVoltageLevelId)); vscConverterStationMappings.addColumnMapping("bus", new ColumnMapping<>(String.class, VscConverterStationAttributes::getBus, VscConverterStationAttributes::setBus)); vscConverterStationMappings.addColumnMapping(CONNECTABLE_BUS, new ColumnMapping<>(String.class, VscConverterStationAttributes::getConnectableBus, VscConverterStationAttributes::setConnectableBus)); - vscConverterStationMappings.addColumnMapping(VOLTAGE_REGULATOR_ON, new ColumnMapping<>(Boolean.class, VscConverterStationAttributes::getVoltageRegulatorOn, VscConverterStationAttributes::setVoltageRegulatorOn)); vscConverterStationMappings.addColumnMapping("p", new ColumnMapping<>(Double.class, VscConverterStationAttributes::getP, VscConverterStationAttributes::setP)); vscConverterStationMappings.addColumnMapping("q", new ColumnMapping<>(Double.class, VscConverterStationAttributes::getQ, VscConverterStationAttributes::setQ)); vscConverterStationMappings.addColumnMapping("lossFactor", new ColumnMapping<>(Float.class, VscConverterStationAttributes::getLossFactor, VscConverterStationAttributes::setLossFactor)); diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index d17a66f6..b941eba4 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -2098,7 +2098,7 @@ private void deletePermanentLimits(UUID netwo public void insertRegulatingPoints(Map regulatingPoints) { try (var connection = dataSource.getConnection()) { try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildInsertRegulatingPointsQuery())) { - List values = new ArrayList<>(10); + List values = new ArrayList<>(11); List> list = new ArrayList<>(regulatingPoints.entrySet()); for (List> subUnit : Lists.partition(list, BATCH_SIZE)) { for (Map.Entry attributes : subUnit) { @@ -2124,12 +2124,16 @@ public void insertRegulatingPoints(Map reg values.add(attributes.getValue().getRegulatedResourceType() != null ? attributes.getValue().getRegulatedResourceType().toString() : null); + values.add(attributes.getValue().getRegulating() != null + ? attributes.getValue().getRegulating().toString() + : null); } else { values.add(null); values.add(attributes.getKey().getEquipmentId()); for (int i = 0; i < 4; i++) { values.add(null); } + values.add(false); } bindValues(preparedStmt, values, mapper); preparedStmt.addBatch(); @@ -2157,6 +2161,7 @@ public void updateRegulatingPoints(Map reg values.add(regulatingTerminal != null ? regulatingTerminal.getConnectableId() : null); values.add(regulatingTerminal != null ? regulatingTerminal.getSide() : null); values.add(attributes.getValue().getRegulatedResourceType() != null ? attributes.getValue().getRegulatedResourceType().toString() : null); + values.add(attributes.getValue().getRegulating()); // where values values.add(attributes.getKey().getNetworkUuid()); values.add(attributes.getKey().getVariantNum()); @@ -2401,6 +2406,7 @@ private Map innerGetRegulatingPoints(Prepa if (regulatingConnectableId.isPresent()) { regulatingPointAttributes.setRegulatingTerminal(new TerminalRefAttributes(resultSet.getString(7), resultSet.getString(8))); } + regulatingPointAttributes.setRegulating(resultSet.getBoolean(9)); map.put(owner, regulatingPointAttributes); } return map; diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java index 8025f140..3aae2301 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java @@ -46,6 +46,7 @@ public final class QueryCatalog { static final String REGULATION_MODE = "regulationMode"; static final String SIDE_COLUMN = "side"; static final String LIMIT_TYPE_COLUMN = "limitType"; + static final String REGULATING = "regulating"; private QueryCatalog() { } @@ -496,8 +497,9 @@ public static String buildDeleteReactiveCapabilityCurvePointsQuery() { public static String buildInsertRegulatingPointsQuery() { return "insert into " + REGULATING_POINT_TABLE + " (" + NETWORK_UUID_COLUMN + " ," + VARIANT_NUM_COLUMN + ", " + REGULATING_EQUIPMENT_ID + ", " + REGULATING_EQUIPMENT_TYPE_COLUMN + ", " + - REGULATION_MODE + ", localTerminalConnectableId, localTerminalSide, regulatingterminalconnectableid, regulatingterminalside, " + REGULATED_EQUIPMENT_TYPE_COLUMN + ")" + - " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + REGULATION_MODE + ", localTerminalConnectableId, localTerminalSide, regulatingterminalconnectableid, regulatingterminalside, " + + REGULATED_EQUIPMENT_TYPE_COLUMN + ", " + REGULATING + ")" + + " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; } public static String buildUpdateRegulatingPointsQuery() { @@ -505,7 +507,8 @@ public static String buildUpdateRegulatingPointsQuery() { " set " + REGULATION_MODE + " = ?, " + "regulatingterminalconnectableid = ?, " + "regulatingterminalside = ?, " + - REGULATED_EQUIPMENT_TYPE_COLUMN + " = ? " + + REGULATED_EQUIPMENT_TYPE_COLUMN + " = ?, " + + REGULATING + " = ? " + "where " + NETWORK_UUID_COLUMN + " = ? AND " + VARIANT_NUM_COLUMN + " = ? AND " + @@ -517,10 +520,10 @@ public static String buildCloneRegulatingPointsQuery() { return "insert into " + REGULATING_POINT_TABLE + " (" + NETWORK_UUID_COLUMN + " ," + VARIANT_NUM_COLUMN + ", " + REGULATING_EQUIPMENT_ID + ", " + REGULATING_EQUIPMENT_TYPE_COLUMN + ", " + REGULATION_MODE + ", localTerminalConnectableId, localTerminalSide, regulatingTerminalConnectableId, regulatingTerminalSide, " + - REGULATED_EQUIPMENT_TYPE_COLUMN + ") select ?, ?" + ", " + REGULATING_EQUIPMENT_ID + ", " + + REGULATED_EQUIPMENT_TYPE_COLUMN + ", " + REGULATING + ") select ?, ?" + ", " + REGULATING_EQUIPMENT_ID + ", " + REGULATING_EQUIPMENT_TYPE_COLUMN + ", " + REGULATION_MODE + ", localTerminalConnectableId, localTerminalSide, regulatingTerminalConnectableId, regulatingTerminalSide, " - + REGULATED_EQUIPMENT_TYPE_COLUMN + " from " + REGULATING_POINT_TABLE + " where " + NETWORK_UUID_COLUMN + + + REGULATED_EQUIPMENT_TYPE_COLUMN + ", " + REGULATING + " from " + REGULATING_POINT_TABLE + " where " + NETWORK_UUID_COLUMN + " = ? and " + VARIANT_NUM_COLUMN + " = ?"; } @@ -529,7 +532,7 @@ public static String buildRegulatingPointsQuery() { NETWORK_UUID_COLUMN + ", " + VARIANT_NUM_COLUMN + ", " + REGULATING_EQUIPMENT_ID + ", " + REGULATION_MODE + ", localterminalconnectableid, localterminalside, " + - "regulatingterminalconnectableid, regulatingterminalside, " + REGULATED_EQUIPMENT_TYPE_COLUMN + + "regulatingterminalconnectableid, regulatingterminalside, " + REGULATING + " from " + REGULATING_POINT_TABLE + " where " + NETWORK_UUID_COLUMN + " = ? and " + VARIANT_NUM_COLUMN + " = ? and " + @@ -543,7 +546,7 @@ public static String buildRegulatingPointsWithInClauseQuery(String columnNameFor return "select " + NETWORK_UUID_COLUMN + ", " + VARIANT_NUM_COLUMN + ", " + REGULATING_EQUIPMENT_ID + ", " + REGULATION_MODE + ", localterminalconnectableid, localterminalside, " + - "regulatingterminalconnectableid, regulatingterminalside, " + REGULATED_EQUIPMENT_TYPE_COLUMN + "regulatingterminalconnectableid, regulatingterminalside, " + REGULATING + " from " + REGULATING_POINT_TABLE + " where " + NETWORK_UUID_COLUMN + " = ? and " + VARIANT_NUM_COLUMN + " = ? and " + diff --git a/network-store-server/src/main/resources/db/changelog/changesets/changelog_20241204T110000Z.xml b/network-store-server/src/main/resources/db/changelog/changesets/changelog_20241204T110000Z.xml new file mode 100644 index 00000000..d4c2083c --- /dev/null +++ b/network-store-server/src/main/resources/db/changelog/changesets/changelog_20241204T110000Z.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/network-store-server/src/main/resources/db/changelog/changesets/move_regulating_to_regulationPoint_20241204T110000Z.sql b/network-store-server/src/main/resources/db/changelog/changesets/move_regulating_to_regulationPoint_20241204T110000Z.sql new file mode 100644 index 00000000..4d57ca33 --- /dev/null +++ b/network-store-server/src/main/resources/db/changelog/changesets/move_regulating_to_regulationPoint_20241204T110000Z.sql @@ -0,0 +1,29 @@ +-- generator +update regulatingpoint +set regulating = (select generator.voltageregulatoron from generator +where regulatingequipmenttype = 'GENERATOR' + and regulatingequipmentid = generator.id + and regulatingpoint.networkuuid = generator.networkuuid + and regulatingpoint.variantnum = generator.variantnum); +-- vsc +update regulatingpoint +set regulating = (select vscconverterstation.voltageregulatoron +from vscconverterstation +where regulatingequipmenttype = 'VSC_CONVERTER_STATION' + and regulatingequipmentid = vscconverterstation.id + and regulatingpoint.networkuuid = vscconverterstation.networkuuid + and regulatingpoint.variantnum = vscconverterstation.variantnum); +-- shunt +update regulatingpoint +set regulating = (select shuntcompensator.voltageregulatoron +from shuntcompensator +where regulatingequipmenttype = 'SHUNT_COMPENSATOR' + and regulatingequipmentid = shuntcompensator.id + and regulatingpoint.networkuuid = shuntcompensator.networkuuid + and regulatingpoint.variantnum = shuntcompensator.variantnum); + +-- svc +update regulatingpoint +set regulating = (CASE WHEN regulatingpoint.regulationmode = 'VOLTAGE' + THEN TRUE ELSE FALSE END) +where regulatingpoint.regulatingequipmenttype = 'STATIC_VAR_COMPENSATOR'; \ No newline at end of file diff --git a/network-store-server/src/main/resources/db/changelog/db.changelog-master.yaml b/network-store-server/src/main/resources/db/changelog/db.changelog-master.yaml index a3b273af..5d007952 100644 --- a/network-store-server/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/network-store-server/src/main/resources/db/changelog/db.changelog-master.yaml @@ -87,3 +87,7 @@ databaseChangeLog: - include: file: changesets/changelog_20241031T110000Z.xml relativeToChangelogFile: true + + - include: + file: changesets/changelog_20241204T110000Z.xml + relativeToChangelogFile: true diff --git a/pom.xml b/pom.xml index bc999588..92fcf51c 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,7 @@ 1.0 2.16.0 - + 1.21.0-SNAPSHOT @@ -81,6 +81,24 @@ pom import + + com.powsybl + powsybl-network-store-client + + ${powsybl-network-store.version} + + + + com.powsybl + powsybl-network-store-iidm-impl + ${powsybl-network-store.version} + + + + com.powsybl + powsybl-network-store-model + ${powsybl-network-store.version} + From 6a21a2b01ae74e0d504589303e59bf0c7583b90a Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Mon, 9 Dec 2024 15:26:49 +0100 Subject: [PATCH 2/9] review and fix Signed-off-by: Etienne LESOT --- .../com/powsybl/network/store/server/Mappings.java | 1 - .../network/store/server/NetworkStoreRepository.java | 3 +-- ...egulating_to_regulationPoint_20241204T110000Z.sql | 12 ++++++------ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java b/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java index 5ba26ae6..4206851b 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java @@ -129,7 +129,6 @@ public class Mappings { private static final String SELECTED_OPERATIONAL_LIMITS_GROUP_ID_COLUMN = "selectedOperationalLimitsGroupId"; private static final String SELECTED_OPERATIONAL_LIMITS_GROUP_ID1_COLUMN = "selectedOperationalLimitsGroupId1"; private static final String SELECTED_OPERATIONAL_LIMITS_GROUP_ID2_COLUMN = "selectedOperationalLimitsGroupId2"; - private static final String VOLTAGE_REGULATOR_ON = "voltageRegulatorOn"; private static final String MINQ = "minQ"; private static final String MAXQ = "maxQ"; private static final String TIE_LINE_ID = "tieLineId"; diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index b941eba4..97892e49 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -2125,8 +2125,7 @@ public void insertRegulatingPoints(Map reg ? attributes.getValue().getRegulatedResourceType().toString() : null); values.add(attributes.getValue().getRegulating() != null - ? attributes.getValue().getRegulating().toString() - : null); + ? attributes.getValue().getRegulating() : null); } else { values.add(null); values.add(attributes.getKey().getEquipmentId()); diff --git a/network-store-server/src/main/resources/db/changelog/changesets/move_regulating_to_regulationPoint_20241204T110000Z.sql b/network-store-server/src/main/resources/db/changelog/changesets/move_regulating_to_regulationPoint_20241204T110000Z.sql index 4d57ca33..29c025fa 100644 --- a/network-store-server/src/main/resources/db/changelog/changesets/move_regulating_to_regulationPoint_20241204T110000Z.sql +++ b/network-store-server/src/main/resources/db/changelog/changesets/move_regulating_to_regulationPoint_20241204T110000Z.sql @@ -1,26 +1,26 @@ -- generator update regulatingpoint -set regulating = (select generator.voltageregulatoron from generator +set regulating = generator.voltageregulatoron from generator where regulatingequipmenttype = 'GENERATOR' and regulatingequipmentid = generator.id and regulatingpoint.networkuuid = generator.networkuuid - and regulatingpoint.variantnum = generator.variantnum); + and regulatingpoint.variantnum = generator.variantnum; -- vsc update regulatingpoint -set regulating = (select vscconverterstation.voltageregulatoron +set regulating = vscconverterstation.voltageregulatoron from vscconverterstation where regulatingequipmenttype = 'VSC_CONVERTER_STATION' and regulatingequipmentid = vscconverterstation.id and regulatingpoint.networkuuid = vscconverterstation.networkuuid - and regulatingpoint.variantnum = vscconverterstation.variantnum); + and regulatingpoint.variantnum = vscconverterstation.variantnum; -- shunt update regulatingpoint -set regulating = (select shuntcompensator.voltageregulatoron +set regulating = shuntcompensator.voltageregulatoron from shuntcompensator where regulatingequipmenttype = 'SHUNT_COMPENSATOR' and regulatingequipmentid = shuntcompensator.id and regulatingpoint.networkuuid = shuntcompensator.networkuuid - and regulatingpoint.variantnum = shuntcompensator.variantnum); + and regulatingpoint.variantnum = shuntcompensator.variantnum; -- svc update regulatingpoint From 548cd0e6702ffa31d621c0486dd4b9c1f1259147 Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Tue, 10 Dec 2024 10:26:58 +0100 Subject: [PATCH 3/9] fix changelog Signed-off-by: Etienne LESOT --- .../changesets/changelog_20241204T110000Z.xml | 1 + ...ating_to_regulationPoint_20241204T110000Z.sql | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/network-store-server/src/main/resources/db/changelog/changesets/changelog_20241204T110000Z.xml b/network-store-server/src/main/resources/db/changelog/changesets/changelog_20241204T110000Z.xml index d4c2083c..1a07bb95 100644 --- a/network-store-server/src/main/resources/db/changelog/changesets/changelog_20241204T110000Z.xml +++ b/network-store-server/src/main/resources/db/changelog/changesets/changelog_20241204T110000Z.xml @@ -9,6 +9,7 @@ Date: Tue, 10 Dec 2024 13:22:57 +0100 Subject: [PATCH 4/9] fix sql migration Signed-off-by: Etienne LESOT --- .../changesets/changelog_20241204T110000Z.xml | 1 - ...ng_to_regulationPoint_20241204T110000Z.sql | 37 ++++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/network-store-server/src/main/resources/db/changelog/changesets/changelog_20241204T110000Z.xml b/network-store-server/src/main/resources/db/changelog/changesets/changelog_20241204T110000Z.xml index 1a07bb95..d4c2083c 100644 --- a/network-store-server/src/main/resources/db/changelog/changesets/changelog_20241204T110000Z.xml +++ b/network-store-server/src/main/resources/db/changelog/changesets/changelog_20241204T110000Z.xml @@ -9,7 +9,6 @@ Date: Tue, 10 Dec 2024 13:33:18 +0100 Subject: [PATCH 5/9] fix Signed-off-by: Etienne LESOT --- .../move_regulating_to_regulationPoint_20241204T110000Z.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/network-store-server/src/main/resources/db/changelog/changesets/move_regulating_to_regulationPoint_20241204T110000Z.sql b/network-store-server/src/main/resources/db/changelog/changesets/move_regulating_to_regulationPoint_20241204T110000Z.sql index 4b8da9ee..9c97e57b 100644 --- a/network-store-server/src/main/resources/db/changelog/changesets/move_regulating_to_regulationPoint_20241204T110000Z.sql +++ b/network-store-server/src/main/resources/db/changelog/changesets/move_regulating_to_regulationPoint_20241204T110000Z.sql @@ -1,8 +1,8 @@ -- generator update regulatingpoint set regulating = (select generator.voltageregulatoron from generator - where regulatingequipmenttype = 'GENERATOR' - and regulatingequipmentid = generator.id + where regulatingpoint.regulatingequipmenttype = 'GENERATOR' + and regulatingpoint.regulatingequipmentid = generator.id and regulatingpoint.networkuuid = generator.networkuuid and regulatingpoint.variantnum = generator.variantnum) where regulatingequipmenttype = 'GENERATOR'; From 0567dddadbcf97992c18284b3b473ac72e40e912 Mon Sep 17 00:00:00 2001 From: Franck LECUYER Date: Wed, 18 Dec 2024 16:10:42 +0100 Subject: [PATCH 6/9] upgrade to powsybl dependencies 2024.4.0 Signed-off-by: Franck LECUYER --- .../store/integration/NetworkStoreIT.java | 74 ++++++++++--------- pom.xml | 22 +----- 2 files changed, 40 insertions(+), 56 deletions(-) diff --git a/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java b/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java index 035203d9..637a0c0c 100644 --- a/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java +++ b/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java @@ -199,10 +199,12 @@ public void visitGenerator(Generator generator) { assertNull(voltageLevel1.getNodeBreakerView().getTerminal(4)); List traversedNodes = new ArrayList<>(); voltageLevel1.getNodeBreakerView().traverse(2, (node1, sw, node2) -> { - traversedNodes.add(node1); + if (!traversedNodes.contains(node1)) { + traversedNodes.add(node1); + } return TraverseResult.CONTINUE; }); - assertEquals(Arrays.asList(2, 3, 0, 1, 6), traversedNodes); + assertEquals(Arrays.asList(2, 3, 0, 1, 6, 5), traversedNodes); } } @@ -681,9 +683,9 @@ void testSubstationUpdate() { s.setTso("New TSO"); s.addGeographicalTag("paris"); - verify(mockedListener, times(1)).onUpdate(s, "country", Country.FR, Country.BB); - verify(mockedListener, times(1)).onUpdate(s, "tso", null, "New TSO"); - verify(mockedListener, times(1)).onElementAdded(s, "geographicalTags", "paris"); + verify(mockedListener, times(1)).onUpdate(s, "country", INITIAL_VARIANT_ID, Country.FR, Country.BB); + verify(mockedListener, times(1)).onUpdate(s, "tso", INITIAL_VARIANT_ID, null, "New TSO"); + verify(mockedListener, times(1)).onPropertyAdded(s, "geographicalTags", "paris"); service.flush(readNetwork); } @@ -733,14 +735,14 @@ void substationTest() { assertEquals(Country.BE, s1.getCountry().get()); assertEquals("TSO_BE", s1.getTso()); - verify(mockedListener, times(1)).onUpdate(s1, "country", Country.FR, Country.BE); - verify(mockedListener, times(1)).onUpdate(s1, "tso", "TSO_FR", "TSO_BE"); - verify(mockedListener, times(1)).onElementAdded(s1, "geographicalTags", "BELGIUM"); + verify(mockedListener, times(1)).onUpdate(s1, "country", INITIAL_VARIANT_ID, Country.FR, Country.BE); + verify(mockedListener, times(1)).onUpdate(s1, "tso", INITIAL_VARIANT_ID, "TSO_FR", "TSO_BE"); + verify(mockedListener, times(1)).onPropertyAdded(s1, "geographicalTags", "BELGIUM"); s1.setProperty("testProperty", "original"); - verify(mockedListener, times(1)).onElementAdded(s1, "properties[testProperty]", "original"); + verify(mockedListener, times(1)).onPropertyAdded(s1, "properties[testProperty]", "original"); s1.setProperty("testProperty", "modified"); - verify(mockedListener, times(1)).onElementReplaced(s1, "properties[testProperty]", "original", "modified"); + verify(mockedListener, times(1)).onPropertyReplaced(s1, "properties[testProperty]", "original", "modified"); } } @@ -785,9 +787,9 @@ void voltageLevelTest() { assertEquals(370, vl1.getLowVoltageLimit(), 0.1); assertEquals(390, vl1.getHighVoltageLimit(), 0.1); - verify(mockedListener, times(1)).onUpdate(vl1, "nominalV", 400d, 380d); - verify(mockedListener, times(1)).onUpdate(vl1, "lowVoltageLimit", 385d, 370d); - verify(mockedListener, times(1)).onUpdate(vl1, "highVoltageLimit", 415d, 390d); + verify(mockedListener, times(1)).onUpdate(vl1, "nominalV", INITIAL_VARIANT_ID, 400d, 380d); + verify(mockedListener, times(1)).onUpdate(vl1, "lowVoltageLimit", INITIAL_VARIANT_ID, 385d, 370d); + verify(mockedListener, times(1)).onUpdate(vl1, "highVoltageLimit", INITIAL_VARIANT_ID, 415d, 390d); } } @@ -865,12 +867,12 @@ void lineTest() { assertEquals(8, line.getB1(), 0.1); assertEquals(16, line.getB2(), 0.1); - verify(mockedListener, times(1)).onUpdate(line, "r", 1d, 5d); - verify(mockedListener, times(1)).onUpdate(line, "x", 3d, 6d); - verify(mockedListener, times(1)).onUpdate(line, "g1", 4d, 12d); - verify(mockedListener, times(1)).onUpdate(line, "g2", 8d, 24d); - verify(mockedListener, times(1)).onUpdate(line, "b1", 2d, 8d); - verify(mockedListener, times(1)).onUpdate(line, "b2", 4d, 16d); + verify(mockedListener, times(1)).onUpdate(line, "r", null, 1d, 5d); + verify(mockedListener, times(1)).onUpdate(line, "x", INITIAL_VARIANT_ID, 3d, 6d); + verify(mockedListener, times(1)).onUpdate(line, "g1", INITIAL_VARIANT_ID, 4d, 12d); + verify(mockedListener, times(1)).onUpdate(line, "g2", INITIAL_VARIANT_ID, 8d, 24d); + verify(mockedListener, times(1)).onUpdate(line, "b1", INITIAL_VARIANT_ID, 2d, 8d); + verify(mockedListener, times(1)).onUpdate(line, "b2", INITIAL_VARIANT_ID, 4d, 16d); } } @@ -927,8 +929,8 @@ void batteryTest() { battery.setMaxP(90); battery.setMinP(50); - verify(mockedListener, times(1)).onUpdate(battery, "maxP", 70d, 90d); - verify(mockedListener, times(1)).onUpdate(battery, "minP", 40d, 50d); + verify(mockedListener, times(1)).onUpdate(battery, "maxP", INITIAL_VARIANT_ID, 70d, 90d); + verify(mockedListener, times(1)).onUpdate(battery, "minP", INITIAL_VARIANT_ID, 40d, 50d); } } @@ -1082,18 +1084,18 @@ void danglingLineTest() { danglingLine.getGeneration().setVoltageRegulationOn(false); // Check update notification - verify(mockedListener, times(1)).onUpdate(danglingLine, "r", 27d, 25d); - verify(mockedListener, times(1)).onUpdate(danglingLine, "x", 44d, 48d); - verify(mockedListener, times(1)).onUpdate(danglingLine, "g", 89d, 83d); - verify(mockedListener, times(1)).onUpdate(danglingLine, "b", 11d, 15d); + verify(mockedListener, times(1)).onUpdate(danglingLine, "r", INITIAL_VARIANT_ID, 27d, 25d); + verify(mockedListener, times(1)).onUpdate(danglingLine, "x", INITIAL_VARIANT_ID, 44d, 48d); + verify(mockedListener, times(1)).onUpdate(danglingLine, "g", INITIAL_VARIANT_ID, 89d, 83d); + verify(mockedListener, times(1)).onUpdate(danglingLine, "b", INITIAL_VARIANT_ID, 11d, 15d); verify(mockedListener, times(1)).onUpdate(danglingLine, "p0", INITIAL_VARIANT_ID, 533d, 520d); verify(mockedListener, times(1)).onUpdate(danglingLine, "q0", INITIAL_VARIANT_ID, 242d, 250d); - verify(mockedListener, times(1)).onUpdate(danglingLine, "minP", 10d, 20d); - verify(mockedListener, times(1)).onUpdate(danglingLine, "maxP", 500d, 900d); + verify(mockedListener, times(1)).onUpdate(danglingLine, "minP", INITIAL_VARIANT_ID, 10d, 20d); + verify(mockedListener, times(1)).onUpdate(danglingLine, "maxP", INITIAL_VARIANT_ID, 500d, 900d); verify(mockedListener, times(1)).onUpdate(danglingLine, "targetP", INITIAL_VARIANT_ID, 100d, 300d); verify(mockedListener, times(1)).onUpdate(danglingLine, "targetQ", INITIAL_VARIANT_ID, 200d, 1100d); verify(mockedListener, times(1)).onUpdate(danglingLine, "targetV", INITIAL_VARIANT_ID, 300d, 350d); - verify(mockedListener, times(1)).onUpdate(danglingLine, "voltageRegulationOn", true, false); + verify(mockedListener, times(1)).onUpdate(danglingLine, "voltageRegulationOn", INITIAL_VARIANT_ID, true, false); readNetwork.removeListener(mockedListener); @@ -1506,14 +1508,14 @@ void twoWindingsTransformerTest() { assertEquals(120, twoWindingsTransformer.getRatedU2(), 0.1); assertEquals(100, twoWindingsTransformer.getRatedS(), 0.1); - verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "r", 250d, 280d); - verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "x", 100d, 130d); - verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "g", 52d, 82d); - verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "b", 12d, 42d); - verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "ratedU1", 65d, 95d); - verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "ratedU2", 90d, 120d); - verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "ratedS", 50d, 100d); - verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "fictitious", false, true); + verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "r", INITIAL_VARIANT_ID, 250d, 280d); + verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "x", INITIAL_VARIANT_ID, 100d, 130d); + verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "g", INITIAL_VARIANT_ID, 52d, 82d); + verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "b", INITIAL_VARIANT_ID, 12d, 42d); + verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "ratedU1", INITIAL_VARIANT_ID, 65d, 95d); + verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "ratedU2", INITIAL_VARIANT_ID, 90d, 120d); + verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "ratedS", INITIAL_VARIANT_ID, 50d, 100d); + verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "fictitious", null, false, true); readNetwork.removeListener(mockedListener); } diff --git a/pom.xml b/pom.xml index b438216a..260d0921 100644 --- a/pom.xml +++ b/pom.xml @@ -49,8 +49,8 @@ 1.0 - 2.16.0 - 1.21.0-SNAPSHOT + 2.17.0-SNAPSHOT + @@ -81,24 +81,6 @@ pom import - - com.powsybl - powsybl-network-store-client - - ${powsybl-network-store.version} - - - - com.powsybl - powsybl-network-store-iidm-impl - ${powsybl-network-store.version} - - - - com.powsybl - powsybl-network-store-model - ${powsybl-network-store.version} - From d1b33dfb1697a8aaef19202abc32f91193eb6dec Mon Sep 17 00:00:00 2001 From: Franck LECUYER Date: Mon, 23 Dec 2024 11:32:36 +0100 Subject: [PATCH 7/9] upgrade to powsybl ws dependencies 2.17.0 Signed-off-by: Franck LECUYER --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 260d0921..25759d03 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ 1.0 - 2.17.0-SNAPSHOT + 2.17.0 From 2c1ac740db9d965dd7ad79ee0b6377cbbc0c1aaf Mon Sep 17 00:00:00 2001 From: Franck LECUYER Date: Thu, 9 Jan 2025 10:10:12 +0100 Subject: [PATCH 8/9] Changes after changes in network-store-client Signed-off-by: Franck LECUYER --- .../com/powsybl/network/store/integration/NetworkStoreIT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java b/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java index 637a0c0c..26abbd5d 100644 --- a/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java +++ b/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java @@ -867,7 +867,7 @@ void lineTest() { assertEquals(8, line.getB1(), 0.1); assertEquals(16, line.getB2(), 0.1); - verify(mockedListener, times(1)).onUpdate(line, "r", null, 1d, 5d); + verify(mockedListener, times(1)).onUpdate(line, "r", INITIAL_VARIANT_ID, 1d, 5d); verify(mockedListener, times(1)).onUpdate(line, "x", INITIAL_VARIANT_ID, 3d, 6d); verify(mockedListener, times(1)).onUpdate(line, "g1", INITIAL_VARIANT_ID, 4d, 12d); verify(mockedListener, times(1)).onUpdate(line, "g2", INITIAL_VARIANT_ID, 8d, 24d); @@ -1515,7 +1515,7 @@ void twoWindingsTransformerTest() { verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "ratedU1", INITIAL_VARIANT_ID, 65d, 95d); verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "ratedU2", INITIAL_VARIANT_ID, 90d, 120d); verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "ratedS", INITIAL_VARIANT_ID, 50d, 100d); - verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "fictitious", null, false, true); + verify(mockedListener, times(1)).onUpdate(twoWindingsTransformer, "fictitious", INITIAL_VARIANT_ID, false, true); readNetwork.removeListener(mockedListener); } From 04cf0eee53cf94cd24d33b312fd5cc2f4bc747fa Mon Sep 17 00:00:00 2001 From: Seddik Yengui Date: Thu, 26 Dec 2024 11:25:28 +0100 Subject: [PATCH 9/9] Add commits from PR : https://github.com/powsybl/powsybl-network-store-server/pull/87 Signed-off-by: Franck LECUYER --- .../store/server/NetworkStoreController.java | 296 ++++++------ .../store/server/NetworkStoreRepository.java | 154 +++--- .../network/store/server/QueryCatalog.java | 16 +- .../server/NetworkStoreControllerIT.java | 448 +++++++++++++++++- .../server/NetworkStoreRepositoryTest.java | 20 +- 5 files changed, 686 insertions(+), 248 deletions(-) diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java index 01756d83..c3a4de4f 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java @@ -213,18 +213,21 @@ public ResponseEntity updateSubstations(@Parameter(description = "Network return updateAll(resources -> repository.updateSubstations(networkId, resources), substationsResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/substations/{substationId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a substation by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/substations", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple substations by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete substation") + @ApiResponse(responseCode = "200", description = "Successfully deleted substations"), + @ApiResponse(responseCode = "400", description = "Invalid request payload") }) - public ResponseEntity deleteSubstation(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Substation ID", required = true) @PathVariable("substationId") String substationId) { - repository.deleteSubstation(networkId, variantNum, substationId); + public ResponseEntity deleteSubstations( + @Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of substation IDs to delete", required = true) @RequestBody List substationIds) { + repository.deleteSubstations(networkId, variantNum, substationIds); return ResponseEntity.ok().build(); } + // voltage level @GetMapping(value = "/{networkId}/{variantNum}/voltage-levels", produces = APPLICATION_JSON_VALUE) @@ -274,15 +277,16 @@ public ResponseEntity updateVoltageLevelsSv(@Parameter(description = "Netw return updateAll(resources -> repository.updateVoltageLevelsSv(networkId, resources), voltageLevelResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/voltage-levels/{voltageLevelId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a voltage level by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/voltage-levels", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple voltage levels by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete voltage level") + @ApiResponse(responseCode = "200", description = "Successfully delete voltage levels"), + @ApiResponse(responseCode = "400", description = "Invalid request payload") }) - public ResponseEntity deleteVoltageLevel(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + public ResponseEntity deleteVoltageLevels(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Voltage level ID", required = true) @PathVariable("voltageLevelId") String voltageLevelId) { - repository.deleteVoltageLevel(networkId, variantNum, voltageLevelId); + @Parameter(description = "List of voltage level IDs to delete", required = true) @RequestBody List voltageLevelIds) { + repository.deleteVoltageLevels(networkId, variantNum, voltageLevelIds); return ResponseEntity.ok().build(); } @@ -472,18 +476,18 @@ public ResponseEntity updateGeneratorsSv(@Parameter(description = "Network return updateAll(resources -> repository.updateGeneratorsSv(networkId, resources), generatorResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/generators/{generatorId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a generator by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/generators", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple generators by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete generator") + @ApiResponse(responseCode = "200", description = "Successfully delete generator"), + @ApiResponse(responseCode = "400", description = "Invalid request payload") }) - public ResponseEntity deleteGenerator(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Generator ID", required = true) @PathVariable("generatorId") String generatorId) { - repository.deleteGenerator(networkId, variantNum, generatorId); + public ResponseEntity deleteGenerators(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of generator IDs to delete", required = true) @RequestBody List generatorIds) { + repository.deleteGenerators(networkId, variantNum, generatorIds); return ResponseEntity.ok().build(); } - // tie line @PostMapping(value = "/{networkId}/tie-lines") @@ -524,18 +528,18 @@ public ResponseEntity updateTieLines(@Parameter(description = "Network ID" return updateAll(resources -> repository.updateTieLines(networkId, resources), tieLineResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/tie-lines/{tieLineId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a generator by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/tie-lines", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple tie lines by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete generator") + @ApiResponse(responseCode = "200", description = "Successfully delete tie lines"), + @ApiResponse(responseCode = "400", description = "Invalid request payload") }) - public ResponseEntity deleteTieLine(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Tie line ID", required = true) @PathVariable("tieLineId") String tieLineId) { - repository.deleteTieLine(networkId, variantNum, tieLineId); + public ResponseEntity deleteTieLines(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of tie line IDs to delete", required = true) @RequestBody List tieLineIds) { + repository.deleteTieLines(networkId, variantNum, tieLineIds); return ResponseEntity.ok().build(); } - // battery @PostMapping(value = "/{networkId}/batteries") @@ -585,15 +589,16 @@ public ResponseEntity updateBatteriesSv(@Parameter(description = "Network return updateAll(resources -> repository.updateBatteriesSv(networkId, resources), batteryResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/batteries/{batteryId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a battery by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/batteries", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple batteries by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete battery") + @ApiResponse(responseCode = "200", description = "Successfully delete batteries"), + @ApiResponse(responseCode = "400", description = "Invalid request payload") }) public ResponseEntity deleteBattery(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Battery ID", required = true) @PathVariable("batteryId") String batteryId) { - repository.deleteBattery(networkId, variantNum, batteryId); + @Parameter(description = "List of battery IDs to delete", required = true) @RequestBody List batteryIds) { + repository.deleteBatteries(networkId, variantNum, batteryIds); return ResponseEntity.ok().build(); } @@ -646,15 +651,16 @@ public ResponseEntity updateLoadsSv(@Parameter(description = "Network ID", return updateAll(resources -> repository.updateLoadsSv(networkId, resources), loadResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/loads/{loadId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a load by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/loads", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple loads by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete load") + @ApiResponse(responseCode = "200", description = "Successfully delete loads"), + @ApiResponse(responseCode = "400", description = "Invalid request payload") }) - public ResponseEntity deleteLoad(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Load ID", required = true) @PathVariable("loadId") String loadId) { - repository.deleteLoad(networkId, variantNum, loadId); + public ResponseEntity deleteLoads(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of load IDs to delete", required = true) @RequestBody List loadIds) { + repository.deleteLoads(networkId, variantNum, loadIds); return ResponseEntity.ok().build(); } @@ -707,15 +713,17 @@ public ResponseEntity updateShuntCompensatorsSv(@Parameter(description = " return updateAll(resources -> repository.updateShuntCompensatorsSv(networkId, resources), shuntCompensatorResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/shunt-compensators/{shuntCompensatorId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a shunt compensator by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/shunt-compensators", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple shunt compensators by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete shunt compensator") + @ApiResponse(responseCode = "200", description = "Successfully deleted shunt compensators"), + @ApiResponse(responseCode = "400", description = "Invalid input"), }) - public ResponseEntity deleteShuntCompensator(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Shunt compensator ID", required = true) @PathVariable("shuntCompensatorId") String shuntCompensatorId) { - repository.deleteShuntCompensator(networkId, variantNum, shuntCompensatorId); + public ResponseEntity deleteShuntCompensators( + @Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of shunt compensator IDs to delete", required = true) @RequestBody List shuntCompensatorIds) { + repository.deleteShuntCompensators(networkId, variantNum, shuntCompensatorIds); return ResponseEntity.ok().build(); } @@ -768,18 +776,21 @@ public ResponseEntity updateVscConverterStations(@Parameter(description = return updateAll(resources -> repository.updateVscConverterStationsSv(networkId, resources), vscConverterStationResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/vsc-converter-stations/{vscConverterStationId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a vsc converter station by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/vsc-converter-stations", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple VSC converter stations by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete vsc converter station") + @ApiResponse(responseCode = "200", description = "Successfully deleted VSC converter stations"), + @ApiResponse(responseCode = "400", description = "Invalid input"), }) - public ResponseEntity deleteVscConverterStation(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Vsc converter station ID", required = true) @PathVariable("vscConverterStationId") String vscConverterStationId) { - repository.deleteVscConverterStation(networkId, variantNum, vscConverterStationId); + public ResponseEntity deleteVscConverterStations( + @Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of VSC converter station IDs to delete", required = true) @RequestBody List vscConverterStationIds) { + repository.deleteVscConverterStations(networkId, variantNum, vscConverterStationIds); return ResponseEntity.ok().build(); } + // LCC converter station @PostMapping(value = "/{networkId}/lcc-converter-stations") @@ -829,18 +840,21 @@ public ResponseEntity updateLccConverterStationsSv(@Parameter(description return updateAll(resources -> repository.updateLccConverterStationsSv(networkId, resources), lccConverterStationResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/lcc-converter-stations/{lccConverterStationId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a lcc converter station by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/lcc-converter-stations", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple LCC converter stations by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete lcc converter station") + @ApiResponse(responseCode = "200", description = "Successfully deleted LCC converter stations"), + @ApiResponse(responseCode = "400", description = "Invalid input"), }) - public ResponseEntity deleteLccConverterStation(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Lcc converter station ID", required = true) @PathVariable("lccConverterStationId") String lccConverterStationId) { - repository.deleteLccConverterStation(networkId, variantNum, lccConverterStationId); + public ResponseEntity deleteLccConverterStations( + @Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of LCC converter station IDs to delete", required = true) @RequestBody List lccConverterStationIds) { + repository.deleteLccConverterStations(networkId, variantNum, lccConverterStationIds); return ResponseEntity.ok().build(); } + // static var compensator @PostMapping(value = "/{networkId}/static-var-compensators") @@ -890,15 +904,16 @@ public ResponseEntity updateStaticVarCompensatorsSv(@Parameter(description return updateAll(resources -> repository.updateStaticVarCompensatorsSv(networkId, resources), staticVarCompensatorResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/static-var-compensators/{staticVarCompensatorId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a static var compensator by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/static-var-compensators", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple static var compensators by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete static var compensator") + @ApiResponse(responseCode = "200", description = "Successfully deleted static var compensators"), + @ApiResponse(responseCode = "400", description = "Invalid input"), }) - public ResponseEntity deleteStaticVarCompensator(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Static var compensator ID", required = true) @PathVariable("staticVarCompensatorId") String staticVarCompensatorId) { - repository.deleteStaticVarCompensator(networkId, variantNum, staticVarCompensatorId); + public ResponseEntity deleteStaticVarCompensators(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of static var compensator IDs to delete", required = true) @RequestBody List staticVarCompensatorIds) { + repository.deleteStaticVarCompensators(networkId, variantNum, staticVarCompensatorIds); return ResponseEntity.ok().build(); } @@ -934,15 +949,17 @@ public ResponseEntity> getBusbarSectio return get(() -> repository.getBusbarSection(networkId, variantNum, busbarSectionId)); } - @DeleteMapping(value = "/{networkId}/{variantNum}/busbar-sections/{busBarSectionId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a bus bar section by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/busbar-sections", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple bus bar sections by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete bus bar section") + @ApiResponse(responseCode = "200", description = "Successfully deleted bus bar sections"), + @ApiResponse(responseCode = "400", description = "Invalid input"), }) - public ResponseEntity deleteBusBarSection(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Bus bar section ID", required = true) @PathVariable("busBarSectionId") String busBarSectionId) { - repository.deleteBusBarSection(networkId, variantNum, busBarSectionId); + public ResponseEntity deleteBusBarSections( + @Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of bus bar section IDs to delete", required = true) @RequestBody List busBarSectionIds) { + repository.deleteBusBarSections(networkId, variantNum, busBarSectionIds); return ResponseEntity.ok().build(); } @@ -994,18 +1011,21 @@ public ResponseEntity updateSwitches(@Parameter(description = "Network ID" return updateAll(resources -> repository.updateSwitches(networkId, resources), switchResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/switches/{switchId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a switch by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/switches", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple switches by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete switch") + @ApiResponse(responseCode = "200", description = "Successfully deleted switches"), + @ApiResponse(responseCode = "400", description = "Invalid input"), }) - public ResponseEntity deleteSwitch(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Switch ID", required = true) @PathVariable("switchId") String switchId) { - repository.deleteSwitch(networkId, variantNum, switchId); + public ResponseEntity deleteSwitches( + @Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of switch IDs to delete", required = true) @RequestBody List switchIds) { + repository.deleteSwitches(networkId, variantNum, switchIds); return ResponseEntity.ok().build(); } + // 2 windings transformer @PostMapping(value = "/{networkId}/2-windings-transformers") @@ -1055,18 +1075,20 @@ public ResponseEntity updateTwoWindingsTransformersSv(@Parameter(descripti return updateAll(resources -> repository.updateTwoWindingsTransformersSv(networkId, resources), twoWindingsTransformerResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/2-windings-transformers/{twoWindingsTransformerId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a 2 windings transformer by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/2-windings-transformers", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple 2-windings transformers by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete 2 windings transformer") + @ApiResponse(responseCode = "200", description = "Successfully deleted 2-windings transformers"), + @ApiResponse(responseCode = "400", description = "Invalid input"), }) - public ResponseEntity deleteTwoWindingsTransformer(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "2 windings transformer ID", required = true) @PathVariable("twoWindingsTransformerId") String twoWindingsTransformerId) { - repository.deleteTwoWindingsTransformer(networkId, variantNum, twoWindingsTransformerId); + public ResponseEntity deleteTwoWindingsTransformers(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of 2-windings transformer IDs to delete", required = true) @RequestBody List twoWindingsTransformerIds) { + repository.deleteTwoWindingsTransformers(networkId, variantNum, twoWindingsTransformerIds); return ResponseEntity.ok().build(); } + // 3 windings transformer @PostMapping(value = "/{networkId}/3-windings-transformers") @@ -1116,18 +1138,20 @@ public ResponseEntity updateThreeWindingsTransformersSv(@Parameter(descrip return updateAll(resources -> repository.updateThreeWindingsTransformersSv(networkId, resources), threeWindingsTransformerResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/3-windings-transformers/{threeWindingsTransformerId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a 3 windings transformer by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/3-windings-transformers", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple 3-windings transformers by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete 3 windings transformer") + @ApiResponse(responseCode = "200", description = "Successfully deleted 3-windings transformers"), + @ApiResponse(responseCode = "400", description = "Invalid input"), }) - public ResponseEntity deleteThreeWindingsTransformer(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "3 windings transformer ID", required = true) @PathVariable("threeWindingsTransformerId") String threeWindingsTransformerId) { - repository.deleteThreeWindingsTransformer(networkId, variantNum, threeWindingsTransformerId); + public ResponseEntity deleteThreeWindingsTransformers(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of 3-windings transformer IDs to delete", required = true) @RequestBody List threeWindingsTransformerIds) { + repository.deleteThreeWindingsTransformers(networkId, variantNum, threeWindingsTransformerIds); return ResponseEntity.ok().build(); } + // line @PostMapping(value = "/{networkId}/lines") @@ -1177,18 +1201,20 @@ public ResponseEntity updateLinesSv(@Parameter(description = "Network ID", return updateAll(resources -> repository.updateLinesSv(networkId, resources), lineResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/lines/{lineId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a line by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/lines", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple lines by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete line") + @ApiResponse(responseCode = "200", description = "Successfully deleted lines"), + @ApiResponse(responseCode = "400", description = "Invalid input"), }) - public ResponseEntity deleteLine(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Line ID", required = true) @PathVariable("lineId") String lineId) { - repository.deleteLine(networkId, variantNum, lineId); + public ResponseEntity deleteLines(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of line IDs to delete", required = true) @RequestBody List lineIds) { + repository.deleteLines(networkId, variantNum, lineIds); return ResponseEntity.ok().build(); } + // hvdc line @PostMapping(value = "/{networkId}/hvdc-lines") @@ -1229,18 +1255,20 @@ public ResponseEntity updateHvdcLines(@Parameter(description = "Network ID return updateAll(resources -> repository.updateHvdcLines(networkId, resources), hvdcLineResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/hvdc-lines/{hvdcLineId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a hvdc line by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/hvdc-lines", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple hvdc lines by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete hvdc line") + @ApiResponse(responseCode = "200", description = "Successfully deleted hvdc lines"), + @ApiResponse(responseCode = "400", description = "Invalid input"), }) - public ResponseEntity deleteHvdcLine(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Hvdc line ID", required = true) @PathVariable("hvdcLineId") String hvdcLineId) { - repository.deleteHvdcLine(networkId, variantNum, hvdcLineId); + public ResponseEntity deleteHvdcLines(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of hvdc line IDs to delete", required = true) @RequestBody List hvdcLineIds) { + repository.deleteHvdcLines(networkId, variantNum, hvdcLineIds); return ResponseEntity.ok().build(); } + // dangling line @PostMapping(value = "/{networkId}/dangling-lines") @@ -1272,15 +1300,16 @@ public ResponseEntity> getDanglingLine( return get(() -> repository.getDanglingLine(networkId, variantNum, danglingLineId)); } - @DeleteMapping(value = "/{networkId}/{variantNum}/dangling-lines/{danglingLineId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a dangling line by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/dangling-lines", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple dangling lines by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete dangling line") + @ApiResponse(responseCode = "200", description = "Successfully deleted dangling lines"), + @ApiResponse(responseCode = "400", description = "Invalid input"), }) - public ResponseEntity deleteDanglingLine(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Dangling line ID", required = true) @PathVariable("danglingLineId") String danglingLineId) { - repository.deleteDanglingLine(networkId, variantNum, danglingLineId); + public ResponseEntity deleteDanglingLines(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of dangling line IDs to delete", required = true) @RequestBody List danglingLineIds) { + repository.deleteDanglingLines(networkId, variantNum, danglingLineIds); return ResponseEntity.ok().build(); } @@ -1340,18 +1369,20 @@ public ResponseEntity updateGrounds(@Parameter(description = "Network ID", return updateAll(resources -> repository.updateGrounds(networkId, resources), groundResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/grounds/{groundId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a ground by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/grounds", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple grounds by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete ground") + @ApiResponse(responseCode = "200", description = "Successfully deleted grounds"), + @ApiResponse(responseCode = "400", description = "Invalid input"), }) - public ResponseEntity deleteGround(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Ground ID", required = true) @PathVariable("groundId") String groundId) { - repository.deleteGround(networkId, variantNum, groundId); + public ResponseEntity deleteGrounds(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of ground IDs to delete", required = true) @RequestBody List groundIds) { + repository.deleteGrounds(networkId, variantNum, groundIds); return ResponseEntity.ok().build(); } + // buses @PostMapping(value = "/{networkId}/configured-buses") @@ -1404,15 +1435,16 @@ public ResponseEntity updateBuses(@Parameter(description = "Network ID", r return updateAll(resources -> repository.updateBuses(networkId, resources), busResources); } - @DeleteMapping(value = "/{networkId}/{variantNum}/configured-buses/{busId}", produces = APPLICATION_JSON_VALUE) - @Operation(summary = "Delete a bus by id") + @DeleteMapping(value = "/{networkId}/{variantNum}/configured-buses", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Delete multiple buses by IDs") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully delete bus") + @ApiResponse(responseCode = "200", description = "Successfully deleted buses"), + @ApiResponse(responseCode = "400", description = "Invalid input"), }) - public ResponseEntity deleteBus(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, - @Parameter(description = "Bus ID", required = true) @PathVariable("busId") String busId) { - repository.deleteBus(networkId, variantNum, busId); + public ResponseEntity deleteBuses(@Parameter(description = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "List of bus IDs to delete", required = true) @RequestBody List busIds) { + repository.deleteBuses(networkId, variantNum, busIds); return ResponseEntity.ok().build(); } diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index 97892e49..26bef589 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -28,6 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Repository; +import org.springframework.util.CollectionUtils; import javax.sql.DataSource; import java.sql.Connection; @@ -831,18 +832,28 @@ public void updateIdentifiables(UUID networkU extensionHandler.updateExtensionsFromEquipments(networkUuid, resources); } - public void deleteIdentifiable(UUID networkUuid, int variantNum, String id, String tableName) { + public void deleteIdentifiables(UUID networkUuid, int variantNum, List ids, String tableName) { + if (CollectionUtils.isEmpty(ids)) { + throw new IllegalArgumentException("The list of IDs to delete cannot be null or empty"); + } + try (var connection = dataSource.getConnection()) { - try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildDeleteIdentifiableQuery(tableName))) { - preparedStmt.setObject(1, networkUuid); - preparedStmt.setInt(2, variantNum); - preparedStmt.setString(3, id); - preparedStmt.executeUpdate(); + try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildDeleteIdentifiablesQuery(tableName, ids.size()))) { + for (List idsPartition : Lists.partition(ids, BATCH_SIZE)) { + preparedStmt.setObject(1, networkUuid); + preparedStmt.setInt(2, variantNum); + + for (int i = 0; i < idsPartition.size(); i++) { + preparedStmt.setString(3 + i, idsPartition.get(i)); + } + + preparedStmt.executeUpdate(); + } } } catch (SQLException e) { throw new UncheckedSqlException(e); } - extensionHandler.deleteExtensionsFromIdentifiable(networkUuid, variantNum, id); + extensionHandler.deleteExtensionsFromIdentifiables(networkUuid, variantNum, ids); } // substation @@ -863,8 +874,8 @@ public void updateSubstations(UUID networkUuid, List substationIds) { + deleteIdentifiables(networkUuid, variantNum, substationIds, SUBSTATION_TABLE); } // voltage level @@ -913,8 +924,8 @@ public List> getVoltageLevels(UUID networkUuid, return getIdentifiables(networkUuid, variantNum, mappings.getVoltageLevelMappings()); } - public void deleteVoltageLevel(UUID networkUuid, int variantNum, String voltageLevelId) { - deleteIdentifiable(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_TABLE); + public void deleteVoltageLevels(UUID networkUuid, int variantNum, List voltageLevelIds) { + deleteIdentifiables(networkUuid, variantNum, voltageLevelIds, VOLTAGE_LEVEL_TABLE); } // generator @@ -974,12 +985,11 @@ public void updateGeneratorsSv(UUID networkUuid, List generatorId) { + deleteIdentifiables(networkUuid, variantNum, generatorId, GENERATOR_TABLE); deleteReactiveCapabilityCurvePoints(networkUuid, variantNum, generatorId); - deleteRegulatingPoints(networkUuid, variantNum, Collections.singletonList(generatorId), ResourceType.GENERATOR); + deleteRegulatingPoints(networkUuid, variantNum, generatorId, ResourceType.GENERATOR); } - // battery public void createBatteries(UUID networkUuid, List> resources) { @@ -1030,9 +1040,9 @@ public void updateBatteriesSv(UUID networkUuid, List batteryIds) { + deleteIdentifiables(networkUuid, variantNum, batteryIds, BATTERY_TABLE); + deleteReactiveCapabilityCurvePoints(networkUuid, variantNum, batteryIds); } // load @@ -1065,8 +1075,8 @@ public void updateLoadsSv(UUID networkUuid, List updateInjectionsSv(networkUuid, resources, LOAD_TABLE); } - public void deleteLoad(UUID networkUuid, int variantNum, String loadId) { - deleteIdentifiable(networkUuid, variantNum, loadId, LOAD_TABLE); + public void deleteLoads(UUID networkUuid, int variantNum, List loadIds) { + deleteIdentifiables(networkUuid, variantNum, loadIds, LOAD_TABLE); } // shunt compensator @@ -1107,9 +1117,9 @@ public void updateShuntCompensatorsSv(UUID networkUuid, List shuntCompensatorIds) { + deleteRegulatingPoints(networkUuid, variantNum, shuntCompensatorIds, ResourceType.SHUNT_COMPENSATOR); + deleteIdentifiables(networkUuid, variantNum, shuntCompensatorIds, SHUNT_COMPENSATOR_TABLE); } // VSC converter station @@ -1168,10 +1178,10 @@ public void updateVscConverterStationsSv(UUID networkUuid, List vscConverterStationIds) { + deleteIdentifiables(networkUuid, variantNum, vscConverterStationIds, VSC_CONVERTER_STATION_TABLE); + deleteReactiveCapabilityCurvePoints(networkUuid, variantNum, vscConverterStationIds); + deleteRegulatingPoints(networkUuid, variantNum, vscConverterStationIds, ResourceType.VSC_CONVERTER_STATION); } // LCC converter station @@ -1200,8 +1210,8 @@ public void updateLccConverterStationsSv(UUID networkUuid, List lccConverterStationIds) { + deleteIdentifiables(networkUuid, variantNum, lccConverterStationIds, LCC_CONVERTER_STATION_TABLE); } // static var compensators @@ -1242,9 +1252,9 @@ public void updateStaticVarCompensatorsSv(UUID networkUuid, List staticVarCompensatorIds) { + deleteRegulatingPoints(networkUuid, variantNum, staticVarCompensatorIds, ResourceType.STATIC_VAR_COMPENSATOR); + deleteIdentifiables(networkUuid, variantNum, staticVarCompensatorIds, STATIC_VAR_COMPENSATOR_TABLE); } // busbar section @@ -1273,8 +1283,8 @@ public List> getVoltageLevelBusbarSections(UUI return busbars; } - public void deleteBusBarSection(UUID networkUuid, int variantNum, String busBarSectionId) { - deleteIdentifiable(networkUuid, variantNum, busBarSectionId, BUSBAR_SECTION_TABLE); + public void deleteBusBarSections(UUID networkUuid, int variantNum, List busBarSectionIds) { + deleteIdentifiables(networkUuid, variantNum, busBarSectionIds, BUSBAR_SECTION_TABLE); } // switch @@ -1299,8 +1309,8 @@ public void updateSwitches(UUID networkUuid, List> re updateIdentifiables(networkUuid, resources, mappings.getSwitchMappings(), VOLTAGE_LEVEL_ID_COLUMN); } - public void deleteSwitch(UUID networkUuid, int variantNum, String switchId) { - deleteIdentifiable(networkUuid, variantNum, switchId, SWITCH_TABLE); + public void deleteSwitches(UUID networkUuid, int variantNum, List switchIds) { + deleteIdentifiables(networkUuid, variantNum, switchIds, SWITCH_TABLE); } // 2 windings transformer @@ -1371,11 +1381,11 @@ public void updateTwoWindingsTransformersSv(UUID networkUuid, List twoWindingsTransformerIds) { + deleteIdentifiables(networkUuid, variantNum, twoWindingsTransformerIds, TWO_WINDINGS_TRANSFORMER_TABLE); + deleteTemporaryLimits(networkUuid, variantNum, twoWindingsTransformerIds); + deletePermanentLimits(networkUuid, variantNum, twoWindingsTransformerIds); + deleteTapChangerSteps(networkUuid, variantNum, twoWindingsTransformerIds); } // 3 windings transformer @@ -1468,11 +1478,11 @@ public void updateThreeWindingsTransformersSv(UUID networkUuid, List threeWindingsTransformerIds) { + deleteIdentifiables(networkUuid, variantNum, threeWindingsTransformerIds, THREE_WINDINGS_TRANSFORMER_TABLE); + deleteTemporaryLimits(networkUuid, variantNum, threeWindingsTransformerIds); + deletePermanentLimits(networkUuid, variantNum, threeWindingsTransformerIds); + deleteTapChangerSteps(networkUuid, variantNum, threeWindingsTransformerIds); } // line @@ -1531,10 +1541,10 @@ public void updateLinesSv(UUID networkUuid, List> r updateBranchesSv(networkUuid, resources, LINE_TABLE); } - public void deleteLine(UUID networkUuid, int variantNum, String lineId) { - deleteIdentifiable(networkUuid, variantNum, lineId, LINE_TABLE); - deleteTemporaryLimits(networkUuid, variantNum, lineId); - deletePermanentLimits(networkUuid, variantNum, lineId); + public void deleteLines(UUID networkUuid, int variantNum, List lineIds) { + deleteIdentifiables(networkUuid, variantNum, lineIds, LINE_TABLE); + deleteTemporaryLimits(networkUuid, variantNum, lineIds); + deletePermanentLimits(networkUuid, variantNum, lineIds); } // Hvdc line @@ -1555,8 +1565,8 @@ public void updateHvdcLines(UUID networkUuid, List> updateIdentifiables(networkUuid, resources, mappings.getHvdcLineMappings()); } - public void deleteHvdcLine(UUID networkUuid, int variantNum, String hvdcLineId) { - deleteIdentifiable(networkUuid, variantNum, hvdcLineId, HVDC_LINE_TABLE); + public void deleteHvdcLines(UUID networkUuid, int variantNum, List hvdcLineIds) { + deleteIdentifiables(networkUuid, variantNum, hvdcLineIds, HVDC_LINE_TABLE); } // Dangling line @@ -1595,10 +1605,10 @@ public List> getVoltageLevelDanglingLines(UUID return danglingLines; } - public void deleteDanglingLine(UUID networkUuid, int variantNum, String danglingLineId) { - deleteIdentifiable(networkUuid, variantNum, danglingLineId, DANGLING_LINE_TABLE); - deleteTemporaryLimits(networkUuid, variantNum, danglingLineId); - deletePermanentLimits(networkUuid, variantNum, danglingLineId); + public void deleteDanglingLines(UUID networkUuid, int variantNum, List danglingLineIds) { + deleteIdentifiables(networkUuid, variantNum, danglingLineIds, DANGLING_LINE_TABLE); + deleteTemporaryLimits(networkUuid, variantNum, danglingLineIds); + deletePermanentLimits(networkUuid, variantNum, danglingLineIds); } public void updateDanglingLines(UUID networkUuid, List> resources) { @@ -1639,8 +1649,8 @@ public void updateGrounds(UUID networkUuid, List> res updateIdentifiables(networkUuid, resources, mappings.getGroundMappings(), VOLTAGE_LEVEL_ID_COLUMN); } - public void deleteGround(UUID networkUuid, int variantNum, String groundId) { - deleteIdentifiable(networkUuid, variantNum, groundId, GROUND_TABLE); + public void deleteGrounds(UUID networkUuid, int variantNum, List groundIds) { + deleteIdentifiables(networkUuid, variantNum, groundIds, GROUND_TABLE); } // Tie lines @@ -1657,10 +1667,10 @@ public void createTieLines(UUID networkUuid, List> r createIdentifiables(networkUuid, resources, mappings.getTieLineMappings()); } - public void deleteTieLine(UUID networkUuid, int variantNum, String tieLineId) { - deleteIdentifiable(networkUuid, variantNum, tieLineId, TIE_LINE_TABLE); - deleteTemporaryLimits(networkUuid, variantNum, tieLineId); - deletePermanentLimits(networkUuid, variantNum, tieLineId); + public void deleteTieLines(UUID networkUuid, int variantNum, List tieLineIds) { + deleteIdentifiables(networkUuid, variantNum, tieLineIds, TIE_LINE_TABLE); + deleteTemporaryLimits(networkUuid, variantNum, tieLineIds); + deletePermanentLimits(networkUuid, variantNum, tieLineIds); } public void updateTieLines(UUID networkUuid, List> resources) { @@ -1689,8 +1699,8 @@ public void updateBuses(UUID networkUuid, List updateIdentifiables(networkUuid, resources, mappings.getConfiguredBusMappings(), VOLTAGE_LEVEL_ID_COLUMN); } - public void deleteBus(UUID networkUuid, int variantNum, String configuredBusId) { - deleteIdentifiable(networkUuid, variantNum, configuredBusId, CONFIGURED_BUS_TABLE); + public void deleteBuses(UUID networkUuid, int variantNum, List configuredBusId) { + deleteIdentifiables(networkUuid, variantNum, configuredBusId, CONFIGURED_BUS_TABLE); } private static String getNonEmptyTable(ResultSet resultSet) throws SQLException { @@ -2026,14 +2036,6 @@ private void insertPermanentLimitInEquipment(T equipment getLimits(equipment, type, side, groupId).setPermanentLimit(permanentLimit.getValue()); } - private void deleteTemporaryLimits(UUID networkUuid, int variantNum, String equipmentId) { - deleteTemporaryLimits(networkUuid, variantNum, List.of(equipmentId)); - } - - private void deletePermanentLimits(UUID networkUuid, int variantNum, String equipmentId) { - deletePermanentLimits(networkUuid, variantNum, List.of(equipmentId)); - } - private void deleteTemporaryLimits(UUID networkUuid, int variantNum, List equipmentIds) { try (var connection = dataSource.getConnection()) { try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildDeleteTemporaryLimitsVariantEquipmentINQuery(equipmentIds.size()))) { @@ -2566,10 +2568,6 @@ private void insertReactiveCapabilityCurvePointI } } - private void deleteReactiveCapabilityCurvePoints(UUID networkUuid, int variantNum, String equipmentId) { - deleteReactiveCapabilityCurvePoints(networkUuid, variantNum, List.of(equipmentId)); - } - private void deleteReactiveCapabilityCurvePoints(UUID networkUuid, int variantNum, List equipmentIds) { try (var connection = dataSource.getConnection()) { try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildDeleteReactiveCapabilityCurvePointsVariantEquipmentINQuery(equipmentIds.size()))) { @@ -2821,10 +2819,6 @@ void insertTapChangerStepInEquipment(T tapChangerParent, TapChangerStepAttribute } } - private void deleteTapChangerSteps(UUID networkUuid, int variantNum, String equipmentId) { - deleteTapChangerSteps(networkUuid, variantNum, List.of(equipmentId)); - } - private void deleteTapChangerSteps(UUID networkUuid, int variantNum, List equipmentIds) { try (var connection = dataSource.getConnection()) { try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildDeleteTapChangerStepVariantEquipmentINQuery(equipmentIds.size()))) { diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java index 3aae2301..74132768 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java @@ -96,12 +96,16 @@ public static String buildGetIdentifiablesInContainerQuery(String tableName, Col return sql.toString(); } - public static String buildDeleteIdentifiableQuery(String tableName) { - return "delete from " + - tableName + - " where " + NETWORK_UUID_COLUMN + " = ?" + - " and " + VARIANT_NUM_COLUMN + " = ?" + - " and " + ID_COLUMN + " = ?"; + public static String buildDeleteIdentifiablesQuery(String tableName, int numberOfValues) { + if (numberOfValues < 1) { + throw new IllegalArgumentException(MINIMAL_VALUE_REQUIREMENT_ERROR); + } + + return "delete from " + tableName + " where " + + NETWORK_UUID_COLUMN + " = ? and " + + VARIANT_NUM_COLUMN + " = ? and " + + ID_COLUMN + " in (" + + "?, ".repeat(numberOfValues - 1) + "?)"; } public static String buildDeleteNetworkQuery() { diff --git a/network-store-server/src/test/java/com/powsybl/network/store/server/NetworkStoreControllerIT.java b/network-store-server/src/test/java/com/powsybl/network/store/server/NetworkStoreControllerIT.java index a85adc72..040fa2bd 100644 --- a/network-store-server/src/test/java/com/powsybl/network/store/server/NetworkStoreControllerIT.java +++ b/network-store-server/src/test/java/com/powsybl/network/store/server/NetworkStoreControllerIT.java @@ -271,9 +271,7 @@ void test() throws Exception { .andExpect(jsonPath("data[0].attributes.calculatedBusesForBusView[0].vertices[0].node").value(13)) .andExpect(jsonPath("data[0].attributes.calculatedBusesForBusView[0].vertices[0].side").value("TWO")); - mvc.perform(delete("/" + VERSION + "/networks/" + NETWORK_UUID + "/" + Resource.INITIAL_VARIANT_NUM + "/switches/b1") - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()); + deleteIdentifiables(List.of("bar"), "switches"); // switch creation and update Resource resBreaker = Resource.switchBuilder() @@ -637,9 +635,7 @@ void test() throws Exception { .andExpect(jsonPath("data[0].attributes.p").value("310.0")) .andExpect(jsonPath("data[0].attributes.q").value("120.0")); - mvc.perform(delete("/" + VERSION + "/networks/" + NETWORK_UUID + "/" + Resource.INITIAL_VARIANT_NUM + "/batteries/battery1") - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()); + deleteIdentifiables(List.of("battery1"), "batteries"); // shunt compensator creation and update Resource shuntCompensator = Resource.shuntCompensatorBuilder() @@ -850,17 +846,9 @@ void test() throws Exception { .andExpect(jsonPath("data[0].attributes.node").value(6)); // Test removals - mvc.perform(delete("/" + VERSION + "/networks/" + NETWORK_UUID + "/" + Resource.INITIAL_VARIANT_NUM + "/switches/b1") - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()); - - mvc.perform(delete("/" + VERSION + "/networks/" + NETWORK_UUID + "/" + Resource.INITIAL_VARIANT_NUM + "/voltage-levels/baz") - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()); - - mvc.perform(delete("/" + VERSION + "/networks/" + NETWORK_UUID + "/" + Resource.INITIAL_VARIANT_NUM + "/substations/bar") - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()); + deleteIdentifiables(List.of("b1"), "switches"); + deleteIdentifiables(List.of("baz"), "voltage-levels"); + deleteIdentifiables(List.of("bar"), "substations"); // tie line creation and update Resource tieLine = Resource.tieLineBuilder() @@ -887,9 +875,7 @@ void test() throws Exception { .content(objectMapper.writeValueAsString(Collections.singleton(tieLine)))) .andExpect(status().isOk()); - mvc.perform(delete("/" + VERSION + "/networks/" + NETWORK_UUID + "/" + Resource.INITIAL_VARIANT_NUM + "/tie-lines/idTieLine") - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()); + deleteIdentifiables(List.of("idTieLine"), "tie-lines"); } @Test @@ -1199,4 +1185,426 @@ GeneratorStartup.NAME, new GeneratorStartupAttributes(10, 23, 7, 9, 10) .content(objectMapper.writeValueAsString(Collections.singleton(generator2)))) .andExpect(status().isCreated()); } + + @Test + void testDeleteIdentifiables() throws Exception { + Resource foo = Resource.networkBuilder() + .id("foo") + .attributes(NetworkAttributes.builder() + .uuid(NETWORK_UUID) + .variantId(String.valueOf(Resource.INITIAL_VARIANT_NUM)) + .caseDate(ZonedDateTime.parse("2015-01-01T00:00:00.000Z")) + .build()) + .build(); + mvc.perform(post("/" + VERSION + "/networks") + .contentType(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(Collections.singleton(foo)))) + .andExpect(status().isCreated()); + + Resource vl1 = Resource.voltageLevelBuilder() + .id("vl1") + .attributes(VoltageLevelAttributes.builder() + .nominalV(382) + .lowVoltageLimit(362) + .highVoltageLimit(402) + .topologyKind(TopologyKind.NODE_BREAKER) + .internalConnections(Collections.emptyList()) + .build()) + .build(); + createIdentifiable(vl1, "voltage-levels"); + + // substations + Resource sub1 = Resource.substationBuilder().id("sub1") + .attributes(SubstationAttributes.builder() + .country(Country.FR) + .tso("RTE") + .entsoeArea(EntsoeAreaAttributes.builder().code("D7").build()) + .build()) + .build(); + createIdentifiable(sub1, "substations"); + + Resource sub2 = Resource.substationBuilder().id("sub2") + .attributes(SubstationAttributes.builder() + .country(Country.FR) + .tso("RTE") + .entsoeArea(EntsoeAreaAttributes.builder().code("D7").build()) + .build()) + .build(); + createIdentifiable(sub2, "substations"); + + deleteIdentifiables(List.of("sub1", "sub2"), "substations"); + + // voltage levels + Resource vl11 = Resource.voltageLevelBuilder() + .id("vl11") + .attributes(VoltageLevelAttributes.builder() + .nominalV(382) + .lowVoltageLimit(362) + .highVoltageLimit(402) + .topologyKind(TopologyKind.NODE_BREAKER) + .internalConnections(Collections.emptyList()) + .build()) + .build(); + createIdentifiable(vl11, "voltage-levels"); + + Resource vl12 = Resource.voltageLevelBuilder() + .id("vl12") + .attributes(VoltageLevelAttributes.builder() + .nominalV(382) + .lowVoltageLimit(362) + .highVoltageLimit(402) + .topologyKind(TopologyKind.NODE_BREAKER) + .internalConnections(Collections.emptyList()) + .build()) + .build(); + createIdentifiable(vl12, "voltage-levels"); + + deleteIdentifiables(List.of("vl11", "vl12"), "voltage-levels"); + + // generators + Resource generator1 = Resource.generatorBuilder() + .id("gen1") + .attributes(GeneratorAttributes.builder() + .voltageLevelId("vl1") + .name("gen1") + .energySource(EnergySource.HYDRO) + .reactiveLimits(MinMaxReactiveLimitsAttributes.builder().maxQ(10).minQ(10).build()).build()) + .build(); + createIdentifiable(generator1, "generators"); + + Resource generator2 = Resource.generatorBuilder() + .id("gen2") + .attributes(GeneratorAttributes.builder() + .voltageLevelId("vl1") + .name("gen1") + .energySource(EnergySource.HYDRO) + .reactiveLimits(MinMaxReactiveLimitsAttributes.builder().maxQ(10).minQ(10).build()) + .build()) + .build(); + createIdentifiable(generator2, "generators"); + + // switches + Resource switch1 = Resource.switchBuilder() + .id("b1") + .attributes(SwitchAttributes.builder() + .voltageLevelId("vl1") + .kind(SwitchKind.BREAKER) + .node1(1) + .node2(2) + .open(false) + .retained(false) + .fictitious(false) + .build()) + .build(); + createIdentifiable(switch1, "switches"); + + Resource switch2 = Resource.switchBuilder() + .id("b2") + .attributes(SwitchAttributes.builder() + .voltageLevelId("vl1") + .kind(SwitchKind.BREAKER) + .node1(1) + .node2(2) + .open(false) + .retained(false) + .fictitious(false) + .build()) + .build(); + createIdentifiable(switch2, "switches"); + deleteIdentifiables(List.of("b1", "b2"), "switches"); + + // lines + Resource line1 = Resource.lineBuilder() + .id("line1") + .attributes(LineAttributes.builder() + .voltageLevelId1("vl1") + .voltageLevelId2("vl2") + .build()) + .build(); + createIdentifiable(line1, "lines"); + + Resource line2 = Resource.lineBuilder() + .id("line2") + .attributes(LineAttributes.builder() + .voltageLevelId1("vl1") + .voltageLevelId2("vl2") + .build()) + .build(); + createIdentifiable(line2, "lines"); + + deleteIdentifiables(List.of("line1", "line2"), "lines"); + + // batteries + Resource battery1 = Resource.batteryBuilder() + .id("bat1") + .attributes(BatteryAttributes.builder() + .voltageLevelId("vl1") + .name("battery1") + .targetP(250) + .targetQ(100) + .maxP(500) + .minP(100) + .reactiveLimits(MinMaxReactiveLimitsAttributes.builder().maxQ(10).minQ(10).build()) + .build()) + .build(); + createIdentifiable(battery1, "batteries"); + + Resource battery2 = Resource.batteryBuilder() + .id("bat2") + .attributes(BatteryAttributes.builder() + .voltageLevelId("vl1") + .name("battery1") + .targetP(250) + .targetQ(100) + .maxP(500) + .minP(100) + .reactiveLimits(MinMaxReactiveLimitsAttributes.builder().maxQ(10).minQ(10).build()) + .build()) + .build(); + createIdentifiable(battery2, "batteries"); + + deleteIdentifiables(List.of("bat1", "bat2"), "batteries"); + + // shunt-compensators + Resource shuntCompensator1 = Resource.shuntCompensatorBuilder() + .id("idShunt1") + .attributes(ShuntCompensatorAttributes.builder() + .voltageLevelId("vl1") + .name("shunt1") + .model(ShuntCompensatorLinearModelAttributes.builder().bPerSection(1).gPerSection(2).maximumSectionCount(3).build()) + .p(100.) + .build()) + .build(); + createIdentifiable(shuntCompensator1, "shunt-compensators"); + + Resource shuntCompensator2 = Resource.shuntCompensatorBuilder() + .id("idShunt2") + .attributes(ShuntCompensatorAttributes.builder() + .voltageLevelId("vl1") + .name("shunt1") + .model(ShuntCompensatorLinearModelAttributes.builder().bPerSection(1).gPerSection(2).maximumSectionCount(3).build()) + .p(100.) + .build()) + .build(); + createIdentifiable(shuntCompensator2, "shunt-compensators"); + + deleteIdentifiables(List.of("idShunt2", "idShunt1"), "shunt-compensators"); + + Resource danglingLine1 = Resource.danglingLineBuilder() + .id("idDanglingLine1") + .attributes(DanglingLineAttributes.builder() + .voltageLevelId("vl1") + .name("dl1") + .build()) + .build(); + createIdentifiable(danglingLine1, "dangling-lines"); + + Resource danglingLine2 = Resource.danglingLineBuilder() + .id("idDanglingLine2") + .attributes(DanglingLineAttributes.builder() + .voltageLevelId("vl1") + .name("dl1") + .build()) + .build(); + createIdentifiable(danglingLine2, "dangling-lines"); + + deleteIdentifiables(List.of("idDanglingLine1", "idDanglingLine2"), "dangling-lines"); + + // grounds + Resource ground1 = Resource.groundBuilder() + .id("idGround1") + .attributes(GroundAttributes.builder() + .voltageLevelId("vl1") + .name("ground1") + .build()) + .build(); + createIdentifiable(ground1, "grounds"); + + Resource ground2 = Resource.groundBuilder() + .id("idGround2") + .attributes(GroundAttributes.builder() + .voltageLevelId("vl1") + .name("ground1") + .build()) + .build(); + createIdentifiable(ground2, "grounds"); + + deleteIdentifiables(List.of("idGround2", "idGround1"), "grounds"); + + // tie-lines + Resource tieLine1 = Resource.tieLineBuilder() + .id("idTieLine1") + .attributes(TieLineAttributes.builder().name("TieLine").fictitious(false).danglingLine1Id("half1").danglingLine2Id("half2") + .build()) + .build(); + createIdentifiable(tieLine1, "tie-lines"); + + Resource tieLine2 = Resource.tieLineBuilder() + .id("idTieLine2") + .attributes(TieLineAttributes.builder().name("TieLine").fictitious(false).danglingLine1Id("half1").danglingLine2Id("half2") + .build()) + .build(); + createIdentifiable(tieLine2, "tie-lines"); + + deleteIdentifiables(List.of("idTieLine1", "idTieLine2"), "tie-lines"); + + // vsc converter stations + Resource vsc1 = Resource.vscConverterStationBuilder() + .id("vsc1") + .attributes(VscConverterStationAttributes.builder().name("vsc1").build()) + .build(); + createIdentifiable(vsc1, "vsc-converter-stations"); + + Resource vsc2 = Resource.vscConverterStationBuilder() + .id("vsc2") + .attributes(VscConverterStationAttributes.builder().name("vsc2").build()) + .build(); + createIdentifiable(vsc2, "vsc-converter-stations"); + + deleteIdentifiables(List.of("vsc1", "vsc2"), "vsc-converter-stations"); + + // lcc converter stations + Resource lcc1 = Resource.lccConverterStationBuilder() + .id("lcc1") + .attributes(LccConverterStationAttributes.builder().name("lcc1").build()) + .build(); + createIdentifiable(lcc1, "lcc-converter-stations"); + + Resource lcc2 = Resource.lccConverterStationBuilder() + .id("lcc2") + .attributes(LccConverterStationAttributes.builder().name("lcc2").build()) + .build(); + createIdentifiable(lcc2, "lcc-converter-stations"); + + deleteIdentifiables(List.of("lcc1", "lcc2"), "lcc-converter-stations"); + + //HVDC + Resource hvdc1 = Resource.hvdcLineBuilder() + .id("hvdc1") + .attributes(HvdcLineAttributes.builder().name("hvdc1").build()) + .build(); + createIdentifiable(hvdc1, "hvdc-lines"); + + Resource hvdc2 = Resource.hvdcLineBuilder() + .id("hvdc2") + .attributes(HvdcLineAttributes.builder().name("hvdc2").build()) + .build(); + createIdentifiable(hvdc2, "hvdc-lines"); + + deleteIdentifiables(List.of("hvdc1", "hvdc2"), "hvdc-lines"); + + // loads + Resource load1 = Resource.loadBuilder() + .id("load1") + .attributes(LoadAttributes.builder().name("load1").build()) + .build(); + createIdentifiable(load1, "loads"); + + Resource load2 = Resource.loadBuilder() + .id("load2") + .attributes(LoadAttributes.builder().name("load2").build()) + .build(); + createIdentifiable(load2, "loads"); + + deleteIdentifiables(List.of("load1", "load2"), "loads"); + + // static var compensators + Resource svc1 = Resource.staticVarCompensatorBuilder() + .id("svc1") + .attributes(StaticVarCompensatorAttributes.builder().name("svc1").build()) + .build(); + createIdentifiable(svc1, "static-var-compensators"); + + Resource svc2 = Resource.staticVarCompensatorBuilder() + .id("svc2") + .attributes(StaticVarCompensatorAttributes.builder().name("svc2").build()) + .build(); + createIdentifiable(svc2, "static-var-compensators"); + + deleteIdentifiables(List.of("svc1", "svc2"), "static-var-compensators"); + + // 2 windings transformers + Resource twoWT1 = Resource.twoWindingsTransformerBuilder() + .id("TwoWT1") + .attributes(TwoWindingsTransformerAttributes.builder().name("TwoWT1").build()) + .build(); + createIdentifiable(twoWT1, "2-windings-transformers"); + + Resource twoWT2 = Resource.twoWindingsTransformerBuilder() + .id("TwoWT2") + .attributes(TwoWindingsTransformerAttributes.builder().name("TwoWT2").build()) + .build(); + createIdentifiable(twoWT2, "2-windings-transformers"); + + deleteIdentifiables(List.of("TwoWT1", "TwoWT2"), "2-windings-transformers"); + + // 3 windings transformers + Resource threeWT1 = Resource.threeWindingsTransformerBuilder() + .id("ThreeWT1") + .attributes(ThreeWindingsTransformerAttributes.builder() + .name("ThreeWT1") + .leg1(LegAttributes.builder().voltageLevelId("baz").build()) + .leg2(LegAttributes.builder().voltageLevelId("baz").build()) + .leg3(LegAttributes.builder().voltageLevelId("baz").build()) + .build()) + .build(); + createIdentifiable(threeWT1, "3-windings-transformers"); + + Resource threeWT2 = Resource.threeWindingsTransformerBuilder() + .id("ThreeWT2") + .attributes(ThreeWindingsTransformerAttributes.builder() + .name("ThreeWT2") + .leg1(LegAttributes.builder().voltageLevelId("baz").build()) + .leg2(LegAttributes.builder().voltageLevelId("baz").build()) + .leg3(LegAttributes.builder().voltageLevelId("baz").build()) + .build()) + .build(); + createIdentifiable(threeWT2, "3-windings-transformers"); + + deleteIdentifiables(List.of("ThreeWT2", "ThreeWT1"), "3-windings-transformers"); + + // busbar sections + Resource busBar1 = Resource.busbarSectionBuilder() + .id("busBar1") + .attributes(BusbarSectionAttributes.builder().name("busBar1").build()) + .build(); + createIdentifiable(busBar1, "busbar-sections"); + + Resource busBar2 = Resource.busbarSectionBuilder() + .id("busBar2") + .attributes(BusbarSectionAttributes.builder().name("busBar2").build()) + .build(); + createIdentifiable(busBar2, "busbar-sections"); + + deleteIdentifiables(List.of("busBar2", "busBar1"), "busbar-sections"); + + // configured buses + Resource bus1 = Resource.configuredBusBuilder() + .id("bus1") + .attributes(ConfiguredBusAttributes.builder().name("bus1").build()) + .build(); + createIdentifiable(bus1, "configured-buses"); + + Resource bus2 = Resource.configuredBusBuilder() + .id("bus2") + .attributes(ConfiguredBusAttributes.builder().name("bus2").build()) + .build(); + createIdentifiable(bus2, "configured-buses"); + + deleteIdentifiables(List.of("bus1", "bus2"), "configured-buses"); + } + + private void createIdentifiable(Resource resource, String identifiableType) throws Exception { + mvc.perform(post("/" + VERSION + "/networks/" + NETWORK_UUID + "/" + identifiableType) + .contentType(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(Collections.singleton(resource)))) + .andExpect(status().isCreated()); + } + + private void deleteIdentifiables(List ids, String identifiableType) throws Exception { + mvc.perform(delete("/" + VERSION + "/networks/" + NETWORK_UUID + "/" + Resource.INITIAL_VARIANT_NUM + "/" + identifiableType) + .contentType(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(ids))) + .andExpect(status().isOk()); + } } diff --git a/network-store-server/src/test/java/com/powsybl/network/store/server/NetworkStoreRepositoryTest.java b/network-store-server/src/test/java/com/powsybl/network/store/server/NetworkStoreRepositoryTest.java index f229725c..1f95c837 100644 --- a/network-store-server/src/test/java/com/powsybl/network/store/server/NetworkStoreRepositoryTest.java +++ b/network-store-server/src/test/java/com/powsybl/network/store/server/NetworkStoreRepositoryTest.java @@ -785,8 +785,8 @@ void test() { List identifiablesIds = networkStoreRepository.getIdentifiablesIds(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM); assertEquals(List.of(loadId, lineId), identifiablesIds); - networkStoreRepository.deleteLoad(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, loadId); - networkStoreRepository.deleteLine(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, lineId); + networkStoreRepository.deleteLoads(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, List.of(loadId)); + networkStoreRepository.deleteLines(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, List.of(lineId)); assertTrue(networkStoreRepository.getLoad(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, loadId).isEmpty()); assertTrue(networkStoreRepository.getLine(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, lineId).isEmpty()); } @@ -870,8 +870,8 @@ void testRegulatingPointForGenerator() { assertEquals(ResourceType.GENERATOR, loadResult.get().getAttributes().getRegulatingEquipments().get(generatorId)); // delete - networkStoreRepository.deleteGenerator(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, generatorId); - networkStoreRepository.deleteLoad(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, loadId); + networkStoreRepository.deleteGenerators(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, List.of(generatorId)); + networkStoreRepository.deleteLoads(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, List.of(loadId)); assertTrue(networkStoreRepository.getLoad(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, loadId).isEmpty()); assertTrue(networkStoreRepository.getGenerator(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, generatorId).isEmpty()); } @@ -955,8 +955,8 @@ void testRegulatingPointForShuntCompensator() { assertEquals(ResourceType.SHUNT_COMPENSATOR, loadResult.get().getAttributes().getRegulatingEquipments().get(shuntCompensatorId)); // delete - networkStoreRepository.deleteShuntCompensator(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, shuntCompensatorId); - networkStoreRepository.deleteLoad(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, loadId); + networkStoreRepository.deleteShuntCompensators(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, List.of(shuntCompensatorId)); + networkStoreRepository.deleteLoads(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, List.of(loadId)); assertTrue(networkStoreRepository.getLoad(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, loadId).isEmpty()); assertTrue(networkStoreRepository.getShuntCompensator(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, shuntCompensatorId).isEmpty()); } @@ -1042,8 +1042,8 @@ void testRegulatingPointForStaticVarCompensator() { assertEquals(ResourceType.STATIC_VAR_COMPENSATOR, loadResult.get().getAttributes().getRegulatingEquipments().get(staticVarCompensatorId)); // delete - networkStoreRepository.deleteStaticVarCompensator(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, staticVarCompensatorId); - networkStoreRepository.deleteLoad(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, loadId); + networkStoreRepository.deleteStaticVarCompensators(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, List.of(staticVarCompensatorId)); + networkStoreRepository.deleteLoads(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, List.of(loadId)); assertTrue(networkStoreRepository.getLoad(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, loadId).isEmpty()); assertTrue(networkStoreRepository.getStaticVarCompensator(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, staticVarCompensatorId).isEmpty()); } @@ -1127,8 +1127,8 @@ void testRegulatingPointForVSC() { assertEquals(ResourceType.VSC_CONVERTER_STATION, loadResult.get().getAttributes().getRegulatingEquipments().get(vscId)); // delete - networkStoreRepository.deleteVscConverterStation(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, vscId); - networkStoreRepository.deleteLoad(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, loadId); + networkStoreRepository.deleteVscConverterStations(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, List.of(vscId)); + networkStoreRepository.deleteLoads(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, List.of(loadId)); assertTrue(networkStoreRepository.getLoad(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, loadId).isEmpty()); assertTrue(networkStoreRepository.getVscConverterStation(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, vscId).isEmpty()); }