Skip to content

feat: handle LoadFlowResult saving to database through API call#229

Open
KoloMenek wants to merge 1 commit intomainfrom
marutk/feat/handle_saving_loadflow_results_on_api_call
Open

feat: handle LoadFlowResult saving to database through API call#229
KoloMenek wants to merge 1 commit intomainfrom
marutk/feat/handle_saving_loadflow_results_on_api_call

Conversation

@KoloMenek
Copy link
Member

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

@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3a1174f7-5d6c-41f6-914b-052993593b19

📥 Commits

Reviewing files that changed from the base of the PR and between 1c90502 and cddb33e.

📒 Files selected for processing (4)
  • src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java
  • src/main/java/org/gridsuite/loadflow/server/RestTemplateConfig.java
  • src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultService.java
  • src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultService.java
  • src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java
  • src/main/java/org/gridsuite/loadflow/server/RestTemplateConfig.java

📝 Walkthrough

Walkthrough

A 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

Cohort / File(s) Summary
Results Endpoint & Tests
src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java, src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java
Added POST /results handler saveResults(...) that generates a UUID, calls loadFlowResultService.insert(resultUuid, loadFlowResult), and returns the UUID. Added integration test verifying request serialization, service invocation, and response UUID.
Service Layer
src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultService.java
Added insert(UUID resultUuid, LoadFlowResult result) overload: validates inputs, computes LoadFlowStatus, initializes default/empty persistence fields, and delegates to existing insert method.
Serialization Configuration
src/main/java/org/gridsuite/loadflow/server/RestTemplateConfig.java
Registered LoadFlowResultJsonModule in the ObjectMapper used by the RestTemplate message converter to support (de)serialization of LoadFlowResult objects.

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)
Loading
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding an API endpoint to save LoadFlowResult entries to the database, which aligns with the actual changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining that the PR handles saving LoadFlowResult to the database through an API call with empty objects for network-derived data.

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

Tip

You can customize the tone of the review comments and chat replies.

Configure the tone_instructions setting to customize the tone of the review comments and chat replies. For example, you can set the tone to Act like a strict teacher, Act like a pirate and more.

Copy link

@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

🧹 Nitpick comments (2)
src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java (1)

105-105: Use UuidGeneratorService for 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 VERSION here 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

📥 Commits

Reviewing files that changed from the base of the PR and between 48571a5 and 1c90502.

📒 Files selected for processing (4)
  • src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java
  • src/main/java/org/gridsuite/loadflow/server/RestTemplateConfig.java
  • src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultService.java
  • src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java

This api will only save the LoadFlowResult and will save empty objects for data retrieved from network and loadflow run context
@KoloMenek KoloMenek force-pushed the marutk/feat/handle_saving_loadflow_results_on_api_call branch from 1c90502 to cddb33e Compare March 20, 2026 18:18
@sonarqubecloud
Copy link

Copy link
Contributor

@TheMaskedTurtle TheMaskedTurtle left a comment

Choose a reason for hiding this comment

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

Remove formatting diff please 🙏

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.

2 participants