Skip to content

export network#1001

Open
ghazwarhili wants to merge 3 commits into
mainfrom
import-export-study
Open

export network#1001
ghazwarhili wants to merge 3 commits into
mainfrom
import-export-study

Conversation

@ghazwarhili
Copy link
Copy Markdown
Contributor

PR Summary

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Review Change Stack

Caution

Review failed

Failed to post review comments

📝 Walkthrough

Walkthrough

Replaces node-scoped network-modifications export with a study-scoped export API. Adds DTOs for export/import, a batch network-modification export method, StudyService orchestration to assemble StudyExportInfos, a GET endpoint returning StudyExportInfos, and corresponding tests.

Changes

Full Study Export

Layer / File(s) Summary
Study Export DTO Contracts
src/main/java/org/gridsuite/study/server/dto/RootNetworkExportInfos.java, src/main/java/org/gridsuite/study/server/dto/StudyExportInfos.java, src/main/java/org/gridsuite/study/server/dto/StudyTreeNodeExportInfos.java, src/main/java/org/gridsuite/study/server/dto/StudyImportInfos.java
Adds DTOs defining export/import payloads: RootNetworkExportInfos, recursive StudyTreeNodeExportInfos, top-level StudyExportInfos, and StudyImportInfos for import payloads.
Batch Network Modification Export Service
src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java
Refactors path constants and adds getModificationsInfosToExport(List<UUID>), which POSTs a list of group UUIDs to groups/network-modifications/export and returns Map<UUID, Object>.
Full Study Export Orchestration
src/main/java/org/gridsuite/study/server/service/StudyService.java, src/main/java/org/gridsuite/study/server/service/RootNetworkService.java
Adds getStudyExport(UUID) that validates the study, exports root networks, collects modification-group UUIDs by traversing the tree, fetches batch modification payloads, and constructs a recursive StudyTreeNodeExportInfos tree embedding node-level modifications. Also updates some imports to wildcards.
Study Export REST Endpoint
src/main/java/org/gridsuite/study/server/controller/StudyController.java
Adds GET /studies/{studyUuid}/network-modifications/export returning ResponseEntity<StudyExportInfos> by delegating to studyService.getStudyExport(studyUuid), replacing the previous node-scoped endpoint.
Tests and MockWebServer
src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java
Updates MockWebServer to handle POST /v1/groups/network-modifications/export, rewrites node-export test to use the new study-level export and deserializes to StudyExportInfos, and adds a 404 test for missing studies.

Suggested reviewers

  • Meklo
  • Mathieu-Deharbe
  • khouadrired
🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is completely empty; the template was not filled in with any information about changes, context, or reviewer notes. Fill in the PR description with a summary of the changes, rationale, and any important notes for reviewers to understand the scope and impact of the changes.
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.
Title check ❓ Inconclusive The title 'export network' is vague and generic; it does not provide meaningful information about what specific changes were made or the primary objective. Provide a more descriptive title that clearly indicates the scope of changes, such as 'Replace node-scoped network export with study-scoped export endpoint' or 'Refactor network-modifications export to study-level API'.
✅ Passed checks (2 passed)
Check name Status Explanation
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.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.42.3)
src/main/java/org/gridsuite/study/server/controller/StudyController.java
src/main/java/org/gridsuite/study/server/service/StudyService.java

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
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: 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/study/server/service/NetworkModificationService.java`:
- Around line 95-107: The method getModificationsInfosToExport currently returns
whatever restTemplate.exchange(...).getBody() returns, which can be null if the
remote service responds without a body; change the return path to defensively
handle null by returning Map.of() when getBody() is null. Update
getModificationsInfosToExport (and the other batch-export helper that invokes
restTemplate.exchange(...).getBody() for a Map<UUID,Object>) to capture the
response body into a local variable and return body != null ? body : Map.of(),
ensuring callers always receive a non-null 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: dc2e1299-9776-461c-b48d-455fd6f4964c

📥 Commits

Reviewing files that changed from the base of the PR and between 159ad86 and 0367d2f.

📒 Files selected for processing (8)
  • src/main/java/org/gridsuite/study/server/controller/StudyController.java
  • src/main/java/org/gridsuite/study/server/dto/RootNetworkExportInfos.java
  • src/main/java/org/gridsuite/study/server/dto/StudyExportInfos.java
  • src/main/java/org/gridsuite/study/server/dto/StudyImportInfos.java
  • src/main/java/org/gridsuite/study/server/dto/StudyTreeNodeExportInfos.java
  • src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java
  • src/main/java/org/gridsuite/study/server/service/RootNetworkService.java
  • src/main/java/org/gridsuite/study/server/service/StudyService.java

Comment on lines +95 to 107
public Map<UUID, Object> getModificationsInfosToExport(List<UUID> groupUuids) {
Objects.requireNonNull(groupUuids);
if (groupUuids.isEmpty()) {
return Map.of();
}
var path = UriComponentsBuilder.fromPath("groups" + DELIMITER + "modifications" + DELIMITER + "export")
.queryParam(QUERY_PARAM_ERROR_ON_GROUP_NOT_FOUND, false)
.toUriString();

return restTemplate.exchange(getNetworkModificationServerURI(false) + path, HttpMethod.GET, null, String.class).getBody();
HttpEntity<List<UUID>> httpEntity = new HttpEntity<>(groupUuids);
return restTemplate.exchange(getNetworkModificationServerURI(false) + path, HttpMethod.POST, httpEntity,
new ParameterizedTypeReference<Map<UUID, Object>>() { }).getBody();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Handle null HTTP bodies for batch export responses.

Line 106 and Line 477 can return null when the remote service responds without a body, which can break callers expecting a map. Return Map.of() instead.

💡 Proposed fix
 public Map<UUID, Object> getModificationsInfosToExport(List<UUID> groupUuids) {
     Objects.requireNonNull(groupUuids);
     if (groupUuids.isEmpty()) {
         return Map.of();
@@
-    return restTemplate.exchange(getNetworkModificationServerURI(false) + path, HttpMethod.POST, httpEntity,
-            new ParameterizedTypeReference<Map<UUID, Object>>() { }).getBody();
+    Map<UUID, Object> body = restTemplate.exchange(
+            getNetworkModificationServerURI(false) + path,
+            HttpMethod.POST,
+            httpEntity,
+            new ParameterizedTypeReference<Map<UUID, Object>>() { }
+    ).getBody();
+    return body != null ? body : Map.of();
 }
@@
 public Map<UUID, JsonNode> getModificationsToExportByGroups(List<UUID> groupUuids) {
     Objects.requireNonNull(groupUuids);
     if (groupUuids.isEmpty()) {
         return Map.of();
@@
-    return restTemplate.exchange(
+    Map<UUID, JsonNode> body = restTemplate.exchange(
             getNetworkModificationServerURI(false) + path,
             HttpMethod.POST,
             entity,
             new ParameterizedTypeReference<Map<UUID, JsonNode>>() { }
-    ).getBody();
+    ).getBody();
+    return body != null ? body : Map.of();
 }

Also applies to: 457-478

🤖 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/NetworkModificationService.java`
around lines 95 - 107, The method getModificationsInfosToExport currently
returns whatever restTemplate.exchange(...).getBody() returns, which can be null
if the remote service responds without a body; change the return path to
defensively handle null by returning Map.of() when getBody() is null. Update
getModificationsInfosToExport (and the other batch-export helper that invokes
restTemplate.exchange(...).getBody() for a Map<UUID,Object>) to capture the
response body into a local variable and return body != null ? body : Map.of(),
ensuring callers always receive a non-null Map.

@sonarqubecloud
Copy link
Copy Markdown

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