Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Condition to not update createdtime in update demand call for reindexing #969

Closed
wants to merge 5 commits into from

Conversation

Taniya-eGov
Copy link
Collaborator

@Taniya-eGov Taniya-eGov commented Oct 8, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced audit detail retrieval process for various services, improving tracking during amendments and bill preparations.
    • Improved validation logic for amendment requests, ensuring more robust error handling and workflow validation.
  • Bug Fixes

    • Refined error handling in amendment validation to enhance clarity and specificity.
  • Documentation

    • Updated method signatures to reflect the inclusion of new parameters for audit detail retrieval.

Copy link

coderabbitai bot commented Oct 8, 2024

Walkthrough

The changes in this pull request primarily involve modifications to various service classes and a utility class within the billing service. The getAuditDetail method in the Util class has been updated to include an additional boolean parameter, influencing how audit details are retrieved and processed across multiple service methods. This adjustment affects the AmendmentService, BillService, BillServicev2, DemandService, and AmendmentValidator, enhancing the handling of audit details during create and update operations.

Changes

File Change Summary
.../AmendmentService.java Updated updateDemandWithAmendmentTax to call util.getAuditDetail(requestInfo, true).
.../BillService.java Modified prepareBill to call util.getAuditDetail(requestInfo, true).
.../BillServicev2.java Updated prepareBill to call util.getAuditDetail(requestInfo, true).
.../DemandService.java Changed create method to call util.getAuditDetail(requestInfo, true) and updateAsync to call util.getAuditDetail(requestInfo, false).
.../util/Util.java Updated getAuditDetail method signature to include Boolean isCreate and modified its internal logic.
.../validator/AmendmentValidator.java Modified enrichAmendmentForCreate and validateAndEnrichAmendmentForUpdate to include the new parameter in util.getAuditDetail.

Possibly related PRs

  • Develop #971: The DemandService class in this PR has updated the util.getAuditDetail(requestInfo) method call to include an additional boolean parameter, similar to the changes made in the AmendmentService class in the main PR. This indicates a related focus on modifying how audit details are retrieved across different services.

Suggested reviewers

  • pradeepkumarcm-egov

Poem

In the land of bills and demands,
Where audits dance and take their stands,
We’ve added a flag, oh what a delight,
To track our changes both day and night.
With amendments in hand, we hop with glee,
For clearer audits, as bright as can be! 🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c32b17b and e06eb8a.

📒 Files selected for processing (2)
  • business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java (2 hunks)
  • business-services/billing-service/src/main/java/org/egov/demand/util/Util.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java
  • business-services/billing-service/src/main/java/org/egov/demand/util/Util.java

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

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

🧹 Outside diff range and nitpick comments (6)
business-services/billing-service/src/main/java/org/egov/demand/util/Util.java (1)

Line range hint 1-427: Summary of changes and potential impact

The main change in this file is the modification of the getAuditDetail method in the Util class. This change allows for more flexible creation of audit details, distinguishing between create and update operations. While this change improves the functionality, it has the following potential impacts:

  1. It introduces a backwards-incompatible change to the method's signature.
  2. It may require updates to all parts of the codebase that call this method.
  3. It might affect the behavior of audit trails in the system, depending on how it's used.

Please ensure that all callers of this method are updated and that the new behavior aligns with the expected audit trail requirements across the system.

Consider the following architectural advice:

  1. If this change is part of a larger refactoring effort to improve audit trails, ensure that it's consistently applied across all relevant services.
  2. Consider creating a separate AuditService if audit-related functionality grows more complex in the future.
  3. Evaluate if this change aligns with any existing audit policies or regulations that the system needs to comply with.
business-services/billing-service/src/main/java/org/egov/demand/service/BillService.java (1)

365-365: Summary: Updated audit detail generation for bills

The change to util.getAuditDetail(requestInfo, true) introduces a new boolean parameter in the audit detail generation process for bills. While this change is minimal, it may have implications on how audit information is recorded and processed throughout the system.

Recommendations:

  1. Ensure that the Util.getAuditDetail method correctly handles this new boolean parameter.
  2. Verify that all other calls to getAuditDetail across the codebase have been updated consistently.
  3. Update any relevant documentation or comments related to audit detail generation.
  4. Consider adding a comment explaining the purpose of the true parameter for future maintainability.
business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java (2)

Line range hint 638-1022: Consider refactoring the getAllDemands method

The getAllDemands method is quite long and complex, making it difficult to understand and maintain. Consider breaking it down into smaller, more focused methods to improve readability and maintainability.

Some suggestions for refactoring:

  1. Extract the demand filtering logic into a separate method.
  2. Create a method for calculating various totals (e.g., currentmonthBill, totalAreas, etc.).
  3. Consider using the Builder pattern for constructing the AggregatedDemandDetailResponse.

Example of extracting demand filtering logic:

private List<Demand> filterActiveDemands(List<Demand> demands) {
    return demands.stream()
        .filter(demand -> demand.getStatus().equals(Demand.StatusEnum.ACTIVE))
        .collect(Collectors.toList());
}

Line range hint 638-1022: Add comments to explain complex stream operations

There are multiple instances of complex stream operations and business logic throughout the getAllDemands method. Adding comments to explain the purpose and logic of these operations would greatly improve code readability and maintainability.

For example, consider adding comments before complex stream operations like:

// Calculate the total areas without penalty for specific tax head codes
totalAreas = remainingMonthDemandDetailList.stream()
    .filter(dd -> taxHeadCodesToFilterWithoutPenalty.contains(dd.getTaxHeadMasterCode()))
    .map(dd -> dd.getTaxAmount().subtract(dd.getCollectionAmount()))
    .reduce(BigDecimal.ZERO, BigDecimal::add);
business-services/billing-service/src/main/java/org/egov/demand/web/validator/AmendmentValidator.java (2)

Line range hint 237-237: Typo in method name 'getIsAmendmentworkflowEnabed'

The method getIsAmendmentworkflowEnabed() appears to have a typo in the word "Enabed". It should likely be getIsAmendmentWorkflowEnabled().

This occurs in the following lines:

  • Line 237: if (props.getIsAmendmentworkflowEnabed()) {
  • Line 246: if (!props.getIsAmendmentworkflowEnabed()) {

Apply this diff to correct the method name:

- if (props.getIsAmendmentworkflowEnabed()) {
+ if (props.getIsAmendmentWorkflowEnabled()) {

Ensure that the method name is updated in the ApplicationProperties class and any other references to maintain consistency.

Also applies to: 246-246


Line range hint 263-263: Typographical error in error message

There's a typo in the error message string:

  • Current: "Mandatory workflow fileds missing in the update request, Please add all the following fields module, businessservice, businessid and action"
  • Corrected: "Mandatory workflow fields missing in the update request. Please add all the following fields: module, businessservice, businessid, and action"

Apply this diff to correct the typo and improve clarity:

- "Mandatory workflow fileds missing in the update request, Please add all the following fields module, businessservice, businessid and action"
+ "Mandatory workflow fields missing in the update request. Please add all the following fields: module, businessservice, businessid, and action"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5f94c27 and 8422d99.

📒 Files selected for processing (6)
  • business-services/billing-service/src/main/java/org/egov/demand/service/AmendmentService.java (1 hunks)
  • business-services/billing-service/src/main/java/org/egov/demand/service/BillService.java (1 hunks)
  • business-services/billing-service/src/main/java/org/egov/demand/service/BillServicev2.java (1 hunks)
  • business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java (2 hunks)
  • business-services/billing-service/src/main/java/org/egov/demand/util/Util.java (1 hunks)
  • business-services/billing-service/src/main/java/org/egov/demand/web/validator/AmendmentValidator.java (2 hunks)
🧰 Additional context used
🔇 Additional comments (7)
business-services/billing-service/src/main/java/org/egov/demand/util/Util.java (1)

115-127: Approve changes with suggestions for improvement

The changes to the getAuditDetail method improve its flexibility by allowing different behavior for create and update operations. This is a good improvement. However, there are a few points to consider:

  1. The method signature change is backwards incompatible. Ensure all callers of this method are updated accordingly.
  2. Consider adding Javadoc to explain the purpose of the isCreate parameter.
  3. The createdBy is set even when isCreate is false. This might be confusing. Consider setting it to null in the update case.

To verify the impact of this change, please run the following script:

This script will help identify all places where the getAuditDetail method is called and where AuditDetails are created, allowing you to ensure all usages are updated correctly.

✅ Verification successful

Verification Successful

All usages of the getAuditDetail method have been updated to include the new isCreate parameter, ensuring backward compatibility is maintained.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all occurrences of getAuditDetail method calls in the codebase

# Search for getAuditDetail method calls
echo "Searching for getAuditDetail method calls:"
rg --type java "getAuditDetail\s*\(" -A 2

# Search for AuditDetails creation
echo "\nSearching for AuditDetails creation:"
rg --type java "AuditDetails\s*\." -A 3

Length of output: 34219

business-services/billing-service/src/main/java/org/egov/demand/service/BillService.java (2)

365-365: Verify consistency of getAuditDetail usage

While the change to getAuditDetail appears isolated, it's important to ensure that this new boolean parameter is used consistently across the codebase. This change might require updates in other services or classes that use the Util.getAuditDetail method.

Let's check for other occurrences of getAuditDetail in the codebase:

#!/bin/bash
# Description: Find other occurrences of getAuditDetail method calls
# Expected result: All calls should now include a boolean parameter

rg 'getAuditDetail\s*\(' --type java

365-365: Audit details now include a boolean parameter

The getAuditDetail method call has been updated to include a boolean parameter set to true. This change might affect how audit details are generated or logged for bills.

To ensure this change doesn't introduce any unintended side effects, let's verify the implementation of the getAuditDetail method in the Util class:

✅ Verification successful

[/run_scripts]


Verified: getAuditDetail method now accepts a boolean parameter

The getAuditDetail method in the Util class has been successfully updated to include a boolean parameter (isCreate). This aligns with the change in the BillService class and ensures that audit details are generated or logged appropriately based on the provided parameter.

  • Location: business-services/billing-service/src/main/java/org/egov/demand/util/Util.java
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the implementation of getAuditDetail method in Util class
# Expected result: The method should accept a boolean parameter

ast-grep --lang java --pattern 'class Util {
  $$$
  getAuditDetail($_, boolean $_) {
    $$$
  }
  $$$
}'

Length of output: 2319


Script:

#!/bin/bash
# Description: Verify that the getAuditDetail method in Util class accepts a boolean parameter
# Expected result: The method signature includes a boolean parameter

rg 'public\s+AuditDetails\s+getAuditDetail\s*\(\s*RequestInfo\s+\w+,\s*Boolean\s+\w+\s*\)' --type java business-services/billing-service/src/main/java/org/egov/demand/util/Util.java

Length of output: 263

business-services/billing-service/src/main/java/org/egov/demand/service/BillServicev2.java (1)

459-459: LGTM! Verify consistency with Util class.

The change to util.getAuditDetail(requestInfo, true) looks good. It appears to be part of an update to how audit details are generated for new bills.

To ensure consistency, let's check the Util class for the updated getAuditDetail method:

business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java (2)

147-147: Verify consistency of audit detail retrieval

The getAuditDetail method now includes a boolean parameter set to true. This change likely affects how audit details are generated or processed during the creation of demands.

Please ensure that this change is consistent with the intended behavior and is applied correctly in other relevant parts of the code. Run the following script to check for other occurrences of getAuditDetail and verify if they need similar updates:

✅ Verification successful

Audit detail retrieval consistency verified

The addition of the true parameter in the getAuditDetail method within the create method is consistent with its usage across the codebase. Different usages of getAuditDetail with true and false are appropriate based on the context of the operation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other occurrences of getAuditDetail
rg "getAuditDetail\s*\(" -t java

Length of output: 2086


231-231: Verify intentional difference in audit detail retrieval

The getAuditDetail method call in updateAsync now includes a boolean parameter set to false, while in the create method it's set to true. This difference suggests distinct behavior for creation and updating of demands.

Please confirm that this difference is intentional and correctly implemented. Consider adding a comment explaining the reason for the different boolean values if it's not immediately obvious. Run the following script to check the implementation of getAuditDetail:

business-services/billing-service/src/main/java/org/egov/demand/web/validator/AmendmentValidator.java (1)

218-218: Correct usage of 'createdTime' during creation

In the enrichAmendmentForCreate method, passing true to util.getAuditDetail(requestInfo, true) correctly ensures that the createdTime is set for new amendments.

@@ -165,7 +165,7 @@ public void updateDemandWithAmendmentTax(RequestInfo requestInfo, Amendment amen
List<Demand> demands = demandService.getDemands(demandCriteria, requestInfo);
if(!CollectionUtils.isEmpty(demands)) {

AuditDetails auditDetails = util.getAuditDetail(requestInfo);
AuditDetails auditDetails = util.getAuditDetail(requestInfo,true);
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Inconsistency Found in util.getAuditDetail Method Calls

There is an inconsistent usage of the boolean parameter in the util.getAuditDetail method:

  • Most calls use true as the second parameter.
  • One call in DemandService.java uses false.

Please verify whether the false parameter in DemandService.java is intentional and aligns with the intended behavior. If it is not intended, consider updating it to true to maintain consistency.

🔗 Analysis chain

Verify the impact of the new parameter in util.getAuditDetail

The util.getAuditDetail method now includes an additional boolean parameter set to true. This change might affect how audit details are generated or processed. Please ensure that:

  1. The Util class has been updated to handle this new parameter correctly.
  2. The behavior change aligns with the intended functionality for this specific use case.
  3. Other calls to getAuditDetail across the codebase have been updated consistently, if necessary.

To ensure consistency across the codebase, please run the following script:

This script will help identify any inconsistencies in the usage of util.getAuditDetail across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for inconsistencies in util.getAuditDetail method calls

# Search for all occurrences of util.getAuditDetail
echo "Occurrences of util.getAuditDetail:"
rg --type java "util\.getAuditDetail\(" -A 1

# Search for the updated method call with the boolean parameter
echo "\nOccurrences of util.getAuditDetail with boolean parameter:"
rg --type java "util\.getAuditDetail\([^)]+,\s*true\)" -A 1

# Compare the results to identify any inconsistencies

Length of output: 3802

@@ -286,7 +286,7 @@ public Amendment validateAndEnrichAmendmentForUpdate(@Valid AmendmentUpdateReque
* enriching the update object
*/
amendmentUpdate.setAdditionalDetails(util.jsonMerge(amendments.get(0).getAdditionalDetails(), amendmentUpdate.getAdditionalDetails()));
amendmentUpdate.setAuditDetails(util.getAuditDetail(amendmentUpdateRequest.getRequestInfo()));
amendmentUpdate.setAuditDetails(util.getAuditDetail(amendmentUpdateRequest.getRequestInfo(),true));
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid updating 'createdTime' during update operations

In the validateAndEnrichAmendmentForUpdate method, passing true to util.getAuditDetail(amendmentUpdateRequest.getRequestInfo(), true) will update the createdTime. For update operations, you should preserve the original createdTime and only update the lastModifiedTime.

Apply this diff to prevent updating the createdTime:

- amendmentUpdate.setAuditDetails(util.getAuditDetail(amendmentUpdateRequest.getRequestInfo(), true));
+ amendmentUpdate.setAuditDetails(util.getAuditDetail(amendmentUpdateRequest.getRequestInfo(), false));

This ensures that only the lastModifiedTime is updated during amendments.

📝 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
amendmentUpdate.setAuditDetails(util.getAuditDetail(amendmentUpdateRequest.getRequestInfo(),true));
amendmentUpdate.setAuditDetails(util.getAuditDetail(amendmentUpdateRequest.getRequestInfo(), false));

@@ -286,7 +286,7 @@ public Amendment validateAndEnrichAmendmentForUpdate(@Valid AmendmentUpdateReque
* enriching the update object
*/
amendmentUpdate.setAdditionalDetails(util.jsonMerge(amendments.get(0).getAdditionalDetails(), amendmentUpdate.getAdditionalDetails()));
amendmentUpdate.setAuditDetails(util.getAuditDetail(amendmentUpdateRequest.getRequestInfo()));
amendmentUpdate.setAuditDetails(util.getAuditDetail(amendmentUpdateRequest.getRequestInfo(),true));

Choose a reason for hiding this comment

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

check here it might required false here as it is update call

@@ -165,7 +165,7 @@ public void updateDemandWithAmendmentTax(RequestInfo requestInfo, Amendment amen
List<Demand> demands = demandService.getDemands(demandCriteria, requestInfo);
if(!CollectionUtils.isEmpty(demands)) {

AuditDetails auditDetails = util.getAuditDetail(requestInfo);
AuditDetails auditDetails = util.getAuditDetail(requestInfo,true);

Choose a reason for hiding this comment

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

its a update call make it false here as well

@Taniya-eGov Taniya-eGov deleted the ISNE-304 branch October 11, 2024 09:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants