Skip to content

[INJIWEB-1865] Modified the formatValue function#1041

Open
Rudhhi-Shah-14 wants to merge 2 commits intoinji:developfrom
tw-mosip:injiweb-1865
Open

[INJIWEB-1865] Modified the formatValue function#1041
Rudhhi-Shah-14 wants to merge 2 commits intoinji:developfrom
tw-mosip:injiweb-1865

Conversation

@Rudhhi-Shah-14
Copy link
Contributor

@Rudhhi-Shah-14 Rudhhi-Shah-14 commented Mar 4, 2026

Modified the formatValue function to enable Multilang support
Added the test cases for the same

Summary by CodeRabbit

  • Bug Fixes
    • Improved credential PDF generation to recognize alternate language/value field names, improving localization handling and compatibility with varied credential formats.
  • Tests
    • Added unit tests validating formatting/localization behavior for multiple language key variants and ensuring correct handling of unmatched or null entries.

…support

Signed-off-by: Rudhhi Shah <rudhhi.shah@thoughtworks.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

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: 3a519510-595c-4078-be46-fdab3e56d74b

📥 Commits

Reviewing files that changed from the base of the PR and between 890bb38 and 1b37358.

📒 Files selected for processing (1)
  • src/test/java/io/mosip/mimoto/service/CredentialPDFGeneratorServiceTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/io/mosip/mimoto/service/CredentialPDFGeneratorServiceTest.java

Walkthrough

This PR updates CredentialPDFGeneratorService.formatValue to accept alternative map keys for language and value (@language/lang, @value/value) when processing lists of maps, and adds unit tests covering both key variants and multiple locales.

Changes

Cohort / File(s) Summary
Language and Value Key Fallbacks
src/main/java/io/mosip/mimoto/service/CredentialPDFGeneratorService.java
Changed map lookups in formatValue to use getOrDefault() with aliases: check @language then lang for language, and @value then value for value.
Localization Format Tests
src/test/java/io/mosip/mimoto/service/CredentialPDFGeneratorServiceTest.java
Added two unit tests that invoke the private formatValue via reflection to validate handling of lists of maps using @language/@value and language/value keys across locales (en, fr, fil) and edge cases (unmatched/null).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰
A tiny hop to maps that sway,
Keys now listen both night and day,
@language or lang they'll heed,
@value or value fills the need,
Tests applaud the localized way.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: modifying the formatValue function to support alternative language/value key aliases. It directly relates to the primary modification in the changeset.

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

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

Caution

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

⚠️ Outside diff range comments (2)
src/test/java/io/mosip/mimoto/service/CredentialPDFGeneratorServiceTest.java (2)

334-362: ⚠️ Potential issue | 🟡 Minor

Same issue: test uses unsupported "language" key format.

The testGeneratePdfWithLocaleSpecificMapListFormatting test also uses Map.of("language", "en", "value", "English Name") which won't work with the updated formatValue logic.

🔧 Suggested fix
 List<Map<String, Object>> localeData = List.of(
-        Map.of("language", "en", "value", "English Name"),
-        Map.of("language", "fr", "value", "French Name")
+        Map.of("@language", "en", "@value", "English Name"),
+        Map.of("@language", "fr", "@value", "French Name")
 );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/io/mosip/mimoto/service/CredentialPDFGeneratorServiceTest.java`
around lines 334 - 362, The test
testGeneratePdfWithLocaleSpecificMapListFormatting constructs locale maps using
the old "language" key which no longer matches the updated formatValue logic;
update the localeData maps to use the key expected by formatValue (e.g.,
"locale" or the exact key your formatValue reads) — for example replace
Map.of("language", "en", "value", "English Name") with Map.of("locale", "en",
"value", "English Name") (and similarly for "fr"), so the VCCredentialProperties
credentialSubject in the test matches the shape consumed by formatValue used by
credentialPDFGeneratorService.generatePdfForVerifiableCredential.

816-844: ⚠️ Potential issue | 🟡 Minor

Existing test uses unsupported "language" key format.

The testFormatValueWithLocaleMapList test uses Map.of("language", "en", "value", "English Name"), but the production code change now only supports @language and lang keys. This test will pass (due to assertNotNull(result)) but won't actually validate localization behavior—the format will silently return an empty string.

Either update this test to use the new key format, or if the "language" key should remain supported for backward compatibility, ensure the production code handles it.

🔧 Suggested fix to align test with new key format
 List<Map<String, Object>> localeData = List.of(
-        Map.of("language", "en", "value", "English Name"),
-        Map.of("language", "fr", "value", "French Name")
+        Map.of("@language", "en", "@value", "English Name"),
+        Map.of("@language", "fr", "@value", "French Name")
 );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/io/mosip/mimoto/service/CredentialPDFGeneratorServiceTest.java`
around lines 816 - 844, The test testFormatValueWithLocaleMapList uses locale
maps with the old "language" key which the production code no longer recognizes;
update the localeData entries in this test to use the new key (e.g., "@language"
or "lang") and corresponding values (e.g.,
Map.of("@language","en","value","English Name")) so that
credentialPDFGeneratorService.generatePdfForVerifiableCredential and the
formatValue logic will actually select the expected localized string during the
test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/io/mosip/mimoto/service/CredentialPDFGeneratorService.java`:
- Around line 254-261: The locale-matching lambda in
CredentialPDFGeneratorService currently only checks "@language" and "lang" keys,
causing credentials using "language" to be skipped; update the filter to also
check for "language" (i.e., try m.getOrDefault("@language",
m.getOrDefault("lang", m.get("language")))) so LocaleUtils.matchesLocale
receives the correct locale string, and mirror the same fallback in the
subsequent map that extracts "@value"/"value"/"value" keys if needed; verify
behavior against CredentialPDFGeneratorServiceTest and
CredentialShareServiceImpl usages.

---

Outside diff comments:
In
`@src/test/java/io/mosip/mimoto/service/CredentialPDFGeneratorServiceTest.java`:
- Around line 334-362: The test
testGeneratePdfWithLocaleSpecificMapListFormatting constructs locale maps using
the old "language" key which no longer matches the updated formatValue logic;
update the localeData maps to use the key expected by formatValue (e.g.,
"locale" or the exact key your formatValue reads) — for example replace
Map.of("language", "en", "value", "English Name") with Map.of("locale", "en",
"value", "English Name") (and similarly for "fr"), so the VCCredentialProperties
credentialSubject in the test matches the shape consumed by formatValue used by
credentialPDFGeneratorService.generatePdfForVerifiableCredential.
- Around line 816-844: The test testFormatValueWithLocaleMapList uses locale
maps with the old "language" key which the production code no longer recognizes;
update the localeData entries in this test to use the new key (e.g., "@language"
or "lang") and corresponding values (e.g.,
Map.of("@language","en","value","English Name")) so that
credentialPDFGeneratorService.generatePdfForVerifiableCredential and the
formatValue logic will actually select the expected localized string during the
test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6fa22f27-2042-4a0a-8af7-16877ff0c51f

📥 Commits

Reviewing files that changed from the base of the PR and between e753b52 and 890bb38.

📒 Files selected for processing (2)
  • src/main/java/io/mosip/mimoto/service/CredentialPDFGeneratorService.java
  • src/test/java/io/mosip/mimoto/service/CredentialPDFGeneratorServiceTest.java

Signed-off-by: Rudhhi Shah <rudhhi.shah@thoughtworks.com>
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