Skip to content

Commit b404c8b

Browse files
feat: allow partial loading for branches and generators (#285)
* feat: allow partial loading for branches and generators Signed-off-by: Joris Mancini <[email protected]> * fix: transform all request in post Signed-off-by: Joris Mancini <[email protected]> * fix: tests with branches Signed-off-by: Joris Mancini <[email protected]> * fix: tests and sonar Signed-off-by: Joris Mancini <[email protected]> * feat: add selected operational limits group by default Signed-off-by: Joris Mancini <[email protected]> --------- Signed-off-by: Joris Mancini <[email protected]> Co-authored-by: dbraquart <[email protected]>
1 parent 6e2d5fe commit b404c8b

19 files changed

+4110
-130
lines changed

src/main/java/org/gridsuite/network/map/NetworkMapController.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
import org.springframework.context.annotation.ComponentScan;
2020
import org.springframework.web.bind.annotation.*;
2121

22-
import java.util.Comparator;
23-
import java.util.List;
24-
import java.util.Optional;
25-
import java.util.UUID;
22+
import java.util.*;
2623

2724
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
2825

@@ -52,13 +49,14 @@ public List<String> getElementsIds(@Parameter(description = "Network UUID") @Pat
5249
return networkMapService.getElementsIds(networkUuid, variantId, substationsIds.orElseGet(List::of), elementType, nominalVoltages);
5350
}
5451

55-
@GetMapping(value = "/networks/{networkUuid}/all", produces = APPLICATION_JSON_VALUE)
52+
@PostMapping(value = "/networks/{networkUuid}/all", produces = APPLICATION_JSON_VALUE)
5653
@Operation(summary = "Get all equipments descriptions")
5754
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "all equipments descriptions")})
5855
public AllElementsInfos getAll(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid,
5956
@Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId,
60-
@Parameter(description = "Substations id") @RequestParam(name = "substationId", defaultValue = "") List<String> substationsIds) {
61-
return networkMapService.getAllElementsInfos(networkUuid, variantId, substationsIds);
57+
@Parameter(description = "Substations id") @RequestParam(name = "substationId", defaultValue = "") List<String> substationsIds,
58+
@RequestBody Map<String, Map<String, String>> additionalParametersByType) {
59+
return networkMapService.getAllElementsInfos(networkUuid, variantId, substationsIds, additionalParametersByType);
6260
}
6361

6462
@PostMapping(value = "/networks/{networkUuid}/elements", produces = APPLICATION_JSON_VALUE)

src/main/java/org/gridsuite/network/map/NetworkMapService.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,34 @@ private List<String> getSubstationsIds(UUID networkUuid, String variantId, List<
6161
.map(Substation::getId).toList();
6262
}
6363

64-
public AllElementsInfos getAllElementsInfos(UUID networkUuid, String variantId, @NonNull List<String> substationsId) {
64+
public AllElementsInfos getAllElementsInfos(UUID networkUuid, String variantId, @NonNull List<String> substationsId, Map<String, Map<String, String>> additionalParametersByType) {
6565
Network network = getNetwork(networkUuid, PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW, variantId);
6666
return AllElementsInfos.builder()
67-
.substations(getSubstationsInfos(network, substationsId, InfoTypeParameters.TAB, null))
68-
.voltageLevels(getVoltageLevelsInfos(network, substationsId, InfoTypeParameters.TAB, null))
69-
.hvdcLines(getHvdcLinesInfos(network, substationsId, InfoTypeParameters.TAB, null))
70-
.lines(getElementsInfos(network, substationsId, ElementType.LINE, InfoTypeParameters.TAB, null))
71-
.loads(getElementsInfos(network, substationsId, ElementType.LOAD, InfoTypeParameters.TAB, null))
72-
.generators(getElementsInfos(network, substationsId, ElementType.GENERATOR, InfoTypeParameters.TAB, null))
73-
.twoWindingsTransformers(getElementsInfos(network, substationsId, ElementType.TWO_WINDINGS_TRANSFORMER, InfoTypeParameters.TAB, null))
74-
.threeWindingsTransformers(getElementsInfos(network, substationsId, ElementType.THREE_WINDINGS_TRANSFORMER, InfoTypeParameters.TAB, null))
75-
.batteries(getElementsInfos(network, substationsId, ElementType.BATTERY, InfoTypeParameters.TAB, null))
76-
.danglingLines(getElementsInfos(network, substationsId, ElementType.DANGLING_LINE, InfoTypeParameters.TAB, null))
77-
.tieLines(getTieLinesInfos(network, substationsId, InfoTypeParameters.TAB, null))
78-
.lccConverterStations(getElementsInfos(network, substationsId, ElementType.LCC_CONVERTER_STATION, InfoTypeParameters.TAB, null))
79-
.shuntCompensators(getElementsInfos(network, substationsId, ElementType.SHUNT_COMPENSATOR, InfoTypeParameters.TAB, null))
80-
.staticVarCompensators(getElementsInfos(network, substationsId, ElementType.STATIC_VAR_COMPENSATOR, InfoTypeParameters.TAB, null))
81-
.vscConverterStations(getElementsInfos(network, substationsId, ElementType.VSC_CONVERTER_STATION, InfoTypeParameters.TAB, null))
82-
.buses(getBusesInfos(network, substationsId, InfoTypeParameters.TAB))
83-
.busbarSections(getElementsInfos(network, substationsId, ElementType.BUSBAR_SECTION, InfoTypeParameters.TAB, null))
84-
.branches(getElementsInfos(network, substationsId, ElementType.BRANCH, InfoTypeParameters.TAB, null))
67+
.substations(getSubstationsInfos(network, substationsId, getInfoTypeParameters(additionalParametersByType, ElementType.SUBSTATION), null))
68+
.voltageLevels(getVoltageLevelsInfos(network, substationsId, getInfoTypeParameters(additionalParametersByType, ElementType.VOLTAGE_LEVEL), null))
69+
.hvdcLines(getHvdcLinesInfos(network, substationsId, getInfoTypeParameters(additionalParametersByType, ElementType.HVDC_LINE), null))
70+
.lines(getElementsInfos(network, substationsId, ElementType.LINE, getInfoTypeParameters(additionalParametersByType, ElementType.LINE), null))
71+
.loads(getElementsInfos(network, substationsId, ElementType.LOAD, getInfoTypeParameters(additionalParametersByType, ElementType.LOAD), null))
72+
.generators(getElementsInfos(network, substationsId, ElementType.GENERATOR, getInfoTypeParameters(additionalParametersByType, ElementType.GENERATOR), null))
73+
.twoWindingsTransformers(getElementsInfos(network, substationsId, ElementType.TWO_WINDINGS_TRANSFORMER, getInfoTypeParameters(additionalParametersByType, ElementType.TWO_WINDINGS_TRANSFORMER), null))
74+
.threeWindingsTransformers(getElementsInfos(network, substationsId, ElementType.THREE_WINDINGS_TRANSFORMER, getInfoTypeParameters(additionalParametersByType, ElementType.THREE_WINDINGS_TRANSFORMER), null))
75+
.batteries(getElementsInfos(network, substationsId, ElementType.BATTERY, getInfoTypeParameters(additionalParametersByType, ElementType.BATTERY), null))
76+
.danglingLines(getElementsInfos(network, substationsId, ElementType.DANGLING_LINE, getInfoTypeParameters(additionalParametersByType, ElementType.DANGLING_LINE), null))
77+
.tieLines(getTieLinesInfos(network, substationsId, getInfoTypeParameters(additionalParametersByType, ElementType.TIE_LINE), null))
78+
.lccConverterStations(getElementsInfos(network, substationsId, ElementType.LCC_CONVERTER_STATION, getInfoTypeParameters(additionalParametersByType, ElementType.LCC_CONVERTER_STATION), null))
79+
.shuntCompensators(getElementsInfos(network, substationsId, ElementType.SHUNT_COMPENSATOR, getInfoTypeParameters(additionalParametersByType, ElementType.SHUNT_COMPENSATOR), null))
80+
.staticVarCompensators(getElementsInfos(network, substationsId, ElementType.STATIC_VAR_COMPENSATOR, getInfoTypeParameters(additionalParametersByType, ElementType.STATIC_VAR_COMPENSATOR), null))
81+
.vscConverterStations(getElementsInfos(network, substationsId, ElementType.VSC_CONVERTER_STATION, getInfoTypeParameters(additionalParametersByType, ElementType.VSC_CONVERTER_STATION), null))
82+
.buses(getBusesInfos(network, substationsId, getInfoTypeParameters(additionalParametersByType, ElementType.BUS)))
83+
.busbarSections(getElementsInfos(network, substationsId, ElementType.BUSBAR_SECTION, getInfoTypeParameters(additionalParametersByType, ElementType.BUSBAR_SECTION), null))
84+
.branches(getElementsInfos(network, substationsId, ElementType.BRANCH, getInfoTypeParameters(additionalParametersByType, ElementType.BRANCH), null))
8585
.build();
8686
}
8787

88+
private static InfoTypeParameters getInfoTypeParameters(Map<String, Map<String, String>> additionalParametersByType, ElementType elementType) {
89+
return new InfoTypeParameters(ElementInfos.InfoType.TAB, additionalParametersByType.get(String.valueOf(elementType)));
90+
}
91+
8892
private List<String> getVoltageLevelsIds(UUID networkUuid, String variantId, @NonNull List<String> substationsIds, List<Double> nominalVoltages) {
8993
Network network = getNetwork(networkUuid, getPreloadingStrategy(substationsIds), variantId);
9094
return getVoltageLevelStream(network, substationsIds, nominalVoltages).map(VoltageLevel::getId).toList();

src/main/java/org/gridsuite/network/map/dto/InfoTypeParameters.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
@Data
1515
public class InfoTypeParameters {
1616
public static final String QUERY_PARAM_DC_POWERFACTOR = "dcPowerFactor";
17+
public static final String QUERY_PARAM_LOAD_OPERATIONAL_LIMIT_GROUPS = "loadOperationalLimitGroups";
18+
public static final String QUERY_PARAM_LOAD_REGULATING_TERMINALS = "loadRegulatingTerminals";
1719

1820
public static final InfoTypeParameters TAB = new InfoTypeParameters(ElementInfos.InfoType.TAB, null);
1921

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,23 @@ public class BranchTabInfos extends ElementInfosWithProperties {
8282
@JsonInclude(Include.NON_EMPTY)
8383
private List<String> operationalLimitsGroup1Names;
8484

85+
@JsonInclude(Include.NON_EMPTY)
86+
private CurrentLimitsData selectedOperationalLimitsGroup1;
87+
8588
@JsonInclude(Include.NON_NULL)
86-
private String selectedOperationalLimitsGroup1;
89+
private String selectedOperationalLimitsGroup1Name;
8790

8891
@JsonInclude(Include.NON_EMPTY)
8992
private Map<String, CurrentLimitsData> operationalLimitsGroup2;
9093

9194
@JsonInclude(Include.NON_EMPTY)
9295
private List<String> operationalLimitsGroup2Names;
9396

97+
@JsonInclude(Include.NON_EMPTY)
98+
private CurrentLimitsData selectedOperationalLimitsGroup2;
99+
94100
@JsonInclude(Include.NON_NULL)
95-
private String selectedOperationalLimitsGroup2;
101+
private String selectedOperationalLimitsGroup2Name;
96102

97103
@JsonInclude(Include.NON_ABSENT)
98104
private Optional<BranchObservabilityInfos> branchObservability;

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.stream.Stream;
2727

2828
import static org.gridsuite.network.map.dto.InfoTypeParameters.QUERY_PARAM_DC_POWERFACTOR;
29+
import static org.gridsuite.network.map.dto.InfoTypeParameters.QUERY_PARAM_LOAD_OPERATIONAL_LIMIT_GROUPS;
2930
import static org.gridsuite.network.map.dto.common.CurrentLimitsData.Applicability.SIDE1;
3031
import static org.gridsuite.network.map.dto.common.CurrentLimitsData.Applicability.SIDE2;
3132
import static org.gridsuite.network.map.dto.utils.ElementUtils.mapCountry;
@@ -39,14 +40,19 @@ public static ElementInfos toData(@NonNull final Identifiable<?> identifiable,
3940
final Branch<?> branch = (Branch<?>) identifiable;
4041
final Double dcPowerFactor = Optional.ofNullable(infoTypeParameters.getOptionalParameters().get(QUERY_PARAM_DC_POWERFACTOR))
4142
.map(Double::valueOf).orElse(null);
43+
final boolean loadOperationalLimitGroups = Optional.ofNullable(infoTypeParameters.getOptionalParameters().get(QUERY_PARAM_LOAD_OPERATIONAL_LIMIT_GROUPS))
44+
.map(Boolean::valueOf).orElse(false);
4245
return switch (infoTypeParameters.getInfoType()) {
43-
case TAB -> toTabInfos(branch, dcPowerFactor);
46+
case TAB -> toTabInfos(branch, dcPowerFactor, loadOperationalLimitGroups);
4447
default -> throw new UnsupportedOperationException("TODO");
4548
};
4649
}
4750

4851
protected static<T extends BranchTabInfos, B extends BranchTabInfosBuilder<T, ?>> B toTabBuilder(
49-
@NonNull final B builder, @NonNull final Branch<?> branch, @Nullable final Double dcPowerFactor
52+
@NonNull final B builder,
53+
@NonNull final Branch<?> branch,
54+
@Nullable final Double dcPowerFactor,
55+
@NonNull final boolean loadOperationalLimitGroups
5056
) {
5157
/* even if x & r properties are in branch properties doc, it is not in branch getter but each impls... */
5258
//TODO https://github.com/powsybl/powsybl-core/issues/3521 tagged for release 09/2025
@@ -66,14 +72,24 @@ public static ElementInfos toData(@NonNull final Identifiable<?> identifiable,
6672
// common properties
6773
final Terminal terminal1 = branch.getTerminal1();
6874
final Terminal terminal2 = branch.getTerminal2();
69-
final Map<String, CurrentLimitsData> mapOperationalLimitsGroup1 = buildCurrentLimitsMap(branch.getOperationalLimitsGroups1());
70-
builder.operationalLimitsGroup1(mapOperationalLimitsGroup1)
71-
.operationalLimitsGroup1Names(List.copyOf(mapOperationalLimitsGroup1.keySet()))
72-
.selectedOperationalLimitsGroup1(branch.getSelectedOperationalLimitsGroupId1().orElse(null));
73-
final Map<String, CurrentLimitsData> mapOperationalLimitsGroup2 = buildCurrentLimitsMap(branch.getOperationalLimitsGroups2());
74-
builder.operationalLimitsGroup2(mapOperationalLimitsGroup2)
75-
.operationalLimitsGroup2Names(List.copyOf(mapOperationalLimitsGroup2.keySet()))
76-
.selectedOperationalLimitsGroup2(branch.getSelectedOperationalLimitsGroupId2().orElse(null));
75+
76+
branch.getSelectedOperationalLimitsGroup1()
77+
.flatMap(OperationalLimitsGroup::getCurrentLimits)
78+
.map(cl -> builder.selectedOperationalLimitsGroup1(toMapDataCurrentLimits(cl, null, null)));
79+
branch.getSelectedOperationalLimitsGroupId1().map(name -> builder.selectedOperationalLimitsGroup1Name(name));
80+
branch.getSelectedOperationalLimitsGroup2()
81+
.flatMap(OperationalLimitsGroup::getCurrentLimits)
82+
.map(cl -> builder.selectedOperationalLimitsGroup2(toMapDataCurrentLimits(cl, null, null)));
83+
branch.getSelectedOperationalLimitsGroupId2().map(name -> builder.selectedOperationalLimitsGroup2Name(name));
84+
85+
if (loadOperationalLimitGroups) {
86+
final Map<String, CurrentLimitsData> mapOperationalLimitsGroup1 = buildCurrentLimitsMap(branch.getOperationalLimitsGroups1());
87+
builder.operationalLimitsGroup1(mapOperationalLimitsGroup1)
88+
.operationalLimitsGroup1Names(List.copyOf(mapOperationalLimitsGroup1.keySet()));
89+
final Map<String, CurrentLimitsData> mapOperationalLimitsGroup2 = buildCurrentLimitsMap(branch.getOperationalLimitsGroups2());
90+
builder.operationalLimitsGroup2(mapOperationalLimitsGroup2)
91+
.operationalLimitsGroup2Names(List.copyOf(mapOperationalLimitsGroup2.keySet()));
92+
}
7793
//noinspection unchecked
7894
return (B) builder
7995
.type(branch.getType().name())
@@ -106,9 +122,9 @@ public static ElementInfos toData(@NonNull final Identifiable<?> identifiable,
106122
.operatingStatus(ExtensionUtils.toOperatingStatus(branch));
107123
}
108124

109-
private static BranchTabInfos toTabInfos(@NonNull final Branch<?> branch, @Nullable final Double dcPowerFactor) {
125+
private static BranchTabInfos toTabInfos(@NonNull final Branch<?> branch, @Nullable final Double dcPowerFactor, @NonNull final Boolean loadOperationalLimitGroups) {
110126
/// Why is {@link BranchTabInfos#builder()} return wildcards in return type {@code BranchTabInfosBuilder<?, ?>}
111-
return toTabBuilder((BranchTabInfosBuilder<BranchTabInfos, ?>) BranchTabInfos.builder(), branch, dcPowerFactor).build();
127+
return toTabBuilder((BranchTabInfosBuilder<BranchTabInfos, ?>) BranchTabInfos.builder(), branch, dcPowerFactor, loadOperationalLimitGroups).build();
112128
}
113129

114130
private static Map<String, CurrentLimitsData> buildCurrentLimitsMap(@NonNull final Collection<OperationalLimitsGroup> operationalLimitsGroups) {

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Optional;
3131
import java.util.stream.Collectors;
3232

33+
import static org.gridsuite.network.map.dto.InfoTypeParameters.QUERY_PARAM_LOAD_REGULATING_TERMINALS;
3334
import static org.gridsuite.network.map.dto.utils.ElementUtils.*;
3435

3536
/**
@@ -42,8 +43,10 @@ private GeneratorInfosMapper() {
4243
}
4344

4445
public static ElementInfos toData(Identifiable<?> identifiable, InfoTypeParameters infoTypeParameters) {
46+
boolean loadRegulatingTerminals = Optional.ofNullable(infoTypeParameters.getOptionalParameters().get(QUERY_PARAM_LOAD_REGULATING_TERMINALS))
47+
.map(Boolean::valueOf).orElse(false);
4548
return switch (infoTypeParameters.getInfoType()) {
46-
case TAB -> toTabInfos(identifiable);
49+
case TAB -> toTabInfos(identifiable, loadRegulatingTerminals);
4750
case FORM -> toFormInfos(identifiable);
4851
case LIST -> ElementInfosMapper.toInfosWithType(identifiable);
4952
default -> throw new UnsupportedOperationException("TODO");
@@ -60,7 +63,7 @@ private static List<ReactiveCapabilityCurveMapData> getReactiveCapabilityCurvePo
6063
.collect(Collectors.toList());
6164
}
6265

63-
private static GeneratorTabInfos toTabInfos(Identifiable<?> identifiable) {
66+
private static GeneratorTabInfos toTabInfos(Identifiable<?> identifiable, boolean loadRegulatingTerminals) {
6467
Generator generator = (Generator) identifiable;
6568
Terminal terminal = generator.getTerminal();
6669
GeneratorTabInfos.GeneratorTabInfosBuilder<?, ?> builder = GeneratorTabInfos.builder()
@@ -87,14 +90,17 @@ private static GeneratorTabInfos toTabInfos(Identifiable<?> identifiable) {
8790
.generatorShortCircuit(toGeneratorShortCircuit(generator))
8891
.generatorStartup(toGeneratorStartup(generator));
8992

90-
Terminal regulatingTerminal = generator.getRegulatingTerminal();
91-
//If there is no regulating terminal in file, regulating terminal voltage level is equal to generator voltage level
92-
if (regulatingTerminal != null && !regulatingTerminal.getVoltageLevel().equals(terminal.getVoltageLevel())) {
93-
builder.regulatingTerminalVlName(regulatingTerminal.getVoltageLevel().getOptionalName().orElse(null));
94-
builder.regulatingTerminalConnectableId(regulatingTerminal.getConnectable().getId());
95-
builder.regulatingTerminalConnectableType(regulatingTerminal.getConnectable().getType().name());
96-
builder.regulatingTerminalVlId(regulatingTerminal.getVoltageLevel().getId());
93+
if (loadRegulatingTerminals) {
94+
Terminal regulatingTerminal = generator.getRegulatingTerminal();
95+
//If there is no regulating terminal in file, regulating terminal voltage level is equal to generator voltage level
96+
if (regulatingTerminal != null && !regulatingTerminal.getVoltageLevel().equals(terminal.getVoltageLevel())) {
97+
builder.regulatingTerminalVlName(regulatingTerminal.getVoltageLevel().getOptionalName().orElse(null));
98+
builder.regulatingTerminalConnectableId(regulatingTerminal.getConnectable().getId());
99+
builder.regulatingTerminalConnectableType(regulatingTerminal.getConnectable().getType().name());
100+
builder.regulatingTerminalVlId(regulatingTerminal.getVoltageLevel().getId());
101+
}
97102
}
103+
98104
ReactiveLimits reactiveLimits = generator.getReactiveLimits();
99105
if (reactiveLimits != null) {
100106
ReactiveLimitsKind limitsKind = reactiveLimits.getKind();

0 commit comments

Comments
 (0)