Skip to content

Set node column position when creation#995

Open
SlimaneAmar wants to merge 14 commits into
mainfrom
set_node_column_position_when_creation
Open

Set node column position when creation#995
SlimaneAmar wants to merge 14 commits into
mainfrom
set_node_column_position_when_creation

Conversation

@SlimaneAmar

Copy link
Copy Markdown
Contributor

PR Summary

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown

Review Change Stack

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

Adds column-position tracking: repository queries expose column positions and child UUIDs; service returns node-info and computes/assigns columnPosition for CHILD/BEFORE/AFTER insertions, reworks stash/delete flows; tests updated and added to assert columnPosition across insertion, cut/paste, duplication, stash, and delete flows.

Changes

Column Position Tracking for Network Modification Nodes

Layer / File(s) Summary
Repository queries for columnPosition and children
src/main/java/org/gridsuite/study/server/repository/networkmodificationtree/NetworkModificationNodeInfoRepository.java, src/main/java/org/gridsuite/study/server/repository/networkmodificationtree/NodeRepository.java
Add findColumnPositionsByUuidIn() JPQL query and findChildrenUuids() native SQL query to support columnPosition lookups and sibling enumeration during node operations.
Service Refactoring: Node creation, insertion, duplicate, stash and delete
src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java
Refactor createNetworkModificationNode() to return the node-info entity with its persisted Node reference. Rewrite createAndInsertNode() to compute and assign columnPosition based on insert mode (CHILD, BEFORE, AFTER), update duplicateNode() call, replace stashNodes() with stashNode() plus insertNodesToParent() shifting siblings' columnPosition, and switch recursive deletion to use deleteNode().
Controller API rename
src/main/java/org/gridsuite/study/server/controller/StudyController.java
Rename DELETE handler method from deleteNode(...) to deleteNodes(...) without changing parameters or behavior.
Test Base and Unit Tests
src/test/java/org/gridsuite/study/server/studycontroller/StudyTestBase.java, src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java
Return freshly fetched node from StudyTestBase.createNetworkModificationNode() and add unit assertions verifying columnPosition before/after insertions (testNodeInsertion, testInsertAfter).
Integration Tests: Cut/Paste, Duplication, Subtree, and Positioning
src/test/java/org/gridsuite/study/server/studycontroller/NodeControllerTest.java, src/test/java/org/gridsuite/study/server/NodePositionTest.java
Update cut/paste and duplication tests to use getAllStudyNodesByUuid() and verify columnPosition for involved nodes; add NodePositionTest to validate column positions after stash/delete operations.

Suggested reviewers

  • flomillot
  • souissimai
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

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.
Description check ❓ Inconclusive The PR description is empty (only placeholder text), providing no meaningful information about the changeset or its objectives. Add a detailed PR description explaining what changed, why it was necessary, and how it affects the system's node positioning logic.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: setting node column position during node creation, which is the primary focus of the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java`:
- Around line 151-159: getNextColumnPosition currently computes next sibling
columnPosition in-memory using
networkModificationNodeInfoRepository.findColumnPositionsByUuidIn(nodesRepository.findChildrenUuids(parentNodeId))
and returns max+1, which is race-prone; change it to perform the max calculation
inside a single transactional DB operation (e.g. a repository method that runs
SELECT MAX(column_position) FROM ... WHERE parent_id = :parentNodeId FOR UPDATE
or an equivalent DB-side atomic increment) or add a unique constraint on
(parent_id, column_position) and implement a retry-on-constraint-violation
strategy; ensure the new repository method is used in getNextColumnPosition and
that the surrounding service call is annotated/handled with a transaction to
prevent concurrent duplicates.
🪄 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: 243a4303-d277-4f19-a49a-beb510f44a97

📥 Commits

Reviewing files that changed from the base of the PR and between b07c75b and ca9a746.

📒 Files selected for processing (6)
  • src/main/java/org/gridsuite/study/server/repository/networkmodificationtree/NetworkModificationNodeInfoRepository.java
  • src/main/java/org/gridsuite/study/server/repository/networkmodificationtree/NodeRepository.java
  • src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java
  • src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java
  • src/test/java/org/gridsuite/study/server/studycontroller/NodeControllerTest.java
  • src/test/java/org/gridsuite/study/server/studycontroller/StudyTestBase.java

@ayolab ayolab self-requested a review May 26, 2026 06:16
Slimane AMAR added 3 commits June 1, 2026 14:31
…into set_node_column_position_when_creation
…into set_node_column_position_when_creation
…into set_node_column_position_when_creation

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java (1)

133-149: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Cut/paste still leaves moved nodes with stale columnPosition.

This method now defines the CHILD/BEFORE/AFTER position rules for newly created nodes, but moveNode(...) at Lines 250-274 still only rewires parents. After a cut/paste, the moved node keeps the position from its old parent, BEFORE never copies the anchor position or resets the anchor to 0, and AFTER never puts the moved node at 0 under the new parent.

🧹 Nitpick comments (1)
src/test/java/org/gridsuite/study/server/NodePositionTest.java (1)

86-88: ⚡ Quick win

Fail fast when the expected node is missing

Returning null from getNode causes downstream NPEs (Line 74, Lines 80-83) and hides the real test failure. Throw an assertion-friendly exception instead so failures point to the missing node name.

Suggested change
 private AbstractNode getNode(String name, List<AbstractNode> nodes) {
-    return nodes.stream().filter(node -> node.getName().equals(name)).findFirst().orElse(null);
+    return nodes.stream()
+        .filter(node -> name.equals(node.getName()))
+        .findFirst()
+        .orElseThrow(() -> new AssertionError("Node not found: " + name));
 }

Based on learnings: duplicate sibling columnPosition values are intentionally accepted in this repository, so that concern is intentionally excluded.

🤖 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/study/server/NodePositionTest.java` around lines
86 - 88, The helper getNode currently returns null when a node is not found
which leads to downstream NPEs; change getNode(String name, List<AbstractNode>
nodes) to fail fast by throwing an assertion-friendly exception (e.g., throw new
AssertionError or IllegalStateException) including the missing node name and
available node names so test failures clearly indicate the missing node
(referencing getNode, AbstractNode and node.getName() to locate the method).
🤖 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/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java`:
- Around line 326-339: When deleting nodes with deleteChildren=false inside
deleteNodes(...), reuse the existing insertNodesToParent(...) promotion logic
instead of directly reparenting descendants: collect the list of promoted
children (the descendants to move up), and call
insertNodesToParent(parentOfDeletedNode, deletedNode.getColumnPosition(),
promotedChildren). This ensures each promoted NodeEntity has parent set and
NetworkModificationNodeInfoEntity positions are shifted/assigned consistently
(the same repositories used in insertNodesToParent: nodesRepository and
networkModificationNodeInfoRepository). Replace the ad-hoc reparenting branch in
deleteNodes(...) with this call so promoted children occupy the deleted node's
slot with correct columnPosition.
- Around line 306-335: The code unboxes and compares nullable column positions
which can NPE for legacy rows; in stashNode grab the column position as an
Integer (e.g. Integer columnPosition = nodeToStashInfo.getColumnPosition()),
handle null by deciding a safe default or by calling insertNodesToParent with a
nullable/optional position; update insertNodesToParent to accept Integer
position (or check for null) and when shifting siblings only operate on non-null
positions (e.g. filter info.getColumnPosition() != null &&
info.getColumnPosition() >= position) and compute the increment using
newChildrenInfos.size() safely; ensure any arithmetic avoids auto-unboxing of
nulls and that parent/position logic treats null columnPosition as a defined
insertion policy (end-of-list or zero) consistently across stashNode and
insertNodesToParent.

---

Nitpick comments:
In `@src/test/java/org/gridsuite/study/server/NodePositionTest.java`:
- Around line 86-88: The helper getNode currently returns null when a node is
not found which leads to downstream NPEs; change getNode(String name,
List<AbstractNode> nodes) to fail fast by throwing an assertion-friendly
exception (e.g., throw new AssertionError or IllegalStateException) including
the missing node name and available node names so test failures clearly indicate
the missing node (referencing getNode, AbstractNode and node.getName() to locate
the method).
🪄 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: cce12663-6530-4206-8863-586335624cb4

📥 Commits

Reviewing files that changed from the base of the PR and between 065ac86 and 81bd2f6.

📒 Files selected for processing (4)
  • src/main/java/org/gridsuite/study/server/controller/StudyController.java
  • src/main/java/org/gridsuite/study/server/repository/networkmodificationtree/NetworkModificationNodeInfoRepository.java
  • src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java
  • src/test/java/org/gridsuite/study/server/NodePositionTest.java

@SlimaneAmar SlimaneAmar force-pushed the set_node_column_position_when_creation branch from 81bd2f6 to 81fc850 Compare June 5, 2026 15:12
@sonarqubecloud

Copy link
Copy Markdown

@SlimaneAmar SlimaneAmar force-pushed the set_node_column_position_when_creation branch from e1bb301 to 51a38d7 Compare June 11, 2026 08:10
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