Skip to content

Commit c8d57a2

Browse files
authored
add globalFilters to getSecurityAnalysisResult endpoint (#803)
Signed-off-by: Rehili Ghazwa <[email protected]>
1 parent bc6dfa6 commit c8d57a2

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

src/main/java/org/gridsuite/study/server/StudyConstants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ private StudyConstants() {
5050
public static final String QUERY_PARAM_INFO_TYPE = "infoType";
5151
public static final String QUERY_PARAM_OPTIONAL_PARAMS = "optionalParameters";
5252
public static final String QUERY_FORMAT_OPTIONAL_PARAMS = QUERY_PARAM_OPTIONAL_PARAMS + "[%s]";
53-
public static final String QUERY_PARAM_SUBSTATIONS_IDS = "substationsIds";
5453
public static final String QUERY_PARAM_SUBSTATION_ID = "substationId";
5554
public static final String QUERY_PARAM_RESULTS_UUIDS = "resultsUuids";
5655
public static final String QUERY_PARAM_RESULT_UUID = "resultUuid";

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,8 +983,9 @@ public ResponseEntity<String> getSecurityAnalysisResult(@Parameter(description =
983983
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid,
984984
@Parameter(description = "result type") @RequestParam(name = "resultType") SecurityAnalysisResultType resultType,
985985
@Parameter(description = "JSON array of filters") @RequestParam(name = "filters", required = false) String filters,
986+
@Parameter(description = "JSON array of global filters") @RequestParam(name = "globalFilters", required = false) String globalFilters,
986987
Pageable pageable) {
987-
String result = rootNetworkNodeInfoService.getSecurityAnalysisResult(nodeUuid, rootNetworkUuid, resultType, filters, pageable);
988+
String result = rootNetworkNodeInfoService.getSecurityAnalysisResult(nodeUuid, rootNetworkUuid, resultType, filters, globalFilters, pageable);
988989
return result != null ? ResponseEntity.ok().body(result) :
989990
ResponseEntity.noContent().build();
990991
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,13 @@ public String getLoadFlowResult(UUID nodeUuid, UUID rootNetworkUuid, String filt
541541
}
542542

543543
@Transactional(readOnly = true)
544-
public String getSecurityAnalysisResult(UUID nodeUuid, UUID rootNetworkUuid, SecurityAnalysisResultType resultType, String filters, Pageable pageable) {
544+
public String getSecurityAnalysisResult(UUID nodeUuid, UUID rootNetworkUuid, SecurityAnalysisResultType resultType, String filters, String globalFilters, Pageable pageable) {
545+
RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(nodeUuid, rootNetworkUuid).orElseThrow(()
546+
-> new StudyException(ROOT_NETWORK_NOT_FOUND));
547+
String variantId = rootNetworkNodeInfoEntity.getVariantId();
548+
UUID networkUuid = rootNetworkNodeInfoEntity.getRootNetwork().getNetworkUuid();
545549
UUID resultUuid = getComputationResultUuid(nodeUuid, rootNetworkUuid, SECURITY_ANALYSIS);
546-
return securityAnalysisService.getSecurityAnalysisResult(resultUuid, resultType, filters, pageable);
550+
return securityAnalysisService.getSecurityAnalysisResult(resultUuid, networkUuid, variantId, resultType, filters, globalFilters, pageable);
547551
}
548552

549553
@Transactional(readOnly = true)

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
import org.apache.commons.lang3.StringUtils;
1313
import org.gridsuite.study.server.RemoteServicesProperties;
1414
import org.gridsuite.study.server.StudyException;
15-
import org.gridsuite.study.server.dto.*;
15+
import org.gridsuite.study.server.dto.NodeReceiver;
16+
import org.gridsuite.study.server.dto.ReportInfos;
17+
import org.gridsuite.study.server.dto.RunSecurityAnalysisParametersInfos;
18+
import org.gridsuite.study.server.dto.SecurityAnalysisStatus;
1619
import org.gridsuite.study.server.repository.StudyEntity;
1720
import org.gridsuite.study.server.service.common.AbstractComputationService;
1821
import org.gridsuite.study.server.service.securityanalysis.SecurityAnalysisResultType;
@@ -62,7 +65,7 @@ public SecurityAnalysisService(RemoteServicesProperties remoteServicesProperties
6265
this.restTemplate = restTemplate;
6366
}
6467

65-
public String getSecurityAnalysisResult(UUID resultUuid, SecurityAnalysisResultType resultType, String filters, Pageable pageable) {
68+
public String getSecurityAnalysisResult(UUID resultUuid, UUID networkUuid, String variantId, SecurityAnalysisResultType resultType, String filters, String globalFilters, Pageable pageable) {
6669
String result;
6770

6871
if (resultUuid == null) {
@@ -77,6 +80,14 @@ public String getSecurityAnalysisResult(UUID resultUuid, SecurityAnalysisResultT
7780
pathBuilder.queryParam("filters", URLEncoder.encode(filters, StandardCharsets.UTF_8));
7881
}
7982

83+
if (!StringUtils.isEmpty(globalFilters)) {
84+
pathBuilder.queryParam("globalFilters", URLEncoder.encode(globalFilters, StandardCharsets.UTF_8));
85+
pathBuilder.queryParam("networkUuid", networkUuid);
86+
if (!StringUtils.isBlank(variantId)) {
87+
pathBuilder.queryParam(QUERY_PARAM_VARIANT_ID, variantId);
88+
}
89+
}
90+
8091
for (Sort.Order order : pageable.getSort()) {
8192
pathBuilder.queryParam("sort", order.getProperty() + "," + order.getDirection());
8293
}

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.gridsuite.study.server.repository.nonevacuatedenergy.NonEvacuatedEnergyParametersEntity;
3030
import org.gridsuite.study.server.repository.rootnetwork.RootNetworkNodeInfoRepository;
3131
import org.gridsuite.study.server.service.*;
32-
import org.gridsuite.study.server.service.LoadFlowService;
3332
import org.gridsuite.study.server.service.securityanalysis.SecurityAnalysisResultType;
3433
import org.gridsuite.study.server.utils.TestUtils;
3534
import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch;
@@ -223,11 +222,11 @@ public MockResponse dispatch(RecordedRequest request) {
223222
} else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_RESULT_UUID + "/limit-types")
224223
|| ("/v1/results/" + SECURITY_ANALYSIS_OTHER_NODE_RESULT_UUID + "/limit-types").equals(path)) {
225224
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), limitTypeJson);
226-
} else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_RESULT_UUID + "/n-result\\?page=.*size=.*filters=.*sort=.*")) {
225+
} else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_RESULT_UUID + "/n-result\\?page=.*size=.*filters=.*globalFilters=.*sort=.*")) {
227226
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SECURITY_ANALYSIS_N_RESULT_JSON);
228-
} else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_RESULT_UUID + "/nmk-contingencies-result/paged\\?page=.*size=.*filters=.*sort=.*")) {
227+
} else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_RESULT_UUID + "/nmk-contingencies-result/paged\\?page=.*size=.*filters=.*globalFilters=.*sort=.*")) {
229228
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SECURITY_ANALYSIS_NMK_CONTINGENCIES_RESULT_JSON);
230-
} else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_RESULT_UUID + "/nmk-constraints-result/paged\\?page=.*size=.*filters=.*sort=.*")) {
229+
} else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_RESULT_UUID + "/nmk-constraints-result/paged\\?page=.*size=.*filters=.*globalFilters=.*sort=.*")) {
231230
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SECURITY_ANALYSIS_NMK_CONSTRAINTS_RESULT_JSON);
232231
} else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_RESULT_UUID + "/n-result/csv")) {
233232
return new MockResponse.Builder().code(200).body(getBinaryAsBuffer(SECURITY_ANALYSIS_N_RESULT_CSV_ZIPPED))
@@ -256,11 +255,11 @@ public MockResponse dispatch(RecordedRequest request) {
256255
} else if (path.matches("/v1/contingency-lists/count\\?ids=" + CONTINGENCY_LIST_NAME + "&networkUuid=" + NETWORK_UUID_STRING)
257256
|| path.matches("/v1/contingency-lists/count\\?ids=" + CONTINGENCY_LIST_NAME + "&networkUuid=" + NETWORK_UUID_STRING + "&variantId=.*")) {
258257
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), CONTINGENCIES_COUNT);
259-
} else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_OTHER_NODE_RESULT_UUID + "/n-result\\?page=.*size=.*filters=.*sort=.*")) {
258+
} else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_OTHER_NODE_RESULT_UUID + "/n-result\\?page=.*size=.*filters=.*globalFilters=.*sort=.*")) {
260259
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SECURITY_ANALYSIS_N_RESULT_JSON);
261-
} else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_OTHER_NODE_RESULT_UUID + "/nmk-contingencies-result/paged\\?page=.*size=.*filters=.*sort=.*")) {
260+
} else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_OTHER_NODE_RESULT_UUID + "/nmk-contingencies-result/paged\\?page=.*size=.*filters=.*globalFilters=.*sort=.*")) {
262261
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SECURITY_ANALYSIS_NMK_CONTINGENCIES_RESULT_JSON);
263-
} else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_OTHER_NODE_RESULT_UUID + "/nmk-constraints-result/paged\\?page=.*size=.*filters=.*sort=.*")) {
262+
} else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_OTHER_NODE_RESULT_UUID + "/nmk-constraints-result/paged\\?page=.*size=.*filters=.*globalFilters=.*sort=.*")) {
264263
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SECURITY_ANALYSIS_NMK_CONSTRAINTS_RESULT_JSON);
265264
} else if (("/v1/results/" + SECURITY_ANALYSIS_OTHER_NODE_RESULT_UUID + "/status").equals(path)) {
266265
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), SECURITY_ANALYSIS_STATUS_JSON);
@@ -528,25 +527,25 @@ private void testSecurityAnalysisWithRootNetworkUuidAndNodeUuid(final MockWebSer
528527
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/results/" + resultUuid + "/limit-types")));
529528

530529
// get N security analysis result
531-
mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/security-analysis/result?resultType={resultType}&page=0&size=10&filters=random_filters&sort=random_sort", studyUuid, rootNetworkUuid, nodeUuid, SecurityAnalysisResultType.N)).andExpectAll(
530+
mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/security-analysis/result?resultType={resultType}&page=0&size=10&filters=random_filters&globalFilters=random_globalfilters&sort=random_sort", studyUuid, rootNetworkUuid, nodeUuid, SecurityAnalysisResultType.N)).andExpectAll(
532531
status().isOk(),
533532
content().string(SECURITY_ANALYSIS_N_RESULT_JSON));
534533

535-
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches(String.format("/v1/results/%s/n-result\\?page=.*size=.*filters=.*sort=.*", resultUuid))));
534+
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches(String.format("/v1/results/%s/n-result\\?page=.*size=.*filters=.*globalFilters=.*sort=.*", resultUuid))));
536535

537536
// get NMK_CONTINGENCIES security analysis result
538-
mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/security-analysis/result?resultType={resultType}&page=0&size=10&filters=random_filters&sort=random_sort", studyUuid, rootNetworkUuid, nodeUuid, SecurityAnalysisResultType.NMK_CONTINGENCIES)).andExpectAll(
537+
mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/security-analysis/result?resultType={resultType}&page=0&size=10&filters=random_filters&globalFilters=random_globalfilters&sort=random_sort", studyUuid, rootNetworkUuid, nodeUuid, SecurityAnalysisResultType.NMK_CONTINGENCIES)).andExpectAll(
539538
status().isOk(),
540539
content().string(SECURITY_ANALYSIS_NMK_CONTINGENCIES_RESULT_JSON));
541540

542-
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches(String.format("/v1/results/%s/nmk-contingencies-result/paged\\?page=.*size=.*filters=.*sort=.*", resultUuid))));
541+
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches(String.format("/v1/results/%s/nmk-contingencies-result/paged\\?page=.*size=.*filters=.*globalFilters=.*sort=.*", resultUuid))));
543542

544543
// get NMK_CONSTRAINTS security analysis result
545-
mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/security-analysis/result?resultType={resultType}&page=0&size=10&filters=random_filters&sort=random_sort", studyUuid, rootNetworkUuid, nodeUuid, SecurityAnalysisResultType.NMK_LIMIT_VIOLATIONS)).andExpectAll(
544+
mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/security-analysis/result?resultType={resultType}&page=0&size=10&filters=random_filters&globalFilters=random_globalfilters&sort=random_sort", studyUuid, rootNetworkUuid, nodeUuid, SecurityAnalysisResultType.NMK_LIMIT_VIOLATIONS)).andExpectAll(
546545
status().isOk(),
547546
content().string(SECURITY_ANALYSIS_NMK_CONSTRAINTS_RESULT_JSON));
548547

549-
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches(String.format("/v1/results/%s/nmk-constraints-result/paged\\?page=.*size=.*filters=.*sort=.*", resultUuid))));
548+
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches(String.format("/v1/results/%s/nmk-constraints-result/paged\\?page=.*size=.*filters=.*globalFilters=.*sort=.*", resultUuid))));
550549

551550
// get security analysis status
552551
MvcResult result = mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/security-analysis/status", studyUuid, rootNetworkUuid, nodeUuid)).andExpectAll(

0 commit comments

Comments
 (0)