Add Line segments infos into database for line creation#787
Add Line segments infos into database for line creation#787
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe changes introduce support for managing line segments within line creation entities. A new Changes
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
pom.xmlsrc/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineCreationEntity.javasrc/main/java/org/gridsuite/modification/server/entities/equipment/creation/LineSegmentEntity.javasrc/main/resources/db/changelog/db.changelog-master.yaml
| @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; |
There was a problem hiding this comment.
🧩 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 -60Repository: 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 -20Repository: 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 javaRepository: 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 -20Repository: 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 -20Repository: 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.javaRepository: 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 -80Repository: 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/nullRepository: 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 -20Repository: 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 -20Repository: 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 -100Repository: 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 -100Repository: 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/nullRepository: 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.xmlRepository: 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 catRepository: 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 -20Repository: 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 -10Repository: 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 -5Repository: 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 -20Repository: 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 -50Repository: 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 -100Repository: 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.javaRepository: 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.javaRepository: 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 -60Repository: 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.
| @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.
...in/java/org/gridsuite/modification/server/entities/equipment/creation/LineSegmentEntity.java
Show resolved
Hide resolved
Signed-off-by: basseche <bassel.el-cheikh_externe@rte-france.com>
c09f515 to
5ff3748
Compare
PR Summary
Add Line segments entity table related to line creation