From 435ee0dacf1e90cca5fd43a50ab316d48dafb7cc Mon Sep 17 00:00:00 2001 From: Lincpay Tech Date: Mon, 24 Nov 2025 17:48:54 +0530 Subject: [PATCH] added constant in bbps constant --- .../bbps/serviceImpl/AgentServiceImpl.java | 135 +++++---- .../bbps/serviceImpl/ComplainServiceImpl.java | 172 +++++------ .../serviceImpl/MasterDataServiceImpl.java | 271 +++++++++--------- .../bbps/serviceImpl/PaymentServiceImpl.java | 1 - .../bbps/util/BBPSConstant.java | 78 ++++- .../bbps/util/EntityRelationshipUtil.java | 3 - .../billpaymentservice/bbps/util/Helper.java | 59 ---- 7 files changed, 368 insertions(+), 351 deletions(-) diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java index 29bab13..5196372 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java @@ -6,8 +6,7 @@ import java.util.Optional; 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; import com.billpaymentservice.bbps.dto.GeneralResp; @@ -22,7 +21,6 @@ import com.billpaymentservice.bbps.dto.response.FetchBillResponse; import com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse; import com.billpaymentservice.bbps.dto.sentRequest.FetchBillForwardRequest; import com.billpaymentservice.bbps.dto.sentRequest.FetchBillValidatestForwardRequest; -import com.billpaymentservice.bbps.entites.BharatConnectMaster; import com.billpaymentservice.bbps.entites.BillInitiate; import com.billpaymentservice.bbps.entites.BillMaster; import com.billpaymentservice.bbps.entites.InboundTraceLog; @@ -41,7 +39,6 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; @Service public class AgentServiceImpl implements AgentService { @@ -80,7 +77,7 @@ public class AgentServiceImpl implements AgentService { public ResponseModel initiateBillFetch(FetchBillRequest fetchBillRequest) { LOGGER.info("Initiating bill fetch for request ID: {} and MID :{} and billerId:{} ", fetchBillRequest.getReqId(), fetchBillRequest.getMid(),fetchBillRequest.getBillerId()); - String apiName = "InitiateBillFetch"; + String apiName = BBPSConstant.API_INITIATE_BILL_FETCH; String txnId = helper.generateTxnId(15); String requestId = fetchBillRequest.getReqId(); String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_INTI; @@ -93,8 +90,8 @@ public class AgentServiceImpl implements AgentService { String requestJson = helper.convertObjectToJson(fetchBillRequest); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, fetchBillRequest.getMid(), - "POST", requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, fullUrl, "POST", + BBPSConstant.HTTP_POST, requestJson); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, fullUrl, BBPSConstant.HTTP_POST, forwardJson); LOGGER.debug("Outbound log created successfully for txnId: {} and reqId: {}", txnId, requestId); @@ -107,10 +104,10 @@ public class AgentServiceImpl implements AgentService { LOGGER.debug("Response received from BBPS: {}", responseData); Map dataMap = objectMapper.readValue(responseData, - new TypeReference>() { - }); + new TypeReference>() { + }); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); LOGGER.warn("Invalid response received for txnId: {}", txnId); throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), @@ -150,7 +147,7 @@ public class AgentServiceImpl implements AgentService { return fetchBillById(billFetchByBillIdRequest, inboundLog); } catch (JsonProcessingException e) { LOGGER.error("JSON Parsing Error: {}", 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"); } } @@ -158,14 +155,14 @@ public class AgentServiceImpl implements AgentService { public ResponseModel fetchBillById(BillFetchByBillIdRequest billFetchByBillIdRequest, InboundTraceLog inboundLog) { LOGGER.info("Fetching bill by BILLID for request ID={} and MID={}", billFetchByBillIdRequest.getReqId(), billFetchByBillIdRequest.getMid()); - String apiName = "FetchBillById"; + String apiName = BBPSConstant.API_FETCH_BILL_BY_ID; String txnId = helper.generateTxnId(15); String reqId = billFetchByBillIdRequest.getReqId(); String billId = billFetchByBillIdRequest.getBillId(); String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID + billFetchByBillIdRequest.getBillId(); helper.validateMerchant(billFetchByBillIdRequest.getMid()); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.debug("Outbound log created successfully for FetchBillById: {}", fullUrl); try { @@ -177,11 +174,11 @@ public class AgentServiceImpl implements AgentService { helper.updateOutboundLogResponse(outboundLog, responseData); Map dataMap = objectMapper.readValue(responseData, - new TypeReference>() { - }); + new TypeReference>() { + }); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + 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"))), @@ -202,14 +199,14 @@ public class AgentServiceImpl implements AgentService { Integer.parseInt(generalResp.getStatusCode()), responseWrapper); } catch (JsonProcessingException e) { LOGGER.error("Error parsing BillById 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 fetchBillById(BillFetchByBillIdRequest billFetchByBillIdRequest) { - String apiName = "FetchBillById"; + String apiName = BBPSConstant.API_FETCH_BILL_BY_ID; String txnId = helper.generateTxnId(15); String reqId = billFetchByBillIdRequest.getReqId(); String billId = billFetchByBillIdRequest.getBillId(); @@ -218,13 +215,13 @@ public class AgentServiceImpl implements AgentService { LOGGER.info("Initiating {} API for billId={} and reqId={}", apiName, billId, reqId); InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, - billFetchByBillIdRequest.getMid(), "GET", null); + billFetchByBillIdRequest.getMid(), BBPSConstant.HTTP_GET, null); try { helper.validateMerchant(billFetchByBillIdRequest.getMid()); LOGGER.debug("Merchant validated successfully for MID={}", billFetchByBillIdRequest.getMid()); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external BBPS API for FetchBillById, URL={}", fullUrl); Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); String responseData = responseMap.get("data"); @@ -237,7 +234,7 @@ public class AgentServiceImpl implements AgentService { }); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); LOGGER.warn("Invalid response structure received for billId={} | Response={}", billId, responseData); throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), @@ -258,7 +255,7 @@ public class AgentServiceImpl implements AgentService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON for billId={} : {}", billId, 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"); } } @@ -268,7 +265,7 @@ public class AgentServiceImpl implements AgentService { LOGGER.info("Initiating bill Validate for request ID: {} and MID:{} and billerId:{}", fetchBillValidateRequest.getReqId(), fetchBillValidateRequest.getMid(),fetchBillValidateRequest.getBillerId()); - String apiName = "InitiateBillValidate"; + String apiName = BBPSConstant.API_INITIATE_BILL_VALIDATE; String txnId = helper.generateTxnId(15); String reqId = fetchBillValidateRequest.getReqId(); String fullUrl = agentDtaUrl + BBPSConstant.BILLER_VALIDATE_URL; @@ -283,8 +280,8 @@ public class AgentServiceImpl implements AgentService { String requestJson = helper.convertObjectToJson(fetchBillValidateRequest); InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, fetchBillValidateRequest.getMid(), - "POST", requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "POST", forwardJson); + BBPSConstant.HTTP_POST, requestJson); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_POST, forwardJson); LOGGER.debug("Outbound log created successfully for txnId: {} and reqId: {}", txnId, reqId); try { @@ -296,10 +293,10 @@ public class AgentServiceImpl implements AgentService { LOGGER.debug("Response received from BBPS: {}", responseData); Map dataMap = objectMapper.readValue(responseData, - new TypeReference>() { - }); + new TypeReference>() { + }); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); LOGGER.warn("Invalid response received for txnId: {}", txnId); throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), @@ -338,7 +335,7 @@ public class AgentServiceImpl implements AgentService { return BillvaidateByBillId(billFetchByBillIdRequest, inboundLog); } catch (JsonProcessingException e) { LOGGER.error("JSON Parsing Error: {}", 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"); } } @@ -347,7 +344,7 @@ public class AgentServiceImpl implements AgentService { { LOGGER.info("Validating bill by BILLID for request ID={} and MID={}", billRequest.getReqId(), billRequest.getMid()); - String apiName = "FetchBillById"; + String apiName = BBPSConstant.API_FETCH_BILL_BY_ID; String txnId = helper.generateTxnId(15); String reqId = billRequest.getReqId(); String billId = billRequest.getBillId(); @@ -355,7 +352,7 @@ public class AgentServiceImpl implements AgentService { helper.validateMerchant(billRequest.getMid()); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.debug("Outbound log created successfully for FetchBillById: {}", fullUrl); try { @@ -367,11 +364,11 @@ public class AgentServiceImpl implements AgentService { helper.updateOutboundLogResponse(outboundLog, responseData); Map dataMap = objectMapper.readValue(responseData, - new TypeReference>() { - }); + new TypeReference>() { + }); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + 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"))), @@ -394,7 +391,7 @@ public class AgentServiceImpl implements AgentService { Integer.parseInt(generalResp.getStatusCode()), responseWrapper); } catch (JsonProcessingException e) { LOGGER.error("Error parsing BillById 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"); } @@ -403,7 +400,7 @@ public class AgentServiceImpl implements AgentService { @Override public ResponseModel initiateBillValidateByBillId(BillFetchByBillIdRequest billRequest) { - String apiName = "FetchBillById"; + String apiName = BBPSConstant.API_FETCH_BILL_BY_ID; String txnId = helper.generateTxnId(15); String reqId = billRequest.getReqId(); String billId = billRequest.getBillId(); @@ -411,12 +408,12 @@ public class AgentServiceImpl implements AgentService { LOGGER.info("Initiating {} API for billId={} and reqId={}", apiName, billId, reqId); - InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, billRequest.getMid(), "GET", null); + InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, billRequest.getMid(), BBPSConstant.HTTP_GET, null); try { helper.validateMerchant(billRequest.getMid()); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external BBPS API for ValidateByBillId, URL={}", fullUrl); Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); @@ -428,7 +425,7 @@ public class AgentServiceImpl implements AgentService { Map dataMap = objectMapper.readValue(responseData, new com.fasterxml.jackson.core.type.TypeReference>(){}); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); LOGGER.warn("Invalid response structure received for billId={} | Response={}", billId, responseData); throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), @@ -447,7 +444,7 @@ public class AgentServiceImpl implements AgentService { } catch (com.fasterxml.jackson.core.JsonProcessingException e) { LOGGER.error("Error parsing ValidateByBillId 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"); } } @@ -457,14 +454,14 @@ public class AgentServiceImpl implements AgentService { @Override public ResponseModel fetchBillValidateByClientReqId(BillValidateByClientIdRequest billValidateByClientIdRequest) { - String apiName = "FetchBillValidateByClientIdRequest"; + String apiName = BBPSConstant.API_FETCH_BILL_VALIDATE_BY_CLIENT_ID; String txnId = helper.generateTxnId(15); String reqId = billValidateByClientIdRequest.getReqId(); String clientReqId = billValidateByClientIdRequest.getClientReqId(); Optional billInitiate = billIntiateRepository.findByReqId(clientReqId); if (billInitiate.isEmpty()) { - throw new CustomException("No Bill Found for given Client Req Id"); + throw new CustomException(BBPSConstant.NO_BILL_FOUND); } String fullUrl = agentDtaUrl + BBPSConstant.BILL_VALIDATE_BY_CLIENT_REQ_ID + billInitiate.get().getTxnId(); @@ -472,9 +469,9 @@ public class AgentServiceImpl implements AgentService { helper.validateMerchant(billValidateByClientIdRequest.getMid()); InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, - billValidateByClientIdRequest.getMid(), "GET", null); + billValidateByClientIdRequest.getMid(), BBPSConstant.HTTP_GET, null); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); try { LOGGER.info("Calling BBPS API FetchBillValidateByClientReqId, URL={}", fullUrl); @@ -484,11 +481,11 @@ public class AgentServiceImpl implements AgentService { helper.updateOutboundLogResponse(outboundLog, responseData); Map dataMap = objectMapper.readValue(responseData, - new TypeReference>() { - }); + new TypeReference>() { + }); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), String.valueOf(dataMap.get("remarks"))); @@ -504,7 +501,7 @@ public class AgentServiceImpl implements AgentService { Integer.parseInt(generalResp.getStatusCode()), responseWrapper); } catch (JsonProcessingException e) { - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -512,14 +509,14 @@ public class AgentServiceImpl implements AgentService { @Override public ResponseModel fetchBillByClientReqId(BillFetchByClientIdRequest billFetchByClientIdRequest) { - String apiName = "FetchBillByClientIdRequest"; + String apiName = BBPSConstant.API_FETCH_BILL_BY_CLIENT_ID; String txnId = helper.generateTxnId(15); String reqId = billFetchByClientIdRequest.getReqId(); String clientReqId = billFetchByClientIdRequest.getClientReqId(); Optional billInitiate = billIntiateRepository.findByReqId(clientReqId); if (billInitiate.isEmpty()) { - throw new CustomException("No Bill Found for given Client Req Id"); + throw new CustomException(BBPSConstant.NO_BILL_FOUND); } String fullUrl = agentDtaUrl + BBPSConstant.BILL_VALIDATE_BY_CLIENT_REQ_ID + billInitiate.get().getTxnId(); @@ -527,9 +524,9 @@ public class AgentServiceImpl implements AgentService { helper.validateMerchant(billFetchByClientIdRequest.getMid()); InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, billFetchByClientIdRequest.getMid(), - "GET", null); + BBPSConstant.HTTP_GET, null); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); try { LOGGER.info("Calling BBPS API FetchBillByClientReqId, URL={}", fullUrl); @@ -539,11 +536,11 @@ public class AgentServiceImpl implements AgentService { helper.updateOutboundLogResponse(outboundLog, responseData); Map dataMap = objectMapper.readValue(responseData, - new TypeReference>() { - }); + new TypeReference>() { + }); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), String.valueOf(dataMap.get("remarks"))); @@ -558,7 +555,7 @@ public class AgentServiceImpl implements AgentService { Integer.parseInt(generalResp.getStatusCode()), responseWrapper); } catch (JsonProcessingException e) { - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -566,26 +563,28 @@ public class AgentServiceImpl implements AgentService { @Override public ResponseModel processBillFetchCallback(BillDataResponse billDataResponse) { LOGGER.info("Recived Call Back from billDataResponse: {}", billDataResponse); - if(billDataResponse.getGenericResponse().getStatusCode().equals("200")) { } + if(billDataResponse.getGenericResponse().getStatusCode().equals(BBPSConstant.SUCCESS_CODE_STR)) { } else { - LOGGER.info("Bill Fetch Callback Failed with Status: {}", billDataResponse.getGenericResponse().getStatus()); + LOGGER.info("Bill Fetch Callback Failed with Status: {}", billDataResponse.getGenericResponse().getStatus()); } - return new ResponseModel("CallBack Recieved Successfully", - "200", - 200, - ""); + return new ResponseModel(BBPSConstant.CALLBACK_RECEIVED_SUCCESS, + BBPSConstant.SUCCESS_CODE_STR, + 200, + "" + ); } @Override public ResponseModel processBillValidateCallback(FetchBillValidateResponse billValidateResponse) { LOGGER.info("Recived Call Back from FetchBillValidateResponse: {}", billValidateResponse); - if(billValidateResponse.getGenericResponse().getStatusCode().equals("200")) { } + if(billValidateResponse.getGenericResponse().getStatusCode().equals(BBPSConstant.SUCCESS_CODE_STR)) { } else { - LOGGER.info("Bill Fetch Callback Failed with Status: {}", billValidateResponse.getGenericResponse().getStatus()); + LOGGER.info("Bill Fetch Callback Failed with Status: {}", billValidateResponse.getGenericResponse().getStatus()); } - return new ResponseModel("CallBack Recieved Successfully", - "200", - 200, - ""); + return new ResponseModel(BBPSConstant.CALLBACK_RECEIVED_SUCCESS, + BBPSConstant.SUCCESS_CODE_STR, + 200, + "" + ); } } \ No newline at end of file diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java index 1333591..9fa3124 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java @@ -8,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; @@ -20,13 +19,11 @@ import com.billpaymentservice.bbps.dto.request.ComplaintRequestDTO; import com.billpaymentservice.bbps.dto.request.GetTicketLatestStausRequest; import com.billpaymentservice.bbps.dto.request.TxnStatusRequest; import com.billpaymentservice.bbps.dto.request.ViewAllComplaintsTicketsRequest; -import com.billpaymentservice.bbps.dto.request.ViewAllComplaintsRequest; import com.billpaymentservice.bbps.dto.response.ComplaintHistoryStatusResponse; import com.billpaymentservice.bbps.dto.response.ComplaintResponse; import com.billpaymentservice.bbps.dto.response.TicketCheckStatusResponse; import com.billpaymentservice.bbps.dto.response.TxnStatusResponse; import com.billpaymentservice.bbps.dto.response.ViewAllComplaintsTicketsResponse; -import com.billpaymentservice.bbps.dto.response.ViewAllComplaintsResponse; import com.billpaymentservice.bbps.dto.response.ViewComplainByIdResponse; import com.billpaymentservice.bbps.entites.BharatConnectMaster; import com.billpaymentservice.bbps.entites.ComplaintStatusOptionsMaster; @@ -90,7 +87,7 @@ public class ComplainServiceImpl implements ComplainService { LOGGER.info("Initiating add Complain for request ID: {} and MID {}", complainRequestDTO.getReqId(), complainRequestDTO.getMid()); - String apiName = "ADD_COMPLAIN"; + String apiName = BBPSConstant.API_ADD_COMPLAIN; String txnId = helper.generateTxnId(15); String requestId = complainRequestDTO.getReqId(); String fullUrl = complainDataUrl + BBPSConstant.ADD_COMPLAIN_ENDPOINT; @@ -101,13 +98,13 @@ public class ComplainServiceImpl implements ComplainService { String requestJson = helper.convertObjectToJson(complainRequestDTO); // Fetch tenant & agent from DB - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); 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", null); + BBPSConstant.HTTP_POST, requestJson); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, fullUrl, BBPSConstant.HTTP_POST, null); try { // Inject tenantId + agentId into request JSON @@ -121,13 +118,13 @@ public class ComplainServiceImpl implements ComplainService { // IMPORTANT: Send finalJson, not requestJson Map responseMap = httpService.postRequest(fullUrl, finalJson, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Fetched response: {}", 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) { @@ -141,12 +138,13 @@ public class ComplainServiceImpl implements ComplainService { new TypeReference>() { }); - 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) { - throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), - statusCode, String.valueOf(dataMap.get("remarks"))); + 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))); } // Convert to response wrapper @@ -160,7 +158,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"); } } @@ -170,7 +168,7 @@ public class ComplainServiceImpl implements ComplainService { LOGGER.info("Fetching Complaint Status for TicketId={} ReqId={}", request.getTicketId(), request.getReqId()); - String apiName = "COMPLAINT_STATUS"; + String apiName = BBPSConstant.API_COMPLAINT_STATUS; String txnId = helper.generateTxnId(15); String reqId = request.getReqId(); String complaintId = request.getTicketId(); @@ -178,17 +176,17 @@ public class ComplainServiceImpl implements ComplainService { helper.validateMerchant(request.getMid()); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); HttpHeaders headers = helper.buildHeaders(headersData); // Convert request to JSON String requestJson = helper.convertObjectToJson(request); - InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "POST", - requestJson); + InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), BBPSConstant.HTTP_POST, + requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "POST", complaintId); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_POST, complaintId); try { @@ -201,12 +199,13 @@ public class ComplainServiceImpl implements ComplainService { // LOGGER.info("Calling external API: {}", fullUrl); Map responseMap = httpService.postRequest(fullUrl, finalJson, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Complaint Fetch Response: {}", 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) { @@ -220,11 +219,12 @@ public class ComplainServiceImpl implements ComplainService { new TypeReference>() { }); - int statusCode = Integer.parseInt(String.valueOf(dataMap.get("statusCode"))); + int statusCode = Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))); - if (statusCode != 200) { - throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), - statusCode, String.valueOf(dataMap.get("remarks"))); + 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); @@ -236,7 +236,7 @@ public class ComplainServiceImpl implements ComplainService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing JSON in complaint status API: {}", 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"); } } @@ -245,7 +245,7 @@ public class ComplainServiceImpl implements ComplainService { public ResponseModel viewComplaintHistory(ComplainStatusRequest request) { LOGGER.info("Fetching View Complaint History Complaint by Complaint Id={}", request.getTicketId(), request.getReqId()); - String apiName = "View_Complaint_History"; + String apiName = BBPSConstant.API_VIEW_COMPLAINT_HISTORY; String txnId = helper.generateTxnId(15); String reqId = request.getReqId(); String ticketId = request.getTicketId(); @@ -253,20 +253,20 @@ public class ComplainServiceImpl implements ComplainService { helper.validateMerchant(request.getMid()); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + 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); + 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: {}", fullUrl); Map 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); @@ -275,11 +275,12 @@ public class ComplainServiceImpl implements ComplainService { new TypeReference>() { }); - 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("")); } ComplaintHistoryStatusResponse responseWrapper = objectMapper.convertValue(dataMap, @@ -297,7 +298,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"); } } @@ -306,7 +307,7 @@ public class ComplainServiceImpl implements ComplainService { public ResponseModel viewComplaintById(ComplainStatusRequest request) { LOGGER.info("Fetching View Complaint Complaint by Complaint Id={}", request.getTicketId(), request.getReqId()); - String apiName = "View_Complaint_By_ID"; + String apiName = BBPSConstant.API_VIEW_COMPLAINT_BY_ID; String txnId = helper.generateTxnId(15); String reqId = request.getReqId(); String ticketId = request.getTicketId(); @@ -314,20 +315,20 @@ public class ComplainServiceImpl implements ComplainService { helper.validateMerchant(request.getMid()); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + 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); + 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: {}", fullUrl); Map 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); @@ -336,11 +337,12 @@ public class ComplainServiceImpl implements ComplainService { new TypeReference>() { }); - 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, @@ -358,7 +360,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"); } } @@ -368,17 +370,17 @@ public class ComplainServiceImpl implements ComplainService { try { LOGGER.info("Fetch All Master Options - MID: {}", request.getMid()); - String apiName = "View All Options Fetch By Id"; + String apiName = BBPSConstant.API_GET_ALL_MASTER_OPTIONS; String txnId = helper.generateTxnId(15); String reqId = request.getReqId(); - String fullUrl = "Data Base Options"; + 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(), "GET", - requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null); + 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 @@ -389,27 +391,29 @@ 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, + 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) { LOGGER.info("Check Txn Status Request by Id={} and ReqId ={}", request.getId(), request.getReqId()); - String apiName = "CheckTxnStatus"; + String apiName = BBPSConstant.API_CHECK_TXN_STATUS; String txnId = helper.generateTxnId(15); String reqId = request.getReqId(); String ID = request.getId(); @@ -417,20 +421,20 @@ public class ComplainServiceImpl implements ComplainService { helper.validateMerchant(request.getMid()); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + 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", 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 API: {}", fullUrl); Map 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); @@ -439,11 +443,12 @@ public class ComplainServiceImpl implements ComplainService { new TypeReference>() { }); - 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); @@ -457,7 +462,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"); } @@ -468,30 +473,30 @@ public class ComplainServiceImpl implements ComplainService { 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 txnId = helper.generateTxnId(15); String reqId = request.getReqId(); String fullUrl = complainDataUrl + BBPSConstant.VIEW_ALL_COMPLAINTS_BASE + "?pageNo=" + request.getPageNo() - + "&pageSize=" + request.getPageSize() + "&statusType=" + request.getStatusType() + "&ticketType=" - + request.getTicketType(); + + "&pageSize=" + request.getPageSize() + "&statusType=" + request.getStatusType() + "&ticketType=" + + request.getTicketType(); helper.validateMerchant(request.getMid()); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + 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(), "POST", - requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", - request.getStatusType()); + 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: {}", fullUrl); Map responseMap = httpService.getRequest(fullUrl, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Response: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -500,11 +505,12 @@ public class ComplainServiceImpl implements ComplainService { new TypeReference>() { }); - 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, @@ -521,7 +527,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"); } } diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java index dc84b78..5caf1ca 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java @@ -10,10 +10,7 @@ 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 com.billpaymentservice.bbps.dto.ContactMaster; import com.billpaymentservice.bbps.dto.CustomParamDTO; import com.billpaymentservice.bbps.dto.CustomerParamGroupsDTO; import com.billpaymentservice.bbps.dto.GeneralResp; @@ -108,16 +105,16 @@ public class MasterDataServiceImpl implements MasterDataService { public ResponseModel getMasterData(MasterRequest masterRequest) { LOGGER.info("Fetching Master Data for ReqId={} and MID={}", masterRequest.getReqId(), masterRequest.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "GetMasterData"; + String apiName = BBPSConstant.API_GET_MASTER_DATA; String requestId = masterRequest.getReqId(); String requestJson = helper.convertObjectToJson(masterRequest); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), "POST", + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), BBPSConstant.HTTP_POST, requestJson); try { // Merchant Validation helper.validateMerchant(masterRequest.getMid()); // check Tenant Id is present DB - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); if (headersData == null) { LOGGER.warn("header data not found for the orgID"); throw new CustomException("Something went wrong", "FAILED", 500, ""); @@ -125,21 +122,21 @@ public class MasterDataServiceImpl implements MasterDataService { // get full url String fullUrl = masterRegisterUrl + BBPSConstant.MASTER_CATEGORY_URL + headersData.getTenantId(); LOGGER.info("Calling external API: {}", fullUrl); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); HttpHeaders headers = helper.buildHeaders(headersData); Map responseMap = httpService.getRequest(fullUrl, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); helper.updateOutboundLogResponse(outboundLog, responseData); Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - throw new CustomException(String.valueOf(dataMap.get("message")), // message - String.valueOf(dataMap.get("status")), // status - Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode - String.valueOf(dataMap.get("remarks")) // remarks + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)) // remarks ); } @@ -155,8 +152,9 @@ public class MasterDataServiceImpl implements MasterDataService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", 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"); + } } @@ -168,31 +166,31 @@ public class MasterDataServiceImpl implements MasterDataService { helper.validateMerchant(billerDetailRequest.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "GetBillerByBillerId"; + String apiName = BBPSConstant.API_GET_BILLER_BY_ID; String requestId = billerDetailRequest.getReqId(); String billerId = billerDetailRequest.getBillerId(); String fullUrl = masterRegisterUrl + BBPSConstant.BILLER_DATA_FETCH_URL + billerId; String requestJson = helper.convertObjectToJson(billerDetailRequest); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, billerDetailRequest.getMid(), - "POST", requestJson); + BBPSConstant.HTTP_POST, requestJson); System.out.println(billerDataRespository.findByBillerId(billerId)); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external API: {}", fullUrl); Map responseMap = httpService.getRequest(fullUrl); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("fetched data from api is :{}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); try { Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), - Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), - String.valueOf(dataMap.get("remarks"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + 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(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } BillerDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillerDataResponse.class); GeneralResp generalResp = responseWrapper.getGeneralResp(); @@ -208,7 +206,7 @@ public class MasterDataServiceImpl implements MasterDataService { return responseModel; } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", 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"); } } @@ -220,21 +218,21 @@ public class MasterDataServiceImpl implements MasterDataService { customerParamRequest.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "GetCustomerParamByBillerId"; + String apiName = BBPSConstant.API_GET_CUSTOMER_PARAM_BY_BILLER_ID; String requestId = customerParamRequest.getReqId(); String requestJson = helper.convertObjectToJson(customerParamRequest); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, customerParamRequest.getMid(), - "POST", requestJson); + BBPSConstant.HTTP_POST, requestJson); try { helper.validateMerchant(customerParamRequest.getMid()); String billerId = customerParamRequest.getBillerId(); String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMPARAM_URL + billerId; - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external API: {}", fullUrl); Map responseMap = httpService.getRequest(fullUrl); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("data is :{}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -242,12 +240,12 @@ public class MasterDataServiceImpl implements MasterDataService { Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - throw new CustomException(String.valueOf(dataMap.get("message")), // message - String.valueOf(dataMap.get("status")), // status - Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int) - String.valueOf(dataMap.get("remarks"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode (int) + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } CustomParamResp responseWrapper = objectMapper.convertValue(dataMap, CustomParamResp.class); @@ -270,7 +268,7 @@ public class MasterDataServiceImpl implements MasterDataService { return responseModel; } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", 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"); } } @@ -280,23 +278,23 @@ public class MasterDataServiceImpl implements MasterDataService { LOGGER.info("Fetching Contact Master Request Data " + contactMasterRequest); String txnID = helper.generateTxnId(15); - String apiName = "FetchMasterDataCategoryWise"; + String apiName = BBPSConstant.API_FETCH_MASTER_DATA_CATEGORY_WISE; String requestId = contactMasterRequest.getReqId(); String requestJson = helper.convertObjectToJson(contactMasterRequest); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, contactMasterRequest.getMid(), - "POST", requestJson); + BBPSConstant.HTTP_POST, requestJson); try { helper.validateMerchant(contactMasterRequest.getMid()); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); String fullUrl = masterRegisterUrl + String.format(BBPSConstant.CONTACT_MASTER_URL, headersData.getTenantId(), contactMasterRequest.getCategory()); LOGGER.info("Contact Master Full URL-:" + fullUrl); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); HttpHeaders headers = helper.buildHeaders(headersData); Map responseMap = httpService.getRequest(fullUrl, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Response Data: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -305,12 +303,12 @@ public class MasterDataServiceImpl implements MasterDataService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - throw new CustomException(String.valueOf(dataMap.get("message")), // message - String.valueOf(dataMap.get("status")), // status - Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode - String.valueOf(dataMap.get("remarks")) // remarks + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)) // remarks ); } @@ -329,7 +327,7 @@ public class MasterDataServiceImpl implements MasterDataService { return responseModel; } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", 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"); } } @@ -339,10 +337,10 @@ public class MasterDataServiceImpl implements MasterDataService { LOGGER.info("Fetching Master Data CategoryResponseList-wise " + masterRequest); String txnID = helper.generateTxnId(15); - String apiName = "FetchMasterDataCategoryWise"; + String apiName = BBPSConstant.API_FETCH_MASTER_DATA_CATEGORY_WISE; String requestId = masterRequest.getReqId(); String requestJson = helper.convertObjectToJson(masterRequest); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), "POST", + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), BBPSConstant.HTTP_POST, requestJson); try { helper.validateMerchant(masterRequest.getMid()); @@ -351,10 +349,10 @@ public class MasterDataServiceImpl implements MasterDataService { masterRequest.getPageNo(), masterRequest.getPageSize()); LOGGER.info("Calling external API: {}", fullUrl); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); Map responseMap = httpService.getRequest(fullUrl); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); // LOGGER.info("Response Data: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -363,12 +361,12 @@ public class MasterDataServiceImpl implements MasterDataService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - throw new CustomException(String.valueOf(dataMap.get("message")), // message - String.valueOf(dataMap.get("status")), // status - Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode - String.valueOf(dataMap.get("remarks")) // remarks + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)) // remarks ); } @@ -386,7 +384,7 @@ public class MasterDataServiceImpl implements MasterDataService { return responseModel; } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", 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"); } } @@ -397,17 +395,17 @@ public class MasterDataServiceImpl implements MasterDataService { dispositionDetailRequest.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "GetDispositionDetails"; + String apiName = BBPSConstant.API_GET_TICKET_DISPOSITIONS; String requestId = dispositionDetailRequest.getReqId(); helper.validateMerchant(dispositionDetailRequest.getMid()); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, - dispositionDetailRequest.getMid(), "GET", "N/A"); + dispositionDetailRequest.getMid(), BBPSConstant.HTTP_GET, "N/A"); String fullUrl = masterRegisterUrl + BBPSConstant.DISPOSTION_URL; - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external API: {}", fullUrl); Map responseMap = httpService.getRequest(fullUrl); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); helper.updateOutboundLogResponse(outboundLog, responseData); try { @@ -415,12 +413,12 @@ public class MasterDataServiceImpl implements MasterDataService { Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - throw new CustomException(String.valueOf(dataMap.get("message")), // message - String.valueOf(dataMap.get("status")), // status - Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int) - String.valueOf(dataMap.get("remarks"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode (int) + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } DispositionResponse responseWrapper = objectMapper.convertValue(dataMap, DispositionResponse.class); @@ -447,7 +445,7 @@ public class MasterDataServiceImpl implements MasterDataService { return responseModel; } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", 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"); } @@ -458,31 +456,31 @@ public class MasterDataServiceImpl implements MasterDataService { LOGGER.info("Fetching Customer Param Group for ReqId={} and MID={}", requestModel.getReqId(), requestModel.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "FetchCustomerParamGroup"; + String apiName = BBPSConstant.API_FETCH_CUSTOMER_PARAM_GROUP; String requestId = requestModel.getReqId(); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST", + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel)); try { helper.validateMerchant(requestModel.getMid()); String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMER_PARAM_GROUP + requestModel.getBillerId(); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external API: {}", fullUrl); Map apiResponse = httpService.getRequest(fullUrl); - String responseData = apiResponse.get("data").toString(); + String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString(); helper.updateOutboundLogResponse(outboundLog, responseData); Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - throw new CustomException(String.valueOf(dataMap.get("message")), // message - String.valueOf(dataMap.get("status")), // status - Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int) - String.valueOf(dataMap.get("remarks"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode (int) + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } CustomerParamGroupsResponse responseWrapper = objectMapper.convertValue(dataMap, @@ -501,7 +499,7 @@ public class MasterDataServiceImpl implements MasterDataService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", 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"); } @@ -513,20 +511,20 @@ public class MasterDataServiceImpl implements MasterDataService { LOGGER.info("Fetching Master Data Amount List for ReqId={} and MID={}", requestModel.getReqId(), requestModel.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "FetchAllMasterAmountOption"; + String apiName = BBPSConstant.API_FETCH_ALL_MASTER_AMOUNT_OPTION; String requestId = requestModel.getReqId(); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST", + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel)); try { helper.validateMerchant(requestModel.getMid()); String fullUrl = masterRegisterUrl + BBPSConstant.AMOUNT_OPTIONS + requestModel.getBillerId(); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external API: {}", fullUrl); Map apiResponse = httpService.getRequest(fullUrl); LOGGER.info("Response" + apiResponse); - String responseData = apiResponse.get("data").toString(); + String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString(); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -534,12 +532,12 @@ public class MasterDataServiceImpl implements MasterDataService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - throw new CustomException(String.valueOf(dataMap.get("message")), // message - String.valueOf(dataMap.get("status")), // status - Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int) - String.valueOf(dataMap.get("remarks"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode (int) + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } AmountOptionsResponse responseWrapper = objectMapper.convertValue(dataMap, AmountOptionsResponse.class); @@ -558,7 +556,7 @@ public class MasterDataServiceImpl implements MasterDataService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", 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"); } @@ -568,20 +566,20 @@ public class MasterDataServiceImpl implements MasterDataService { public ResponseModel fetchPlanCategorie(BillerDetailRequest requestModel) { LOGGER.info("Fetching Plan Categories for ReqId={} and MID={}", requestModel.getReqId(), requestModel.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "FetchPlanCategorie"; + String apiName = BBPSConstant.API_FETCH_PLAN_CATEGORIES; String requestId = requestModel.getReqId(); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST", + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel)); try { helper.validateMerchant(requestModel.getMid()); String fullUrl = masterRegisterUrl + BBPSConstant.PLAN_CATEGORIES + requestModel.getBillerId(); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external API: {}", fullUrl); Map apiResponse = httpService.getRequest(fullUrl); LOGGER.info("Response" + apiResponse); - String responseData = apiResponse.get("data").toString(); + String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString(); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -589,12 +587,12 @@ public class MasterDataServiceImpl implements MasterDataService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - throw new CustomException(String.valueOf(dataMap.get("message")), // message - String.valueOf(dataMap.get("status")), // status - Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int) - String.valueOf(dataMap.get("remarks"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode (int) + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } PlaneCategoriesResponse responseWrapper = objectMapper.convertValue(dataMap, PlaneCategoriesResponse.class); @@ -611,7 +609,7 @@ public class MasterDataServiceImpl implements MasterDataService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", 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"); } @@ -622,9 +620,9 @@ public class MasterDataServiceImpl implements MasterDataService { LOGGER.info("Fetching Initiating Channel for ReqId={} and MID={}", requestModel.getReqId(), requestModel.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "FetchInitiatingChannel"; + String apiName = BBPSConstant.API_FETCH_INITIATING_CHANNEL; String requestId = requestModel.getReqId(); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST", + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel)); try { @@ -632,11 +630,11 @@ public class MasterDataServiceImpl implements MasterDataService { String fullUrl = masterRegisterUrl + BBPSConstant.INITIATING_CHANNEL; - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling Master API: {}", fullUrl); Map apiResponse = httpService.getRequest(fullUrl); LOGGER.info("Response" + apiResponse); - String responseData = apiResponse.get("data").toString(); + String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString(); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -644,12 +642,12 @@ public class MasterDataServiceImpl implements MasterDataService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - throw new CustomException(String.valueOf(dataMap.get("message")), // message - String.valueOf(dataMap.get("status")), // status - Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int) - String.valueOf(dataMap.get("remarks"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode (int) + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } ChannelsListResponse responseWrapper = objectMapper.convertValue(dataMap, ChannelsListResponse.class); @@ -664,7 +662,7 @@ public class MasterDataServiceImpl implements MasterDataService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", 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"); } @@ -675,7 +673,7 @@ public class MasterDataServiceImpl implements MasterDataService { LOGGER.info("Fetching Plan By Categories for ReqId={} and MID={}", requestModel.getReqId(), requestModel.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "FetchPlanByCategories"; + String apiName = BBPSConstant.API_FETCH_PLAN_BY_CATEGORIES; String requestId = requestModel.getReqId(); helper.validateMerchant(requestModel.getMid()); @@ -691,12 +689,12 @@ public class MasterDataServiceImpl implements MasterDataService { // Convert request to JSON and create inbound & outbound logs String requestJson = helper.convertObjectToJson(requestModel); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST", + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), BBPSConstant.HTTP_POST, requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, BBPSConstant.HTTP_GET, null); try { Map apiResponse = httpService.getRequest(url); - String responseData = apiResponse.get("data"); + String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Response Data: {}", responseData); // Update outbound log with response @@ -706,12 +704,13 @@ public class MasterDataServiceImpl implements MasterDataService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { // Failure response - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), - Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), - String.valueOf(dataMap.get("remarks"))); + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + 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(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } // Success response @@ -727,7 +726,7 @@ public class MasterDataServiceImpl implements MasterDataService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", 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"); } } @@ -738,17 +737,17 @@ public class MasterDataServiceImpl implements MasterDataService { dispositionDetailRequest.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "GetTicketDispositionDetails"; + String apiName = BBPSConstant.API_GET_TICKET_DISPOSITIONS; String requestId = dispositionDetailRequest.getReqId(); helper.validateMerchant(dispositionDetailRequest.getMid()); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, - dispositionDetailRequest.getMid(), "GET", "N/A"); + dispositionDetailRequest.getMid(), BBPSConstant.HTTP_GET, "N/A"); String fullUrl = masterRegisterUrl + BBPSConstant.TICKET_DISPOSTION_URL; - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external API: {}", fullUrl); Map responseMap = httpService.getRequest(fullUrl); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); helper.updateOutboundLogResponse(outboundLog, responseData); try { @@ -756,12 +755,12 @@ public class MasterDataServiceImpl implements MasterDataService { Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - throw new CustomException(String.valueOf(dataMap.get("message")), // message - String.valueOf(dataMap.get("status")), // status - Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int) - String.valueOf(dataMap.get("remarks"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode (int) + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } TicketDispositionResponse responseWrapper = objectMapper.convertValue(dataMap, @@ -779,9 +778,9 @@ public class MasterDataServiceImpl implements MasterDataService { return responseModel; } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", 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"); } } -} +} \ No newline at end of file diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java index d54bb22..4bfe2a1 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java @@ -10,7 +10,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 com.billpaymentservice.bbps.dto.GeneralResp; import com.billpaymentservice.bbps.dto.ResponseModel; diff --git a/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java b/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java index 71924f1..be6c549 100644 --- a/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java +++ b/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java @@ -59,4 +59,80 @@ public class BBPSConstant { public static final String ADD_COMPLAIN_ENDPOINT = "/couapp/ticket/raise"; public static final String VIEW_ALL_COMPLAINTS_BASE = "/couapp/tickets"; -} + // New centralized string/constants used across services + public static final String API_INITIATE_BILL_FETCH = "InitiateBillFetch"; + public static final String API_FETCH_BILL_BY_ID = "FetchBillById"; + public static final String API_INITIATE_BILL_VALIDATE = "InitiateBillValidate"; + public static final String API_FETCH_BILL_VALIDATE_BY_CLIENT_ID = "FetchBillValidateByClientIdRequest"; + public static final String API_FETCH_BILL_BY_CLIENT_ID = "FetchBillByClientIdRequest"; + + public static final String HTTP_POST = "POST"; + public static final String HTTP_GET = "GET"; + + public static final String INVALID_RESPONSE = "INVALID_RESPONSE"; + public static final String JSON_ERROR = "JSON_ERROR"; + + public static final String CALLBACK_RECEIVED_SUCCESS = "CallBack Recieved Successfully"; + public static final String NO_BILL_FOUND = "No Bill Found for given Client Req Id"; + + public static final String SUCCESS_CODE_STR = "200"; + + // Added constants referenced by ComplainServiceImpl + public static final String ORG_ID = "ORG001"; + + public static final String API_ADD_COMPLAIN = "ADD_COMPLAIN"; + public static final String API_COMPLAINT_STATUS = "COMPLAINT_STATUS"; + public static final String API_VIEW_COMPLAINT_HISTORY = "View_Complaint_History"; + public static final String API_VIEW_COMPLAINT_BY_ID = "View_Complaint_By_ID"; + public static final String API_GET_ALL_MASTER_OPTIONS = "View All Options Fetch By Id"; + public static final String API_CHECK_TXN_STATUS = "CheckTxnStatus"; + public static final String API_VIEW_ALL_COMPLAINTS_BY_STATUS = "View_All_Complaint_By_Status_Type"; + + // API names used by MasterDataServiceImpl + public static final String API_GET_MASTER_DATA = "GetMasterData"; + public static final String API_GET_BILLER_BY_ID = "GetBillerByBillerId"; + public static final String API_GET_CUSTOMER_PARAM_BY_BILLER_ID = "GetCustomerParamByBillerId"; + public static final String API_FETCH_MASTER_DATA_CATEGORY_WISE = "FetchMasterDataCategoryWise"; + public static final String API_FETCH_CUSTOMER_PARAM_GROUP = "FetchCustomerParamGroup"; + public static final String API_FETCH_ALL_MASTER_AMOUNT_OPTION = "FetchAllMasterAmountOption"; + public static final String API_FETCH_PLAN_CATEGORIES = "FetchPlanCategorie"; + public static final String API_FETCH_INITIATING_CHANNEL = "FetchInitiatingChannel"; + public static final String API_FETCH_PLAN_BY_CATEGORIES = "FetchPlanByCategories"; + public static final String API_GET_TICKET_DISPOSITIONS = "GetTicketDispositionDetails"; + + // Payment related API names + public static final String API_INITIATE_PAYMENT = "InitiatePayment"; + public static final String API_CHECK_TRANSACTION_STATUS = "CheckTransactionStatus"; + public static final String API_CHECK_TRANSACTION_PUBLIC = "checkTrasactionStatus"; + public static final String API_CHECK_BY_CLIENT_REQ_ID = "checkTrasactionStatusbyClientReqId"; + + // Response and helper keys (already existing ones kept) + public static final String RESPONSE_GENERIC_KEY = "genericResponse"; + + // Common messages used in PaymentServiceImpl + public static final String EMPTY_RESPONSE_FROM_BBPS = "Empty response from BBPS"; + public static final String INVALID_STRUCTURE = "INVALID_STRUCTURE"; + public static final String FAILED_STR = "FAILED"; + + public static final int HTTP_OK_INT = 200; + public static final int HTTP_NOT_FOUND = 404; + public static final int HTTP_INTERNAL_SERVER_ERROR = 500; + + // Response and helper keys + public static final String HTTP_SERVICE_ERROR_PREFIX = "HttpService Error"; + public static final String RESPONSE_DATA_KEY = "data"; + public static final String RESPONSE_MESSAGE_KEY = "message"; + public static final String RESPONSE_STATUS_KEY = "status"; + public static final String RESPONSE_STATUSCODE_KEY = "statusCode"; + public static final String RESPONSE_REMARKS_KEY = "remarks"; + public static final String RESPONSE_GENERAL_RESP = "generalResp"; + public static final String SUCCESS_RESPONSE = "SUCCESS"; + + // Newly added constants used by ComplainServiceImpl + public static final String DB_OPTIONS = "/db/options"; // used as a logical URL/identifier for master options + public static final String NULL_DATA_FROM_DB = "NULL_DATA_FROM_DB"; + public static final String NO_MASTER_FIELDS_FOUND = "No master fields found"; + public static final String ALL_MASTER_FIELDS_FETCH = "All master fields fetched successfully"; + public static final String SOMETHING_WENT_WRONG = "Something went wrong"; + +} \ No newline at end of file diff --git a/src/main/java/com/billpaymentservice/bbps/util/EntityRelationshipUtil.java b/src/main/java/com/billpaymentservice/bbps/util/EntityRelationshipUtil.java index caec51d..3d7c59f 100644 --- a/src/main/java/com/billpaymentservice/bbps/util/EntityRelationshipUtil.java +++ b/src/main/java/com/billpaymentservice/bbps/util/EntityRelationshipUtil.java @@ -1,7 +1,4 @@ package com.billpaymentservice.bbps.util; - -import com.billpaymentservice.bbps.dto.request.FetchBillRequest; -import com.billpaymentservice.bbps.dto.sentRequest.FetchBillForwardRequest; import com.billpaymentservice.bbps.entites.BillerDetails; import com.billpaymentservice.bbps.entites.BillerResponseParams; import com.billpaymentservice.bbps.entites.InterchangeFee; diff --git a/src/main/java/com/billpaymentservice/bbps/util/Helper.java b/src/main/java/com/billpaymentservice/bbps/util/Helper.java index edda1a7..087ca8f 100644 --- a/src/main/java/com/billpaymentservice/bbps/util/Helper.java +++ b/src/main/java/com/billpaymentservice/bbps/util/Helper.java @@ -2,44 +2,14 @@ package com.billpaymentservice.bbps.util; import java.security.SecureRandom; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Collectors; - -import org.modelmapper.ModelMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; - -import com.billpaymentservice.bbps.dto.AdditionalInfoBillDTO; -import com.billpaymentservice.bbps.dto.CustomerParamDAO; -import com.billpaymentservice.bbps.dto.ResponseModel; -import com.billpaymentservice.bbps.dto.request.BillFetchByBillIdRequest; -import com.billpaymentservice.bbps.dto.request.BillPaymentRequest; -import com.billpaymentservice.bbps.dto.request.FetchBillRequest; -import com.billpaymentservice.bbps.dto.request.FetchBillValidatestRequest; -import com.billpaymentservice.bbps.dto.response.BillDataResponse; -import com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse; -import com.billpaymentservice.bbps.dto.sentRequest.BillPaymentForwardRequest; -import com.billpaymentservice.bbps.dto.sentRequest.FetchBillForwardRequest; -import com.billpaymentservice.bbps.dto.sentRequest.FetchBillValidatestForwardRequest; -import com.billpaymentservice.bbps.entites.AdditionalInfoBill; -import com.billpaymentservice.bbps.entites.AdditionalInfoBillValidate; import com.billpaymentservice.bbps.entites.BBPSMastersData; -import com.billpaymentservice.bbps.entites.BillMaster; -import com.billpaymentservice.bbps.entites.BillValidation; -import com.billpaymentservice.bbps.entites.BillerDetails; -import com.billpaymentservice.bbps.entites.BillerResponse; -import com.billpaymentservice.bbps.entites.CustomerParamBill; -import com.billpaymentservice.bbps.entites.CustomerParamBillValidation; import com.billpaymentservice.bbps.entites.InboundTraceLog; import com.billpaymentservice.bbps.entites.OutboundTraceLog; -import com.billpaymentservice.bbps.entites.PaymentChannel; -import com.billpaymentservice.bbps.entites.PaymentMode; import com.billpaymentservice.bbps.entites.BharatConnectMaster; import com.billpaymentservice.bbps.exception.CustomException; import com.billpaymentservice.bbps.repository.BBPSMasterDataRepo; @@ -81,34 +51,6 @@ public class Helper { * * */ - public void startPolling(T requestObject, // Request object (any type) - Function apiCallFunction, // Function to call API - int intervalSeconds, // gap between two polls - int maxDurationSeconds // total polling time - ) { - new Thread(() -> { - try { - int maxAttempts = maxDurationSeconds / intervalSeconds; - - for (int i = 0; i < maxAttempts; i++) { - LOGGER.info("⏳ Polling attempt {}...", i + 1); - - ResponseModel response = apiCallFunction.apply(requestObject); - LOGGER.info("📥 Poll response: {}", response); - - if ("SUCCESS".equalsIgnoreCase(response.getStatus())) { - LOGGER.info("✅ Polling successful, stopping early."); - break; - } - - Thread.sleep(intervalSeconds * 1000L); - } - } catch (Exception e) { - LOGGER.error("❌ Error in polling thread: {}", e.getMessage(), e); - } - }).start(); - } - public void validateMerchant(String mid) { if (mid == null || mid == "") { LOGGER.warn("MerchantRequestModel or MID is null"); @@ -206,7 +148,6 @@ public class Helper { outboundLog.setResponsePayload(responsePayload); outboundLog.setResponseReceiveTime(LocalDateTime.now()); outboundTraceLogRepository.save(outboundLog); - } /* ---------- End helpers ---------- */