diff --git a/src/main/java/org/gridsuite/study/server/controller/StudyController.java b/src/main/java/org/gridsuite/study/server/controller/StudyController.java index eb600d4ae..4386bbcad 100644 --- a/src/main/java/org/gridsuite/study/server/controller/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/controller/StudyController.java @@ -45,6 +45,7 @@ import org.gridsuite.study.server.service.securityanalysis.SecurityAnalysisResultType; import org.gridsuite.study.server.service.shortcircuit.FaultResultsMode; import org.gridsuite.study.server.service.shortcircuit.ShortcircuitAnalysisType; +import org.gridsuite.study.server.utils.ResultParameters; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.util.Pair; @@ -816,17 +817,18 @@ public ResponseEntity stopShortCircuitAnalysis(@Parameter(description = "S @ApiResponse(responseCode = "204", description = "No short circuit analysis has been done yet"), @ApiResponse(responseCode = "404", description = "The short circuit analysis has not been found")}) public ResponseEntity getShortCircuitResult(@Parameter(description = "study UUID") @PathVariable("studyUuid") UUID studyUuid, - @PathVariable("rootNetworkUuid") UUID rootNetworkUuid, - @Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid, + @Parameter(description = "root network UUID") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid, + @Parameter(description = "node UUID") @PathVariable("nodeUuid") UUID nodeUuid, @Parameter(description = "BASIC (faults without limits and feeders), " + "FULL (faults with both), " + "WITH_LIMIT_VIOLATIONS (like FULL but only those with limit violations) or " + "NONE (no fault)") @RequestParam(name = "mode", required = false, defaultValue = "FULL") FaultResultsMode mode, @Parameter(description = "type") @RequestParam(value = "type", required = false, defaultValue = "ALL_BUSES") ShortcircuitAnalysisType type, @Parameter(description = "JSON array of filters") @RequestParam(name = "filters", required = false) String filters, + @Parameter(description = "JSON array of global filters") @RequestParam(name = "globalFilters", required = false) String globalFilters, @Parameter(description = "If we wanted the paged version of the results or not") @RequestParam(name = "paged", required = false, defaultValue = "false") boolean paged, Pageable pageable) { - String result = rootNetworkNodeInfoService.getShortCircuitAnalysisResult(nodeUuid, rootNetworkUuid, mode, type, filters, paged, pageable); + String result = rootNetworkNodeInfoService.getShortCircuitAnalysisResult(new ResultParameters(rootNetworkUuid, nodeUuid), mode, type, filters, globalFilters, paged, pageable); return result != null ? ResponseEntity.ok().body(result) : ResponseEntity.noContent().build(); } diff --git a/src/main/java/org/gridsuite/study/server/service/ConsumerService.java b/src/main/java/org/gridsuite/study/server/service/ConsumerService.java index fee200b1e..682317ed1 100644 --- a/src/main/java/org/gridsuite/study/server/service/ConsumerService.java +++ b/src/main/java/org/gridsuite/study/server/service/ConsumerService.java @@ -553,7 +553,7 @@ public void consumeCalculationFailed(Message msg, ComputationType comput try { receiverObj = objectMapper.readValue(URLDecoder.decode(receiver, StandardCharsets.UTF_8), NodeReceiver.class); - LOGGER.info("{} failed for node '{}' with error messsage: {}", computationType.getLabel(), receiverObj.getNodeUuid(), errorMessage); + LOGGER.info("{} failed for node '{}' with error message: {}", computationType.getLabel(), receiverObj.getNodeUuid(), errorMessage); // delete computation results from the databases // ==> 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 diff --git a/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java b/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java index 302774b18..5b047ce13 100644 --- a/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java +++ b/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java @@ -33,6 +33,7 @@ import org.gridsuite.study.server.service.shortcircuit.FaultResultsMode; import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; import org.gridsuite.study.server.service.shortcircuit.ShortcircuitAnalysisType; +import org.gridsuite.study.server.utils.ResultParameters; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; @@ -603,10 +604,15 @@ public String getNonEvacuatedEnergyResult(UUID nodeUuid, UUID rootNetworkUuid) { } @Transactional(readOnly = true) - public String getShortCircuitAnalysisResult(UUID nodeUuid, UUID rootNetworkUuid, FaultResultsMode mode, ShortcircuitAnalysisType type, String filters, boolean paged, Pageable pageable) { - UUID resultUuid = getComputationResultUuid(nodeUuid, rootNetworkUuid, - type == ShortcircuitAnalysisType.ALL_BUSES ? SHORT_CIRCUIT : SHORT_CIRCUIT_ONE_BUS); - return shortCircuitService.getShortCircuitAnalysisResult(resultUuid, mode, type, filters, paged, pageable); + public String getShortCircuitAnalysisResult(ResultParameters resultParameters, FaultResultsMode mode, ShortcircuitAnalysisType type, String filters, String globalFilters, boolean paged, Pageable pageable) { + RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(resultParameters.getNodeUuid(), resultParameters.getRootNetworkUuid()).orElse(null); + ResultParameters resultParametersEnriched = new ResultParameters( + resultParameters.getRootNetworkUuid(), + resultParameters.getNodeUuid(), + rootNetworkNodeInfoEntity == null ? null : rootNetworkNodeInfoEntity.getVariantId(), + rootNetworkNodeInfoEntity == null ? resultParameters.getRootNetworkUuid() : rootNetworkNodeInfoEntity.getRootNetwork().getNetworkUuid(), + getComputationResultUuid(resultParameters.getNodeUuid(), resultParameters.getRootNetworkUuid(), type == ShortcircuitAnalysisType.ALL_BUSES ? SHORT_CIRCUIT : SHORT_CIRCUIT_ONE_BUS)); + return shortCircuitService.getShortCircuitAnalysisResult(resultParametersEnriched, mode, type, filters, globalFilters, paged, pageable); } @Transactional(readOnly = true) diff --git a/src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java b/src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java index f2ce16ed0..733c9a414 100644 --- a/src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java +++ b/src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java @@ -18,6 +18,7 @@ import org.gridsuite.study.server.dto.ShortCircuitStatus; import org.gridsuite.study.server.service.StudyService; import org.gridsuite.study.server.service.common.AbstractComputationService; +import org.gridsuite.study.server.utils.ResultParameters; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; import org.springframework.http.*; @@ -122,11 +123,11 @@ private String getShortCircuitAnalysisResultsPageResourcePath(UUID resultUuid, S return resultPath + "/paged"; } - public String getShortCircuitAnalysisResult(UUID resultUuid, FaultResultsMode mode, ShortcircuitAnalysisType type, String filters, boolean paged, Pageable pageable) { + public String getShortCircuitAnalysisResult(ResultParameters resultParameters, FaultResultsMode mode, ShortcircuitAnalysisType type, String filters, String globalFilters, boolean paged, Pageable pageable) { if (paged) { - return getShortCircuitAnalysisResultsPage(resultUuid, mode, type, filters, pageable); + return getShortCircuitAnalysisResultsPage(resultParameters, mode, type, filters, globalFilters, pageable); } else { - return getShortCircuitAnalysisResult(resultUuid, mode); + return getShortCircuitAnalysisResult(resultParameters.getResultUuid(), mode); } } @@ -170,19 +171,25 @@ public String getShortCircuitAnalysisResult(UUID resultUuid, FaultResultsMode mo return getShortCircuitAnalysisResource(builder.build().toUri()); } - public String getShortCircuitAnalysisResultsPage(UUID resultUuid, FaultResultsMode mode, ShortcircuitAnalysisType type, String filters, Pageable pageable) { - String resultsPath = getShortCircuitAnalysisResultsPageResourcePath(resultUuid, type); + public String getShortCircuitAnalysisResultsPage(ResultParameters resultParameters, FaultResultsMode mode, ShortcircuitAnalysisType type, String filters, String globalFilters, Pageable pageable) { + String resultsPath = getShortCircuitAnalysisResultsPageResourcePath(resultParameters.getResultUuid(), type); if (resultsPath == null) { return null; } UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(shortCircuitServerBaseUri + resultsPath) + .queryParam("rootNetworkUuid", resultParameters.getNetworkUuid()) + .queryParam("variantId", resultParameters.getVariantId()) .queryParam("mode", mode); if (filters != null && !filters.isEmpty()) { builder.queryParam("filters", filters); } + if (globalFilters != null && !globalFilters.isEmpty()) { + builder.queryParam("globalFilters", globalFilters); + } + addPageableToQueryParams(builder, pageable); return getShortCircuitAnalysisResource(builder.build().encode().toUri()); // need to encode because of filter JSON array diff --git a/src/main/java/org/gridsuite/study/server/utils/ResultParameters.java b/src/main/java/org/gridsuite/study/server/utils/ResultParameters.java new file mode 100644 index 000000000..59e8a9806 --- /dev/null +++ b/src/main/java/org/gridsuite/study/server/utils/ResultParameters.java @@ -0,0 +1,33 @@ +package org.gridsuite.study.server.utils; + +import lombok.Getter; + +import java.util.UUID; + +@Getter +public final class ResultParameters { + + private final UUID rootNetworkUuid; + private final UUID nodeUuid; + private final String variantId; + private final UUID networkUuid; + private final UUID resultUuid; + + /** + * Full constructor + */ + public ResultParameters(UUID rootNetworkUuid, UUID nodeUuid, String variantId, UUID networkUuid, UUID resultUuid) { + this.rootNetworkUuid = rootNetworkUuid; + this.nodeUuid = nodeUuid; + this.variantId = variantId; + this.networkUuid = networkUuid; + this.resultUuid = resultUuid; + } + + /** + * Minimal constructor + */ + public ResultParameters(UUID rootNetworkUuid, UUID nodeUuid) { + this(rootNetworkUuid, nodeUuid, null, null, null); + } +} diff --git a/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java b/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java index 2b827153d..149b49d92 100644 --- a/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java +++ b/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java @@ -223,13 +223,13 @@ public MockResponse dispatch(RecordedRequest request) { return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SHORT_CIRCUIT_ANALYSIS_RESULT_JSON); } else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/fault-types")) { return new MockResponse(200); - } else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/fault_results/paged" + "\\?mode=FULL&page=0&size=20&sort=id,DESC")) { + } 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")) { return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SHORT_CIRCUIT_ANALYSIS_RESULT_JSON); } else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/csv")) { return new MockResponse.Builder().code(200).body(getBinaryAsBuffer(SHORT_CIRCUIT_ANALYSIS_CSV_RESULT)).addHeader("Content-Type", "application/json; charset=utf-8").build(); } else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID_NOT_FOUND + "/csv")) { return new MockResponse(404); - } 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")) { + } 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")) { return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SHORT_CIRCUIT_ANALYSIS_RESULT_JSON); } else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/status")) { return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SHORT_CIRCUIT_ANALYSIS_STATUS_JSON); @@ -502,7 +502,7 @@ void testPagedShortCircuit(final MockWebServer server) throws Exception { status().isOk(), content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON)); - 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"))); + 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"))); // get short circuit result with pagination but with unknown node mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/shortcircuit/result?paged=true&page=0&size=20", studyNameUserIdUuid, firstRootNetworkUuid, unknownModificationNodeUuid)).andExpect( @@ -588,7 +588,7 @@ void testOneBusShortCircuit(final MockWebServer server) throws Exception { status().isOk(), content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON)); - 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"))); + 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"))); // get one bus short circuit status mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/shortcircuit/status", studyNameUserIdUuid, firstRootNetworkUuid, modificationNode3Uuid)