Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1059,11 +1059,11 @@ public byte[] getSecurityAnalysisResult(@Parameter(description = "study UUID") @
@GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/contingency-count")
@Operation(summary = "Get contingency count for a list of contingency list on a study")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The contingency count")})
public ResponseEntity<Integer> getContingencyCount(@Parameter(description = "Study UUID") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "rootNetworkUuid") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
@Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "Contingency list UUIDs") @RequestParam(name = "contingencyListIds", required = false) List<UUID> contingencyListIds) {
return ResponseEntity.ok().body(CollectionUtils.isEmpty(contingencyListIds) ? 0 : studyService.getContingencyCount(studyUuid, contingencyListIds, nodeUuid, rootNetworkUuid));
public ResponseEntity<ContingencyCount> getContingencyCount(@Parameter(description = "Study UUID") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "rootNetworkUuid") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
@Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "Contingency list UUIDs") @RequestParam(name = "contingencyListIds", required = false) List<UUID> contingencyListIds) {
return ResponseEntity.ok().body(CollectionUtils.isEmpty(contingencyListIds) ? ActionsService.EMPTY_CONTINGENCY_COUNT : studyService.getContingencyCount(studyUuid, contingencyListIds, nodeUuid, rootNetworkUuid));
}

@GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/limit-violations")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,29 @@ public class ActionsService {
private static final String NETWORK_UUID = "networkUuid";
private static final String CONTINGENCY_LIST_IDS = "ids";

public static final ContingencyCount EMPTY_CONTINGENCY_COUNT = new ContingencyCount(0, 0);

private String actionsServerBaseUri;

public ActionsService(RemoteServicesProperties remoteServicesProperties, RestTemplate restTemplate) {
this.actionsServerBaseUri = remoteServicesProperties.getServiceUri("actions-server");
this.restTemplate = restTemplate;
}

public Integer getContingencyCount(UUID networkUuid, String variantId, List<UUID> contingencyListIds) {
public ContingencyCount getContingencyCount(UUID networkUuid, String variantId, List<UUID> contingencyListIds) {
var uriComponentsBuilder = UriComponentsBuilder
.fromPath(DELIMITER + ACTIONS_API_VERSION + "/contingency-lists/count")
.queryParam(CONTINGENCY_LIST_IDS, contingencyListIds)
.queryParam(NETWORK_UUID, networkUuid);
if (!StringUtils.isBlank(variantId)) {
uriComponentsBuilder.queryParam(QUERY_PARAM_VARIANT_ID, variantId);
}
return restTemplate.exchange(actionsServerBaseUri + uriComponentsBuilder.toUriString(), HttpMethod.GET, null, Integer.class).getBody();
return restTemplate.exchange(
actionsServerBaseUri + uriComponentsBuilder.toUriString(),
HttpMethod.GET,
null,
ContingencyCount.class
).getBody();
}

public void setActionsServerBaseUri(String actionsServerBaseUri) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2026, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.study.server.service;

/**
* @author Radouane KHOUADRI {@literal <redouane.khouadri at rte-france.com>}
*/
public record ContingencyCount(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carojeandat this is a DTO why is it in service/??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in :
#962

int contingencies,
int notFoundElements
) { }
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ private UUID handleSecurityAnalysisRequest(StudyEntity study, UUID nodeUuid, UUI
return result;
}

public Integer getContingencyCount(UUID studyUuid, List<UUID> contingencyListIds, UUID nodeUuid, UUID rootNetworkUuid) {
public ContingencyCount getContingencyCount(UUID studyUuid, List<UUID> contingencyListIds, UUID nodeUuid, UUID rootNetworkUuid) {
Objects.requireNonNull(studyUuid);
Objects.requireNonNull(contingencyListIds);
Objects.requireNonNull(nodeUuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class SecurityAnalysisTest {
private static final byte[] SECURITY_ANALYSIS_NMK_CONTINGENCIES_RESULT_CSV_ZIPPED = {0x02, 0x03};
private static final byte[] SECURITY_ANALYSIS_NMK_CONSTRAINTS_RESULT_CSV_ZIPPED = {0x04, 0x03};
private static final String SECURITY_ANALYSIS_STATUS_JSON = "\"CONVERGED\"";
private static final String CONTINGENCIES_COUNT = "2";
private static final ContingencyCount CONTINGENCIES_COUNT = new ContingencyCount(2, 0);

public static final String SECURITY_ANALYSIS_DEFAULT_PARAMETERS_JSON = "{\"lowVoltageAbsoluteThreshold\":0.0,\"lowVoltageProportionalThreshold\":0.0,\"highVoltageAbsoluteThreshold\":0.0,\"highVoltageProportionalThreshold\":0.0,\"flowProportionalThreshold\":0.1}";
private static final String SECURITY_ANALYSIS_PROFILE_PARAMETERS_JSON = "{\"lowVoltageAbsoluteThreshold\":30.0,\"lowVoltageProportionalThreshold\":0.4,\"highVoltageAbsoluteThreshold\":0.0,\"highVoltageProportionalThreshold\":0.0,\"flowProportionalThreshold\":0.1}";
Expand Down Expand Up @@ -628,26 +628,25 @@ private void testSecurityAnalysisWithRootNetworkUuidAndNodeUuid(UUID studyUuid,
computationServerStubs.verifyComputationStop(resultUuid, Map.of("receiver", WireMock.matching(".*")));

// get contingency count
securityAnalysisServerStubs.stubContingencyListCount(CONTINGENCIES_COUNT, Map.of("ids", equalTo(CONTINGENCY_LIST_ID), "networkUuid", equalTo(NETWORK_UUID_STRING)));
securityAnalysisServerStubs.stubContingencyListCount(objectMapper.writeValueAsString(CONTINGENCIES_COUNT), Map.of("ids", equalTo(CONTINGENCY_LIST_ID), "networkUuid", equalTo(NETWORK_UUID_STRING)));

mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/contingency-count?contingencyListIds={contingencyListId}",
studyUuid, rootNetworkUuid, nodeUuid, CONTINGENCY_LIST_ID))
.andReturn();
resultAsString = mvcResult.getResponse().getContentAsString();
Integer integerResponse = Integer.parseInt(resultAsString);
Integer expectedResponse = Integer.parseInt(CONTINGENCIES_COUNT);
assertEquals(expectedResponse, integerResponse);
ContingencyCount count = objectMapper.readValue(resultAsString, ContingencyCount.class);
Integer expectedResponse = CONTINGENCIES_COUNT.contingencies();
assertEquals(expectedResponse, count.contingencies());

securityAnalysisServerStubs.verifyContingencyListCount(Map.of("ids", WireMock.matching(".*")));

// get contingency count with no list
securityAnalysisServerStubs.stubContingencyListCount("0", Map.of("networkUuid", equalTo(NETWORK_UUID_STRING)));
mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/contingency-count",
studyUuid, rootNetworkUuid, nodeUuid))
.andReturn();
resultAsString = mvcResult.getResponse().getContentAsString();
Integer integerResponse2 = Integer.parseInt(resultAsString);
assertEquals(0, integerResponse2);
ContingencyCount count2 = objectMapper.readValue(resultAsString, ContingencyCount.class);
assertEquals(0, count2.contingencies());

}

Expand Down