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

[ISNE-304] - set createdtime and createdby in audit details for demand and water reindexing #977

Merged
merged 8 commits into from
Oct 14, 2024

Conversation

Taniya-eGov
Copy link
Collaborator

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

Summary by CodeRabbit

  • New Features

    • Enhanced audit detail handling during demand updates for improved tracking.
    • Updates to water connection methods for better change tracking and status management.
  • Bug Fixes

    • Improved robustness of the demand update process with new audit details logic.
  • Documentation

    • Updated method signatures to reflect changes in parameters and functionality.

Copy link

coderabbitai bot commented Oct 14, 2024

Walkthrough

The pull request introduces modifications to several service classes to enhance the handling of audit details during updates. Key changes include the addition of current audit details in the DemandService and EnrichmentService classes, which improves the tracking of created time and user information. Method signatures have been updated to accommodate these changes, and logging statements have been refined for clarity. The WaterServiceImpl class has also been modified to ensure better tracking of water connection updates and creations.

Changes

File Path Change Summary
business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java Updated updateAsync method to include current audit details; modified method signature.
municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/EnrichmentService.java Updated enrichUpdateWaterConnection method to accept AuditDetails currentAuditDetails; modified method signature.
municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterServiceImpl.java Modified updateWaterConnection and createWaterConnection methods to enhance audit tracking; updated method signatures.

Possibly related PRs

  • Develop #801: This PR modifies the DemandService class, specifically updating the method signature of getAllDemands, which is related to the changes made in the main PR regarding the updateAsync method and audit details handling.
  • Develop #815: This PR also involves changes to the DemandService class, including modifications to methods that handle demand processing, which aligns with the enhancements made in the main PR.
  • Develop #971: This PR includes significant changes to the DemandService class, particularly in methods that deal with bill processing and notifications, which are relevant to the audit details and demand updates discussed in the main PR.

🐰 In the fields where the audits grow,
New details sprout, as updates flow.
With every change, we track and see,
How time and actions dance in harmony.
Hopping through code, we make it bright,
Each method shines, a joyful sight! 🌼


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

🧹 Outside diff range and nitpick comments (5)
municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/EnrichmentService.java (1)

201-207: LGTM! Consider adding null check for individual fields.

The changes to the enrichUpdateWaterConnection method look good. They allow preserving the original creation details when updating a water connection, which is a good practice for maintaining accurate audit trails.

Consider adding individual null checks for createdBy and createdTime fields of currentAuditDetails for extra safety:

 if (currentAuditDetails != null) {
-    auditDetails.setCreatedBy(currentAuditDetails.getCreatedBy());
-    auditDetails.setCreatedTime(currentAuditDetails.getCreatedTime());
+    if (currentAuditDetails.getCreatedBy() != null) {
+        auditDetails.setCreatedBy(currentAuditDetails.getCreatedBy());
+    }
+    if (currentAuditDetails.getCreatedTime() != null) {
+        auditDetails.setCreatedTime(currentAuditDetails.getCreatedTime());
+    }
 }
business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java (4)

Line range hint 1-1000: Consider implementing pagination for large result sets

The getDemands method retrieves all demands matching the given criteria without any pagination. For large datasets, this could lead to performance issues and excessive memory usage.

Consider implementing pagination in the getDemands method:

  1. Add pagination parameters (page number and page size) to the DemandCriteria class.
  2. Modify the demandRepository.getDemands method to support pagination.
  3. Update the getDemands method to use these pagination parameters:
public List<Demand> getDemands(DemandCriteria demandCriteria, RequestInfo requestInfo) {
    // ... existing code ...
    
    int pageSize = demandCriteria.getPageSize() != null ? demandCriteria.getPageSize() : defaultPageSize;
    int pageNumber = demandCriteria.getPageNumber() != null ? demandCriteria.getPageNumber() : 0;
    
    demands = demandRepository.getDemands(demandCriteria, pageSize, pageNumber);
    
    // ... rest of the method ...
}

This change would improve the performance and scalability of the service when dealing with large numbers of demands.


Line range hint 1-1000: Enhance error handling and logging

The current implementation could benefit from more robust error handling and logging, especially in critical sections like demand creation, updating, and searching.

  1. Wrap critical operations in try-catch blocks to handle specific exceptions.
  2. Use a logging framework consistently throughout the class to log important events and errors.
  3. Consider using a custom exception class for domain-specific errors.

Example:

try {
    demands = demandRepository.getDemands(demandCriteria);
    log.info("Retrieved {} demands for criteria: {}", demands.size(), demandCriteria);
} catch (DatabaseException e) {
    log.error("Error retrieving demands: {}", e.getMessage());
    throw new DemandServiceException("Failed to retrieve demands", e);
}

This would improve the robustness and debuggability of the service.


Line range hint 1-1000: Consider implementing caching for frequently accessed data

The service makes frequent calls to external services and databases, which could be optimized by implementing caching for frequently accessed and relatively static data.

Implement caching for user data and other relatively static information:

  1. Use a caching solution like Ehcache or Redis.
  2. Cache user data retrieved from the user service.
  3. Implement cache invalidation strategies to ensure data consistency.

Example:

@Cacheable(value = "userCache", key = "#userSearchRequest.uuid")
public List<User> getUsers(UserSearchRequest userSearchRequest) {
    // Existing code to fetch users
}

This would reduce the load on external services and improve response times for repeated requests.


Line range hint 1-1000: Overall assessment of DemandService class

The changes made to the updateAsync method improve the handling of audit details during demand updates. However, there are several areas where the class could be further improved:

  1. Implement pagination for large result sets to enhance performance and scalability.
  2. Enhance error handling and logging for better debuggability and robustness.
  3. Consider implementing caching for frequently accessed data to reduce load on external services.
  4. Refactor the audit details handling to process each demand individually, ensuring correctness for all demands.

These improvements would significantly enhance the overall quality, performance, and maintainability of the DemandService class.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d94a3e0 and d87fd5c.

📒 Files selected for processing (3)
  • business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java (1 hunks)
  • municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/EnrichmentService.java (1 hunks)
  • municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterServiceImpl.java (4 hunks)
🧰 Additional context used

Comment on lines 231 to 236
AuditDetails currAuditDetails=demands.get(0).getAuditDetails();
AuditDetails auditDetail = util.getAuditDetail(requestInfo);
if (currAuditDetails != null) {
auditDetail.setCreatedTime(currAuditDetails.getCreatedTime());
auditDetail.setCreatedBy(currAuditDetails.getCreatedBy());
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure proper handling of audit details

The changes introduce a new variable currAuditDetails and update the auditDetail object with the created time and created by information from the current audit details. This approach preserves the original creation information during updates.

However, there are a few points to consider:

  1. The currAuditDetails is obtained from the first demand in the list. This assumes all demands in the list have the same audit details, which may not always be the case.
  2. There's no null check on currAuditDetails.getCreatedTime() and currAuditDetails.getCreatedBy() before setting them in auditDetail.

Consider refactoring this part to handle each demand's audit details individually:

-AuditDetails currAuditDetails=demands.get(0).getAuditDetails();
 AuditDetails auditDetail = util.getAuditDetail(requestInfo);
-if (currAuditDetails != null) {
-    auditDetail.setCreatedTime(currAuditDetails.getCreatedTime());
-    auditDetail.setCreatedBy(currAuditDetails.getCreatedBy());
-}

+for (Demand demand : demands) {
+    AuditDetails currAuditDetails = demand.getAuditDetails();
+    if (currAuditDetails != null) {
+        auditDetail.setCreatedTime(currAuditDetails.getCreatedTime());
+        auditDetail.setCreatedBy(currAuditDetails.getCreatedBy());
+    }
+    demand.setAuditDetails(auditDetail);
+}

This approach ensures that each demand's audit details are handled correctly and individually.

Committable suggestion was skipped due to low confidence.

@@ -240,7 +240,7 @@ public List<WaterConnection> updateWaterConnection(WaterConnectionRequest waterC
throw new CustomException("DUPLICATE_OLD_CONNECTION_NUMBER",
"Duplicate Old connection number");
}

AuditDetails auditDetails=waterConnection.get(0).getAuditDetails();
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential NullPointerException when accessing waterConnection.get(0)

In the methods updateWaterConnection (line 243) and updateWaterConnectionForModifyFlow (line 334), you are accessing waterConnection.get(0) without checking if waterConnection is not null and not empty. This could lead to a NullPointerException or IndexOutOfBoundsException if waterConnection is null or empty. Ensure that you perform a null check and size check before accessing elements of the list.

Apply this diff to fix the issue:

+        if (waterConnection != null && !waterConnection.isEmpty()) {
             AuditDetails auditDetails = waterConnection.get(0).getAuditDetails();
+        } else {
+            // Handle the null or empty waterConnection case appropriately
+            // For example, throw a CustomException or initialize auditDetails differently
+        }

Also applies to: 334-334

@@ -252,7 +252,7 @@ public List<WaterConnection> updateWaterConnection(WaterConnectionRequest waterC
String previousApplicationStatus = workflowService.getApplicationStatus(waterConnectionRequest.getRequestInfo(),
waterConnectionRequest.getWaterConnection().getApplicationNo(),
waterConnectionRequest.getWaterConnection().getTenantId(), config.getBusinessServiceValue());
enrichmentService.enrichUpdateWaterConnection(waterConnectionRequest);
enrichmentService.enrichUpdateWaterConnection(auditDetails, waterConnectionRequest);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure auditDetails is not null before passing to enrichUpdateWaterConnection

In the methods updateWaterConnection (line 255) and updateWaterConnectionForModifyFlow (line 346), you are passing auditDetails to enrichUpdateWaterConnection. If auditDetails is null, this may cause a NullPointerException within enrichUpdateWaterConnection. Ensure that auditDetails is properly initialized and not null before using it.

Apply this diff to validate auditDetails:

         // Previous code ensuring waterConnection is not null or empty
+        if (auditDetails != null) {
             enrichmentService.enrichUpdateWaterConnection(auditDetails, waterConnectionRequest);
+        } else {
+            // Handle the null auditDetails case appropriately
+            // For example, initialize auditDetails or handle the error
+        }

Also applies to: 346-346

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 (1)
business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java (1)

232-239: Ensure null safety when accessing currAuditDetails properties

While there's a null check for currAuditDetails, there are no checks for currAuditDetails.getCreatedTime() and currAuditDetails.getCreatedBy(). If either of these properties is null, it could cause a NullPointerException. Consider adding null checks before setting these values.

Apply this diff to add null checks:

 if (currAuditDetails != null) {
+    if (currAuditDetails.getCreatedTime() != null) {
         auditDetail.setCreatedTime(currAuditDetails.getCreatedTime());
+    }
+    if (currAuditDetails.getCreatedBy() != null) {
         auditDetail.setCreatedBy(currAuditDetails.getCreatedBy());
+    }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d87fd5c and 564d24a.

📒 Files selected for processing (2)
  • business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java (1 hunks)
  • municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterServiceImpl.java (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterServiceImpl.java
🧰 Additional context used

Comment on lines +232 to +239
for (Demand demand : demands) {
AuditDetails currAuditDetails = demand.getAuditDetails();
if (currAuditDetails != null) {
auditDetail.setCreatedTime(currAuditDetails.getCreatedTime());
auditDetail.setCreatedBy(currAuditDetails.getCreatedBy());
}
demand.setAuditDetails(auditDetail);
}
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 reusing the same AuditDetails instance across demands

The current implementation modifies a single auditDetail instance for all demands. This can lead to unintended side effects, as all demands will share the same AuditDetails object. To ensure each demand has its own unique audit details, create a new AuditDetails instance inside the loop for each demand.

Apply this diff to create a new AuditDetails for each demand:

 AuditDetails auditDetail = util.getAuditDetail(requestInfo);
 for (Demand demand : demands) {
+    AuditDetails demandAuditDetail = new AuditDetails();
     AuditDetails currAuditDetails = demand.getAuditDetails();
     if (currAuditDetails != null) {
-        auditDetail.setCreatedTime(currAuditDetails.getCreatedTime());
-        auditDetail.setCreatedBy(currAuditDetails.getCreatedBy());
+        demandAuditDetail.setCreatedTime(currAuditDetails.getCreatedTime());
+        demandAuditDetail.setCreatedBy(currAuditDetails.getCreatedBy());
     }
-    demand.setAuditDetails(auditDetail);
+    demand.setAuditDetails(demandAuditDetail);
 }
📝 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
for (Demand demand : demands) {
AuditDetails currAuditDetails = demand.getAuditDetails();
if (currAuditDetails != null) {
auditDetail.setCreatedTime(currAuditDetails.getCreatedTime());
auditDetail.setCreatedBy(currAuditDetails.getCreatedBy());
}
demand.setAuditDetails(auditDetail);
}
AuditDetails auditDetail = util.getAuditDetail(requestInfo);
for (Demand demand : demands) {
AuditDetails demandAuditDetail = new AuditDetails();
AuditDetails currAuditDetails = demand.getAuditDetails();
if (currAuditDetails != null) {
demandAuditDetail.setCreatedTime(currAuditDetails.getCreatedTime());
demandAuditDetail.setCreatedBy(currAuditDetails.getCreatedBy());
}
demand.setAuditDetails(demandAuditDetail);
}

🛠️ Refactor suggestion

Consider copying the entire currAuditDetails

Instead of selectively copying createdTime and createdBy, you might want to copy all relevant audit details to preserve the full audit trail. This ensures consistency and completeness of audit information.

Apply this diff to copy the audit details:

 for (Demand demand : demands) {
-    AuditDetails currAuditDetails = demand.getAuditDetails();
-    if (currAuditDetails != null) {
-        auditDetail.setCreatedTime(currAuditDetails.getCreatedTime());
-        auditDetail.setCreatedBy(currAuditDetails.getCreatedBy());
-    }
-    demand.setAuditDetails(auditDetail);
+    AuditDetails currAuditDetails = demand.getAuditDetails();
+    if (currAuditDetails != null) {
+        demand.setAuditDetails(currAuditDetails);
+    } else {
+        demand.setAuditDetails(util.getAuditDetail(requestInfo));
+    }
 }

Committable suggestion was skipped due to low confidence.

@pradeepkumarcm-egov pradeepkumarcm-egov merged commit 70ff18f into master Oct 14, 2024
1 of 2 checks passed
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