Skip to content

Commit d6617b9

Browse files
ipirogghazwarhili
andauthored
Short circuit results add global filter (#806)
* First step in adding global filter on shortcircuit analysis panel * Unused import and TU Signed-off-by: Igor PIROG <[email protected]> * Adjust number of parameters below the max sonar Signed-off-by: Igor PIROG <[email protected]> * Remarks ok Signed-off-by: Igor PIROG <[email protected]> * Sonarlint trouble Signed-off-by: Igor PIROG <[email protected]> --------- Signed-off-by: Igor PIROG <[email protected]> Co-authored-by: Ghazoua Rhili <[email protected]>
1 parent 8824880 commit d6617b9

File tree

6 files changed

+65
-17
lines changed

6 files changed

+65
-17
lines changed

src/main/java/org/gridsuite/study/server/controller/StudyController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.gridsuite.study.server.service.securityanalysis.SecurityAnalysisResultType;
4646
import org.gridsuite.study.server.service.shortcircuit.FaultResultsMode;
4747
import org.gridsuite.study.server.service.shortcircuit.ShortcircuitAnalysisType;
48+
import org.gridsuite.study.server.utils.ResultParameters;
4849
import org.springframework.data.domain.Pageable;
4950
import org.springframework.data.domain.Sort;
5051
import org.springframework.data.util.Pair;
@@ -817,17 +818,18 @@ public ResponseEntity<Void> stopShortCircuitAnalysis(@Parameter(description = "S
817818
@ApiResponse(responseCode = "204", description = "No short circuit analysis has been done yet"),
818819
@ApiResponse(responseCode = "404", description = "The short circuit analysis has not been found")})
819820
public ResponseEntity<String> getShortCircuitResult(@Parameter(description = "study UUID") @PathVariable("studyUuid") UUID studyUuid,
820-
@PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
821-
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid,
821+
@Parameter(description = "root network UUID") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
822+
@Parameter(description = "node UUID") @PathVariable("nodeUuid") UUID nodeUuid,
822823
@Parameter(description = "BASIC (faults without limits and feeders), " +
823824
"FULL (faults with both), " +
824825
"WITH_LIMIT_VIOLATIONS (like FULL but only those with limit violations) or " +
825826
"NONE (no fault)") @RequestParam(name = "mode", required = false, defaultValue = "FULL") FaultResultsMode mode,
826827
@Parameter(description = "type") @RequestParam(value = "type", required = false, defaultValue = "ALL_BUSES") ShortcircuitAnalysisType type,
827828
@Parameter(description = "JSON array of filters") @RequestParam(name = "filters", required = false) String filters,
829+
@Parameter(description = "JSON array of global filters") @RequestParam(name = "globalFilters", required = false) String globalFilters,
828830
@Parameter(description = "If we wanted the paged version of the results or not") @RequestParam(name = "paged", required = false, defaultValue = "false") boolean paged,
829831
Pageable pageable) {
830-
String result = rootNetworkNodeInfoService.getShortCircuitAnalysisResult(nodeUuid, rootNetworkUuid, mode, type, filters, paged, pageable);
832+
String result = rootNetworkNodeInfoService.getShortCircuitAnalysisResult(new ResultParameters(rootNetworkUuid, nodeUuid), mode, type, filters, globalFilters, paged, pageable);
831833
return result != null ? ResponseEntity.ok().body(result) :
832834
ResponseEntity.noContent().build();
833835
}

src/main/java/org/gridsuite/study/server/service/ConsumerService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ public void consumeCalculationFailed(Message<String> msg, ComputationType comput
556556
try {
557557
receiverObj = objectMapper.readValue(URLDecoder.decode(receiver, StandardCharsets.UTF_8), NodeReceiver.class);
558558

559-
LOGGER.info("{} failed for node '{}' with error messsage: {}", computationType.getLabel(), receiverObj.getNodeUuid(), errorMessage);
559+
LOGGER.info("{} failed for node '{}' with error message: {}", computationType.getLabel(), receiverObj.getNodeUuid(), errorMessage);
560560

561561
// delete computation results from the databases
562562
// ==> will probably be removed soon because it prevents the front from recovering the resultId ; or 'null' parameter will be replaced by null like in VOLTAGE_INITIALIZATION

src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.gridsuite.study.server.service.shortcircuit.FaultResultsMode;
3434
import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService;
3535
import org.gridsuite.study.server.service.shortcircuit.ShortcircuitAnalysisType;
36+
import org.gridsuite.study.server.utils.ResultParameters;
3637
import org.springframework.data.domain.Pageable;
3738
import org.springframework.data.domain.Sort;
3839
import org.springframework.stereotype.Service;
@@ -603,10 +604,15 @@ public String getNonEvacuatedEnergyResult(UUID nodeUuid, UUID rootNetworkUuid) {
603604
}
604605

605606
@Transactional(readOnly = true)
606-
public String getShortCircuitAnalysisResult(UUID nodeUuid, UUID rootNetworkUuid, FaultResultsMode mode, ShortcircuitAnalysisType type, String filters, boolean paged, Pageable pageable) {
607-
UUID resultUuid = getComputationResultUuid(nodeUuid, rootNetworkUuid,
608-
type == ShortcircuitAnalysisType.ALL_BUSES ? SHORT_CIRCUIT : SHORT_CIRCUIT_ONE_BUS);
609-
return shortCircuitService.getShortCircuitAnalysisResult(resultUuid, mode, type, filters, paged, pageable);
607+
public String getShortCircuitAnalysisResult(ResultParameters resultParameters, FaultResultsMode mode, ShortcircuitAnalysisType type, String filters, String globalFilters, boolean paged, Pageable pageable) {
608+
RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(resultParameters.getNodeUuid(), resultParameters.getRootNetworkUuid()).orElse(null);
609+
ResultParameters resultParametersEnriched = new ResultParameters(
610+
resultParameters.getRootNetworkUuid(),
611+
resultParameters.getNodeUuid(),
612+
rootNetworkNodeInfoEntity == null ? null : rootNetworkNodeInfoEntity.getVariantId(),
613+
rootNetworkNodeInfoEntity == null ? resultParameters.getRootNetworkUuid() : rootNetworkNodeInfoEntity.getRootNetwork().getNetworkUuid(),
614+
getComputationResultUuid(resultParameters.getNodeUuid(), resultParameters.getRootNetworkUuid(), type == ShortcircuitAnalysisType.ALL_BUSES ? SHORT_CIRCUIT : SHORT_CIRCUIT_ONE_BUS));
615+
return shortCircuitService.getShortCircuitAnalysisResult(resultParametersEnriched, mode, type, filters, globalFilters, paged, pageable);
610616
}
611617

612618
@Transactional(readOnly = true)

src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.gridsuite.study.server.dto.VariantInfos;
2121
import org.gridsuite.study.server.service.StudyService;
2222
import org.gridsuite.study.server.service.common.AbstractComputationService;
23+
import org.gridsuite.study.server.utils.ResultParameters;
2324
import org.springframework.beans.factory.annotation.Autowired;
2425
import org.springframework.data.domain.Pageable;
2526
import org.springframework.http.*;
@@ -130,11 +131,11 @@ private String getShortCircuitAnalysisResultsPageResourcePath(UUID resultUuid, S
130131
return resultPath + "/paged";
131132
}
132133

133-
public String getShortCircuitAnalysisResult(UUID resultUuid, FaultResultsMode mode, ShortcircuitAnalysisType type, String filters, boolean paged, Pageable pageable) {
134+
public String getShortCircuitAnalysisResult(ResultParameters resultParameters, FaultResultsMode mode, ShortcircuitAnalysisType type, String filters, String globalFilters, boolean paged, Pageable pageable) {
134135
if (paged) {
135-
return getShortCircuitAnalysisResultsPage(resultUuid, mode, type, filters, pageable);
136+
return getShortCircuitAnalysisResultsPage(resultParameters, mode, type, filters, globalFilters, pageable);
136137
} else {
137-
return getShortCircuitAnalysisResult(resultUuid, mode);
138+
return getShortCircuitAnalysisResult(resultParameters.getResultUuid(), mode);
138139
}
139140
}
140141

@@ -178,19 +179,25 @@ public String getShortCircuitAnalysisResult(UUID resultUuid, FaultResultsMode mo
178179
return getShortCircuitAnalysisResource(builder.build().toUri());
179180
}
180181

181-
public String getShortCircuitAnalysisResultsPage(UUID resultUuid, FaultResultsMode mode, ShortcircuitAnalysisType type, String filters, Pageable pageable) {
182-
String resultsPath = getShortCircuitAnalysisResultsPageResourcePath(resultUuid, type);
182+
public String getShortCircuitAnalysisResultsPage(ResultParameters resultParameters, FaultResultsMode mode, ShortcircuitAnalysisType type, String filters, String globalFilters, Pageable pageable) {
183+
String resultsPath = getShortCircuitAnalysisResultsPageResourcePath(resultParameters.getResultUuid(), type);
183184
if (resultsPath == null) {
184185
return null;
185186
}
186187

187188
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(shortCircuitServerBaseUri + resultsPath)
189+
.queryParam("rootNetworkUuid", resultParameters.getNetworkUuid())
190+
.queryParam("variantId", resultParameters.getVariantId())
188191
.queryParam("mode", mode);
189192

190193
if (filters != null && !filters.isEmpty()) {
191194
builder.queryParam("filters", filters);
192195
}
193196

197+
if (globalFilters != null && !globalFilters.isEmpty()) {
198+
builder.queryParam("globalFilters", globalFilters);
199+
}
200+
194201
addPageableToQueryParams(builder, pageable);
195202

196203
return getShortCircuitAnalysisResource(builder.build().encode().toUri()); // need to encode because of filter JSON array
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.gridsuite.study.server.utils;
2+
3+
import lombok.Getter;
4+
5+
import java.util.UUID;
6+
7+
@Getter
8+
public final class ResultParameters {
9+
10+
private final UUID rootNetworkUuid;
11+
private final UUID nodeUuid;
12+
private final String variantId;
13+
private final UUID networkUuid;
14+
private final UUID resultUuid;
15+
16+
/**
17+
* Full constructor
18+
*/
19+
public ResultParameters(UUID rootNetworkUuid, UUID nodeUuid, String variantId, UUID networkUuid, UUID resultUuid) {
20+
this.rootNetworkUuid = rootNetworkUuid;
21+
this.nodeUuid = nodeUuid;
22+
this.variantId = variantId;
23+
this.networkUuid = networkUuid;
24+
this.resultUuid = resultUuid;
25+
}
26+
27+
/**
28+
* Minimal constructor
29+
*/
30+
public ResultParameters(UUID rootNetworkUuid, UUID nodeUuid) {
31+
this(rootNetworkUuid, nodeUuid, null, null, null);
32+
}
33+
}

src/test/java/org/gridsuite/study/server/ShortCircuitTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ public MockResponse dispatch(RecordedRequest request) {
224224
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SHORT_CIRCUIT_ANALYSIS_RESULT_JSON);
225225
} else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/fault-types")) {
226226
return new MockResponse(200);
227-
} else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/fault_results/paged" + "\\?mode=FULL&page=0&size=20&sort=id,DESC")) {
227+
} else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/fault_results/paged" + "\\?rootNetworkUuid=" + NETWORK_UUID_STRING + "&variantId=" + VARIANT_ID_2 + "&mode=FULL&page=0&size=20&sort=id,DESC")) {
228228
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SHORT_CIRCUIT_ANALYSIS_RESULT_JSON);
229229
} else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/csv")) {
230230
return new MockResponse.Builder().code(200).body(getBinaryAsBuffer(SHORT_CIRCUIT_ANALYSIS_CSV_RESULT)).addHeader("Content-Type", "application/json; charset=utf-8").build();
231231
} else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID_NOT_FOUND + "/csv")) {
232232
return new MockResponse(404);
233-
} else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/feeder_results/paged" + "\\?mode=FULL&filters=fakeFilters&page=0&size=20&sort=id,DESC")) {
233+
} else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/feeder_results/paged" + "\\?rootNetworkUuid=" + NETWORK_UUID_STRING + "&variantId=" + VARIANT_ID_2 + "&mode=FULL&filters=fakeFilters&page=0&size=20&sort=id,DESC")) {
234234
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SHORT_CIRCUIT_ANALYSIS_RESULT_JSON);
235235
} else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/status")) {
236236
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SHORT_CIRCUIT_ANALYSIS_STATUS_JSON);
@@ -504,7 +504,7 @@ void testPagedShortCircuit(final MockWebServer server) throws Exception {
504504
status().isOk(),
505505
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON));
506506

507-
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/fault_results/paged\\?mode=FULL&page=0&size=20&sort=id,DESC")));
507+
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/fault_results/paged\\?rootNetworkUuid=" + NETWORK_UUID_STRING + "&variantId=variant_2&mode=FULL&page=0&size=20&sort=id,DESC")));
508508

509509
// get short circuit result with pagination but with unknown node
510510
mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/shortcircuit/result?paged=true&page=0&size=20", studyNameUserIdUuid, firstRootNetworkUuid, unknownModificationNodeUuid)).andExpect(
@@ -590,7 +590,7 @@ void testOneBusShortCircuit(final MockWebServer server) throws Exception {
590590
status().isOk(),
591591
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON));
592592

593-
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/feeder_results/paged\\?mode=FULL&filters=fakeFilters&page=0&size=20&sort=id,DESC")));
593+
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/feeder_results/paged\\?rootNetworkUuid=" + NETWORK_UUID_STRING + "&variantId=variant_2&mode=FULL&filters=fakeFilters&page=0&size=20&sort=id,DESC")));
594594

595595
// get one bus short circuit status
596596
mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/shortcircuit/status", studyNameUserIdUuid, firstRootNetworkUuid, modificationNode3Uuid)

0 commit comments

Comments
 (0)