feat: handle LoadFlowResult saving to database through API call#229
feat: handle LoadFlowResult saving to database through API call#229
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughA new POST /results endpoint was added to save load flow results. The endpoint accepts a LoadFlowResult, generates a UUID, persists it through the service layer, and returns the generated UUID. Supporting changes register a Jackson module and add a service overload. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Controller as LoadFlowController
participant Service as LoadFlowResultService
participant DB as Database
Client->>Controller: POST /results (LoadFlowResult)
Controller->>Controller: generate UUID
Controller->>Service: insert(resultUuid, LoadFlowResult)
Service->>Service: validate, compute LoadFlowStatus, init defaults
Service->>DB: persist result and related records
DB-->>Service: persistence confirmed
Service-->>Controller: return
Controller-->>Client: 200 OK (UUID)
🚥 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 Tip You can customize the tone of the review comments and chat replies.Configure the |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java (1)
105-105: UseUuidGeneratorServicefor UUID creation consistency.This endpoint bypasses the existing UUID generation abstraction used elsewhere in the controller.
♻️ Proposed refactor
- UUID resultUuid = UUID.randomUUID(); + UUID resultUuid = uuidGeneratorService.generate();🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java` at line 105, The code creates a UUID directly with UUID.randomUUID() (resultUuid) which bypasses the project's UUID abstraction; replace that call in LoadFlowController with the project's UuidGeneratorService (call its UUID generation method, e.g., UuidGeneratorService.generateUuid() or the existing generate()/create() method used elsewhere) and assign the returned value to resultUuid so UUID creation is consistent across the controller.src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java (1)
836-836: Avoid hardcoding API version in test URL.Use
VERSIONhere too, so this test remains aligned with the rest of the suite after version changes.🧹 Proposed cleanup
- MvcResult mvcResult = mockMvc.perform(post("/v1/results").contentType(MediaType.APPLICATION_JSON) + MvcResult mvcResult = mockMvc.perform(post("/" + VERSION + "/results").contentType(MediaType.APPLICATION_JSON)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java` at line 836, The test is hardcoding the API version in the URL: change the call that creates MvcResult via mockMvc.perform(post("/v1/results")...) to use the shared VERSION constant instead of the literal "/v1/results" (e.g., build the path using VERSION + "/results"), updating the mockMvc.perform(...) invocation so the test stays aligned with other tests; locate the usage in the MvcResult creation and replace the string literal with the VERSION-based path.
🤖 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/loadflow/server/service/LoadFlowResultService.java`:
- Around line 145-153: The call to LoadFlowService.computeLoadFlowStatus(result)
can throw an NPE when result.componentResults is null; guard this in insert by
ensuring result.componentResults is non-null (e.g., replace null with an empty
collection or set a default in result) before calling
LoadFlowService.computeLoadFlowStatus, so update the insert method (in
LoadFlowResultService.insert) to normalize result.componentResults and then call
LoadFlowService.computeLoadFlowStatus(result).
---
Nitpick comments:
In `@src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java`:
- Line 105: The code creates a UUID directly with UUID.randomUUID() (resultUuid)
which bypasses the project's UUID abstraction; replace that call in
LoadFlowController with the project's UuidGeneratorService (call its UUID
generation method, e.g., UuidGeneratorService.generateUuid() or the existing
generate()/create() method used elsewhere) and assign the returned value to
resultUuid so UUID creation is consistent across the controller.
In `@src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java`:
- Line 836: The test is hardcoding the API version in the URL: change the call
that creates MvcResult via mockMvc.perform(post("/v1/results")...) to use the
shared VERSION constant instead of the literal "/v1/results" (e.g., build the
path using VERSION + "/results"), updating the mockMvc.perform(...) invocation
so the test stays aligned with other tests; locate the usage in the MvcResult
creation and replace the string literal with the VERSION-based path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cb86fef2-dd14-472d-9219-4987d32f2272
📒 Files selected for processing (4)
src/main/java/org/gridsuite/loadflow/server/LoadFlowController.javasrc/main/java/org/gridsuite/loadflow/server/RestTemplateConfig.javasrc/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultService.javasrc/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java
src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultService.java
Show resolved
Hide resolved
This api will only save the LoadFlowResult and will save empty objects for data retrieved from network and loadflow run context
1c90502 to
cddb33e
Compare
|
TheMaskedTurtle
left a comment
There was a problem hiding this comment.
Remove formatting diff please 🙏



PR Summary
handle saving LoadFlowResult saving to database through API call
This api will only save the LoadFlowResult and will save empty objects for data retrieved from network and loadflow run context