update Code Resolve Conflict

This commit is contained in:
Mohd-Arham
2025-11-11 11:56:41 +05:30
13 changed files with 516 additions and 153 deletions
@@ -17,7 +17,7 @@ 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.FetchBillValidatestResponse;
import com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse;
import com.billpaymentservice.bbps.entites.BharatConnectMaster;
import com.billpaymentservice.bbps.entites.BillInitiate;
import com.billpaymentservice.bbps.entites.BillMaster;
@@ -141,7 +141,7 @@ public class AgentServiceImpl implements AgentService {
billFetchByBillIdRequest.setReqId(requestId);
LOGGER.info("Waiting for 2 seconds before fetching bill by ID...");
try {
Thread.sleep(2000);
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOGGER.warn("Thread interrupted during delay: {}", e.getMessage());
@@ -273,143 +273,165 @@ public class AgentServiceImpl implements AgentService {
@Override
public ResponseModel initiateBillValidate(FetchBillValidatestRequest fetchBillValidateRequest) {
ResponseModel responseModel = new ResponseModel();
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;
helper.validateMerchant(fetchBillValidateRequest.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();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
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);
LOGGER.debug("Outbound log created successfully for txnId: {} and reqId: {}", txnId, reqId);
try {
String apiName = "InitiateBillValidate";
String txnId = helper.generateTxnId(15);
String requestId = fetchBillValidateRequest.getReqId();
String url = agentDtaUrl + BBPSConstant.BILLER_VALIDATE_URL;
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);
String requestJson = helper.convertObjectToJson(fetchBillValidateRequest);
ObjectMapper objectMapper = new ObjectMapper();
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName,
fetchBillValidateRequest.getMid(), "POST", requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, "POST",
requestJson);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
String json = objectMapper.writeValueAsString(fetchBillValidateRequest);
Map<String, String> responseMap = httpService.postRequest(url, json, headers);
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.postRequest(fullUrl, requestJson, headers);
String responseData = responseMap.get("data");
LOGGER.info("📦 Bill Fetch API Response: {}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData);
LOGGER.debug("Response received from BBPS: {}", responseData);
if (responseData == null || responseData.isEmpty()) {
helper.updateInboundLogFailure(inboundLog, "Empty response from BBPS", "FAILED");
throw new CustomException("Empty response from BBPS server");
}
Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() {
});
if (!dataMap.containsKey("genericResponse")) {
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_STRUCTURE");
throw new CustomException("Invalid response structure from BBPS");
helper.updateInboundLogFailure(inboundLog, responseData, "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"))),
String.valueOf(dataMap.get("remarks")));
}
FetchBillValidatestResponse fetchBillResponse = objectMapper.convertValue(dataMap,
FetchBillValidatestResponse.class);
BillMaster billMaster = new BillMaster();
billMaster.setBillId((String) dataMap.get("billId"));
billMaster.setReqId(fetchBillValidateRequest.getReqId());
billMaster.setTxnId(txnId);
billMasterRepository.save(billMaster);
LOGGER.info("BillMaster saved for billId: {}", billMaster.getBillId());
mapperHelper.saveFetchBillValidateResponse(fetchBillResponse, requestId, txnId);
FetchBillResponse fetchBillResponse = objectMapper.convertValue(dataMap, FetchBillResponse.class);
GeneralResp generalResponse = fetchBillResponse.getGenericResponse();
helper.updateInboundLogSuccess(inboundLog, responseData, generalResponse.getStatus());
responseModel = new ResponseModel(generalResponse.getMessage(), generalResponse.getStatus(),
Integer.parseInt(generalResponse.getStatusCode()), fetchBillResponse);
} catch (CustomException ex) {
LOGGER.warn("Merchant validation failed: {}", ex.getMessage());
return ex.getResponseModel();
} catch (Exception e) {
LOGGER.error("❌ Exception in initiateBillFetch(): {}", e.getMessage(), e);
responseModel.setStatus("500");
responseModel.setMessage("Exception occurred");
responseModel.setData(e.getMessage());
BillInitiate billInitiate = new BillInitiate();
billInitiate.setBillId((String) dataMap.get("billId"));
billInitiate.setReqId(fetchBillValidateRequest.getReqId());
billInitiate.setTxnId(txnId);
billIntiateRepository.save(billInitiate);
LOGGER.info("BillInitiate entry saved for billId: {}", billInitiate.getBillId());
BillFetchByBillIdRequest billFetchByBillIdRequest = new BillFetchByBillIdRequest();
billFetchByBillIdRequest.setBillId(fetchBillResponse.getBillId());
billFetchByBillIdRequest.setMid(fetchBillValidateRequest.getMid());
billFetchByBillIdRequest.setReqId(reqId);
LOGGER.info("Waiting for 2 seconds before fetching bill by ID...");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOGGER.warn("Thread interrupted during delay: {}", e.getMessage());
}
LOGGER.info("Calling internal method Fetching bill by ID: {}", billFetchByBillIdRequest.getBillId());
return BillvaidateByBillId(billFetchByBillIdRequest, inboundLog);
} catch (JsonProcessingException e) {
LOGGER.error("JSON Parsing Error: {}", e.getMessage(), e);
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
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();
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+ "c9670952-ebd7-487a-b6ea-49f2b4d4a718";
LOGGER.info("Full URL" + url);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
helper.validateMerchant(billRequest.getMid());
Map<String, String> responseMap = httpService.getRequest(url, headers);
String responseData = responseMap.get("data");
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);
LOGGER.info("📦 Bill Fetch API Response: {}", responseData);
ObjectMapper objectMapper = new ObjectMapper();
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null);
LOGGER.debug("Outbound log created successfully for FetchBillById: {}", fullUrl);
if (responseData == null || responseData.isEmpty()) {
throw new CustomException("Empty response from BBPS server");
}
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);
Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() {
});
helper.updateOutboundLogResponse(outboundLog, responseData);
if (!dataMap.containsKey("genericResponse")) {
throw new CustomException("Invalid response structure from BBPS");
}
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
BillDataResponse fetchBillResponse = objectMapper.convertValue(dataMap, BillDataResponse.class);
GeneralResp generalResponse = fetchBillResponse.getGenericResponse();
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"))
);
}
responseModel = new ResponseModel(generalResponse.getRemarks(), generalResponse.getStatus(),
Integer.parseInt(generalResponse.getStatusCode()), fetchBillResponse);
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");
}
}}
} catch (CustomException ex) {
LOGGER.warn("Merchant validation failed: {}", ex.getMessage());
return ex.getResponseModel();
} catch (Exception e) {
LOGGER.error("❌ Exception in initiateBillFetch(): {}", e.getMessage(), e);
responseModel.setStatus("500");
responseModel.setMessage("Exception occurred");
responseModel.setData(e.getMessage());
}
return responseModel;
}
/*
* @Override public ResponseModel
@@ -598,4 +620,11 @@ public class AgentServiceImpl implements AgentService {
* }
*/
}
@Override
public ResponseModel initiateBillValidateByBillId(BillFetchByBillIdRequest billRequest) {
// TODO Auto-generated method stub
return null;
}}
@@ -141,7 +141,7 @@ public class HttpService {
return response;
}
}
@@ -122,6 +122,7 @@ public class MasterDataServiceImpl implements MasterDataService {
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
Map<String, String> responseMap = httpService.getRequest(fullUrl);
String responseData = responseMap.get("data");
LOGGER.info("Response Data: {}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData);
Map<String, Object> dataMap = objectMapper.readValue(responseData,
@@ -191,7 +192,7 @@ public class MasterDataServiceImpl implements MasterDataService {
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
BillerDetails entity = mapper.map(responseWrapper.getBillerDAO(), BillerDetails.class);
EntityRelationshipUtil.linkBillerRelationships(entity);// linking nesting entity foreign key
helper.saveOrUpdateBillerData(entity);
//helper.saveOrUpdateBillerData(entity);
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());