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

Develop #797

Merged
merged 19 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
97df349
PFM-5638: Added the PenaltyApplicabledays from penalty master call.
May 21, 2024
2581ecc
ISTE-44: Added demand change audit logs from ws-calculator service
May 22, 2024
a676686
ISTE-44: Added demand change audit logs from ws-calculator service
May 22, 2024
6b35ee8
ISTE-44: Added demand change audit logs from ws-calculator service
May 22, 2024
370fb9f
ISTE-44: Added demand change audit db script from ws-calculator service
May 23, 2024
1fe1efb
ISTE-44: Added demand change audit db script from ws-calculator service
May 23, 2024
a3028b4
ISTE-44: Added demand change audit db script from ws-calculator service
May 23, 2024
0d7ae0f
ISTE-44: Added demand change audit db script from ws-calculator service
May 23, 2024
7ac1b31
ISTE-44: Added demand change audit db script from ws-calculator service
May 23, 2024
95bac77
ISTE-44: Added demand change audit db script from ws-calculator service
May 23, 2024
a081c68
ISTE-44: Added demand change audit db script from ws-calculator service
May 23, 2024
57f1da3
ISTE-44: Added demand change audit db script from ws-calculator service
May 23, 2024
2e378d7
ISTE-44: Added demand change audit db script from ws-calculator service
May 23, 2024
84c182e
ISTE-44: Added demand change audit db script from ws-calculator service
May 23, 2024
5c04bbe
ISTE-44: Added demand change audit db script from ws-calculator service
May 24, 2024
f47749b
ISTE-44: Added demand change audit db script from ws-calculator service
May 24, 2024
3504cdd
ISTE-44: Added demand change audit db script from ws-calculator service
May 24, 2024
f87fb13
ISTE-44: Added demand change audit db script from ws-calculator service
May 24, 2024
44cf702
Merge pull request #794 from egovernments/ISTE-44-fix
pradeepkumarcm-egov May 27, 2024
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 @@ -249,5 +249,10 @@ public class WSCalculationConfiguration {

@Value("${sms.exclude.tenant}")
private String smsExcludeTenant;


@Value("${is.save.demand.audit.enabled}")
private boolean isSaveDemandAuditEnabled;

@Value("${egov.save.demand.audit.from.wscal}")
private String saveDemandAudit;
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private void generateDemandAndSendnotification(RequestInfo requestInfo, String t
}

} catch (Exception e) {
System.out.println("Got the exception while genating the demands:" + connectionNo);
System.out.println("Got the exception while genating the demands:" + e);
Copy link

Choose a reason for hiding this comment

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

Improve exception handling by logging the exception details.

- System.out.println("Got the exception while genating the demands:" + e);
+ log.error("Got the exception while generating the demands:", e);

This change aligns with the PR's objective to improve exception handling by including the exception itself in the message, rather than just printing it to the console. This will help in better debugging and maintaining the logs.


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.

Suggested change
System.out.println("Got the exception while genating the demands:" + e);
log.error("Got the exception while generating the demands:", e);

Consider rethrowing the exception or handling it more comprehensively.

- e.printStackTrace();
+ throw new CustomException("DEMAND_GENERATION_ERROR", "Error occurred during demand generation", e);

This change would allow the exception to be handled or logged by the caller, providing more flexibility in managing errors and aligning with the PR's focus on improved exception handling.

Committable suggestion was skipped due low confidence.


Add type and null checks to prevent potential ClassCastException or NullPointerException.

- HashMap<Object, Object> demandData = (HashMap<Object, Object>) messageData;
+ if (!(messageData instanceof HashMap)) {
+     throw new IllegalArgumentException("Expected message data to be of type HashMap");
+ }
+ HashMap<Object, Object> demandData = (HashMap<Object, Object>) messageData;
+ if (demandData.get("tenantId") == null || demandData.get("isSendMessage") == null) {
+     throw new IllegalArgumentException("Missing required keys in message data");
+ }

This change ensures that the message data is of the expected type and contains all required keys, thus preventing runtime exceptions and aligning with best practices for robust and secure code.


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.

Suggested change
System.out.println("Got the exception while genating the demands:" + e);
System.out.println("Got the exception while genating the demands:" + e);
if (!(messageData instanceof HashMap)) {
throw new IllegalArgumentException("Expected message data to be of type HashMap");
}
HashMap<Object, Object> demandData = (HashMap<Object, Object>) messageData;
if (demandData.get("tenantId") == null || demandData.get("isSendMessage") == null) {
throw new IllegalArgumentException("Missing required keys in message data");
}

Refactor to improve readability and maintainability.

- private void generateDemandAndSendnotification(RequestInfo requestInfo, String tenantId, String billingCycle,
-         Map<String, Object> master, boolean isSendMessage, boolean isManual) {
+ private void generateDemandAndSendnotification(DemandNotificationContext context) {
+     // Implementation using context object to hold all parameters
+ }

Refactoring this method to use a context object for passing parameters can simplify the method signature and improve readability. This change also helps in managing the method's complexity by encapsulating the parameters in a single object.

Committable suggestion was skipped due low confidence.

failedConnectionNos.add(connectionNo);
}
}
Expand Down Expand Up @@ -462,14 +462,12 @@ private void generateDemandAndSendnotification(RequestInfo requestInfo, String t
String msgLink = config.getNotificationUrl() + config.getGpUserDemandLink();

for (OwnerInfo userInfo : userDetailResponse.getUser()) {
log.info("USER NUMBER:" + userInfo.getMobileNumber() + " USER ROLE:" + userInfo.getRoles());
if (userInfo.getName() != null) {
mobileNumberIdMap.put(userInfo.getMobileNumber(), userInfo.getName());
} else {
mobileNumberIdMap.put(userInfo.getMobileNumber(), userInfo.getUserName());
}
}
log.info("MOBILENUMBER MAPPINNG USERROLE:" +mobileNumberIdMap);
mobileNumberIdMap.entrySet().stream().forEach(map -> {
String msg = demandMessage.get(WSCalculationConstant.MSG_KEY);
msg = msg.replace("{ownername}", map.getValue());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.egov.wscalculation.repository;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

@Component
@Slf4j
@Repository
public class DemandAuditSeqBuilder {

@Autowired
private JdbcTemplate jdbcTemplate;

public static final String SELECT_NEXT_SEQUENCE_USER = "select nextval('seq_eg_ws_demand_auditchange')";

public Long getNextSequence() {
return jdbcTemplate.queryForObject(SELECT_NEXT_SEQUENCE_USER, Long.class);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.egov.wscalculation.config.WSCalculationConfiguration;
import org.egov.wscalculation.constants.WSCalculationConstant;
import org.egov.wscalculation.producer.WSCalculationProducer;
import org.egov.wscalculation.repository.DemandAuditSeqBuilder;
import org.egov.wscalculation.repository.DemandRepository;
import org.egov.wscalculation.repository.ServiceRequestRepository;
import org.egov.wscalculation.repository.WSCalculationDao;
Expand All @@ -51,26 +52,8 @@
import org.egov.wscalculation.util.WSCalculationUtil;
import org.egov.wscalculation.validator.WSCalculationValidator;
import org.egov.wscalculation.validator.WSCalculationWorkflowValidator;
import org.egov.wscalculation.web.models.BulkDemand;
import org.egov.wscalculation.web.models.Calculation;
import org.egov.wscalculation.web.models.Category;
import org.egov.wscalculation.web.models.Demand;
import org.egov.wscalculation.web.models.*;
import org.egov.wscalculation.web.models.Demand.StatusEnum;
import org.egov.wscalculation.web.models.DemandDetail;
import org.egov.wscalculation.web.models.DemandDetailAndCollection;
import org.egov.wscalculation.web.models.DemandPenaltyResponse;
import org.egov.wscalculation.web.models.DemandRequest;
import org.egov.wscalculation.web.models.DemandResponse;
import org.egov.wscalculation.web.models.GetBillCriteria;
import org.egov.wscalculation.web.models.OwnerInfo;
import org.egov.wscalculation.web.models.Property;
import org.egov.wscalculation.web.models.Recipient;
import org.egov.wscalculation.web.models.RequestInfoWrapper;
import org.egov.wscalculation.web.models.SMSRequest;
import org.egov.wscalculation.web.models.TaxHeadEstimate;
import org.egov.wscalculation.web.models.TaxPeriod;
import org.egov.wscalculation.web.models.WaterConnection;
import org.egov.wscalculation.web.models.WaterConnectionRequest;
import org.egov.wscalculation.web.models.users.UserDetailResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -147,6 +130,9 @@ public class DemandService {
@Autowired
private EstimationService estimationService;

@Autowired
private DemandAuditSeqBuilder demandAuditSeqBuilder;

/**
* Creates or updates Demand
*
Expand Down Expand Up @@ -285,6 +271,22 @@ private List<Demand> createDemand(RequestInfo requestInfo, List<Calculation> cal
.businessService(businessService).status(StatusEnum.valueOf("ACTIVE")).billExpiryTime(expiryDate)
.build());
}

if(config.isSaveDemandAuditEnabled()){
demands.stream().forEach(demand -> {
Long id = demandAuditSeqBuilder.getNextSequence();
WsDemandChangeAuditRequest wsDemandChangeAuditRequest = WsDemandChangeAuditRequest.builder().id(id).
consumercode(demand.getConsumerCode()).
tenant_id(demand.getTenantId()).
status(demand.getStatus().toString()).
action("CREATE DEMAND BULK").
data(demand).
createdby(requestInfo.getUserInfo().getUuid()).
createdtime(System.currentTimeMillis()).build();
WsDemandChangeAuditRequestWrapper wsDemandChangeAuditRequestWrapper = WsDemandChangeAuditRequestWrapper.builder().wsDemandChangeAuditRequest(wsDemandChangeAuditRequest).build();
producer.push(config.getSaveDemandAudit(), wsDemandChangeAuditRequestWrapper);
});
}
demandRes = demandRepository.saveDemand(requestInfo, demands);
finalDemandRes.addAll(demandRes);

Expand Down Expand Up @@ -887,6 +889,21 @@ public List<Demand> updateDemands(GetBillCriteria getBillCriteria, RequestInfoWr
// Call demand update in bulk to update the interest or penalty
if(!isGetPenaltyEstimate) {
if(demandsToBeUpdated.size() > 0) {
if(config.isSaveDemandAuditEnabled()){
demandsToBeUpdated.stream().forEach(demand -> {
Long id = demandAuditSeqBuilder.getNextSequence();
WsDemandChangeAuditRequest wsDemandChangeAuditRequest = WsDemandChangeAuditRequest.builder().id(id).
consumercode(demand.getConsumerCode()).
tenant_id(demand.getTenantId()).
status(demand.getStatus().toString()).
action("UPDATE DEMAND GET PENALTY/UPDATE API").
data(demand).
createdby(demand.getAuditDetails().getCreatedBy()).
createdtime(demand.getAuditDetails().getLastModifiedTime()).build();
WsDemandChangeAuditRequestWrapper wsDemandChangeAuditRequestWrapper = WsDemandChangeAuditRequestWrapper.builder().wsDemandChangeAuditRequest(wsDemandChangeAuditRequest).build();
producer.push(config.getSaveDemandAudit(), wsDemandChangeAuditRequestWrapper);
});
}
DemandRequest request = DemandRequest.builder().demands(demandsToBeUpdated).requestInfo(requestInfo).build();
repository.fetchResult(utils.getUpdateDemandUrl(), request);
return res.getDemands();
Expand Down Expand Up @@ -946,6 +963,22 @@ private List<Demand> updateDemandForCalculation(RequestInfo requestInfo, List<Ca
.tenantId(calculation.getTenantId()).build());
});
demands.add(demand);
//TODO: write logic to enter in new table
if(config.isSaveDemandAuditEnabled()){
demands.stream().forEach(dem -> {
Long id = demandAuditSeqBuilder.getNextSequence();
WsDemandChangeAuditRequest wsDemandChangeAuditRequest = WsDemandChangeAuditRequest.builder().id(id).
consumercode(dem.getConsumerCode()).
tenant_id(dem.getTenantId()).
status(dem.getStatus().toString()).
action("UPDATE DEMAND BULK").
data(dem).
createdby(dem.getAuditDetails().getCreatedBy()).
createdtime(dem.getAuditDetails().getLastModifiedTime()).build();
WsDemandChangeAuditRequestWrapper wsDemandChangeAuditRequestWrapper = WsDemandChangeAuditRequestWrapper.builder().wsDemandChangeAuditRequest(wsDemandChangeAuditRequest).build();
producer.push(config.getSaveDemandAudit(), wsDemandChangeAuditRequestWrapper);
});
}
demandRes = demandRepository.updateDemand(requestInfo, demands);
finalDemandRes.addAll(demandRes);
List<String> billNumbers = fetchBill(demands, waterConnectionRequest.getRequestInfo());
Expand Down Expand Up @@ -1375,6 +1408,21 @@ public int compare(Demand d1, Demand d2) {
}

log.info("Updated Demand Details " + demands.toString());
if(config.isSaveDemandAuditEnabled()){
demands.stream().forEach(demand -> {
Long id = demandAuditSeqBuilder.getNextSequence();
WsDemandChangeAuditRequest wsDemandChangeAuditRequest = WsDemandChangeAuditRequest.builder().id(id).
consumercode(demand.getConsumerCode()).
tenant_id(demand.getTenantId()).
status(demand.getStatus().toString()).
action("UPDATE DEMAND APPLYADHOCTAX").
data(demand).
createdby(demand.getAuditDetails().getCreatedBy()).
createdtime(demand.getAuditDetails().getLastModifiedTime()).build();
WsDemandChangeAuditRequestWrapper wsDemandChangeAuditRequestWrapper = WsDemandChangeAuditRequestWrapper.builder().wsDemandChangeAuditRequest(wsDemandChangeAuditRequest).build();
producer.push(config.getSaveDemandAudit(), wsDemandChangeAuditRequestWrapper);
});
}
demandRepository.updateDemand(requestInfo, demands);
return calculations;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,9 @@
import org.egov.wscalculation.config.WSCalculationConfiguration;
import org.egov.wscalculation.constants.WSCalculationConstant;
import org.egov.wscalculation.producer.WSCalculationProducer;
import org.egov.wscalculation.web.models.AdhocTaxReq;
import org.egov.wscalculation.web.models.BulkDemand;
import org.egov.wscalculation.web.models.Calculation;
import org.egov.wscalculation.web.models.CalculationCriteria;
import org.egov.wscalculation.web.models.CalculationReq;
import org.egov.wscalculation.web.models.Demand;
import org.egov.wscalculation.repository.DemandAuditSeqBuilder;
import org.egov.wscalculation.web.models.*;
Comment on lines +20 to +21
Copy link

Choose a reason for hiding this comment

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

Updates to service implementation are correct. Consider using method references in the stream operation for better readability.

- searchResult.stream().forEach(demand -> {
+ searchResult.forEach(demand -> {

Also applies to: 73-135


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.

Suggested change
import org.egov.wscalculation.repository.DemandAuditSeqBuilder;
import org.egov.wscalculation.web.models.*;
import org.egov.wscalculation.repository.DemandAuditSeqBuilder;
import org.egov.wscalculation.web.models.*;
searchResult.forEach(demand -> {

import org.egov.wscalculation.web.models.Demand.StatusEnum;
import org.egov.wscalculation.web.models.GetBillCriteria;
import org.egov.wscalculation.web.models.TaxHeadCategory;
import org.egov.wscalculation.web.models.Property;
import org.egov.wscalculation.web.models.RequestInfoWrapper;
import org.egov.wscalculation.web.models.TaxHeadEstimate;
import org.egov.wscalculation.web.models.TaxHeadMaster;
import org.egov.wscalculation.web.models.WaterConnection;
import org.egov.wscalculation.web.models.WaterConnectionRequest;
import org.egov.wscalculation.web.models.enums.Status;
import org.egov.wscalculation.repository.DemandRepository;
import org.egov.wscalculation.repository.ServiceRequestRepository;
Expand Down Expand Up @@ -82,6 +70,9 @@ public class WSCalculationServiceImpl implements WSCalculationService {
@Autowired
private WSCalculationConfiguration config;

@Autowired
private DemandAuditSeqBuilder demandAuditSeqBuilder;

/**
* Get CalculationReq and Calculate the Tax Head on Water Charge And Estimation Charge
*/
Expand Down Expand Up @@ -127,6 +118,21 @@ public List<Calculation> getCalculation(CalculationReq request) {
.getWaterConnection().getPreviousReadingDate().longValue())) {
searchResult.get(0).setStatus(StatusEnum.CANCELLED);
isWSUpdateSMS = true;
if(config.isSaveDemandAuditEnabled()){
searchResult.stream().forEach(demand -> {
Long id = demandAuditSeqBuilder.getNextSequence();
WsDemandChangeAuditRequest wsDemandChangeAuditRequest = WsDemandChangeAuditRequest.builder().id(id).
consumercode(demand.getConsumerCode()).
tenant_id(demand.getTenantId()).
status(demand.getStatus().toString()).
action("GET CALCULATION UPDATE").
data(demand).
createdby(demand.getAuditDetails().getCreatedBy()).
createdtime(demand.getAuditDetails().getLastModifiedTime()).build();
WsDemandChangeAuditRequestWrapper wsDemandChangeAuditRequestWrapper = WsDemandChangeAuditRequestWrapper.builder().wsDemandChangeAuditRequest(wsDemandChangeAuditRequest).build();
wsCalculationProducer.push(config.getSaveDemandAudit(), wsDemandChangeAuditRequestWrapper);
});
}
demandRepository.updateDemand(request.getRequestInfo(), searchResult);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.egov.wscalculation.web.models;

import lombok.*;

import java.util.Map;

import static org.apache.commons.lang3.StringUtils.isNotEmpty;


@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
public class WsDemandChangeAuditRequest {
private Long id;
private String consumercode;
private String tenant_id;
private String status;
private String action;
private Object data;
private String createdby;
private Long createdtime;
public boolean isValid() {

return isNotEmpty(consumercode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.egov.wscalculation.web.models;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.*;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
public class WsDemandChangeAuditRequestWrapper {

@JsonProperty("WsDemandChangeAuditRequest")
Copy link

Choose a reason for hiding this comment

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

Correct the JsonProperty value to match the variable name.

- @JsonProperty("WsDemandChangeAuditRequest")
+ @JsonProperty("wsDemandChangeAuditRequest")

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.

Suggested change
@JsonProperty("WsDemandChangeAuditRequest")
@JsonProperty("wsDemandChangeAuditRequest")

private WsDemandChangeAuditRequest wsDemandChangeAuditRequest;
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,7 @@ sms.demand.enabled: true
sms.payment.link.enabled: true
sms.bill.download.enabled: true
sms.exclude.tenant="pb.testing"

#SAVE DEMAND AUDIT FROM WS_SERVICE
is.save.demand.audit.enabled= true
egov.save.demand.audit.from.wscal= save-ws-demand-change-audit
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE TABLE IF NOT EXISTS eg_ws_demand_auditchange (
id bigint NOT NULL,
consumercode VARCHAR(30) NOT NULL,
tenant_id VARCHAR(50),
status VARCHAR(50),
action VARCHAR(100),
data JSONB,
createdby VARCHAR(250),
createdtime bigint

);
CREATE SEQUENCE seq_eg_ws_demand_auditchange
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE eg_ws_demand_auditchange ADD CONSTRAINT eg_ws_demand_auditchange_pkey PRIMARY KEY (id);
Loading