Skip to content

Add Line segments infos into database for line creation#787

Open
basseche wants to merge 3 commits intomainfrom
add_LineSegments_LineCreation
Open

Add Line segments infos into database for line creation#787
basseche wants to merge 3 commits intomainfrom
add_LineSegments_LineCreation

Conversation

@basseche
Copy link
Copy Markdown
Contributor

PR Summary

Add Line segments entity table related to line creation

@basseche basseche self-assigned this Mar 24, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

Adds persistent line-segment support: new LineSegmentEntity, LineCreationEntity now holds a one-to-many association to line segments, Liquibase changelog entries add corresponding tables and constraints, and the Maven property network-modification.version is bumped to 0.73.0-SNAPSHOT.

Changes

Cohort / File(s) Summary
Dependency Update
pom.xml
Bumped network-modification.version from 0.72.0 to 0.73.0-SNAPSHOT (affects org.gridsuite:gridsuite-network-modification via dependencyManagement).
Line Segment Entity
src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineSegmentEntity.java
Added new JPA entity LineSegmentEntity with UUID PK and columns for segmentTypeId, segmentDistanceValue, area, temperature, shapeFactor; includes static converters to/from LineSegmentInfos.
Line Creation Entity
src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineCreationEntity.java
Added @OneToMany lineSegments relation (join table, cascade ALL, orphanRemoval true) and updated constructors/serializers to populate/emit lineSegments from/to LineCreationInfos.
Database Migrations
src/main/resources/db/changelog/db.changelog-master.yaml, src/main/resources/db/changelog/changesets/changelog_20260324T101024Z.xml
Appended include to master changelog and added changelog that creates line_segments and line_creation_line_segments tables, unique constraint and foreign keys linking line creations to line segments.
🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding line segment information persistence to the database for line creation functionality.
Description check ✅ Passed The description is related to the changeset, stating that line segments entity/table support for line creation is being added.

✏️ 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.

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineCreationEntity.java`:
- Around line 44-49: LineCreationEntity currently maps the
List<LineSegmentEntity> lineSegments without preserving order; update the
mapping on lineSegments to add an `@OrderColumn` (e.g., `@OrderColumn`(name =
"line_segments_order") or similar) so the list index is persisted and round-trip
order is stable, and explicitly set the join table name in the `@JoinTable` (e.g.,
name = "line_creation_line_segments") rather than relying on Hibernate defaults
so Liquibase schema matches; keep the existing joinColumns, inverseJoinColumns
and uniqueConstraints but move them into the explicitly named `@JoinTable` and
ensure the OrderColumn column name does not conflict with existing constraints.

In
`@src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineSegmentEntity.java`:
- Around line 66-75: fromLineSegmentsEntity currently dereferences its input
list and will NPE if lineSegmentEntities is null; make it null-safe by returning
Collections.emptyList() (or new ArrayList<>()) when lineSegmentEntities is null,
otherwise map each LineSegmentEntity to a LineSegmentInfos as it does now,
updating the method body in fromLineSegmentsEntity to check for null before
iterating; this mirrors the null-safety in toLineSegmentEntities and avoids
breaking LineCreationEntity.toLineCreationInfosBuilder.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e37c68b4-5f4e-4f48-8d9e-95d0b0d7429d

📥 Commits

Reviewing files that changed from the base of the PR and between 5bfaf54 and 6b7538f.

📒 Files selected for processing (4)
  • pom.xml
  • src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineCreationEntity.java
  • src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineSegmentEntity.java
  • src/main/resources/db/changelog/db.changelog-master.yaml

Signed-off-by: basseche <bassel.el-cheikh_externe@rte-france.com>
@basseche basseche force-pushed the add_LineSegments_LineCreation branch from c09f515 to 5ff3748 Compare March 24, 2026 13:20
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.

♻️ Duplicate comments (1)
src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineCreationEntity.java (1)

44-49: ⚠️ Potential issue | 🟠 Major

Persist lineSegments order.

This is still mapped as an ordered List, but the association does not store any index. After a save/reload cycle, segment order is unspecified and the reconstructed LineCreationInfos can change. Add an @OrderColumn here and the matching column in line_creation_line_segments.

Suggested change
     `@OneToMany`(cascade = CascadeType.ALL, orphanRemoval = true)
+    `@OrderColumn`(name = "segment_index")
     `@JoinTable`(
         joinColumns = `@JoinColumn`(name = "line_id"), foreignKey = `@ForeignKey`(name = "line_id_fk"),
         inverseJoinColumns = `@JoinColumn`(name = "line_segments_id"), inverseForeignKey = `@ForeignKey`(name = "line_segments_id_fk"),
         uniqueConstraints = `@UniqueConstraint`(name = "line_creation_line_segments_uk", columnNames = {"line_segments_id"}))
     private List<LineSegmentEntity> lineSegments;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineCreationEntity.java`
around lines 44 - 49, The lineSegments List in LineCreationEntity is not
persisted with an order index; add `@OrderColumn` to the lineSegments field (e.g.,
`@OrderColumn`(name = "segment_order")) and update the join table definition for
line_creation_line_segments to include the matching index column (segment_order)
so JPA will persist and restore the List element order; ensure the column is
included in the JoinTable DDL/migration and name matches the `@OrderColumn` value.
🧹 Nitpick comments (1)
src/main/resources/db/changelog/changesets/changelog_20260324T101024Z.xml (1)

4-11: Index line_creation_line_segments.line_id.

LineCreationEntity.lineSegments will be read and cleaned up through line_id, but the schema only gets an index on line_segments_id via the unique constraint. Add a parent-side index here to avoid full scans and expensive FK checks once this join table grows.

Suggested change
     <changeSet author="elcheikhbas (generated)" id="1774347058503-15">
         <createTable tableName="line_creation_line_segments">
             <column name="line_id" type="UUID">
                 <constraints nullable="false"/>
             </column>
             <column name="line_segments_id" type="UUID">
                 <constraints nullable="false"/>
             </column>
         </createTable>
+        <createIndex indexName="line_creation_line_segments_line_id_idx"
+                     tableName="line_creation_line_segments">
+            <column name="line_id"/>
+        </createIndex>
     </changeSet>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/resources/db/changelog/changesets/changelog_20260324T101024Z.xml`
around lines 4 - 11, Add a non-unique index on the parent column to avoid full
scans: modify the changeset that creates the join table
line_creation_line_segments to add an index for column "line_id" (in addition to
the existing unique constraint on "line_segments_id"); update the XML to include
an <createIndex> (or equivalent index element) targeting
tableName="line_creation_line_segments" and column name="line_id" so lookups
from LineCreationEntity.lineSegments use the indexed parent key.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In
`@src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineCreationEntity.java`:
- Around line 44-49: The lineSegments List in LineCreationEntity is not
persisted with an order index; add `@OrderColumn` to the lineSegments field (e.g.,
`@OrderColumn`(name = "segment_order")) and update the join table definition for
line_creation_line_segments to include the matching index column (segment_order)
so JPA will persist and restore the List element order; ensure the column is
included in the JoinTable DDL/migration and name matches the `@OrderColumn` value.

---

Nitpick comments:
In `@src/main/resources/db/changelog/changesets/changelog_20260324T101024Z.xml`:
- Around line 4-11: Add a non-unique index on the parent column to avoid full
scans: modify the changeset that creates the join table
line_creation_line_segments to add an index for column "line_id" (in addition to
the existing unique constraint on "line_segments_id"); update the XML to include
an <createIndex> (or equivalent index element) targeting
tableName="line_creation_line_segments" and column name="line_id" so lookups
from LineCreationEntity.lineSegments use the indexed parent key.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 15fbc59c-757c-495e-972a-c80ba2170599

📥 Commits

Reviewing files that changed from the base of the PR and between 6b7538f and 5fc3f77.

📒 Files selected for processing (5)
  • pom.xml
  • src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineCreationEntity.java
  • src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineSegmentEntity.java
  • src/main/resources/db/changelog/changesets/changelog_20260324T101024Z.xml
  • src/main/resources/db/changelog/db.changelog-master.yaml
✅ Files skipped from review due to trivial changes (2)
  • src/main/resources/db/changelog/db.changelog-master.yaml
  • pom.xml
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineSegmentEntity.java

Copy link
Copy Markdown
Contributor

@flomillot flomillot left a comment

Choose a reason for hiding this comment

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

No tests ? DTO conversion etc

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