Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
27efb12
SA results: add locationId to entities and dtos.
AAJELLAL Dec 31, 2024
ea42413
Merge branch 'main' of https://github.com/gridsuite/security-analysis…
AAJELLAL Dec 31, 2024
6f0ead6
Merge branch 'main' into add-locationId-to-sa-result
AAJELLAL Jan 7, 2025
0f2fdfb
SA results: add locationId to the allowed sort properties.
AAJELLAL Jan 8, 2025
68415ca
SA results: add changelog.
AAJELLAL Jan 9, 2025
9416a75
Merge branch 'main' into add-locationId-to-sa-result
AAJELLAL Jan 9, 2025
0910c7d
Add tests.
AAJELLAL Jan 13, 2025
a3d255b
Merge branch 'add-locationId-to-sa-result' of https://github.com/grid…
AAJELLAL Jan 13, 2025
94905a7
Merge branch 'main' of https://github.com/gridsuite/security-analysis…
Jan 27, 2025
1ee3328
Merge branch 'main' of https://github.com/gridsuite/security-analysis…
Feb 18, 2025
45db592
Change the DB schema in order to add locationId.
AAJELLAL Feb 24, 2025
845bc0d
Merge branch 'add-locationId-to-sa-result' of https://github.com/grid…
AAJELLAL Feb 24, 2025
eac35fd
Merge branch 'main' of https://github.com/gridsuite/security-analysis…
AAJELLAL Feb 24, 2025
7afb451
Add changelog
AAJELLAL Feb 24, 2025
6034834
Merge branch 'main' of https://github.com/gridsuite/security-analysis…
Feb 26, 2025
6319c1b
Clean upd tests.
AAJELLAL Feb 26, 2025
ea814a3
Merge branch 'main' of https://github.com/gridsuite/security-analysis…
AAJELLAL Feb 26, 2025
22bdfbf
Merge branch 'add-locationId-to-sa-result' of https://github.com/grid…
AAJELLAL Feb 26, 2025
d030431
update tests.
AAJELLAL Feb 26, 2025
38cef29
update tests.
AAJELLAL Feb 26, 2025
de51e12
Merge branch 'main' of https://github.com/gridsuite/security-analysis…
Feb 27, 2025
97d4a9c
Merge branch 'main' into add-locationId-to-sa-result
AAJELLAL May 26, 2025
6dfeb75
Merge branch 'main' into add-locationId-to-sa-result
AAJELLAL May 28, 2025
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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<liquibase-hibernate-package>org.gridsuite.securityanalysis.server</liquibase-hibernate-package>
<db-util.version>1.0.5</db-util.version>
<mockwebserver3.version>5.0.0-alpha.14</mockwebserver3.version>
<!-- FIXME: powsybl-ws-commons modules'version is overloaded in the dependencies section
The overloads and this property below have to be removed at next powsybl-ws-dependencies.version upgrade -->
<powsybl-ws-commons.version>1.17.0</powsybl-ws-commons.version>
</properties>

<build>
Expand Down Expand Up @@ -144,6 +147,8 @@
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-ws-commons</artifactId>
<version>${powsybl-ws-commons.version}</version>

</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@
public class PreContingencyLimitViolationResultDTO {

private String subjectId;
private String locationId;
private String status;
private LimitViolationDTO limitViolation;

public static PreContingencyLimitViolationResultDTO toDto(PreContingencyLimitViolationEntity preContingencyLimitViolation) {
String subjectId = preContingencyLimitViolation.getSubjectLimitViolation() != null
? preContingencyLimitViolation.getSubjectLimitViolation().getSubjectId()
: null;

String locationId = preContingencyLimitViolation.getSubjectLimitViolation() != null
? preContingencyLimitViolation.getSubjectLimitViolation().getLocationId()
: null;
return PreContingencyLimitViolationResultDTO.builder()
.subjectId(subjectId)
.locationId(locationId)
.status(preContingencyLimitViolation.getResult().getPreContingencyStatus())
.limitViolation(LimitViolationDTO.toDto(preContingencyLimitViolation))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@Builder
public class SubjectLimitViolationDTO {
private String subjectId;
private String locationId;

private LimitViolationDTO limitViolation;

Expand All @@ -29,8 +30,13 @@ public static SubjectLimitViolationDTO toDto(ContingencyLimitViolationEntity lim
? limitViolation.getSubjectLimitViolation().getSubjectId()
: null;

String locationId = limitViolation.getSubjectLimitViolation() != null
? limitViolation.getSubjectLimitViolation().getLocationId()
: null;

return SubjectLimitViolationDTO.builder()
.subjectId(subjectId)
.locationId(locationId)
.limitViolation(LimitViolationDTO.toDto(limitViolation))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
public class SubjectLimitViolationResultDTO {
private String subjectId;

private String locationId;

private List<ContingencyLimitViolationDTO> contingencies;

public static SubjectLimitViolationResultDTO toDto(SubjectLimitViolationEntity subjectLimitViolation) {
Expand All @@ -37,6 +39,7 @@ public static SubjectLimitViolationResultDTO toDto(SubjectLimitViolationEntity s

return SubjectLimitViolationResultDTO.builder()
.subjectId(subjectLimitViolation.getSubjectId())
.locationId(subjectLimitViolation.getLocationId())
.contingencies(contingencies)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.gridsuite.securityanalysis.server.entities;

import com.powsybl.iidm.network.Network;
import com.powsybl.security.results.PostContingencyResult;
import jakarta.persistence.*;
import lombok.Getter;
Expand Down Expand Up @@ -64,11 +65,11 @@ private void setContingencyLimitViolations(List<ContingencyLimitViolationEntity>
}
}

public static ContingencyEntity toEntity(PostContingencyResult postContingencyResult, Map<String, SubjectLimitViolationEntity> subjectLimitViolationsBySubjectId) {
public static ContingencyEntity toEntity(Network network, PostContingencyResult postContingencyResult, Map<String, SubjectLimitViolationEntity> subjectLimitViolationsBySubjectId) {
List<ContingencyElementEmbeddable> contingencyElements = postContingencyResult.getContingency().getElements().stream().map(contingencyElement -> ContingencyElementEmbeddable.toEntity(contingencyElement)).collect(Collectors.toList());

List<ContingencyLimitViolationEntity> contingencyLimitViolations = postContingencyResult.getLimitViolationsResult().getLimitViolations().stream()
.map(limitViolation -> ContingencyLimitViolationEntity.toEntity(limitViolation, subjectLimitViolationsBySubjectId.get(limitViolation.getSubjectId())))
.map(limitViolation -> ContingencyLimitViolationEntity.toEntity(network, limitViolation, subjectLimitViolationsBySubjectId.get(limitViolation.getSubjectId())))
.collect(Collectors.toList());
return new ContingencyEntity(postContingencyResult.getContingency().getId(), postContingencyResult.getStatus().name(), contingencyElements, contingencyLimitViolations);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/
package org.gridsuite.securityanalysis.server.entities;

import com.powsybl.iidm.network.Network;
import com.powsybl.security.LimitViolation;
import com.powsybl.ws.commons.computation.utils.ComputationResultUtils;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.FieldNameConstants;
Expand All @@ -30,7 +32,8 @@ public class ContingencyLimitViolationEntity extends AbstractLimitViolationEntit
@Setter
private ContingencyEntity contingency;

public static ContingencyLimitViolationEntity toEntity(LimitViolation limitViolation, SubjectLimitViolationEntity subjectLimitViolation) {
public static ContingencyLimitViolationEntity toEntity(Network network, LimitViolation limitViolation, SubjectLimitViolationEntity subjectLimitViolation) {
subjectLimitViolation.setLocationId(ComputationResultUtils.getViolationLocationId(limitViolation, network));
ContingencyLimitViolationEntity contingencyLimitViolationEntity = ContingencyLimitViolationEntity.builder()
.limit(limitViolation.getLimit())
.limitName(limitViolation.getLimitName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
*/
package org.gridsuite.securityanalysis.server.entities;

import com.powsybl.iidm.network.Network;
import com.powsybl.security.LimitViolation;
import com.powsybl.security.results.PreContingencyResult;
import com.powsybl.ws.commons.computation.utils.ComputationResultUtils;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
Expand Down Expand Up @@ -40,11 +42,12 @@ public class PreContingencyLimitViolationEntity extends AbstractLimitViolationEn
@Setter
SecurityAnalysisResultEntity result;

public static List<PreContingencyLimitViolationEntity> toEntityList(PreContingencyResult preContingencyResult, Map<String, SubjectLimitViolationEntity> subjectLimitViolationsBySubjectId) {
return preContingencyResult.getLimitViolationsResult().getLimitViolations().stream().map(limitViolation -> toEntity(limitViolation, subjectLimitViolationsBySubjectId.get(limitViolation.getSubjectId()))).collect(Collectors.toList());
public static List<PreContingencyLimitViolationEntity> toEntityList(Network network, PreContingencyResult preContingencyResult, Map<String, SubjectLimitViolationEntity> subjectLimitViolationsBySubjectId) {
return preContingencyResult.getLimitViolationsResult().getLimitViolations().stream().map(limitViolation -> toEntity(network, limitViolation, subjectLimitViolationsBySubjectId.get(limitViolation.getSubjectId()))).collect(Collectors.toList());
}

public static PreContingencyLimitViolationEntity toEntity(LimitViolation limitViolation, SubjectLimitViolationEntity subjectLimitViolation) {
public static PreContingencyLimitViolationEntity toEntity(Network network, LimitViolation limitViolation, SubjectLimitViolationEntity subjectLimitViolation) {
subjectLimitViolation.setLocationId(ComputationResultUtils.getViolationLocationId(limitViolation, network));
return PreContingencyLimitViolationEntity.builder()
.subjectLimitViolation(subjectLimitViolation)
.limit(limitViolation.getLimit())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.gridsuite.securityanalysis.server.entities;

import com.powsybl.iidm.network.Network;
import com.powsybl.security.SecurityAnalysisResult;
import jakarta.persistence.*;
import lombok.*;
Expand Down Expand Up @@ -52,17 +53,17 @@ public SecurityAnalysisResultEntity(UUID id) {
this.id = id;
}

public static SecurityAnalysisResultEntity toEntity(UUID resultUuid, SecurityAnalysisResult securityAnalysisResult, SecurityAnalysisStatus securityAnalysisStatus) {
public static SecurityAnalysisResultEntity toEntity(Network network, UUID resultUuid, SecurityAnalysisResult securityAnalysisResult, SecurityAnalysisStatus securityAnalysisStatus) {
Map<String, SubjectLimitViolationEntity> subjectLimitViolationsBySubjectId = getUniqueSubjectLimitViolationsFromResult(securityAnalysisResult)
.stream().collect(Collectors.toMap(
SubjectLimitViolationEntity::getSubjectId,
subjectLimitViolation -> subjectLimitViolation)
);

List<ContingencyEntity> contingencies = securityAnalysisResult.getPostContingencyResults().stream()
.map(postContingencyResult -> ContingencyEntity.toEntity(postContingencyResult, subjectLimitViolationsBySubjectId)).collect(Collectors.toList());
.map(postContingencyResult -> ContingencyEntity.toEntity(network, postContingencyResult, subjectLimitViolationsBySubjectId)).collect(Collectors.toList());

List<PreContingencyLimitViolationEntity> preContingencyLimitViolations = PreContingencyLimitViolationEntity.toEntityList(securityAnalysisResult.getPreContingencyResult(), subjectLimitViolationsBySubjectId);
List<PreContingencyLimitViolationEntity> preContingencyLimitViolations = PreContingencyLimitViolationEntity.toEntityList(network, securityAnalysisResult.getPreContingencyResult(), subjectLimitViolationsBySubjectId);

List<SubjectLimitViolationEntity> subjectLimitViolations = Stream.concat(
contingencies.stream().flatMap(c -> c.getContingencyLimitViolations().stream()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public SubjectLimitViolationEntity(String subjectId, String subjectName) {

private String subjectName;

@Column
@Setter
@Getter
private String locationId;

@ManyToOne(fetch = FetchType.LAZY)
@Setter
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.ThreeSides;
import com.powsybl.security.LimitViolationType;
import com.powsybl.security.SecurityAnalysisResult;
Expand Down Expand Up @@ -63,11 +64,13 @@ public class SecurityAnalysisResultService extends AbstractComputationResultServ
ContingencyEntity.Fields.contingencyLimitViolations + SpecificationUtils.FIELD_SEPARATOR + AbstractLimitViolationEntity.Fields.loading,
ContingencyEntity.Fields.contingencyLimitViolations + SpecificationUtils.FIELD_SEPARATOR + AbstractLimitViolationEntity.Fields.acceptableDuration,
ContingencyEntity.Fields.contingencyLimitViolations + SpecificationUtils.FIELD_SEPARATOR + AbstractLimitViolationEntity.Fields.side,
ContingencyEntity.Fields.contingencyLimitViolations + SpecificationUtils.FIELD_SEPARATOR + AbstractLimitViolationEntity.Fields.subjectLimitViolation + SpecificationUtils.FIELD_SEPARATOR + SubjectLimitViolationEntity.Fields.subjectId
ContingencyEntity.Fields.contingencyLimitViolations + SpecificationUtils.FIELD_SEPARATOR + AbstractLimitViolationEntity.Fields.subjectLimitViolation + SpecificationUtils.FIELD_SEPARATOR + SubjectLimitViolationEntity.Fields.subjectId,
ContingencyEntity.Fields.contingencyLimitViolations + SpecificationUtils.FIELD_SEPARATOR + AbstractLimitViolationEntity.Fields.subjectLimitViolation + SpecificationUtils.FIELD_SEPARATOR + SubjectLimitViolationEntity.Fields.locationId
);

private static final List<String> ALLOWED_NMK_SUBJECT_LIMIT_VIOLATIONS_RESULT_SORT_PROPERTIES = List.of(
SubjectLimitViolationEntity.Fields.subjectId,
SubjectLimitViolationEntity.Fields.locationId,
SubjectLimitViolationEntity.Fields.contingencyLimitViolations + SpecificationUtils.FIELD_SEPARATOR + AbstractLimitViolationEntity.Fields.limitType,
SubjectLimitViolationEntity.Fields.contingencyLimitViolations + SpecificationUtils.FIELD_SEPARATOR + AbstractLimitViolationEntity.Fields.limitName,
SubjectLimitViolationEntity.Fields.contingencyLimitViolations + SpecificationUtils.FIELD_SEPARATOR + AbstractLimitViolationEntity.Fields.limit,
Expand All @@ -87,8 +90,10 @@ public class SecurityAnalysisResultService extends AbstractComputationResultServ
AbstractLimitViolationEntity.Fields.value,
AbstractLimitViolationEntity.Fields.loading,
AbstractLimitViolationEntity.Fields.acceptableDuration,
AbstractLimitViolationEntity.Fields.side
);
AbstractLimitViolationEntity.Fields.side,
AbstractLimitViolationEntity.Fields.subjectLimitViolation + SpecificationUtils.FIELD_SEPARATOR + SubjectLimitViolationEntity.Fields.locationId

);

public SecurityAnalysisResultService(SecurityAnalysisResultRepository securityAnalysisResultRepository,
ContingencyRepository contingencyRepository,
Expand Down Expand Up @@ -228,11 +233,11 @@ public void assertResultExists(UUID resultUuid) {
}

@Transactional
public void insert(UUID resultUuid, SecurityAnalysisResult result, SecurityAnalysisStatus status) {
public void insert(Network network, UUID resultUuid, SecurityAnalysisResult result, SecurityAnalysisStatus status) {
Objects.requireNonNull(resultUuid);
Objects.requireNonNull(result);

SecurityAnalysisResultEntity securityAnalysisResult = SecurityAnalysisResultEntity.toEntity(resultUuid, result, status);
SecurityAnalysisResultEntity securityAnalysisResult = SecurityAnalysisResultEntity.toEntity(network, resultUuid, result, status);
securityAnalysisResultRepository.save(securityAnalysisResult);
}

Expand Down Expand Up @@ -479,6 +484,11 @@ private static Comparator<ContingencyLimitViolationEntity> getLimitViolationComp
+ SpecificationUtils.FIELD_SEPARATOR
+ SubjectLimitViolationEntity.Fields.subjectId ->
Comparator.comparing(value -> value.getSubjectLimitViolation().getSubjectId(), Comparator.nullsLast(Comparator.naturalOrder()));

case AbstractLimitViolationEntity.Fields.subjectLimitViolation
+ SpecificationUtils.FIELD_SEPARATOR
+ SubjectLimitViolationEntity.Fields.locationId ->
Comparator.comparing(value -> value.getSubjectLimitViolation().getLocationId(), Comparator.nullsLast(Comparator.naturalOrder()));
default -> getCommonComparator(field);
};
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected void postRun(SecurityAnalysisRunContext runContext, AtomicReference<Re

@Override
protected void saveResult(Network network, AbstractResultContext<SecurityAnalysisRunContext> resultContext, SecurityAnalysisResult result) {
resultService.insert(
resultService.insert(network,
resultContext.getResultUuid(),
result,
result.getPreContingencyResult().getStatus() == LoadFlowResult.ComponentResult.Status.CONVERGED
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="ajellalali (generated)" id="1734968432016-1">
<addColumn tableName="subject_limit_violation">
<column name="location_id" type="varchar(255)"/>
</addColumn>
</changeSet>
</databaseChangeLog>
4 changes: 3 additions & 1 deletion src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ databaseChangeLog:
- include:
file: changesets/changelog_20241212T111835Z.xml
relativeToChangelogFile: true

- include:
file: changesets/changelog_20241223T154019Z.xml
relativeToChangelogFile: true
Loading
Loading