AMM-1206 : In closure screen language is not showing in the preferred language list#55
Conversation
WalkthroughThe pull request introduces enhancements to the call closure and record allocation functionality in the ECD (Early Childhood Development) system. New methods are added to repository interfaces for updating the allocation status of child and mother records. In the Changes
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (4)
280-298: Consider enhancing error handling in updatePreferredLanguage.The method effectively handles both mother and child records. Consider adding error logging for failed updates to help with troubleshooting.
private void updatePreferredLanguage(CallClosureDTO request,OutboundCalls callObj,boolean isLanguageMapped) { if (null != request.getPreferredLanguage()) { boolean isMother = callObj.getMotherId() != null; boolean isChild = callObj.getChildId() != null; if (isMother && !isChild) { + try { motherRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getMotherId()); if (!isLanguageMapped) { motherRecordRepo.updateAllocatedStatus(false, callObj.getMotherId()); } + } catch (Exception e) { + logger.error("Failed to update mother's preferred language: " + callObj.getMotherId(), e); + throw new ECDException("Failed to update mother's preferred language", e); + } } if (isChild) { + try { childRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getChildId()); if (!isLanguageMapped) { childRecordRepo.updateAllocatedStatus(false, callObj.getChildId()); } + } catch (Exception e) { + logger.error("Failed to update child's preferred language: " + callObj.getChildId(), e); + throw new ECDException("Failed to update child's preferred language", e); + } } } }
280-298: Consider enhancing error handling and logging.While the logic is correct, consider adding:
- Logging statements for debugging language mapping updates
- Error handling for database operations
private void updatePreferredLanguage(CallClosureDTO request,OutboundCalls callObj,boolean isLanguageMapped) { + logger.debug("Updating preferred language for request: {}", request); if (null != request.getPreferredLanguage()) { boolean isMother = callObj.getMotherId() != null; boolean isChild = callObj.getChildId() != null; if (isMother && !isChild) { + try { motherRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getMotherId()); if (!isLanguageMapped) { motherRecordRepo.updateAllocatedStatus(false, callObj.getMotherId()); } + logger.info("Successfully updated mother record language preferences for motherId: {}", callObj.getMotherId()); + } catch (Exception e) { + logger.error("Failed to update mother record language preferences for motherId: {}", callObj.getMotherId(), e); + throw new ECDException("Failed to update mother record language preferences", e); + } } if (isChild) { + try { childRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getChildId()); if (!isLanguageMapped) { childRecordRepo.updateAllocatedStatus(false, callObj.getChildId()); } + logger.info("Successfully updated child record language preferences for childId: {}", callObj.getChildId()); + } catch (Exception e) { + logger.error("Failed to update child record language preferences for childId: {}", callObj.getChildId(), e); + throw new ECDException("Failed to update child record language preferences", e); + } } } }
280-298: Consider adding error handling for database operations.While the method is well-structured and handles both mother and child records appropriately, it should include try-catch blocks for database operations to handle potential failures gracefully.
private void updatePreferredLanguage(CallClosureDTO request,OutboundCalls callObj,boolean isLanguageMapped) { if (null != request.getPreferredLanguage()) { boolean isMother = callObj.getMotherId() != null; boolean isChild = callObj.getChildId() != null; + try { if (isMother && !isChild) { motherRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getMotherId()); if (!isLanguageMapped) { motherRecordRepo.updateAllocatedStatus(false, callObj.getMotherId()); } } if (isChild) { childRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getChildId()); if (!isLanguageMapped) { childRecordRepo.updateAllocatedStatus(false, callObj.getChildId()); } } + } catch (Exception e) { + logger.error("Failed to update preferred language", e); + throw new ECDException("Failed to update preferred language: " + e.getMessage()); + } } }
300-313: Consider caching language mappings for better performance.The method makes a database call to retrieve language mappings on every call closure. Consider caching the language mappings at the user level to reduce database load.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/java/com/iemr/ecd/repo/call_conf_allocation/ChildRecordRepo.java(1 hunks)src/main/java/com/iemr/ecd/repo/call_conf_allocation/MotherRecordRepo.java(1 hunks)src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java(6 hunks)
👮 Files not reviewed due to content moderation or server errors (2)
- src/main/java/com/iemr/ecd/repo/call_conf_allocation/ChildRecordRepo.java
- src/main/java/com/iemr/ecd/repo/call_conf_allocation/MotherRecordRepo.java
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Analyze (java)
- GitHub Check: Package-test
🔇 Additional comments (5)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (5)
148-148: LGTM! Language mapping check is well integrated.The language mapping verification is properly integrated into the call closure flow, with appropriate updates to the allocation status.
Also applies to: 210-213
300-313: LGTM! Robust language mapping verification.The method effectively verifies user's language mappings with proper null checks using
ObjectUtils.isEmpty.
210-213: LGTM! Language mapping check is well integrated.The code properly checks if the user has the required language mapping and updates the allocation status accordingly.
300-313: LGTM! Well-structured language mapping check.The method effectively retrieves and validates user language mappings using null-safe collection checks.
148-148: LGTM! Language mapping check is well integrated.The code properly handles language mapping verification and updates the allocation status accordingly.
Also applies to: 210-213
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/main/environment/ecd_ci.properties(1 hunks)src/main/environment/ecd_dev.properties(1 hunks)src/main/environment/ecd_test.properties(1 hunks)src/main/environment/ecd_uat.properties(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (java)
🔇 Additional comments (3)
src/main/environment/ecd_ci.properties (1)
22-23: LGTM! Appropriate configuration for CI environment.Disabling Swagger UI and API docs in CI environment aligns with security best practices.
src/main/environment/ecd_test.properties (1)
19-20: LGTM! Appropriate configuration for test environment.Enabling Swagger UI and API docs in test environment facilitates API testing and documentation.
src/main/environment/ecd_dev.properties (1)
19-20: LGTM! Appropriate configuration for dev environment.Enabling Swagger UI and API docs in dev environment supports development workflow.
| springdoc.api-docs.enabled=true | ||
| springdoc.swagger-ui.enabled=true No newline at end of file |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Consider disabling Swagger UI in UAT environment.
UAT environment should mirror production configuration. Enabling Swagger UI and API docs in UAT might pose security risks.
Apply this diff to align with production security practices:
-springdoc.api-docs.enabled=true
-springdoc.swagger-ui.enabled=true
+springdoc.api-docs.enabled=false
+springdoc.swagger-ui.enabled=false📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| springdoc.api-docs.enabled=true | |
| springdoc.swagger-ui.enabled=true | |
| springdoc.api-docs.enabled=false | |
| springdoc.swagger-ui.enabled=false |
There was a problem hiding this comment.
@coderabbitai we need to enable swagger in all the lower environments so we need to keep it as TRUE
There was a problem hiding this comment.
@ravishanigarapu Understood, I'll note this requirement about keeping Swagger UI enabled in all lower environments. Thank you for the clarification.
✏️ Learnings added
Learnt from: ravishanigarapu
PR: PSMRI/ECD-API#55
File: src/main/environment/ecd_uat.properties:19-20
Timestamp: 2025-01-22T12:20:25.594Z
Learning: In the ECD-API project, Swagger UI and API docs should be enabled (set to true) in all lower environments (DEV, TEST, UAT) to facilitate API testing and documentation. Only the production environment should have these disabled.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (3)
148-148: Consider using constants for status values.The logic for handling unmapped languages is correct, but consider extracting the magic strings into constants for better maintainability.
- callObj.setCallStatus(Constants.OPEN); - callObj.setCallAttemptNo(0); - callObj.setAllocationStatus(Constants.UNALLOCATED); + callObj.setCallStatus(Constants.CALL_STATUS_OPEN); + callObj.setCallAttemptNo(Constants.INITIAL_CALL_ATTEMPT); + callObj.setAllocationStatus(Constants.ALLOCATION_STATUS_UNALLOCATED);Also applies to: 210-216
284-302: Consider more descriptive boolean variable names.The method logic is clear, but the boolean variables could be more descriptive for better readability.
- boolean isMother = callObj.getMotherId() != null; - boolean isChild = callObj.getChildId() != null; + boolean hasMotherRecord = callObj.getMotherId() != null; + boolean hasChildRecord = callObj.getChildId() != null;
304-317: Consider using early return pattern for better readability.The method can be simplified using the early return pattern.
private boolean isLanguageMappedWithUser(CallClosureDTO request) { - boolean isLanguageMapped = false; Integer userId = request.getUserId(); List<String> language = new ArrayList<>(); List<V_GetUserlangmapping> languageByUserId = masterServiceImpl.getLanguageByUserId(userId); for (V_GetUserlangmapping v_GetUserlangmapping : languageByUserId) { String languageName = v_GetUserlangmapping.getLanguageName(); language.add(languageName); } - if(!ObjectUtils.isEmpty(language)) { - isLanguageMapped = language.contains(request.getPreferredLanguage()); - } - return isLanguageMapped; + if(ObjectUtils.isEmpty(language)) { + return false; + } + return language.contains(request.getPreferredLanguage()); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java(6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (java)
🔇 Additional comments (2)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (2)
37-37: LGTM! Dependencies are properly configured.The new imports and autowired field for MasterServiceImpl are correctly added.
Also applies to: 45-45, 52-52, 79-81
264-265: Verify error handling for updatePreferredLanguage.The method is called without try-catch. Consider adding error handling to prevent potential runtime exceptions.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (1)
305-318: Improve isLanguageMappedWithUser using Java 8 Stream API.The method can be simplified and made more robust with proper null checks and Stream API.
private boolean isLanguageMappedWithUser(CallClosureDTO request) { - boolean isLanguageMapped = false; Integer userId = request.getUserId(); - List<String> language = new ArrayList<>(); + if (userId == null) { + return false; + } + + String preferredLanguage = request.getPreferredLanguage(); + if (preferredLanguage == null || preferredLanguage.trim().isEmpty()) { + return false; + } + List<V_GetUserlangmapping> languageByUserId = masterServiceImpl.getLanguageByUserId(userId); - for (V_GetUserlangmapping v_GetUserlangmapping : languageByUserId) { - String languageName = v_GetUserlangmapping.getLanguageName(); - language.add(languageName); - } - if(!ObjectUtils.isEmpty(language)) { - isLanguageMapped = language.contains(request.getPreferredLanguage()); - } - return isLanguageMapped; + return !ObjectUtils.isEmpty(languageByUserId) && + languageByUserId.stream() + .map(V_GetUserlangmapping::getLanguageName) + .anyMatch(lang -> lang.equals(preferredLanguage)); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java(6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (java)
🔇 Additional comments (2)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (2)
37-37: LGTM! Dependencies are properly imported and autowired.The new imports and autowired field are correctly added to support the language mapping functionality.
Also applies to: 45-45, 52-52, 79-81
148-148: LGTM! Language mapping validation is properly implemented.The code correctly handles cases where the user's preferred language is not mapped:
- For introductory calls, it:
- Sets the call status to "OPEN"
- Resets the call attempt counter
- Updates the allocation status to "UNALLOCATED"
- This ensures that calls are properly reallocated when language preferences don't match.
Also applies to: 210-217
| private void updatePreferredLanguage(CallClosureDTO request,OutboundCalls callObj,boolean isLanguageMapped) { | ||
| if (null != request.getPreferredLanguage()) { | ||
| boolean isMother = callObj.getMotherId() != null; | ||
| boolean isChild = callObj.getChildId() != null; | ||
|
|
||
| if (isMother && !isChild) { | ||
| motherRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getMotherId()); | ||
| if (!isLanguageMapped) { | ||
| motherRecordRepo.updateAllocatedStatus(false, callObj.getMotherId()); | ||
| } | ||
| } | ||
| if (isChild) { | ||
| childRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getChildId()); | ||
| if (!isLanguageMapped) { | ||
| childRecordRepo.updateAllocatedStatus(false, callObj.getChildId()); | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Enhance error handling and null checks in updatePreferredLanguage.
- Add null checks for request.getPreferredLanguage()
- Wrap database operations in try-catch blocks
private void updatePreferredLanguage(CallClosureDTO request,OutboundCalls callObj,boolean isLanguageMapped) {
- if (null != request.getPreferredLanguage()) {
+ String preferredLanguage = request.getPreferredLanguage();
+ if (preferredLanguage == null || preferredLanguage.trim().isEmpty()) {
+ return;
+ }
boolean isMother = callObj.getMotherId() != null;
boolean isChild = callObj.getChildId() != null;
if (isMother && !isChild) {
+ try {
- motherRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getMotherId());
+ motherRecordRepo.updatePreferredLanguage(preferredLanguage, callObj.getMotherId());
if (!isLanguageMapped) {
motherRecordRepo.updateAllocatedStatus(false, callObj.getMotherId());
}
+ } catch (Exception e) {
+ logger.error("Failed to update mother's preferred language", e);
+ throw new ECDException("Failed to update mother's preferred language: " + e.getMessage());
+ }
}
if (isChild) {
+ try {
- childRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getChildId());
+ childRecordRepo.updatePreferredLanguage(preferredLanguage, callObj.getChildId());
if (!isLanguageMapped) {
childRecordRepo.updateAllocatedStatus(false, callObj.getChildId());
}
+ } catch (Exception e) {
+ logger.error("Failed to update child's preferred language", e);
+ throw new ECDException("Failed to update child's preferred language: " + e.getMessage());
+ }
}
- }
}Committable suggestion skipped: line range outside the PR's diff.
| updatePreferredLanguage(request,callObj,isLanguageMapped); | ||
|
|
There was a problem hiding this comment.
💡 Codebase verification
Add error handling for database operations in updatePreferredLanguage
The method makes database calls through repository methods that should be protected with error handling, following the established patterns in the codebase. The suggested try-catch implementation is appropriate as it:
- Matches the error handling pattern used for similar database operations in the file
- Uses the existing ECDException class for error propagation
- Includes proper error logging
🔗 Analysis chain
Verify error handling for updatePreferredLanguage.
The method call should be wrapped in a try-catch block to handle potential database errors when updating the preferred language.
-updatePreferredLanguage(request,callObj,isLanguageMapped);
+try {
+ updatePreferredLanguage(request,callObj,isLanguageMapped);
+} catch (Exception e) {
+ logger.error("Failed to update preferred language", e);
+ throw new ECDException("Failed to update preferred language: " + e.getMessage());
+}🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash
# Find updatePreferredLanguage method implementation
echo "=== Searching for updatePreferredLanguage method ==="
ast-grep --pattern 'private $_ updatePreferredLanguage($$$) { $$$ }'
# Look for similar method calls with try-catch blocks in the same file
echo -e "\n=== Checking error handling patterns in CallClosureImpl.java ==="
rg "try\s*\{" "src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java" -A 5
# Verify ECDException exists
echo -e "\n=== Checking for ECDException class ==="
fd "ECDException.java"
Length of output: 3997
|



📋 Description
JIRA ID: AMM-1206
In closure screen language is not showing in the preferred language list.
✅ Type of Change
ℹ️ Additional Information
Please describe how the changes were tested, and include any relevant screenshots, logs, or other information that provides additional context.
Summary by CodeRabbit
Release Notes
New Features
Improvements
Documentation Updates