added billValidateByBillId direct method
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
package com.billpaymentservice.bbps.entites;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "additional_info_bill_validate")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class AdditionalInfoBillValidate {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String value;
|
||||||
|
// ✅ Many Params → One Bill
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "bill_id_fk")
|
||||||
|
private BillValidation bill;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -75,8 +75,8 @@ public class AgentServiceImpl implements AgentService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseModel initiateBillFetch(FetchBillRequest fetchBillRequest) {
|
public ResponseModel initiateBillFetch(FetchBillRequest fetchBillRequest) {
|
||||||
LOGGER.info("Initiating bill fetch for request ID: {} and MID", fetchBillRequest.getReqId(),
|
LOGGER.info("Initiating bill fetch for request ID: {} and MID :{} and billerId:{} ", fetchBillRequest.getReqId(),
|
||||||
fetchBillRequest.getMid());
|
fetchBillRequest.getMid(),fetchBillRequest.getBillerId());
|
||||||
String apiName = "InitiateBillFetch";
|
String apiName = "InitiateBillFetch";
|
||||||
String txnId = helper.generateTxnId(15);
|
String txnId = helper.generateTxnId(15);
|
||||||
String requestId = fetchBillRequest.getReqId();
|
String requestId = fetchBillRequest.getReqId();
|
||||||
@@ -224,69 +224,81 @@ public class AgentServiceImpl implements AgentService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseModel fetchBillById(BillFetchByBillIdRequest billFetchByBillIdRequest) {
|
public ResponseModel fetchBillById(BillFetchByBillIdRequest billFetchByBillIdRequest) {
|
||||||
String apiName = "FetchBillById";
|
String apiName = "FetchBillById";
|
||||||
String txnId = helper.generateTxnId(15);
|
String txnId = helper.generateTxnId(15);
|
||||||
String reqId = billFetchByBillIdRequest.getReqId();
|
String reqId = billFetchByBillIdRequest.getReqId();
|
||||||
String billId = billFetchByBillIdRequest.getBillId();
|
String billId = billFetchByBillIdRequest.getBillId();
|
||||||
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID + billFetchByBillIdRequest.getBillId();
|
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID + billFetchByBillIdRequest.getBillId();
|
||||||
|
|
||||||
LOGGER.info("Initiating {} API for billId={} and reqId={}", apiName, billId, reqId);
|
LOGGER.info("Initiating {} API for billId={} and reqId={}", apiName, billId, reqId);
|
||||||
|
|
||||||
try {
|
// create inbound log (GET -> no request body)
|
||||||
helper.validateMerchant(billFetchByBillIdRequest.getMid());
|
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName,
|
||||||
LOGGER.debug("Merchant validated successfully for MID={}", billFetchByBillIdRequest.getMid());
|
billFetchByBillIdRequest.getMid(), "GET", null);
|
||||||
|
|
||||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
|
try {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
helper.validateMerchant(billFetchByBillIdRequest.getMid());
|
||||||
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
|
LOGGER.debug("Merchant validated successfully for MID={}", billFetchByBillIdRequest.getMid());
|
||||||
headers.set("agentId", headersData.getAgentId());
|
|
||||||
headers.set("tenantId", headersData.getTenantId());
|
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
|
|
||||||
LOGGER.info("Calling external BBPS API for FetchBillById, URL={}", fullUrl);
|
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
HttpHeaders headers = new HttpHeaders();
|
||||||
String responseData = responseMap.get("data");
|
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
|
||||||
LOGGER.info("Response received from BBPS for billId={} : {}", billId, responseData);
|
headers.set("agentId", headersData.getAgentId());
|
||||||
|
headers.set("tenantId", headersData.getTenantId());
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
// create outbound log
|
||||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null);
|
||||||
new TypeReference<Map<String, Object>>() {
|
LOGGER.info("Calling external BBPS API for FetchBillById, URL={}", fullUrl);
|
||||||
});
|
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
||||||
|
String responseData = responseMap.get("data");
|
||||||
|
LOGGER.info("Response received from BBPS for billId={} : {}", billId, responseData);
|
||||||
|
|
||||||
if (!dataMap.containsKey("genericResponse")) {
|
// update outbound log with response
|
||||||
LOGGER.warn("Invalid response structure received for billId={} | Response={}", billId, responseData);
|
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||||
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")));
|
|
||||||
}
|
|
||||||
|
|
||||||
BillDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillDataResponse.class);
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
GeneralResp generalResp = responseWrapper.getGenericResponse();
|
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
new TypeReference<Map<String, Object>>() {
|
||||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
});
|
||||||
|
|
||||||
helper.saveOrUpdateBillData(responseWrapper, billFetchByBillIdRequest,txnId);
|
if (!dataMap.containsKey("genericResponse")) {
|
||||||
LOGGER.info("Bill data saved successfully for billId={} | Status={}", billId, generalResp.getStatus());
|
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
|
||||||
|
LOGGER.warn("Invalid response structure received for billId={} | Response={}", billId, responseData);
|
||||||
|
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")));
|
||||||
|
}
|
||||||
|
|
||||||
return responseModel;
|
BillDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillDataResponse.class);
|
||||||
|
GeneralResp generalResp = responseWrapper.getGenericResponse();
|
||||||
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||||
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||||
|
|
||||||
} catch (JsonProcessingException e) {
|
// update inbound log success and persist bill data
|
||||||
LOGGER.error("Error parsing responseData JSON for billId={} : {}", billId, e.getMessage(), e);
|
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||||
throw new CustomException("Invalid JSON received from API");
|
helper.saveOrUpdateBillData(responseWrapper, billFetchByBillIdRequest, txnId);
|
||||||
}
|
LOGGER.info("Bill data saved successfully for billId={} | Status={}", billId, generalResp.getStatus());
|
||||||
|
|
||||||
|
return responseModel;
|
||||||
|
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
LOGGER.error("Error parsing responseData JSON for billId={} : {}", billId, e.getMessage(), e);
|
||||||
|
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||||
|
throw new CustomException("Invalid JSON received from API");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseModel initiateBillValidate(FetchBillValidatestRequest fetchBillValidateRequest) {
|
public ResponseModel initiateBillValidate(FetchBillValidatestRequest fetchBillValidateRequest) {
|
||||||
|
LOGGER.info("Initiating bill Validate for request ID: {} and MID:{} and billerId:{}", fetchBillValidateRequest.getReqId(),
|
||||||
|
fetchBillValidateRequest.getMid(),fetchBillValidateRequest.getBillerId());
|
||||||
LOGGER.info("Initiating bill Validate for request ID: {} and MID", fetchBillValidateRequest.getReqId(),
|
|
||||||
fetchBillValidateRequest.getMid());
|
|
||||||
String apiName = "InitiateBillValidate";
|
String apiName = "InitiateBillValidate";
|
||||||
String txnId = helper.generateTxnId(15);
|
String txnId = helper.generateTxnId(15);
|
||||||
String reqId = fetchBillValidateRequest.getReqId();
|
String reqId = fetchBillValidateRequest.getReqId();
|
||||||
@@ -445,6 +457,71 @@ public class AgentServiceImpl implements AgentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseModel initiateBillValidateByBillId(BillFetchByBillIdRequest billRequest) {
|
||||||
|
String apiName = "FetchBillById";
|
||||||
|
String txnId = helper.generateTxnId(15);
|
||||||
|
String reqId = billRequest.getReqId();
|
||||||
|
String billId = billRequest.getBillId();
|
||||||
|
String fullUrl = agentDtaUrl + BBPSConstant.BILL_VALIDATE_ID_URL + billRequest.getBillId();
|
||||||
|
|
||||||
|
LOGGER.info("Initiating {} API for billId={} and reqId={}", apiName, billId, reqId);
|
||||||
|
|
||||||
|
// create inbound log (GET -> no request body)
|
||||||
|
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, billRequest.getMid(), "GET", null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
helper.validateMerchant(billRequest.getMid());
|
||||||
|
|
||||||
|
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
|
||||||
|
headers.set("agentId", headersData.getAgentId());
|
||||||
|
headers.set("tenantId", headersData.getTenantId());
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
|
// create outbound log
|
||||||
|
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null);
|
||||||
|
LOGGER.info("Calling external BBPS API for ValidateByBillId, URL={}", fullUrl);
|
||||||
|
|
||||||
|
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
||||||
|
String responseData = responseMap.get("data");
|
||||||
|
LOGGER.info("Response received from BBPS for billId={} : {}", billId, responseData);
|
||||||
|
|
||||||
|
// update outbound log with response
|
||||||
|
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||||
|
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
Map<String, Object> dataMap = objectMapper.readValue(responseData, new com.fasterxml.jackson.core.type.TypeReference<Map<String, Object>>(){});
|
||||||
|
|
||||||
|
if (!dataMap.containsKey("genericResponse")) {
|
||||||
|
helper.updateInboundLogFailure(inboundLog, responseData, "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")),
|
||||||
|
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))),
|
||||||
|
String.valueOf(dataMap.get("remarks")));
|
||||||
|
}
|
||||||
|
|
||||||
|
FetchBillValidateResponse responseWrapper = objectMapper.convertValue(dataMap, FetchBillValidateResponse.class);
|
||||||
|
GeneralResp generalResp = responseWrapper.getGenericResponse();
|
||||||
|
|
||||||
|
// update inbound log and save validation data
|
||||||
|
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||||
|
helper.saveBillValidation(responseWrapper, billRequest);
|
||||||
|
LOGGER.info("Bill validation saved successfully for billId: {}", billId);
|
||||||
|
|
||||||
|
return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||||
|
|
||||||
|
} catch (com.fasterxml.jackson.core.JsonProcessingException e) {
|
||||||
|
LOGGER.error("Error parsing ValidateByBillId JSON: {}", e.getMessage(), e);
|
||||||
|
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||||
|
throw new CustomException("Invalid JSON received from API");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//================================== Bill fetch and Bill Validate by Client Req Id==================================//
|
//================================== Bill fetch and Bill Validate by Client Req Id==================================//
|
||||||
@@ -582,201 +659,4 @@ public class AgentServiceImpl implements AgentService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @Override public ResponseModel
|
|
||||||
* initiateBillValidate(FetchBillValidatestRequest fetchBillValidateRequest) {
|
|
||||||
*
|
|
||||||
* ResponseModel responseModel = new ResponseModel(); try {
|
|
||||||
*
|
|
||||||
* helper.validateMerchant(fetchBillValidateRequest.getMid());
|
|
||||||
*
|
|
||||||
* BharatConnectMaster headersData =
|
|
||||||
* beneficiaryDetailsRepository.findByOrgId("ORG001");
|
|
||||||
*
|
|
||||||
* if (headersData == null) { responseModel = new
|
|
||||||
* ResponseModel("Tenant Id Is Null", "Not Found", BBPSConstant.BADREQUEST,
|
|
||||||
* headersData); return responseModel; }
|
|
||||||
*
|
|
||||||
* HttpHeaders headers = new HttpHeaders(); headers.set("x-digiledge-key",
|
|
||||||
* headersData.getXDigiledgeKey()); headers.set("agentId",
|
|
||||||
* headersData.getAgentId()); headers.set("tenantId",
|
|
||||||
* headersData.getTenantId());
|
|
||||||
* headers.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
*
|
|
||||||
* ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
* objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); String
|
|
||||||
* json = objectMapper.writeValueAsString(fetchBillValidateRequest); String url
|
|
||||||
* = agentDtaUrl + BBPSConstant.BILLER_VALIDATE_URL;
|
|
||||||
*
|
|
||||||
* Map<String, String> responseMap = httpService.postRequest(url, json,
|
|
||||||
* headers); String responseData = responseMap.get("data");
|
|
||||||
*
|
|
||||||
* log.info("📦 Bill Fetch API Response: {}", responseData);
|
|
||||||
*
|
|
||||||
* if (responseData == null || responseData.isEmpty()) { throw new
|
|
||||||
* CustomException("Empty response from BBPS server"); }
|
|
||||||
*
|
|
||||||
* // ✅ Convert JSON string → Map Map<String, Object> dataMap =
|
|
||||||
* objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>()
|
|
||||||
* {});
|
|
||||||
*
|
|
||||||
* // ✅ Validate generalResp if (!dataMap.containsKey("genericResponse")) {
|
|
||||||
* throw new CustomException("Invalid response structure from BBPS"); }
|
|
||||||
*
|
|
||||||
* // ✅ Convert to your custom DTO FetchBillValidatestResponse fetchBillResponse
|
|
||||||
* = objectMapper.convertValue(dataMap, FetchBillValidatestResponse.class);
|
|
||||||
* GeneralResp generalResponse = fetchBillResponse.getGenericResponse();
|
|
||||||
*
|
|
||||||
* // ✅ Build final ResponseModel responseModel = new ResponseModel(
|
|
||||||
* generalResponse.getMessage(), generalResponse.getStatus(),
|
|
||||||
* Integer.parseInt(generalResponse.getStatusCode()), fetchBillResponse );
|
|
||||||
*
|
|
||||||
* } catch (CustomException ex) { log.warn("Merchant validation failed: {}",
|
|
||||||
* ex.getMessage()); return ex.getResponseModel(); // Directly return
|
|
||||||
* ResponseModel from exception } catch (Exception e) {
|
|
||||||
* log.error("❌ Exception in initiateBillFetch(): {}", e.getMessage(), e);
|
|
||||||
* responseModel.setStatus("500");
|
|
||||||
* responseModel.setMessage("Exception occurred");
|
|
||||||
* responseModel.setData(e.getMessage()); }
|
|
||||||
*
|
|
||||||
* return responseModel; }
|
|
||||||
*
|
|
||||||
* @Override public ResponseModel
|
|
||||||
* initiateBillValidateByBillId(BillFetchByBillIdRequest billRequest) {
|
|
||||||
*
|
|
||||||
* ResponseModel responseModel = new ResponseModel(); try {
|
|
||||||
* helper.validateMerchant(billRequest.getMid());
|
|
||||||
*
|
|
||||||
* BharatConnectMaster headersData =
|
|
||||||
* beneficiaryDetailsRepository.findByOrgId("ORG001");
|
|
||||||
*
|
|
||||||
* if (headersData == null) { responseModel = new
|
|
||||||
* ResponseModel("Tenant Id Is Null", "Not Found", BBPSConstant.BADREQUEST,
|
|
||||||
* headersData); return responseModel; }
|
|
||||||
*
|
|
||||||
* HttpHeaders headers = new HttpHeaders(); headers.set("x-digiledge-key",
|
|
||||||
* headersData.getXDigiledgeKey()); headers.set("agentId",
|
|
||||||
* headersData.getAgentId()); headers.set("tenantId",
|
|
||||||
* headersData.getTenantId());
|
|
||||||
* headers.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
*
|
|
||||||
* ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
* objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); String
|
|
||||||
* json = objectMapper.writeValueAsString(billRequest); String url = agentDtaUrl
|
|
||||||
* + BBPSConstant.BILL_ID_URL + billRequest.getBillId();
|
|
||||||
*
|
|
||||||
* log.info("Full URL: {}", url);
|
|
||||||
* objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
|
||||||
*
|
|
||||||
* // ✅ Call the API using httpService Map<String, String> responseMap =
|
|
||||||
* httpService.getRequest(url, headers); String responseData =
|
|
||||||
* responseMap.get("data");
|
|
||||||
*
|
|
||||||
* log.info("📦 Bill Fetch API Response: {}", responseData);
|
|
||||||
*
|
|
||||||
* if (responseData == null || responseData.isEmpty()) { throw new
|
|
||||||
* CustomException("Empty response from BBPS server"); }
|
|
||||||
*
|
|
||||||
* // ✅ Convert JSON string → Map Map<String, Object> dataMap =
|
|
||||||
* objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>()
|
|
||||||
* {});
|
|
||||||
*
|
|
||||||
* // ✅ Validate generalResp if (!dataMap.containsKey("genericResponse")) {
|
|
||||||
* throw new CustomException("Invalid response structure from BBPS"); }
|
|
||||||
*
|
|
||||||
* // ✅ Convert to your custom DTO BillDataResponse fetchBillResponse =
|
|
||||||
* objectMapper.convertValue(dataMap, BillDataResponse.class); GeneralResp
|
|
||||||
* generalResponse = fetchBillResponse.getGenericResponse();
|
|
||||||
*
|
|
||||||
* // ✅ Build final ResponseModel responseModel = new ResponseModel(
|
|
||||||
* generalResponse.getRemarks(), generalResponse.getStatus(),
|
|
||||||
* Integer.parseInt(generalResponse.getStatusCode()), fetchBillResponse );
|
|
||||||
*
|
|
||||||
* } catch (CustomException ex) { log.warn("Merchant validation failed: {}",
|
|
||||||
* ex.getMessage()); return ex.getResponseModel(); // Directly return
|
|
||||||
* ResponseModel from exception } catch (Exception e) {
|
|
||||||
* log.error("❌ Exception in initiateBillFetch(): {}", e.getMessage(), e);
|
|
||||||
* responseModel.setStatus("500");
|
|
||||||
* responseModel.setMessage("Exception occurred");
|
|
||||||
* responseModel.setData(e.getMessage()); }
|
|
||||||
*
|
|
||||||
* return responseModel; }
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* POLLING METHOD public ResponseModel fetchBillById(BillFetchByBillIdRequest
|
|
||||||
* billFetchByBillIdRequest, InboundTraceLog inboundLog) { String apiName =
|
|
||||||
* "FetchBillById"; String txnId = helper.generateTxnId(15); String reqId =
|
|
||||||
* billFetchByBillIdRequest.getReqId(); String billId =
|
|
||||||
* billFetchByBillIdRequest.getBillId(); String url = agentDtaUrl +
|
|
||||||
* BBPSConstant.BILL_FETCH_BY_ID + "1ced7566-1add-4e01-9ed6-04cd67ac9684";
|
|
||||||
*
|
|
||||||
* helper.validateMerchant(billFetchByBillIdRequest.getMid());
|
|
||||||
*
|
|
||||||
* BharatConnectMaster headersData =
|
|
||||||
* beneficiaryDetailsRepository.findByOrgId("ORG001"); HttpHeaders headers = new
|
|
||||||
* HttpHeaders(); headers.set("x-digiledge-key",
|
|
||||||
* headersData.getXDigiledgeKey()); headers.set("agentId",
|
|
||||||
* headersData.getAgentId()); headers.set("tenantId",
|
|
||||||
* headersData.getTenantId());
|
|
||||||
* headers.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
*
|
|
||||||
* ObjectMapper objectMapper = new ObjectMapper(); OutboundTraceLog outboundLog
|
|
||||||
* = helper.createOutboundLog(txnId, reqId, apiName, url, "GET", null);
|
|
||||||
*
|
|
||||||
* // ✅ Loop setup long startTime = System.currentTimeMillis(); long
|
|
||||||
* maxWaitTimeMs = 40000; // 40 seconds long intervalMs = 5000; // 5 seconds
|
|
||||||
*
|
|
||||||
* while (true) { try { Map<String, String> responseMap =
|
|
||||||
* httpService.getRequest(url, headers); String responseData =
|
|
||||||
* responseMap.get("data"); log.info("📦 Bill FetchById Response: {}",
|
|
||||||
* responseData);
|
|
||||||
*
|
|
||||||
* helper.updateOutboundLogResponse(outboundLog, responseData);
|
|
||||||
*
|
|
||||||
* Map<String, Object> dataMap = objectMapper.readValue(responseData, new
|
|
||||||
* TypeReference<Map<String, Object>>() {});
|
|
||||||
*
|
|
||||||
* if (!dataMap.containsKey("genericResponse")) {
|
|
||||||
* helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
|
|
||||||
* throw new CustomException( String.valueOf(dataMap.get("message")),
|
|
||||||
* String.valueOf(dataMap.get("status")),
|
|
||||||
* Integer.parseInt(String.valueOf(dataMap.get("statusCode"))),
|
|
||||||
* String.valueOf(dataMap.get("remarks")) ); }
|
|
||||||
*
|
|
||||||
* BillDataResponse responseWrapper = objectMapper.convertValue(dataMap,
|
|
||||||
* BillDataResponse.class); GeneralResp generalResp =
|
|
||||||
* responseWrapper.getGenericResponse();
|
|
||||||
*
|
|
||||||
* String status = generalResp.getStatus();
|
|
||||||
* log.info("📡 Current Bill Status: {}", status); // ✅ Check for "INPROGRESS"
|
|
||||||
* or pending state if ("INPROGRESS".equalsIgnoreCase(status)) { if
|
|
||||||
* (System.currentTimeMillis() - startTime > maxWaitTimeMs) {
|
|
||||||
* helper.updateInboundLogFailure(inboundLog, "Timeout after 40 seconds",
|
|
||||||
* "FAILED"); throw new CustomException("Timeout", "FAILED", 408,
|
|
||||||
* "Bill fetch still in progress"); } Thread.sleep(intervalMs); continue; //
|
|
||||||
* retry again } // ✅ Final successful response
|
|
||||||
* helper.updateInboundLogSuccess(inboundLog, responseData,
|
|
||||||
* generalResp.getStatus()); return new ResponseModel( generalResp.getMessage(),
|
|
||||||
* generalResp.getStatus(), Integer.parseInt(generalResp.getStatusCode()),
|
|
||||||
* responseWrapper ); } catch (JsonProcessingException e) {
|
|
||||||
* log.error("Error parsing BillById JSON: {}", e.getMessage());
|
|
||||||
* helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
|
||||||
* throw new CustomException("Invalid JSON received from API"); } catch
|
|
||||||
* (InterruptedException e) { Thread.currentThread().interrupt();
|
|
||||||
* helper.updateInboundLogFailure(inboundLog, e.getMessage(), "INTERRUPTED");
|
|
||||||
* throw new CustomException("Thread interrupted during bill status check"); } }
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResponseModel initiateBillValidateByBillId(BillFetchByBillIdRequest billRequest) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user