transmit CompositesToBeInserted to network modifications server#1004
transmit CompositesToBeInserted to network modifications server#1004Mathieu-Deharbe wants to merge 1 commit into
Conversation
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
📝 WalkthroughWalkthroughThis pull request generalizes the composite modifications insertion payload contract from a strictly-typed ChangesComposite Modifications Payload Generalization
Suggested Reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ 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.javaWarning Review ran into problems🔥 ProblemsStopped 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 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: 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 liftReplace
List<Object>with a typed/validated payload contract for composite network modifications.
StudyService.insertCompositeNetworkModifications(...)now takescompositesInfosasList<Object>and forwards it unchanged intoNetworkModificationService.insertCompositeModifications(...)asPair<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 useJsonNodewith 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 winMake the request-body schema explicit in docs despite using
List<Object>.The Javadoc mentions
List<CompositesToBeInserted>, but the actual method signature isList<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
📒 Files selected for processing (3)
src/main/java/org/gridsuite/study/server/controller/StudyController.javasrc/main/java/org/gridsuite/study/server/service/NetworkModificationService.javasrc/main/java/org/gridsuite/study/server/service/StudyService.java
| 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 { |
There was a problem hiding this comment.
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.
PR Summary