Skip to content

Add Line segments infos into database for line creation#787

Merged
basseche merged 9 commits intomainfrom
add_LineSegments_LineCreation
Apr 10, 2026
Merged

Add Line segments infos into database for line creation#787
basseche merged 9 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

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

A new JPA entity LineSegmentEntity and a @OneToMany lineSegments association on LineCreationEntity were added, with corresponding Liquibase migrations. Tests were updated to include lineSegments data in LineCreationInfos payloads.

Changes

Cohort / File(s) Summary
Core Entities
src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineSegmentEntity.java, src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineCreationEntity.java
Added LineSegmentEntity (UUID PK, segment fields) and conversion utilities. LineCreationEntity gains a @OneToMany lineSegments mapping with cascade = ALL and orphanRemoval = true; constructors/serializers updated to map LineSegmentInfos.
Database Schema
src/main/resources/db/changelog/db.changelog-master.yaml, src/main/resources/db/changelog/changesets/changelog_20260324T101024Z.xml
Added Liquibase include and new changeset creating line_segments table and line_creation_line_segments join table, with unique constraint and foreign keys to line_creation and line_segments.
Tests
src/test/java/org/gridsuite/modification/server/modifications/LineCreationInBusBreakerTest.java, src/test/java/org/gridsuite/modification/server/modifications/LineCreationInMixedTypologyTest.java, src/test/java/org/gridsuite/modification/server/modifications/LineCreationInNodeBreakerTest.java
Updated test builders to populate LineCreationInfos.lineSegments with sample LineSegmentInfos entries to exercise persistence mapping.
Build config
pom.xml
Added network-modification.version Maven property set to 0.75.0 (temporary).

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Test as Test / Client
participant Mapper as Entity Mapper
participant Repo as JPA Repository
participant DB as Database

Test->>Mapper: build LineCreationInfos with lineSegments
Mapper->>Mapper: convert LineCreationInfos -> LineCreationEntity (create LineSegmentEntity list)
Mapper->>Repo: save(LineCreationEntity)
Repo->>DB: INSERT line_segments, INSERT join row(s)
DB-->>Repo: commit / FK validations
Repo-->>Mapper: persisted entity returned
Mapper-->>Test: response / saved identifiers
🚥 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 PR title accurately summarizes the main change: adding line segments information to the database for line creation functionality.
Description check ✅ Passed The PR description is related to the changeset, describing the addition of a Line segments entity/table to support line creation.

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

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.

🧹 Nitpick comments (1)
src/test/java/org/gridsuite/modification/server/modifications/LineCreationInNodeBreakerTest.java (1)

324-325: Consider extracting a shared line-segment test fixture.

The same lineSegments(List.of(...)) literal now appears across multiple integration tests; a shared helper/fixture would reduce drift when the segment DTO evolves.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/test/java/org/gridsuite/modification/server/modifications/LineCreationInNodeBreakerTest.java`
around lines 324 - 325, The repeated inline List.of(new LineSegmentInfos(...))
literal across tests (seen in LineCreationInNodeBreakerTest) should be extracted
into a shared test fixture helper; add a static factory method (e.g.,
TestFixtures.defaultLineSegments() or a helper in LineCreationInNodeBreakerTest
like createDefaultLineSegments()) that returns the List<LineSegmentInfos> with
the two populated segments, replace all inline occurrences with calls to that
helper, and update imports/usages so tests reference the single source of truth
(class name references: LineCreationInNodeBreakerTest, LineSegmentInfos, and any
other test classes using the literal).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@src/test/java/org/gridsuite/modification/server/modifications/LineCreationInNodeBreakerTest.java`:
- Around line 324-325: The repeated inline List.of(new LineSegmentInfos(...))
literal across tests (seen in LineCreationInNodeBreakerTest) should be extracted
into a shared test fixture helper; add a static factory method (e.g.,
TestFixtures.defaultLineSegments() or a helper in LineCreationInNodeBreakerTest
like createDefaultLineSegments()) that returns the List<LineSegmentInfos> with
the two populated segments, replace all inline occurrences with calls to that
helper, and update imports/usages so tests reference the single source of truth
(class name references: LineCreationInNodeBreakerTest, LineSegmentInfos, and any
other test classes using the literal).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 17e8b534-a703-4538-a923-6563e8217f3c

📥 Commits

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

📒 Files selected for processing (3)
  • src/test/java/org/gridsuite/modification/server/modifications/LineCreationInBusBreakerTest.java
  • src/test/java/org/gridsuite/modification/server/modifications/LineCreationInMixedTypologyTest.java
  • src/test/java/org/gridsuite/modification/server/modifications/LineCreationInNodeBreakerTest.java

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.

🧹 Nitpick comments (1)
src/test/java/org/gridsuite/modification/server/modifications/LineCreationInBusBreakerTest.java (1)

255-256: Use deterministic IDs in test fixtures

Using UUID.randomUUID() in test payloads makes failures less reproducible and fixture diffs noisier. Prefer stable, explicit identifiers for segmentTypeId in tests.

♻️ Proposed change
-            .lineSegments(List.of(new LineSegmentInfos(UUID.randomUUID().toString(), 1, "1", "50", null),
-                new LineSegmentInfos(UUID.randomUUID().toString(), 1, "1", null, 0.95)))
+            .lineSegments(List.of(new LineSegmentInfos("segmentType-1", 1, "1", "50", null),
+                new LineSegmentInfos("segmentType-2", 1, "1", null, 0.95)))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/test/java/org/gridsuite/modification/server/modifications/LineCreationInBusBreakerTest.java`
around lines 255 - 256, Tests use UUID.randomUUID() for
LineSegmentInfos.segmentTypeId which makes fixtures non-deterministic; replace
those calls in the test (LineCreationInBusBreakerTest) with stable, explicit IDs
(e.g., "segment-1", "segment-2") when constructing LineSegmentInfos so the
payloads are reproducible and diffs are stable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@src/test/java/org/gridsuite/modification/server/modifications/LineCreationInBusBreakerTest.java`:
- Around line 255-256: Tests use UUID.randomUUID() for
LineSegmentInfos.segmentTypeId which makes fixtures non-deterministic; replace
those calls in the test (LineCreationInBusBreakerTest) with stable, explicit IDs
(e.g., "segment-1", "segment-2") when constructing LineSegmentInfos so the
payloads are reproducible and diffs are stable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cef9e991-203e-4596-90e2-f064086081fb

📥 Commits

Reviewing files that changed from the base of the PR and between 5579491 and 96585a3.

📒 Files selected for processing (2)
  • src/test/java/org/gridsuite/modification/server/modifications/LineCreationInBusBreakerTest.java
  • src/test/java/org/gridsuite/modification/server/modifications/LineCreationInNodeBreakerTest.java
✅ Files skipped from review due to trivial changes (1)
  • src/test/java/org/gridsuite/modification/server/modifications/LineCreationInNodeBreakerTest.java

Signed-off-by: basseche <bassel.el-cheikh_externe@rte-france.com>
Signed-off-by: basseche <bassel.el-cheikh_externe@rte-france.com>
@sonarqubecloud
Copy link
Copy Markdown

@basseche basseche merged commit 022c331 into main Apr 10, 2026
4 checks passed
@basseche basseche deleted the add_LineSegments_LineCreation branch April 10, 2026 14:18
@basseche basseche restored the add_LineSegments_LineCreation branch April 10, 2026 14:44
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