Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions src/main/java/org/gridsuite/geodata/server/GeoDataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ private void prepareGeoDataForComputation(Network network, Map<String, Substatio
neighboursToBeTreated.forEach(neighbourId -> {
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<String, Set<String>> newNeighbours = getNeighbours(substations);
Expand Down Expand Up @@ -283,17 +288,19 @@ private void step(Step step, Network network, Map<String, Set<String>> sortedNei
for (Iterator<String> it = substationsToCalculate.iterator(); it.hasNext();) {
String substationId = it.next();
Set<String> 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",
Expand Down Expand Up @@ -536,7 +543,14 @@ public List<LineGeoData> getLinesByIds(Network network, Set<String> linesIds) {

List<Line> 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<String, LineGeoData> linesGeoDataDb = lineRepository.findAllById(linesIds).stream().collect(Collectors.toMap(LineEntity::getId, this::toDto));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
Expand Down
Loading