-
Notifications
You must be signed in to change notification settings - Fork 20
[ISNE-304] - set createdtime and createdby in audit details for demand and water reindexing #977
Conversation
Iste 487: Resolved CSS Issue of common page
[ISNE-304] - set createdtime and createdby in audit details for demand and water reindexing
WalkthroughThe 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 Changes
Possibly related PRs
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
andcreatedTime
fields ofcurrentAuditDetails
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 setsThe
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:
- Add pagination parameters (page number and page size) to the
DemandCriteria
class.- Modify the
demandRepository.getDemands
method to support pagination.- 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 loggingThe current implementation could benefit from more robust error handling and logging, especially in critical sections like demand creation, updating, and searching.
- Wrap critical operations in try-catch blocks to handle specific exceptions.
- Use a logging framework consistently throughout the class to log important events and errors.
- 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 dataThe 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:
- Use a caching solution like Ehcache or Redis.
- Cache user data retrieved from the user service.
- 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 classThe 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:
- Implement pagination for large result sets to enhance performance and scalability.
- Enhance error handling and logging for better debuggability and robustness.
- Consider implementing caching for frequently accessed data to reduce load on external services.
- 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
📒 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
AuditDetails currAuditDetails=demands.get(0).getAuditDetails(); | ||
AuditDetails auditDetail = util.getAuditDetail(requestInfo); | ||
if (currAuditDetails != null) { | ||
auditDetail.setCreatedTime(currAuditDetails.getCreatedTime()); | ||
auditDetail.setCreatedBy(currAuditDetails.getCreatedBy()); | ||
} |
There was a problem hiding this comment.
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:
- 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. - There's no null check on
currAuditDetails.getCreatedTime()
andcurrAuditDetails.getCreatedBy()
before setting them inauditDetail
.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Check condition on auditdetails
There was a problem hiding this 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 accessingcurrAuditDetails
propertiesWhile there's a null check for
currAuditDetails
, there are no checks forcurrAuditDetails.getCreatedTime()
andcurrAuditDetails.getCreatedBy()
. If either of these properties isnull
, it could cause aNullPointerException
. 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
📒 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
for (Demand demand : demands) { | ||
AuditDetails currAuditDetails = demand.getAuditDetails(); | ||
if (currAuditDetails != null) { | ||
auditDetail.setCreatedTime(currAuditDetails.getCreatedTime()); | ||
auditDetail.setCreatedBy(currAuditDetails.getCreatedBy()); | ||
} | ||
demand.setAuditDetails(auditDetail); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation