Skip to content

Commit

Permalink
implement connectablePosition modification for branch form (#530)
Browse files Browse the repository at this point in the history
Signed-off-by: Ghazwa Rehili <[email protected]>
  • Loading branch information
ghazwarhili authored Sep 19, 2024
1 parent f001cf8 commit 41ec5c2
Show file tree
Hide file tree
Showing 10 changed files with 526 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.modification.server.dto;
import com.powsybl.iidm.network.extensions.ConnectablePosition;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -35,9 +36,39 @@ public class BranchModificationInfos extends BasicEquipmentModificationInfos {
@Schema(description = "Current limits Side 2")
private CurrentLimitsModificationInfos currentLimits2;

@Schema(description = "Voltage level id modification 1")
private AttributeModification<String> voltageLevelId1;

@Schema(description = "Voltage level id modification 2")
private AttributeModification<String> voltageLevelId2;

@Schema(description = "Bus id modification 1")
private AttributeModification<String> busOrBusbarSectionId1;

@Schema(description = "Bus id modification 2")
private AttributeModification<String> busOrBusbarSectionId2;

@Schema(description = "Connection Name 1")
private AttributeModification<String> connectionName1;

@Schema(description = "Connection Name 2")
private AttributeModification<String> connectionName2;

@Schema(description = "Connection Direction 1")
private AttributeModification<ConnectablePosition.Direction> connectionDirection1;

@Schema(description = "Connection Direction 2")
private AttributeModification<ConnectablePosition.Direction> connectionDirection2;

@Schema(description = "Connection Position 1")
private AttributeModification<Integer> connectionPosition1;

@Schema(description = "Connection Position 2")
private AttributeModification<Integer> connectionPosition2;

@Schema(description = "Connected 1")
private AttributeModification<Boolean> connected1;
private AttributeModification<Boolean> terminal1Connected;

@Schema(description = "Connected 2")
private AttributeModification<Boolean> connected2;
private AttributeModification<Boolean> terminal2Connected;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
*/
package org.gridsuite.modification.server.entities.equipment.modification;

import com.powsybl.iidm.network.extensions.ConnectablePosition;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.gridsuite.modification.server.dto.BranchModificationInfos;
import org.gridsuite.modification.server.dto.ModificationInfos;
import org.gridsuite.modification.server.entities.equipment.modification.attribute.BooleanModificationEmbedded;
import org.gridsuite.modification.server.entities.equipment.modification.attribute.DoubleModificationEmbedded;

import jakarta.persistence.*;
import org.gridsuite.modification.server.entities.equipment.modification.attribute.*;

/**
* @author Ayoub LABIDI <ayoub.labidi at rte-france.com>
Expand Down Expand Up @@ -53,19 +52,89 @@ public class BranchModificationEntity extends BasicEquipmentModificationEntity {
), nullable = true)
private CurrentLimitsModificationEntity currentLimits2;

@Embedded
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "voltageLevelId1")),
@AttributeOverride(name = "opType", column = @Column(name = "voltageLevelId1Op"))
})
private StringModificationEmbedded voltageLevelId1;

@Embedded
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "voltageLevelId2")),
@AttributeOverride(name = "opType", column = @Column(name = "voltageLevelId2Op"))
})
private StringModificationEmbedded voltageLevelId2;

@Embedded
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "busOrBusbarSectionId1")),
@AttributeOverride(name = "opType", column = @Column(name = "busOrBusbarSectionId1Op"))
})
private StringModificationEmbedded busOrBusbarSectionId1;

@Embedded
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "busOrBusbarSectionId2")),
@AttributeOverride(name = "opType", column = @Column(name = "busOrBusbarSectionId2Op"))
})
private StringModificationEmbedded busOrBusbarSectionId2;

@Embedded
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "connectionName1")),
@AttributeOverride(name = "opType", column = @Column(name = "connectionName1Op"))
})
private StringModificationEmbedded connectionName1;

@Embedded
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "connectionName2")),
@AttributeOverride(name = "opType", column = @Column(name = "connectionName2Op"))
})
private StringModificationEmbedded connectionName2;

@Embedded
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "connectionPosition1")),
@AttributeOverride(name = "opType", column = @Column(name = "connectionPosition1Op"))
})
private IntegerModificationEmbedded connectionPosition1;

@Embedded
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "connectionPosition2")),
@AttributeOverride(name = "opType", column = @Column(name = "connectionPosition2Op"))
})
private IntegerModificationEmbedded connectionPosition2;

@Embedded
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "connectionDirection1")),
@AttributeOverride(name = "opType", column = @Column(name = "connectionDirection1Op"))
})
private EnumModificationEmbedded<ConnectablePosition.Direction> connectionDirection1;

@Embedded
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "connectionDirection2")),
@AttributeOverride(name = "opType", column = @Column(name = "connectionDirection2Op"))
})
private EnumModificationEmbedded<ConnectablePosition.Direction> connectionDirection2;

@Embedded
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "connected1")),
@AttributeOverride(name = "opType", column = @Column(name = "connected1Op"))
})
private BooleanModificationEmbedded connected1;
private BooleanModificationEmbedded terminal1Connected;

@Embedded
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "connected2")),
@AttributeOverride(name = "opType", column = @Column(name = "connected2Op"))
})
private BooleanModificationEmbedded connected2;
private BooleanModificationEmbedded terminal2Connected;

protected BranchModificationEntity(BranchModificationInfos branchModificationInfos) {
super(branchModificationInfos);
Expand All @@ -92,7 +161,17 @@ private void assignAttributes(BranchModificationInfos branchModificationInfos) {
} else {
currentLimits2 = branchModificationInfos.getCurrentLimits2().toEntity();
}
this.connected1 = branchModificationInfos.getConnected1() != null ? new BooleanModificationEmbedded(branchModificationInfos.getConnected1()) : null;
this.connected2 = branchModificationInfos.getConnected2() != null ? new BooleanModificationEmbedded(branchModificationInfos.getConnected2()) : null;
this.voltageLevelId1 = branchModificationInfos.getVoltageLevelId1() != null ? new StringModificationEmbedded(branchModificationInfos.getVoltageLevelId1()) : null;
this.voltageLevelId2 = branchModificationInfos.getVoltageLevelId2() != null ? new StringModificationEmbedded(branchModificationInfos.getVoltageLevelId2()) : null;
this.busOrBusbarSectionId1 = branchModificationInfos.getBusOrBusbarSectionId1() != null ? new StringModificationEmbedded(branchModificationInfos.getBusOrBusbarSectionId1()) : null;
this.busOrBusbarSectionId2 = branchModificationInfos.getBusOrBusbarSectionId2() != null ? new StringModificationEmbedded(branchModificationInfos.getBusOrBusbarSectionId2()) : null;
this.connectionName1 = branchModificationInfos.getConnectionName1() != null ? new StringModificationEmbedded(branchModificationInfos.getConnectionName1()) : null;
this.connectionName2 = branchModificationInfos.getConnectionName2() != null ? new StringModificationEmbedded(branchModificationInfos.getConnectionName2()) : null;
this.connectionDirection1 = branchModificationInfos.getConnectionDirection1() != null ? new EnumModificationEmbedded<>(branchModificationInfos.getConnectionDirection1()) : null;
this.connectionDirection2 = branchModificationInfos.getConnectionDirection2() != null ? new EnumModificationEmbedded<>(branchModificationInfos.getConnectionDirection2()) : null;
this.connectionPosition1 = branchModificationInfos.getConnectionPosition1() != null ? new IntegerModificationEmbedded(branchModificationInfos.getConnectionPosition1()) : null;
this.connectionPosition2 = branchModificationInfos.getConnectionPosition2() != null ? new IntegerModificationEmbedded(branchModificationInfos.getConnectionPosition2()) : null;
this.terminal1Connected = branchModificationInfos.getTerminal1Connected() != null ? new BooleanModificationEmbedded(branchModificationInfos.getTerminal1Connected()) : null;
this.terminal2Connected = branchModificationInfos.getTerminal2Connected() != null ? new BooleanModificationEmbedded(branchModificationInfos.getTerminal2Connected()) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,18 @@ public LineModificationInfos toModificationInfos() {
.activated(getActivated())
.equipmentId(getEquipmentId())
.equipmentName(AttributeModification.toAttributeModification(getEquipmentNameValue(), getEquipmentNameOp()))
.connected1(toAttributeModification(getConnected1()))
.connected2(toAttributeModification(getConnected2()))
.voltageLevelId1(toAttributeModification(getVoltageLevelId1()))
.voltageLevelId2(toAttributeModification(getVoltageLevelId2()))
.busOrBusbarSectionId1(toAttributeModification(getBusOrBusbarSectionId1()))
.busOrBusbarSectionId2(toAttributeModification(getBusOrBusbarSectionId2()))
.connectionName1(toAttributeModification(getConnectionName1()))
.connectionName2(toAttributeModification(getConnectionName2()))
.connectionDirection1(toAttributeModification(getConnectionDirection1()))
.connectionDirection2(toAttributeModification(getConnectionDirection2()))
.connectionPosition1(toAttributeModification(getConnectionPosition1()))
.connectionPosition2(toAttributeModification(getConnectionPosition2()))
.terminal1Connected(toAttributeModification(getTerminal1Connected()))
.terminal2Connected(toAttributeModification(getTerminal2Connected()))
.r(toAttributeModification(getR()))
.x(toAttributeModification(getX()))
.g1(toAttributeModification(getG1()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,18 @@ public TwoWindingsTransformerModificationInfos toModificationInfos() {
.activated(getActivated())
.equipmentId(getEquipmentId())
.equipmentName(AttributeModification.toAttributeModification(getEquipmentNameValue(), getEquipmentNameOp()))
.connected1(toAttributeModification(getConnected1()))
.connected2(toAttributeModification(getConnected2()))
.voltageLevelId1(toAttributeModification(getVoltageLevelId1()))
.voltageLevelId2(toAttributeModification(getVoltageLevelId2()))
.busOrBusbarSectionId1(toAttributeModification(getBusOrBusbarSectionId1()))
.busOrBusbarSectionId2(toAttributeModification(getBusOrBusbarSectionId2()))
.connectionName1(toAttributeModification(getConnectionName1()))
.connectionName2(toAttributeModification(getConnectionName2()))
.connectionDirection1(toAttributeModification(getConnectionDirection1()))
.connectionDirection2(toAttributeModification(getConnectionDirection2()))
.connectionPosition1(toAttributeModification(getConnectionPosition1()))
.connectionPosition2(toAttributeModification(getConnectionPosition2()))
.terminal1Connected(toAttributeModification(getTerminal1Connected()))
.terminal2Connected(toAttributeModification(getTerminal2Connected()))
.r(AttributeModification.toAttributeModification(getR()))
.x(AttributeModification.toAttributeModification(getX()))
.g(AttributeModification.toAttributeModification(getG()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.powsybl.commons.report.ReportNode;
import com.powsybl.commons.report.TypedValue;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.ConnectablePosition;
import com.powsybl.iidm.network.extensions.ConnectablePositionAdder;
import org.gridsuite.modification.server.NetworkModificationException;
import org.gridsuite.modification.server.dto.BranchModificationInfos;
import org.gridsuite.modification.server.dto.CurrentLimitsModificationInfos;
Expand Down Expand Up @@ -48,6 +50,8 @@ protected void modifyBranch(Branch<?> branch, BranchModificationInfos branchModi
branch.setName(branchModificationInfos.getEquipmentName().getValue());
}

modifyBranchConnectivityAttributes(branchModificationInfos, branch, subReportNode);

if (characteristicsModified(branchModificationInfos)) {
modifyCharacteristics(branch, branchModificationInfos, subReportNode);
}
Expand Down Expand Up @@ -78,13 +82,13 @@ protected void modifyBranch(Branch<?> branch, BranchModificationInfos branchModi
private void updateConnections(Branch<?> branch, BranchModificationInfos branchModificationInfos) {
List<TwoSides> errorSides = new ArrayList<>();
List<String> errorTypes = new ArrayList<>();
if (branchModificationInfos.getConnected1() != null && !updateConnection(branch, TwoSides.ONE, modificationInfos.getConnected1().getValue())) {
if (branchModificationInfos.getTerminal1Connected() != null && !updateConnection(branch, TwoSides.ONE, modificationInfos.getTerminal1Connected().getValue())) {
errorSides.add(TwoSides.ONE);
errorTypes.add(Boolean.TRUE.equals(modificationInfos.getConnected1().getValue()) ? "connect" : "disconnect");
errorTypes.add(Boolean.TRUE.equals(modificationInfos.getTerminal1Connected().getValue()) ? "connect" : "disconnect");
}
if (branchModificationInfos.getConnected2() != null && !updateConnection(branch, TwoSides.TWO, modificationInfos.getConnected2().getValue())) {
if (branchModificationInfos.getTerminal2Connected() != null && !updateConnection(branch, TwoSides.TWO, modificationInfos.getTerminal2Connected().getValue())) {
errorSides.add(TwoSides.TWO);
errorTypes.add(Boolean.TRUE.equals(modificationInfos.getConnected2().getValue()) ? "connect" : "disconnect");
errorTypes.add(Boolean.TRUE.equals(modificationInfos.getTerminal2Connected().getValue()) ? "connect" : "disconnect");
}
if (!errorSides.isEmpty()) {
throw new NetworkModificationException(BRANCH_MODIFICATION_ERROR,
Expand Down Expand Up @@ -219,4 +223,11 @@ protected boolean characteristicsModified(BranchModificationInfos branchModifica

protected abstract void modifyCharacteristics(Branch<?> branch, BranchModificationInfos branchModificationInfos,
ReportNode subReportNode);

private ReportNode modifyBranchConnectivityAttributes(BranchModificationInfos branchModificationInfos,
Branch<?> branch, ReportNode subReportNode) {
ConnectablePosition<?> connectablePosition = (ConnectablePosition<?>) branch.getExtension(ConnectablePosition.class);
ConnectablePositionAdder<?> connectablePositionAdder = branch.newExtension(ConnectablePositionAdder.class);
return ModificationUtils.getInstance().modifyBranchConnectivityAttributes(connectablePosition, connectablePositionAdder, branch, branchModificationInfos, subReportNode);
}
}
Loading

0 comments on commit 41ec5c2

Please sign in to comment.