Skip to content

Commit 8493b5d

Browse files
Merge branch 'main' into send-all-limit-sets-to-branch-forms
2 parents ec069a2 + 6c7787c commit 8493b5d

22 files changed

+714
-469
lines changed

src/main/java/org/gridsuite/network/map/dto/definition/branch/BranchTabInfos.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import com.fasterxml.jackson.annotation.JsonInclude;
1010
import com.fasterxml.jackson.annotation.JsonInclude.Include;
11+
import com.powsybl.iidm.network.Country;
1112
import lombok.Getter;
1213
import lombok.experimental.SuperBuilder;
1314
import org.gridsuite.network.map.dto.ElementInfosWithProperties;
@@ -22,6 +23,8 @@
2223
@SuperBuilder
2324
@Getter
2425
public class BranchTabInfos extends ElementInfosWithProperties {
26+
private String type;
27+
2528
private String voltageLevelId1;
2629
private String voltageLevelId2;
2730

@@ -34,6 +37,18 @@ public class BranchTabInfos extends ElementInfosWithProperties {
3437
private Double nominalVoltage1;
3538
private Double nominalVoltage2;
3639

40+
@JsonInclude(Include.NON_NULL)
41+
private String substationId1;
42+
43+
@JsonInclude(Include.NON_NULL)
44+
private String substationId2;
45+
46+
@JsonInclude(Include.NON_NULL)
47+
private Country country1;
48+
49+
@JsonInclude(Include.NON_NULL)
50+
private Country country2;
51+
3752
private Boolean terminal1Connected;
3853
private Boolean terminal2Connected;
3954

@@ -94,6 +109,9 @@ public class BranchTabInfos extends ElementInfosWithProperties {
94109
@JsonInclude(Include.NON_NULL)
95110
private Map<String, String> voltageLevelProperties2;
96111

112+
@JsonInclude(JsonInclude.Include.NON_NULL)
113+
private String operatingStatus;
114+
97115
/* * * Extensions * * */
98116

99117
@JsonInclude(JsonInclude.Include.NON_ABSENT)

src/main/java/org/gridsuite/network/map/dto/definition/branch/line/LineTabInfos.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package org.gridsuite.network.map.dto.definition.branch.line;
88

99
import com.fasterxml.jackson.annotation.JsonInclude;
10-
import com.powsybl.iidm.network.Country;
1110
import lombok.Getter;
1211
import lombok.experimental.SuperBuilder;
1312
import org.gridsuite.network.map.dto.definition.branch.BranchTabInfos;
@@ -18,12 +17,6 @@
1817
@SuperBuilder
1918
@Getter
2019
public class LineTabInfos extends BranchTabInfos {
21-
@JsonInclude(JsonInclude.Include.NON_NULL)
22-
private Country country1;
23-
24-
@JsonInclude(JsonInclude.Include.NON_NULL)
25-
private Country country2;
26-
2720
@JsonInclude(JsonInclude.Include.NON_NULL)
2821
private Double g1;
2922

src/main/java/org/gridsuite/network/map/dto/definition/branch/twowindingstransformer/TwoWindingsTransformerTabInfos.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ public class TwoWindingsTransformerTabInfos extends BranchTabInfos {
4747
private ConnectablePositionInfos connectablePosition1;
4848
private ConnectablePositionInfos connectablePosition2;
4949

50-
@JsonInclude(JsonInclude.Include.NON_NULL)
51-
private String operatingStatus;
52-
5350
@JsonInclude(JsonInclude.Include.NON_ABSENT)
5451
private Optional<TapChangerDiscreteMeasurementsInfos> measurementRatioTap;
5552

src/main/java/org/gridsuite/network/map/dto/definition/voltagelevel/VoltageLevelFormInfos.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public class VoltageLevelFormInfos extends ElementInfosWithProperties {
5454
@JsonInclude(JsonInclude.Include.NON_NULL)
5555
private Boolean isRetrievedBusbarSections;
5656

57+
@JsonInclude(JsonInclude.Include.NON_NULL)
58+
private Boolean isBusbarSectionPositionFound;
59+
5760
@JsonInclude(JsonInclude.Include.NON_NULL)
5861
private Map<String, List<String>> busBarSectionInfos;
5962
}

src/main/java/org/gridsuite/network/map/dto/mapper/BranchInfosMapper.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static org.gridsuite.network.map.dto.InfoTypeParameters.QUERY_PARAM_DC_POWERFACTOR;
2929
import static org.gridsuite.network.map.dto.common.CurrentLimitsData.Applicability.SIDE1;
3030
import static org.gridsuite.network.map.dto.common.CurrentLimitsData.Applicability.SIDE2;
31+
import static org.gridsuite.network.map.dto.utils.ElementUtils.mapCountry;
3132
import static org.gridsuite.network.map.dto.utils.ExtensionUtils.buildQualityInfos;
3233

3334
public sealed class BranchInfosMapper permits LineInfosMapper, TieLineInfosMapper, TwoWindingsTransformerInfosMapper {
@@ -75,8 +76,13 @@ public static ElementInfos toData(@NonNull final Identifiable<?> identifiable,
7576
.selectedOperationalLimitsGroup2(branch.getSelectedOperationalLimitsGroupId2().orElse(null));
7677
//noinspection unchecked
7778
return (B) builder
79+
.type(branch.getType().name())
7880
.name(branch.getOptionalName().orElse(null))
7981
.id(branch.getId())
82+
.substationId1(terminal1.getVoltageLevel().getSubstation().map(Substation::getId).orElse(null))
83+
.substationId2(terminal2.getVoltageLevel().getSubstation().map(Substation::getId).orElse(null))
84+
.country1(mapCountry(terminal1.getVoltageLevel().getSubstation().orElse(null)))
85+
.country2(mapCountry(terminal2.getVoltageLevel().getSubstation().orElse(null)))
8086
.terminal1Connected(terminal1.isConnected())
8187
.terminal2Connected(terminal2.isConnected())
8288
.voltageLevelId1(terminal1.getVoltageLevel().getId())
@@ -96,7 +102,8 @@ public static ElementInfos toData(@NonNull final Identifiable<?> identifiable,
96102
.voltageLevelProperties2(ElementUtils.getProperties(terminal2.getVoltageLevel()))
97103
.substationProperties1(terminal1.getVoltageLevel().getSubstation().map(ElementUtils::getProperties).orElse(null))
98104
.substationProperties2(terminal2.getVoltageLevel().getSubstation().map(ElementUtils::getProperties).orElse(null))
99-
.branchObservability(toBranchObservability(branch));
105+
.branchObservability(toBranchObservability(branch))
106+
.operatingStatus(ExtensionUtils.toOperatingStatus(branch));
100107
}
101108

102109
private static BranchTabInfos toTabInfos(@NonNull final Branch<?> branch, @Nullable final Double dcPowerFactor) {

src/main/java/org/gridsuite/network/map/dto/mapper/LineInfosMapper.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ private static LineMapInfos toMapInfos(Identifiable<?> identifiable, Double dcPo
131131
private static LineTabInfos toTabInfos(Identifiable<?> identifiable, Double dcPowerFactor) {
132132
final Line line = (Line) identifiable;
133133
return toTabBuilder((LineTabInfosBuilder<LineTabInfos, ?>) LineTabInfos.builder(), line, dcPowerFactor)
134-
.country1(mapCountry(line.getTerminal1().getVoltageLevel().getSubstation().orElse(null)))
135-
.country2(mapCountry(line.getTerminal2().getVoltageLevel().getSubstation().orElse(null)))
136134
.g1(line.getG1())
137135
.b1(line.getB1())
138136
.g2(line.getG2())

src/main/java/org/gridsuite/network/map/dto/mapper/TwoWindingsTransformerInfosMapper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ private static TwoWindingsTransformerTabInfos toTabInfos(Identifiable<?> identif
113113
.ratedU1(twoWT.getRatedU1())
114114
.ratedU2(twoWT.getRatedU2())
115115
.ratedS(nullIfNan(twoWT.getRatedS()))
116-
.operatingStatus(ExtensionUtils.toOperatingStatus(twoWT))
117116
.connectablePosition1(ExtensionUtils.toMapConnectablePosition(twoWT, 1))
118117
.connectablePosition2(ExtensionUtils.toMapConnectablePosition(twoWT, 2))
119118
.measurementRatioTap(ExtensionUtils.toMeasurementTapChanger(twoWT, DiscreteMeasurement.Type.TAP_POSITION, TapChanger.RATIO_TAP_CHANGER))

src/main/java/org/gridsuite/network/map/dto/mapper/VoltageLevelInfosMapper.java

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import com.powsybl.iidm.network.*;
1010
import com.powsybl.iidm.network.extensions.BusbarSectionPosition;
11+
import lombok.Builder;
1112
import lombok.Getter;
1213
import lombok.Setter;
1314
import org.gridsuite.network.map.dto.ElementInfos;
@@ -42,41 +43,48 @@ public static ElementInfos toData(Identifiable<?> identifiable, InfoTypeParamete
4243
}
4344

4445
private static VoltageLevelTopologyInfos getTopologyInfos(VoltageLevel voltageLevel) {
45-
VoltageLevelTopologyInfos topologyInfos = new VoltageLevelTopologyInfos();
4646
Map<Integer, Integer> nbSectionsPerBusbar = new HashMap<>();
4747
List<BusBarSectionFormInfos> busbarSectionInfos = new ArrayList<>();
48+
int maxBusbarIndex = 1;
49+
int maxSectionIndex = 1;
50+
boolean busbarSectionPositionFound = true;
4851
for (BusbarSection bbs : voltageLevel.getNodeBreakerView().getBusbarSections()) {
4952
var extension = bbs.getExtension(BusbarSectionPosition.class);
50-
if (extension != null) {
51-
if (extension.getBusbarIndex() > topologyInfos.getBusbarCount()) {
52-
topologyInfos.setBusbarCount(extension.getBusbarIndex());
53-
}
54-
if (extension.getSectionIndex() > topologyInfos.getSectionCount()) {
55-
topologyInfos.setSectionCount(extension.getSectionIndex());
56-
}
57-
nbSectionsPerBusbar.putIfAbsent(extension.getBusbarIndex(), 1);
58-
if (extension.getSectionIndex() > nbSectionsPerBusbar.get(extension.getBusbarIndex())) {
59-
nbSectionsPerBusbar.put(extension.getBusbarIndex(), extension.getSectionIndex());
60-
}
61-
BusBarSectionFormInfos busbarSectionInfo = BusBarSectionFormInfos.builder()
62-
.id(bbs.getId())
63-
.vertPos(extension.getSectionIndex())
64-
.horizPos(extension.getBusbarIndex())
65-
.build();
66-
busbarSectionInfos.add(busbarSectionInfo);
67-
} else {
68-
return new VoltageLevelTopologyInfos();
53+
if (extension == null) {
54+
busbarSectionPositionFound = false;
55+
break;
6956
}
57+
int busbarIndex = extension.getBusbarIndex();
58+
int sectionIndex = extension.getSectionIndex();
59+
maxBusbarIndex = Math.max(maxBusbarIndex, busbarIndex);
60+
maxSectionIndex = Math.max(maxSectionIndex, sectionIndex);
61+
nbSectionsPerBusbar.merge(busbarIndex, sectionIndex, Math::max);
62+
busbarSectionInfos.add(BusBarSectionFormInfos.builder()
63+
.id(bbs.getId())
64+
.vertPos(sectionIndex)
65+
.horizPos(busbarIndex)
66+
.build());
7067
}
71-
if (nbSectionsPerBusbar.values().stream().anyMatch(v -> v != topologyInfos.getSectionCount())) { // Non-symmetrical busbars (nb sections)
72-
return new VoltageLevelTopologyInfos();
68+
VoltageLevelTopologyInfos voltageLevelTopologyInfos = createDefaultTopologyInfosBuilder().build();
69+
if (!busbarSectionPositionFound) {
70+
return voltageLevelTopologyInfos;
7371
}
7472

75-
topologyInfos.setRetrievedBusbarSections(true);
76-
topologyInfos.setSwitchKinds(Collections.nCopies(topologyInfos.getSectionCount() - 1, SwitchKind.DISCONNECTOR));
77-
topologyInfos.setBusbarSections(busbarSectionInfos);
73+
voltageLevelTopologyInfos.setBusbarSections(busbarSectionInfos);
74+
voltageLevelTopologyInfos.setBusbarSectionPositionFound(true);
7875

79-
return topologyInfos;
76+
int finalMaxSectionIndex = maxSectionIndex;
77+
boolean isSymmetrical = nbSectionsPerBusbar.values()
78+
.stream()
79+
.allMatch(v -> v == finalMaxSectionIndex);
80+
81+
if (isSymmetrical) {
82+
voltageLevelTopologyInfos.setBusbarCount(maxBusbarIndex);
83+
voltageLevelTopologyInfos.setSectionCount(maxSectionIndex);
84+
voltageLevelTopologyInfos.setRetrievedBusbarSections(true);
85+
voltageLevelTopologyInfos.setSwitchKinds(Collections.nCopies(maxSectionIndex - 1, SwitchKind.DISCONNECTOR));
86+
}
87+
return voltageLevelTopologyInfos;
8088
}
8189

8290
static VoltageLevelFormInfos toFormInfos(Identifiable<?> identifiable) {
@@ -97,6 +105,7 @@ static VoltageLevelFormInfos toFormInfos(Identifiable<?> identifiable) {
97105
builder.sectionCount(vlTopologyInfos.getSectionCount());
98106
builder.switchKinds(vlTopologyInfos.getSwitchKinds());
99107
builder.isRetrievedBusbarSections(vlTopologyInfos.isRetrievedBusbarSections());
108+
builder.isBusbarSectionPositionFound(vlTopologyInfos.isBusbarSectionPositionFound());
100109
builder.busBarSectionInfos(vlTopologyInfos.getBusBarSectionInfosGrouped());
101110
}
102111

@@ -133,14 +142,22 @@ static VoltageLevelTabInfos toTabInfos(Identifiable<?> identifiable) {
133142
return builder.build();
134143
}
135144

145+
private static VoltageLevelTopologyInfos.VoltageLevelTopologyInfosBuilder createDefaultTopologyInfosBuilder() {
146+
return VoltageLevelTopologyInfos.builder()
147+
.busbarCount(1).sectionCount(1).isRetrievedBusbarSections(false)
148+
.switchKinds(List.of()).busbarSections(List.of()).isBusbarSectionPositionFound(false);
149+
}
150+
151+
@Builder
136152
@Getter
137153
@Setter
138154
public static class VoltageLevelTopologyInfos {
139-
private List<BusBarSectionFormInfos> busbarSections = List.of();
140-
private boolean isRetrievedBusbarSections = false;
141-
private int busbarCount = 1;
142-
private int sectionCount = 1;
143-
private List<SwitchKind> switchKinds = List.of();
155+
private List<BusBarSectionFormInfos> busbarSections;
156+
private boolean isRetrievedBusbarSections; // true if busbar sections are symmetrical
157+
private boolean isBusbarSectionPositionFound;
158+
private int busbarCount;
159+
private int sectionCount;
160+
private List<SwitchKind> switchKinds;
144161

145162
public Map<String, List<String>> getBusBarSectionInfosGrouped() {
146163
return busbarSections.stream()

src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,23 @@ void setUp() {
10551055
.add();
10561056
bbs1.newExtension(OperatingStatusAdder.class).withStatus(OperatingStatus.Status.FORCED_OUTAGE).add();
10571057
vlgen5.newExtension(IdentifiableShortCircuitAdder.class).withIpMin(0.0).withIpMax(100.0).add();
1058+
vlgen5.getNodeBreakerView()
1059+
.getBusbarSection("NGEN5")
1060+
.newExtension(BusbarSectionPositionAdder.class)
1061+
.withBusbarIndex(1)
1062+
.withSectionIndex(2)
1063+
.add();
1064+
vlgen5.getNodeBreakerView().newBusbarSection()
1065+
.setId("NGEN5_2")
1066+
.setName("NGEN5_2")
1067+
.setNode(1)
1068+
.add();
1069+
vlgen5.getNodeBreakerView()
1070+
.getBusbarSection("NGEN5_2")
1071+
.newExtension(BusbarSectionPositionAdder.class)
1072+
.withBusbarIndex(2)
1073+
.withSectionIndex(1)
1074+
.add();
10581075

10591076
// Create a connected shunt compensator on a NODE_BREAKER voltage level
10601077
ShuntCompensator shunt4 = vlgen4.newShuntCompensator().setId("SHUNT_VLNB")
@@ -2198,6 +2215,12 @@ void shouldReturnVotlageLevelFormData() throws Exception {
21982215
succeedingTestForElementInfosWithElementId(NETWORK_UUID, VARIANT_ID, ElementType.VOLTAGE_LEVEL, InfoType.FORM, "VLGEN4", resourceToString("/voltage-level-form-data.json"));
21992216
}
22002217

2218+
@Test
2219+
void shouldReturnVotlageLevelNonSymmetricalBusbarsFormData() throws Exception {
2220+
succeedingTestForElementInfosWithElementId(NETWORK_UUID, null, ElementType.VOLTAGE_LEVEL, InfoType.FORM, "VLGEN5", resourceToString("/voltage-level-non-symmetrical-busbars-form-data.json"));
2221+
succeedingTestForElementInfosWithElementId(NETWORK_UUID, VARIANT_ID, ElementType.VOLTAGE_LEVEL, InfoType.FORM, "VLGEN5", resourceToString("/voltage-level-non-symmetrical-busbars-form-data.json"));
2222+
}
2223+
22012224
@Test
22022225
void shouldReturnVotlageLevelTabData() throws Exception {
22032226
succeedingTestForElementInfosWithElementId(NETWORK_UUID, null, ElementType.VOLTAGE_LEVEL, InfoType.TAB, "VLGEN4", resourceToString("/voltage-level-tab-data.json"));

0 commit comments

Comments
 (0)