Skip to content

Commit

Permalink
review code
Browse files Browse the repository at this point in the history
Signed-off-by: Seddik Yengui <[email protected]>
  • Loading branch information
Seddik Yengui committed Dec 26, 2024
1 parent a5d3055 commit 753066a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -832,13 +832,13 @@ public <T extends IdentifiableAttributes> void updateIdentifiables(UUID networkU
extensionHandler.updateExtensionsFromEquipments(networkUuid, resources);
}

public void deleteIdentifiableList(UUID networkUuid, int variantNum, List<String> ids, String tableName) {
public void deleteIdentifiables(UUID networkUuid, int variantNum, List<String> 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.buildDeleteIdentifiableListQuery(tableName, ids.size()))) {
try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildDeleteIdentifiablesQuery(tableName, ids.size()))) {
for (List<String> idsPartition : Lists.partition(ids, BATCH_SIZE)) {
preparedStmt.setObject(1, networkUuid);
preparedStmt.setInt(2, variantNum);
Expand Down Expand Up @@ -875,7 +875,7 @@ public void updateSubstations(UUID networkUuid, List<Resource<SubstationAttribut
}

public void deleteSubstations(UUID networkUuid, int variantNum, List<String> substationIds) {
deleteIdentifiableList(networkUuid, variantNum, substationIds, SUBSTATION_TABLE);
deleteIdentifiables(networkUuid, variantNum, substationIds, SUBSTATION_TABLE);
}

// voltage level
Expand Down Expand Up @@ -925,7 +925,7 @@ public List<Resource<VoltageLevelAttributes>> getVoltageLevels(UUID networkUuid,
}

public void deleteVoltageLevels(UUID networkUuid, int variantNum, List<String> voltageLevelIds) {
deleteIdentifiableList(networkUuid, variantNum, voltageLevelIds, VOLTAGE_LEVEL_TABLE);
deleteIdentifiables(networkUuid, variantNum, voltageLevelIds, VOLTAGE_LEVEL_TABLE);
}

// generator
Expand Down Expand Up @@ -986,7 +986,7 @@ public void updateGeneratorsSv(UUID networkUuid, List<Resource<InjectionSvAttrib
}

public void deleteGenerators(UUID networkUuid, int variantNum, List<String> generatorId) {
deleteIdentifiableList(networkUuid, variantNum, generatorId, GENERATOR_TABLE);
deleteIdentifiables(networkUuid, variantNum, generatorId, GENERATOR_TABLE);
deleteReactiveCapabilityCurvePoints(networkUuid, variantNum, generatorId);
deleteRegulatingPoints(networkUuid, variantNum, generatorId, ResourceType.GENERATOR);
}
Expand Down Expand Up @@ -1041,7 +1041,7 @@ public void updateBatteriesSv(UUID networkUuid, List<Resource<InjectionSvAttribu
}

public void deleteBatteries(UUID networkUuid, int variantNum, List<String> batteryIds) {
deleteIdentifiableList(networkUuid, variantNum, batteryIds, BATTERY_TABLE);
deleteIdentifiables(networkUuid, variantNum, batteryIds, BATTERY_TABLE);
deleteReactiveCapabilityCurvePoints(networkUuid, variantNum, batteryIds);
}

Expand Down Expand Up @@ -1076,7 +1076,7 @@ public void updateLoadsSv(UUID networkUuid, List<Resource<InjectionSvAttributes>
}

public void deleteLoads(UUID networkUuid, int variantNum, List<String> loadIds) {
deleteIdentifiableList(networkUuid, variantNum, loadIds, LOAD_TABLE);
deleteIdentifiables(networkUuid, variantNum, loadIds, LOAD_TABLE);
}

// shunt compensator
Expand Down Expand Up @@ -1119,7 +1119,7 @@ public void updateShuntCompensatorsSv(UUID networkUuid, List<Resource<InjectionS

public void deleteShuntCompensators(UUID networkUuid, int variantNum, List<String> shuntCompensatorIds) {
deleteRegulatingPoints(networkUuid, variantNum, shuntCompensatorIds, ResourceType.SHUNT_COMPENSATOR);
deleteIdentifiableList(networkUuid, variantNum, shuntCompensatorIds, SHUNT_COMPENSATOR_TABLE);
deleteIdentifiables(networkUuid, variantNum, shuntCompensatorIds, SHUNT_COMPENSATOR_TABLE);
}

// VSC converter station
Expand Down Expand Up @@ -1179,7 +1179,7 @@ public void updateVscConverterStationsSv(UUID networkUuid, List<Resource<Injecti
}

public void deleteVscConverterStations(UUID networkUuid, int variantNum, List<String> vscConverterStationIds) {
deleteIdentifiableList(networkUuid, variantNum, vscConverterStationIds, VSC_CONVERTER_STATION_TABLE);
deleteIdentifiables(networkUuid, variantNum, vscConverterStationIds, VSC_CONVERTER_STATION_TABLE);
deleteReactiveCapabilityCurvePoints(networkUuid, variantNum, vscConverterStationIds);
deleteRegulatingPoints(networkUuid, variantNum, vscConverterStationIds, ResourceType.VSC_CONVERTER_STATION);
}
Expand Down Expand Up @@ -1211,7 +1211,7 @@ public void updateLccConverterStationsSv(UUID networkUuid, List<Resource<Injecti
}

public void deleteLccConverterStations(UUID networkUuid, int variantNum, List<String> lccConverterStationIds) {
deleteIdentifiableList(networkUuid, variantNum, lccConverterStationIds, LCC_CONVERTER_STATION_TABLE);
deleteIdentifiables(networkUuid, variantNum, lccConverterStationIds, LCC_CONVERTER_STATION_TABLE);
}

// static var compensators
Expand Down Expand Up @@ -1254,7 +1254,7 @@ public void updateStaticVarCompensatorsSv(UUID networkUuid, List<Resource<Inject

public void deleteStaticVarCompensators(UUID networkUuid, int variantNum, List<String> staticVarCompensatorIds) {
deleteRegulatingPoints(networkUuid, variantNum, staticVarCompensatorIds, ResourceType.STATIC_VAR_COMPENSATOR);
deleteIdentifiableList(networkUuid, variantNum, staticVarCompensatorIds, STATIC_VAR_COMPENSATOR_TABLE);
deleteIdentifiables(networkUuid, variantNum, staticVarCompensatorIds, STATIC_VAR_COMPENSATOR_TABLE);
}

// busbar section
Expand Down Expand Up @@ -1284,7 +1284,7 @@ public List<Resource<BusbarSectionAttributes>> getVoltageLevelBusbarSections(UUI
}

public void deleteBusBarSections(UUID networkUuid, int variantNum, List<String> busBarSectionIds) {
deleteIdentifiableList(networkUuid, variantNum, busBarSectionIds, BUSBAR_SECTION_TABLE);
deleteIdentifiables(networkUuid, variantNum, busBarSectionIds, BUSBAR_SECTION_TABLE);
}

// switch
Expand All @@ -1310,7 +1310,7 @@ public void updateSwitches(UUID networkUuid, List<Resource<SwitchAttributes>> re
}

public void deleteSwitches(UUID networkUuid, int variantNum, List<String> switchIds) {
deleteIdentifiableList(networkUuid, variantNum, switchIds, SWITCH_TABLE);
deleteIdentifiables(networkUuid, variantNum, switchIds, SWITCH_TABLE);
}

// 2 windings transformer
Expand Down Expand Up @@ -1382,7 +1382,7 @@ public void updateTwoWindingsTransformersSv(UUID networkUuid, List<Resource<Bran
}

public void deleteTwoWindingsTransformers(UUID networkUuid, int variantNum, List<String> twoWindingsTransformerIds) {
deleteIdentifiableList(networkUuid, variantNum, twoWindingsTransformerIds, TWO_WINDINGS_TRANSFORMER_TABLE);
deleteIdentifiables(networkUuid, variantNum, twoWindingsTransformerIds, TWO_WINDINGS_TRANSFORMER_TABLE);
deleteTemporaryLimits(networkUuid, variantNum, twoWindingsTransformerIds);
deletePermanentLimits(networkUuid, variantNum, twoWindingsTransformerIds);
deleteTapChangerSteps(networkUuid, variantNum, twoWindingsTransformerIds);
Expand Down Expand Up @@ -1479,7 +1479,7 @@ public void updateThreeWindingsTransformersSv(UUID networkUuid, List<Resource<Th
}

public void deleteThreeWindingsTransformers(UUID networkUuid, int variantNum, List<String> threeWindingsTransformerIds) {
deleteIdentifiableList(networkUuid, variantNum, threeWindingsTransformerIds, THREE_WINDINGS_TRANSFORMER_TABLE);
deleteIdentifiables(networkUuid, variantNum, threeWindingsTransformerIds, THREE_WINDINGS_TRANSFORMER_TABLE);
deleteTemporaryLimits(networkUuid, variantNum, threeWindingsTransformerIds);
deletePermanentLimits(networkUuid, variantNum, threeWindingsTransformerIds);
deleteTapChangerSteps(networkUuid, variantNum, threeWindingsTransformerIds);
Expand Down Expand Up @@ -1542,7 +1542,7 @@ public void updateLinesSv(UUID networkUuid, List<Resource<BranchSvAttributes>> r
}

public void deleteLines(UUID networkUuid, int variantNum, List<String> lineIds) {
deleteIdentifiableList(networkUuid, variantNum, lineIds, LINE_TABLE);
deleteIdentifiables(networkUuid, variantNum, lineIds, LINE_TABLE);
deleteTemporaryLimits(networkUuid, variantNum, lineIds);
deletePermanentLimits(networkUuid, variantNum, lineIds);
}
Expand All @@ -1566,7 +1566,7 @@ public void updateHvdcLines(UUID networkUuid, List<Resource<HvdcLineAttributes>>
}

public void deleteHvdcLines(UUID networkUuid, int variantNum, List<String> hvdcLineIds) {
deleteIdentifiableList(networkUuid, variantNum, hvdcLineIds, HVDC_LINE_TABLE);
deleteIdentifiables(networkUuid, variantNum, hvdcLineIds, HVDC_LINE_TABLE);
}

// Dangling line
Expand Down Expand Up @@ -1606,7 +1606,7 @@ public List<Resource<DanglingLineAttributes>> getVoltageLevelDanglingLines(UUID
}

public void deleteDanglingLines(UUID networkUuid, int variantNum, List<String> danglingLineIds) {
deleteIdentifiableList(networkUuid, variantNum, danglingLineIds, DANGLING_LINE_TABLE);
deleteIdentifiables(networkUuid, variantNum, danglingLineIds, DANGLING_LINE_TABLE);
deleteTemporaryLimits(networkUuid, variantNum, danglingLineIds);
deletePermanentLimits(networkUuid, variantNum, danglingLineIds);
}
Expand Down Expand Up @@ -1650,7 +1650,7 @@ public void updateGrounds(UUID networkUuid, List<Resource<GroundAttributes>> res
}

public void deleteGrounds(UUID networkUuid, int variantNum, List<String> groundIds) {
deleteIdentifiableList(networkUuid, variantNum, groundIds, GROUND_TABLE);
deleteIdentifiables(networkUuid, variantNum, groundIds, GROUND_TABLE);
}

// Tie lines
Expand All @@ -1668,7 +1668,7 @@ public void createTieLines(UUID networkUuid, List<Resource<TieLineAttributes>> r
}

public void deleteTieLines(UUID networkUuid, int variantNum, List<String> tieLineIds) {
deleteIdentifiableList(networkUuid, variantNum, tieLineIds, TIE_LINE_TABLE);
deleteIdentifiables(networkUuid, variantNum, tieLineIds, TIE_LINE_TABLE);
deleteTemporaryLimits(networkUuid, variantNum, tieLineIds);
deletePermanentLimits(networkUuid, variantNum, tieLineIds);
}
Expand Down Expand Up @@ -1700,7 +1700,7 @@ public void updateBuses(UUID networkUuid, List<Resource<ConfiguredBusAttributes>
}

public void deleteBuses(UUID networkUuid, int variantNum, List<String> configuredBusId) {
deleteIdentifiableList(networkUuid, variantNum, configuredBusId, CONFIGURED_BUS_TABLE);
deleteIdentifiables(networkUuid, variantNum, configuredBusId, CONFIGURED_BUS_TABLE);
}

private static String getNonEmptyTable(ResultSet resultSet) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,7 @@ 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 buildDeleteIdentifiableListQuery(String tableName, int idCount) {
public static String buildDeleteIdentifiablesQuery(String tableName, int idCount) {
return "delete from " + tableName + " where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void test() throws Exception {
.build();
createIdentifiable(sub2, "substations");

deleteIdentifiableList(List.of("sub1", "sub2"), "substations");
deleteIdentifiables(List.of("sub1", "sub2"), "substations");

List<InternalConnectionAttributes> ics1 = new ArrayList<>();
ics1.add(InternalConnectionAttributes.builder()
Expand Down Expand Up @@ -317,10 +317,10 @@ void test() throws Exception {
.build();
createIdentifiable(vl2, "voltage-levels");

deleteIdentifiableList(List.of("vl1", "vl2"), "voltage-levels");
deleteIdentifiables(List.of("vl1", "vl2"), "voltage-levels");

// switch delete
deleteIdentifiableList(List.of("bar"), "switches");
deleteIdentifiables(List.of("bar"), "switches");

Resource<SwitchAttributes> switch1 = Resource.switchBuilder()
.id("b1")
Expand Down Expand Up @@ -349,7 +349,7 @@ void test() throws Exception {
.build())
.build();
createIdentifiable(switch2, "switches");
deleteIdentifiableList(List.of("b1", "b2"), "switches");
deleteIdentifiables(List.of("b1", "b2"), "switches");

// switch creation and update
Resource<SwitchAttributes> resBreaker = Resource.switchBuilder()
Expand Down Expand Up @@ -613,7 +613,7 @@ void test() throws Exception {
.build();
createIdentifiable(line2, "lines");

deleteIdentifiableList(List.of("line1", "line2"), "lines");
deleteIdentifiables(List.of("line1", "line2"), "lines");

// generator creation, update and delete
RegulatingPointAttributes regulatingPointAttributes = RegulatingPointAttributes.builder()
Expand Down Expand Up @@ -757,7 +757,7 @@ void test() throws Exception {
.andExpect(jsonPath("data[0].attributes.p").value("310.0"))
.andExpect(jsonPath("data[0].attributes.q").value("120.0"));

deleteIdentifiableList(List.of("battery1"), "batteries");
deleteIdentifiables(List.of("battery1"), "batteries");

Resource<BatteryAttributes> battery1 = Resource.batteryBuilder()
.id("bat1")
Expand Down Expand Up @@ -787,7 +787,7 @@ void test() throws Exception {
.build();
createIdentifiable(battery2, "batteries");

deleteIdentifiableList(List.of("bat1", "bat2"), "batteries");
deleteIdentifiables(List.of("bat1", "bat2"), "batteries");

// shunt compensator creation, update and delete
Resource<ShuntCompensatorAttributes> shuntCompensator = Resource.shuntCompensatorBuilder()
Expand Down Expand Up @@ -868,7 +868,7 @@ void test() throws Exception {
.build();
createIdentifiable(shuntCompensator2, "shunt-compensators");

deleteIdentifiableList(List.of("idShunt2", "idShunt1"), "shunt-compensators");
deleteIdentifiables(List.of("idShunt2", "idShunt1"), "shunt-compensators");

// dangling line creation, update and delete
Resource<DanglingLineAttributes> danglingLine = Resource.danglingLineBuilder()
Expand Down Expand Up @@ -1021,7 +1021,7 @@ void test() throws Exception {
.build();
createIdentifiable(danglingLine2, "dangling-lines");

deleteIdentifiableList(List.of("idDanglingLine1", "idDanglingLine2"), "dangling-lines");
deleteIdentifiables(List.of("idDanglingLine1", "idDanglingLine2"), "dangling-lines");

// ground creation, update and delete
Resource<GroundAttributes> ground = Resource.groundBuilder()
Expand Down Expand Up @@ -1127,7 +1127,7 @@ void test() throws Exception {
.build();
createIdentifiable(ground2, "grounds");

deleteIdentifiableList(List.of("idGround2", "idGround1"), "grounds");
deleteIdentifiables(List.of("idGround2", "idGround1"), "grounds");

// tie line creation, update and delete
Resource<TieLineAttributes> tieLine = Resource.tieLineBuilder()
Expand Down Expand Up @@ -1168,7 +1168,7 @@ void test() throws Exception {
.build();
createIdentifiable(tieLine2, "tie-lines");

deleteIdentifiableList(List.of("idTieLine1", "idTieLine2"), "tie-lines");
deleteIdentifiables(List.of("idTieLine1", "idTieLine2"), "tie-lines");

// test batch removal
// VscConverterStation
Expand All @@ -1184,7 +1184,7 @@ void test() throws Exception {
.build();
createIdentifiable(vsc2, "vsc-converter-stations");

deleteIdentifiableList(List.of("vsc1", "vsc2"), "vsc-converter-stations");
deleteIdentifiables(List.of("vsc1", "vsc2"), "vsc-converter-stations");

// LccConverterStation
Resource<LccConverterStationAttributes> lcc1 = Resource.lccConverterStationBuilder()
Expand All @@ -1199,7 +1199,7 @@ void test() throws Exception {
.build();
createIdentifiable(lcc2, "lcc-converter-stations");

deleteIdentifiableList(List.of("lcc1", "lcc2"), "lcc-converter-stations");
deleteIdentifiables(List.of("lcc1", "lcc2"), "lcc-converter-stations");

//HVDC
Resource<HvdcLineAttributes> hvdc1 = Resource.hvdcLineBuilder()
Expand All @@ -1214,7 +1214,7 @@ void test() throws Exception {
.build();
createIdentifiable(hvdc2, "hvdc-lines");

deleteIdentifiableList(List.of("hvdc1", "hvdc2"), "hvdc-lines");
deleteIdentifiables(List.of("hvdc1", "hvdc2"), "hvdc-lines");

// load
Resource<LoadAttributes> load1 = Resource.loadBuilder()
Expand All @@ -1229,7 +1229,7 @@ void test() throws Exception {
.build();
createIdentifiable(load2, "loads");

deleteIdentifiableList(List.of("load1", "load2"), "loads");
deleteIdentifiables(List.of("load1", "load2"), "loads");

// StaticVarCompensator
Resource<StaticVarCompensatorAttributes> svc1 = Resource.staticVarCompensatorBuilder()
Expand All @@ -1244,7 +1244,7 @@ void test() throws Exception {
.build();
createIdentifiable(svc2, "static-var-compensators");

deleteIdentifiableList(List.of("svc1", "svc2"), "static-var-compensators");
deleteIdentifiables(List.of("svc1", "svc2"), "static-var-compensators");

// TwoWindingsTransformer
Resource<TwoWindingsTransformerAttributes> twoWT1 = Resource.twoWindingsTransformerBuilder()
Expand All @@ -1259,7 +1259,7 @@ void test() throws Exception {
.build();
createIdentifiable(twoWT2, "2-windings-transformers");

deleteIdentifiableList(List.of("TwoWT1", "TwoWT2"), "2-windings-transformers");
deleteIdentifiables(List.of("TwoWT1", "TwoWT2"), "2-windings-transformers");

// ThreeWindingsTransformer
Resource<ThreeWindingsTransformerAttributes> threeWT1 = Resource.threeWindingsTransformerBuilder()
Expand All @@ -1284,7 +1284,7 @@ void test() throws Exception {
.build();
createIdentifiable(threeWT2, "3-windings-transformers");

deleteIdentifiableList(List.of("ThreeWT2", "ThreeWT1"), "3-windings-transformers");
deleteIdentifiables(List.of("ThreeWT2", "ThreeWT1"), "3-windings-transformers");

// BusbarSection
Resource<BusbarSectionAttributes> busBar1 = Resource.busbarSectionBuilder()
Expand All @@ -1299,7 +1299,7 @@ void test() throws Exception {
.build();
createIdentifiable(busBar2, "busbar-sections");

deleteIdentifiableList(List.of("busBar2", "busBar1"), "busbar-sections");
deleteIdentifiables(List.of("busBar2", "busBar1"), "busbar-sections");

// ConfiguredBus
Resource<ConfiguredBusAttributes> bus1 = Resource.configuredBusBuilder()
Expand All @@ -1314,7 +1314,7 @@ void test() throws Exception {
.build();
createIdentifiable(bus2, "configured-buses");

deleteIdentifiableList(List.of("bus1", "bus2"), "configured-buses");
deleteIdentifiables(List.of("bus1", "bus2"), "configured-buses");
}

@Test
Expand Down Expand Up @@ -1632,7 +1632,7 @@ private void createIdentifiable(Resource<? extends AbstractIdentifiableAttribute
.andExpect(status().isCreated());
}

private void deleteIdentifiableList(List<String> ids, String identifiableType) throws Exception {
private void deleteIdentifiables(List<String> ids, String identifiableType) throws Exception {
mvc.perform(delete("/" + VERSION + "/networks/" + NETWORK_UUID + "/" + Resource.INITIAL_VARIANT_NUM + "/" + identifiableType)
.contentType(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(ids)))
Expand Down

0 comments on commit 753066a

Please sign in to comment.