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
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
import org.gridsuite.study.server.dto.ElementAttributes;
import org.gridsuite.study.server.dto.networkexport.PermissionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

import java.util.List;
import java.util.UUID;
import java.util.*;

import static org.gridsuite.study.server.StudyConstants.*;

Expand Down Expand Up @@ -56,6 +57,37 @@ public String getElementName(UUID elementUuid) {
return restTemplate.getForObject(getDirectoryServerServerBaseUri() + path, String.class);
}

public Map<UUID, String> getElementNames(Set<UUID> elementUuids) {
Objects.requireNonNull(elementUuids);

if (elementUuids.isEmpty()) {
return Map.of();
}

String path = UriComponentsBuilder
.fromPath(DELIMITER + DIRECTORY_API_VERSION + "/elements/names")
.queryParam("ids", elementUuids)
.queryParam("strictMode", "false") // to ignore non existing elements error
.buildAndExpand()
.toUriString();

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

try {
Map<UUID, String> body = restTemplate.exchange(
getDirectoryServerServerBaseUri() + path,
HttpMethod.GET,
new HttpEntity<>(headers),
new ParameterizedTypeReference<Map<UUID, String>>() { }
).getBody();
return body != null ? body : Map.of();

} catch (RestClientException e) {
return Map.of();
}
}

public boolean elementExists(UUID directoryUuid, String elementName, String type) {
UriComponentsBuilder pathBuilder = UriComponentsBuilder.fromPath(DELIMITER + DIRECTORY_API_VERSION + "/directories/{directoryUuid}/elements/{elementName}/types/{type}");
String path = pathBuilder.buildAndExpand(directoryUuid, elementName, type).toUriString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.*;

import static org.gridsuite.study.server.StudyConstants.*;
import static org.gridsuite.study.server.error.StudyBusinessErrorCode.*;
Expand Down Expand Up @@ -67,7 +65,8 @@ public UUID runSensitivityAnalysis(UUID nodeUuid, UUID rootNetworkUuid, UUID net
UUID reportUuid,
String userId,
UUID parametersUuid,
UUID loadFlowParametersUuid) {
UUID loadFlowParametersUuid,
Map<UUID, String> elementNamesMap) {
String receiver;
try {
receiver = URLEncoder.encode(objectMapper.writeValueAsString(new NodeReceiver(nodeUuid, rootNetworkUuid)), StandardCharsets.UTF_8);
Expand All @@ -88,8 +87,10 @@ public UUID runSensitivityAnalysis(UUID nodeUuid, UUID rootNetworkUuid, UUID net
if (!StringUtils.isBlank(variantId)) {
uriComponentsBuilder.queryParam(QUERY_PARAM_VARIANT_ID, variantId);
}
// add query param Map container ids -> container names
var path = uriComponentsBuilder
.queryParam(QUERY_PARAM_RECEIVER, receiver)
.queryParam("elementNamesMap", elementNamesMap)
.buildAndExpand(networkUuid).toUriString();

HttpHeaders headers = new HttpHeaders();
Expand Down Expand Up @@ -338,4 +339,7 @@ public String getSensitivityAnalysisFactorCount(UUID networkUuid, String variant
public List<String> getEnumValues(String enumName, UUID resultUuidOpt) {
return List.of();
}

public List<UUID> getContainerIds(UUID sensiParamsUuid) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2699,7 +2699,14 @@ private UUID handleSensitivityAnalysisRequest(StudyEntity study, UUID nodeUuid,
UUID sensiReportUuid = networkModificationTreeService.getComputationReports(nodeUuid, rootNetworkUuid).getOrDefault(SENSITIVITY_ANALYSIS.name(), UUID.randomUUID());
networkModificationTreeService.updateComputationReportUuid(nodeUuid, rootNetworkUuid, SENSITIVITY_ANALYSIS, sensiReportUuid);

UUID result = sensitivityAnalysisService.runSensitivityAnalysis(nodeUuid, rootNetworkUuid, networkUuid, variantId, sensiReportUuid, userId, study.getSensitivityAnalysisParametersUuid(), study.getLoadFlowParametersUuid());
UUID sensiParamsUuid = study.getSensitivityAnalysisParametersUuid();

// fetch the filters and contingencyLists contained in sensi parameters
// and retrieve their names, as they are needed in the results
List<UUID> elementIds = sensitivityAnalysisService.getContainerIds(sensiParamsUuid);
Map<UUID, String> elementNamesMap = directoryService.getElementNames(new HashSet<>(elementIds));

UUID result = sensitivityAnalysisService.runSensitivityAnalysis(nodeUuid, rootNetworkUuid, networkUuid, variantId, sensiReportUuid, userId, sensiParamsUuid, study.getLoadFlowParametersUuid(), elementNamesMap);

updateComputationResultUuid(nodeUuid, rootNetworkUuid, result, SENSITIVITY_ANALYSIS);
notificationService.emitStudyChanged(study.getId(), nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS);
Expand Down
Loading