Skip to content

voltage measurements modification for busbar-section network-modification#821

Merged
benrejebmoh merged 6 commits into
mainfrom
busbar-voltage-measurements
May 29, 2026
Merged

voltage measurements modification for busbar-section network-modification#821
benrejebmoh merged 6 commits into
mainfrom
busbar-voltage-measurements

Conversation

@benrejebmoh
Copy link
Copy Markdown
Contributor

PR Summary

voltage measurements modification for busbar-section network-modification

KoloMenek and others added 3 commits May 26, 2026 11:31
…n' into busbar-voltage-measurements

# Conflicts:
#	pom.xml
#	src/main/resources/db/changelog/db.changelog-master.yaml
#	src/test/java/org/gridsuite/modification/server/modifications/BatteryModificationTest.java
…tion

Signed-off-by: benrejebmoh <mohamed.ben-rejeb@rte-france.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds busbar section voltage measurement support to the network modification server. It introduces a new JPA entity to persist voltage measurements and validity on individual busbar sections, integrates the entity into voltage level modifications with lifecycle synchronization, defines the database schema with proper constraints, and validates the feature with comprehensive test coverage including an upsert scenario.

Changes

Busbar Section Voltage Measurement Feature

Layer / File(s) Summary
Data Model and Database Schema
pom.xml, src/main/java/org/gridsuite/modification/server/entities/equipment/modification/BusbarSectionVMeasurementEntity.java, src/main/resources/db/changelog/changesets/changelog_20260526T094439Z.xml, src/main/resources/db/changelog/db.changelog-master.yaml
Network-modification dependency upgraded to 0.84.0-SNAPSHOT to provide supporting DTOs. New BusbarSectionVMeasurementEntity JPA entity maps to busbar_section_v_measurement table with UUID PK, busbar section linkage, and embedded modification fields for voltage value (double) and validity (boolean). Database migration creates table and foreign key constraint to voltage_level_modification.
Entity Relationship and Persistence Sync
src/main/java/org/gridsuite/modification/server/entities/equipment/modification/VoltageLevelModificationEntity.java
VoltageLevelModificationEntity adds OneToMany relationship with cascade and orphan removal to BusbarSectionVMeasurementEntity. assignAttributes() initializes and repopulates measurements from DTOs. toVoltageLevelModificationInfosBuilder() maps persisted entities back to DTO representation. Imports consolidated to jakarta.persistence wildcard.
Test Fixtures and Validation
src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelModificationTest.java
Test imports and constants added for measurement support. Modification fixtures extended to create and update busbar section voltage measurements on busbar section "1.1". New assertBusbarSectionMeasurement() helper validates measurement value and validity from network graph extensions. Integration test testBusbarSectionMeasurementUpdateExistingPath() verifies sequential modification updates to existing measurements.

Suggested reviewers

  • achour94
  • etiennehomer
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding voltage measurements modification functionality for busbar-section network-modification.
Description check ✅ Passed The description directly relates to the changeset by identifying the primary feature being added (voltage measurements modification for busbar-section network-modification).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@KoloMenek KoloMenek self-requested a review May 28, 2026 12:35
Comment thread src/main/resources/db/changelog/changesets/changelog_20260526T094439Z.xml Outdated
Comment thread src/main/resources/db/changelog/changesets/changelog_20260526T094439Z.xml Outdated
Signed-off-by: benrejebmoh <mohamed.ben-rejeb@rte-france.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/main/java/org/gridsuite/modification/server/entities/equipment/modification/BusbarSectionVMeasurementEntity.java (1)

33-34: ⚡ Quick win

Mark busbarSectionId as non-null in JPA mapping.

busbarSectionId is required to identify the target busbar section; leaving it nullable in the entity weakens validation and drifts from expected domain constraints.

Suggested change
-    `@Column`(name = "busbar_section_id")
+    `@Column`(name = "busbar_section_id", nullable = false)
     private String busbarSectionId;
🤖 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/server/entities/equipment/modification/BusbarSectionVMeasurementEntity.java`
around lines 33 - 34, The busbarSectionId field in
BusbarSectionVMeasurementEntity must be marked non-nullable: update the JPA
mapping for the field busbarSectionId to include nullable = false on the `@Column`
and add a validation annotation such as `@NotNull`
(javax.validation.constraints.NotNull) on the same field; also ensure any
corresponding DB migration/schema is updated to make the column NOT NULL so the
entity and database constraints stay in sync.
src/main/resources/db/changelog/changesets/changelog_20260526T094439Z.xml (1)

19-19: ⚡ Quick win

Add an index on voltage_level_modification_id.

The FK does not automatically guarantee an index in PostgreSQL; indexing this column helps parent-row maintenance and child lookups.

Suggested addition
     <changeSet author="benrejebmoh (generated)" id="1779788708250-6">
         <addForeignKeyConstraint baseColumnNames="voltage_level_modification_id" baseTableName="busbar_section_v_measurement" constraintName="busbar_section_v_measurement_vl_id_fk" deferrable="false" initiallyDeferred="false" referencedColumnNames="id" referencedTableName="voltage_level_modification" validate="true"/>
     </changeSet>
+    <changeSet author="benrejebmoh" id="1779788708250-7">
+        <createIndex tableName="busbar_section_v_measurement" indexName="idx_busbar_section_v_measurement_vl_id">
+            <column name="voltage_level_modification_id"/>
+        </createIndex>
+    </changeSet>
🤖 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/resources/db/changelog/changesets/changelog_20260526T094439Z.xml` at
line 19, Add a createIndex change for the column referenced by the FK: in the
changelog that adds the foreign key (the line that creates constraint
"busbar_section_v_measurement_vl_id_fk") also add a createIndex for table
"busbar_section_v_measurement" on column "voltage_level_modification_id" (e.g.,
index name like
"idx_busbar_section_v_measurement_voltage_level_modification_id") so PostgreSQL
has an index for parent-row maintenance and child lookups; ensure the index
change is in the same changeset or an immediately following one and include a
matching rollback if your changelog pattern requires it.
🤖 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/resources/db/changelog/changesets/changelog_20260526T094439Z.xml`:
- Around line 4-20: Add a NOT NULL constraint to busbar_section_id and add a
unique constraint on (voltage_level_modification_id, busbar_section_id) for the
busbar_section_v_measurement table: update the createTable for
busbar_section_v_measurement to mark column busbar_section_id as
nullable="false" and add an addUniqueConstraint changeSet (or inline constraint)
for columns voltage_level_modification_id and busbar_section_id (name it e.g.
busbar_section_v_measurement_vl_bs_uk) so duplicate rows for the same
voltage_level_modification_id + busbar_section_id are prevented and the target
busbar is required.

In
`@src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelModificationTest.java`:
- Around line 117-121: The test currently allows multiple voltage measurements;
tighten it by asserting that the collection returned by
measurements.getMeasurements(Measurement.Type.VOLTAGE) has size 1 before
checking fields—e.g., replace or augment the current
assertThat(voltageMeasurements).isNotEmpty() check with an exact cardinality
assertion (sizeEquals/hasSize(1)) on voltageMeasurements, then validate
m.getValue() and m.isValid() for the single element; apply the same change to
the other occurrence around lines 279-300 to enforce upsert semantics.

---

Nitpick comments:
In
`@src/main/java/org/gridsuite/modification/server/entities/equipment/modification/BusbarSectionVMeasurementEntity.java`:
- Around line 33-34: The busbarSectionId field in
BusbarSectionVMeasurementEntity must be marked non-nullable: update the JPA
mapping for the field busbarSectionId to include nullable = false on the `@Column`
and add a validation annotation such as `@NotNull`
(javax.validation.constraints.NotNull) on the same field; also ensure any
corresponding DB migration/schema is updated to make the column NOT NULL so the
entity and database constraints stay in sync.

In `@src/main/resources/db/changelog/changesets/changelog_20260526T094439Z.xml`:
- Line 19: Add a createIndex change for the column referenced by the FK: in the
changelog that adds the foreign key (the line that creates constraint
"busbar_section_v_measurement_vl_id_fk") also add a createIndex for table
"busbar_section_v_measurement" on column "voltage_level_modification_id" (e.g.,
index name like
"idx_busbar_section_v_measurement_voltage_level_modification_id") so PostgreSQL
has an index for parent-row maintenance and child lookups; ensure the index
change is in the same changeset or an immediately following one and include a
matching rollback if your changelog pattern requires it.
🪄 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: f2939d1b-833e-4ea4-8953-6110d99b2b39

📥 Commits

Reviewing files that changed from the base of the PR and between 6e50610 and 648e344.

📒 Files selected for processing (6)
  • pom.xml
  • src/main/java/org/gridsuite/modification/server/entities/equipment/modification/BusbarSectionVMeasurementEntity.java
  • src/main/java/org/gridsuite/modification/server/entities/equipment/modification/VoltageLevelModificationEntity.java
  • src/main/resources/db/changelog/changesets/changelog_20260526T094439Z.xml
  • src/main/resources/db/changelog/db.changelog-master.yaml
  • src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelModificationTest.java

Comment on lines +4 to +20
<createTable tableName="busbar_section_v_measurement">
<column name="id" type="UUID">
<constraints nullable="false" primaryKey="true" primaryKeyName="busbar_section_v_measurementPK"/>
</column>
<column name="busbar_section_id" type="VARCHAR(255)"/>
<column name="v_measurement_validity_op" type="VARCHAR(255)"/>
<column name="v_measurement_validity" type="BOOLEAN"/>
<column name="v_measurement_value_op" type="VARCHAR(255)"/>
<column name="v_measurement_value" type="FLOAT(53)"/>
<column name="voltage_level_modification_id" type="UUID">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet author="benrejebmoh (generated)" id="1779788708250-6">
<addForeignKeyConstraint baseColumnNames="voltage_level_modification_id" baseTableName="busbar_section_v_measurement" constraintName="busbar_section_v_measurement_vl_id_fk" deferrable="false" initiallyDeferred="false" referencedColumnNames="id" referencedTableName="voltage_level_modification" validate="true"/>
</changeSet>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Enforce busbar measurement row uniqueness and required target busbar.

The schema currently allows multiple rows for the same (voltage_level_modification_id, busbar_section_id) and allows busbar_section_id to be null. That can break deterministic upsert behavior and permit invalid records.

Suggested migration hardening
     <changeSet author="benrejebmoh (generated)" id="1779788708250-3">
         <createTable tableName="busbar_section_v_measurement">
@@
-            <column name="busbar_section_id" type="VARCHAR(255)"/>
+            <column name="busbar_section_id" type="VARCHAR(255)">
+                <constraints nullable="false"/>
+            </column>
@@
         </createTable>
+        <addUniqueConstraint
+                tableName="busbar_section_v_measurement"
+                columnNames="voltage_level_modification_id,busbar_section_id"
+                constraintName="uk_busbar_section_v_measurement_vl_bbs"/>
     </changeSet>
🤖 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/resources/db/changelog/changesets/changelog_20260526T094439Z.xml`
around lines 4 - 20, Add a NOT NULL constraint to busbar_section_id and add a
unique constraint on (voltage_level_modification_id, busbar_section_id) for the
busbar_section_v_measurement table: update the createTable for
busbar_section_v_measurement to mark column busbar_section_id as
nullable="false" and add an addUniqueConstraint changeSet (or inline constraint)
for columns voltage_level_modification_id and busbar_section_id (name it e.g.
busbar_section_v_measurement_vl_bs_uk) so duplicate rows for the same
voltage_level_modification_id + busbar_section_id are prevented and the target
busbar is required.

Comment on lines +117 to +121
Collection<Measurement> voltageMeasurements = measurements.getMeasurements(Measurement.Type.VOLTAGE).stream().toList();
assertThat(voltageMeasurements).isNotEmpty().allSatisfy(m -> {
assertThat(m.getValue()).isEqualTo(expectedValue);
assertThat(m.isValid()).isEqualTo(expectedValid);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Assert single voltage measurement to actually validate upsert semantics.

Current checks allow duplicate measurements with the same value/validity. For the update-existing path, assert cardinality is exactly 1 before validating fields.

Suggested test tightening
-        Collection<Measurement> voltageMeasurements = measurements.getMeasurements(Measurement.Type.VOLTAGE).stream().toList();
-        assertThat(voltageMeasurements).isNotEmpty().allSatisfy(m -> {
+        Collection<Measurement> voltageMeasurements = measurements.getMeasurements(Measurement.Type.VOLTAGE).stream().toList();
+        assertThat(voltageMeasurements).hasSize(1).allSatisfy(m -> {
             assertThat(m.getValue()).isEqualTo(expectedValue);
             assertThat(m.isValid()).isEqualTo(expectedValid);
         });

Also applies to: 279-300

🤖 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/test/java/org/gridsuite/modification/server/modifications/VoltageLevelModificationTest.java`
around lines 117 - 121, The test currently allows multiple voltage measurements;
tighten it by asserting that the collection returned by
measurements.getMeasurements(Measurement.Type.VOLTAGE) has size 1 before
checking fields—e.g., replace or augment the current
assertThat(voltageMeasurements).isNotEmpty() check with an exact cardinality
assertion (sizeEquals/hasSize(1)) on voltageMeasurements, then validate
m.getValue() and m.isValid() for the single element; apply the same change to
the other occurrence around lines 279-300 to enforce upsert semantics.

@sonarqubecloud
Copy link
Copy Markdown

@benrejebmoh benrejebmoh merged commit 2d95e69 into main May 29, 2026
5 checks passed
@benrejebmoh benrejebmoh deleted the busbar-voltage-measurements branch May 29, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants