Skip to content

Commit 19c23c9

Browse files
authored
add isAllBusbars (#91)
Signed-off-by: Rehili Ghazwa <[email protected]>
1 parent ea98e98 commit 19c23c9

File tree

2 files changed

+61
-15
lines changed

2 files changed

+61
-15
lines changed

src/main/java/org/gridsuite/modification/modifications/CreateVoltageLevelSection.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,47 @@ public void apply(Network network, ReportNode subReportNode) {
7474
CreateVoltageLevelSections modification = new CreateVoltageLevelSectionsBuilder()
7575
.withReferenceBusbarSectionId(busbarSection.getId())
7676
.withCreateTheBusbarSectionsAfterTheReferenceBusbarSection(modificationInfos.isAfterBusbarSectionId())
77-
.withAllBusbars(false)
77+
.withAllBusbars(modificationInfos.isAllBusbars())
7878
.withLeftSwitchKind(modificationInfos.getLeftSwitchKind() != null ? SwitchKind.valueOf(modificationInfos.getLeftSwitchKind()) : SwitchKind.DISCONNECTOR)
7979
.withRightSwitchKind(modificationInfos.getRightSwitchKind() != null ? SwitchKind.valueOf(modificationInfos.getRightSwitchKind()) : SwitchKind.DISCONNECTOR)
8080
.withSwitchPrefixId(voltageLevel.getId())
8181
.withBusbarSectionPrefixId(voltageLevel.getId())
8282
.build();
8383
modification.apply(network, true, subReportNode);
8484

85-
BusbarSection newBusbarSection = null;
86-
for (BusbarSection bbs : voltageLevel.getNodeBreakerView().getBusbarSections()) {
87-
if (!busBarIds.contains(bbs.getId())) {
88-
newBusbarSection = bbs;
89-
break;
85+
if (modificationInfos.isAllBusbars()) {
86+
List<BusbarSection> newBusbarSections = new ArrayList<>();
87+
for (BusbarSection bbs : voltageLevel.getNodeBreakerView().getBusbarSections()) {
88+
if (!busBarIds.contains(bbs.getId())) {
89+
newBusbarSections.add(bbs);
90+
}
91+
}
92+
for (BusbarSection section : newBusbarSections) {
93+
subReportNode.newReportNode()
94+
.withMessageTemplate("network.modification.voltageLevel.sectionCreation")
95+
.withUntypedValue("sectionId", section.getId())
96+
.withUntypedValue("busbarIndex", section.getExtension(BusbarSectionPosition.class).getBusbarIndex())
97+
.withUntypedValue("sectionIndex", section.getExtension(BusbarSectionPosition.class).getSectionIndex())
98+
.withSeverity(TypedValue.INFO_SEVERITY)
99+
.add();
100+
}
101+
} else {
102+
BusbarSection newBusbarSection = null;
103+
for (BusbarSection bbs : voltageLevel.getNodeBreakerView().getBusbarSections()) {
104+
if (!busBarIds.contains(bbs.getId())) {
105+
newBusbarSection = bbs;
106+
break;
107+
}
108+
}
109+
if (newBusbarSection != null) {
110+
subReportNode.newReportNode()
111+
.withMessageTemplate("network.modification.voltageLevel.sectionCreation")
112+
.withUntypedValue("sectionId", newBusbarSection.getId())
113+
.withUntypedValue("busbarIndex", newBusbarSection.getExtension(BusbarSectionPosition.class).getBusbarIndex())
114+
.withUntypedValue("sectionIndex", newBusbarSection.getExtension(BusbarSectionPosition.class).getSectionIndex())
115+
.withSeverity(TypedValue.INFO_SEVERITY)
116+
.add();
90117
}
91-
}
92-
if (newBusbarSection != null) {
93-
subReportNode.newReportNode()
94-
.withMessageTemplate("network.modification.voltageLevel.sectionCreation")
95-
.withUntypedValue("sectionId", newBusbarSection.getId())
96-
.withUntypedValue("busbarIndex", newBusbarSection.getExtension(BusbarSectionPosition.class).getBusbarIndex())
97-
.withUntypedValue("sectionIndex", newBusbarSection.getExtension(BusbarSectionPosition.class).getSectionIndex())
98-
.withSeverity(TypedValue.INFO_SEVERITY)
99-
.add();
100118
}
101119
}
102120

src/test/java/org/gridsuite/modification/modifications/CreateVoltageLevelSectionTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.powsybl.commons.report.ReportNode;
1111
import com.powsybl.iidm.network.Network;
1212
import com.powsybl.iidm.network.Switch;
13+
import com.powsybl.iidm.network.VoltageLevel;
14+
import com.powsybl.iidm.network.extensions.BusbarSectionPositionAdder;
1315
import org.gridsuite.modification.NetworkModificationException;
1416
import org.gridsuite.modification.dto.CreateVoltageLevelSectionInfos;
1517
import org.gridsuite.modification.dto.ModificationInfos;
@@ -105,4 +107,30 @@ void testCreateSubReportNode() {
105107
modification.createSubReportNode(reportNode);
106108
assertLogMessage("Adding busbar section on v1", "network.modification.voltageLevel.section.created", reportNode);
107109
}
110+
111+
@Test
112+
void testCreateModificationWithAllBusbars() {
113+
Network network = getNetwork();
114+
VoltageLevel voltageLevel = network.getVoltageLevel("v1");
115+
var bbs = voltageLevel.getNodeBreakerView().newBusbarSection()
116+
.setId("bbs1_2")
117+
.setName("bbs1_2")
118+
.setNode(1)
119+
.add();
120+
bbs.newExtension(BusbarSectionPositionAdder.class).withBusbarIndex(1).withSectionIndex(0).add();
121+
CreateVoltageLevelSectionInfos.builder()
122+
.stashed(false)
123+
.voltageLevelId("v1")
124+
.busbarSectionId("bbs1_2")
125+
.busbarIndex(2)
126+
.isAfterBusbarSectionId(true)
127+
.leftSwitchKind("BREAKER")
128+
.rightSwitchKind("DISCONNECTOR")
129+
.isAllBusbars(true)
130+
.build().toModification().apply(network);
131+
List<String> busBarIds = new ArrayList<>();
132+
getNetwork().getBusbarSections().forEach(busbarSection -> busBarIds.add(busbarSection.getId()));
133+
assertEquals(7, busBarIds.size());
134+
assertTrue(busBarIds.containsAll(List.of("bbs1", "bbs2", "bbs3", "bbs4", "bbs1_2", "v1_0_1", "v1_1_1")));
135+
}
108136
}

0 commit comments

Comments
 (0)