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

updated auditdetails logic #974

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

updated auditdetails logic #974

wants to merge 3 commits into from

Conversation

Taniya-eGov
Copy link
Collaborator

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

Summary by CodeRabbit

  • New Features

    • Enhanced handling of audit details during water connection updates.
    • Automatic assignment of connection numbers upon submission of water connection requests.
    • Improved enrichment of property details associated with water connections.
    • Refined payment type handling during water connection creation.
  • Bug Fixes

    • Adjusted duplicate connection number checks to prevent conflicts during updates.
    • Refined logic for filtering connections based on application status.
  • Chores

    • Removed deprecated method for enriching file store IDs.

Copy link

coderabbitai bot commented Oct 10, 2024

Walkthrough

The EnrichmentService and WaterServiceImpl classes in the org.egov.waterconnection.service package have been updated to enhance the processing of WaterConnectionRequest objects. Key modifications include the addition of audit details during updates, improved connection number assignment, and refined validation logic for handling duplicates. The enrichFileStoreIds method has been commented out, indicating it is no longer in use. Overall, these changes focus on better audit handling and validation within the water connection services.

Changes

File Path Change Summary
.../EnrichmentService.java - Added audit details handling in enrichUpdateWaterConnection method.
- Updated postStatusEnrichment to set connection number.
- Modified setConnectionNO to check connection number list size and throw exception if invalid.
- Commented out enrichFileStoreIds, marking it as inactive.
- Refined filterConnections logic for application status.
- Enhanced enrichPropertyDetails to populate additional owner details.
.../WaterServiceImpl.java - Incorporated audit details retrieval in updateWaterConnection method.
- Adjusted duplicate connection number checks to throw CustomException if a duplicate is detected.
- Refined payment type handling in createWaterConnection method.
- Updated postForMeterReading to include connection type checks.

Poem

In the service of water, we strive and we play,
Enriching the details, come what may.
With audits in order and numbers in line,
Our connections are stronger, our process divine!
So hop along, friends, let’s cheer and rejoice,
For every small change, we give a loud voice! 🐇✨


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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d448410 and ea71284.

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

Comment on lines 202 to 208
AuditDetails currentAuditDetails = waterConnectionRequest.getWaterConnection().getAuditDetails();
AuditDetails auditDetails = waterServicesUtil
.getAuditDetails(waterConnectionRequest.getRequestInfo().getUserInfo().getUuid(), false);

auditDetails.setCreatedBy(currentAuditDetails.getCreatedBy());
auditDetails.setCreatedTime(currentAuditDetails.getCreatedTime());

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 currentAuditDetails

Accessing currentAuditDetails.getCreatedBy() and currentAuditDetails.getCreatedTime() without checking if currentAuditDetails is null may lead to a NullPointerException. Consider adding a null check before accessing these methods.

Apply this diff to add a null check:

+        if (currentAuditDetails != null) {
           auditDetails.setCreatedBy(currentAuditDetails.getCreatedBy());
           auditDetails.setCreatedTime(currentAuditDetails.getCreatedTime());
+        }
📝 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
AuditDetails currentAuditDetails = waterConnectionRequest.getWaterConnection().getAuditDetails();
AuditDetails auditDetails = waterServicesUtil
.getAuditDetails(waterConnectionRequest.getRequestInfo().getUserInfo().getUuid(), false);
auditDetails.setCreatedBy(currentAuditDetails.getCreatedBy());
auditDetails.setCreatedTime(currentAuditDetails.getCreatedTime());
AuditDetails currentAuditDetails = waterConnectionRequest.getWaterConnection().getAuditDetails();
AuditDetails auditDetails = waterServicesUtil
.getAuditDetails(waterConnectionRequest.getRequestInfo().getUserInfo().getUuid(), false);
if (currentAuditDetails != null) {
auditDetails.setCreatedBy(currentAuditDetails.getCreatedBy());
auditDetails.setCreatedTime(currentAuditDetails.getCreatedTime());
}

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

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

201-209: LGTM! Consider handling the null case explicitly.

The changes to preserve the original creation details during updates are good. This helps maintain an accurate audit trail. However, consider explicitly handling the case where currentAuditDetails is null, perhaps by logging a warning or setting default values.

You might want to add an else clause to handle the null case:

 if (currentAuditDetails != null) {
   auditDetails.setCreatedBy(currentAuditDetails.getCreatedBy());
   auditDetails.setCreatedTime(currentAuditDetails.getCreatedTime());
+} else {
+  log.warn("currentAuditDetails is null, unable to set original creation details");
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ea71284 and 18ddb96.

📒 Files selected for processing (2)
  • 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 +201 to +209
public void enrichUpdateWaterConnection(AuditDetails currentAuditDetails,WaterConnectionRequest waterConnectionRequest) {
AuditDetails auditDetails = waterServicesUtil
.getAuditDetails(waterConnectionRequest.getRequestInfo().getUserInfo().getUuid(), false);

if (currentAuditDetails != null) {
auditDetails.setCreatedBy(currentAuditDetails.getCreatedBy());
auditDetails.setCreatedTime(currentAuditDetails.getCreatedTime());
}

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider refactoring for improved maintainability.

The enrichUpdateWaterConnection method is quite long and handles multiple responsibilities. Consider breaking it down into smaller, more focused methods to improve readability and maintainability.

For example, you could extract the document, plumber info, and road cutting info enrichment into separate methods:

private void enrichDocuments(WaterConnection connection, AuditDetails auditDetails) {
    if (!CollectionUtils.isEmpty(connection.getDocuments())) {
        connection.getDocuments().forEach(document -> {
            // ... (existing document enrichment logic)
        });
    }
}

private void enrichPlumberInfo(WaterConnection connection, AuditDetails auditDetails) {
    if (!CollectionUtils.isEmpty(connection.getPlumberInfo())) {
        connection.getPlumberInfo().forEach(plumberInfo -> {
            // ... (existing plumber info enrichment logic)
        });
    }
}

private void enrichRoadCuttingInfo(WaterConnection connection, AuditDetails auditDetails) {
    if (!CollectionUtils.isEmpty(connection.getRoadCuttingInfo())) {
        connection.getRoadCuttingInfo().forEach(roadCuttingInfo -> {
            // ... (existing road cutting info enrichment logic)
        });
    }
}

Then, call these methods from enrichUpdateWaterConnection:

public void enrichUpdateWaterConnection(AuditDetails currentAuditDetails, WaterConnectionRequest waterConnectionRequest) {
    // ... (existing audit details logic)

    WaterConnection connection = waterConnectionRequest.getWaterConnection();
    enrichDocuments(connection, auditDetails);
    enrichPlumberInfo(connection, auditDetails);
    enrichRoadCuttingInfo(connection, auditDetails);

    enrichingAdditionalDetails(waterConnectionRequest);
}

This refactoring would make the method easier to understand and maintain.

@@ -252,7 +253,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 properly initialized before use

At line 256, auditDetails is passed to enrichmentService.enrichUpdateWaterConnection(auditDetails, waterConnectionRequest);. Ensure that auditDetails has been properly initialized and is not null to prevent potential NullPointerException.

@@ -342,7 +344,7 @@ private List<WaterConnection> updateWaterConnectionForModifyFlow(WaterConnection
String previousApplicationStatus = workflowService.getApplicationStatus(waterConnectionRequest.getRequestInfo(),
waterConnectionRequest.getWaterConnection().getApplicationNo(),
waterConnectionRequest.getWaterConnection().getTenantId(), config.getModifyWSBusinessServiceName());
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 properly initialized before use

At line 347, auditDetails is passed to enrichmentService.enrichUpdateWaterConnection(auditDetails, waterConnectionRequest);. Verify that auditDetails is not null to prevent potential NullPointerException during method execution.

@@ -236,6 +236,7 @@ public List<WaterConnection> updateWaterConnection(WaterConnectionRequest waterC
mDMSValidator.validateMISFields(waterConnectionRequest);
waterConnectionValidator.validateWaterConnection(waterConnectionRequest, WCConstants.UPDATE_APPLICATION);
List<WaterConnection> waterConnection = getWaterConnectionForOldConnectionNo(waterConnectionRequest);
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 or IndexOutOfBoundsException due to unchecked access of waterConnection

At line 239, waterConnection.get(0).getAuditDetails() is called without verifying whether waterConnection is non-null and contains elements. If waterConnection is null or empty, this will lead to a NullPointerException or IndexOutOfBoundsException.

Apply this diff to fix the issue:

+if (waterConnection != null && !waterConnection.isEmpty()) {
    AuditDetails auditDetails = waterConnection.get(0).getAuditDetails();
+} else {
+    // Handle the scenario where waterConnection is null or empty
+    throw new CustomException("WATER_CONNECTION_NOT_FOUND", "No water connections found for the given criteria");
+}

Committable suggestion was skipped due to low confidence.

@@ -326,6 +327,7 @@ private List<WaterConnection> getWaterConnectionForOldConnectionNo(WaterConnecti
private List<WaterConnection> updateWaterConnectionForModifyFlow(WaterConnectionRequest waterConnectionRequest) {
waterConnectionValidator.validateWaterConnection(waterConnectionRequest, WCConstants.MODIFY_CONNECTION);
List<WaterConnection> waterConnection = getWaterConnectionForOldConnectionNo(waterConnectionRequest);
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 or IndexOutOfBoundsException due to unchecked access of waterConnection

At line 330, waterConnection.get(0).getAuditDetails() is accessed without checking if waterConnection is non-null and not empty. This can lead to exceptions if waterConnection is null or has no elements.

Apply this diff to fix the issue:

+if (waterConnection != null && !waterConnection.isEmpty()) {
    AuditDetails auditDetails = waterConnection.get(0).getAuditDetails();
+} else {
+    // Handle the scenario where waterConnection is null or empty
+    throw new CustomException("WATER_CONNECTION_NOT_FOUND", "No water connections found for the given criteria");
+}

Committable suggestion was skipped due to low confidence.

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.

1 participant