voltage measurements modification for busbar-section network-modification#821
Conversation
…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>
📝 WalkthroughWalkthroughThis 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. ChangesBusbar Section Voltage Measurement Feature
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ 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. Comment |
Signed-off-by: benrejebmoh <mohamed.ben-rejeb@rte-france.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/main/java/org/gridsuite/modification/server/entities/equipment/modification/BusbarSectionVMeasurementEntity.java (1)
33-34: ⚡ Quick winMark
busbarSectionIdas non-null in JPA mapping.
busbarSectionIdis 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 winAdd 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
📒 Files selected for processing (6)
pom.xmlsrc/main/java/org/gridsuite/modification/server/entities/equipment/modification/BusbarSectionVMeasurementEntity.javasrc/main/java/org/gridsuite/modification/server/entities/equipment/modification/VoltageLevelModificationEntity.javasrc/main/resources/db/changelog/changesets/changelog_20260526T094439Z.xmlsrc/main/resources/db/changelog/db.changelog-master.yamlsrc/test/java/org/gridsuite/modification/server/modifications/VoltageLevelModificationTest.java
| <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> |
There was a problem hiding this comment.
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.
| 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); | ||
| }); |
There was a problem hiding this comment.
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.
# Conflicts: # pom.xml
|



PR Summary
voltage measurements modification for busbar-section network-modification