add voltage regulation for battery creation#209
Conversation
Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com>
📝 WalkthroughWalkthroughBattery creation now accepts voltage regulation settings, validates regulating terminals and target voltage, and creates the corresponding ChangesBattery voltage regulation
Sequence Diagram(s)sequenceDiagram
participant BatteryCreationInfos
participant BatteryCreation
participant Network
participant VoltageRegulation
BatteryCreationInfos->>BatteryCreation: map voltage regulation settings
BatteryCreation->>Network: resolve regulating terminal and validate targetV
BatteryCreation->>VoltageRegulation: create extension with terminal and targetV
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/main/java/org/gridsuite/modification/dto/BatteryCreationInfos.java (1)
85-86: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider using
Booleaninstead of primitivebooleanfor consistency.Using a primitive
booleandefaults tofalsewhen omitted from the request payload. For consistency with other optional parameters in this class (such asparticipateandreactiveCapabilityCurve), consider using theBooleanwrapper class to allow representing an omitted configuration asnull.♻️ Proposed refactor
`@Schema`(description = "Voltage regulation on") - private boolean voltageRegulationOn; + private Boolean voltageRegulationOn;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/org/gridsuite/modification/dto/BatteryCreationInfos.java` around lines 85 - 86, Change the voltageRegulationOn field in BatteryCreationInfos from primitive boolean to Boolean so omitted request values remain null, matching the optional participate and reactiveCapabilityCurve fields.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/org/gridsuite/modification/modifications/BatteryCreation.java`:
- Around line 97-104: Update the regulated-terminal validation in
BatteryCreation to reject partially specified regulating terminal fields instead
of allowing getTerminalFromIdentifiable to return null; validate that the
regulating terminal arguments are either all provided or all absent, then
perform lookup using the existing network argument rather than
voltageLevel.getNetwork().
- Around line 192-213: Update createBatteryVoltageRegulation to return without
creating a VoltageRegulation extension when voltage regulation parameters are
not configured, while preserving the existing setup when configuration is
present. Build the equipment report identifier without producing "null:null"
when regulatingTerminalType or regulatingTerminalId is missing, using a
null-safe representation instead.
---
Nitpick comments:
In `@src/main/java/org/gridsuite/modification/dto/BatteryCreationInfos.java`:
- Around line 85-86: Change the voltageRegulationOn field in
BatteryCreationInfos from primitive boolean to Boolean so omitted request values
remain null, matching the optional participate and reactiveCapabilityCurve
fields.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7ba89dd8-8f4f-4c29-9d00-6965c47d0019
📒 Files selected for processing (4)
src/main/java/org/gridsuite/modification/dto/BatteryCreationInfos.javasrc/main/java/org/gridsuite/modification/modifications/BatteryCreation.javasrc/test/java/org/gridsuite/modification/modifications/BatteryCreationInBusBreakerTest.javasrc/test/java/org/gridsuite/modification/modifications/BatteryCreationInNodeBreakerTest.java
| // check regulated terminal | ||
| VoltageLevel voltageLevel = ModificationUtils.getInstance().getVoltageLevel(network, voltageLevelId); | ||
| ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(), | ||
| regulatingTerminalId, | ||
| regulatingTerminalType, | ||
| regulatingTerminalVlId); | ||
| checkIsNotNegativeValue(errorMessage, targetV, CREATE_BATTERY_ERROR, "Target Voltage"); | ||
|
|
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Fix partial regulating terminal validation and redundant network lookup.
There are two issues here:
ModificationUtils.getInstance().getTerminalFromIdentifiable()will returnnullif any of the regulating terminal arguments arenull. Consequently, if a request provides partial properties (e.g., specifyingregulatingTerminalIdbut omittingregulatingTerminalType), it bypasses validation and silently returnsnullinstead of throwing an error.- Fetching
voltageLevel.getNetwork()is redundant since thenetworkis already directly available as the method argument.
🐛 Proposed fix
- // check regulated terminal
- VoltageLevel voltageLevel = ModificationUtils.getInstance().getVoltageLevel(network, voltageLevelId);
- ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(),
- regulatingTerminalId,
- regulatingTerminalType,
- regulatingTerminalVlId);
- checkIsNotNegativeValue(errorMessage, targetV, CREATE_BATTERY_ERROR, "Target Voltage");
+ // check regulated terminal
+ VoltageLevel voltageLevel = ModificationUtils.getInstance().getVoltageLevel(network, voltageLevelId);
+ if (regulatingTerminalId != null || regulatingTerminalType != null || regulatingTerminalVlId != null) {
+ if (regulatingTerminalId == null || regulatingTerminalType == null || regulatingTerminalVlId == null) {
+ throw new NetworkModificationException(CREATE_BATTERY_ERROR, errorMessage + "regulatingTerminalId, regulatingTerminalType, and regulatingTerminalVlId must all be provided together");
+ }
+ ModificationUtils.getInstance().getTerminalFromIdentifiable(network,
+ regulatingTerminalId,
+ regulatingTerminalType,
+ regulatingTerminalVlId);
+ }
+ checkIsNotNegativeValue(errorMessage, targetV, CREATE_BATTERY_ERROR, "Target Voltage");📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // check regulated terminal | |
| VoltageLevel voltageLevel = ModificationUtils.getInstance().getVoltageLevel(network, voltageLevelId); | |
| ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(), | |
| regulatingTerminalId, | |
| regulatingTerminalType, | |
| regulatingTerminalVlId); | |
| checkIsNotNegativeValue(errorMessage, targetV, CREATE_BATTERY_ERROR, "Target Voltage"); | |
| // check regulated terminal | |
| VoltageLevel voltageLevel = ModificationUtils.getInstance().getVoltageLevel(network, voltageLevelId); | |
| if (regulatingTerminalId != null || regulatingTerminalType != null || regulatingTerminalVlId != null) { | |
| if (regulatingTerminalId == null || regulatingTerminalType == null || regulatingTerminalVlId == null) { | |
| throw new NetworkModificationException(CREATE_BATTERY_ERROR, errorMessage + "regulatingTerminalId, regulatingTerminalType, and regulatingTerminalVlId must all be provided together"); | |
| } | |
| ModificationUtils.getInstance().getTerminalFromIdentifiable(network, | |
| regulatingTerminalId, | |
| regulatingTerminalType, | |
| regulatingTerminalVlId); | |
| } | |
| checkIsNotNegativeValue(errorMessage, targetV, CREATE_BATTERY_ERROR, "Target Voltage"); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/main/java/org/gridsuite/modification/modifications/BatteryCreation.java`
around lines 97 - 104, Update the regulated-terminal validation in
BatteryCreation to reject partially specified regulating terminal fields instead
of allowing getTerminalFromIdentifiable to return null; validate that the
regulating terminal arguments are either all provided or all absent, then
perform lookup using the existing network argument rather than
voltageLevel.getNetwork().
| private void createBatteryVoltageRegulation(Battery battery, VoltageLevel voltageLevel, ReportNode subReportNode) { | ||
| Terminal regulatingTerminal = ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(), | ||
| regulatingTerminalId, | ||
| regulatingTerminalType, | ||
| regulatingTerminalVlId); | ||
| List<ReportNode> voltageReports = new ArrayList<>(); | ||
| VoltageRegulationAdder voltageRegulationAdder = battery.newExtension(VoltageRegulationAdder.class) | ||
| .withRegulatingTerminal(regulatingTerminal) | ||
| .withVoltageRegulatorOn(voltageRegulationOn); | ||
| if (targetV != null) { | ||
| voltageRegulationAdder.withTargetV(targetV); | ||
| } | ||
| voltageRegulationAdder.add(); | ||
| voltageReports.add(ModificationUtils.getInstance().buildCreationReport( | ||
| regulatingTerminalVlId, | ||
| "Voltage level")); | ||
| voltageReports.add(ModificationUtils.getInstance().buildCreationReport( | ||
| regulatingTerminalType + ":" + regulatingTerminalId, | ||
| "Equipment")); | ||
| ModificationUtils.getInstance().reportModifications(subReportNode, voltageReports, "network.modification.VoltageRegulationCreated"); | ||
| } | ||
|
|
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Conditionally create the VoltageRegulation extension and prevent "null:null" in reports.
Currently, a VoltageRegulation extension is unconditionally added to every created battery, even if no voltage regulation parameters were provided. Additionally, if the regulating terminal parameters are missing, the report will literally output "null:null" for the Equipment.
Add a guard to only create the extension when voltage regulation is configured, and handle null safely in the reports.
🐛 Proposed fix
private void createBatteryVoltageRegulation(Battery battery, VoltageLevel voltageLevel, ReportNode subReportNode) {
+ if (!voltageRegulationOn && targetV == null && regulatingTerminalId == null && regulatingTerminalType == null && regulatingTerminalVlId == null) {
+ return;
+ }
Terminal regulatingTerminal = ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(),
regulatingTerminalId,
regulatingTerminalType,
regulatingTerminalVlId);
List<ReportNode> voltageReports = new ArrayList<>();
VoltageRegulationAdder voltageRegulationAdder = battery.newExtension(VoltageRegulationAdder.class)
.withRegulatingTerminal(regulatingTerminal)
.withVoltageRegulatorOn(voltageRegulationOn);
if (targetV != null) {
voltageRegulationAdder.withTargetV(targetV);
}
voltageRegulationAdder.add();
- voltageReports.add(ModificationUtils.getInstance().buildCreationReport(
- regulatingTerminalVlId,
- "Voltage level"));
- voltageReports.add(ModificationUtils.getInstance().buildCreationReport(
- regulatingTerminalType + ":" + regulatingTerminalId,
- "Equipment"));
+ if (regulatingTerminalVlId != null) {
+ voltageReports.add(ModificationUtils.getInstance().buildCreationReport(
+ regulatingTerminalVlId,
+ "Voltage level"));
+ }
+ if (regulatingTerminalId != null && regulatingTerminalType != null) {
+ voltageReports.add(ModificationUtils.getInstance().buildCreationReport(
+ regulatingTerminalType + ":" + regulatingTerminalId,
+ "Equipment"));
+ }
ModificationUtils.getInstance().reportModifications(subReportNode, voltageReports, "network.modification.VoltageRegulationCreated");
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| private void createBatteryVoltageRegulation(Battery battery, VoltageLevel voltageLevel, ReportNode subReportNode) { | |
| Terminal regulatingTerminal = ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(), | |
| regulatingTerminalId, | |
| regulatingTerminalType, | |
| regulatingTerminalVlId); | |
| List<ReportNode> voltageReports = new ArrayList<>(); | |
| VoltageRegulationAdder voltageRegulationAdder = battery.newExtension(VoltageRegulationAdder.class) | |
| .withRegulatingTerminal(regulatingTerminal) | |
| .withVoltageRegulatorOn(voltageRegulationOn); | |
| if (targetV != null) { | |
| voltageRegulationAdder.withTargetV(targetV); | |
| } | |
| voltageRegulationAdder.add(); | |
| voltageReports.add(ModificationUtils.getInstance().buildCreationReport( | |
| regulatingTerminalVlId, | |
| "Voltage level")); | |
| voltageReports.add(ModificationUtils.getInstance().buildCreationReport( | |
| regulatingTerminalType + ":" + regulatingTerminalId, | |
| "Equipment")); | |
| ModificationUtils.getInstance().reportModifications(subReportNode, voltageReports, "network.modification.VoltageRegulationCreated"); | |
| } | |
| private void createBatteryVoltageRegulation(Battery battery, VoltageLevel voltageLevel, ReportNode subReportNode) { | |
| if (!voltageRegulationOn && targetV == null && regulatingTerminalId == null && regulatingTerminalType == null && regulatingTerminalVlId == null) { | |
| return; | |
| } | |
| Terminal regulatingTerminal = ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(), | |
| regulatingTerminalId, | |
| regulatingTerminalType, | |
| regulatingTerminalVlId); | |
| List<ReportNode> voltageReports = new ArrayList<>(); | |
| VoltageRegulationAdder voltageRegulationAdder = battery.newExtension(VoltageRegulationAdder.class) | |
| .withRegulatingTerminal(regulatingTerminal) | |
| .withVoltageRegulatorOn(voltageRegulationOn); | |
| if (targetV != null) { | |
| voltageRegulationAdder.withTargetV(targetV); | |
| } | |
| voltageRegulationAdder.add(); | |
| if (regulatingTerminalVlId != null) { | |
| voltageReports.add(ModificationUtils.getInstance().buildCreationReport( | |
| regulatingTerminalVlId, | |
| "Voltage level")); | |
| } | |
| if (regulatingTerminalId != null && regulatingTerminalType != null) { | |
| voltageReports.add(ModificationUtils.getInstance().buildCreationReport( | |
| regulatingTerminalType + ":" + regulatingTerminalId, | |
| "Equipment")); | |
| } | |
| ModificationUtils.getInstance().reportModifications(subReportNode, voltageReports, "network.modification.VoltageRegulationCreated"); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/main/java/org/gridsuite/modification/modifications/BatteryCreation.java`
around lines 192 - 213, Update createBatteryVoltageRegulation to return without
creating a VoltageRegulation extension when voltage regulation parameters are
not configured, while preserving the existing setup when configuration is
present. Build the equipment report identifier without producing "null:null"
when regulatingTerminalType or regulatingTerminalId is missing, using a
null-safe representation instead.



PR Summary