-
Notifications
You must be signed in to change notification settings - Fork 20
Conversation
ISTE-345: Added chnages to remove multiple call to fetch bill API .
WalkthroughThe changes involve significant refactoring of the Changes
Possibly related PRs
Suggested reviewers
Poem
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: 9
🧹 Outside diff range and nitpick comments (5)
municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillResponseV2.java (1)
14-22
: Enhance the class-level comment for better documentation.The current class-level comment is not very descriptive. Consider expanding it to provide more information about the purpose and usage of this class, especially since it appears to be a new version.
Here's a suggested improvement:
/** * BillResponseV2 * * This class represents the response structure for bill-related operations in version 2 of the API. * It encapsulates response information and a collection of bills. */municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillV2.java (4)
31-33
: Consider adding validation touserId
fieldThe
userId
field lacks validation annotations. Adding@Size(max = 256)
or other appropriate constraints will ensure consistency and data integrity across your model.
50-52
: Ensurestatus
field is not nullIf the
status
field is mandatory for the application's logic, consider adding the@NotNull
annotation to enforce this constraint.
64-66
: Consider validatingbillDate
fieldIf
billDate
is a required field, add the@NotNull
annotation to ensure it is always provided.
85-87
: Add@Valid
annotation toauditDetails
fieldIncluding the
@Valid
annotation ensures that the fields withinauditDetails
are also validated according to their constraints.Apply this diff:
@JsonProperty("auditDetails") +@Valid private AuditDetails auditDetails;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
- municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandService.java (6 hunks)
- municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillDetailV2.java (1 hunks)
- municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillResponseV2.java (1 hunks)
- municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillV2.java (1 hunks)
✅ Files skipped from review due to trivial changes (1)
- municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillDetailV2.java
🧰 Additional context used
🔇 Additional comments (1)
municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillResponseV2.java (1)
3-12
: Import statements look good.The import statements are appropriate and follow good practices:
- Necessary classes are imported from standard Java libraries and project-specific packages.
- Lombok annotations are imported individually, which is preferred over wildcard imports.
@JsonProperty("ResposneInfo") | ||
private ResponseInfo resposneInfo = null; |
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.
Fix typo in field name and JsonProperty value.
There's a typo in the field name resposneInfo
and its corresponding @JsonProperty
value. This could lead to issues with JSON serialization/deserialization.
Apply this diff to fix the typo:
- @JsonProperty("ResposneInfo")
- private ResponseInfo resposneInfo = null;
+ @JsonProperty("ResponseInfo")
+ private ResponseInfo responseInfo = null;
📝 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.
@JsonProperty("ResposneInfo") | |
private ResponseInfo resposneInfo = null; | |
@JsonProperty("ResponseInfo") | |
private ResponseInfo responseInfo = null; |
@JsonProperty("billDetails") | ||
@Valid | ||
private List<BillDetailV2> billDetails; |
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
Initialize billDetails
to prevent null pointer exceptions
To avoid potential NullPointerException
when accessing billDetails
, initialize the list upon declaration.
Apply this diff to initialize billDetails
:
@JsonProperty("billDetails")
@Valid
-private List<BillDetailV2> billDetails;
+private List<BillDetailV2> billDetails = new ArrayList<>();
📝 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.
@JsonProperty("billDetails") | |
@Valid | |
private List<BillDetailV2> billDetails; | |
@JsonProperty("billDetails") | |
@Valid | |
private List<BillDetailV2> billDetails = new ArrayList<>(); |
@JsonProperty("payerEmail") | ||
@Size(max = 256) | ||
private String payerEmail; |
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.
Add email validation to payerEmail
field
The payerEmail
field should be validated to ensure it contains a valid email address. Consider using the @Email
annotation from javax.validation.constraints
.
Apply this diff to add email validation:
@JsonProperty("payerEmail")
@Size(max = 256)
+@Email(message = "Invalid email format")
private String payerEmail;
📝 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.
@JsonProperty("payerEmail") | |
@Size(max = 256) | |
private String payerEmail; | |
@JsonProperty("payerEmail") | |
@Size(max = 256) | |
@Email(message = "Invalid email format") | |
private String payerEmail; |
@JsonProperty("totalAmount") | ||
private BigDecimal totalAmount; | ||
|
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.
Add validation to totalAmount
field
To prevent issues with billing calculations, ensure that totalAmount
is not null and is a non-negative value.
Apply this diff to add validation constraints:
@JsonProperty("totalAmount")
+@NotNull(message = "Total amount is required")
+@DecimalMin(value = "0.0", inclusive = true, message = "Total amount cannot be negative")
private BigDecimal totalAmount;
📝 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.
@JsonProperty("totalAmount") | |
private BigDecimal totalAmount; | |
@JsonProperty("totalAmount") | |
@NotNull(message = "Total amount is required") | |
@DecimalMin(value = "0.0", inclusive = true, message = "Total amount cannot be negative") | |
private BigDecimal totalAmount; | |
public static BillStatus fromValue(String text) { | ||
for (BillStatus b : BillStatus.values()) { | ||
if (String.valueOf(b.value).equalsIgnoreCase(text)) { | ||
return b; | ||
} | ||
} | ||
return null; | ||
} |
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.
Handle invalid inputs in BillStatus.fromValue
method
Returning null
for unrecognized values may lead to NullPointerException
. Throwing an exception provides clearer feedback about invalid input.
Apply this diff to throw an exception for invalid values:
return null;
+throw new IllegalArgumentException("Unexpected value '" + text + "' for BillStatus");
📝 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.
public static BillStatus fromValue(String text) { | |
for (BillStatus b : BillStatus.values()) { | |
if (String.valueOf(b.value).equalsIgnoreCase(text)) { | |
return b; | |
} | |
} | |
return null; | |
} | |
public static BillStatus fromValue(String text) { | |
for (BillStatus b : BillStatus.values()) { | |
if (String.valueOf(b.value).equalsIgnoreCase(text)) { | |
return b; | |
} | |
} | |
throw new IllegalArgumentException("Unexpected value '" + text + "' for BillStatus"); | |
} |
if (!CollectionUtils.isEmpty(bills)) { | ||
String billNumber = bills.get(0).getBillNumber(); | ||
Long billDate = bills.get(0).getBillDate(); | ||
billDate = billDate + 1296000000l; |
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
Replace magic number with named constant or use TimeUnit
for clarity
The code uses a magic number 1296000000l
, which reduces readability and maintainability. Consider using TimeUnit.DAYS.toMillis(15)
or defining a named constant for better clarity.
Apply this diff to enhance readability:
- billDate = billDate + 1296000000l;
+ billDate = billDate + TimeUnit.DAYS.toMillis(15);
Alternatively, define a constant:
+ private static final long FIFTEEN_DAYS_IN_MILLIS = TimeUnit.DAYS.toMillis(15);
And update the code:
- billDate = billDate + 1296000000l;
+ billDate = billDate + FIFTEEN_DAYS_IN_MILLIS;
boolean notificationSent = false; | ||
List<String> billNumber = new ArrayList<>(); | ||
public List<BillV2> fetchBill(List<Demand> demandResponse, RequestInfo requestInfo) { | ||
boolean notificationSent = false; new ArrayList<>(); |
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.
Fix syntax error: invalid statement new ArrayList<>()
The statement new ArrayList<>();
is not valid where it currently appears. It seems like an incomplete variable initialization.
Apply this diff to fix the issue:
- boolean notificationSent = false; new ArrayList<>();
+ boolean notificationSent = false;
If you intended to initialize bills
, consider initializing it as follows:
List<BillV2> bills = new ArrayList<>();
LocalDate billDateLocal = Instant.ofEpochMilli(billDate).atZone(ZoneId.systemDefault()).toLocalDate(); | ||
String paymentDueDate = billDateLocal.format(dateTimeFormatter); | ||
BigDecimal totalAmount=bills.get(0).getTotalAmount(); | ||
if (ObjectUtils.isEmpty(totalAmount) && totalAmount.signum() > 0) { |
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.
Fix potential NullPointerException
in null check condition
The condition may throw a NullPointerException
if totalAmount
is null because totalAmount.signum()
is called without a prior null check.
Apply this diff to fix the condition:
- if (ObjectUtils.isEmpty(totalAmount) && totalAmount.signum() > 0) {
+ if (totalAmount != null && totalAmount.signum() > 0) {
📝 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.
if (ObjectUtils.isEmpty(totalAmount) && totalAmount.signum() > 0) { | |
if (totalAmount != null && totalAmount.signum() > 0) { |
@@ -371,8 +365,8 @@ private void sendDownloadBillSMSNotification(RequestInfo requestInfo, String ten | |||
//System.out.println("Localization message get bill::" + messageString); | |||
//System.out.println("isForConnectionNO:" + isForConnectionNO); | |||
if (!StringUtils.isEmpty(messageString) && isForConnectionNO) { | |||
if (totalamount!=null && billNumbers.size() > 0 && totalamount.signum()>0) { | |||
actionLink = actionLink.replace("$billNumber", billNumbers.get(0)); | |||
if (totalamount!=null && totalamount.signum()>0) { |
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 consistent variable naming for totalAmount
The variable totalamount
should be renamed to totalAmount
to maintain consistency and adhere to naming conventions.
Apply this diff to fix the variable name:
- if (totalamount != null && totalamount.signum() > 0) {
+ if (totalAmount != null && totalAmount.signum() > 0) {
Also, update the method parameter and all usages within the method to use totalAmount
.
Committable suggestion was skipped due to low confidence.
Summary by CodeRabbit
BillV2
class to represent billing entities with enhanced attributes.BillResponseV2
to encapsulate response information and a collection of bills.BillDetailV2
class created for future development.fetchBill
method to return structured bill data.