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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,15 @@ private List<String> getIdList(RequestInfo requestInfo, String tenantId, String
*
* @param waterConnectionRequest WaterConnectionRequest Object
*/
public void enrichUpdateWaterConnection(WaterConnectionRequest waterConnectionRequest) {
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());
}

Comment on lines +201 to +209
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.

waterConnectionRequest.getWaterConnection().setAuditDetails(auditDetails);
WaterConnection connection = waterConnectionRequest.getWaterConnection();
if (!CollectionUtils.isEmpty(connection.getDocuments())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

if(waterConnection != null && waterConnection.size() > 0) {
throw new CustomException("DUPLICATE_OLD_CONNECTION_NUMBER",
"Duplicate Old connection number");
Expand All @@ -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.

actionValidator.validateUpdateRequest(waterConnectionRequest, businessService, previousApplicationStatus);
waterConnectionValidator.validateUpdate(waterConnectionRequest, searchResult, WCConstants.UPDATE_APPLICATION);
userService.updateUser(waterConnectionRequest, searchResult);
Expand Down Expand Up @@ -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.

if(waterConnection != null && waterConnection.size() > 0 && !waterConnectionRequest.getWaterConnection().getConnectionNo()
.equalsIgnoreCase(waterConnection.get(0).getConnectionNo())) {
throw new CustomException("DUPLICATE_OLD_CONNECTION_NUMBER",
Expand All @@ -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.

actionValidator.validateUpdateRequest(waterConnectionRequest, businessService, previousApplicationStatus);
userService.updateUser(waterConnectionRequest, searchResult);
waterConnectionValidator.validateUpdate(waterConnectionRequest, searchResult, WCConstants.MODIFY_CONNECTION);
Expand Down