Skip to content

Fix import parameters#990

Open
etiennehomer wants to merge 14 commits into
mainfrom
fix_import_parameters
Open

Fix import parameters#990
etiennehomer wants to merge 14 commits into
mainfrom
fix_import_parameters

Conversation

@etiennehomer
Copy link
Copy Markdown
Contributor

PR Summary

Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Migrates importParameters from Map<String,String> to Map<String,Object>. DTOs serialize objects to JSON strings for persistence; entities deserialize stored strings back to objects. Services, consumer, and tests updated; Liquibase change normalizes empty stored values.

Changes

Import Parameters Type Migration

Layer / File(s) Summary
DTO and Entity Serialization/Deserialization Infrastructure
src/main/java/org/gridsuite/study/server/dto/RootNetworkInfos.java, src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkEntity.java, src/main/java/org/gridsuite/study/server/utils/JsonUtils.java, src/main/java/org/gridsuite/study/server/error/StudyBusinessErrorCode.java
RootNetworkInfos.importParameters -> Map<String,Object>; toEntity() calls serializeImportParameters(...) to persist JSON strings. RootNetworkEntity uses @ElementCollection(fetch = FetchType.EAGER) and toDto() uses deserializeImportParameters(...). JSON helpers added and UNPROCESSABLE_IMPORT_PARAMETER error code introduced.
Service and Consumer Type Updates
src/main/java/org/gridsuite/study/server/service/ConsumerService.java, src/main/java/org/gridsuite/study/server/service/RootNetworkService.java, src/main/java/org/gridsuite/study/server/service/StudyService.java, src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java
ConsumerService reads HEADER_IMPORT_PARAMETERS as Map<String,Object> and forwards it. StudyService insertStudy / saveStudyThenCreateBasicTree signatures updated to Map<String,Object>. RootNetworkService serializes importParameters when persisting and deserializes stored values when returning; getImportParameters(UUID) now returns Map<String,Object>. NetworkModificationService uses the new JsonUtils.getModificationContextJsonString overload.
Test Compatibility & WireMock expectations
src/test/java/org/gridsuite/study/server/rootnetworks/RootNetworkTest.java, src/test/java/org/gridsuite/study/server/studycontroller/*, src/test/java/org/gridsuite/study/server/NetworkModificationTest.java
Tests updated to build and assert against Map<String,Object> importParameters including mixed types and nulls; WireMock verification payloads updated to use the new getModificationContextJsonString(modificationBody) overload.
Database Migration
src/main/resources/db/changelog/changesets/changelog_20260519T112945Z.xml
Add Liquibase changeset to convert empty-string values in import_parameters.import_parameters to NULL prior to JSON parsing.

Sequence Diagram(s)

sequenceDiagram
  participant Consumer as ConsumerService
  participant Service as RootNetworkService
  participant Entity as RootNetworkEntity(DB)
  Consumer->>Service: send importParameters (Map<String,Object>)
  Service->>Service: serializeImportParameters -> Map<String,String>
  Service->>Entity: persist importParameters (Map<String,String>)
  Entity->>Entity: deserializeImportParameters -> Map<String,Object>
  Entity->>Service: return DTO with importParameters (Map<String,Object>)
Loading

Suggested reviewers:

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

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is empty and provides no information about the changes, making it impossible to assess whether it relates to the changeset. Add a detailed description explaining the changes to import parameters handling, including the rationale for moving from Map<String, String> to Map<String, Object> and the serialization/deserialization approach.
Docstring Coverage ⚠️ Warning Docstring coverage is 1.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix import parameters' accurately reflects the main change in the changeset, which updates import parameters handling across multiple files from Map<String, String> to Map<String, Object> with JSON serialization.
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.

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/RootNetworkService.java`:
- Line 187: The duplicated importParameters are being copied as
Map<String,Object> from a persisted Map<String,String> (newImportParameters =
Map.copyOf(rootNetworkEntityToDuplicate.getImportParameters())), which leads to
double-serialization when RootNetworkInfos.toEntity() writes them out; instead
transform the entries so String values that contain JSON are deserialized into
their native objects before storing in newImportParameters (e.g., iterate
rootNetworkEntityToDuplicate.getImportParameters(), for each entry: if value is
a String attempt to parse it with the project JSON mapper into Object, otherwise
keep as-is), then use that transformed map in place of the direct Map.copyOf to
prevent quoted strings becoming double-quoted JSON in
RootNetworkInfos.toEntity().
🪄 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: 0b5debd4-6097-4146-9ce5-258e59cd963f

📥 Commits

Reviewing files that changed from the base of the PR and between 7a04ef0 and 91d863f.

📒 Files selected for processing (6)
  • src/main/java/org/gridsuite/study/server/dto/RootNetworkInfos.java
  • src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkEntity.java
  • src/main/java/org/gridsuite/study/server/service/ConsumerService.java
  • src/main/java/org/gridsuite/study/server/service/RootNetworkService.java
  • src/main/java/org/gridsuite/study/server/service/StudyService.java
  • src/test/java/org/gridsuite/study/server/rootnetworks/RootNetworkTest.java

Comment thread src/main/java/org/gridsuite/study/server/service/RootNetworkService.java Outdated
Signed-off-by: Etienne Homer <etiennehomer@gmail.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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkEntity.java (1)

76-80: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Change importParameters to lazy loading

The @ElementCollection(fetch = FetchType.EAGER) forces unnecessary loading of the separate importParameters table on all RootNetworkEntity queries. Most operations that fetch root networks (e.g., getNetworkUuid(), getCaseName(), getRootReportUuid()) only access basic properties and never need the import parameters. The single method that requires them (getImportParameters()) already explicitly loads them using findWithImportParametersById() with @EntityGraph. Change to FetchType.LAZY to avoid the overhead.

Suggested change
-    `@ElementCollection`(fetch = FetchType.EAGER)
+    `@ElementCollection`(fetch = FetchType.LAZY)
🤖 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/repository/rootnetwork/RootNetworkEntity.java`
around lines 76 - 80, Change the importParameters element collection in
RootNetworkEntity from eager to lazy loading: replace `@ElementCollection`(fetch =
FetchType.EAGER) on the importParameters field with `@ElementCollection`(fetch =
FetchType.LAZY) so the separate importParameters table isn't always loaded; keep
the existing findWithImportParametersById() / getImportParameters() usage
(EntityGraph) to explicitly load parameters where needed. Ensure the field
declaration name importParameters and class RootNetworkEntity remain unchanged
so existing EntityGraph/query methods continue to work.
🤖 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/repository/rootnetwork/RootNetworkEntity.java`:
- Around line 117-121: In RootNetworkEntity where objectMapper.readValue(value,
Object.class) is called (the block that populates result.put(key, ...)), guard
against null values before attempting Jackson deserialization: if value == null,
put null (or the raw null value) into result for that key instead of calling
readValue, otherwise proceed to readValue and fall back to result.put(key,
value) in the existing JsonProcessingException catch; reference
objectMapper.readValue, result.put, and the surrounding try/catch to locate the
fix.

---

Outside diff comments:
In
`@src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkEntity.java`:
- Around line 76-80: Change the importParameters element collection in
RootNetworkEntity from eager to lazy loading: replace `@ElementCollection`(fetch =
FetchType.EAGER) on the importParameters field with `@ElementCollection`(fetch =
FetchType.LAZY) so the separate importParameters table isn't always loaded; keep
the existing findWithImportParametersById() / getImportParameters() usage
(EntityGraph) to explicitly load parameters where needed. Ensure the field
declaration name importParameters and class RootNetworkEntity remain unchanged
so existing EntityGraph/query methods continue to work.
🪄 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: 0fdedd79-971f-4983-8f3f-9888cd45d7c9

📥 Commits

Reviewing files that changed from the base of the PR and between 91d863f and b067516.

📒 Files selected for processing (2)
  • src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkEntity.java
  • src/test/java/org/gridsuite/study/server/studycontroller/StudyControllerCreationTest.java

Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
Signed-off-by: Etienne Homer <etiennehomer@gmail.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: 1

🧹 Nitpick comments (2)
src/main/java/org/gridsuite/study/server/utils/JsonUtils.java (1)

80-80: ⚡ Quick win

Reuse ObjectMapper instance for better performance.

Creating a new ObjectMapper instance on every call to deserializeImportParameters and serializeImportParameters is inefficient. ObjectMapper is thread-safe and relatively expensive to construct. Consider using a shared static instance or injecting a singleton.

♻️ Refactor to use static ObjectMapper
 public final class JsonUtils {
+    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
     private JsonUtils() {
         throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
     }
     
     // ... existing methods ...
     
     public static Map<String, Object> deserializeImportParameters(Map<String, String> rawParams) {
         Map<String, Object> result = new HashMap<>();
         if (rawParams == null) {
             return result;
         }
 
-        ObjectMapper objectMapper = new ObjectMapper();
         rawParams.forEach((key, value) -> {
             if (value == null) {
                 result.put(key, null);
                 return;
             }
             try {
-                result.put(key, objectMapper.readValue(value, Object.class));
+                result.put(key, OBJECT_MAPPER.readValue(value, Object.class));
             } catch (JsonProcessingException e) {
                 throw new StudyException(UNPROCESSABLE_IMPORT_PARAMETER, "Import parameter '" + key + " => " + value + "' is not valid JSON: " + e.getMessage());
             }
         });
         return result;
     }
 
     public static Map<String, String> serializeImportParameters(Map<String, Object> params) {
         Map<String, String> result = new HashMap<>();
         if (params == null) {
             return result;
         }
 
-        ObjectMapper objectMapper = new ObjectMapper();
         params.forEach((key, value) -> {
             try {
-                result.put(key, objectMapper.writeValueAsString(value));
+                result.put(key, OBJECT_MAPPER.writeValueAsString(value));
             } catch (JsonProcessingException e) {
                 result.put(key, String.valueOf(value));
             }
         });
         return result;
     }

Also applies to: 101-101

🤖 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/utils/JsonUtils.java` at line 80,
Replace the per-call new ObjectMapper() allocations in JsonUtils by a shared,
thread-safe singleton: add a private static final ObjectMapper (e.g.,
OBJECT_MAPPER) field on the JsonUtils class and initialize it once, then update
deserializeImportParameters and serializeImportParameters to use
JsonUtils.OBJECT_MAPPER instead of creating a new ObjectMapper; alternatively
accept/inject a singleton ObjectMapper if preferred. Ensure any configuration
(modules, visibility, date formats) currently applied to the local instances is
applied once to the shared instance.
src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkEntity.java (1)

76-76: 💤 Low value

Consider the performance impact of EAGER fetching.

Changing the fetch strategy to FetchType.EAGER means all import parameters will be loaded whenever a RootNetworkEntity is retrieved, even if they're not needed. This could impact performance if import parameters are large or if entities are frequently loaded without needing the parameters.

If import parameters are always required when loading the entity, EAGER fetch is appropriate. Otherwise, consider keeping the default LAZY fetch and explicitly join-fetch when needed.

🤖 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/repository/rootnetwork/RootNetworkEntity.java`
at line 76, The annotation on the import-parameters collection in
RootNetworkEntity currently uses FetchType.EAGER which may hurt performance;
change the `@ElementCollection`(fetch = FetchType.EAGER) on the import parameters
field in class RootNetworkEntity to FetchType.LAZY (or remove explicit fetch to
use the default LAZY) and then update callers/repositories that need parameters
to explicitly fetch them (e.g., add join fetch to the RootNetworkEntity
repository queries or define an EntityGraph for methods that must load import
parameters).
🤖 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/utils/JsonUtils.java`:
- Around line 95-110: The current serializeImportParameters method silently
falls back to String.valueOf(value) on JsonProcessingException which can store
non-JSON strings and break deserializeImportParameters; change
serializeImportParameters (in class JsonUtils) to fail-fast by removing the
String.valueOf fallback and instead catch JsonProcessingException and rethrow a
StudyException with a clear message including the key and original exception
(propagate the cause), so invalid objects are not written to the DB and
deserializeImportParameters can assume stored values are valid JSON.

---

Nitpick comments:
In
`@src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkEntity.java`:
- Line 76: The annotation on the import-parameters collection in
RootNetworkEntity currently uses FetchType.EAGER which may hurt performance;
change the `@ElementCollection`(fetch = FetchType.EAGER) on the import parameters
field in class RootNetworkEntity to FetchType.LAZY (or remove explicit fetch to
use the default LAZY) and then update callers/repositories that need parameters
to explicitly fetch them (e.g., add join fetch to the RootNetworkEntity
repository queries or define an EntityGraph for methods that must load import
parameters).

In `@src/main/java/org/gridsuite/study/server/utils/JsonUtils.java`:
- Line 80: Replace the per-call new ObjectMapper() allocations in JsonUtils by a
shared, thread-safe singleton: add a private static final ObjectMapper (e.g.,
OBJECT_MAPPER) field on the JsonUtils class and initialize it once, then update
deserializeImportParameters and serializeImportParameters to use
JsonUtils.OBJECT_MAPPER instead of creating a new ObjectMapper; alternatively
accept/inject a singleton ObjectMapper if preferred. Ensure any configuration
(modules, visibility, date formats) currently applied to the local instances is
applied once to the shared instance.
🪄 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: a3024a42-1a4a-441b-9720-23c71eb091e2

📥 Commits

Reviewing files that changed from the base of the PR and between 5256bd4 and 23ba8a2.

📒 Files selected for processing (8)
  • src/main/java/org/gridsuite/study/server/dto/RootNetworkInfos.java
  • src/main/java/org/gridsuite/study/server/error/StudyBusinessErrorCode.java
  • src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkEntity.java
  • src/main/java/org/gridsuite/study/server/service/RootNetworkService.java
  • src/main/java/org/gridsuite/study/server/utils/JsonUtils.java
  • src/main/resources/db/changelog/changesets/changelog_20260519T112945Z.xml
  • src/test/java/org/gridsuite/study/server/rootnetworks/RootNetworkTest.java
  • src/test/java/org/gridsuite/study/server/studycontroller/StudyControllerCreationTest.java
✅ Files skipped from review due to trivial changes (2)
  • src/main/resources/db/changelog/changesets/changelog_20260519T112945Z.xml
  • src/main/java/org/gridsuite/study/server/error/StudyBusinessErrorCode.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/test/java/org/gridsuite/study/server/studycontroller/StudyControllerCreationTest.java
  • src/main/java/org/gridsuite/study/server/service/RootNetworkService.java

Comment thread src/main/java/org/gridsuite/study/server/utils/JsonUtils.java
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
@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