Skip to content

Null check#79

Closed
ravishanigarapu wants to merge 0 commit intoPSMRI:developfrom
ravishanigarapu:develop
Closed

Null check#79
ravishanigarapu wants to merge 0 commit intoPSMRI:developfrom
ravishanigarapu:develop

Conversation

@ravishanigarapu
Copy link
Copy Markdown
Contributor

@ravishanigarapu ravishanigarapu commented May 26, 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

  • New Features
    • Added support for filtering unallocated mother and child record counts by preferred language.
    • Introduced new constants for JWT token, user agent, and HTTP client identification.
  • Bug Fixes
    • Improved handling of JWT token headers to prevent issues when the header is absent.
  • Refactor
    • Replaced hardcoded string literals with constants for better maintainability and consistency.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2025

Walkthrough

This update introduces language-specific filtering to certain count queries in the repository layer, adds new string constants for JWT and user-agent headers, and refactors usages of these literals to use the new constants. Additionally, it improves query formatting and adds null checks before adding JWT headers in HTTP utilities.

Changes

File(s) Change Summary
.../repo/call_conf_allocation/MotherRecordRepo.java Refined JPQL query formatting in getRecordCount to remove trailing whitespace.
.../repo/call_conf_allocation/OutboundCallsRepo.java Added language-filtered count queries and corresponding methods for mother and child records.
.../utils/constants/Constants.java Added new constants: JWT_TOKEN, USER_AGENT, and OKHTTP.
.../utils/mapper/JwtUserIdValidationFilter.java Refactored to use new constants for JWT token, user-agent, and okhttp string literals.
.../utils/mapper/RestTemplateUtil.java Replaced hardcoded JWT header with constant and added null check before adding JWT header to requests.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RestTemplateUtil
    participant HttpHeaders

    Client->>RestTemplateUtil: createRequestEntity(body, authorization)
    RestTemplateUtil->>HttpHeaders: Add Authorization header (if present)
    RestTemplateUtil->>HttpHeaders: Add User-Agent header via Constants.USER_AGENT
    RestTemplateUtil->>HttpHeaders: Check for JWT token header via Constants.JWT_TOKEN
    alt JWT token header present
        RestTemplateUtil->>HttpHeaders: Add JWT token header
    end
    RestTemplateUtil-->>Client: Return HttpEntity with headers and body
Loading

Possibly related PRs

  • PSMRI/ECD-API#44: Updates query formatting and adds language-specific filtering in repository and service methods, directly related to new language-filtered queries here.
  • PSMRI/ECD-API#77: Adds constants for JWT tokens and headers, and refactors usages, closely matching the changes in this PR.
  • PSMRI/ECD-API#65: Adds support for filtering by preferred language in repository and service methods, similar to the new query logic in this update.

Suggested reviewers

  • devikasuresh20

Poem

Hopping through the code with glee,
New constants set our headers free!
Queries now speak in every tongue,
JWT and agents neatly strung.
With language filters in the mix,
Our repo’s logic’s up to new tricks.
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 320389c and 59a23b9.

📒 Files selected for processing (5)
  • 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)
  • 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 comments (6)
src/main/java/com/iemr/ecd/utils/constants/Constants.java (1)

19-21: PR title doesn't match the changes

The PR is titled "Null check" but these changes add new constants without any null checking logic. Consider updating the PR title to accurately reflect the changes, such as "Refactor string literals to constants and add null checks".

Additionally, I notice the constant JWT_TOKEN has a value of "Jwttoken" with mixed casing. Please verify this is the expected casing for your JWT header/cookie name.

Likely an incorrect or invalid review comment.

src/main/java/com/iemr/ecd/repo/call_conf_allocation/MotherRecordRepo.java (1)

66-69: Good formatting cleanup

Removing the trailing space improves code consistency.

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

9-9: Good refactoring to use constants

Excellent work replacing magic strings with constants. This improves maintainability and reduces the risk of typos.

Also applies to: 71-71, 91-91, 116-116, 122-122


71-71:

Details

✅ Verification successful

Potential breaking change: Header name casing changed

The original code used "JwtToken" (with capital T) for the header name, but the constant Constants.JWT_TOKEN has value "Jwttoken" (lowercase t). This change in casing could break existing API clients that send the header with the original casing.

Please verify if HTTP header names are case-insensitive in your application server. If they are case-sensitive, this could be a breaking change.


🏁 Script executed:

#!/bin/bash
# Search for any other usages of JwtToken header to understand the expected casing
rg -i "jwttoken" --type java -A 3 -B 3

Length of output: 10048


Header names are case-insensitive – no action needed

HTTP header field names are defined as case-insensitive by RFC 7230, and HttpServletRequest.getHeader() treats names without regard to case. Since all header lookups use Constants.JWT_TOKEN ("Jwttoken"), changing the casing of the literal has no impact on clients or the servlet container.

– No other occurrences of a differently-cased header literal were found
– Cookie names are handled separately (and already match "Jwttoken")

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

44-46: Good defensive programming practice!

The null check before adding the JWT token header prevents potential issues with null header values and aligns with the proper use of constants.

src/main/java/com/iemr/ecd/repo/call_conf_allocation/OutboundCallsRepo.java (1)

350-355:

Details

✅ Verification successful

Verify the join field name for ChildRecord

The query joins using t.childId = cv.ecdIdNoChildId. Please ensure that ecdIdNoChildId is the correct field name in the ChildRecord entity for joining with the childId from OutboundCalls.

Run the following script to verify the field name:


🏁 Script executed:

#!/bin/bash
# Description: Verify the ChildRecord entity has the field ecdIdNoChildId

# Search for ChildRecord class definition and check for the field
ast-grep --pattern 'class ChildRecord {
  $$$
}'

Length of output: 50


To locate and inspect the ChildRecord entity definition and verify the ecdIdNoChildId field, let’s search for the class and then for that specific field:


🏁 Script executed:

#!/bin/bash
# 1. Find where ChildRecord is defined
rg -n "class ChildRecord"

# 2. Search for the ecdIdNoChildId field declaration
rg -n "ecdIdNoChildId"

Length of output: 4194


Join field verified: ChildRecord.ecdIdNoChildId exists and is used correctly

Confirmed that the ChildRecord entity declares the ecdIdNoChildId field (see src/main/java/com/iemr/ecd/dao/associate/ChildRecord.java:55), and all repository queries join on this field as intended. No further changes needed.

✨ 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

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