Get multiple statuses at once - #235
Conversation
…s at once given a collection of resultUuids in body Signed-off-by: sBouzols <sylvain.bouzols@gmail.com>
📝 WalkthroughWalkthroughRepository interfaces GlobalStatusRepository and ResultRepository remove custom findByResultUuid/deleteByResultUuid methods, relying on JpaRepository's findById/deleteById. LoadFlowResultService is updated accordingly. LoadFlowController adds a POST /results/statuses endpoint. pom.xml pins gridsuite-computation.version. Tests are updated and added. ChangesStatus/result repository refactor and new endpoint
Sequence Diagram(s)sequenceDiagram
participant Client
participant LoadFlowController
participant LoadFlowResultService
participant GlobalStatusRepository
Client->>LoadFlowController: POST /results/statuses (resultUuids)
LoadFlowController->>LoadFlowResultService: getStatuses(resultUuids)
LoadFlowResultService->>GlobalStatusRepository: findAllById(resultUuids)
GlobalStatusRepository-->>LoadFlowResultService: List<GlobalStatusEntity>
LoadFlowResultService-->>LoadFlowController: Map<UUID, LoadFlowStatus>
LoadFlowController-->>Client: 200 OK with status map
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches⚔️ Resolve merge conflicts
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 |
| <sonar.organization>gridsuite</sonar.organization> | ||
| <sonar.projectKey>org.gridsuite:loadflow-server</sonar.projectKey> | ||
| <!-- FIXME: to be removed at next powsybl-ws-dependencies upgrade --> | ||
| <gridsuite-computation.version>2.3.0-SNAPSHOT</gridsuite-computation.version> |
There was a problem hiding this comment.
Don't forget to delete it
Signed-off-by: sBouzols <sylvain.bouzols@gmail.com>
Co-authored-by: Copilot <copilot@github.com> Signed-off-by: sBouzols <sylvain.bouzols@gmail.com>
…s_for_multiple_results_at_once Signed-off-by: sBouzols <sylvain.bouzols@gmail.com>
…balStatusEntity` then no need for specific methods in Jpa Repositories (#239) Signed-off-by: sBouzols <sylvain.bouzols@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/loadflow/server/service/LoadFlowResultService.java`:
- Around line 236-240: `LoadFlowResultService.findStatuses` currently uses
`Collectors.toMap` on `GlobalStatusEntity::getStatus`, which can fail when a row
has a null status. Update this method to match `findStatus()` behavior by making
the collection null-tolerant, either by filtering out null statuses before
collecting or by mapping them safely so `null` values do not break the result
map.
🪄 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: c37aee0e-653d-476a-bfb4-029eebcc2239
📒 Files selected for processing (6)
pom.xmlsrc/main/java/org/gridsuite/loadflow/server/LoadFlowController.javasrc/main/java/org/gridsuite/loadflow/server/repositories/GlobalStatusRepository.javasrc/main/java/org/gridsuite/loadflow/server/repositories/ResultRepository.javasrc/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultService.javasrc/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java
💤 Files with no reviewable changes (2)
- src/main/java/org/gridsuite/loadflow/server/repositories/GlobalStatusRepository.java
- src/main/java/org/gridsuite/loadflow/server/repositories/ResultRepository.java
| public Map<UUID, LoadFlowStatus> findStatuses(List<UUID> resultUuids) { | ||
| Objects.requireNonNull(resultUuids); | ||
| List<GlobalStatusEntity> globalEntities = globalStatusRepository.findAllById(resultUuids); | ||
| return globalEntities.stream().collect(Collectors.toMap(GlobalStatusEntity::getResultUuid, GlobalStatusEntity::getStatus)); | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check GlobalStatusEntity field annotations for nullability constraints
rg -n -A2 'status' --type=java src/main/java/org/gridsuite/loadflow/server/entities/GlobalStatusEntity.javaRepository: gridsuite/loadflow-server
Length of output: 210
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== LoadFlowResultService excerpt =="
sed -n '220,245p' src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultService.java | cat -n
echo
echo "== GlobalStatusEntity file =="
sed -n '1,120p' src/main/java/org/gridsuite/loadflow/server/entities/GlobalStatusEntity.java | cat -n
echo
echo "== Search for status nullability / schema constraints =="
rg -n --hidden --glob '!target/**' --glob '!build/**' --glob '!dist/**' \
'`@Column`\\(|nullable\\s*=\\s*false|status.*not null|not null.*status|GlobalStatusEntity' \
src main resources .Repository: gridsuite/loadflow-server
Length of output: 2975
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Search for globalStatus schema/migrations =="
rg -n --hidden --glob '!target/**' --glob '!build/**' --glob '!dist/**' \
'globalStatus|global_status|status' \
src/main/resources src/main/java
echo
echo "== Search for migration files =="
fd -a -t f '.*(sql|xml|yml|yaml)$' src/main/resources db . | sed -n '1,200p'Repository: gridsuite/loadflow-server
Length of output: 11245
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '1,40p' src/main/resources/db/changelog/changesets/changelog_20230606T161304Z.xml | cat -nRepository: gridsuite/loadflow-server
Length of output: 3073
Handle nullable status in findStatuses
global_status.status is nullable in both the entity and the Liquibase DDL, so Collectors.toMap(...) can throw if any row has a null status. findStatus() already returns null in that case; make findStatuses() use a null-tolerant collector or filter nulls first.
🤖 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/loadflow/server/service/LoadFlowResultService.java`
around lines 236 - 240, `LoadFlowResultService.findStatuses` currently uses
`Collectors.toMap` on `GlobalStatusEntity::getStatus`, which can fail when a row
has a null status. Update this method to match `findStatus()` behavior by making
the collection null-tolerant, either by filtering out null statuses before
collecting or by mapping them safely so `null` values do not break the result
map.
PR Summary
Add POST "/results/statuses" endpoint to get multiple statuses at once given a collection of
resultUuidsin bodyDo I remove the previous endpoint ?
-> No