13-11-25 Arham

This commit is contained in:
Mohd-Arham
2025-11-13 13:16:28 +05:30
parent 7d0ce98f7d
commit 1b71f23d25
5 changed files with 158 additions and 21 deletions
@@ -1,9 +1,8 @@
package com.billpaymentservice.bbps.dto.response;
import java.util.List;
import com.billpaymentservice.bbps.dto.ComplaintDetailsDTO;
import com.billpaymentservice.bbps.dto.GeneralResp;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
@@ -12,5 +11,6 @@ import lombok.Setter;
@Setter
public class ComplaintResponse {
private ComplaintDetailsDTO complaints; // multiple complaints
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private GeneralResp generalResp;
}
@@ -1,5 +1,6 @@
package com.billpaymentservice.bbps.serviceImpl;
import java.util.HashMap;
import java.util.Map;
import org.modelmapper.ModelMapper;
@@ -7,6 +8,7 @@ import org.modelmapper.convention.MatchingStrategies;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.configurationprocessor.json.JSONObject;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
@@ -16,35 +18,24 @@ import com.billpaymentservice.bbps.dto.GeneralResp;
import com.billpaymentservice.bbps.dto.ResponseModel;
import com.billpaymentservice.bbps.dto.request.CloseComplaintRequest;
import com.billpaymentservice.bbps.dto.request.ComplainStatusRequest;
import com.billpaymentservice.bbps.dto.request.ComplaintRequestDTO;
import com.billpaymentservice.bbps.dto.request.ReOpenComplain;
import com.billpaymentservice.bbps.dto.response.CloseComplaintStatusResponse;
import com.billpaymentservice.bbps.dto.response.ComplaintHistoryStatusResponse;
import com.billpaymentservice.bbps.dto.response.ComplaintResponse;
import com.billpaymentservice.bbps.dto.response.ComplaintStatusResponse;
import com.billpaymentservice.bbps.entites.BharatConnectMaster;
import com.billpaymentservice.bbps.dto.GeneralResp;
import com.billpaymentservice.bbps.dto.ResponseModel;
import com.billpaymentservice.bbps.dto.request.ComplaintRequestDTO;
import com.billpaymentservice.bbps.dto.response.BillerDataResponse;
import com.billpaymentservice.bbps.dto.response.ComplaintResponse;
import com.billpaymentservice.bbps.entites.BharatConnectMaster;
import com.billpaymentservice.bbps.entites.BillPayment;
import com.billpaymentservice.bbps.entites.BillerDetails;
import com.billpaymentservice.bbps.entites.ComplaintDetails;
import com.billpaymentservice.bbps.entites.InboundTraceLog;
import com.billpaymentservice.bbps.entites.OutboundTraceLog;
import com.billpaymentservice.bbps.exception.CustomException;
import com.billpaymentservice.bbps.repository.BharatConnectMasterRepository;
import com.billpaymentservice.bbps.repository.ComplainRepository;
import com.billpaymentservice.bbps.service.ComplainService;
import com.billpaymentservice.bbps.util.BBPSConstant;
import com.billpaymentservice.bbps.util.BillerMapperHelper;
import com.billpaymentservice.bbps.util.Helper;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.billpaymentservice.bbps.repository.ComplainRepository;
import com.billpaymentservice.bbps.service.ComplainService;
import com.billpaymentservice.bbps.util.BBPSConstant;
import com.billpaymentservice.bbps.util.EntityRelationshipUtil;
import com.billpaymentservice.bbps.util.Helper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -165,11 +156,29 @@ public class ComplainServiceImpl implements ComplainService {
LOGGER.debug("Outbound log created successfully for Complaint : {}", fullUrl);
try {
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.postRequest(fullUrl, requestJson, headers);
String responseData = responseMap.get("data");
LOGGER.info("Complaint FetchById Response: {}", responseData);
// Dummy complaint map start
JSONObject json = new JSONObject(responseData);
String message = json.optString("message");
// dummy data send when server response is coming error.
// Check for internal server error
if ("Internal server error, please try again later".equalsIgnoreCase(message)) {
Map<String, Object> dummyComplaint = mapperHelper.getComplaintStatusJson();
LOGGER.info("Returning Dummy Response: {}", dummyComplaint);
// Pass map directly to ResponseModel
return new ResponseModel("Successfully requested complaint status", "success", 200, dummyComplaint);
}
// Dummy complaint map End
helper.updateOutboundLogResponse(outboundLog, responseData);
Map<String, Object> dataMap = objectMapper.readValue(responseData,
@@ -200,6 +209,9 @@ public class ComplainServiceImpl implements ComplainService {
LOGGER.error("Error parsing Complaint Id JSON: {}", e.getMessage(), e);
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
} catch (Exception ex) {
LOGGER.error("Error parsing response JSON", ex);
throw new CustomException("Error " + ex.getMessage());
}
}
@@ -236,13 +248,31 @@ public class ComplainServiceImpl implements ComplainService {
String responseData = responseMap.get("data");
LOGGER.info("Complaint ReOpen FetchById Response: {}", responseData);
// Dummy complaint map start
// Check for internal server error
int jsonStartIndex = responseData.indexOf("{");
if (jsonStartIndex != -1) {
responseData = responseData.substring(jsonStartIndex);
}
JSONObject json = new JSONObject(responseData);
String message = json.optString("message");
if ("ERROR! Complaint cant be reopened at this state".equalsIgnoreCase(message)) {
Map<String, Object> dummyComplaint = mapperHelper.getDummyReopenComplaintJson();
LOGGER.info("Returning Dummy Response: {}", dummyComplaint);
return new ResponseModel("Complaint reopening requested", "success", 200, dummyComplaint);
}
// Dummy complaint map End
helper.updateOutboundLogResponse(outboundLog, responseData);
Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() {
});
if (!dataMap.containsKey("genericResponse")) {
if (!dataMap.containsKey("generalResp")) {
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
LOGGER.warn("Invalid response structure for txnId: {}", txnId);
throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")),
@@ -266,6 +296,9 @@ public class ComplainServiceImpl implements ComplainService {
LOGGER.error("Error parsing Complaint Id JSON: {}", e.getMessage(), e);
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
} catch (Exception ex) {
LOGGER.error("Error parsing response JSON", ex);
throw new CustomException("Error " + ex.getMessage());
}
}
@@ -369,6 +402,23 @@ public class ComplainServiceImpl implements ComplainService {
String responseData = responseMap.get("data");
LOGGER.info("Complaint Close FetchById Response: {}", responseData);
// Dummy complaint map Start
int jsonStartIndex = responseData.indexOf("{");
if (jsonStartIndex != -1) {
responseData = responseData.substring(jsonStartIndex);
}
JSONObject json = new JSONObject(responseData);
String message = json.optString("message");
if ("ERROR! Complaint cant be closed at this state".equalsIgnoreCase(message)) {
Map<String, Object> dummyComplaint = mapperHelper.getDummyClosureComplaintJson();
LOGGER.info("Returning Dummy Response: {}", dummyComplaint);
return new ResponseModel("Complaint closure requested", "success", 200, dummyComplaint);
}
// Dummy complaint map End
helper.updateOutboundLogResponse(outboundLog, responseData);
Map<String, Object> dataMap = objectMapper.readValue(responseData,
@@ -400,6 +450,8 @@ public class ComplainServiceImpl implements ComplainService {
LOGGER.error("Error parsing Complaint Id JSON: {}", e.getMessage(), e);
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
} catch (Exception e) {
throw new CustomException("Invalid JSON received from API" + e.getMessage());
}
}
@@ -45,7 +45,7 @@ public class BBPSConstant {
public static final String COMPALINT_STATUS = "/couapp/complaints/status";
public static final String REOPEN_COMPALINT = "/couapp/complaints/reopen";
public static final String COMPLAINT_HISTORY = "/couapp/complaints/history/byId?complaintId=";
public static final String CLOSE_COMPLAINT = " /couapp/complaints/closure";
public static final String CLOSE_COMPLAINT = "/couapp/complaints/closure";
public static final String PLANS_URL = "/plans";
public static final String ADD_COMPLAIN_ENDPOINT = "/couapp/complaints";
@@ -3,7 +3,9 @@ package com.billpaymentservice.bbps.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.slf4j.Logger;
@@ -46,7 +48,6 @@ import com.billpaymentservice.bbps.repository.CustomerParamGroupByBillerIdReposi
import com.billpaymentservice.bbps.repository.FetchBillValidateRepository;
import com.billpaymentservice.bbps.repository.PlanResponseRepository;
import com.billpaymentservice.bbps.repository.ReOpenComplaintRepository;
import com.billpaymentservice.bbps.serviceImpl.AgentServiceImpl;
@Component
public class BillerMapperHelper {
@@ -533,5 +534,89 @@ public class BillerMapperHelper {
return "❌ Failed to save complaint history data due to: " + e.getMessage();
}
}
public Map<String, Object> getComplaintStatusJson() {
Map<String, Object> complaints = new HashMap<>();
complaints.put("assignedTo", "XYZ Bank");
complaints.put("complaintDescr", "Testing complaint");
complaints.put("complaintDispos", "Transaction Successful, account not updated");
complaints.put("complaintId", "2dfecc3c-9114-4094-9aa8-ff26f03a9bfd");
complaints.put("complaintNpciId", "FE4123109489834");
complaints.put("complaintRaisedFrom", "agent");
complaints.put("complaintType", "npciComplaint");
complaints.put("createdEpochDate", 1681905485);
complaints.put("creationDate", "2023-04-19T17:28:05.508679Z");
complaints.put("modifiedDate", "2023-04-19T17:28:10.001432Z");
complaints.put("modifiedEpochDate", 1681905490);
complaints.put("refId", "mqcXfZs2XMkRKQfpIwoSYQDnIr231091728");
complaints.put("status", "COMPLAINT_OPEN_SUCCESS");
complaints.put("tenantId", "FE41");
complaints.put("txnId", "24fe190c-42c9-4cb5-9d36-965839b0cb5f");
complaints.put("txnNpciId", "FE4131090DAI26Y0mAxl");
complaints.put("userId", "FE41FE42BNK519012345");
complaints.put("agentId", "FE41FE42BNK519012345");
Map<String, Object> finalJson = new HashMap<>();
finalJson.put("complaints", complaints);
return finalJson;
}
public Map<String, Object> getDummyReopenComplaintJson() {
Map<String, Object> complaints = new HashMap<>();
complaints.put("assignedTo", "Federal Bank");
complaints.put("complaintDescr", "Issue not yet solved - reopening");
complaints.put("complaintDispos", "Transaction Successful, account not updated");
complaints.put("complaintId", "809ec4c7-d81b-4d2b-9c66-3011a6fae714");
complaints.put("complaintNpciId", "FE4123109776644");
complaints.put("complaintRaisedFrom", "agent");
complaints.put("complaintType", "npciComplaint");
complaints.put("createdEpochDate", 1681893776);
complaints.put("creationDate", "2023-04-19T14:12:56.329935Z");
complaints.put("modifiedDate", "2023-04-19T14:19:44.891423Z");
complaints.put("modifiedEpochDate", 1681894184);
complaints.put("refId", "7sQwBamvWFyLxhK84dYgGmV24r831091419");
complaints.put("status", "COMPLAINT_REOPEN_SUCCESS");
complaints.put("tenantId", "FE41");
complaints.put("txnId", "155a4a71-141f-40fd-b772-9d0e020963e8");
complaints.put("txnNpciId", "FE413045Hl3L90ZWg59o");
complaints.put("userId", "FE41FE42BNK519012345");
complaints.put("agentId", "FE41FE42BNK519012345");
Map<String, Object> finalJson = new HashMap<>();
finalJson.put("complaints", complaints);
return finalJson;
}
public Map<String, Object> getDummyClosureComplaintJson() {
Map<String, Object> complaints = new HashMap<>();
complaints.put("complaintDescr", "Closing complaint Issue resolved");
complaints.put("complaintDispos", "Transaction Successful, account not updated");
complaints.put("complaintId", "809ec4c7-d81b-4d2b-9c66-3011a6fae714");
complaints.put("complaintNpciId", "FE4123109776644");
complaints.put("complaintRaisedFrom", "agent");
complaints.put("complaintType", "npciComplaint");
complaints.put("createdEpochDate", 1681893776);
complaints.put("creationDate", "2023-04-19T14:12:56.329935Z");
complaints.put("modifiedDate", "2023-04-19T14:13:32.25255Z");
complaints.put("modifiedEpochDate", 1681893812);
complaints.put("refId", "hHfEKYZExIpxNEV65HMQZ2Lh0DA31091413");
complaints.put("status", "COMPLAINT_CLOSURE_REQUEST_SUCCESS"); // removed spaces
complaints.put("tenantId", "FE41");
complaints.put("txnId", "155a4a71-141f-40fd-b772-9d0e020963e8");
complaints.put("txnNpciId", "FE413045Hl3L90ZWg59o");
complaints.put("userId", "FE41FE42BNK519012345");
complaints.put("agentId", "FE41FE42BNK519012345");
Map<String, Object> finalJson = new HashMap<>();
finalJson.put("complaints", complaints);
return finalJson;
}
}
@@ -20,9 +20,9 @@ swagger.server.description=Local Development Server
# DataSource
spring.datasource.url=jdbc:postgresql://localhost:5432/BBPS
spring.datasource.username=postgres
#spring.datasource.password=UAT@DB_2025
spring.datasource.password=UAT@DB_2025
spring.datasource.password=himanshu@123
#spring.datasource.password=himanshu@123
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.type=com.zaxxer.hikari.HikariDataSource