-
Notifications
You must be signed in to change notification settings - Fork 0
[DRAFT] Move contingency lists to SA parameters #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,20 @@ | ||||||||||||||||||
| package org.gridsuite.securityanalysis.server.dto; | ||||||||||||||||||
|
|
||||||||||||||||||
| import lombok.AllArgsConstructor; | ||||||||||||||||||
| import lombok.Getter; | ||||||||||||||||||
| import lombok.NoArgsConstructor; | ||||||||||||||||||
| import lombok.Setter; | ||||||||||||||||||
|
|
||||||||||||||||||
| import java.util.UUID; | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * @author Caroline Jeandat {@literal <caroline.jeandat at rte-france.com>} | ||||||||||||||||||
| */ | ||||||||||||||||||
| @NoArgsConstructor | ||||||||||||||||||
| @AllArgsConstructor | ||||||||||||||||||
| @Getter | ||||||||||||||||||
| @Setter | ||||||||||||||||||
| public class ParametersContingenciesDTO { | ||||||||||||||||||
| UUID id; | ||||||||||||||||||
| String name; | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+17
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
IMO, a simple name such as IdNameInfos is enough and generic to be reused if need, for example filters |
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Copyright (c) 2025, RTE (http://www.rte-france.com) | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
| * 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.securityanalysis.server.dto; | ||||||||||||||||||||||
| import lombok.*; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * @author Caroline Jeandat {@literal <caroline.jeandat at rte-france.com>} | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| @Builder | ||||||||||||||||||||||
| @AllArgsConstructor | ||||||||||||||||||||||
| @NoArgsConstructor | ||||||||||||||||||||||
| @Getter | ||||||||||||||||||||||
| @Setter | ||||||||||||||||||||||
| public class ParametersContingencyListDTO { | ||||||||||||||||||||||
| List<ParametersContingenciesDTO> contingencies; | ||||||||||||||||||||||
| String description; | ||||||||||||||||||||||
| boolean activated; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+20
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
IMO, we should move SecurityAnalysisParametersValues, LimitReductionsByVoltageLevel, ContingencyListsInfos, IdNameInfos to package dto/parameters We can do the same for results but later when we work on results |
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,49 @@ | ||||||||||||||||||||
| package org.gridsuite.securityanalysis.server.entities; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import jakarta.persistence.*; | ||||||||||||||||||||
| import lombok.Getter; | ||||||||||||||||||||
| import lombok.NoArgsConstructor; | ||||||||||||||||||||
| import lombok.Setter; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||
| import java.util.UUID; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * @author Caroline Jeandat {@literal <caroline.jeandat at rte-france.com>} | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| @Getter | ||||||||||||||||||||
| @Setter | ||||||||||||||||||||
| @NoArgsConstructor | ||||||||||||||||||||
| @Entity | ||||||||||||||||||||
| @Table(name = "parameters_contingency_list", indexes = {@Index(name = "idx_security_analysis_parameters_id_contingency_lists", columnList = "security_analysis_parameters_id")}) | ||||||||||||||||||||
| public class ParametersContingencyListEntity { | ||||||||||||||||||||
|
Comment on lines
+18
to
+19
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| @Id | ||||||||||||||||||||
| @GeneratedValue(strategy = GenerationType.UUID) | ||||||||||||||||||||
| @Column(name = "contingency_list_id") | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
| private UUID id; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @ElementCollection | ||||||||||||||||||||
| @CollectionTable( | ||||||||||||||||||||
| name = "parameters_contingency_list_contingencies", | ||||||||||||||||||||
| joinColumns = @JoinColumn(name = "contingency_list_id") | ||||||||||||||||||||
| ) | ||||||||||||||||||||
|
Comment on lines
+27
to
+30
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
| @Column(name = "contingencies_id") | ||||||||||||||||||||
| private List<UUID> contingenciesIds; | ||||||||||||||||||||
|
Comment on lines
+31
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| @Column(name = "description") | ||||||||||||||||||||
| private String description; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @Column(name = "activated") | ||||||||||||||||||||
| private boolean activated; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @ManyToOne | ||||||||||||||||||||
| @JoinColumn(name = "security_analysis_parameters_id") | ||||||||||||||||||||
| private SecurityAnalysisParametersEntity securityAnalysisParameters; | ||||||||||||||||||||
|
Comment on lines
+40
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, I dont think we really need a reverse direction from child to parent |
||||||||||||||||||||
|
|
||||||||||||||||||||
| public ParametersContingencyListEntity(List<UUID> contingenciesIds, String description, boolean activated) { | ||||||||||||||||||||
| this.contingenciesIds = contingenciesIds; | ||||||||||||||||||||
| this.description = description; | ||||||||||||||||||||
| this.activated = activated; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |||||||||||||||||
|
|
||||||||||||||||||
| import jakarta.persistence.*; | ||||||||||||||||||
| import lombok.*; | ||||||||||||||||||
| import org.gridsuite.securityanalysis.server.dto.ParametersContingenciesDTO; | ||||||||||||||||||
| import org.gridsuite.securityanalysis.server.dto.ParametersContingencyListDTO; | ||||||||||||||||||
| import org.gridsuite.securityanalysis.server.dto.SecurityAnalysisParametersValues; | ||||||||||||||||||
| import org.springframework.lang.Nullable; | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -55,11 +57,26 @@ public SecurityAnalysisParametersEntity(SecurityAnalysisParametersValues securit | |||||||||||||||||
| @Column(name = "flowProportionalThreshold") | ||||||||||||||||||
| private double flowProportionalThreshold; | ||||||||||||||||||
|
|
||||||||||||||||||
| @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "securityAnalysisParameters") | ||||||||||||||||||
| @OrderColumn(name = "index") | ||||||||||||||||||
| @Builder.Default | ||||||||||||||||||
| private List<ParametersContingencyListEntity> contingencyLists = new ArrayList<>(); | ||||||||||||||||||
|
|
||||||||||||||||||
| @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) | ||||||||||||||||||
| @JoinColumn(name = "security_analysis_parameters_id", foreignKey = @ForeignKey(name = "securityAnalysisParametersEntity_limitReductions_fk")) | ||||||||||||||||||
| @OrderColumn(name = "index") | ||||||||||||||||||
| private List<LimitReductionEntity> limitReductions; | ||||||||||||||||||
|
|
||||||||||||||||||
| public List<UUID> getActivatedContingencyListUuids() { | ||||||||||||||||||
| if (contingencyLists == null) { | ||||||||||||||||||
| return List.of(); | ||||||||||||||||||
| } | ||||||||||||||||||
| return this.contingencyLists.stream() | ||||||||||||||||||
| .filter(ParametersContingencyListEntity::isActivated) | ||||||||||||||||||
| .flatMap(contingencyList -> contingencyList.getContingenciesIds().stream()) | ||||||||||||||||||
| .toList(); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| public List<List<Double>> toLimitReductionsValues() { | ||||||||||||||||||
| return this.limitReductions.stream().map(LimitReductionEntity::getReductions).map(ArrayList::new).collect(Collectors.toList()); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
@@ -75,9 +92,30 @@ private void assignAttributes(SecurityAnalysisParametersValues securityAnalysisP | |||||||||||||||||
| this.highVoltageProportionalThreshold = securityAnalysisParametersValues.getHighVoltageProportionalThreshold(); | ||||||||||||||||||
| this.lowVoltageAbsoluteThreshold = securityAnalysisParametersValues.getLowVoltageAbsoluteThreshold(); | ||||||||||||||||||
| this.lowVoltageProportionalThreshold = securityAnalysisParametersValues.getLowVoltageProportionalThreshold(); | ||||||||||||||||||
| assignContingencyLists(securityAnalysisParametersValues.getContingencyLists()); | ||||||||||||||||||
| assignLimitReductions(securityAnalysisParametersValues.getLimitReductionsValues()); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private void assignContingencyLists(List<ParametersContingencyListDTO> contingencyListsDTO) { | ||||||||||||||||||
| if (contingencyListsDTO == null) { | ||||||||||||||||||
| return; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| List<ParametersContingencyListEntity> entities = contingencyListsDTO.stream() | ||||||||||||||||||
| .map(dto -> { | ||||||||||||||||||
| ParametersContingencyListEntity entity = new ParametersContingencyListEntity( | ||||||||||||||||||
| dto.getContingencies().stream().map(ParametersContingenciesDTO::getId).toList(), | ||||||||||||||||||
| dto.getDescription(), | ||||||||||||||||||
| dto.isActivated() | ||||||||||||||||||
| ); | ||||||||||||||||||
| entity.setSecurityAnalysisParameters(this); | ||||||||||||||||||
| return entity; | ||||||||||||||||||
| }) | ||||||||||||||||||
| .toList(); | ||||||||||||||||||
| contingencyLists.clear(); | ||||||||||||||||||
| contingencyLists.addAll(entities); | ||||||||||||||||||
|
Comment on lines
+115
to
+116
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private void assignLimitReductions(@Nullable List<List<Double>> values) { | ||||||||||||||||||
| if (values == null) { | ||||||||||||||||||
| return; | ||||||||||||||||||
|
|
@@ -95,4 +133,3 @@ public void updateProvider(String provider) { | |||||||||||||||||
| this.provider = provider; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||||||||||||||||
| package org.gridsuite.securityanalysis.server.service; | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| import org.springframework.beans.factory.annotation.Value; | ||||||||||||||||||||
| import org.springframework.core.ParameterizedTypeReference; | ||||||||||||||||||||
| import org.springframework.http.HttpMethod; | ||||||||||||||||||||
| import org.springframework.http.ResponseEntity; | ||||||||||||||||||||
| import org.springframework.stereotype.Service; | ||||||||||||||||||||
| import org.springframework.web.client.HttpClientErrorException; | ||||||||||||||||||||
| import org.springframework.web.client.RestTemplate; | ||||||||||||||||||||
| import org.springframework.web.util.UriComponentsBuilder; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import java.net.URI; | ||||||||||||||||||||
| import java.util.*; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * @author Caroline Jeandat {@literal <caroline.jeandat at rte-france.com>} | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| @Service | ||||||||||||||||||||
| public class DirectoryService { | ||||||||||||||||||||
| static final String DIRECTORY_API_VERSION = "v1"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| private static final String DELIMITER = "/"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| private String baseUri; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| private RestTemplate restTemplate; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| public void setDirectoryServiceBaseUri(String baseUri) { | ||||||||||||||||||||
| this.baseUri = baseUri; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| public DirectoryService( | ||||||||||||||||||||
| @Value("${gridsuite.services.directory-server.base-uri:http://directory-server}") String baseUri, | ||||||||||||||||||||
| RestTemplate restTemplate) { | ||||||||||||||||||||
| this.baseUri = baseUri; | ||||||||||||||||||||
| this.restTemplate = restTemplate; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| public String getContingenciesName(UUID contingenciesId) { | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is better with a bulk fetch with a list of uuid and make the signature more generic, for example Map<UUID, String> getElementNames(List elementUuids) |
||||||||||||||||||||
| Objects.requireNonNull(contingenciesId); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| URI path = UriComponentsBuilder | ||||||||||||||||||||
| .fromPath(DELIMITER + DIRECTORY_API_VERSION + "/elements/{elementUuid}") | ||||||||||||||||||||
| .buildAndExpand(contingenciesId) | ||||||||||||||||||||
| .toUri(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| try { | ||||||||||||||||||||
| ResponseEntity<Map<String, Object>> response = | ||||||||||||||||||||
| restTemplate.exchange( | ||||||||||||||||||||
| baseUri + path, | ||||||||||||||||||||
| HttpMethod.GET, | ||||||||||||||||||||
| null, | ||||||||||||||||||||
| new ParameterizedTypeReference<>() { } | ||||||||||||||||||||
| ); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Map<String, Object> responseBody = response.getBody(); | ||||||||||||||||||||
| return responseBody != null ? (String) responseBody.get("elementName") : null; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| } catch (HttpClientErrorException.NotFound e) { | ||||||||||||||||||||
| return null; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package org.gridsuite.securityanalysis.server.service; | ||
|
|
||
| import org.gridsuite.securityanalysis.server.dto.ParametersContingenciesDTO; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| /** | ||
| * @author Caroline Jeandat {@literal <caroline.jeandat at rte-france.com>} | ||
| */ | ||
| @Service | ||
| public class ParametersContingenciesService { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure we need a dedicated service just for mapping |
||
|
|
||
| private final DirectoryService directoryService; | ||
|
|
||
| public ParametersContingenciesService(DirectoryService directoryService) { | ||
| this.directoryService = directoryService; | ||
| } | ||
|
|
||
| public List<ParametersContingenciesDTO> toDTO(List<UUID> contingenciesIds) { | ||
| return contingenciesIds == null ? null : | ||
| contingenciesIds.stream() | ||
| .map(id -> new ParametersContingenciesDTO(id, getContingenciesName(id))) | ||
| .toList(); | ||
| } | ||
|
|
||
| public List<UUID> toUUIDs(List<ParametersContingenciesDTO> contingenciesDTOs) { | ||
| return contingenciesDTOs == null ? null : | ||
| contingenciesDTOs.stream() | ||
| .map(ParametersContingenciesDTO::getId) | ||
| .toList(); | ||
| } | ||
|
|
||
| private String getContingenciesName(UUID contingencyId) { | ||
| return directoryService.getContingenciesName(contingencyId); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.