Skip to content
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

complete limits in branch creation #572

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6c6e608
draft complete limits in branch creation (not tested)
Mathieu-Deharbe Dec 10, 2024
cad336c
draft functional change set
Mathieu-Deharbe Dec 11, 2024
a1c26a9
back to CurrentLimitsEntity + update application
Mathieu-Deharbe Dec 12, 2024
2cd3053
back to original table names
Mathieu-Deharbe Dec 12, 2024
01d429a
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Dec 16, 2024
b2a7ee3
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Dec 16, 2024
8d1ab52
TUs
Mathieu-Deharbe Dec 16, 2024
96c7682
corrects cascade referencing problem
Mathieu-Deharbe Dec 16, 2024
d385970
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Dec 18, 2024
aed3d13
OperationalLimitsGroupEntity and everything that uses it
Mathieu-Deharbe Dec 19, 2024
28685d3
maj changeset de réf
Mathieu-Deharbe Dec 19, 2024
b4c86d8
new changelog and TU corrections
Mathieu-Deharbe Dec 19, 2024
d5d6f0b
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Dec 20, 2024
aaff292
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Jan 6, 2025
58dad14
post review 1
Mathieu-Deharbe Jan 6, 2025
e4a7e32
post review 3
Mathieu-Deharbe Jan 7, 2025
ca851f8
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Jan 7, 2025
d67b51e
post review 3
Mathieu-Deharbe Jan 7, 2025
e7bde6c
TU
Mathieu-Deharbe Jan 9, 2025
f8854ed
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Jan 9, 2025
b5e56a2
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Jan 15, 2025
e2ee671
named foreign keys
Mathieu-Deharbe Jan 15, 2025
d539281
migration
Mathieu-Deharbe Jan 16, 2025
d247c47
new changeset
Mathieu-Deharbe Jan 16, 2025
c65b5c7
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Jan 21, 2025
29834b6
cleaning
Mathieu-Deharbe Jan 23, 2025
0a8723b
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Jan 23, 2025
4d7bc87
TU !pg
Mathieu-Deharbe Jan 23, 2025
f1ec1cc
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Jan 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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<dependency>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-network-modification</artifactId>
<version>${network-modification.version}</version>
<version>0.3.0-SNAPSHOT</version>
Mathieu-Deharbe marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.gridsuite.modification.dto.BranchCreationInfos;
import org.gridsuite.modification.dto.CurrentLimitsInfos;
import org.gridsuite.modification.dto.ModificationInfos;

import jakarta.persistence.*;

import java.util.ArrayList;
import java.util.List;

/**
* @author Sylvain Bouzols <sylvain.bouzols at rte-france.com>
*/
Expand Down Expand Up @@ -64,21 +68,19 @@ public class BranchCreationEntity extends EquipmentCreationEntity {
@Column(name = "connected2", columnDefinition = "boolean default true")
private boolean connected2;

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
@JoinColumn(name = "current_limits_id1",
referencedColumnName = "id",
foreignKey = @ForeignKey(
name = "current_limits_id1_fk"
), nullable = true)
private CurrentLimitsEntity currentLimits1;

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
@JoinColumn(name = "current_limits_id2",
referencedColumnName = "id",
foreignKey = @ForeignKey(
name = "current_limits_id2_fk"
), nullable = true)
private CurrentLimitsEntity currentLimits2;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
Copy link
Contributor

Choose a reason for hiding this comment

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

you removed the @joincolumn ?

Copy link
Contributor Author

@Mathieu-Deharbe Mathieu-Deharbe Dec 18, 2024

Choose a reason for hiding this comment

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

Yes. Now that this is a list instead of a single object, a join column can't reference the whole list of the entry.

@OrderColumn
Copy link
Contributor

Choose a reason for hiding this comment

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

@OrderColumn(name = "pos_currentLimits1")

Copy link
Contributor Author

@Mathieu-Deharbe Mathieu-Deharbe Dec 18, 2024

Choose a reason for hiding this comment

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

Ok but renamed @OrderColumn(name = "pos_operationalLimitsGroups1") given that I changed the structure.

private List<CurrentLimitsEntity> currentLimits1;

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@OrderColumn
Copy link
Contributor

Choose a reason for hiding this comment

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

@OrderColumn(name = "pos_currentLimits2")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok but renamed @OrderColumn(name = "pos_operationalLimitsGroups2") given that I changed the structure.

private List<CurrentLimitsEntity> currentLimits2;

@Column(name = "selectedOperationalLimitsGroupId1")
private String selectedOperationalLimitsGroupId1;

@Column(name = "selectedOperationalLimitsGroupId2")
private String selectedOperationalLimitsGroupId2;

protected BranchCreationEntity(BranchCreationInfos branchCreationInfos) {
super(branchCreationInfos);
Expand All @@ -99,23 +101,34 @@ private void assignAttributes(BranchCreationInfos branchCreationInfos) {
voltageLevelId2 = branchCreationInfos.getVoltageLevelId2();
busOrBusbarSectionId1 = branchCreationInfos.getBusOrBusbarSectionId1();
busOrBusbarSectionId2 = branchCreationInfos.getBusOrBusbarSectionId2();
if (branchCreationInfos.getCurrentLimits1() != null) {
currentLimits1 = new CurrentLimitsEntity(branchCreationInfos.getCurrentLimits1());
} else {
currentLimits1 = null;
}
if (branchCreationInfos.getCurrentLimits2() != null) {
currentLimits2 = new CurrentLimitsEntity(branchCreationInfos.getCurrentLimits2());
} else {
currentLimits2 = null;
}
currentLimits1 = assignCurrentLimits(branchCreationInfos.getCurrentLimits1(), currentLimits1);
currentLimits2 = assignCurrentLimits(branchCreationInfos.getCurrentLimits2(), currentLimits2);
connectionDirection1 = branchCreationInfos.getConnectionDirection1();
connectionName1 = branchCreationInfos.getConnectionName1();
connectionDirection2 = branchCreationInfos.getConnectionDirection2();
connectionName2 = branchCreationInfos.getConnectionName2();
selectedOperationalLimitsGroupId1 = branchCreationInfos.getSelectedOperationalLimitsGroupId1();
Copy link
Contributor

Choose a reason for hiding this comment

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

getActiveOperationalLimits ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could have been a good name but I use the iidm terminology. Cf LineAttributes.java in powsybl network store.

selectedOperationalLimitsGroupId2 = branchCreationInfos.getSelectedOperationalLimitsGroupId2();
connectionPosition1 = branchCreationInfos.getConnectionPosition1();
connectionPosition2 = branchCreationInfos.getConnectionPosition2();
connected1 = branchCreationInfos.isConnected1();
connected2 = branchCreationInfos.isConnected2();
}

/**
* the point of this function is to never dereference previousCurrentLimits if it already exists,
* in order for Hibernate not to lose this reference when doing some cascade cleaning or whatever
Copy link
Contributor

Choose a reason for hiding this comment

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

in order to prevent Hibernate from losing the reference during cascade cleaning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK done.

*/
private List<CurrentLimitsEntity> assignCurrentLimits(List<CurrentLimitsInfos> currentLimitsInfos, List<CurrentLimitsEntity> previousCurrentLimits) {
List<CurrentLimitsEntity> updatedCurrentLimits = previousCurrentLimits;
if (previousCurrentLimits == null) {
updatedCurrentLimits = new ArrayList<>();
} else {
updatedCurrentLimits.clear();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

List<OperationalLimitsGroupEntity> updatedLimitsGroups = (operationalLimitsGroups == null)
                ? new ArrayList<>()
                : new ArrayList<>(operationalLimitsGroups);
        }

maybe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will try but I think it won't work because new ArrayList<>(operationalLimitsGroups); may lose the reference to operationalLimitsGroups by creating a new Array.

if (currentLimitsInfos != null) {
updatedCurrentLimits.addAll(CurrentLimitsEntity.toCurrentLimitsEntities(currentLimitsInfos));
}
return updatedCurrentLimits;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
*/
package org.gridsuite.modification.server.entities.equipment.creation;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;
basseche marked this conversation as resolved.
Show resolved Hide resolved
import org.gridsuite.modification.dto.CurrentLimitsInfos;

import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

import jakarta.persistence.*;
import org.springframework.util.CollectionUtils;

/**
* @author Sylvain Bouzols <sylvain.bouzols at rte-france.com>
Expand All @@ -36,22 +35,39 @@ public class CurrentLimitsEntity {
@Column(name = "permanentLimit")
private Double permanentLimit;

@Column(name = "operationalLimitGroupId")
private String operationalLimitGroupId;

@ElementCollection
@CollectionTable(
name = "currentTemporaryLimits",
joinColumns = @JoinColumn(name = "id", foreignKey = @ForeignKey(name = "temporaryLimits_fk_constraint"))
joinColumns = @JoinColumn(name = "id", foreignKey = @ForeignKey(name = "temporaryLimits_constraint_fk")) // TODO : réssayer l'ancienne ?
)
private List<CurrentTemporaryLimitCreationEmbeddable> temporaryLimits;

public CurrentLimitsInfos toCurrentLimitsInfos() {
return CurrentLimitsInfos
.builder()
.permanentLimit(getPermanentLimit())
.temporaryLimits(CurrentTemporaryLimitCreationEmbeddable.fromEmbeddableCurrentTemporaryLimits(getTemporaryLimits()))
.build();
public static List<CurrentLimitsInfos> fromCurrentLimitsEntities(List<CurrentLimitsEntity> limitsEntities) {
return CollectionUtils.isEmpty(limitsEntities) ? null :
limitsEntities.stream()
.map(limitEntity ->
CurrentLimitsInfos.builder()
.operationalLimitGroupId(limitEntity.getOperationalLimitGroupId())
.permanentLimit(limitEntity.getPermanentLimit())
.temporaryLimits(CurrentTemporaryLimitCreationEmbeddable.fromEmbeddableCurrentTemporaryLimits(limitEntity.getTemporaryLimits()))
.build()
)
.collect(Collectors.toList());
}

public CurrentLimitsEntity(CurrentLimitsInfos currentLimitsInfos) {
this(null, currentLimitsInfos.getPermanentLimit(), CurrentTemporaryLimitCreationEmbeddable.toEmbeddableCurrentTemporaryLimits(currentLimitsInfos.getTemporaryLimits()));
public static List<CurrentLimitsEntity> toCurrentLimitsEntities(@NonNull List<CurrentLimitsInfos> limits) {
return limits.stream()
.map(currentLimit ->
new CurrentLimitsEntity(
null,
currentLimit.getPermanentLimit(),
currentLimit.getOperationalLimitGroupId(),
CurrentTemporaryLimitCreationEmbeddable.toEmbeddableCurrentTemporaryLimits(currentLimit.getTemporaryLimits())
)
)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
@Embeddable
public class CurrentTemporaryLimitCreationEmbeddable {

// TODO : pas besoin d'id ici ??
Copy link
Contributor

@basseche basseche Dec 18, 2024

Choose a reason for hiding this comment

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

forgotten todo ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. It already worked without it. I was too suspicious because of a bug.


@Column(name = "name")
private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public LineCreationInfos toModificationInfos() {
.busOrBusbarSectionId2(getBusOrBusbarSectionId2())
.connectionName1(getConnectionName1())
.connectionName2(getConnectionName2())
.selectedOperationalLimitsGroupId1(getSelectedOperationalLimitsGroupId1())
.selectedOperationalLimitsGroupId2(getSelectedOperationalLimitsGroupId2())
.connectionDirection1(getConnectionDirection1())
.connectionDirection2(getConnectionDirection2())
.connectionPosition1(getConnectionPosition1())
Expand All @@ -94,14 +96,10 @@ public LineCreationInfos toModificationInfos() {
.properties(CollectionUtils.isEmpty(getProperties()) ? null :
getProperties().stream()
.map(FreePropertyEntity::toInfos)
.toList());
.toList())
.currentLimits1(CurrentLimitsEntity.fromCurrentLimitsEntities(getCurrentLimits1()))
.currentLimits2(CurrentLimitsEntity.fromCurrentLimitsEntities(getCurrentLimits2()));

if (getCurrentLimits1() != null) {
builder.currentLimits1(getCurrentLimits1().toCurrentLimitsInfos());
}
if (getCurrentLimits2() != null) {
builder.currentLimits2(getCurrentLimits2().toCurrentLimitsInfos());
}
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ public TwoWindingsTransformerCreationInfos toModificationInfos() {
.busOrBusbarSectionId2(getBusOrBusbarSectionId2())
.connectionName1(getConnectionName1())
.connectionName2(getConnectionName2())
.selectedOperationalLimitsGroupId1(getSelectedOperationalLimitsGroupId1())
.selectedOperationalLimitsGroupId2(getSelectedOperationalLimitsGroupId2())
.connectionDirection1(getConnectionDirection1())
.connectionDirection2(getConnectionDirection2())
.connectionPosition1(getConnectionPosition1())
Expand All @@ -208,14 +210,9 @@ public TwoWindingsTransformerCreationInfos toModificationInfos() {
.properties(CollectionUtils.isEmpty(getProperties()) ? null :
getProperties().stream()
.map(FreePropertyEntity::toInfos)
.toList());

if (getCurrentLimits1() != null) {
builder.currentLimits1(getCurrentLimits1().toCurrentLimitsInfos());
}
if (getCurrentLimits2() != null) {
builder.currentLimits2(getCurrentLimits2().toCurrentLimitsInfos());
}
.toList())
.currentLimits1(CurrentLimitsEntity.fromCurrentLimitsEntities(getCurrentLimits1()))
.currentLimits2(CurrentLimitsEntity.fromCurrentLimitsEntities(getCurrentLimits2()));

if (!ratioTapChangerSteps.isEmpty()) {
List<TapChangerStepCreationInfos> ratioTapChangerStepCreationInfos = ratioTapChangerSteps.stream().map(TapChangerStepCreationEmbeddable::toModificationInfos).collect(Collectors.toList());
Expand Down
Loading
Loading