Skip to content

Commit

Permalink
Add report for non-existent section ID (#260)
Browse files Browse the repository at this point in the history
* Add report for non-existent section ID
---------

Signed-off-by: TOURI ANIS <[email protected]>
  • Loading branch information
anistouri authored Jun 8, 2023
1 parent fb236d4 commit fef0dbd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fef0dbd

Please sign in to comment.