merged with himanshu code after bbps contant added
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// language: java
|
||||
package com.billpaymentservice.bbps.serviceImpl;
|
||||
|
||||
import java.util.List;
|
||||
@@ -7,7 +8,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
@@ -62,8 +62,9 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
private final ComplainRepository complainRepository;
|
||||
private final ComplaintOptionsStatusMasterRepository complaintStatusMasterRepository;
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AgentServiceImpl.class);
|
||||
// moved to class-level
|
||||
private final ObjectMapper objectMapper;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ComplainServiceImpl.class);
|
||||
|
||||
public ComplainServiceImpl(RestClient restClient, HttpService httpService, Helper helper,
|
||||
BharatConnectMasterRepository beneficiaryDetailsRepository, BillerMapperHelper mapperHelper,
|
||||
@@ -76,12 +77,16 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
this.mapperHelper = mapperHelper;
|
||||
this.complainRepository = complainRepository;
|
||||
this.complaintStatusMasterRepository = complaintStatusMasterRepository;
|
||||
|
||||
// initialize shared ObjectMapper once
|
||||
this.objectMapper = new ObjectMapper();
|
||||
this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseModel addComplain(ComplaintRequestDTO complainRequestDTO) {
|
||||
|
||||
String apiName = "ADD_COMPLAIN";
|
||||
String apiName = BBPSConstant.API_ADD_COMPLAIN;
|
||||
String requestId = complainRequestDTO.getReqId();
|
||||
String mid = complainRequestDTO.getMid();
|
||||
|
||||
@@ -92,25 +97,19 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
String fullUrl = complainDataUrl + BBPSConstant.ADD_COMPLAIN_ENDPOINT;
|
||||
LOGGER.info("[{}] Full URL={}", apiName, fullUrl);
|
||||
// Fetch tenant & agent from DB
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
// Convert input DTO to JSON
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
FetchComplaintForwardRequest forwardReq = helper.fetchComplaintForwardRequestMap(complainRequestDTO);
|
||||
|
||||
String forwardJson = helper.convertObjectToJson(forwardReq);
|
||||
String requestJson = helper.convertObjectToJson(complainRequestDTO);
|
||||
HttpHeaders headers = helper.buildHeaders(headersData);
|
||||
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, complainRequestDTO.getMid(),
|
||||
"POST", requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, fullUrl, "POST",
|
||||
forwardJson);
|
||||
BBPSConstant.HTTP_POST, requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, fullUrl,
|
||||
BBPSConstant.HTTP_POST, null);
|
||||
|
||||
try {
|
||||
// Inject tenantId + agentId into request JSON
|
||||
@@ -124,13 +123,13 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
// IMPORTANT: Send finalJson, not requestJson
|
||||
Map<String, String> responseMap = httpService.postRequest(fullUrl, finalJson, headers);
|
||||
|
||||
String responseData = responseMap.get("data");
|
||||
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
||||
LOGGER.debug("[{}] Response Received | reqId={} | data={}", apiName, requestId, responseData);
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
// Handle HttpService error wrapper
|
||||
if (responseData.startsWith("HttpService Error")) {
|
||||
if (responseData.startsWith(BBPSConstant.HTTP_SERVICE_ERROR_PREFIX)) {
|
||||
int start = responseData.indexOf("{");
|
||||
int end = responseData.lastIndexOf("}");
|
||||
if (start != -1 && end != -1) {
|
||||
@@ -144,13 +143,14 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
int statusCode = Integer.parseInt(String.valueOf(dataMap.get("statusCode")));
|
||||
int statusCode = Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY)));
|
||||
|
||||
// Throw exception for non-200
|
||||
if (statusCode != 200) {
|
||||
if (statusCode != BBPSConstant.HTTP_OK_INT) {
|
||||
LOGGER.warn("[{}] Failure Response | reqId={} | statusCode={}", apiName, requestId, statusCode);
|
||||
throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")),
|
||||
statusCode, String.valueOf(dataMap.get("remarks")));
|
||||
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)),
|
||||
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), statusCode,
|
||||
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)));
|
||||
}
|
||||
|
||||
// Convert to response wrapper
|
||||
@@ -165,7 +165,7 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error("JSON Parsing Error: {}", e.getMessage());
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
}
|
||||
@@ -173,9 +173,7 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
@Override
|
||||
public ResponseModel getComplaintStatus(GetTicketLatestStausRequest request) {
|
||||
|
||||
LOGGER.info("Fetching Complaint Status for TicketId={} ReqId={}", request.getTicketId(), request.getReqId());
|
||||
|
||||
String apiName = "COMPLAINT_STATUS";
|
||||
String apiName = BBPSConstant.API_COMPLAINT_STATUS;
|
||||
String reqId = request.getReqId();
|
||||
String complaintId = request.getTicketId();
|
||||
String mid = request.getMid();
|
||||
@@ -184,16 +182,11 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
LOGGER.info("[{}] START | reqId={} | mid={} | ticketId={}", apiName, reqId, mid, ticketId);
|
||||
String fullUrl = agentDtaUrl + BBPSConstant.COMPALINT_STATUS;
|
||||
|
||||
LOGGER.info("FUll URL -: " + fullUrl);
|
||||
helper.validateMerchant(mid);
|
||||
helper.validateMerchant(request.getMid());
|
||||
String txnId = helper.generateTxnId(15);
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
HttpHeaders headers = helper.buildHeaders(headersData);
|
||||
|
||||
// Convert request to JSON
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
@@ -203,10 +196,10 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
String forwardJson = helper.convertObjectToJson(forwardReq);
|
||||
String requestJson = helper.convertObjectToJson(request);
|
||||
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "POST",
|
||||
requestJson);
|
||||
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "POST", forwardJson);
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(),
|
||||
BBPSConstant.HTTP_POST, requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_POST,
|
||||
complaintId);
|
||||
|
||||
try {
|
||||
|
||||
@@ -219,59 +212,56 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
|
||||
Map<String, String> responseMap = httpService.postRequest(fullUrl, finalJson, headers);
|
||||
|
||||
String responseData = responseMap.get("data");
|
||||
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
||||
|
||||
LOGGER.debug("[{}] Raw Response | reqId={} | data={}", apiName, reqId, responseData);
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
if (responseData.startsWith("HttpService Error")) {
|
||||
// Handle HttpService error wrapper
|
||||
if (responseData.startsWith(BBPSConstant.HTTP_SERVICE_ERROR_PREFIX)) {
|
||||
int start = responseData.indexOf("{");
|
||||
int end = responseData.lastIndexOf("}");
|
||||
if (start != -1 && end != -1) {
|
||||
responseData = responseData.substring(start, end + 1);
|
||||
LOGGER.info("Extracted Clean JSON: {}", responseData);
|
||||
}
|
||||
|
||||
LOGGER.info("Extracted pure JSON from error: {}", responseData);
|
||||
}
|
||||
|
||||
// Convert JSON to Map
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
int statusCode = Integer.parseInt(String.valueOf(dataMap.get("statusCode")));
|
||||
|
||||
if (statusCode != 200) {
|
||||
LOGGER.warn("[{}] Failure Response | reqId={} | statusCode={}", apiName, reqId, statusCode);
|
||||
throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")),
|
||||
statusCode, String.valueOf(dataMap.get("remarks")));
|
||||
int statusCode = Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY)));
|
||||
if (statusCode != BBPSConstant.HTTP_OK_INT) {
|
||||
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)),
|
||||
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), statusCode,
|
||||
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)));
|
||||
}
|
||||
|
||||
TicketCheckStatusResponse responseWrapper = objectMapper.convertValue(dataMap,
|
||||
TicketCheckStatusResponse.class);
|
||||
LOGGER.info("[{}] Complaint Status | ticketId={} | status={}", apiName, ticketId,
|
||||
responseWrapper.getStatus());
|
||||
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, responseWrapper.getStatus());
|
||||
|
||||
// Save in DB
|
||||
String saveComplaintStatus = mapperHelper.saveComplaintStatus(responseWrapper, reqId, txnId);
|
||||
LOGGER.info("[{}] Save Status | ticketId={} | status={}", apiName, ticketId, saveComplaintStatus);
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, responseWrapper.getStatus());
|
||||
|
||||
return new ResponseModel(responseWrapper.getMessage(), responseWrapper.getStatus(),
|
||||
Integer.parseInt(responseWrapper.getStatusCode()), responseWrapper);
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
|
||||
LOGGER.error("Error parsing Complaint Status JSON: {}", e.getMessage());
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
LOGGER.error("Error parsing JSON in complaint status API: {}", e.getMessage(), e);
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseModel viewComplaintHistory(ComplainStatusRequest request) {
|
||||
|
||||
String apiName = "View_Complaint_History";
|
||||
LOGGER.info("Fetching View Complaint History Complaint by Complaint Id={}", request.getTicketId(),
|
||||
request.getReqId());
|
||||
String apiName = BBPSConstant.API_VIEW_COMPLAINT_HISTORY;
|
||||
String reqId = request.getReqId();
|
||||
String ticketId = request.getTicketId();
|
||||
String mid = request.getMid();
|
||||
@@ -281,26 +271,23 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
|
||||
helper.validateMerchant(request.getMid());
|
||||
String txnId = helper.generateTxnId(15);
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
|
||||
HttpHeaders headers = helper.buildHeaders(headersData);
|
||||
|
||||
String requestJson = helper.convertObjectToJson(request);
|
||||
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "GET",
|
||||
requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", ticketId);
|
||||
LOGGER.debug("[{}] Outbound log created | URL={}", apiName, fullUrl);
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(),
|
||||
BBPSConstant.HTTP_GET, requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET,
|
||||
ticketId);
|
||||
LOGGER.debug("Outbound log created successfully for Complaint : {}", fullUrl);
|
||||
|
||||
try {
|
||||
LOGGER.info("[{}] Calling external API | URL={} | reqId={}", apiName, fullUrl, reqId);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
||||
String responseData = responseMap.get("data");
|
||||
|
||||
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
||||
LOGGER.debug("[{}] Raw Response | reqId={} | data={}", apiName, reqId, responseData);
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
@@ -309,11 +296,15 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) {
|
||||
LOGGER.warn("[{}] Invalid response structure | reqId={} | data={}", apiName, reqId, responseData);
|
||||
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
|
||||
throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")),
|
||||
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), String.valueOf(""));
|
||||
|
||||
helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE);
|
||||
LOGGER.warn("Invalid response structure for txnId: {}", txnId);
|
||||
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)),
|
||||
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)),
|
||||
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))),
|
||||
String.valueOf(""));
|
||||
}
|
||||
|
||||
ComplaintHistoryStatusResponse responseWrapper = objectMapper.convertValue(dataMap,
|
||||
@@ -331,14 +322,15 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error("Error parsing Complaint Id JSON: {}", e.getMessage(), e);
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseModel viewComplaintById(ComplainStatusRequest request) {
|
||||
String apiName = "View_Complaint_By_ID";
|
||||
|
||||
String apiName = BBPSConstant.API_VIEW_COMPLAINT_BY_ID;
|
||||
String reqId = request.getReqId();
|
||||
String ticketId = request.getTicketId();
|
||||
String mid = request.getMid();
|
||||
@@ -349,26 +341,21 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
String txnId = helper.generateTxnId(15);
|
||||
String fullUrl = agentDtaUrl + BBPSConstant.VIEW_COMPLAINT_BY_ID + request.getTicketId();
|
||||
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
|
||||
HttpHeaders headers = helper.buildHeaders(headersData);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
String requestJson = helper.convertObjectToJson(request);
|
||||
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "GET",
|
||||
requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", ticketId);
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(),
|
||||
BBPSConstant.HTTP_GET, requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET,
|
||||
ticketId);
|
||||
LOGGER.debug("Outbound log created successfully for Complaint : {}", fullUrl);
|
||||
|
||||
try {
|
||||
LOGGER.info("[{}] Calling external API | reqId={} | URL={}", apiName, reqId, fullUrl);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
||||
String responseData = responseMap.get("data");
|
||||
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
||||
LOGGER.info("Complaint History Complaint FetchById Response: {}", responseData);
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
@@ -377,11 +364,13 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
|
||||
if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) {
|
||||
helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE);
|
||||
LOGGER.warn("Invalid response structure for txnId: {}", txnId);
|
||||
throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")),
|
||||
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), String.valueOf(""));
|
||||
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)),
|
||||
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)),
|
||||
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))),
|
||||
String.valueOf(""));
|
||||
}
|
||||
|
||||
ViewComplainByIdResponse responseWrapper = objectMapper.convertValue(dataMap,
|
||||
@@ -399,7 +388,7 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error("Error parsing Complaint Id JSON: {}", e.getMessage(), e);
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
}
|
||||
@@ -408,19 +397,20 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
public ResponseModel getAllActiveStatuses(AllMasterOptionsRequest request) {
|
||||
|
||||
try {
|
||||
String apiName = "View All Options Fetch By Id";
|
||||
String reqId = request.getReqId();
|
||||
String fullUrl = "Data Base Options";
|
||||
String mid = request.getMid();
|
||||
LOGGER.info("[{}] START | reqId={} | mid={}", apiName, reqId, mid);
|
||||
// Validate merchant
|
||||
helper.validateMerchant(mid);
|
||||
String txnId = helper.generateTxnId(15);
|
||||
String requestJson = helper.convertObjectToJson(request);
|
||||
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "GET",
|
||||
requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null);
|
||||
LOGGER.info("Fetch All Master Options - MID: {}", request.getMid());
|
||||
String apiName = BBPSConstant.API_GET_ALL_MASTER_OPTIONS;
|
||||
String txnId = helper.generateTxnId(15);
|
||||
String reqId = request.getReqId();
|
||||
String fullUrl = BBPSConstant.DB_OPTIONS;
|
||||
|
||||
String requestJson = helper.convertObjectToJson(request);
|
||||
// Validate merchant
|
||||
helper.validateMerchant(request.getMid());
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(),
|
||||
BBPSConstant.HTTP_GET, requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl,
|
||||
BBPSConstant.HTTP_GET, null);
|
||||
LOGGER.debug("Outbound log created successfully for Complaint : {}", fullUrl);
|
||||
|
||||
// Fetch data from DB
|
||||
@@ -431,26 +421,31 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
|
||||
// Check empty or null
|
||||
if (allActiveStatuses == null || allActiveStatuses.isEmpty()) {
|
||||
helper.updateInboundLogFailure(inboundLog, allActiveStatuses.toString(), "Null Data From DB");
|
||||
return new ResponseModel("No Master Fields Found", "failed", 404, null, 0);
|
||||
helper.updateInboundLogFailure(inboundLog, String.valueOf(allActiveStatuses),
|
||||
BBPSConstant.NULL_DATA_FROM_DB);
|
||||
return new ResponseModel(BBPSConstant.NO_MASTER_FIELDS_FOUND, BBPSConstant.FAILED_STATUS,
|
||||
BBPSConstant.HTTP_NOT_FOUND, null, 0);
|
||||
}
|
||||
|
||||
helper.updateInboundLogSuccess(inboundLog, allActiveStatuses.toString(), "200");
|
||||
helper.updateInboundLogSuccess(inboundLog, String.valueOf(allActiveStatuses),
|
||||
String.valueOf(BBPSConstant.HTTP_OK_INT));
|
||||
// SUCCESS RESPONSE
|
||||
return new ResponseModel("All Master Fields Fetch", "SUCCESS", 200, allActiveStatuses,
|
||||
allActiveStatuses.size());
|
||||
return new ResponseModel(BBPSConstant.ALL_MASTER_FIELDS_FETCH, BBPSConstant.SUCCESS_RESPONSE,
|
||||
BBPSConstant.HTTP_OK_INT, allActiveStatuses, allActiveStatuses.size());
|
||||
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
LOGGER.error("Error while fetching master options", e);
|
||||
return new ResponseModel("Something went wrong", "failed", 500, null, 0);
|
||||
return new ResponseModel(BBPSConstant.SOMETHING_WENT_WRONG, BBPSConstant.FAILED_STATUS,
|
||||
BBPSConstant.HTTP_INTERNAL_SERVER_ERROR, null, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ResponseModel checkTxnStatus(TxnStatusRequest request) {
|
||||
String apiName = "Check_Txn_Status";
|
||||
|
||||
String apiName = BBPSConstant.API_CHECK_TXN_STATUS;
|
||||
String reqId = request.getReqId();
|
||||
String ID = request.getId();
|
||||
String mid = request.getMid();
|
||||
@@ -461,26 +456,21 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
String txnId = helper.generateTxnId(15);
|
||||
String fullUrl = agentDtaUrl + BBPSConstant.CHECK_TRANSACTION_URL + request.getId();
|
||||
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
|
||||
HttpHeaders headers = helper.buildHeaders(headersData);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
String requestJson = helper.convertObjectToJson(request);
|
||||
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "GET",
|
||||
requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", ID);
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(),
|
||||
BBPSConstant.HTTP_GET, requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET,
|
||||
ID);
|
||||
LOGGER.debug("Outbound log created successfully for Complaint : {}", fullUrl);
|
||||
|
||||
try {
|
||||
LOGGER.info("[{}] Calling external BBPS API | URL={}", apiName, fullUrl);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
||||
String responseData = responseMap.get("data");
|
||||
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
||||
LOGGER.info("checkTxnStatus: {}", responseData);
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
@@ -489,11 +479,13 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
|
||||
if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) {
|
||||
helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE);
|
||||
LOGGER.warn("Invalid response structure for txnId: {}", txnId);
|
||||
throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")),
|
||||
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), String.valueOf(""));
|
||||
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)),
|
||||
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)),
|
||||
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))),
|
||||
String.valueOf(""));
|
||||
}
|
||||
|
||||
TxnStatusResponse responseWrapper = objectMapper.convertValue(dataMap, TxnStatusResponse.class);
|
||||
@@ -508,7 +500,7 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error("Error parsing Complaint Id JSON: {}", e.getMessage(), e);
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
|
||||
@@ -517,9 +509,7 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
@Override
|
||||
public ResponseModel ViewAllComplaints(ViewAllComplaintsTicketsRequest request) {
|
||||
|
||||
LOGGER.info("Fetching All Complaint for status Type={} and reqId={} ", request.getStatusType(),
|
||||
request.getReqId());
|
||||
String apiName = "View_All_Complaint_By_Status_Type";
|
||||
String apiName = BBPSConstant.API_VIEW_ALL_COMPLAINTS_BY_STATUS;
|
||||
String reqId = request.getReqId();
|
||||
String mid = request.getMid();
|
||||
String statusType = request.getStatusType();
|
||||
@@ -532,28 +522,22 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
+ "&pageSize=" + request.getPageSize() + "&statusType=" + request.getStatusType() + "&ticketType="
|
||||
+ request.getTicketType();
|
||||
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
|
||||
HttpHeaders headers = helper.buildHeaders(headersData);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
String requestJson = helper.convertObjectToJson(request);
|
||||
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "GET",
|
||||
requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET",
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(),
|
||||
BBPSConstant.HTTP_POST, requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET,
|
||||
request.getStatusType());
|
||||
LOGGER.debug("Outbound log created successfully for Complaint : {}", fullUrl);
|
||||
|
||||
try {
|
||||
LOGGER.info("[{}] Calling external API | URL={}", apiName, fullUrl);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
||||
String responseData = responseMap.get("data");
|
||||
LOGGER.info("[{}] API Response received", apiName);
|
||||
|
||||
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
||||
LOGGER.info("Response: {}", responseData);
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
@@ -561,11 +545,13 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
|
||||
if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) {
|
||||
helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE);
|
||||
LOGGER.warn("Invalid response structure for txnId: {}", txnId);
|
||||
throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")),
|
||||
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), String.valueOf(""));
|
||||
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)),
|
||||
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)),
|
||||
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))),
|
||||
String.valueOf(""));
|
||||
}
|
||||
|
||||
ViewAllComplaintsTicketsResponse responseWrapper = objectMapper.convertValue(dataMap,
|
||||
@@ -582,9 +568,9 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error("Error parsing Complaint Id JSON: {}", e.getMessage(), e);
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user