Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ABHA - Address Search API changes #56

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

helenKaryamsetty
Copy link
Member

@helenKaryamsetty helenKaryamsetty commented Dec 13, 2024

πŸ“‹ 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

    • Introduced new web login functionality for the ABHA API, including endpoints for requesting and verifying OTPs.
  • Bug Fixes

    • Updated formatting for the abdmVerifyOTP property to ensure proper URL structure.
  • Documentation

    • Added new configuration properties for web login in various environment files, enhancing clarity on API endpoints.

Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

Walkthrough

The changes in this pull request involve the addition of new properties related to web login functionality for the ABHA API across multiple configuration files. Specifically, two new properties, webLoginAbhaRequestOtp and webLoginAbhaVerify, have been introduced to facilitate OTP requests and verifications for web-based logins. Additionally, the LoginAbhaV3ServiceImpl class has been updated to utilize these new properties, enhancing the handling of different login methods and conditions.

Changes

File Path Change Summary
src/main/environment/common_ci.properties - Added webLoginAbhaRequestOtp and webLoginAbhaVerify properties for web login functionality.
src/main/environment/common_dev.properties - Added webLoginAbhaRequestOtp and webLoginAbhaVerify properties for web login functionality.
src/main/environment/common_example.properties - Added webLoginAbhaRequestOtp and webLoginAbhaVerify properties.
- Updated abdmVerifyOTP to remove extra space.
src/main/environment/common_test.properties - Added webLoginAbhaRequestOtp and webLoginAbhaVerify properties for web login functionality.
src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java - Introduced new properties webLoginAbhaRequestOtp and webLoginAbhaVerify.
- Updated methods to utilize new endpoints based on login methods.

Possibly related PRs

  • Abdm M1 V3 ChangesΒ #52: The changes in this PR involve adding new properties for web login functionality in the ABHA API, which directly relates to the new properties added in the main PR for web login operations.
  • Modified tnxId keyword to txnIdΒ #55: This PR modifies the variable name from tnxId to txnId, which is relevant as the main PR introduces new properties that may interact with these identifiers in the context of login operations.

Suggested reviewers

  • ravishanigarapu

Poem

🐰 In the world of code, where logins abound,
New paths for access, we’ve finally found.
With OTPs flying, and properties new,
Web logins are ready, for me and for you!
Hopping through changes, with joy we declare,
ABHA’s bright future, we’re all set to share! 🌟


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?

❀️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Experiment)
  • @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.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
38.9% Duplication on New Code (required ≀ 3%)

See analysis details on SonarQube Cloud

Copy link
Contributor

@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: 3

🧹 Outside diff range and nitpick comments (3)
src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java (3)

Line range hint 99-125: Fix incorrect conditions in if-else blocks

There are redundant or incorrect conditions in the if-else statements:

  • At line 115, the condition compares loginMethod with itself:

    } else if ("mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod())) {

    This should compare loginMethod with loginHint.

  • Similarly, at line 119, the condition repeats the same comparison with "aadhaar":

    } else if ("aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod())) {

Apply the following diff to correct the conditions:

- } else if ("mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod())) {
+ } else if ("mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "mobile".equalsIgnoreCase(loginAbhaRequest.getLoginHint())) {

...
- } else if ("aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod())) {
+ } else if ("aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginHint())) {

Line range hint 99-125: Consider refactoring conditional statements for maintainability

The series of if-else conditions can be simplified to reduce redundancy and improve readability. Consider mapping the combinations of loginMethod and loginHint to their corresponding configurations.

For example, using a Map<Pair<String, String>, Configuration> can streamline the logic.


Line range hint 74-225: Input validation for loginId in requestOtpForAbhaLogin and verifyAbhaLogin

Based on previous learnings, loginId is mandatory, but the process can proceed even if it is null due to lack of input validation. This could lead to unexpected behavior or errors.

Add input validation to ensure loginId is not null or empty before proceeding.

πŸ“œ Review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between a9624ae and 08f485f.

πŸ“’ Files selected for processing (5)
  • src/main/environment/common_ci.properties (1 hunks)
  • src/main/environment/common_dev.properties (1 hunks)
  • src/main/environment/common_example.properties (1 hunks)
  • src/main/environment/common_test.properties (1 hunks)
  • src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java (6 hunks)
🧰 Additional context used
πŸ““ Learnings (3)
src/main/environment/common_test.properties (1)
Learnt from: helenKaryamsetty
PR: PSMRI/FHIR-API#52
File: src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java:84-91
Timestamp: 2024-12-09T16:01:39.809Z
Learning: In the `requestOtpForAbhaLogin` and `verifyAbhaLogin` methods of `LoginAbhaV3ServiceImpl.java`, `loginId` is mandatory, but even if it is null, the process can proceed without input validation.
src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java (1)
Learnt from: helenKaryamsetty
PR: PSMRI/FHIR-API#52
File: src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java:84-91
Timestamp: 2024-12-09T16:01:39.809Z
Learning: In the `requestOtpForAbhaLogin` and `verifyAbhaLogin` methods of `LoginAbhaV3ServiceImpl.java`, `loginId` is mandatory, but even if it is null, the process can proceed without input validation.
src/main/environment/common_dev.properties (1)
Learnt from: helenKaryamsetty
PR: PSMRI/FHIR-API#52
File: src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java:84-91
Timestamp: 2024-12-09T16:01:39.809Z
Learning: In the `requestOtpForAbhaLogin` and `verifyAbhaLogin` methods of `LoginAbhaV3ServiceImpl.java`, `loginId` is mandatory, but even if it is null, the process can proceed without input validation.
πŸ”‡ Additional comments (8)
src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java (2)

56-61: Addition of new configuration properties looks good

The new configuration properties webLoginAbhaRequestOtp and webLoginAbhaVerify are appropriately added.


207-211: Verify scopes in verifyAbhaLogin method

Ensure that the scopes set for "abha-mobile" and "abha-aadhaar" login methods are correct and consistent with the expected authentication flow.

Please confirm that "abha-address-login" is the intended scope for these login methods.

src/main/environment/common_ci.properties (1)

95-96: New properties added correctly

The properties webLoginAbhaRequestOtp and webLoginAbhaVerify have been added with the correct placeholders for the base URL.

src/main/environment/common_example.properties (1)

58-59: New properties added with correct URLs

The addition of webLoginAbhaRequestOtp and webLoginAbhaVerify with the specified URLs is appropriate.

src/main/environment/common_test.properties (1)

95-96: New properties added correctly

The new properties webLoginAbhaRequestOtp and webLoginAbhaVerify are appropriately added to support web login functionality.

src/main/environment/common_dev.properties (3)

95-96: Verify configuration consistency across environments.

The new properties should be consistently defined across all environment configurations (dev, test, ci, prod).

βœ… Verification successful

Properties are consistently defined across relevant environment configurations

The verification shows that the webLoginAbhaRequestOtp and webLoginAbhaVerify properties are properly defined in all environment-specific configuration files:

  • common_ci.properties (using environment variable)
  • common_dev.properties
  • common_example.properties
  • common_test.properties

The properties are missing in application.properties and version.properties, but this is expected as these files serve different purposes and are not environment-specific configuration files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the properties exist in all environment files
echo "Checking environment files for web login properties..."
for env_file in $(fd -e properties); do
  echo "=== $env_file ==="
  rg "webLoginAbhaRequestOtp|webLoginAbhaVerify" "$env_file" || echo "Properties missing in $env_file"
done

Length of output: 2535


95-96: Confirm sandbox URLs for development environment.

The URLs are currently pointing to the sandbox environment (abhasbx). This is consistent with abhaMode=sbx setting, but ensure this is intentional for the development environment.

βœ… Verification successful

Sandbox URLs are correctly configured for development environment

The verification confirms that the sandbox URLs are intentionally configured for the development environment:

  • All environment files (dev, test, ci) consistently use abhaMode=sbx
  • The codebase has proper fallback logic in multiple services that defaults to abhaMode="sbx" if the mode is invalid
  • The sandbox URLs (abhasbx.abdm.gov.in) are consistently used across all environment property files
  • The implementation validates that abhaMode can only be "abdm" or "sbx"
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the abhaMode setting and URL patterns across files
echo "Checking ABHA mode and URL patterns..."
rg "abhaMode|abhasbx" 

Length of output: 6035


95-96: πŸ’‘ Codebase verification

Input validation is present but could be strengthened

The code shows basic validation is implemented:

  • Null checks for loginId
  • Login method and hint validation with specific error messages
  • Exception handling for invalid responses

However, there are opportunities for improvement:

  • No validation for empty strings or malformed input
  • Missing validation annotations (@NotNull, @notblank) on the request object
  • Validation logic is scattered across the implementation
πŸ”— Analysis chain

Verify input validation in the web login implementation.

Based on previous learnings from PR #52, ensure proper input validation is implemented in the corresponding service methods that use these new web login endpoints. The related LoginAbhaV3ServiceImpl has known issues with null loginId handling.

Consider implementing proper input validation at the service layer to prevent potential security issues.


Let me gather more information about the input validation in LoginAbhaV3ServiceImpl.


Let me search for the input validation logic in a different way.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for web login related implementations to verify input validation
ast-grep --pattern 'webLoginAbhaRequestOtp|webLoginAbhaVerify' 

# Search for potential null checks in the implementation
rg -A 5 'webLoginAbhaRequestOtp|webLoginAbhaVerify'

Length of output: 4902


Script:

#!/bin/bash
# Search for method implementations in LoginAbhaV3ServiceImpl that use these endpoints
ast-grep --pattern 'class LoginAbhaV3ServiceImpl {
  $$$
  $method($$$) {
    $$$
    webLoginAbhaRequestOtp
    $$$
  }
  $$$
}'

# Look for input validation patterns around these endpoints
rg -B 10 -A 2 'webLoginAbhaRequestOtp|webLoginAbhaVerify' src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java

# Search for any validation utilities or annotations used
rg "@Valid|@NotNull|@NotBlank|StringUtils\.isEmpty|Objects\.isNull" src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java

Length of output: 2015


Script:

#!/bin/bash
# Search for the method that handles the login request
ast-grep --pattern 'class LoginAbhaV3ServiceImpl {
  $$$
  public $_ loginAbha($_) {
    $$$
  }
}'

# Look for validation or error handling patterns
rg -B 5 -A 5 "throw new|if.*null|isEmpty|invalid" src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java

# Search for the request object structure
rg -A 10 "class LoginAbhaRequest|class ReqOtpEnrollment" --type java

Length of output: 3843

β›” Skipped due to learnings
Learnt from: helenKaryamsetty
PR: PSMRI/FHIR-API#52
File: src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java:84-91
Timestamp: 2024-12-09T16:01:39.809Z
Learning: In the `requestOtpForAbhaLogin` and `verifyAbhaLogin` methods of `LoginAbhaV3ServiceImpl.java`, `loginId` is mandatory, but even if it is null, the process can proceed without input validation.

@@ -65,6 +71,7 @@ public String requestOtpForAbhaLogin(String request) throws FHIRException {
RestTemplate restTemplate = new RestTemplate();
String encryptedLoginId = null;
String publicKeyString = null;
ResponseEntity<String> responseEntity;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure proper initialization of responseEntity

The variable responseEntity is declared but may not be initialized in all code paths before use. Verify that it is properly assigned before any operation that depends on it.

Comment on lines +219 to +225
if("abha-aadhaar".equalsIgnoreCase(loginData.getLoginMethod()) || "abha-mobile".equalsIgnoreCase(loginData.getLoginMethod())) {
responseEntity = restTemplate.exchange(webLoginAbhaVerify, HttpMethod.POST,
httpEntity, String.class);
} else {
responseEntity = restTemplate.exchange(verifyAbhaLoginUrl, HttpMethod.POST,
httpEntity, String.class);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential issue with conditional logic in response handling

At line 220, the condition may not cover all necessary cases appropriately. Review the logic to ensure the correct URL endpoint is used based on loginData.getLoginMethod().

Consider revising the condition to match the handling in the requestOtpForAbhaLogin method for consistency.

Comment on lines +131 to +137
if("abha-address".equalsIgnoreCase(loginAbhaRequest.getLoginHint())) {
responseEntity = restTemplate.exchange(webLoginAbhaRequestOtp, HttpMethod.POST,
httpEntity, String.class);
} else {
responseEntity = restTemplate.exchange(abhaLoginRequestOtp, HttpMethod.POST,
httpEntity, String.class);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Null check for loginHint before comparison

Before comparing loginAbhaRequest.getLoginHint() with "abha-address", ensure that loginHint is not null to prevent potential NullPointerException.

Apply this diff to add null checks:

+ if ("abha-address".equalsIgnoreCase(StringUtils.defaultString(loginAbhaRequest.getLoginHint()))) {
πŸ“ 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
if("abha-address".equalsIgnoreCase(loginAbhaRequest.getLoginHint())) {
responseEntity = restTemplate.exchange(webLoginAbhaRequestOtp, HttpMethod.POST,
httpEntity, String.class);
} else {
responseEntity = restTemplate.exchange(abhaLoginRequestOtp, HttpMethod.POST,
httpEntity, String.class);
}
if("abha-address".equalsIgnoreCase(StringUtils.defaultString(loginAbhaRequest.getLoginHint()))) {
responseEntity = restTemplate.exchange(webLoginAbhaRequestOtp, HttpMethod.POST,
httpEntity, String.class);
} else {
responseEntity = restTemplate.exchange(abhaLoginRequestOtp, HttpMethod.POST,
httpEntity, String.class);
}

Copy link
Member

@ravishanigarapu ravishanigarapu left a comment

Choose a reason for hiding this comment

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

looks fine

@ravishanigarapu ravishanigarapu merged commit dfe5ec6 into PSMRI:develop Dec 16, 2024
5 of 6 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jan 30, 2025
10 tasks
@coderabbitai coderabbitai bot mentioned this pull request Feb 27, 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