update code resolved conflict

This commit is contained in:
Mohd-Arham
2025-11-21 10:55:54 +05:30
32 changed files with 964 additions and 419 deletions
@@ -1,6 +1,7 @@
package com.billpaymentservice.bbps.serviceImpl;
import java.util.Map;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,11 +14,15 @@ import org.springframework.web.client.RestClient;
import com.billpaymentservice.bbps.dto.GeneralResp;
import com.billpaymentservice.bbps.dto.ResponseModel;
import com.billpaymentservice.bbps.dto.request.BillFetchByBillIdRequest;
import com.billpaymentservice.bbps.dto.request.BillFetchByClientIdRequest;
import com.billpaymentservice.bbps.dto.request.BillValidateByClientIdRequest;
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.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;
@@ -37,7 +42,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
@@ -54,7 +58,7 @@ public class AgentServiceImpl implements AgentService {
private final BillMasterRepository billMasterRepository;
private final BillInitateRepository billIntiateRepository;
private static final Logger LOGGER = LoggerFactory.getLogger(AgentServiceImpl.class);
public AgentServiceImpl(RestClient restClient, HttpService httpService, Helper helper,
BharatConnectMasterRepository beneficiaryDetailsRepository,
InboundTraceLogRepository inboundTraceLogRepository, OutboundTraceLogRepository outboundTraceLogRepository,
@@ -77,7 +81,7 @@ public class AgentServiceImpl implements AgentService {
String txnId = helper.generateTxnId(15);
String requestId = fetchBillRequest.getReqId();
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_INTI;
fetchBillRequest.setClientReqId(txnId);
helper.validateMerchant(fetchBillRequest.getMid());
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
@@ -89,18 +93,21 @@ public class AgentServiceImpl implements AgentService {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
FetchBillForwardRequest forwardReq = helper.fetchBillForwardRequestMap(fetchBillRequest);
String forwardJson = helper.convertObjectToJson(forwardReq);
String requestJson = helper.convertObjectToJson(fetchBillRequest);
// ✅ Create inbound & outbound logs
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, fetchBillRequest.getMid(),
"POST", requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, fullUrl, "POST",
requestJson);
forwardJson);
LOGGER.debug("Outbound log created successfully for txnId: {} and reqId: {}", txnId, requestId);
try {
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.postRequest(fullUrl, requestJson, headers);
Map<String, String> responseMap = httpService.postRequest(fullUrl, forwardJson, headers);
String responseData = responseMap.get("data");
helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -163,9 +170,7 @@ public class AgentServiceImpl implements AgentService {
String reqId = billFetchByBillIdRequest.getReqId();
String billId = billFetchByBillIdRequest.getBillId();
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID + billFetchByBillIdRequest.getBillId();
helper.validateMerchant(billFetchByBillIdRequest.getMid());
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
HttpHeaders headers = new HttpHeaders();
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
@@ -204,7 +209,7 @@ public class AgentServiceImpl implements AgentService {
LOGGER.info("Current Bill Status: {}", status);
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
helper.saveOrUpdateBillerData(responseWrapper, billFetchByBillIdRequest);
helper.saveOrUpdateBillData(responseWrapper, billFetchByBillIdRequest, txnId);
LOGGER.info("Bill data saved successfully for billId: {}", billId);
return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
@@ -222,7 +227,7 @@ public class AgentServiceImpl implements AgentService {
String txnId = helper.generateTxnId(15);
String reqId = billFetchByBillIdRequest.getReqId();
String billId = billFetchByBillIdRequest.getBillId();
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID + "43f61299-7682-4586-b298-1f8828dcaa46";
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID + billFetchByBillIdRequest.getBillId();
LOGGER.info("Initiating {} API for billId={} and reqId={}", apiName, billId, reqId);
@@ -260,7 +265,7 @@ public class AgentServiceImpl implements AgentService {
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
helper.saveOrUpdateBillerData(responseWrapper, billFetchByBillIdRequest);
helper.saveOrUpdateBillData(responseWrapper, billFetchByBillIdRequest, txnId);
LOGGER.info("Bill data saved successfully for billId={} | Status={}", billId, generalResp.getStatus());
return responseModel;
@@ -274,14 +279,13 @@ public class AgentServiceImpl implements AgentService {
@Override
public ResponseModel initiateBillValidate(FetchBillValidatestRequest fetchBillValidateRequest) {
LOGGER.info("Initiating bill Validate for request ID: {} and MID", fetchBillValidateRequest.getReqId(),
fetchBillValidateRequest.getMid());
String apiName = "InitiateBillValidate";
String txnId = helper.generateTxnId(15);
String reqId = fetchBillValidateRequest.getReqId();
String fullUrl = agentDtaUrl + BBPSConstant.BILLER_VALIDATE_URL;
fetchBillValidateRequest.setClientReqId(txnId);
helper.validateMerchant(fetchBillValidateRequest.getMid());
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
@@ -293,25 +297,27 @@ public class AgentServiceImpl implements AgentService {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
FetchBillValidatestForwardRequest forwardReq = helper
.fetchBillValidatestForwardRequest(fetchBillValidateRequest);
String forwardJson = helper.convertObjectToJson(forwardReq);
String requestJson = helper.convertObjectToJson(fetchBillValidateRequest);
// ✅ Create inbound & outbound logs
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, fetchBillValidateRequest.getMid(),
"POST", requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "POST",
requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "POST", forwardJson);
LOGGER.debug("Outbound log created successfully for txnId: {} and reqId: {}", txnId, reqId);
try {
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.postRequest(fullUrl, requestJson, headers);
Map<String, String> responseMap = httpService.postRequest(fullUrl, forwardJson, headers);
String responseData = responseMap.get("data");
helper.updateOutboundLogResponse(outboundLog, responseData);
LOGGER.debug("Response received from BBPS: {}", responseData);
Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() {
});
@@ -329,7 +335,6 @@ public class AgentServiceImpl implements AgentService {
billMaster.setTxnId(txnId);
billMasterRepository.save(billMaster);
LOGGER.info("BillMaster saved for billId: {}", billMaster.getBillId());
FetchBillResponse fetchBillResponse = objectMapper.convertValue(dataMap, FetchBillResponse.class);
GeneralResp generalResponse = fetchBillResponse.getGenericResponse();
helper.updateInboundLogSuccess(inboundLog, responseData, generalResponse.getStatus());
@@ -360,79 +365,208 @@ public class AgentServiceImpl implements AgentService {
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
}
public ResponseModel BillvaidateByBillId(BillFetchByBillIdRequest billRequest, InboundTraceLog inboundLog) {
{
LOGGER.info("Validating bill by BILLID for request ID={} and MID={}", billRequest.getReqId(),
billRequest.getMid());
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();
;
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);
ObjectMapper objectMapper = new ObjectMapper();
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null);
LOGGER.debug("Outbound log created successfully for FetchBillById: {}", fullUrl);
try {
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
String responseData = responseMap.get("data");
LOGGER.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");
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(dataMap.get("remarks")));
}
FetchBillValidateResponse responseWrapper = objectMapper.convertValue(dataMap,
FetchBillValidateResponse.class);
GeneralResp generalResp = responseWrapper.getGenericResponse();
String status = generalResp.getStatus();
LOGGER.info("Current Bill Status: {}", status);
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
System.out.println("responseWrapper:" + responseWrapper);
helper.saveBillValidation(responseWrapper, billRequest);
LOGGER.info("Bill data saved successfully for billId: {}", billId);
return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
} catch (JsonProcessingException e) {
LOGGER.error("Error parsing BillById JSON: {}", e.getMessage(), e);
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
}
}
public ResponseModel BillvaidateByBillId( BillFetchByBillIdRequest billRequest,InboundTraceLog inboundLog) { {
LOGGER.info("Validating bill by BILLID for request ID={} and MID={}", billRequest.getReqId(), billRequest.getMid());
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(); ;
// ================================== Bill fetch and Bill Validate by Client Req
// Id==================================//
helper.validateMerchant(billRequest.getMid());
@Override
public ResponseModel fetchBillValidateByClientReqId(BillValidateByClientIdRequest billValidateByClientIdRequest) {
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);
String apiName = "FetchBillValidateByClientIdRequest";
String txnId = helper.generateTxnId(15);
String reqId = billValidateByClientIdRequest.getReqId();
String clientReqId = billValidateByClientIdRequest.getClientReqId();
ObjectMapper objectMapper = new ObjectMapper();
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null);
LOGGER.debug("Outbound log created successfully for FetchBillById: {}", fullUrl);
Optional<BillInitiate> billInitiate = billIntiateRepository.findByReqId(clientReqId);
if (billInitiate.isEmpty()) {
throw new CustomException("No Bill Found for given Client Req Id");
}
try {
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
String responseData = responseMap.get("data");
LOGGER.info("Bill FetchById Response: {}", responseData);
String fullUrl = agentDtaUrl + BBPSConstant.BILL_VALIDATE_BY_CLIENT_REQ_ID + billInitiate.get().getTxnId();
helper.updateOutboundLogResponse(outboundLog, responseData);
helper.validateMerchant(billValidateByClientIdRequest.getMid());
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
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);
if (!dataMap.containsKey("genericResponse")) {
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
LOGGER.warn("Invalid response structure for txnId: {}", txnId);
throw new CustomException(
String.valueOf(dataMap.get("message")),
String.valueOf(dataMap.get("status")),
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))),
String.valueOf(dataMap.get("remarks"))
);
}
ObjectMapper objectMapper = new ObjectMapper();
FetchBillValidateResponse responseWrapper = objectMapper.convertValue(dataMap, FetchBillValidateResponse.class);
GeneralResp generalResp = responseWrapper.getGenericResponse();
// 🔵 Create Inbound + Outbound Logs
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName,
billValidateByClientIdRequest.getMid(), "GET", null);
String status = generalResp.getStatus();
LOGGER.info("Current Bill Status: {}", status);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null);
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
System.out.println("responseWrapper:"+responseWrapper);
helper.saveBillValidation(responseWrapper,billRequest);
LOGGER.info("Bill data saved successfully for billId: {}", billId);
try {
LOGGER.info("Calling BBPS API FetchBillValidateByClientReqId, URL={}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
String responseData = responseMap.get("data");
return new ResponseModel(
generalResp.getMessage(),
generalResp.getStatus(),
Integer.parseInt(generalResp.getStatusCode()),
responseWrapper
);
} catch (JsonProcessingException e) {
LOGGER.error("Error parsing BillById JSON: {}", e.getMessage(), e);
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
}}
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")));
}
FetchBillValidateResponse responseWrapper = objectMapper.convertValue(dataMap,
FetchBillValidateResponse.class);
GeneralResp generalResp = responseWrapper.getGenericResponse();
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
} catch (JsonProcessingException e) {
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
}
@Override
public ResponseModel fetchBillByClientReqId(BillFetchByClientIdRequest billFetchByClientIdRequest) {
String apiName = "FetchBillByClientIdRequest";
String txnId = helper.generateTxnId(15);
String reqId = billFetchByClientIdRequest.getReqId();
String clientReqId = billFetchByClientIdRequest.getClientReqId();
Optional<BillInitiate> billInitiate = billIntiateRepository.findByReqId(clientReqId);
if (billInitiate.isEmpty()) {
throw new CustomException("No Bill Found for given Client Req Id");
}
String fullUrl = agentDtaUrl + BBPSConstant.BILL_VALIDATE_BY_CLIENT_REQ_ID + billInitiate.get().getTxnId();
helper.validateMerchant(billFetchByClientIdRequest.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();
// 🔵 Create inbound + outbound logs
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, billFetchByClientIdRequest.getMid(),
"GET", null);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null);
try {
LOGGER.info("Calling BBPS API FetchBillByClientReqId, URL={}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
String responseData = responseMap.get("data");
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();
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
} catch (JsonProcessingException e) {
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
}
/*
* @Override public ResponseModel
@@ -621,11 +755,9 @@ public class AgentServiceImpl implements AgentService {
* }
*/
@Override
public ResponseModel initiateBillValidateByBillId(BillFetchByBillIdRequest billRequest) {
// TODO Auto-generated method stub
return null;
}}
}
}