13-11-25 Arham
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user