Skip to content

import shared composites#830

Open
Mathieu-Deharbe wants to merge 29 commits into
mainfrom
import-shared-composite
Open

import shared composites#830
Mathieu-Deharbe wants to merge 29 commits into
mainfrom
import-shared-composite

Conversation

@Mathieu-Deharbe

@Mathieu-Deharbe Mathieu-Deharbe commented Jun 5, 2026

Copy link
Copy Markdown
Contributor
  • Adds the CompositesToBeInserted dto to match the front and introduces the possibility to import a composite.
  • adds endpoints allowing to get the data of the reference modification spécifically

@coderabbitai

This comment was marked as low quality.

@Mathieu-Deharbe Mathieu-Deharbe marked this pull request as draft June 5, 2026 10:19
@Mathieu-Deharbe Mathieu-Deharbe self-assigned this Jun 5, 2026
Base automatically changed from shared-modification to main June 15, 2026 14:27
Mathieu-Deharbe and others added 4 commits June 16, 2026 16:30
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
@Mathieu-Deharbe Mathieu-Deharbe marked this pull request as ready for review June 17, 2026 12:03

@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

🧹 Nitpick comments (2)
src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java (1)

717-723: ⚡ Quick win

Batch-load references data instead of issuing one query per UUID.

Line 719–723 performs one findById call per UUID, which creates an N+1 query pattern for large requests. This endpoint is list-based; loading once with findAllByIdIn(...) and then filtering in-memory will reduce DB round-trips.

🤖 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/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java`
around lines 717 - 723, The getReferencesData method is experiencing an N+1
query problem where each iteration of the loop calls findById on the
modificationRepository for individual UUIDs. Instead of looping through
modificationUuids and making separate findById calls, refactor this to use a
single batch query by calling findAllByIdIn with the entire modificationUuids
list. After retrieving all records at once, filter the results in-memory to
identify which ones are not found (throw the exception if expected records are
missing), and then apply the existing filtering logic checking for stashed
status and ModificationReferenceEntity type. This approach reduces database
round-trips from N queries to a single query.
src/test/java/org/gridsuite/modification/server/service/ModificationIndexationTest.java (1)

311-318: ⚡ Quick win

Add coverage for the new shared-reference path.

This test only exercises isShared=false (split behavior). The new shared insertion branch and reference lookup flow remain untested, so regressions in the new feature can pass unnoticed.

🤖 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/modification/server/service/ModificationIndexationTest.java`
around lines 311 - 318, The test in ModificationIndexationTest currently only
covers the case where isShared is set to false in the CompositesToBeInserted
constructor, leaving the new shared insertion branch and reference lookup flow
untested. Add an additional test case or extend the existing test to also
exercise the isShared=true path by creating another CompositesToBeInserted
instance with isShared set to true, and verify that the
splitCompositeModifications method correctly handles the shared reference
behavior. This ensures that both the split behavior (isShared=false) and the
shared insertion/reference lookup behavior (isShared=true) are properly tested
to catch potential regressions.
🤖 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/modification/server/NetworkModificationController.java`:
- Around line 266-269: The issue is that the getNetworkModifications call on
line 266 only retrieves root-level modifications, missing references inside
composite children. To fix this, you need to modify the logic to include nested
modifications from composites in the netModUuids list before passing it to
getReferencesData. Either adjust the parameters passed to
getNetworkModifications to include composite children modifications, or add
logic to extract and collect all nested modification UUIDs from composite
modifications in addition to the root ones, ensuring that all modification UUIDs
(root and nested) are included in the referencesData mapping.

In
`@src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java`:
- Around line 967-994: The code casts to CompositeModificationInfos without type
validation on lines 972 and 986, which can cause ClassCastException if the UUID
refers to a non-composite modification. Additionally, when composite
modifications are not found, the shared branch silently skips them while the
non-shared branch only logs, both allowing partial inserts to succeed. Add
instanceof checks before both cast operations to validate the type, and throw an
exception (instead of returning null or continuing silently) when a required
composite modification cannot be found to ensure the operation fails completely
rather than succeeding partially.

---

Nitpick comments:
In
`@src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java`:
- Around line 717-723: The getReferencesData method is experiencing an N+1 query
problem where each iteration of the loop calls findById on the
modificationRepository for individual UUIDs. Instead of looping through
modificationUuids and making separate findById calls, refactor this to use a
single batch query by calling findAllByIdIn with the entire modificationUuids
list. After retrieving all records at once, filter the results in-memory to
identify which ones are not found (throw the exception if expected records are
missing), and then apply the existing filtering logic checking for stashed
status and ModificationReferenceEntity type. This approach reduces database
round-trips from N queries to a single query.

In
`@src/test/java/org/gridsuite/modification/server/service/ModificationIndexationTest.java`:
- Around line 311-318: The test in ModificationIndexationTest currently only
covers the case where isShared is set to false in the CompositesToBeInserted
constructor, leaving the new shared insertion branch and reference lookup flow
untested. Add an additional test case or extend the existing test to also
exercise the isShared=true path by creating another CompositesToBeInserted
instance with isShared set to true, and verify that the
splitCompositeModifications method correctly handles the shared reference
behavior. This ensures that both the split behavior (isShared=false) and the
shared insertion/reference lookup behavior (isShared=true) are properly tested
to catch potential regressions.
🪄 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: 3f451ef4-e13e-4818-895a-466c1eb11f5d

📥 Commits

Reviewing files that changed from the base of the PR and between 476ade0 and 88c5a3d.

📒 Files selected for processing (6)
  • src/main/java/org/gridsuite/modification/server/CompositeController.java
  • src/main/java/org/gridsuite/modification/server/NetworkModificationController.java
  • src/main/java/org/gridsuite/modification/server/dto/CompositesToBeInserted.java
  • src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java
  • src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java
  • src/test/java/org/gridsuite/modification/server/service/ModificationIndexationTest.java

Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>

@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

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

206-207: ⚡ Quick win

Add one isShared=true insertion test to cover the new shared branch.

In this file, updated insertion payloads only exercise new CompositesToBeInserted(..., false). Adding one INSERT case with isShared=true would directly lock behavior for shared composite imports and reference creation.

🤖 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/modification/server/CompositeControllerTest.java`
around lines 206 - 207, The current test cases for composite insertions in the
CompositeControllerTest only exercise the isShared=false path when creating
CompositesToBeInserted objects. Add a new INSERT test case that creates a
composite modification payload using
getJsonBodyModificationCompositeToBeInserted with CompositesToBeInserted
constructed with isShared=true parameter instead of false, to ensure the shared
composite import and reference creation logic is properly tested and locked.
🤖 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/test/java/org/gridsuite/modification/server/ModificationControllerTest.java`:
- Around line 1818-1819: In the CompositesToBeInserted constructor call on line
1818, replace the hardcoded string "composite" with the name parameter that is
passed to this helper method. This ensures the helper properly uses its name
argument and allows the call site to accurately validate that the name is being
propagated correctly through the composite insertion path.

---

Nitpick comments:
In
`@src/test/java/org/gridsuite/modification/server/CompositeControllerTest.java`:
- Around line 206-207: The current test cases for composite insertions in the
CompositeControllerTest only exercise the isShared=false path when creating
CompositesToBeInserted objects. Add a new INSERT test case that creates a
composite modification payload using
getJsonBodyModificationCompositeToBeInserted with CompositesToBeInserted
constructed with isShared=true parameter instead of false, to ensure the shared
composite import and reference creation logic is properly tested and locked.
🪄 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: 02c61ce7-0ec9-4c59-a433-46d1b55ae8c5

📥 Commits

Reviewing files that changed from the base of the PR and between 88c5a3d and e5c6c0f.

📒 Files selected for processing (4)
  • src/main/java/org/gridsuite/modification/server/NetworkModificationController.java
  • src/test/java/org/gridsuite/modification/server/CompositeControllerTest.java
  • src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java
  • src/test/java/org/gridsuite/modification/server/utils/TestUtils.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/gridsuite/modification/server/NetworkModificationController.java

Comment thread src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java Outdated
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
@sonarqubecloud

Copy link
Copy Markdown

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