Skip to content

Constants added and null check#77

Merged
ravishanigarapu merged 2 commits intoPSMRI:developfrom
ravishanigarapu:develop
May 26, 2025
Merged

Constants added and null check#77
ravishanigarapu merged 2 commits intoPSMRI:developfrom
ravishanigarapu:develop

Conversation

@ravishanigarapu
Copy link
Copy Markdown
Contributor

@ravishanigarapu ravishanigarapu commented May 25, 2025

📋 Description

JIRA ID:

Please provide a summary of the change and the motivation behind it. Include relevant context and details.


✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

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

  • Refactor
    • Replaced hardcoded string literals with constants for JWT token, user agent, and client detection to improve maintainability.
    • Centralized header and cookie keys into constants for consistency.
    • Added null check to ensure JWT token header is only included when present.
  • Bug Fixes
    • Updated SQL query to refine record counting by including condition for isFurtherCallRequired.
    • Extended filtering conditions in repository queries to include records requiring further calls or with unset flags.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2025

Walkthrough

String literals for JWT token, user agent, and okhttp identifiers have been centralized into new constants within the Constants class. Corresponding usages in authentication and HTTP utility classes have been updated to reference these constants, and a null check was added before propagating the JWT token header in outgoing requests.

Changes

File(s) Change Summary
src/main/java/com/iemr/ecd/utils/constants/Constants.java Added constants: JWT_TOKEN, USER_AGENT, and OKHTTP.
src/main/java/com/iemr/ecd/utils/mapper/JwtUserIdValidationFilter.java Replaced hardcoded JWT, User-Agent, and okhttp strings with new constants; removed unused variable.
src/main/java/com/iemr/ecd/utils/mapper/RestTemplateUtil.java Replaced hardcoded JWT token header with constant; added null check before adding JWT header.
src/main/java/com/iemr/ecd/repo/call_conf_allocation/MotherRecordRepo.java Updated SQL query in getRecordCount to include t.isFurtherCallRequired condition.
src/main/java/com/iemr/ecd/repo/call_conf_allocation/OutboundCallsRepo.java Added (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL) to count queries.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant JwtUserIdValidationFilter
    participant RestTemplateUtil

    Client->>JwtUserIdValidationFilter: Sends HTTP request with headers/cookies
    JwtUserIdValidationFilter->>JwtUserIdValidationFilter: Reads JWT token and User-Agent using constants
    JwtUserIdValidationFilter->>RestTemplateUtil: Forwards request details
    RestTemplateUtil->>RestTemplateUtil: Checks for JWT token header (using constant)
    RestTemplateUtil->>Client: Forwards request (if JWT token present, adds header)
Loading

Possibly related PRs

  • PSMRI/ECD-API#76: The main PR refactors string literals into constants and updates query conditions to include t.isFurtherCallRequired checks, which are directly related to the query modifications in the retrieved PR.
  • PSMRI/ECD-API#74: The main PR updates string constants and refactors header and query conditions related to isFurtherCallRequired, similar to the retrieved PR which modifies query methods to include AND t.isFurtherCallRequired != 0.
  • PSMRI/ECD-API#71: The changes involve centralizing string constants and updating related code to use these constants, related to modifications in the OutboundCallsRepo interface that add filters based on isFurtherCallRequired.

Suggested reviewers

  • devikasuresh20

Poem

Three constants now in one safe place,
No more strings lost in code’s embrace.
JWT and User-Agent, okhttp too,
All centralized—tidy and new!
A hop, a skip, a bunny cheer,
For code that’s cleaner year by year!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link
Copy Markdown

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19c2552 and 7f29081.

📒 Files selected for processing (3)
  • src/main/java/com/iemr/ecd/utils/constants/Constants.java (1 hunks)
  • src/main/java/com/iemr/ecd/utils/mapper/JwtUserIdValidationFilter.java (4 hunks)
  • src/main/java/com/iemr/ecd/utils/mapper/RestTemplateUtil.java (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/main/java/com/iemr/ecd/utils/mapper/RestTemplateUtil.java (1)
src/main/java/com/iemr/ecd/utils/constants/Constants.java (1)
  • Constants (5-24)
src/main/java/com/iemr/ecd/utils/mapper/JwtUserIdValidationFilter.java (1)
src/main/java/com/iemr/ecd/utils/constants/Constants.java (1)
  • Constants (5-24)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)
🔇 Additional comments (8)
src/main/java/com/iemr/ecd/utils/constants/Constants.java (1)

19-21: LGTM! Constants properly defined.

The new constants are well-defined and follow proper naming conventions. Centralizing these string literals improves maintainability and reduces the risk of typos in header and cookie name usage across the codebase.

src/main/java/com/iemr/ecd/utils/mapper/RestTemplateUtil.java (2)

13-13: LGTM! Import added for constants.

Good addition of the Constants import to support the refactoring to use centralized string literals.


44-46: Excellent defensive programming with null check.

The null check before adding the JWT token header is a good practice that prevents potential issues with null header values. The use of Constants.JWT_TOKEN also improves maintainability.

src/main/java/com/iemr/ecd/utils/mapper/JwtUserIdValidationFilter.java (5)

9-9: LGTM! Import added for constants.

Good addition of the Constants import to support the refactoring effort.


71-71: Good refactoring to use constant.

Replacing the hardcoded "JwtToken" string with Constants.JWT_TOKEN improves maintainability and consistency.


91-91: Good refactoring to use constant.

Replacing the hardcoded "User-Agent" string with Constants.USER_AGENT improves maintainability and consistency.


116-116: Good refactoring to use constant.

Replacing the hardcoded "okhttp" string with Constants.OKHTTP improves maintainability and consistency for mobile client detection.


122-122: Good refactoring to use constant.

Replacing the hardcoded cookie name with Constants.JWT_TOKEN ensures consistency between header and cookie name usage throughout the application.

headers.add(Constants.JWT_TOKEN,requestHeader.getHeader(Constants.JWT_TOKEN));
}
if(null != jwtTokenFromCookie) {
headers.add(HttpHeaders.COOKIE, "Jwttoken=" + jwtTokenFromCookie);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix inconsistent string literal usage.

Line 48 still uses a hardcoded string "Jwttoken=" instead of using the constant. For consistency with the refactoring effort, this should use the constant as well.

Apply this diff to maintain consistency:

-        	headers.add(HttpHeaders.COOKIE, "Jwttoken=" + jwtTokenFromCookie);
+        	headers.add(HttpHeaders.COOKIE, Constants.JWT_TOKEN + "=" + jwtTokenFromCookie);
📝 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.

Suggested change
headers.add(HttpHeaders.COOKIE, "Jwttoken=" + jwtTokenFromCookie);
headers.add(HttpHeaders.COOKIE, Constants.JWT_TOKEN + "=" + jwtTokenFromCookie);
🤖 Prompt for AI Agents
In src/main/java/com/iemr/ecd/utils/mapper/RestTemplateUtil.java at line 48,
replace the hardcoded string "Jwttoken=" with the appropriate constant defined
for this token to maintain consistency with the rest of the code. Identify the
constant representing the JWT token prefix and use it in the headers.add method
instead of the literal string.

@ravishanigarapu ravishanigarapu merged commit 320389c into PSMRI:develop May 26, 2025
5 checks passed
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

🔭 Outside diff range comments (2)
src/main/java/com/iemr/ecd/repo/call_conf_allocation/OutboundCallsRepo.java (2)

95-124: 🛠️ Refactor suggestion

Apply the isFurtherCallRequired condition consistently across all unallocated count queries.

The changes correctly add the isFurtherCallRequired filtering condition to mother-related count queries. However, there's an inconsistency issue:

  1. Child-related count queries (getChildUnAllocatedCountLR at line 106 and getChildUnAllocatedCountHR at line 121) do not have this condition
  2. Language-specific mother count query (getMotherUnAllocatedCountLRByLanguage at line 346) also lacks this condition

This inconsistency could lead to mismatched counts between different query methods.

Consider applying the same filtering logic to maintain consistency:

 // un-allocated, child low risk,
 @Query(value = " SELECT COUNT(1) FROM OutboundCalls AS t WHERE t.allocationStatus =:allocationStatus AND "
         + " t.psmId=:psmId AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND "
         + " t.childId IS NOT NULL AND (t.isHrni = false OR t.isHrni IS NULL )  "
-        + " AND t.phoneNumberType=:phoneNoType AND t.deleted = false ")
+        + " AND t.phoneNumberType=:phoneNoType AND t.deleted = false AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL ) ")
 int getChildUnAllocatedCountLR(@Param("allocationStatus") String allocationStatus, @Param("psmId") Integer psmId,
         @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("phoneNoType") String phoneNoType);

 // un-allocated, child high risk,
 @Query(value = " SELECT COUNT(1) FROM OutboundCalls AS t WHERE t.allocationStatus =:allocationStatus AND "
         + " t.psmId=:psmId AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND "
-        + " t.childId IS NOT NULL AND t.isHrni = true  " + " AND t.phoneNumberType=:phoneNoType AND t.deleted = false ")
+        + " t.childId IS NOT NULL AND t.isHrni = true  " + " AND t.phoneNumberType=:phoneNoType AND t.deleted = false AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL )")
 int getChildUnAllocatedCountHR(@Param("allocationStatus") String allocationStatus, @Param("psmId") Integer psmId,
         @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("phoneNoType") String phoneNoType);

342-355: 🛠️ Refactor suggestion

Add the isFurtherCallRequired condition to language-specific count queries.

The language-specific count queries should also include the isFurtherCallRequired filtering condition for consistency with the updated non-language-specific queries.

Apply this diff to maintain consistency:

 @Query(value = " SELECT COUNT(1) FROM OutboundCalls AS t INNER JOIN MotherRecord AS mv ON t.motherId = mv.ecdIdNo WHERE t.allocationStatus =:allocationStatus AND "
         + " t.psmId=:psmId AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND "
         + " t.childId IS NULL AND t.motherId IS NOT NULL  AND (t.isHighRisk = false OR t.isHighRisk IS NULL ) "
-        + " AND t.phoneNumberType=:phoneNoType AND t.deleted = false AND mv.preferredLanguage = :preferredLanguage ")
+        + " AND t.phoneNumberType=:phoneNoType AND t.deleted = false AND mv.preferredLanguage = :preferredLanguage AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL ) ")
 int getMotherUnAllocatedCountLRByLanguage(@Param("allocationStatus") String allocationStatus, @Param("psmId") Integer psmId,
         @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("phoneNoType") String phoneNoType, @Param("preferredLanguage") String preferredLanguage);

 // un-allocated, child low risk,
 @Query(value = " SELECT COUNT(1) FROM OutboundCalls AS t INNER JOIN ChildRecord AS cv ON t.childId = cv.ecdIdNoChildId WHERE t.allocationStatus =:allocationStatus AND "
         + " t.psmId=:psmId AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND "
         + " t.childId IS NOT NULL AND (t.isHrni = false OR t.isHrni IS NULL )  "
-        + " AND t.phoneNumberType=:phoneNoType AND t.deleted = false AND cv.preferredLanguage = :preferredLanguage")
+        + " AND t.phoneNumberType=:phoneNoType AND t.deleted = false AND cv.preferredLanguage = :preferredLanguage AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL )")
 int getChildUnAllocatedCountLRByLanguage(@Param("allocationStatus") String allocationStatus, @Param("psmId") Integer psmId,
         @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("phoneNoType") String phoneNoType, @Param("preferredLanguage") String preferredLanguage);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f29081 and 354bd53.

📒 Files selected for processing (2)
  • src/main/java/com/iemr/ecd/repo/call_conf_allocation/MotherRecordRepo.java (1 hunks)
  • src/main/java/com/iemr/ecd/repo/call_conf_allocation/OutboundCallsRepo.java (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)
🔇 Additional comments (1)
src/main/java/com/iemr/ecd/repo/call_conf_allocation/MotherRecordRepo.java (1)

1-116: ⚠️ Potential issue

Critical: File changes don't match PR objectives

The PR is titled "Constants added and null check" and the AI summary mentions JWT token constants and HTTP utility updates, but this file contains only a database query modification for mother records. This appears to be either:

  • An incorrect file included in the PR
  • An incorrect PR title/description
  • A merge issue

Please clarify the intended changes for this PR.

Likely an incorrect or invalid review comment.

Comment on lines 66 to 69
@Query(value = " SELECT COUNT(1) FROM MotherRecord as t WHERE t.isAllocated=:isAllocated AND "
+ " t.createdDate >=:fDate AND t.createdDate <=:tDate AND t.whomPhoneNo=:whomPhoneNo ")
+ " t.createdDate >=:fDate AND t.createdDate <=:tDate AND t.whomPhoneNo=:whomPhoneNo AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL ) ")
public int getRecordCount(@Param("isAllocated") Boolean isAllocated, @Param("fDate") Timestamp fDate,
@Param("tDate") Timestamp tDate, @Param("whomPhoneNo") String whomPhoneNo);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify the business logic change for record filtering

The query modification adds filtering for isFurtherCallRequired field, excluding records where this flag is explicitly set to false. While the syntax is correct, please ensure:

  1. This business logic change is intended and documented
  2. All consumers of getRecordCount method are aware of this behavioral change
  3. This aligns with similar filtering in other repository methods

Run the following script to verify consistent filtering across related repositories:


🏁 Script executed:

#!/bin/bash
# Description: Check if similar isFurtherCallRequired filtering is applied consistently across other repository methods

# Search for other queries with isFurtherCallRequired conditions
rg -A 3 -B 3 "isFurtherCallRequired" --type java

# Search for other uses of getRecordCount to understand impact
ast-grep --pattern 'getRecordCount($$$)'

Length of output: 24457


Review update: Filter consistency verified
The added filter for isFurtherCallRequired in MotherRecordRepo#getRecordCount matches the same condition used throughout OutboundCallsRepo, so the technical change is correct.

Please address the following:

  • Document this business logic change (that records with isFurtherCallRequired = false are now excluded) in your API/repo documentation.
  • Communicate the updated behavior to all consumers of getRecordCount.

Affected location:

  • src/main/java/com/iemr/ecd/repo/call_conf_allocation/MotherRecordRepo.java (lines 66–69)
🤖 Prompt for AI Agents
In src/main/java/com/iemr/ecd/repo/call_conf_allocation/MotherRecordRepo.java
between lines 66 and 69, the query now filters records where
isFurtherCallRequired is true or null, excluding false values. This change
affects the business logic by omitting records with isFurtherCallRequired set to
false. Add documentation to clarify that getRecordCount now only counts records
with isFurtherCallRequired true or null, and ensure all consumers are aware of
this behavioral change to prevent misunderstandings.

@coderabbitai coderabbitai Bot mentioned this pull request May 26, 2025
10 tasks
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