|
26 | 26 | import java.util.*;
|
27 | 27 | import java.util.stream.Collectors;
|
28 | 28 | import java.util.stream.Stream;
|
| 29 | +import java.util.stream.StreamSupport; |
| 30 | + |
| 31 | +import static org.gridsuite.network.map.dto.InfoTypeParameters.QUERY_PARAM_LOAD_NETWORK_COMPONENTS; |
29 | 32 |
|
30 | 33 | /**
|
31 | 34 | * @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
|
@@ -62,7 +65,16 @@ private List<String> getSubstationsIds(UUID networkUuid, String variantId, List<
|
62 | 65 | }
|
63 | 66 |
|
64 | 67 | public AllElementsInfos getAllElementsInfos(UUID networkUuid, String variantId, @NonNull List<String> substationsId, Map<String, Map<String, String>> additionalParametersByType) {
|
65 |
| - Network network = getNetwork(networkUuid, PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW, variantId); |
| 68 | + // With network components we have to traverse almost all the network to recompute so we can switch to |
| 69 | + // ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW directly |
| 70 | + boolean shouldLoadNetworkComponents = Optional.ofNullable(additionalParametersByType.get(ElementType.BUS.toString())) |
| 71 | + .map(map -> map.get(QUERY_PARAM_LOAD_NETWORK_COMPONENTS)) |
| 72 | + .map(Boolean::valueOf) |
| 73 | + .orElse(false); |
| 74 | + PreloadingStrategy preloadingStrategy = shouldLoadNetworkComponents || substationsId.size() >= 5 ? |
| 75 | + PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW : |
| 76 | + PreloadingStrategy.NONE; |
| 77 | + Network network = getNetwork(networkUuid, preloadingStrategy, variantId); |
66 | 78 | return AllElementsInfos.builder()
|
67 | 79 | .substations(getSubstationsInfos(network, substationsId, getInfoTypeParameters(additionalParametersByType, ElementType.SUBSTATION), null))
|
68 | 80 | .voltageLevels(getVoltageLevelsInfos(network, substationsId, getInfoTypeParameters(additionalParametersByType, ElementType.VOLTAGE_LEVEL), null))
|
@@ -253,10 +265,11 @@ private List<ElementInfos> getTieLinesInfos(Network network, @NonNull List<Strin
|
253 | 265 |
|
254 | 266 | private List<ElementInfos> getBusesInfos(Network network, @NonNull List<String> substationsId, InfoTypeParameters infoTypeParameters) {
|
255 | 267 | Stream<Bus> buses = substationsId.isEmpty() ? network.getBusView().getBusStream() :
|
256 |
| - network.getBusView().getBusStream() |
257 |
| - .filter(Objects::nonNull) |
258 |
| - .filter(bus -> bus.getVoltageLevel().getSubstation().stream().anyMatch(substation -> substationsId.contains(substation.getId()))) |
259 |
| - .distinct(); |
| 268 | + substationsId |
| 269 | + .stream() |
| 270 | + .flatMap(id -> network.getSubstation(id).getVoltageLevelStream()) |
| 271 | + .flatMap(vl -> StreamSupport.stream(vl.getBusView().getBuses().spliterator(), false)); |
| 272 | + |
260 | 273 | return buses
|
261 | 274 | .map(c -> ElementType.BUS.getInfosGetter().apply(c, infoTypeParameters))
|
262 | 275 | .distinct()
|
|
0 commit comments