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

Added failed connection logic in generate demand Bulk topic #884

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

Conversation

debasishchakraborty-egovt
Copy link
Collaborator

@debasishchakraborty-egovt debasishchakraborty-egovt commented Aug 7, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced demand generation process with improved date handling.
    • Introduced modern date-time management for clarity and error reduction.
    • Added robust checks for demand and connection existence, enhancing reliability.
    • Improved messaging capabilities with the integration of Kafka support.
  • Configuration Changes

    • New Kafka consumer and producer properties added for improved session management and configurability.
    • Minor formatting improvement in the application properties file.
  • Bug Fixes

    • Improved logging for better traceability and debugging of operations.
    • Updated logic for processing demand and connection checks to strengthen reliability.

Copy link

coderabbitai bot commented Aug 7, 2024

Walkthrough

Recent changes modernize the DemandGenerationConsumer class by integrating KafkaTemplate for enhanced message handling and transitioning from Calendar to LocalDate and LocalDateTime for date management. This improves clarity and reduces errors. The demand generation process is strengthened with refined checks for existence and expanded logging for better traceability. New Kafka configuration properties optimize message processing, ensuring increased operational reliability and visibility.

Changes

Files Change Summary
.../DemandGenerationConsumer.java Integrated KafkaTemplate for messaging; refactored to use LocalDate and LocalDateTime; improved checks for demand and connection existence; enhanced logging for operational visibility.
.../application.properties Added new Kafka consumer and producer properties for message acknowledgment, batching, and memory management; ensured proper file formatting.

Poem

In a world of dates and queues,
The Rabbit hops with joyful news!
With clearer paths and logs so bright,
Demand flows smoothly, what a delight!
Kafka hums, settings are grand,
A leap of joy, all systems stand! 🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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 8c3ad62 and 4621328.

Files selected for processing (2)
  • municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (6 hunks)
  • municipal-services/ws-calculator/src/main/resources/application.properties (1 hunks)
Additional comments not posted (12)
municipal-services/ws-calculator/src/main/resources/application.properties (3)

163-163: LGTM!

The spring.kafka.consumer.session.timeout.ms property is correctly set to 30000.


164-164: LGTM!

The spring.kafka.consumer.heartbeat.interval.ms property is correctly set to 10000.


165-165: LGTM!

The spring.kafka.consumer.max.poll.interval.ms property is correctly set to 600000.

municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (9)

277-277: LGTM!

The commented-out code using Calendar has been replaced with a more modern and clear approach using LocalDate and LocalDateTime.


Line range hint 305-315: LGTM!

The commented-out code for checking demand and connection existence in the previous billing cycle has been removed, simplifying the logic.


610-611: LGTM!

The DateTimeFormatter is correctly defined for parsing dates.


613-614: LGTM!

The LocalDate instances for fromDate and toDate are correctly parsed from the billingCycle.


616-621: LGTM!

The LocalDateTime instances for dayStartTime and dayEndTime are correctly calculated.


633-647: LGTM!

The logic for checking demand and connection existence and generating demand has been improved and is clear.


580-587: LGTM!

The detailed logging statements enhance traceability and debugging.


588-590: LGTM!

The updateAddPenalty method correctly processes the DemandRequest and updates the penalty.


Line range hint 591-600: LGTM!

The added check for excluded tenants adds robustness to the demand generation process.

Comment on lines 622 to 631
Calendar previousFromDate = Calendar.getInstance();
Calendar previousToDate = Calendar.getInstance();

previousFromDate.setTimeInMillis(dayStartTime);
previousToDate.setTimeInMillis(dayEndTime);

previousFromDate.add(Calendar.MONTH, -1); //assuming billing cycle will be first day of month
previousToDate.add(Calendar.MONTH, -1);
int max = previousToDate.getActualMaximum(Calendar.DAY_OF_MONTH);
previousToDate.set(Calendar.DAY_OF_MONTH, max);
Copy link

Choose a reason for hiding this comment

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

Consider removing redundant code.

The Calendar instances for previousFromDate and previousToDate are still being used, which seems redundant given the new LocalDate approach.

-		Calendar previousFromDate = Calendar.getInstance();
-		Calendar previousToDate = Calendar.getInstance();
-		previousFromDate.setTimeInMillis(dayStartTime);
-		previousToDate.setTimeInMillis(dayEndTime);
-		previousFromDate.add(Calendar.MONTH, -1); //assuming billing cycle will be first day of month
-		previousToDate.add(Calendar.MONTH, -1);
-		int max = previousToDate.getActualMaximum(Calendar.DAY_OF_MONTH);
-		previousToDate.set(Calendar.DAY_OF_MONTH, max);
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
Calendar previousFromDate = Calendar.getInstance();
Calendar previousToDate = Calendar.getInstance();
previousFromDate.setTimeInMillis(dayStartTime);
previousToDate.setTimeInMillis(dayEndTime);
previousFromDate.add(Calendar.MONTH, -1); //assuming billing cycle will be first day of month
previousToDate.add(Calendar.MONTH, -1);
int max = previousToDate.getActualMaximum(Calendar.DAY_OF_MONTH);
previousToDate.set(Calendar.DAY_OF_MONTH, max);

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4621328 and e356e3d.

Files selected for processing (1)
  • municipal-services/ws-calculator/src/main/resources/application.properties (1 hunks)
Files skipped from review due to trivial changes (1)
  • municipal-services/ws-calculator/src/main/resources/application.properties

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

Outside diff range, codebase verification and nitpick comments (5)
municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (5)

272-274: Consider refining logging messages.

The logging message for the time taken to get connections could be more descriptive. Consider including the tenant ID or other context to make logs more informative.

- log.info("Time taken for the for Get Connetions : "+(System.currentTimeMillis()-StartTimeForGetConnetion)/1000+ " Secondss");
+ log.info("Time taken to retrieve connections for tenantId {}: {} seconds", tenantId, (System.currentTimeMillis()-StartTimeForGetConnetion)/1000);

290-294: Clarify logging message for MDMS data retrieval.

The log message for MDMS data retrieval time could include additional context, such as the tenant ID.

- log.info("Time taken for the for Get Mdms Data : "+(System.currentTimeMillis()-startTimeForMdms)/1000+ " Secondss");
+ log.info("Time taken to retrieve MDMS data for tenantId {}: {} seconds", tenantId, (System.currentTimeMillis()-startTimeForMdms)/1000);

Line range hint 297-335:
Optimize loop logging.

The log message for the loop execution time could be more descriptive by including the number of connections processed.

- log.info("Time taken for the for loop : "+(System.currentTimeMillis()-startTimeForLoop)/1000+ " Secondss");
+ log.info("Time taken to process {} connections: {} seconds", connectionNos.size(), (System.currentTimeMillis()-startTimeForLoop)/1000);

371-371: Clarify notification logging message.

The log message for notification time could include additional context, such as the tenant ID or the number of notifications sent.

- log.info("Time taken for notification : "+(System.currentTimeMillis()-starttimeforNotification)/1000+ " Secondss");
+ log.info("Time taken to send notifications for tenantId {}: {} seconds", tenantId, (System.currentTimeMillis()-starttimeforNotification)/1000);

585-592: Enhance logging for demand generation.

The log messages for demand generation could be more informative by including additional context, such as the number of demands generated.

- log.info("CALL FROM TOPIC egov.generate.bulk.demand.manually.topic for tenantid:" + bulkDemand.getTenantId() + " BillPeriod:" + billingPeriod + " Start Time:" + System.currentTimeMillis());
- log.info("time takenn to generate demand for Tenantid:" + bulkDemand.getTenantId() + " BillPeriod:" + billingPeriod + " is : " + diff/1000 +" seconds");
+ log.info("Bulk demand generation started for tenantId: {}, billingPeriod: {}, startTime: {}", bulkDemand.getTenantId(), billingPeriod, System.currentTimeMillis());
+ log.info("Time taken to generate demand for tenantId: {}, billingPeriod: {}: {} seconds", bulkDemand.getTenantId(), billingPeriod, diff/1000);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e356e3d and 6402055.

Files selected for processing (2)
  • municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (8 hunks)
  • municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/WSCalculationDaoImpl.java (1 hunks)
Additional comments not posted (3)
municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/WSCalculationDaoImpl.java (1)

130-131: Logging Enhancement Approved.

The added logging statements for the SQL query and prepared statement parameters will improve traceability and debugging capabilities.

municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (2)

Line range hint 278-287:
Remove commented-out code.

The code block using the Calendar class is commented out. If it's no longer needed, consider removing it to keep the codebase clean.


615-652: Consider removing redundant Calendar usage.

The Calendar instances for previousFromDate and previousToDate are redundant given the new LocalDate approach.

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

Outside diff range, codebase verification and nitpick comments (1)
municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (1)

594-596: Improve Exception Handling in DemandGenerationConsumer

The DemandGenerationConsumer.java file contains exception handling that uses e.printStackTrace() and System.out.println(). These are not suitable for production environments. Consider implementing proper logging and handling mechanisms to ensure robustness and maintainability.

  • File: municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java
    • Lines with inadequate handling:
      • e.printStackTrace();
      • System.out.println("Got the exception while generating the demands:" + e);
Analysis chain

Verify exception handling comprehensiveness.

Ensure that all potential exceptions are adequately handled to prevent unexpected failures during demand generation.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify exception handling in `generateBulkDemandForULB`.

# Test: Search for exception handling patterns. Expect: Comprehensive handling of exceptions.
rg --type java 'catch \(Exception e\)' -A 3

Length of output: 66093

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6402055 and 5a1b561.

Files selected for processing (2)
  • municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (8 hunks)
  • municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/WSCalculationServiceImpl.java (1 hunks)
Files skipped from review due to trivial changes (1)
  • municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/WSCalculationServiceImpl.java
Additional comments not posted (4)
municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (4)

272-274: LGTM: Use of modern date-time API.

The transition to LocalDate and LocalDateTime improves code clarity and reduces potential errors associated with Calendar.


Line range hint 278-287:
Remove redundant Calendar code.

The Calendar instances are commented out and no longer needed. Consider removing this code to clean up the file.


644-655: LGTM: Logic for checking demands and connections.

The logic for verifying the existence of demands and connections is well-implemented and enhances the robustness of the demand generation process.


589-596: LGTM: Logging enhancements.

The logging of start and end times for demand generation is beneficial for monitoring and debugging.

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 5a1b561 and 9cf61b5.

Files selected for processing (1)
  • municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (10 hunks)
Additional comments not posted (6)
municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (6)

75-76: KafkaTemplate Injection Looks Good.

The injection of KafkaTemplate is appropriate for handling Kafka messages. Ensure that the KafkaTemplate is properly configured in the application context.


276-278: Logging Enhancements Approved.

The detailed timing logs enhance the ability to monitor performance and identify bottlenecks.


Line range hint 282-291: Commented-Out Calendar Code Approved.

Commenting out the Calendar code aligns with the transition to LocalDate. Ensure all relevant code uses the modern date-time API.


338-340: Kafka Message Production Approved.

The use of producer.push for Kafka message handling is appropriate. Ensure that messages are validated and errors are handled properly.


374-374: KafkaTemplate Usage for SMS Notifications Approved.

The integration of kafkaTemplate for sending SMS notifications is appropriate. Ensure the SMS notification topic is correctly configured.


593-600: Logging Enhancements Approved.

The detailed logs provide valuable insights into the demand generation process, aiding in debugging and performance monitoring.

Comment on lines 635 to 644
Calendar previousFromDate = Calendar.getInstance();
Calendar previousToDate = Calendar.getInstance();

previousFromDate.setTimeInMillis(dayStartTime);
previousToDate.setTimeInMillis(dayEndTime);

previousFromDate.add(Calendar.MONTH, -1); //assuming billing cycle will be first day of month
previousToDate.add(Calendar.MONTH, -1);
int max = previousToDate.getActualMaximum(Calendar.DAY_OF_MONTH);
previousToDate.set(Calendar.DAY_OF_MONTH, max);
Copy link

Choose a reason for hiding this comment

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

Refactor Calendar Usage to LocalDate.

Replace Calendar with LocalDate for consistency and to leverage the modern date-time API.

LocalDate previousFromDate = fromDate.minusMonths(1);
LocalDate previousToDate = toDate.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth());

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9cf61b5 and 0c673b8.

Files selected for processing (1)
  • municipal-services/ws-calculator/src/main/resources/application.properties (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • municipal-services/ws-calculator/src/main/resources/application.properties

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

Outside diff range, codebase verification and nitpick comments (1)
municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (1)

Line range hint 282-291: Remove Commented-Out Calendar Code.

The transition to LocalDate is beneficial, but the commented-out Calendar code should be removed for code cleanliness.

-	/*	Calendar previousFromDate = Calendar.getInstance();
-	Calendar previousToDate = Calendar.getInstance();
-	
-	previousFromDate.setTimeInMillis(dayStartTime);
-	previousToDate.setTimeInMillis(dayEndTime);
-
-	previousFromDate.add(Calendar.MONTH, -1); //assuming billing cycle will be first day of month
-	previousToDate.add(Calendar.MONTH, -1); 
-	int max = previousToDate.getActualMaximum(Calendar.DAY_OF_MONTH);
-	previousToDate.set(Calendar.DAY_OF_MONTH, max);*/
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0c673b8 and 75277c3.

Files selected for processing (2)
  • municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (10 hunks)
  • municipal-services/ws-calculator/src/main/resources/application.properties (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • municipal-services/ws-calculator/src/main/resources/application.properties
Additional comments not posted (6)
municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (6)

40-40: KafkaTemplate Import Addition Approved.

The addition of KafkaTemplate is a positive change, leveraging Spring's Kafka support for better message handling.


75-76: KafkaTemplate Field Addition Approved.

Introducing KafkaTemplate as a field is a good practice for managing Kafka message production within the Spring framework.


276-278: Logging Additions Approved.

The added logging statements enhance the method's traceability and performance monitoring.


635-644: Refactor Calendar Usage to LocalDate.

Replace Calendar with LocalDate for consistency and to leverage the modern date-time API.

LocalDate previousFromDate = fromDate.minusMonths(1);
LocalDate previousToDate = toDate.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth());

654-659: Logging Additions Approved.

The detailed logging for request processing time is beneficial for performance monitoring and debugging.


593-600: Logging Additions Approved.

The logging for manual demand generation provides valuable information for tracking and debugging.

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

Outside diff range, codebase verification and nitpick comments (1)
municipal-services/ws-calculator/src/main/resources/application.properties (1)

165-165: Potential Issue: ws.generate.demand.bulk topic not utilized in codebase.

The Kafka topic ws-generate-demand-bulk is defined in the application.properties file, but there are no references to it in the Java or Kotlin codebase. Please verify if this topic is used elsewhere or if it is intended for future use.

  • Ensure the topic is utilized in the application logic or remove it if unnecessary.
Analysis chain

Configuration approved: ws.generate.demand.bulk=ws-generate-demand-bulk.

Ensure that this Kafka topic is correctly configured and utilized in the application.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `ws.generate.demand.bulk` topic in the codebase.

# Test: Search for the topic usage. Expect: Occurrences of the topic in the codebase.
rg --type java --type kotlin 'ws-generate-demand-bulk'

Length of output: 177

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 75277c3 and b9fe4c4.

Files selected for processing (1)
  • municipal-services/ws-calculator/src/main/resources/application.properties (2 hunks)
Additional comments not posted (5)
municipal-services/ws-calculator/src/main/resources/application.properties (5)

25-25: Configuration approved: spring.kafka.producer.linger.ms=10.

This setting is appropriate for balancing latency and throughput in Kafka message production.


26-26: Configuration approved: spring.kafka.producer.batch.size=32768.

This batch size is reasonable for balancing throughput and resource usage.


27-27: Configuration approved: spring.kafka.producer.buffer.memory=33554432.

This buffer size is suitable for managing memory usage and ensuring smooth message production.


28-28: Configuration approved: spring.kafka.consumer.session.timeout.ms=30000.

This timeout value is appropriate for ensuring consumer session stability.


29-29: Configuration approved: spring.kafka.consumer.heartbeat.interval.ms=10000.

This interval is suitable for maintaining consumer session health and should be less than the session timeout.

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 b9fe4c4 and 3ffcc52.

Files selected for processing (2)
  • municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (9 hunks)
  • municipal-services/ws-calculator/src/main/resources/application.properties (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • municipal-services/ws-calculator/src/main/resources/application.properties
Additional comments not posted (4)
municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java (4)

75-77: LGTM!

The addition of KafkaTemplate looks good and aligns with the PR objectives.


Line range hint 276-294:
LGTM!

The use of LocalDate and LocalDateTime for date handling is a good improvement over the Calendar API.


588-595: LGTM!

The logging improvements provide better visibility into the demand generation process.


618-654: LGTM!

The method correctly processes messages and updates demands with penalties.

Comment on lines +630 to +639
Calendar previousFromDate = Calendar.getInstance();
Calendar previousToDate = Calendar.getInstance();

log.info("got generate demand call for :"+calculationReq.getCalculationCriteria().get(0).getConnectionNo());
generateDemandInBulk(calculationReq,billingCycle,masterMap,isSendMessage,tenantId);
previousFromDate.setTimeInMillis(dayStartTime);
previousToDate.setTimeInMillis(dayEndTime);

previousFromDate.add(Calendar.MONTH, -1); //assuming billing cycle will be first day of month
previousToDate.add(Calendar.MONTH, -1);
int max = previousToDate.getActualMaximum(Calendar.DAY_OF_MONTH);
previousToDate.set(Calendar.DAY_OF_MONTH, max);
Copy link

Choose a reason for hiding this comment

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

Refactor Calendar Usage to LocalDate.

Replace Calendar with LocalDate for consistency and to leverage the modern date-time API.

LocalDate previousFromDate = fromDate.minusMonths(1);
LocalDate previousToDate = toDate.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth());

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