Skip to content

Get the names of filters contained in sensi parameters and give it to…#997

Merged
carojeandat merged 8 commits into
mainfrom
get-filter-names-for-sensi-before-run
Jun 2, 2026
Merged

Get the names of filters contained in sensi parameters and give it to…#997
carojeandat merged 8 commits into
mainfrom
get-filter-names-for-sensi-before-run

Conversation

@carojeandat
Copy link
Copy Markdown
Contributor

… sensi server before execution

PR Summary

… sensi server before execution

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

coderabbitai Bot commented May 22, 2026

Review Change Stack

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: 950372a4-d8c3-4349-a9db-49c379fd9651

📥 Commits

Reviewing files that changed from the base of the PR and between bd22305 and f75b8f1.

📒 Files selected for processing (2)
  • src/main/java/org/gridsuite/study/server/service/StudyService.java
  • src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/java/org/gridsuite/study/server/service/StudyService.java
  • src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java

📝 Walkthrough

Walkthrough

The PR adds element name resolution to sensitivity analysis: DirectoryService fetches names, SensitivityAnalysisService retrieves IDs and accepts a UUID→name map, StudyService orchestrates lookups and passes the map into the analysis run, and tests/stubs are updated to assert these interactions.

Changes

Element name resolution for sensitivity analysis

Layer / File(s) Summary
DirectoryService element name resolution
src/main/java/org/gridsuite/study/server/service/DirectoryService.java
New getElementNames(Set<UUID>) method queries /v1/elements/names with ids and strictMode=false, uses restTemplate.exchange with ParameterizedTypeReference<Map<UUID,String>>, and returns an empty map for empty input, null bodies, or RestClientException. Imports updated.
SensitivityAnalysisService integration
src/main/java/org/gridsuite/study/server/service/SensitivityAnalysisService.java
runSensitivityAnalysis(...) now accepts Map<UUID,String> elementsIdNameMap and sends it as the POST body; adds getElementIds(UUID) to fetch element IDs from the contingency-lists-and-filters endpoint and deserialize as List<UUID>. Imports adjusted for ParameterizedTypeReference and collection usages.
StudyService orchestration
src/main/java/org/gridsuite/study/server/service/StudyService.java
handleSensitivityAnalysisRequest() now derives sensitivity parameters UUID, calls sensitivityAnalysisService.getElementIds(), resolves names with directoryService.getElementNames(), and passes the name map into sensitivityAnalysisService.runSensitivityAnalysis().
WireMock test utilities and stubs
src/test/java/org/gridsuite/study/server/utils/wiremock/...
Added verifyPostRequest() overload accepting a request body; ComputationServerStubs adds verifyComputationRun() overload that verifies body; DirectoryServerStubs adds stubGetElementNames() and verifyGetElementNames(Set<UUID>); SensitivityAnalysisServerStubs simplified to accept pre-serialized response bodies and no ObjectMapper.
SensitivityAnalysisTest integration
src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java
Tests add fixtures for an element UUID and name and an immutable UUID→name map, initialize new stub collaborators and wire DirectoryService to WireMock in @BeforeEach, stub element IDs and names during runs, and verify element ID/name lookups plus computation request body contains the serialized name map.

Suggested reviewers

  • antoinebhs
  • khouadrired
  • AbdelHedhili
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.85% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description is incomplete, providing only a partial sentence that continues from the title without substantive detail about implementation or changes. Complete the PR description with details about how the changes work and which services are modified, such as mentioning DirectoryService and SensitivityAnalysisService updates.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: retrieving filter names from sensitivity parameters and providing them to the sensi server before execution.
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.

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

@carojeandat carojeandat marked this pull request as draft May 22, 2026 13:50
@carojeandat carojeandat marked this pull request as ready for review May 26, 2026 15:11
Signed-off-by: Caroline Jeandat <caroline.jeandat@rte-france.com>
Copy link
Copy Markdown

@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: 4

🧹 Nitpick comments (1)
src/main/java/org/gridsuite/study/server/service/DirectoryService.java (1)

86-87: ⚡ Quick win

Log directory lookup failures before fallback.

At Line 86, swallowing the exception without a log makes missing element-name payloads hard to diagnose in production.

Proposed patch
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@@
 public class DirectoryService {
+    private static final Logger LOGGER = LoggerFactory.getLogger(DirectoryService.class);
@@
         } catch (RestClientException e) {
+            LOGGER.warn("Failed to resolve element names for {} IDs", elementUuids.size(), e);
             return Map.of();
         }
🤖 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/DirectoryService.java`
around lines 86 - 87, The catch block in DirectoryService that currently
swallows RestClientException and returns Map.of() should log the failure before
returning so missing element-name payloads can be diagnosed; inside the method
(the try/catch around the REST lookup—refer to the method in DirectoryService
that catches RestClientException) replace the silent swallow with a
processLogger/LOGGER.error or warn call that includes a descriptive message and
the exception (e.g., "Directory lookup failed for [context/identifier]" plus the
exception), then continue to return Map.of() as the fallback.
🤖 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/study/server/service/SensitivityAnalysisService.java`:
- Around line 349-355: getElementIds currently returns response.getBody() from
restTemplate.exchange which may be null; change the method to capture the
ResponseEntity from restTemplate.exchange and return a non-null List by using
Optional.ofNullable(response.getBody()).orElseGet(Collections::emptyList) (or
Collections.emptyList()) so callers building a HashSet won't get a
NullPointerException; update the code around the restTemplate.exchange call in
getElementIds to assign to a ResponseEntity<List<UUID>> variable and return a
guaranteed non-null list.

In `@src/main/java/org/gridsuite/study/server/service/StudyService.java`:
- Around line 2702-2707: sensiParamsUuid is being read from
study.getSensitivityAnalysisParametersUuid() and used to prefetch element IDs
before the sensitivity parameters are guaranteed to be initialized, which can
cause a null-related failure; modify the flow so the sensitivity parameters UUID
is initialized/created on the Study before calling
sensitivityAnalysisService.getElementIds — for example call or inline the
existing initialization routine (or create a new
ensureSensitivityAnalysisParametersInitialized(study) step) so that
sensiParamsUuid is non-null, then assign UUID sensiParamsUuid =
study.getSensitivityAnalysisParametersUuid(); and only then call
sensitivityAnalysisService.getElementIds(sensiParamsUuid) and
directoryService.getElementNames(...).

In `@src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java`:
- Line 204: Fix the Checkstyle WhitespaceAfter issue by adding a space after the
comma in the SensitivityAnalysisServerStubs constructor call: change the
invocation of SensitivityAnalysisServerStubs(wireMockServer,objectMapper) to
include a space after the comma so it reads
SensitivityAnalysisServerStubs(wireMockServer, objectMapper);; update the call
site where SensitivityAnalysisServerStubs is instantiated (the line constructing
sensitivityAnalysisStubs) to follow this spacing.

In
`@src/test/java/org/gridsuite/study/server/utils/wiremock/DirectoryServerStubs.java`:
- Around line 114-119: The current verifyGetElementNames builds a full URL
string which leads to brittle ordering-dependent matching; change
verifyGetElementNames to verify the request by path-only matching and explicit
query-parameter matchers: call WireMockUtilsCriteria.verifyGetRequest with the
path "/v1/elements/names" (so it uses urlPathEqualTo internally) and supply a
query map containing PARAM_IDS mapped to the givenElementUuids and "strictMode"
mapped to "false" so the verification checks query parameters irrespective of
their order.

---

Nitpick comments:
In `@src/main/java/org/gridsuite/study/server/service/DirectoryService.java`:
- Around line 86-87: The catch block in DirectoryService that currently swallows
RestClientException and returns Map.of() should log the failure before returning
so missing element-name payloads can be diagnosed; inside the method (the
try/catch around the REST lookup—refer to the method in DirectoryService that
catches RestClientException) replace the silent swallow with a
processLogger/LOGGER.error or warn call that includes a descriptive message and
the exception (e.g., "Directory lookup failed for [context/identifier]" plus the
exception), then continue to return Map.of() as the fallback.
🪄 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: e8a88af5-2e70-469e-a10f-e8f467e505ec

📥 Commits

Reviewing files that changed from the base of the PR and between b07c75b and a0cde6e.

📒 Files selected for processing (9)
  • src/main/java/org/gridsuite/study/server/service/DirectoryService.java
  • src/main/java/org/gridsuite/study/server/service/SensitivityAnalysisService.java
  • src/main/java/org/gridsuite/study/server/service/StudyService.java
  • src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java
  • src/test/java/org/gridsuite/study/server/utils/wiremock/ComputationServerStubs.java
  • src/test/java/org/gridsuite/study/server/utils/wiremock/DirectoryServerStubs.java
  • src/test/java/org/gridsuite/study/server/utils/wiremock/SensitivityAnalysisServerStubs.java
  • src/test/java/org/gridsuite/study/server/utils/wiremock/WireMockStubs.java
  • src/test/java/org/gridsuite/study/server/utils/wiremock/WireMockUtilsCriteria.java

Comment thread src/main/java/org/gridsuite/study/server/service/SensitivityAnalysisService.java Outdated
Comment thread src/main/java/org/gridsuite/study/server/service/StudyService.java
Comment thread src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java Outdated
Signed-off-by: Caroline Jeandat <caroline.jeandat@rte-france.com>
Copy link
Copy Markdown

@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.

♻️ Duplicate comments (1)
src/test/java/org/gridsuite/study/server/utils/wiremock/DirectoryServerStubs.java (1)

91-100: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Stub won't match actual requests – missing ids query parameter and using exact URL matching.

The stub builds a URL with only strictMode=false (line 93) and uses urlEqualTo for exact matching (line 95). However, the actual service calls will include the ids query parameter (as shown in verifyGetElementNames at line 104), so this stub will never match and requests will fail with 404.

Use path-only matching like stubGetElementIds does in SensitivityAnalysisServerStubs.

🔧 Proposed fix
 public void stubGetElementNames(String responseBody) {
-    UriComponentsBuilder pathBuilder = UriComponentsBuilder.fromPath("/v1/elements/names");
-    pathBuilder.queryParam("strictMode", "false");
-
-    wireMock.stubFor(WireMock.get(WireMock.urlEqualTo(pathBuilder.buildAndExpand().toUriString()))
+    wireMock.stubFor(WireMock.get(WireMock.urlPathEqualTo("/v1/elements/names"))
         .willReturn(WireMock.aResponse()
             .withStatus(HttpStatus.OK.value())
             .withHeader("Content-Type", "application/json")
             .withBody(responseBody)));
 }
🤖 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/DirectoryServerStubs.java`
around lines 91 - 100, The stubGetElementNames currently uses urlEqualTo with
only strictMode in the built URL so it won't match requests that include the ids
query parameter; update stubGetElementNames to use path-based matching (e.g.,
WireMock.urlPathEqualTo("/v1/elements/names")) and add a query param matcher for
strictMode (WireMock.withQueryParam("strictMode", WireMock.equalTo("false"))) so
requests including ids will match (follow the approach used by stubGetElementIds
in SensitivityAnalysisServerStubs); verifyGetElementNames should then correctly
correspond to the stub.
🤖 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.

Duplicate comments:
In
`@src/test/java/org/gridsuite/study/server/utils/wiremock/DirectoryServerStubs.java`:
- Around line 91-100: The stubGetElementNames currently uses urlEqualTo with
only strictMode in the built URL so it won't match requests that include the ids
query parameter; update stubGetElementNames to use path-based matching (e.g.,
WireMock.urlPathEqualTo("/v1/elements/names")) and add a query param matcher for
strictMode (WireMock.withQueryParam("strictMode", WireMock.equalTo("false"))) so
requests including ids will match (follow the approach used by stubGetElementIds
in SensitivityAnalysisServerStubs); verifyGetElementNames should then correctly
correspond to the stub.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a37ed161-30ff-4415-8e81-eb931839994f

📥 Commits

Reviewing files that changed from the base of the PR and between a0cde6e and 9c10dd3.

📒 Files selected for processing (3)
  • src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java
  • src/test/java/org/gridsuite/study/server/utils/wiremock/DirectoryServerStubs.java
  • src/test/java/org/gridsuite/study/server/utils/wiremock/SensitivityAnalysisServerStubs.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java

carojeandat and others added 5 commits May 27, 2026 13:53
Signed-off-by: Caroline Jeandat <caroline.jeandat@rte-france.com>
…-before-run

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

# Conflicts:
#	src/main/java/org/gridsuite/study/server/service/SensitivityAnalysisService.java
Signed-off-by: Caroline Jeandat <caroline.jeandat@rte-france.com>
Signed-off-by: Caroline Jeandat <caroline.jeandat@rte-france.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

@antoinebhs antoinebhs left a comment

Choose a reason for hiding this comment

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

LGTM

@carojeandat carojeandat merged commit f0cafbc into main Jun 2, 2026
5 of 6 checks passed
@carojeandat carojeandat deleted the get-filter-names-for-sensi-before-run branch June 2, 2026 12:25
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.

3 participants