Skip to content

Add Line segments infos into database for line creation#787

Open
basseche wants to merge 1 commit intomainfrom
add_LineSegments_LineCreation
Open

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

Conversation

@basseche
Copy link
Contributor

PR Summary

Add Line segments entity table related to line creation

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

coderabbitai bot commented Mar 24, 2026

Warning

Rate limit exceeded

@basseche has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 49 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e3f6f8d9-ef94-4196-b490-eea2c1875380

📥 Commits

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

📒 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
📝 Walkthrough

Walkthrough

The changes introduce support for managing line segments within line creation entities. A new LineSegmentEntity JPA entity is added to persist line segment data, with LineCreationEntity updated to maintain a one-to-many relationship to line segments. A corresponding database migration is included, and the network-modification dependency is updated to version 0.73.0-SNAPSHOT.

Changes

Cohort / File(s) Summary
Dependency Update
pom.xml
Updated network-modification.version from 0.72.0 to 0.73.0-SNAPSHOT, which affects the resolved version of the managed org.gridsuite:gridsuite-network-modification dependency.
Line Segment Entity Model
src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineSegmentEntity.java
New JPA entity class persisting line segment data with fields for segment type, distance value, area, temperature, and shape factor. Includes static conversion utilities to map between LineSegmentEntity and LineSegmentInfos objects.
Line Creation Entity Update
src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineCreationEntity.java
Added @OneToMany relationship to LineSegmentEntity with cascade-all and orphan removal enabled. Updated constructors and assignment methods to populate line segments from LineCreationInfos. Modified toLineCreationInfosBuilder() to include converted line segment data in the output.
Database Schema Migration
src/main/resources/db/changelog/db.changelog-master.yaml
Added Flyway Liquibase changelog include entry for changesets/changelog_20260324T101024Z.xml to apply the new line segments table schema to the database.
🚥 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 'Add Line segments infos into database for line creation' accurately summarizes the main change: adding a new LineSegmentEntity and database table to support line segments in the line creation process.
Description check ✅ Passed The description 'Add Line segments entity table related to line creation' is directly related to the changeset, which introduces LineSegmentEntity, database schema updates, and integration with LineCreationEntity.

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

@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

Comment on lines +44 to +49
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@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;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's verify the current state of the file
cat -n src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineCreationEntity.java | head -60

Repository: gridsuite/network-modification-server

Length of output: 2661


🏁 Script executed:

# Check if there's a Liquibase schema with the join table definition
find . -type f -name "*.xml" -o -name "*.sql" | xargs grep -l "line_creation_line_segments" 2>/dev/null | head -20

Repository: gridsuite/network-modification-server

Length of output: 63


🏁 Script executed:

# Look for LineSegmentEntity definition and how it's used
fd -t f "LineSegmentEntity.java"

Repository: gridsuite/network-modification-server

Length of output: 179


🏁 Script executed:

# Check LineCreationInfos to understand the round-trip
fd -t f "LineCreationInfos.java"

Repository: gridsuite/network-modification-server

Length of output: 63


🏁 Script executed:

# Search for any `@OrderColumn` usage patterns in the codebase
rg "@OrderColumn" --type java

Repository: gridsuite/network-modification-server

Length of output: 1798


🏁 Script executed:

# Search for Liquibase changesets defining the join table
find . -type f \( -name "*.xml" -o -name "*.sql" -o -name "*.yaml" -o -name "*.yml" \) | xargs grep -l "line_creation" 2>/dev/null | head -20

Repository: gridsuite/network-modification-server

Length of output: 1270


🏁 Script executed:

# Look for any schema definitions or database migrations
find . -path "*/db/changelog*" -o -path "*/liquibase*" -o -path "*/migration*" | head -20

Repository: gridsuite/network-modification-server

Length of output: 1543


🏁 Script executed:

# Check LineSegmentEntity definition
cat -n src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineSegmentEntity.java

Repository: gridsuite/network-modification-server

Length of output: 3168


🏁 Script executed:

# Search for LineCreationInfos usage of lineSegments
rg "lineSegments" --type java -A 3 -B 3 | head -80

Repository: gridsuite/network-modification-server

Length of output: 8228


🏁 Script executed:

# Check if there's any database schema definition file
find . -type f -name "*.sql" -o -name "*.xml" | xargs grep -l "line_creation_line_segments" 2>/dev/null

Repository: gridsuite/network-modification-server

Length of output: 65


🏁 Script executed:

# Search for the actual join table definition in Liquibase changesets
grep -r "line_creation" ./src/main/resources/db/changelog/changesets/ 2>/dev/null | head -20

Repository: gridsuite/network-modification-server

Length of output: 3629


🏁 Script executed:

# Check if the mapping is even in the database schema or if it's just runtime
grep -r "line_segments" ./src/main/resources/db/changelog/changesets/ 2>/dev/null | head -20

Repository: gridsuite/network-modification-server

Length of output: 63


🏁 Script executed:

# Check the parent class BranchCreationEntity for context
cat -n src/main/java/org/gridsuite/modification/server/entities/equipment/creation/BranchCreationEntity.java | head -100

Repository: gridsuite/network-modification-server

Length of output: 4279


🏁 Script executed:

# Look at how the round-trip is used in the API/DTO layer
fd -t f "LineCreationInfos.java" -exec cat {} \;

Repository: gridsuite/network-modification-server

Length of output: 268


🏁 Script executed:

# Find LineCreationInfos properly
find . -type f -name "LineCreationInfos.java"

Repository: gridsuite/network-modification-server

Length of output: 63


🏁 Script executed:

# Search for how lineSegments is used in tests or APIs
rg "getLineSegments|setLineSegments" --type java -B 3 -A 3 | head -100

Repository: gridsuite/network-modification-server

Length of output: 2127


🏁 Script executed:

# Check if there are tests that verify order preservation
rg "lineSegments" --type java -l | xargs grep -l "test\|Test" 2>/dev/null

Repository: gridsuite/network-modification-server

Length of output: 65


🏁 Script executed:

# Look at one of the recent changesets to see if line_segments join table is defined
cat src/main/resources/db/changelog/changesets/changelog_20221219T194538Z.xml

Repository: gridsuite/network-modification-server

Length of output: 1711


🏁 Script executed:

# Search for the most recent changelog that might have the lineSegments join table
find ./src/main/resources/db/changelog/changesets -type f -name "*.xml" | sort | tail -5 | xargs cat

Repository: gridsuite/network-modification-server

Length of output: 8649


🏁 Script executed:

# Check if lineSegments join table is actually defined anywhere in the schema
rg "line_creation_line_segments|lineSegments" ./src/main/resources/db/changelog/changesets/ 2>/dev/null | head -20

Repository: gridsuite/network-modification-server

Length of output: 63


🏁 Script executed:

# Look at git history to see when lineSegments was added
git log --oneline --all -- "src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineCreationEntity.java" 2>/dev/null | head -10

Repository: gridsuite/network-modification-server

Length of output: 679


🏁 Script executed:

# Find if there's a DTO definition for LineCreationInfos
find . -path "*/dto/*" -name "*.java" | xargs grep -l "LineCreationInfos" | head -5

Repository: gridsuite/network-modification-server

Length of output: 63


🏁 Script executed:

# Check all entity files in creation package to understand the pattern
ls -la src/main/java/org/gridsuite/modification/server/entities/equipment/creation/*.java | head -20

Repository: gridsuite/network-modification-server

Length of output: 3235


🏁 Script executed:

# Look at the git commit that added line segments
git show 6b7538f --stat 2>/dev/null | head -50

Repository: gridsuite/network-modification-server

Length of output: 2932


🏁 Script executed:

# Check if there's a schema creation in that commit
git show 6b7538f 2>/dev/null | grep -A 20 -B 5 "line_segment" | head -100

Repository: gridsuite/network-modification-server

Length of output: 1886


🏁 Script executed:

# Look for any pending or TODO comments in LineCreationEntity
grep -n "TODO\|FIXME\|XXX" src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineCreationEntity.java

Repository: gridsuite/network-modification-server

Length of output: 63


🏁 Script executed:

# Verify the parent BranchCreationEntity doesn't specify the join table name either
grep -A 5 "@JoinTable" src/main/java/org/gridsuite/modification/server/entities/equipment/creation/BranchCreationEntity.java

Repository: gridsuite/network-modification-server

Length of output: 492


🏁 Script executed:

# Check if there's any schema changelog for the join table that might be pending
find ./src/main/resources/db/changelog/changesets -type f -name "*.xml" -exec grep -l "line_segment" {} \;

Repository: gridsuite/network-modification-server

Length of output: 63


🏁 Script executed:

# Final verification: check if there's an actual schema changeset that was added with the commit
git show 6b7538f --name-only 2>/dev/null | grep -E "\.(xml|sql)$"

Repository: gridsuite/network-modification-server

Length of output: 12531


🏁 Script executed:

# Verify the specific commit to see if schema changes were included
git show 6b7538f -- "*.xml" 2>/dev/null | grep -A 30 "createTable\|addColumn" | head -60

Repository: gridsuite/network-modification-server

Length of output: 3526


Add @OrderColumn to persist lineSegments order.

Lines 44-49 map a List without @OrderColumn, causing segments to return in arbitrary order after reload. This violates the established codebase pattern (see BranchCreationEntity.operationalLimitsGroups and similar) and breaks round-trip consistency for API consumers. Additionally, explicitly declare the join-table name instead of relying on Hibernate's derived default, as the Liquibase schema must match it.

Suggested mapping shape
     `@OneToMany`(cascade = CascadeType.ALL, orphanRemoval = true)
+    `@OrderColumn`(name = "segment_index")
     `@JoinTable`(
+        name = "line_creation_line_segments",
         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;
📝 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.

Suggested change
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@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;
`@OneToMany`(cascade = CascadeType.ALL, orphanRemoval = true)
`@OrderColumn`(name = "segment_index")
`@JoinTable`(
name = "line_creation_line_segments",
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, 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.

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

1 participant