-
Notifications
You must be signed in to change notification settings - Fork 0
add new modification MoveVoltageLevelFeederBays #87
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
Merged
etiennehomer
merged 27 commits into
main
from
add-new-modification-MoveVoltageLevelFeederBays
Sep 24, 2025
Merged
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
f411ee4
add new modification MoveVoltageLevelFeederBays
EtienneLt a2b69bf
Merge branch 'main' into add-new-modification-MoveVoltageLevelFeederBays
EtienneLt 7b3c860
add tests
EtienneLt d70059e
fix checkstyle
EtienneLt 1e86744
more test
EtienneLt bb52932
fix
EtienneLt 3a12caa
fix
EtienneLt 4645f9e
fix checkstyle
EtienneLt d19a435
Merge branch 'main' into add-new-modification-MoveVoltageLevelFeederBays
EtienneLt f9cef7d
Merge branch 'main' into add-new-modification-MoveVoltageLevelFeederBays
EtienneLt f557713
fix
EtienneLt 1481bc0
fix and add coverage
EtienneLt 7645010
add test
EtienneLt 2a3e8c7
code review remarks
ghazwarhili d01731e
Merge branch 'main' into add-new-modification-MoveVoltageLevelFeederBays
ipirog c92216f
Merge branch 'main' into add-new-modification-MoveVoltageLevelFeederBays
ghazwarhili 3cb7471
fix BusbarSectionFinderTraverser
ghazwarhili ef32d7b
Merge branch 'main' into add-new-modification-MoveVoltageLevelFeederBays
ipirog 1059d5f
code remarks review
ghazwarhili cd66318
Merge remote-tracking branch 'origin/add-new-modification-MoveVoltage…
ghazwarhili 6f13d08
Revert all the changes about the Traverser
ghazwarhili 9061f79
fix sonar issues
ghazwarhili 68cb0a3
Merge branch 'main' into add-new-modification-MoveVoltageLevelFeederBays
ghazwarhili 79fc076
code review remarks
ghazwarhili 1527dda
Merge branch 'main' into add-new-modification-MoveVoltageLevelFeederBays
ghazwarhili 0aac0d9
fix sonar issue
ghazwarhili f97c2c5
Merge remote-tracking branch 'origin/add-new-modification-MoveVoltage…
ghazwarhili File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/org/gridsuite/modification/dto/MoveFeederBayInfos.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) 2025, RTE (http://www.rte-france.com) | ||
* 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.modification.dto; | ||
|
||
import com.powsybl.iidm.network.extensions.ConnectablePosition; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
/** | ||
* @author Etienne Lesot <etienne.lesot at rte-france.com> | ||
*/ | ||
@SuperBuilder | ||
@NoArgsConstructor | ||
@Getter | ||
@ToString(callSuper = true) | ||
@Schema(description = "Move feeder bay") | ||
public class MoveFeederBayInfos { | ||
@Schema(description = "Equipment id") | ||
private String equipmentId; | ||
|
||
@Schema(description = "busbar section id") | ||
private String busbarSectionId; | ||
|
||
@Schema(description = "connection side") | ||
private String connectionSide; | ||
|
||
@Schema(description = "connection position") | ||
private Integer connectionPosition; | ||
|
||
@Schema(description = "connection name") | ||
private String connectionName; | ||
|
||
@Schema(description = "connection direction") | ||
private ConnectablePosition.Direction connectionDirection; | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/org/gridsuite/modification/dto/MoveVoltageLevelFeederBaysInfos.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright (c) 2025, RTE (http://www.rte-france.com) | ||
* 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.modification.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import com.powsybl.commons.report.ReportNode; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.experimental.SuperBuilder; | ||
import org.gridsuite.modification.dto.annotation.ModificationErrorTypeName; | ||
import org.gridsuite.modification.modifications.AbstractModification; | ||
import org.gridsuite.modification.modifications.MoveVoltageLevelFeederBays; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Etienne Lesot <etienne.lesot at rte-france.com> | ||
*/ | ||
@SuperBuilder | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@Schema(description = "Move voltage level feeder bays") | ||
@JsonTypeName("MOVE_VOLTAGE_LEVEL_FEEDER_BAYS") | ||
@ModificationErrorTypeName("MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_ERROR") | ||
public class MoveVoltageLevelFeederBaysInfos extends ModificationInfos { | ||
|
||
@Schema(description = "Voltage level id") | ||
private String voltageLevelId; | ||
|
||
@Schema(description = "Feeder bays list") | ||
private List<MoveFeederBayInfos> feederBays; | ||
|
||
@Override | ||
public AbstractModification toModification() { | ||
return new MoveVoltageLevelFeederBays(this); | ||
} | ||
|
||
@Override | ||
public ReportNode createSubReportNode(ReportNode reportNode) { | ||
return reportNode.newReportNode() | ||
.withMessageTemplate("network.modification.MOVE_VOLTAGE_LEVEL_FEEDER_BAYS") | ||
.withUntypedValue("voltageLevelId", getVoltageLevelId()) | ||
.add(); | ||
} | ||
|
||
@Override | ||
public Map<String, String> getMapMessageValues() { | ||
return Map.of("voltageLevelId", getVoltageLevelId()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
src/main/java/org/gridsuite/modification/modifications/MoveVoltageLevelFeederBays.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/** | ||
* Copyright (c) 2025, RTE (http://www.rte-france.com) | ||
* 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.modification.modifications; | ||
|
||
import com.powsybl.commons.report.ReportNode; | ||
import com.powsybl.iidm.network.*; | ||
import com.powsybl.iidm.network.extensions.ConnectablePosition; | ||
import com.powsybl.iidm.network.extensions.ConnectablePositionAdder; | ||
import org.gridsuite.modification.ModificationType; | ||
import org.gridsuite.modification.NetworkModificationException; | ||
import org.gridsuite.modification.dto.*; | ||
import org.gridsuite.modification.utils.ModificationUtils; | ||
|
||
import static org.gridsuite.modification.NetworkModificationException.Type.MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_ERROR; | ||
|
||
/** | ||
* @author Etienne Lesot <etienne.lesot at rte-france.com> | ||
*/ | ||
public class MoveVoltageLevelFeederBays extends AbstractModification { | ||
private static final String VOLTAGE_LEVEL_NOT_FOUND = "Voltage level %s is not found"; | ||
private static final String CONNECTABLE_NOT_FOUND = "Connectable %s not found"; | ||
private static final String BUSBAR_NOT_FOUND = "Bus or busbar section %s where connectable %s is supposed to be is not found in voltage level %s"; | ||
private static final String UNSUPPORTED_CONNECTABLE = "MoveVoltageLevelFeederBays is not implemented for %s"; | ||
private static final String INVALID_CONNECTION_SIDE = "Invalid connection side: %s for branch %s"; | ||
|
||
private final MoveVoltageLevelFeederBaysInfos modificationInfos; | ||
|
||
public MoveVoltageLevelFeederBays(MoveVoltageLevelFeederBaysInfos modificationInfos) { | ||
this.modificationInfos = modificationInfos; | ||
} | ||
|
||
@Override | ||
public void check(Network network) throws NetworkModificationException { | ||
VoltageLevel voltageLevel = getVoltageLevelOrThrow(network, modificationInfos.getVoltageLevelId()); | ||
for (MoveFeederBayInfos info : modificationInfos.getFeederBays()) { | ||
checkBusOrBusbarSectionExist(voltageLevel, info); | ||
checkConnectable(network, info); | ||
} | ||
} | ||
|
||
private VoltageLevel getVoltageLevelOrThrow(Network network, String voltageLevelId) { | ||
VoltageLevel voltageLevel = network.getVoltageLevel(voltageLevelId); | ||
if (voltageLevel == null) { | ||
throw new NetworkModificationException(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_ERROR, String.format(VOLTAGE_LEVEL_NOT_FOUND, voltageLevelId)); | ||
} | ||
return voltageLevel; | ||
} | ||
|
||
private void checkBusOrBusbarSectionExist(VoltageLevel voltageLevel, MoveFeederBayInfos info) { | ||
boolean busOrBusbarSectionExists = voltageLevel.getTopologyKind().equals(TopologyKind.NODE_BREAKER) | ||
? voltageLevel.getNodeBreakerView().getBusbarSection(info.getBusbarSectionId()) != null | ||
: voltageLevel.getBusBreakerView().getBus(info.getBusbarSectionId()) != null; | ||
if (!busOrBusbarSectionExists) { | ||
throw new NetworkModificationException(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_ERROR, String.format(BUSBAR_NOT_FOUND, | ||
info.getBusbarSectionId(), info.getEquipmentId(), modificationInfos.getVoltageLevelId())); | ||
} | ||
} | ||
|
||
private void checkConnectable(Network network, MoveFeederBayInfos info) { | ||
Connectable<?> connectable = network.getConnectable(info.getEquipmentId()); | ||
if (connectable == null) { | ||
throw new NetworkModificationException(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_ERROR, String.format(CONNECTABLE_NOT_FOUND, info.getEquipmentId())); | ||
} | ||
if (connectable instanceof BusbarSection || connectable instanceof ThreeWindingsTransformer) { | ||
throw new NetworkModificationException(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_ERROR, String.format(UNSUPPORTED_CONNECTABLE, connectable.getClass())); | ||
} | ||
} | ||
|
||
@Override | ||
public void apply(Network network, ReportNode subReportNode) { | ||
for (MoveFeederBayInfos info : modificationInfos.getFeederBays()) { | ||
Connectable<?> connectable = network.getConnectable(info.getEquipmentId()); | ||
modifyConnectablePosition(network, connectable, info, subReportNode); | ||
} | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return ModificationType.MOVE_VOLTAGE_LEVEL_FEEDER_BAYS.name(); | ||
} | ||
|
||
private void modifyConnectablePosition(Network network, Connectable<?> connectable, MoveFeederBayInfos newConnectablePositionInfos, ReportNode subReportNode) { | ||
ConnectablePosition<?> oldConnectablePosition = (ConnectablePosition<?>) connectable.getExtension(ConnectablePosition.class); | ||
ConnectablePositionAdder<?> connectablePositionAdder = connectable.newExtension(ConnectablePositionAdder.class); | ||
|
||
switch (connectable) { | ||
case Injection<?> injection -> { | ||
InjectionModificationInfos injectionModificationInfos = buildInjectionModificationInfos(newConnectablePositionInfos); | ||
ModificationUtils.getInstance().modifyInjectionConnectivityAttributes(oldConnectablePosition, connectablePositionAdder, injection, injectionModificationInfos, subReportNode); | ||
} | ||
case Branch<?> branch -> { | ||
BranchModificationInfos branchModificationInfos = buildBranchModificationInfos(newConnectablePositionInfos); | ||
ModificationUtils.getInstance().modifyBranchConnectivityAttributes(oldConnectablePosition, connectablePositionAdder, branch, branchModificationInfos, subReportNode); | ||
} | ||
default -> { | ||
throw new NetworkModificationException(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_ERROR, String.format(UNSUPPORTED_CONNECTABLE, connectable.getClass())); | ||
} | ||
} | ||
moveFeederBay(network, connectable, newConnectablePositionInfos, subReportNode); | ||
} | ||
|
||
private InjectionModificationInfos buildInjectionModificationInfos(MoveFeederBayInfos newConnectablePositionInfos) { | ||
InjectionModificationInfos injectionInfos = new InjectionModificationInfos(); | ||
injectionInfos.setEquipmentId(newConnectablePositionInfos.getEquipmentId()); | ||
setConnectionAttributes(injectionInfos::setConnectionPosition, | ||
injectionInfos::setConnectionName, | ||
injectionInfos::setConnectionDirection, | ||
newConnectablePositionInfos); | ||
return injectionInfos; | ||
} | ||
|
||
private BranchModificationInfos buildBranchModificationInfos(MoveFeederBayInfos info) { | ||
BranchModificationInfos branchInfos = new BranchModificationInfos(); | ||
branchInfos.setEquipmentId(info.getEquipmentId()); | ||
ThreeSides connectionSide = ThreeSides.valueOf(info.getConnectionSide()); | ||
switch (connectionSide) { | ||
case ONE -> setConnectionAttributes(branchInfos::setConnectionPosition1, | ||
branchInfos::setConnectionName1, | ||
branchInfos::setConnectionDirection1, | ||
info); | ||
case TWO -> setConnectionAttributes(branchInfos::setConnectionPosition2, | ||
branchInfos::setConnectionName2, | ||
branchInfos::setConnectionDirection2, | ||
info); | ||
default -> throw new NetworkModificationException(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_ERROR, String.format(INVALID_CONNECTION_SIDE, info.getConnectionSide(), branchInfos.getEquipmentId())); | ||
} | ||
return branchInfos; | ||
} | ||
|
||
private void setConnectionAttributes(java.util.function.Consumer<AttributeModification<Integer>> setPosition, | ||
java.util.function.Consumer<AttributeModification<String>> setName, | ||
java.util.function.Consumer<AttributeModification<ConnectablePosition.Direction>> setDirection, | ||
MoveFeederBayInfos info) { | ||
setPosition.accept(new AttributeModification<>(info.getConnectionPosition(), OperationType.SET)); | ||
setName.accept(new AttributeModification<>(info.getConnectionName(), OperationType.SET)); | ||
setDirection.accept(new AttributeModification<>(info.getConnectionDirection(), OperationType.SET)); | ||
} | ||
|
||
private void moveFeederBay(Network network, Connectable<?> connectable, MoveFeederBayInfos info, ReportNode subReportNode) { | ||
Terminal terminal = getTerminal(network, info); | ||
String currentBusbarId = ModificationUtils.getInstance().getBusOrBusbarSection(terminal); | ||
String targetBusbarId = info.getBusbarSectionId(); | ||
if (!currentBusbarId.equals(targetBusbarId)) { | ||
ModificationUtils.getInstance().moveFeederBay( | ||
connectable, terminal, | ||
new AttributeModification<>(modificationInfos.getVoltageLevelId(), OperationType.SET), | ||
new AttributeModification<>(targetBusbarId, OperationType.SET), | ||
subReportNode); | ||
} | ||
} | ||
|
||
public Terminal getTerminal(Network network, MoveFeederBayInfos info) { | ||
Connectable<?> connectable = network.getConnectable(info.getEquipmentId()); | ||
return switch (connectable) { | ||
case Injection<?> injection -> injection.getTerminal(); | ||
case Branch<?> branch -> { | ||
try { | ||
TwoSides side = TwoSides.valueOf(info.getConnectionSide()); | ||
yield branch.getTerminal(side); | ||
} catch (IllegalArgumentException e) { | ||
throw new NetworkModificationException(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_ERROR, | ||
String.format(INVALID_CONNECTION_SIDE, info.getConnectionSide(), branch.getId())); | ||
} | ||
} | ||
default -> throw new NetworkModificationException(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_ERROR, String.format(UNSUPPORTED_CONNECTABLE, connectable.getClass())); | ||
}; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.