diff --git a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java index 7ca93c0a4..b6cdf2e6f 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java @@ -39,6 +39,7 @@ public final class ModificationUtils { public static final String DISCONNECTOR = "disconnector_"; public static final String BREAKER = "breaker_"; + public static final String BUS_BAR_SECTION_ID = "busbarSectionId"; public static final String NO_VALUE = "No value"; private ModificationUtils() { @@ -235,6 +236,30 @@ public void controlVoltageLevelCreation(VoltageLevelCreationInfos voltageLevelCr } } + private boolean checkBbs(Network network, String busbarSectionId1, String busbarSectionId2, Reporter subReporter) { + Identifiable busOrBbs1 = network.getIdentifiable(busbarSectionId1); + Identifiable busOrBbs2 = network.getIdentifiable(busbarSectionId2); + if (busOrBbs1 == null) { + subReporter.report(Report.builder() + .withKey("notFoundBurOrBusbarSection") + .withDefaultMessage("Bus or busbar section ID ${busbarSectionId} not found. Coupler was not created.") + .withValue(BUS_BAR_SECTION_ID, busbarSectionId1) + .withSeverity(TypedValue.ERROR_SEVERITY) + .build()); + return false; + } + if (busOrBbs2 == null) { + subReporter.report(Report.builder() + .withKey("notFoundBurOrBusbarSection") + .withDefaultMessage("Bus or busbar section ID ${busbarSectionId} not found. Coupler was not created.") + .withValue(BUS_BAR_SECTION_ID, busbarSectionId2) + .withSeverity(TypedValue.ERROR_SEVERITY) + .build()); + return false; + } + return true; + } + void createVoltageLevel(VoltageLevelCreationInfos voltageLevelCreationInfos, Reporter subReporter, Network network) { String substationId = voltageLevelCreationInfos.getSubstationId(); @@ -280,6 +305,9 @@ void createVoltageLevel(VoltageLevelCreationInfos voltageLevelCreationInfos, .build().apply(network); voltageLevelCreationInfos.getCouplingDevices().forEach(couplingDevice -> { + if (!checkBbs(network, couplingDevice.getBusbarSectionId1(), couplingDevice.getBusbarSectionId2(), subReporter)) { + return; + } CreateCouplingDeviceBuilder couplingDeviceBuilder = new CreateCouplingDeviceBuilder(); couplingDeviceBuilder.withBusOrBusbarSectionId1(couplingDevice.getBusbarSectionId1()) .withBusOrBusbarSectionId2(couplingDevice.getBusbarSectionId2()) diff --git a/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelCreationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelCreationTest.java index 38e220078..256c6d528 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelCreationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelCreationTest.java @@ -58,7 +58,7 @@ protected ModificationInfos buildModificationUpdate() { .busbarCount(2) .sectionCount(2) .switchKinds(Arrays.asList(SwitchKind.BREAKER)) - .couplingDevices(Arrays.asList(CouplingDeviceInfos.builder().busbarSectionId1("bbs.nw").busbarSectionId2("bbs.ne").build())) + .couplingDevices(Arrays.asList(CouplingDeviceInfos.builder().busbarSectionId1("1A").busbarSectionId2("1.A").build())) .build(); } @@ -102,7 +102,8 @@ public void testCreateWithErrors() { vli.getErrorType().name(), reportService); vli = (VoltageLevelCreationInfos) buildModification(); - vli.getCouplingDevices().get(0).setBusbarSectionId1("bbs.ne"); + vli.getCouplingDevices().get(0).setBusbarSectionId1("1.1"); + vli.getCouplingDevices().get(0).setBusbarSectionId2("1.1"); String vliJsonObject = mapper.writeValueAsString(vli); mockMvc.perform(post(getNetworkModificationUri()).content(vliJsonObject).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); @@ -136,6 +137,27 @@ public void testCreateWithErrors() { vli.getErrorType().name(), reportService); } + @SneakyThrows + @Test + public void testCreateWithBbsNotExist() { + VoltageLevelCreationInfos vli = (VoltageLevelCreationInfos) buildModification(); + vli.setEquipmentId("vl_1"); + vli.getCouplingDevices().get(0).setBusbarSectionId1("1.1"); + vli.getCouplingDevices().get(0).setBusbarSectionId2("bbs"); + String vliJsonObject = mapper.writeValueAsString(vli); + mockMvc.perform(post(getNetworkModificationUri()).content(vliJsonObject).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertNotNull(getNetwork().getVoltageLevel("vl_1")); + + vli.setEquipmentId("vl_2"); + vli.getCouplingDevices().get(0).setBusbarSectionId1("bbs"); + vli.getCouplingDevices().get(0).setBusbarSectionId2("1.1"); + String vliJsonObject2 = mapper.writeValueAsString(vli); + mockMvc.perform(post(getNetworkModificationUri()).content(vliJsonObject2).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertNotNull(getNetwork().getVoltageLevel("vl_2")); + } + @SneakyThrows @Test public void testCreateWithShortCircuitExtension() { diff --git a/src/test/java/org/gridsuite/modification/server/utils/ModificationCreation.java b/src/test/java/org/gridsuite/modification/server/utils/ModificationCreation.java index 984e90c39..a4921ffb9 100644 --- a/src/test/java/org/gridsuite/modification/server/utils/ModificationCreation.java +++ b/src/test/java/org/gridsuite/modification/server/utils/ModificationCreation.java @@ -34,8 +34,7 @@ public static VoltageLevelCreationInfos getCreationVoltageLevel(String substatio .busbarCount(2) .sectionCount(2) .switchKinds(Arrays.asList(SwitchKind.BREAKER)) - .couplingDevices(Arrays.asList(CouplingDeviceInfos.builder().busbarSectionId1("bbs.nw").busbarSectionId2("bbs.ne").build())) - .build(); + .couplingDevices(Arrays.asList(CouplingDeviceInfos.builder().busbarSectionId1("1A").busbarSectionId2("1B").build())).build(); } public static GeneratorCreationInfos getCreationGenerator(String vlId, String generatorId, String generatorName, String busOrBusbarSectionId,