Skip to content

Homogenise rest services and replace restTemplate with restClient#67

Merged
antoinebhs merged 6 commits intomainfrom
homogenize-rest-service
Mar 16, 2026
Merged

Homogenise rest services and replace restTemplate with restClient#67
antoinebhs merged 6 commits intomainfrom
homogenize-rest-service

Conversation

@klesaulnier
Copy link
Contributor

PR Summary

Signed-off-by: LE SAULNIER Kevin <kevin.lesaulnier.pro@gmail.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 12, 2026

Warning

Rate limit exceeded

@antoinebhs has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 49 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 52a055ad-7fca-40c2-872b-6e3d1a0af0cc

📥 Commits

Reviewing files that changed from the base of the PR and between fb45f00 and fd54180.

📒 Files selected for processing (8)
  • monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisRestService.java
  • monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisResultProvider.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/services/SecurityAnalysisRestServiceTest.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/services/SecurityAnalysisResultProviderTest.java
  • monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ReportRestService.java
  • monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/StepExecutionService.java
  • monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ReportRestServiceTest.java
  • monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/StepExecutionServiceTest.java
📝 Walkthrough

Walkthrough

A systematic migration from Spring's RestTemplate to RestClient across multiple service classes in the monitor codebase. Updates constructors to accept RestClient.Builder instead of RestTemplateBuilder, refactors HTTP calls to use RestClient's fluent API, and introduces a new ReportRestService while updating dependent components. Exception handling is simplified by relying on RestClient's built-in error propagation.

Changes

Cohort / File(s) Summary
RestClient Migration (monitor-server)
monitor-server/src/main/java/org/gridsuite/monitor/server/services/ReportService.java, SecurityAnalysisService.java
Replaced RestTemplate/RestTemplateBuilder with RestClient.Builder; constructor now configures baseUrl with API version and resource path. HTTP calls simplified to RestClient fluent API (get/delete). Logging removed in SecurityAnalysisService.
RestClient Migration (monitor-worker-server)
monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ActionsRestService.java, FilterRestService.java, LoadFlowRestService.java, NetworkModificationRestService.java, ReportService.java, SecurityAnalysisRestService.java
Systematic replacement of RestTemplate with RestClient across six service classes. Constructor signatures updated to accept RestClient.Builder; base URI field removed. HTTP calls now use RestClient fluent API (post/get/put). Error handling simplified; removed try-catch blocks and explicit exception handling.
Report Service Refactoring
monitor-server/src/main/java/org/gridsuite/monitor/server/services/ReportRestService.java (new file), MonitorService.java
New ReportRestService class introduced with getReport/deleteReport methods using RestClient. MonitorService updated to depend on ReportRestService instead of ReportService; field and constructor parameter types swapped.
Test Exception Handling Updates
monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ActionsRestServiceTest.java, FilterRestServiceTest.java, LoadFlowRestServiceTest.java, SecurityAnalysisRestServiceTest.java
Updated exception assertions from PowsyblException to HttpServerErrorException.InternalServerError, reflecting RestClient's HTTP error handling. SecurityAnalysisRestServiceTest also adds userId header verification in GET parameter tests.
Integration & Service Tests
monitor-server/src/test/java/org/gridsuite/monitor/server/MonitorIntegrationTest.java, monitor-server/src/test/java/org/gridsuite/monitor/server/services/MonitorServiceTest.java, monitor-server/src/test/java/org/gridsuite/monitor/server/services/ReportRestServiceTest.java
MonitorIntegrationTest and MonitorServiceTest updated to mock/verify ReportRestService instead of ReportService. ReportServiceTest renamed to ReportRestServiceTest; test annotations and field declarations updated to reference ReportRestService.
Network Conversion Service
monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkConversionService.java
Simplified constructor to accept only base URI string instead of RestTemplateBuilder; removed RestTemplate field. CaseDataSourceClient now instantiated directly with base URI.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • FranckLecuyer
  • thangqp

Poem

🐰 From RestTemplate old to RestClient new,
The fluent API shines, so clean and true,
Base URLs built, and URIs set,
Error handling flows—no regrets yet!
In hopping strides, refactoring's done, 🎉

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

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.
Description check ❓ Inconclusive The description is empty and provides no meaningful information about the changeset, making it impossible to assess alignment with the changes. Provide a description explaining the motivation, scope, and any important implementation details or breaking changes for reviewers.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: replacing RestTemplate with RestClient and homogenizing REST services across the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch homogenize-rest-service
📝 Coding Plan
  • Generate coding plan for human review comments

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.

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 (7)
monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/FilterRestServiceTest.java (1)

90-99: Test name does not match error scenario.

Consistent with other test files in this PR, getFiltersNotFound simulates HTTP 500 via withServerError(), not HTTP 404. Consider renaming to getFiltersServerError for consistency and clarity.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/FilterRestServiceTest.java`
around lines 90 - 99, Rename the misleading test method getFiltersNotFound to
getFiltersServerError in the FilterRestServiceTest class to reflect the
simulated HTTP 500 scenario; update the test method name and any references to
it (keeping the existing assertions that call filterRestService.getFilters and
use FILTER_ERROR_UUID) so the test name matches the withServerError() behavior
and remains consistent with other tests.
monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestService.java (1)

29-35: Same potential double slash issue in base URL construction.

Consistent with other services, normalize the base URI to prevent double slashes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestService.java`
around lines 29 - 35, The constructor SecurityAnalysisRestService currently
concatenates securityAnalysisServerBaseUri + DELIMITER + SA_API_VERSION which
can produce a double slash; update the constructor to normalize the incoming
securityAnalysisServerBaseUri (trim any trailing '/') before passing into
restClientBuilder.baseUrl(...) or use a safe join/URI resolve approach so
DELIMITER and SA_API_VERSION are appended without duplicating slashes; ensure
you adjust the code around restClientBuilder, baseUrl, DELIMITER and
SA_API_VERSION references so the final base URL is always well-formed.
monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterRestService.java (1)

30-34: Potential double slash in base URL construction.

If filterServerBaseUri ends with a trailing slash (which is common, e.g., http://filter-server/), then filterServerBaseUri + DELIMITER + FILTER_SERVER_API_VERSION produces http://filter-server//v1. Consider normalizing the URI or using UriComponentsBuilder for safer composition.

♻️ Proposed fix to handle trailing slash
 public FilterRestService(`@Value`("${gridsuite.services.filter-server.base-uri:http://filter-server/}") String filterServerBaseUri,
                          RestClient.Builder restClientBuilder) {
+    String normalizedUri = filterServerBaseUri.endsWith(DELIMITER) 
+        ? filterServerBaseUri.substring(0, filterServerBaseUri.length() - 1) 
+        : filterServerBaseUri;
     this.restClient = restClientBuilder
-        .baseUrl(filterServerBaseUri + DELIMITER + FILTER_SERVER_API_VERSION)
+        .baseUrl(normalizedUri + DELIMITER + FILTER_SERVER_API_VERSION)
         .build();
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterRestService.java`
around lines 30 - 34, The constructor in FilterRestService currently
concatenates filterServerBaseUri + DELIMITER + FILTER_SERVER_API_VERSION which
can produce a double slash if filterServerBaseUri ends with '/' (e.g.,
http://filter-server/ + / + v1 -> //v1); fix by normalizing the base URI before
building the RestClient: trim any trailing '/' from filterServerBaseUri or use a
URI builder (e.g., UriComponentsBuilder) to join paths safely, then pass the
normalized base URL to restClientBuilder.baseUrl(...) so restClient is built
with a single correct slash between host and FILTER_SERVER_API_VERSION.
monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestServiceTest.java (1)

96-106: Test name does not match error scenario.

Similar to LoadFlowRestServiceTest, this test is named getParametersNotFound but simulates an HTTP 500 error with withServerError(). Consider renaming to getParametersServerError for clarity.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestServiceTest.java`
around lines 96 - 106, The test method name getParametersNotFound in
SecurityAnalysisRestServiceTest does not match the simulated HTTP 500 server
error; rename the test to reflect the actual scenario (e.g.,
getParametersServerError) and update any references or annotations accordingly
so it clearly corresponds to the server error path exercised by the call to
securityAnalysisRestService.getParameters(PARAMETERS_ERROR_UUID) which uses
MockRestResponseCreators.withServerError().
monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisService.java (1)

27-33: Same potential double slash issue in base URL construction.

Similar to FilterRestService, if securityAnalysisServerBaseUri ends with /, this will produce a double slash. Consider normalizing the URI consistently across all services in this PR.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisService.java`
around lines 27 - 33, Normalize the base URI before building the RestClient to
avoid double slashes: in the SecurityAnalysisService constructor, sanitize
securityAnalysisServerBaseUri (used with restClientBuilder, DELIMITER and
SA_API_VERSION) by trimming any trailing '/' (or ensuring exactly one '/'
between base and DELIMITER) and then call .baseUrl(...) with the normalized
string so concatenation of securityAnalysisServerBaseUri + DELIMITER +
SA_API_VERSION cannot produce a double slash.
monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/LoadFlowRestServiceTest.java (1)

68-77: Test name does not match the simulated error scenario.

The test is named getParametersNotFound, which implies a 404 Not Found scenario. However, MockRestResponseCreators.withServerError() returns HTTP 500 Internal Server Error. Consider renaming to getParametersServerError or using withResourceNotFound() if you intend to test a 404 scenario.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/LoadFlowRestServiceTest.java`
around lines 68 - 77, The test method getParametersNotFound is misnamed versus
the simulated response: either rename the test to getParametersServerError to
reflect that MockRestResponseCreators.withServerError() returns a 500, or change
the mock to MockRestResponseCreators.withResourceNotFound() to simulate a 404
and keep the name; update the assertion if you switch to 404 to expect
HttpClientErrorException.NotFound when calling
loadFlowRestService.getParameters(PARAMETERS_ERROR_UUID).
monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java (1)

31-36: Same potential double slash issue in base URL construction.

Consistent with other services in this PR, consider normalizing the base URI to avoid potential double slashes when the property value includes a trailing slash.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java`
around lines 31 - 36, The constructor in NetworkModificationRestService
currently concatenates networkModificationServerBaseUri + DELIMITER +
NETWORK_MODIFICATION_SERVER_API_VERSION which can produce a double slash if the
injected property ends with a slash; update the constructor to normalize
networkModificationServerBaseUri (trim any trailing '/') before concatenation or
use a safe join approach when calling restClientBuilder.baseUrl so
networkModificationServerRest is built with a single slash between the base URI
and NETWORK_MODIFICATION_SERVER_API_VERSION (refer to the constructor,
networkModificationServerRest, DELIMITER and
NETWORK_MODIFICATION_SERVER_API_VERSION).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestService.java`:
- Around line 47-54: The getParameters method in SecurityAnalysisRestService
currently adds a hardcoded header "userId" with value "user1"; remove this
hardcoded header (i.e., delete the .header("userId", "user1") call) to match
other RestService classes, or if a userId is actually required change the method
signature of getParameters(UUID securityAnalysisParametersUuid, String userId)
and use that parameter in the .header(...) call, or alternatively obtain the
user id from the security context (e.g., SecurityContextHolder) before calling
restClient; update any callers of getParameters accordingly if you choose the
parameter or security-context approach.

---

Nitpick comments:
In
`@monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisService.java`:
- Around line 27-33: Normalize the base URI before building the RestClient to
avoid double slashes: in the SecurityAnalysisService constructor, sanitize
securityAnalysisServerBaseUri (used with restClientBuilder, DELIMITER and
SA_API_VERSION) by trimming any trailing '/' (or ensuring exactly one '/'
between base and DELIMITER) and then call .baseUrl(...) with the normalized
string so concatenation of securityAnalysisServerBaseUri + DELIMITER +
SA_API_VERSION cannot produce a double slash.

In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterRestService.java`:
- Around line 30-34: The constructor in FilterRestService currently concatenates
filterServerBaseUri + DELIMITER + FILTER_SERVER_API_VERSION which can produce a
double slash if filterServerBaseUri ends with '/' (e.g., http://filter-server/ +
/ + v1 -> //v1); fix by normalizing the base URI before building the RestClient:
trim any trailing '/' from filterServerBaseUri or use a URI builder (e.g.,
UriComponentsBuilder) to join paths safely, then pass the normalized base URL to
restClientBuilder.baseUrl(...) so restClient is built with a single correct
slash between host and FILTER_SERVER_API_VERSION.

In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java`:
- Around line 31-36: The constructor in NetworkModificationRestService currently
concatenates networkModificationServerBaseUri + DELIMITER +
NETWORK_MODIFICATION_SERVER_API_VERSION which can produce a double slash if the
injected property ends with a slash; update the constructor to normalize
networkModificationServerBaseUri (trim any trailing '/') before concatenation or
use a safe join approach when calling restClientBuilder.baseUrl so
networkModificationServerRest is built with a single slash between the base URI
and NETWORK_MODIFICATION_SERVER_API_VERSION (refer to the constructor,
networkModificationServerRest, DELIMITER and
NETWORK_MODIFICATION_SERVER_API_VERSION).

In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestService.java`:
- Around line 29-35: The constructor SecurityAnalysisRestService currently
concatenates securityAnalysisServerBaseUri + DELIMITER + SA_API_VERSION which
can produce a double slash; update the constructor to normalize the incoming
securityAnalysisServerBaseUri (trim any trailing '/') before passing into
restClientBuilder.baseUrl(...) or use a safe join/URI resolve approach so
DELIMITER and SA_API_VERSION are appended without duplicating slashes; ensure
you adjust the code around restClientBuilder, baseUrl, DELIMITER and
SA_API_VERSION references so the final base URL is always well-formed.

In
`@monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/FilterRestServiceTest.java`:
- Around line 90-99: Rename the misleading test method getFiltersNotFound to
getFiltersServerError in the FilterRestServiceTest class to reflect the
simulated HTTP 500 scenario; update the test method name and any references to
it (keeping the existing assertions that call filterRestService.getFilters and
use FILTER_ERROR_UUID) so the test name matches the withServerError() behavior
and remains consistent with other tests.

In
`@monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/LoadFlowRestServiceTest.java`:
- Around line 68-77: The test method getParametersNotFound is misnamed versus
the simulated response: either rename the test to getParametersServerError to
reflect that MockRestResponseCreators.withServerError() returns a 500, or change
the mock to MockRestResponseCreators.withResourceNotFound() to simulate a 404
and keep the name; update the assertion if you switch to 404 to expect
HttpClientErrorException.NotFound when calling
loadFlowRestService.getParameters(PARAMETERS_ERROR_UUID).

In
`@monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestServiceTest.java`:
- Around line 96-106: The test method name getParametersNotFound in
SecurityAnalysisRestServiceTest does not match the simulated HTTP 500 server
error; rename the test to reflect the actual scenario (e.g.,
getParametersServerError) and update any references or annotations accordingly
so it clearly corresponds to the server error path exercised by the call to
securityAnalysisRestService.getParameters(PARAMETERS_ERROR_UUID) which uses
MockRestResponseCreators.withServerError().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4b7b59df-7e42-4271-a1ea-5afec21fb7cf

📥 Commits

Reviewing files that changed from the base of the PR and between 4416841 and cd65852.

📒 Files selected for processing (13)
  • monitor-server/src/main/java/org/gridsuite/monitor/server/services/ReportService.java
  • monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisService.java
  • monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ActionsRestService.java
  • monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterRestService.java
  • monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/LoadFlowRestService.java
  • monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkConversionService.java
  • monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java
  • monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ReportService.java
  • monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestService.java
  • monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ActionsRestServiceTest.java
  • monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/FilterRestServiceTest.java
  • monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/LoadFlowRestServiceTest.java
  • monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestServiceTest.java

Comment on lines 47 to 54
public SecurityAnalysisParametersValues getParameters(UUID securityAnalysisParametersUuid) {
LOGGER.info("Get security analysis parameters {}", securityAnalysisParametersUuid);

var path = securityAnalysisServerBaseUri + UriComponentsBuilder.fromPath(DELIMITER + SA_API_VERSION + DELIMITER + "parameters/{uuid}")
.buildAndExpand(securityAnalysisParametersUuid)
.toUriString();

try {
HttpHeaders headers = new HttpHeaders();
headers.set("userId", "user1"); // TODO : to remove after the fix that will remove the userId header when getting parameters
HttpEntity<?> requestEntity = new HttpEntity<>(headers);

return restTemplate.exchange(path, HttpMethod.GET, requestEntity, SecurityAnalysisParametersValues.class).getBody();
} catch (RestClientException e) {
throw new PowsyblException("Error retrieving security analysis parameters for UUID: " + securityAnalysisParametersUuid + " - " + e.getMessage(), e);
}
return restClient.get()
.uri("/parameters/{securityAnalysisParametersUuid}",
securityAnalysisParametersUuid)
.header("userId", "user1")
.retrieve()
.body(SecurityAnalysisParametersValues.class);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check how getParameters is called to understand where userId should come from
ast-grep --pattern 'getParameters($$$)'

Repository: gridsuite/monitor-core

Length of output: 48


🏁 Script executed:

rg -t java 'getParameters' --context 3

Repository: gridsuite/monitor-core

Length of output: 15211


🏁 Script executed:

rg -t java 'userId' monitor-worker-server/src --context 2

Repository: gridsuite/monitor-core

Length of output: 2686


🏁 Script executed:

cat -n monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestService.java

Repository: gridsuite/monitor-core

Length of output: 2546


🏁 Script executed:

find monitor-worker-server/src/main/java -name "*RestService.java" -type f

Repository: gridsuite/monitor-core

Length of output: 711


🏁 Script executed:

rg -t java 'header.*userId' monitor-worker-server/src/main/java

Repository: gridsuite/monitor-core

Length of output: 218


🏁 Script executed:

head -60 monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/LoadFlowRestService.java

Repository: gridsuite/monitor-core

Length of output: 1670


🏁 Script executed:

head -50 monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ActionsRestService.java

Repository: gridsuite/monitor-core

Length of output: 1934


🏁 Script executed:

head -50 monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java

Repository: gridsuite/monitor-core

Length of output: 2349


Hardcoded userId header value should not be in production code.

The getParameters method hardcodes "user1" as the userId header value. This appears to be a placeholder value and is inconsistent with other RestService classes in the codebase (LoadFlowRestService, ActionsRestService, NetworkModificationRestService) which do not use userId headers.

The actual user ID should either be:

  • Removed if not required (following the pattern of LoadFlowRestService)
  • Passed as a method parameter if needed
  • Retrieved from the security context
Proposed fix to accept userId as parameter
-public SecurityAnalysisParametersValues getParameters(UUID securityAnalysisParametersUuid) {
+public SecurityAnalysisParametersValues getParameters(UUID securityAnalysisParametersUuid, String userId) {
     return restClient.get()
         .uri("/parameters/{securityAnalysisParametersUuid}",
             securityAnalysisParametersUuid)
-        .header("userId", "user1")
+        .header("userId", userId)
         .retrieve()
         .body(SecurityAnalysisParametersValues.class);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestService.java`
around lines 47 - 54, The getParameters method in SecurityAnalysisRestService
currently adds a hardcoded header "userId" with value "user1"; remove this
hardcoded header (i.e., delete the .header("userId", "user1") call) to match
other RestService classes, or if a userId is actually required change the method
signature of getParameters(UUID securityAnalysisParametersUuid, String userId)
and use that parameter in the .header(...) call, or alternatively obtain the
user id from the security context (e.g., SecurityContextHolder) before calling
restClient; update any callers of getParameters accordingly if you choose the
parameter or security-context approach.

Signed-off-by: LE SAULNIER Kevin <kevin.lesaulnier.pro@gmail.com>
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.

🧹 Nitpick comments (1)
monitor-server/src/main/java/org/gridsuite/monitor/server/services/ReportRestService.java (1)

34-39: Consider using .body(ReportPage.class) for non-generic types.

ParameterizedTypeReference is typically needed for generic types (e.g., List<ReportPage>). Since ReportPage is not a generic type, you can simplify this to:

return restClient.get()
    .uri("/{reportId}/logs", reportId)
    .retrieve()
    .body(ReportPage.class);

This is functionally equivalent but more concise.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@monitor-server/src/main/java/org/gridsuite/monitor/server/services/ReportRestService.java`
around lines 34 - 39, The call in ReportRestService.getReport uses a
ParameterizedTypeReference for a non-generic return type; change the final
retrieval to use .body(ReportPage.class) instead of .body(new
ParameterizedTypeReference<>() { }) so getReport(UUID reportId) returns a
ReportPage more concisely — update the fluent chain on
restClient.get().uri("/{reportId}/logs", reportId).retrieve() to call
.body(ReportPage.class).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@monitor-server/src/main/java/org/gridsuite/monitor/server/services/ReportRestService.java`:
- Around line 34-39: The call in ReportRestService.getReport uses a
ParameterizedTypeReference for a non-generic return type; change the final
retrieval to use .body(ReportPage.class) instead of .body(new
ParameterizedTypeReference<>() { }) so getReport(UUID reportId) returns a
ReportPage more concisely — update the fluent chain on
restClient.get().uri("/{reportId}/logs", reportId).retrieve() to call
.body(ReportPage.class).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6c36b5d9-e686-4eed-b6c0-fde9bf4cac81

📥 Commits

Reviewing files that changed from the base of the PR and between cd65852 and 4743ab5.

📒 Files selected for processing (10)
  • monitor-server/src/main/java/org/gridsuite/monitor/server/services/MonitorService.java
  • monitor-server/src/main/java/org/gridsuite/monitor/server/services/ReportRestService.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/MonitorIntegrationTest.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/services/MonitorServiceTest.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/services/ReportRestServiceTest.java
  • monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/commons/steps/LoadNetworkStep.java
  • monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/CaseRestService.java
  • monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/commons/steps/LoadNetworkStepTest.java
  • monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/CaseRestServiceTest.java
  • monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ProcessExecutionServiceTest.java

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: 2

🧹 Nitpick comments (1)
monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterRestService.java (1)

37-43: Return an empty list when response body is absent.

retrieve().body(...) may return null; returning List.of() here prevents downstream null handling issues for getFilters.

Proposed fix
     public List<AbstractFilter> getFilters(List<UUID> filtersUuids) {
-        return restClient.get()
+        List<AbstractFilter> filters = restClient.get()
             .uri(uriBuilder -> uriBuilder
                 .path("/filters/metadata")
                 .queryParam("ids", filtersUuids.toArray())
                 .build())
             .retrieve()
             .body(new ParameterizedTypeReference<>() { });
+        return filters != null ? filters : List.of();
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterRestService.java`
around lines 37 - 43, The call returning the filters list from the restClient
chain can yield null; after invoking the retrieve().body(...) call in
FilterRestService (the restClient.get()... .retrieve().body(...) expression),
capture the result into a variable and return
Optional.ofNullable(result).orElse(List.of()) (or explicitly check for null and
return List.of()) so the method never returns null and downstream getFilters
callers receive an empty list instead.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterRestService.java`:
- Around line 32-33: The baseUrl construction in FilterRestService appends
DELIMITER to filterServerBaseUri then FILTER_SERVER_API_VERSION, which produces
a double slash when filterServerBaseUri already ends with '/' (resulting in
"//v1"); update the code that builds the WebClient baseUrl to normalize/truncate
any trailing '/' from filterServerBaseUri before concatenating DELIMITER and
FILTER_SERVER_API_VERSION (or use a join that ensures a single delimiter) —
adjust the logic around the baseUrl(...) call that references
filterServerBaseUri, DELIMITER, and FILTER_SERVER_API_VERSION so the final base
URL contains exactly one '/' between the host and the version.

In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java`:
- Around line 31-34: The base URI concatenation in the
NetworkModificationRestService constructor can produce a double slash; normalize
networkModificationServerBaseUri before appending DELIMITER and
NETWORK_MODIFICATION_SERVER_API_VERSION by trimming any trailing '/' (or
otherwise ensuring exactly one separator) so the call to
restClientBuilder.baseUrl(...) always receives a single-slash-separated URL;
update the constructor logic that builds networkModificationServerRest (using
networkModificationServerBaseUri, DELIMITER,
NETWORK_MODIFICATION_SERVER_API_VERSION, restClientBuilder) to remove trailing
slashes from the input base URI before concatenation.

---

Nitpick comments:
In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterRestService.java`:
- Around line 37-43: The call returning the filters list from the restClient
chain can yield null; after invoking the retrieve().body(...) call in
FilterRestService (the restClient.get()... .retrieve().body(...) expression),
capture the result into a variable and return
Optional.ofNullable(result).orElse(List.of()) (or explicitly check for null and
return List.of()) so the method never returns null and downstream getFilters
callers receive an empty list instead.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1dcf1145-f57a-4a76-ab56-676a291cc757

📥 Commits

Reviewing files that changed from the base of the PR and between 4743ab5 and d07e23c.

📒 Files selected for processing (3)
  • monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisService.java
  • monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterRestService.java
  • monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java

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.

🧹 Nitpick comments (1)
monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkConversionService.java (1)

33-34: Validate caseServerBaseUri at startup (fail fast).

At Line 33, the URI is accepted as-is. A null/blank/malformed value will surface only when requests are made. Validate once in the constructor to fail early with a clear config error.

Proposed patch
+import java.net.URI;
+import java.util.Objects;
 import java.util.Properties;
 import java.util.UUID;
@@
     public NetworkConversionService(`@Value`("${powsybl.services.case-server.base-uri:http://case-server/}") String caseServerBaseUri) {
-        this.caseServerBaseUri = caseServerBaseUri;
+        Objects.requireNonNull(caseServerBaseUri, "powsybl.services.case-server.base-uri must not be null");
+        if (caseServerBaseUri.isBlank()) {
+            throw new IllegalArgumentException("powsybl.services.case-server.base-uri must not be blank");
+        }
+        URI.create(caseServerBaseUri); // validate syntax
+        this.caseServerBaseUri = caseServerBaseUri;
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkConversionService.java`
around lines 33 - 34, In the NetworkConversionService constructor, validate the
injected caseServerBaseUri: trim and check it's not null or blank, attempt to
parse it with java.net.URI (or new URL) to ensure it's well-formed, and if
validation fails throw an IllegalArgumentException with a clear message so the
application fails fast; assign the validated value to the caseServerBaseUri
field (optionally normalizing it, e.g., ensuring a trailing slash) so
NetworkConversionService uses a guaranteed-valid URI at runtime.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkConversionService.java`:
- Around line 33-34: In the NetworkConversionService constructor, validate the
injected caseServerBaseUri: trim and check it's not null or blank, attempt to
parse it with java.net.URI (or new URL) to ensure it's well-formed, and if
validation fails throw an IllegalArgumentException with a clear message so the
application fails fast; assign the validated value to the caseServerBaseUri
field (optionally normalizing it, e.g., ensuring a trailing slash) so
NetworkConversionService uses a guaranteed-valid URI at runtime.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f0444beb-1bb5-4e7e-a1c2-955322b818ad

📥 Commits

Reviewing files that changed from the base of the PR and between d07e23c and fb45f00.

📒 Files selected for processing (1)
  • monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkConversionService.java

@sonarqubecloud
Copy link

@antoinebhs antoinebhs merged commit d3b3848 into main Mar 16, 2026
4 checks passed
@antoinebhs antoinebhs deleted the homogenize-rest-service branch March 16, 2026 17:06
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