Skip to content

transmit CompositesToBeInserted to network modifications server#1004

Draft
Mathieu-Deharbe wants to merge 1 commit into
mainfrom
transmit-composites-to-be-inserted
Draft

transmit CompositesToBeInserted to network modifications server#1004
Mathieu-Deharbe wants to merge 1 commit into
mainfrom
transmit-composites-to-be-inserted

Conversation

@Mathieu-Deharbe
Copy link
Copy Markdown
Contributor

PR Summary

Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
@Mathieu-Deharbe Mathieu-Deharbe self-assigned this Jun 4, 2026
@Mathieu-Deharbe Mathieu-Deharbe marked this pull request as draft June 4, 2026 15:57
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request generalizes the composite modifications insertion payload contract from a strictly-typed List<Pair<UUID, String>> to a generic List<Object> across the REST controller, study service, and network modification service layers, allowing more flexible payload handling throughout the insertion workflow.

Changes

Composite Modifications Payload Generalization

Layer / File(s) Summary
Payload contract generalization across call chain
src/main/java/org/gridsuite/study/server/controller/StudyController.java, src/main/java/org/gridsuite/study/server/service/StudyService.java, src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java
The insertCompositeModifications REST endpoint changes its request body parameter from @RequestBody List<Pair<UUID, String>> modificationsToInsert to @RequestBody List<Object> compositesToBeInserted, and the helper method forwards the new payload type. StudyService.insertCompositeNetworkModifications(...) updates its compositesInfos parameter from List<Pair<UUID, String>> to List<Object>, and NetworkModificationService.insertCompositeModifications(...) changes its paired payload structure from Pair<List<Pair<UUID, String>>, List<ModificationApplicationContext>> to Pair<List<Object>, List<ModificationApplicationContext>>, with the HttpEntity generic type updated accordingly.

Suggested Reviewers

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

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is empty and contains no substantive information about the changes made. Provide a detailed description explaining the rationale for changing from List<Pair<UUID, String>> to List, impact on callers, and testing performed.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: updating the composite insertion mechanism to pass composites as a generic list to the network modifications server.
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.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.43.0)
src/main/java/org/gridsuite/study/server/controller/StudyController.java

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


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: 1

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/StudyService.java (1)

2337-2346: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Replace List<Object> with a typed/validated payload contract for composite network modifications.

StudyService.insertCompositeNetworkModifications(...) now takes compositesInfos as List<Object> and forwards it unchanged into NetworkModificationService.insertCompositeModifications(...) as Pair<List<Object>, List<ModificationApplicationContext>>, which then sends it to the network-modification-server. This removes the study-server boundary schema/type guarantees, so malformed JSON array elements will only surface downstream at runtime rather than being rejected/validated early (e.g., StudyService.java:2337-2346, NetworkModificationService.java:285-296).
Define explicit DTO(s (or use JsonNode with per-shape validation) for the supported composite item structures before forwarding.

🤖 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/study/server/service/StudyService.java` around
lines 2337 - 2346, StudyService.insertCompositeNetworkModifications currently
accepts compositesInfos as List<Object] and forwards it to
NetworkModificationService.insertCompositeModifications, losing type guarantees;
replace the raw List<Object> with a typed DTO (or JsonNode with validation)
representing the allowed composite item shapes, update the method signature and
call sites (StudyService.insertCompositeNetworkModifications,
duplicateModificationsOrInsertComposites invocation, and
NetworkModificationService.insertCompositeModifications) to use
List<YourCompositeDto> (or List<JsonNode> plus explicit per-item validation),
add validation logic to reject/transform malformed items before constructing the
Pair passed to networkModificationService, and adjust any downstream handling to
consume the new DTO type.
🧹 Nitpick comments (1)
src/main/java/org/gridsuite/study/server/controller/StudyController.java (1)

693-695: ⚡ Quick win

Make the request-body schema explicit in docs despite using List<Object>.

The Javadoc mentions List<CompositesToBeInserted>, but the actual method signature is List<Object>. Add explicit OpenAPI schema/examples for this endpoint so client contract remains clear and codegen/documentation do not degrade into “array of any”.

🤖 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/study/server/controller/StudyController.java`
around lines 693 - 695, The endpoint currently takes List<Object> (parameter
compositesToBeInserted) which yields an "array of any" in docs; annotate the
controller method in StudyController to provide an explicit OpenAPI request-body
schema by adding `@io.swagger.v3.oas.annotations.parameters.RequestBody` on the
method (or parameter) and supply Content with mediaType "application/json" and
an ArraySchema whose schema points to a concrete documentation-only type (e.g.
CompositesToBeInsertedDoc) or an inline `@Schema` describing expected properties;
if no runtime DTO exists create a small static inner class
CompositesToBeInsertedDoc with the fields used by network-modification-server
and reference it via
`@ArraySchema`(schema=`@Schema`(implementation=CompositesToBeInsertedDoc.class)) and
add an `@ExampleObject` to show a sample payload so codegen/docs produce a clear
contract despite the handler using List<Object>.
🤖 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/controller/StudyController.java`:
- Around line 699-715: The controller currently accepts List<Object>
compositesToBeInserted and forwards it to
handleInsertCompositeNetworkModifications without structural checks; add a
strict payload-shape validation step (either in insertCompositeModifications
before calling handleInsertCompositeNetworkModifications or at the top of
handleInsertCompositeNetworkModifications before calling
studyService.invalidateNodeTreeWithLF) that iterates compositesToBeInserted and
verifies each element matches the expected shape/type (e.g., Pair or Map with
required keys/types and any enum values), and if any element is invalid
immediately throw a 4xx (ResponseStatusException with BAD_REQUEST) so invalid
requests fail fast and prevent node-tree invalidation; reference the parameter
compositesToBeInserted, the controller method insertCompositeModifications, and
the helper handleInsertCompositeNetworkModifications when adding this guard.

---

Outside diff comments:
In `@src/main/java/org/gridsuite/study/server/service/StudyService.java`:
- Around line 2337-2346: StudyService.insertCompositeNetworkModifications
currently accepts compositesInfos as List<Object] and forwards it to
NetworkModificationService.insertCompositeModifications, losing type guarantees;
replace the raw List<Object> with a typed DTO (or JsonNode with validation)
representing the allowed composite item shapes, update the method signature and
call sites (StudyService.insertCompositeNetworkModifications,
duplicateModificationsOrInsertComposites invocation, and
NetworkModificationService.insertCompositeModifications) to use
List<YourCompositeDto> (or List<JsonNode> plus explicit per-item validation),
add validation logic to reject/transform malformed items before constructing the
Pair passed to networkModificationService, and adjust any downstream handling to
consume the new DTO type.

---

Nitpick comments:
In `@src/main/java/org/gridsuite/study/server/controller/StudyController.java`:
- Around line 693-695: The endpoint currently takes List<Object> (parameter
compositesToBeInserted) which yields an "array of any" in docs; annotate the
controller method in StudyController to provide an explicit OpenAPI request-body
schema by adding `@io.swagger.v3.oas.annotations.parameters.RequestBody` on the
method (or parameter) and supply Content with mediaType "application/json" and
an ArraySchema whose schema points to a concrete documentation-only type (e.g.
CompositesToBeInsertedDoc) or an inline `@Schema` describing expected properties;
if no runtime DTO exists create a small static inner class
CompositesToBeInsertedDoc with the fields used by network-modification-server
and reference it via
`@ArraySchema`(schema=`@Schema`(implementation=CompositesToBeInsertedDoc.class)) and
add an `@ExampleObject` to show a sample payload so codegen/docs produce a clear
contract despite the handler using List<Object>.
🪄 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: 486782b0-1382-4c22-9d7f-3f2d0c6c0474

📥 Commits

Reviewing files that changed from the base of the PR and between 9d8849b and b04a6a2.

📒 Files selected for processing (3)
  • src/main/java/org/gridsuite/study/server/controller/StudyController.java
  • src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java
  • src/main/java/org/gridsuite/study/server/service/StudyService.java

Comment on lines 699 to 715
public ResponseEntity<Void> insertCompositeModifications(@PathVariable("studyUuid") UUID studyUuid,
@PathVariable("nodeUuid") UUID nodeUuid,
@RequestParam("action") CompositeModificationsActionType action,
@RequestBody List<Pair<UUID, String>> modificationsToInsert,
@RequestBody List<Object> compositesToBeInserted,
@RequestHeader(HEADER_USER_ID) String userId) {
studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid);
studyService.assertCanUpdateNodeInStudy(studyUuid, nodeUuid);
handleInsertCompositeNetworkModifications(studyUuid, nodeUuid, modificationsToInsert, userId, action);
handleInsertCompositeNetworkModifications(studyUuid, nodeUuid, compositesToBeInserted, userId, action);
return ResponseEntity.ok().build();
}

private void handleInsertCompositeNetworkModifications(UUID targetStudyUuid, UUID targetNodeUuid, List<Pair<UUID, String>> modificationsToCopy, String userId, CompositeModificationsActionType action) {
private void handleInsertCompositeNetworkModifications(UUID targetStudyUuid, UUID targetNodeUuid, List<Object> compositesToBeInserted, String userId, CompositeModificationsActionType action) {
studyService.assertNoBlockedNodeInStudy(targetStudyUuid, targetNodeUuid);
studyService.invalidateNodeTreeWithLF(targetStudyUuid, targetNodeUuid);
try {
studyService.insertCompositeNetworkModifications(targetStudyUuid, targetNodeUuid, modificationsToCopy, userId, action);
studyService.insertCompositeNetworkModifications(targetStudyUuid, targetNodeUuid, compositesToBeInserted, userId, action);
} finally {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Validate the generalized payload before triggering node-tree invalidation.

Line 702 now accepts List<Object>, and Line 714 forwards it without structural checks. That allows malformed/heterogeneous arrays to pass controller binding and fail later, after Line 712 has already started invalidation flow. Add an explicit payload-shape validation step before handleInsertCompositeNetworkModifications(...) (or right at its start, before invalidation) so bad requests fail fast with 4xx.

Suggested guard (example)
+import org.springframework.web.server.ResponseStatusException;
...
     public ResponseEntity<Void> insertCompositeModifications(`@PathVariable`("studyUuid") UUID studyUuid,
                                                          `@PathVariable`("nodeUuid") UUID nodeUuid,
                                                          `@RequestParam`("action") CompositeModificationsActionType action,
                                                          `@RequestBody` List<Object> compositesToBeInserted,
                                                          `@RequestHeader`(HEADER_USER_ID) String userId) {
         studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid);
         studyService.assertCanUpdateNodeInStudy(studyUuid, nodeUuid);
+        validateCompositesToBeInserted(compositesToBeInserted);
         handleInsertCompositeNetworkModifications(studyUuid, nodeUuid, compositesToBeInserted, userId, action);
         return ResponseEntity.ok().build();
     }

+    private static void validateCompositesToBeInserted(List<Object> compositesToBeInserted) {
+        boolean invalid = compositesToBeInserted == null
+                || compositesToBeInserted.stream().anyMatch(item -> !(item instanceof Map<?, ?>));
+        if (invalid) {
+            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Body must be a JSON array of objects");
+        }
+    }

Based on learnings: org.springframework.data.util.Pair request-body deserialization is already supported in this project, so loosening to List<Object> should be paired with explicit boundary validation.

🤖 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/study/server/controller/StudyController.java`
around lines 699 - 715, The controller currently accepts List<Object>
compositesToBeInserted and forwards it to
handleInsertCompositeNetworkModifications without structural checks; add a
strict payload-shape validation step (either in insertCompositeModifications
before calling handleInsertCompositeNetworkModifications or at the top of
handleInsertCompositeNetworkModifications before calling
studyService.invalidateNodeTreeWithLF) that iterates compositesToBeInserted and
verifies each element matches the expected shape/type (e.g., Pair or Map with
required keys/types and any enum values), and if any element is invalid
immediately throw a 4xx (ResponseStatusException with BAD_REQUEST) so invalid
requests fail fast and prevent node-tree invalidation; reference the parameter
compositesToBeInserted, the controller method insertCompositeModifications, and
the helper handleInsertCompositeNetworkModifications when adding this guard.

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