diff --git a/src/main/java/org/gridsuite/geodata/server/GeoDataService.java b/src/main/java/org/gridsuite/geodata/server/GeoDataService.java index 4cd6714c..2b6cd0d8 100644 --- a/src/main/java/org/gridsuite/geodata/server/GeoDataService.java +++ b/src/main/java/org/gridsuite/geodata/server/GeoDataService.java @@ -178,7 +178,12 @@ private void prepareGeoDataForComputation(Network network, Map { if (geoDataForComputation.get(neighbourId) == null && !substationsToCalculate.contains(neighbourId)) { substationsToCalculate.add(neighbourId); - substations.add(network.getSubstation(neighbourId)); + Substation sub = network.getSubstation(neighbourId); + if (sub != null) { // neighbours comes from a Request param string, could not exists in the network + substations.add(sub); + } else { + LOGGER.debug("{} substation doesn't exist in the newtwork, will be ignored.", neighbourId); + } } }); Map> newNeighbours = getNeighbours(substations); @@ -283,17 +288,19 @@ private void step(Step step, Network network, Map> sortedNei for (Iterator it = substationsToCalculate.iterator(); it.hasNext();) { String substationId = it.next(); Set neighbours = sortedNeighbours.get(substationId); - double neighborhoodOffset = calculatedSubstationsOffset.get(neighbours) != null ? nextNeighborhoodOffset(calculatedSubstationsOffset.get(neighbours)) : 0; - - // centroid calculation - Substation substation = network.getSubstation(substationId); - SubstationGeoData substationGeoData = calculateCentroidGeoData(substation, neighbours, step, substationsGeoData, neighborhoodOffset); - - if (substationGeoData != null) { - calculated++; - substationsGeoData.put(substationId, substationGeoData); - calculatedSubstationsOffset.put(neighbours, neighborhoodOffset); - it.remove(); + if (neighbours != null) { // substationsToCalculate comes from a Request param string, could not exists in the network + double neighborhoodOffset = calculatedSubstationsOffset.get(neighbours) != null ? nextNeighborhoodOffset(calculatedSubstationsOffset.get(neighbours)) : 0; + + // centroid calculation + Substation substation = network.getSubstation(substationId); + SubstationGeoData substationGeoData = calculateCentroidGeoData(substation, neighbours, step, substationsGeoData, neighborhoodOffset); + + if (substationGeoData != null) { + calculated++; + substationsGeoData.put(substationId, substationGeoData); + calculatedSubstationsOffset.put(neighbours, neighborhoodOffset); + it.remove(); + } } } LOGGER.info("Step {}, iteration {}, {} substation's coordinates have been calculated, {} remains unknown", @@ -536,7 +543,14 @@ public List getLinesByIds(Network network, Set linesIds) { List lines = new ArrayList<>(); - linesIds.forEach(id -> lines.add(network.getLine(id))); + linesIds.forEach(id -> { + Line line = network.getLine(id); + if (line != null) { // linesIds comes from a Request param string, could not exists in the network + lines.add(line); + } else { + LOGGER.debug("{} line doesn't exist in the newtwork, will be ignored.", id); + } + }); // read lines from DB Map linesGeoDataDb = lineRepository.findAllById(linesIds).stream().collect(Collectors.toMap(LineEntity::getId, this::toDto)); diff --git a/src/test/java/org/gridsuite/geodata/server/GeoDataControllerTest.java b/src/test/java/org/gridsuite/geodata/server/GeoDataControllerTest.java index 68ac624f..eb36a3d3 100644 --- a/src/test/java/org/gridsuite/geodata/server/GeoDataControllerTest.java +++ b/src/test/java/org/gridsuite/geodata/server/GeoDataControllerTest.java @@ -162,6 +162,18 @@ void test() throws Exception { .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) .andExpect(jsonPath("$", hasSize(0))); + mvc.perform(get("/" + VERSION + "/substations?networkUuid=" + networkUuid + "&variantId=" + VARIANT_ID + "&substationId=notExistsId&substationId=P2") + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) + .andExpect(jsonPath("$", hasSize(0))); + + mvc.perform(get("/" + VERSION + "/substations?networkUuid=" + networkUuid + "&variantId=" + VARIANT_ID + "&substationId=notExistsId") + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) + .andExpect(jsonPath("$", hasSize(0))); + mvc.perform(get("/" + VERSION + "/lines?networkUuid=" + networkUuid + "&variantId=" + VARIANT_ID + "&lineId=NHV1_NHV2_2&lineId=NHV1_NHV2_1&country=" + Country.FR) .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) @@ -173,6 +185,18 @@ void test() throws Exception { .andExpect(status().isOk()) .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) .andExpect(jsonPath("$", hasSize(0))); + + mvc.perform(get("/" + VERSION + "/lines?networkUuid=" + networkUuid + "&variantId=" + VARIANT_ID + "&lineId=NHV1_NHV2_2&lineId=notExistsId") + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) + .andExpect(jsonPath("$", hasSize(0))); + + mvc.perform(get("/" + VERSION + "/lines?networkUuid=" + networkUuid + "&variantId=" + VARIANT_ID + "&lineId=notExistsId") + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) + .andExpect(jsonPath("$", hasSize(0))); } @Test