Refactor contingency count to include detailed information per contingency list#170
Refactor contingency count to include detailed information per contingency list#170FranckLecuyer wants to merge 4 commits into
Conversation
…gency list. Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
|
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 (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesPer-list contingency count
Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
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: 2
🤖 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/actions/server/ContingencyListService.java`:
- Around line 141-147: Reject duplicate request IDs before building the
contingenciesCountByContingencyList map in ContingencyListService, because the
current put(uuid, ...) path silently overwrites repeated ids and changes the
behavior of getContingencyCount(...) compared with
getContingencyCountByGroup(...). Update the logic around the ids loop to detect
duplicates up front and fail fast if repeats are not supported; if repeats must
be allowed, change the counting flow so each occurrence is preserved instead of
using a UUID-keyed map that collapses duplicates.
In `@src/main/java/org/gridsuite/actions/server/dto/ContingencyCount.java`:
- Around line 15-16: The `/contingency-lists/count` response shape in
ContingencyCount was changed incompatibly, so keep the legacy scalar total
fields alongside countByContingencyList or version the endpoint before removing
them. Update ContingencyListController and its OpenAPI/response description to
match the chosen contract in the same change, using ContingencyCount and
ContingencyListController as the key symbols to locate the affected code.
🪄 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: e8899c4a-f201-4f8f-a945-8d613611fee9
📒 Files selected for processing (4)
src/main/java/org/gridsuite/actions/server/ContingencyListService.javasrc/main/java/org/gridsuite/actions/server/dto/ContingencyCount.javasrc/main/java/org/gridsuite/actions/server/dto/ContingencyCountByContingencyList.javasrc/test/java/org/gridsuite/actions/server/ContingencyListControllerTest.java
| Map<UUID, ContingencyCountByContingencyList> contingenciesCountByContingencyList = new HashMap<>(); | ||
| for (UUID uuid : ids) { | ||
| Optional<PersistentContingencyList> contingencyList = getAnyContingencyList(uuid, network); | ||
| if (contingencyList.isPresent()) { | ||
| PersistentContingencyList l = contingencyList.get(); | ||
| nbContingencies += getContingencies(l, network).size(); | ||
| nbNotFoundElements += l.getNotFoundElements(network).size(); | ||
| } | ||
| contingencyList.ifPresent(l -> contingenciesCountByContingencyList.put(uuid, | ||
| new ContingencyCountByContingencyList(getContingencies(l, network).size(), l.getNotFoundElements(network)))); | ||
| } | ||
| return new ContingencyCount(nbContingencies, nbNotFoundElements); | ||
| return new ContingencyCount(contingenciesCountByContingencyList); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Reject duplicate ids before populating this map.
put(uuid, ...) silently overwrites repeated request IDs, so ?ids=A&ids=A no longer behaves like the previous implementation and no longer matches getContingencyCountByGroup(...), which still counts every occurrence. If duplicates are unsupported, fail fast here; otherwise the response model needs to preserve multiplicity.
Possible fix
private ContingencyCount getContingencyCount(Network network, List<UUID> ids) {
- Map<UUID, ContingencyCountByContingencyList> contingenciesCountByContingencyList = new HashMap<>();
- for (UUID uuid : ids) {
+ Set<UUID> uniqueIds = new LinkedHashSet<>(ids);
+ if (uniqueIds.size() != ids.size()) {
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Duplicate contingency list ids are not supported");
+ }
+ Map<UUID, ContingencyCountByContingencyList> contingenciesCountByContingencyList = new LinkedHashMap<>();
+ for (UUID uuid : uniqueIds) {
Optional<PersistentContingencyList> contingencyList = getAnyContingencyList(uuid, network);
contingencyList.ifPresent(l -> contingenciesCountByContingencyList.put(uuid,
new ContingencyCountByContingencyList(getContingencies(l, network).size(), l.getNotFoundElements(network))));
}
return new ContingencyCount(contingenciesCountByContingencyList);
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| Map<UUID, ContingencyCountByContingencyList> contingenciesCountByContingencyList = new HashMap<>(); | |
| for (UUID uuid : ids) { | |
| Optional<PersistentContingencyList> contingencyList = getAnyContingencyList(uuid, network); | |
| if (contingencyList.isPresent()) { | |
| PersistentContingencyList l = contingencyList.get(); | |
| nbContingencies += getContingencies(l, network).size(); | |
| nbNotFoundElements += l.getNotFoundElements(network).size(); | |
| } | |
| contingencyList.ifPresent(l -> contingenciesCountByContingencyList.put(uuid, | |
| new ContingencyCountByContingencyList(getContingencies(l, network).size(), l.getNotFoundElements(network)))); | |
| } | |
| return new ContingencyCount(nbContingencies, nbNotFoundElements); | |
| return new ContingencyCount(contingenciesCountByContingencyList); | |
| Set<UUID> uniqueIds = new LinkedHashSet<>(ids); | |
| if (uniqueIds.size() != ids.size()) { | |
| throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Duplicate contingency list ids are not supported"); | |
| } | |
| Map<UUID, ContingencyCountByContingencyList> contingenciesCountByContingencyList = new LinkedHashMap<>(); | |
| for (UUID uuid : uniqueIds) { | |
| Optional<PersistentContingencyList> contingencyList = getAnyContingencyList(uuid, network); | |
| contingencyList.ifPresent(l -> contingenciesCountByContingencyList.put(uuid, | |
| new ContingencyCountByContingencyList(getContingencies(l, network).size(), l.getNotFoundElements(network)))); | |
| } | |
| return new ContingencyCount(contingenciesCountByContingencyList); |
🤖 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/actions/server/ContingencyListService.java`
around lines 141 - 147, Reject duplicate request IDs before building the
contingenciesCountByContingencyList map in ContingencyListService, because the
current put(uuid, ...) path silently overwrites repeated ids and changes the
behavior of getContingencyCount(...) compared with
getContingencyCountByGroup(...). Update the logic around the ids loop to detect
duplicates up front and fail fast if repeats are not supported; if repeats must
be allowed, change the counting flow so each occurrence is preserved instead of
using a UUID-keyed map that collapses duplicates.
| public record ContingencyCount( | ||
| int contingencies, | ||
| int notFoundElements | ||
| Map<UUID, ContingencyCountByContingencyList> countByContingencyList |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
This changes the public /contingency-lists/count schema without a compatible rollout.
src/main/java/org/gridsuite/actions/server/ContingencyListController.java:56-66 still describes this endpoint as returning a global total, but this record drops the legacy scalar fields entirely. Existing clients will break as soon as they deserialize the new payload. Please either version the endpoint or keep the old fields alongside countByContingencyList, and update the controller/OpenAPI wording in the same change.
🤖 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/actions/server/dto/ContingencyCount.java` around
lines 15 - 16, The `/contingency-lists/count` response shape in ContingencyCount
was changed incompatibly, so keep the legacy scalar total fields alongside
countByContingencyList or version the endpoint before removing them. Update
ContingencyListController and its OpenAPI/response description to match the
chosen contract in the same change, using ContingencyCount and
ContingencyListController as the key symbols to locate the affected code.
… the corresponding error message in the dto Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
|



PR Summary