Skip to content

Refactor duplication endpoints#1014

Open
carojeandat wants to merge 2 commits into
mainfrom
refactor-duplication-endpoints
Open

Refactor duplication endpoints#1014
carojeandat wants to merge 2 commits into
mainfrom
refactor-duplication-endpoints

Conversation

@carojeandat

Copy link
Copy Markdown
Contributor

PR Summary

Signed-off-by: Caroline Jeandat <caroline.jeandat@rte-france.com>
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Duplicate operations across the study server are migrated from query-parameter-based endpoints (?duplicateFrom={uuid}) to path-based endpoints (/{uuid}/duplicate). This affects the study controller, case service, load flow, network modification, PCC min, security/sensitivity analysis, state estimation, voltage init, short circuit, dynamic margin/security/simulation clients, and study config services, along with corresponding test stubs and assertions.

Changes

Duplicate endpoint path migration

Layer / File(s) Summary
Study and case duplication endpoints
src/main/java/org/gridsuite/study/server/controller/StudyController.java, src/main/java/org/gridsuite/study/server/service/CaseService.java, src/test/java/org/gridsuite/study/server/studycontroller/StudyTest.java, src/test/java/org/gridsuite/study/server/utils/wiremock/CaseServerStubs.java
Study duplication endpoint moves to POST /studies/{studyUuid}/duplicate and case duplication moves to /cases/{uuid}/duplicate; corresponding tests and WireMock stubs are updated to match the new paths.
Computation service parameter duplication
src/main/java/org/gridsuite/study/server/service/{LoadFlowService,NetworkModificationService,PccMinService,SecurityAnalysisService,SensitivityAnalysisService,StateEstimationService,VoltageInitService}.java, src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java, src/main/java/org/gridsuite/study/server/service/client/.../*.java, src/test/java/org/gridsuite/study/server/{PccMinTest,VoltageInitTest}.java, src/test/java/org/gridsuite/study/server/service/client/.../*.java, src/test/java/org/gridsuite/study/server/utils/wiremock/{ComputationServerStubs,LoadflowServerStubs,WireMockStubs,WireMockUtils}.java
Each service now builds the duplicate request URL by embedding the source UUID into the path (.../{uuid}/duplicate) rather than sending it via duplicateFrom query parameter; WireMock stubs/verifications and test assertions are updated accordingly; WireMockUtils gains a verifyPostRequest overload accepting regexMatching.
StudyConfigService duplication endpoints
src/main/java/org/gridsuite/study/server/service/StudyConfigService.java, src/test/java/org/gridsuite/study/server/SpreadsheetConfigCollectionTest.java, src/test/java/org/gridsuite/study/server/utils/wiremock/WireMockStubs.java
The DUPLICATE_FROM_PARAM constant is removed and the three duplication methods (network visualization params, spreadsheet config collection, workspaces config) embed the UUID in the path; test assertions and WireMock stubs are updated to match.

Suggested reviewers: flomillot, AbdelHedhili, khouadrired

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description is just a placeholder and does not describe the changeset in any meaningful way. Replace the placeholder with a brief summary of the endpoint path changes and affected services/tests.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: duplication endpoints were refactored to use new path-based routes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


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.

Signed-off-by: Caroline Jeandat <caroline.jeandat@rte-france.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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/test/java/org/gridsuite/study/server/SpreadsheetConfigCollectionTest.java (1)

161-166: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Fix the duplicate dispatcher ID parsing.
path.substring(path.lastIndexOf("=") + 1) still assumes the old ?duplicateFrom=<id> format. With /v1/spreadsheet-config-collections/<id>/duplicate, there is no =, so the "non-existing-collection" branch never matches and the intended 404 path is lost.

🤖 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/test/java/org/gridsuite/study/server/SpreadsheetConfigCollectionTest.java`
around lines 161 - 166, The duplicate dispatcher in
SpreadsheetConfigCollectionTest is still extracting the collection ID using the
old query-string parsing, so the non-existing collection case is never matched
for the new /duplicate path. Update the ID extraction logic in the mock
dispatcher branch that handles the duplicate POST route to derive the identifier
from the path segments instead of using lastIndexOf("="), and keep the existing
non-existing-collection 404 check working against that parsed ID.
🧹 Nitpick comments (4)
src/main/java/org/gridsuite/study/server/service/client/dynamicsecurityanalysis/DynamicSecurityAnalysisClient.java (1)

107-117: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse getParametersWithUuidUrl to avoid duplicated URL-building.

duplicateParameters re-derives parametersBaseUrl and rebuilds the {uuid} segment instead of reusing the existing helper.

♻️ Suggested simplification
     public UUID duplicateParameters(`@NonNull` UUID sourceParametersUuid) {
         Objects.requireNonNull(sourceParametersUuid);

-        String parametersBaseUrl = buildEndPointUrl(getBaseUri(), DYNAMIC_SECURITY_ANALYSIS_API_VERSION, DYNAMIC_SECURITY_ANALYSIS_END_POINT_PARAMETER);
-
-        String url = UriComponentsBuilder.fromUriString(parametersBaseUrl + "/{uuid}/duplicate")
-                .buildAndExpand(sourceParametersUuid)
-                .toUriString();
+        String url = getParametersWithUuidUrl(sourceParametersUuid) + "/duplicate";

         return getRestTemplate().postForObject(url, null, UUID.class);
     }
🤖 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/client/dynamicsecurityanalysis/DynamicSecurityAnalysisClient.java`
around lines 107 - 117, The duplicate URL construction in duplicateParameters
should be simplified by reusing the existing getParametersWithUuidUrl helper
instead of rebuilding parametersBaseUrl and the {uuid} path segment locally.
Update duplicateParameters in DynamicSecurityAnalysisClient to derive the
duplicate endpoint from getParametersWithUuidUrl(sourceParametersUuid) and
append the /duplicate suffix there, keeping the UUID handling and REST call
behavior unchanged.
src/test/java/org/gridsuite/study/server/service/client/dynamicmargincalculation/DynamicMarginCalculationClientTest.java (1)

227-227: 🎯 Functional Correctness | 🔵 Trivial

Consider urlPathEqualTo instead of urlPathTemplate for a fully-resolved path.

urlPathTemplate is intended for RFC 6570 templates with {variable} placeholders matched via .withPathParam(...); here the path is already fully concrete (PARAMETERS_UUID is interpolated as a literal value), so urlPathEqualTo would be the more idiomatic matcher. Functionally this should still behave as an exact match since there are no path variables, so this is purely a clarity nit, and the same pattern is already used consistently in sibling dynamic-client tests.

Also applies to: 240-240, 250-250

🤖 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/test/java/org/gridsuite/study/server/service/client/dynamicmargincalculation/DynamicMarginCalculationClientTest.java`
at line 227, The WireMock stubs in DynamicMarginCalculationClientTest are using
urlPathTemplate for a fully concrete endpoint path, which is clearer as an exact
match with urlPathEqualTo. Update the stub setups in the test methods around the
duplicate/delete-style endpoints to use urlPathEqualTo instead of
urlPathTemplate, keeping the same PARAMETERS_BASE_URL, DELIMITER, and
PARAMETERS_UUID path construction so the matcher remains an exact literal path
match.
src/test/java/org/gridsuite/study/server/service/client/dynamicsimulation/DynamicSimulationClientTest.java (1)

234-234: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Misuse of urlPathTemplate for a non-templated literal path.

urlPathTemplate is designed for RFC 6570 path templates containing {var} placeholders (e.g. /{uuid}/duplicate), enabling path-variable matching. Here the UUID is already interpolated into the string before being passed in, so there are no template variables left — the same idiom used elsewhere in this file for literal paths is WireMock.urlPathEqualTo(url) (e.g. testGetProvider, testGetParameters). While this will likely still match as a literal string, it deviates from the documented usage pattern and is inconsistent with the rest of the test class.

♻️ Suggested fix
-        wireMockServer.stubFor(WireMock.post(WireMock.urlPathTemplate(PARAMETERS_BASE_URL + "/" + PARAMETERS_UUID + "/duplicate"))
+        wireMockServer.stubFor(WireMock.post(WireMock.urlPathEqualTo(PARAMETERS_BASE_URL + "/" + PARAMETERS_UUID + "/duplicate"))

The same pattern is repeated in the sibling DynamicMarginCalculationClientTest and DynamicSecurityAnalysisClientTest files per the provided graph context.

Also applies to: 247-247, 257-257

🤖 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/test/java/org/gridsuite/study/server/service/client/dynamicsimulation/DynamicSimulationClientTest.java`
at line 234, Replace the misuse of WireMock.urlPathTemplate in the duplicate
stubs with the literal-path matcher used elsewhere in
DynamicSimulationClientTest, since the PARAMETERS_UUID is already interpolated
and no template variables remain. Update the duplicate request setup in the
corresponding duplicate-related test methods to use WireMock.urlPathEqualTo with
the fully built URL, and apply the same change in the sibling
DynamicMarginCalculationClientTest and DynamicSecurityAnalysisClientTest test
cases that use the same pattern.
src/main/java/org/gridsuite/study/server/service/StudyConfigService.java (1)

127-135: 📐 Maintainability & Code Quality | 🔵 Trivial

Use templated path variables instead of raw string concatenation for the UUID.

duplicateSpreadsheetConfigCollection and duplicateWorkspacesConfig concatenate sourceUuid directly into the path string and call buildAndExpand() with no arguments, unlike duplicateNetworkVisualizationParameters (and the rest of the class) which uses a {uuid} placeholder + buildAndExpand(uuid). Functionally safe today since UUID#toString() never needs escaping, but it's inconsistent with the class's established pattern.

♻️ Proposed fix for consistency
     public UUID duplicateSpreadsheetConfigCollection(UUID sourceUuid) {
         Objects.requireNonNull(sourceUuid);
-        var path = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + SPREADSHEET_CONFIG_COLLECTION_URI + DELIMITER + sourceUuid + "/duplicate")
-                .buildAndExpand().toUriString();
+        var path = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + SPREADSHEET_CONFIG_COLLECTION_URI + "/{uuid}/duplicate")
+                .buildAndExpand(sourceUuid).toUriString();
     public UUID duplicateWorkspacesConfig(UUID sourceUuid) {
         Objects.requireNonNull(sourceUuid);
-        var path = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + WORKSPACES_CONFIG_URI + DELIMITER + sourceUuid + "/duplicate")
-                .toUriString();
+        var path = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + WORKSPACES_CONFIG_URI + "/{uuid}/duplicate")
+                .buildAndExpand(sourceUuid).toUriString();

Also applies to: 332-337

🤖 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/StudyConfigService.java`
around lines 127 - 135, `duplicateSpreadsheetConfigCollection` is building the
URI by concatenating `sourceUuid` directly into the path instead of using the
class’s templated `{uuid}` pattern. Update this method, and the matching
`duplicateWorkspacesConfig` path construction, to use a placeholder plus
`buildAndExpand(...)` like `duplicateNetworkVisualizationParameters` does, so
the URI assembly is consistent across `StudyConfigService`.
🤖 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/test/java/org/gridsuite/study/server/utils/wiremock/WireMockStubs.java`:
- Around line 786-788: The verifyNetworkAreaDiagramConfig helper is using a path
pattern that is currently treated as a literal string, so it will not match
duplicate-config requests. Update this verifier to enable regex matching when
calling verifyPostRequest, keeping the existing NetworkAreaDiagram duplicate
endpoint pattern and the stubId parameter so the helper matches the intended
request.

---

Outside diff comments:
In
`@src/test/java/org/gridsuite/study/server/SpreadsheetConfigCollectionTest.java`:
- Around line 161-166: The duplicate dispatcher in
SpreadsheetConfigCollectionTest is still extracting the collection ID using the
old query-string parsing, so the non-existing collection case is never matched
for the new /duplicate path. Update the ID extraction logic in the mock
dispatcher branch that handles the duplicate POST route to derive the identifier
from the path segments instead of using lastIndexOf("="), and keep the existing
non-existing-collection 404 check working against that parsed ID.

---

Nitpick comments:
In
`@src/main/java/org/gridsuite/study/server/service/client/dynamicsecurityanalysis/DynamicSecurityAnalysisClient.java`:
- Around line 107-117: The duplicate URL construction in duplicateParameters
should be simplified by reusing the existing getParametersWithUuidUrl helper
instead of rebuilding parametersBaseUrl and the {uuid} path segment locally.
Update duplicateParameters in DynamicSecurityAnalysisClient to derive the
duplicate endpoint from getParametersWithUuidUrl(sourceParametersUuid) and
append the /duplicate suffix there, keeping the UUID handling and REST call
behavior unchanged.

In `@src/main/java/org/gridsuite/study/server/service/StudyConfigService.java`:
- Around line 127-135: `duplicateSpreadsheetConfigCollection` is building the
URI by concatenating `sourceUuid` directly into the path instead of using the
class’s templated `{uuid}` pattern. Update this method, and the matching
`duplicateWorkspacesConfig` path construction, to use a placeholder plus
`buildAndExpand(...)` like `duplicateNetworkVisualizationParameters` does, so
the URI assembly is consistent across `StudyConfigService`.

In
`@src/test/java/org/gridsuite/study/server/service/client/dynamicmargincalculation/DynamicMarginCalculationClientTest.java`:
- Line 227: The WireMock stubs in DynamicMarginCalculationClientTest are using
urlPathTemplate for a fully concrete endpoint path, which is clearer as an exact
match with urlPathEqualTo. Update the stub setups in the test methods around the
duplicate/delete-style endpoints to use urlPathEqualTo instead of
urlPathTemplate, keeping the same PARAMETERS_BASE_URL, DELIMITER, and
PARAMETERS_UUID path construction so the matcher remains an exact literal path
match.

In
`@src/test/java/org/gridsuite/study/server/service/client/dynamicsimulation/DynamicSimulationClientTest.java`:
- Line 234: Replace the misuse of WireMock.urlPathTemplate in the duplicate
stubs with the literal-path matcher used elsewhere in
DynamicSimulationClientTest, since the PARAMETERS_UUID is already interpolated
and no template variables remain. Update the duplicate request setup in the
corresponding duplicate-related test methods to use WireMock.urlPathEqualTo with
the fully built URL, and apply the same change in the sibling
DynamicMarginCalculationClientTest and DynamicSecurityAnalysisClientTest test
cases that use the same pattern.
🪄 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: 8495158c-54fd-4b5c-bb2a-b37c6e84f567

📥 Commits

Reviewing files that changed from the base of the PR and between a76a79c and f790ddb.

📒 Files selected for processing (26)
  • src/main/java/org/gridsuite/study/server/controller/StudyController.java
  • src/main/java/org/gridsuite/study/server/service/CaseService.java
  • src/main/java/org/gridsuite/study/server/service/LoadFlowService.java
  • src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java
  • src/main/java/org/gridsuite/study/server/service/PccMinService.java
  • src/main/java/org/gridsuite/study/server/service/SecurityAnalysisService.java
  • src/main/java/org/gridsuite/study/server/service/SensitivityAnalysisService.java
  • src/main/java/org/gridsuite/study/server/service/StateEstimationService.java
  • src/main/java/org/gridsuite/study/server/service/StudyConfigService.java
  • src/main/java/org/gridsuite/study/server/service/VoltageInitService.java
  • src/main/java/org/gridsuite/study/server/service/client/dynamicmargincalculation/DynamicMarginCalculationClient.java
  • src/main/java/org/gridsuite/study/server/service/client/dynamicsecurityanalysis/DynamicSecurityAnalysisClient.java
  • src/main/java/org/gridsuite/study/server/service/client/dynamicsimulation/impl/DynamicSimulationClientImpl.java
  • src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java
  • src/test/java/org/gridsuite/study/server/PccMinTest.java
  • src/test/java/org/gridsuite/study/server/SpreadsheetConfigCollectionTest.java
  • src/test/java/org/gridsuite/study/server/VoltageInitTest.java
  • src/test/java/org/gridsuite/study/server/service/client/dynamicmargincalculation/DynamicMarginCalculationClientTest.java
  • src/test/java/org/gridsuite/study/server/service/client/dynamicsecurityanalysis/DynamicSecurityAnalysisClientTest.java
  • src/test/java/org/gridsuite/study/server/service/client/dynamicsimulation/DynamicSimulationClientTest.java
  • src/test/java/org/gridsuite/study/server/studycontroller/StudyTest.java
  • src/test/java/org/gridsuite/study/server/utils/wiremock/CaseServerStubs.java
  • src/test/java/org/gridsuite/study/server/utils/wiremock/ComputationServerStubs.java
  • src/test/java/org/gridsuite/study/server/utils/wiremock/LoadflowServerStubs.java
  • src/test/java/org/gridsuite/study/server/utils/wiremock/WireMockStubs.java
  • src/test/java/org/gridsuite/study/server/utils/wiremock/WireMockUtils.java

Comment on lines 786 to 788
public void verifyNetworkAreaDiagramConfig(UUID stubId) {
verifyPostRequest(wireMock, stubId, "/v1/network-area-diagram/config", Map.of("duplicateFrom", WireMock.matching(".*")));
verifyPostRequest(wireMock, stubId, "/v1/network-area-diagram/config/.*/duplicate", Map.of());
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Find callers of verifyNetworkAreaDiagramConfig to assess whether this bug is currently exercised.
rg -n "verifyNetworkAreaDiagramConfig" -g '*.java'

Repository: gridsuite/study-server

Length of output: 1996


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate files =="
fd -a 'WireMockStubs.java|WireMockUtils.java' src/test/java src/main/java 2>/dev/null || true

echo
echo "== find relevant symbols =="
rg -n "verifyNetworkAreaDiagramConfig|verifyPostRequest\\(" src/test/java src/main/java -g '*.java' || true

echo
echo "== show relevant sections from WireMockStubs.java =="
file=$(fd -a 'WireMockStubs.java' src/test/java 2>/dev/null | head -n 1 || true)
if [ -n "${file:-}" ]; then
  line=$(rg -n "verifyNetworkAreaDiagramConfig" "$file" | head -n 1 | cut -d: -f1 || true)
  if [ -n "${line:-}" ]; then
    start=$((line-12))
    end=$((line+12))
    sed -n "${start},${end}p" "$file"
  fi
fi

echo
echo "== show relevant sections from WireMockUtils.java =="
file2=$(fd -a 'WireMockUtils.java' src/test/java 2>/dev/null | head -n 1 || true)
if [ -n "${file2:-}" ]; then
  rg -n "verifyPostRequest\\(" "$file2" || true
  sed -n '1,260p' "$file2" | sed -n '/verifyPostRequest(/,/^}/p'
fi

Repository: gridsuite/study-server

Length of output: 1967


Pass regexMatching=true for this verifier
/v1/network-area-diagram/config/.*/duplicate is treated as a literal path unless regex matching is enabled, so this helper will never match a real duplicate-config request as written.

🤖 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/test/java/org/gridsuite/study/server/utils/wiremock/WireMockStubs.java`
around lines 786 - 788, The verifyNetworkAreaDiagramConfig helper is using a
path pattern that is currently treated as a literal string, so it will not match
duplicate-config requests. Update this verifier to enable regex matching when
calling verifyPostRequest, keeping the existing NetworkAreaDiagram duplicate
endpoint pattern and the stubId parameter so the helper matches the intended
request.

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.

1 participant