Skip to content

Commit 4135305

Browse files
committed
fix(): manage null substationIds ou lineIds
Signed-off-by: sBouzols <[email protected]>
1 parent 9d766ce commit 4135305

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

src/main/java/org/gridsuite/geodata/server/GeoDataService.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ private void prepareGeoDataForComputation(Network network, Map<String, Substatio
178178
neighboursToBeTreated.forEach(neighbourId -> {
179179
if (geoDataForComputation.get(neighbourId) == null && !substationsToCalculate.contains(neighbourId)) {
180180
substationsToCalculate.add(neighbourId);
181-
substations.add(network.getSubstation(neighbourId));
181+
Substation sub = network.getSubstation(neighbourId);
182+
if (sub != null) {
183+
substations.add(sub);
184+
}
182185
}
183186
});
184187
Map<String, Set<String>> newNeighbours = getNeighbours(substations);
@@ -283,17 +286,19 @@ private void step(Step step, Network network, Map<String, Set<String>> sortedNei
283286
for (Iterator<String> it = substationsToCalculate.iterator(); it.hasNext();) {
284287
String substationId = it.next();
285288
Set<String> neighbours = sortedNeighbours.get(substationId);
286-
double neighborhoodOffset = calculatedSubstationsOffset.get(neighbours) != null ? nextNeighborhoodOffset(calculatedSubstationsOffset.get(neighbours)) : 0;
287-
288-
// centroid calculation
289-
Substation substation = network.getSubstation(substationId);
290-
SubstationGeoData substationGeoData = calculateCentroidGeoData(substation, neighbours, step, substationsGeoData, neighborhoodOffset);
291-
292-
if (substationGeoData != null) {
293-
calculated++;
294-
substationsGeoData.put(substationId, substationGeoData);
295-
calculatedSubstationsOffset.put(neighbours, neighborhoodOffset);
296-
it.remove();
289+
if (neighbours != null) {
290+
double neighborhoodOffset = calculatedSubstationsOffset.get(neighbours) != null ? nextNeighborhoodOffset(calculatedSubstationsOffset.get(neighbours)) : 0;
291+
292+
// centroid calculation
293+
Substation substation = network.getSubstation(substationId);
294+
SubstationGeoData substationGeoData = calculateCentroidGeoData(substation, neighbours, step, substationsGeoData, neighborhoodOffset);
295+
296+
if (substationGeoData != null) {
297+
calculated++;
298+
substationsGeoData.put(substationId, substationGeoData);
299+
calculatedSubstationsOffset.put(neighbours, neighborhoodOffset);
300+
it.remove();
301+
}
297302
}
298303
}
299304
LOGGER.info("Step {}, iteration {}, {} substation's coordinates have been calculated, {} remains unknown",
@@ -536,7 +541,12 @@ public List<LineGeoData> getLinesByIds(Network network, Set<String> linesIds) {
536541

537542
List<Line> lines = new ArrayList<>();
538543

539-
linesIds.forEach(id -> lines.add(network.getLine(id)));
544+
linesIds.forEach(id -> {
545+
Line line = network.getLine(id);
546+
if (line != null) {
547+
lines.add(line);
548+
}
549+
});
540550

541551
// read lines from DB
542552
Map<String, LineGeoData> linesGeoDataDb = lineRepository.findAllById(linesIds).stream().collect(Collectors.toMap(LineEntity::getId, this::toDto));

src/test/java/org/gridsuite/geodata/server/GeoDataControllerTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ void test() throws Exception {
162162
.andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON))
163163
.andExpect(jsonPath("$", hasSize(0)));
164164

165+
mvc.perform(get("/" + VERSION + "/substations?networkUuid=" + networkUuid + "&variantId=" + VARIANT_ID + "&substationId=null&substationId=P2")
166+
.contentType(APPLICATION_JSON))
167+
.andExpect(status().isOk())
168+
.andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON))
169+
.andExpect(jsonPath("$", hasSize(0)));
170+
171+
mvc.perform(get("/" + VERSION + "/substations?networkUuid=" + networkUuid + "&variantId=" + VARIANT_ID + "&substationId=null")
172+
.contentType(APPLICATION_JSON))
173+
.andExpect(status().isOk())
174+
.andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON))
175+
.andExpect(jsonPath("$", hasSize(0)));
176+
165177
mvc.perform(get("/" + VERSION + "/lines?networkUuid=" + networkUuid + "&variantId=" + VARIANT_ID + "&lineId=NHV1_NHV2_2&lineId=NHV1_NHV2_1&country=" + Country.FR)
166178
.contentType(APPLICATION_JSON))
167179
.andExpect(status().isOk())
@@ -173,6 +185,18 @@ void test() throws Exception {
173185
.andExpect(status().isOk())
174186
.andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON))
175187
.andExpect(jsonPath("$", hasSize(0)));
188+
189+
mvc.perform(get("/" + VERSION + "/lines?networkUuid=" + networkUuid + "&variantId=" + VARIANT_ID + "&lineId=NHV1_NHV2_2&lineId=null")
190+
.contentType(APPLICATION_JSON))
191+
.andExpect(status().isOk())
192+
.andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON))
193+
.andExpect(jsonPath("$", hasSize(0)));
194+
195+
mvc.perform(get("/" + VERSION + "/lines?networkUuid=" + networkUuid + "&variantId=" + VARIANT_ID + "&lineId=null")
196+
.contentType(APPLICATION_JSON))
197+
.andExpect(status().isOk())
198+
.andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON))
199+
.andExpect(jsonPath("$", hasSize(0)));
176200
}
177201

178202
@Test

0 commit comments

Comments
 (0)