Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demand update fix #396

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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 @@ -8,6 +8,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

import org.egov.mgramsevaifixadaptor.config.PropertyConfiguration;
import org.egov.mgramsevaifixadaptor.contract.DemandRequest;
Expand Down Expand Up @@ -80,8 +81,11 @@ public void listenUpdate(final HashMap<String, Object> record, @Header(KafkaHead
if(demandRequest != null) {
Collections.sort(demandRequest.getDemands(), getCreatedTimeComparatorForDemand());
List<Demand> demandListToRemove = new ArrayList<>();

for(Demand demand : demandRequest.getDemands()) {

List<DemandDetail> demandDetails = demand.getDemandDetails();

if(demand.getStatus().toString().equalsIgnoreCase(Constants.CANCELLED) && demand.getIsPaymentCompleted() == false) {
if(demandDetails != null) {
BigDecimal totalAmount = BigDecimal.ZERO;
Expand All @@ -108,16 +112,35 @@ public void listenUpdate(final HashMap<String, Object> record, @Header(KafkaHead
}
else if(Constants.ACTIVE.equalsIgnoreCase(demand.getStatus().toString()) && demandDetails != null && !demandDetails.isEmpty()){
if(demand.getConsumerType().toString().equalsIgnoreCase("waterConnection-arrears")) {
log.info("demandsize: "+demandDetails.size());
List<DemandDetail> demList = new ArrayList<>();
List<DemandDetail> demDetailResponse = demand.getDemandDetails();

CopyOnWriteArrayList<DemandDetail> demDetailList = new CopyOnWriteArrayList<>(demDetailResponse);

int demandDetailsSize = demandDetails.size();

for(int i=0; i<demandDetailsSize; i++) {

Integer count = getCountByDemandDetailsId(demandDetails.get(i).getId());
log.info("num count: "+count);

if(count != null && count > 1) {
demDetailList.remove(demandDetails.get(i));

DemandDetail demanddetail = demandDetails.get(demandDetails.size()-1);
demList.add(demanddetail);
for(int i=0; i<demandDetails.size(); i++) {
demand.getDemandDetails().remove(i);
}

}
demand.setDemandDetails(demList);;
log.info("size after removing: "+demDetailList.size());
demand.getDemandDetails().removeAll(demandDetails);
demand.setDemandDetails(demDetailList);
// List<DemandDetail> demList = new ArrayList<>();
//
// DemandDetail demanddetail = demandDetails.get(demandDetails.size()-1);
// demList.add(demanddetail);
// for(int i=0; i<demandDetails.size(); i++) {
// demand.getDemandDetails().remove(i);
//
// }
// demand.setDemandDetails(demList);
}
else{
for(DemandDetail demandDetail: demandDetails) {
Expand All @@ -135,6 +158,7 @@ else if(Constants.ACTIVE.equalsIgnoreCase(demand.getStatus().toString()) && dema
else {
demandListToRemove.add(demand);
}

}
demandRequest.getDemands().removeAll(demandListToRemove);
if(demandRequest.getDemands().isEmpty()) {
Expand Down