merged with himanshu code after bbps contant added

This commit is contained in:
Mohd-Arham
2025-11-25 11:46:47 +05:30
12 changed files with 1215 additions and 1045 deletions
@@ -1,4 +1,3 @@
// java
package com.billpaymentservice.bbps.serviceImpl;
import java.util.List;
@@ -10,9 +9,8 @@ import org.modelmapper.convention.MatchingStrategies;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
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;
@@ -57,6 +55,7 @@ import com.billpaymentservice.bbps.util.BBPSConstant;
import com.billpaymentservice.bbps.util.BillerMapperHelper;
import com.billpaymentservice.bbps.util.EntityRelationshipUtil;
import com.billpaymentservice.bbps.util.Helper;
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;
@@ -77,7 +76,7 @@ public class MasterDataServiceImpl implements MasterDataService {
private final Helper helper;
private final BillerDataRepository billerDataRespository;
private final HttpService httpService;
private final ObjectMapper objectMapper = new ObjectMapper();
private final ObjectMapper objectMapper;
private final InboundTraceLogRepository inboundTraceLogRepository;
private final OutboundTraceLogRepository outboundTraceLogRepository;
private final CustomParamRepository customParamReposiotory;
@@ -99,50 +98,52 @@ public class MasterDataServiceImpl implements MasterDataService {
this.mapperHelper = mapperHelper;
this.customParamReposiotory = customParamReposiotory;
this.objectMapper = new ObjectMapper();
this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Override
public ResponseModel getMasterData(MasterRequest masterRequest) {
String apiName = "GetMasterData";
String apiName = BBPSConstant.API_GET_MASTER_DATA;
String requestId = masterRequest.getReqId();
String mid = masterRequest.getMid();
LOGGER.info("[{}] START | reqId={} | mid={}", apiName, requestId, mid);
// Merchant Validation
helper.validateMerchant(mid);
// check Tender Id is present DB
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
if (headersData == null) {
LOGGER.warn("header data not found for the orgID");
throw new CustomException("Something went wrong", "FAILED", 500, "");
}
// get full url
String fullUrl = masterRegisterUrl + BBPSConstant.MASTER_CATEGORY_URL + headersData.getTenantId();
String txnID = helper.generateTxnId(15);
String requestJson = helper.convertObjectToJson(masterRequest);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), "GET",
requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", requestJson);
try {
LOGGER.info("[{}] Calling External API | URL={} | Method=GET", apiName, fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl);
String responseData = responseMap.get("data");
LOGGER.debug("[{}] API Response | reqId={}", apiName, requestId);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(),
BBPSConstant.HTTP_POST, requestJson);
try {
// check Tenant Id is present DB
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, "");
}
// 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,
BBPSConstant.HTTP_GET, null);
HttpHeaders headers = helper.buildHeaders(headersData);
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
helper.updateOutboundLogResponse(outboundLog, responseData);
Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() {
});
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
);
}
@@ -158,8 +159,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");
}
}
@@ -167,38 +169,46 @@ public class MasterDataServiceImpl implements MasterDataService {
@Override
public ResponseModel getBillerByBillerId(BillerDetailRequest billerDetailRequest) {
String apiName = "Get_Biller_By_BillerId";
helper.validateMerchant(billerDetailRequest.getMid());
String apiName = BBPSConstant.API_GET_BILLER_BY_ID;
String requestId = billerDetailRequest.getReqId();
String billerId = billerDetailRequest.getBillerId();
String mid = billerDetailRequest.getMid();
LOGGER.info("[{}] START | reqId={} | mid={} | billerId={}", apiName, requestId, mid, billerId);
// 1. Validation
helper.validateMerchant(billerDetailRequest.getMid());
// 2. Transaction Id
String txnID = helper.generateTxnId(15);
// 3. Prepare URL
String fullUrl = masterRegisterUrl + BBPSConstant.BILLER_DATA_FETCH_URL + billerId;
// 4. Prepare Logs
String requestJson = helper.convertObjectToJson(billerDetailRequest);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, fullUrl, "GET", requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", requestJson);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, billerDetailRequest.getMid(),
BBPSConstant.HTTP_POST, requestJson);
System.out.println(billerDataRespository.findByBillerId(billerId));
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
BBPSConstant.HTTP_GET, null);
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl);
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
LOGGER.info("fetched data from api is :{}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData);
try {
LOGGER.info("[{}] Calling external API | URL={}", apiName, fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl);
String responseData = responseMap.get("data");
LOGGER.debug("[{}] API Response | reqId={} | data={}", apiName, requestId, responseData);
helper.updateOutboundLogResponse(outboundLog, responseData);
// Convert response
Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() {
});
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)));
}
// Mapping to Model
BillerDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillerDataResponse.class);
@@ -207,7 +217,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);
mapperHelper.saveOrUpdateBillerData(entity);
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
@@ -216,15 +226,14 @@ 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");
}
}
@Override
public ResponseModel getCustomerParamByBillerId(CustomParamRequest customerParamRequest) {
String apiName = "GetCustomerParamByBillerId";
String apiName = BBPSConstant.API_GET_CUSTOMER_PARAM_BY_BILLER_ID;
String requestId = customerParamRequest.getReqId();
String mid = customerParamRequest.getMid();
@@ -237,24 +246,30 @@ public class MasterDataServiceImpl implements MasterDataService {
String requestJson = helper.convertObjectToJson(customerParamRequest);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, customerParamRequest.getMid(),
"GET", requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", requestJson);
BBPSConstant.HTTP_POST, requestJson);
try {
LOGGER.info("[{}] Calling External API | URL={} | Method=GET", apiName, fullUrl);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
BBPSConstant.HTTP_GET, null);
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl);
String responseData = responseMap.get("data");
LOGGER.debug("[{}] API Response | reqId={} | data={}", apiName, requestId, responseData);
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
LOGGER.info("data is :{}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData);
Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() {
});
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);
@@ -278,7 +293,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");
}
}
@@ -286,7 +301,7 @@ public class MasterDataServiceImpl implements MasterDataService {
@Override
public ResponseModel getContactMaster(ContactMasterRequest contactMasterRequest) {
String apiName = "Fetch_Master_Data_Category_Wise";
String apiName = BBPSConstant.API_FETCH_MASTER_DATA_CATEGORY_WISE;
String requestId = contactMasterRequest.getReqId();
LOGGER.info("[{}] START | reqId={} | mid={} | category={}", apiName, requestId, contactMasterRequest.getMid(),
contactMasterRequest.getCategory());
@@ -294,32 +309,36 @@ public class MasterDataServiceImpl implements MasterDataService {
helper.validateMerchant(contactMasterRequest.getMid());
String txnID = helper.generateTxnId(15);
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());
String requestJson = helper.convertObjectToJson(contactMasterRequest);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, contactMasterRequest.getMid(),
"GET", requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", requestJson);
BBPSConstant.HTTP_POST, requestJson);
try {
LOGGER.info("[{}] Calling External API | URL={} | Method=GET", apiName, fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl);
String responseData = responseMap.get("data");
LOGGER.debug("[{}] External API Response | reqId={} | data={}", apiName, requestId, responseData);
LOGGER.info("Contact Master Full URL-:" + fullUrl);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
BBPSConstant.HTTP_GET, null);
HttpHeaders headers = helper.buildHeaders(headersData);
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
LOGGER.info("Response Data: {}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData);
Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() {
});
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
);
}
@@ -339,7 +358,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");
}
}
@@ -347,7 +366,7 @@ public class MasterDataServiceImpl implements MasterDataService {
@Override
public ResponseModel fetchMasterDataCategoryWise(MasterCategoryRequest masterRequest) {
String apiName = "FetchMasterDataCategoryWise";
String apiName = BBPSConstant.API_FETCH_MASTER_DATA_CATEGORY_WISE;
String requestId = masterRequest.getReqId();
String mid = masterRequest.getMid();
@@ -362,16 +381,18 @@ public class MasterDataServiceImpl implements MasterDataService {
LOGGER.info("Calling external API: {}", fullUrl);
String requestJson = helper.convertObjectToJson(masterRequest);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), "POST",
requestJson);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(),
BBPSConstant.HTTP_POST, requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
BBPSConstant.HTTP_GET, null);
try {
LOGGER.info("[{}] Calling External API | URL={} | Method=GET", apiName, fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl);
String responseData = responseMap.get("data");
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
LOGGER.debug("[{}] API Response | reqId={} | data={}", apiName, requestId, responseData);
helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -380,12 +401,13 @@ public class MasterDataServiceImpl implements MasterDataService {
new TypeReference<Map<String, Object>>() {
});
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
);
}
@@ -404,7 +426,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");
}
}
@@ -412,7 +434,7 @@ public class MasterDataServiceImpl implements MasterDataService {
@Override
public ResponseModel getDispositionDetails(DispositionRequest dispositionDetailRequest) {
String apiName = "GetDispositionDetails";
String apiName = BBPSConstant.API_GET_TICKET_DISPOSITIONS;
String requestId = dispositionDetailRequest.getReqId();
String mid = dispositionDetailRequest.getMid();
LOGGER.info("[{}] START | reqId={} | mid={}", apiName, requestId, mid);
@@ -422,27 +444,30 @@ public class MasterDataServiceImpl implements MasterDataService {
String txnID = helper.generateTxnId(15);
String fullUrl = masterRegisterUrl + BBPSConstant.DISPOSTION_URL;
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName,
dispositionDetailRequest.getMid(), "GET", "N/A");
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET",
dispositionDetailRequest.getMid());
dispositionDetailRequest.getMid(), BBPSConstant.HTTP_GET, "N/A");
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
BBPSConstant.HTTP_GET, null);
try {
LOGGER.info("[{}] Calling external API | URL={} | Method=GET", apiName, fullUrl);
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl);
String responseData = responseMap.get("data");
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
helper.updateOutboundLogResponse(outboundLog, responseData);
LOGGER.debug("[{}] API Response | reqId={} | data={}", apiName, requestId, responseData);
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() {
});
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);
@@ -468,7 +493,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");
}
@@ -477,38 +502,39 @@ public class MasterDataServiceImpl implements MasterDataService {
@Override
public ResponseModel fetchCustomerParamGroup(BillerDetailRequest requestModel) {
String apiName = "FetchCustomerParamGroup";
String apiName = BBPSConstant.API_FETCH_CUSTOMER_PARAM_GROUP;
String requestId = requestModel.getReqId();
String mid = requestModel.getMid();
LOGGER.info("[{}] START | reqId={} | mid={} | billerId={}", apiName, requestId, mid,
requestModel.getBillerId());
helper.validateMerchant(mid);
String txnID = helper.generateTxnId(15);
String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMER_PARAM_GROUP + requestModel.getBillerId();
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "GET",
helper.convertObjectToJson(requestModel));
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(),
BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel));
try {
LOGGER.info("[{}] Calling External API | URL={} | Method=GET", apiName, fullUrl);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
BBPSConstant.HTTP_GET, null);
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
String responseData = apiResponse.get("data").toString();
LOGGER.debug("[{}] API Response | reqId={} | data={}", apiName, requestId, responseData);
String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString();
helper.updateOutboundLogResponse(outboundLog, responseData);
Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() {
});
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,
@@ -530,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");
}
@@ -539,7 +565,7 @@ public class MasterDataServiceImpl implements MasterDataService {
@Override
public ResponseModel fetchAllMasterAmountOption(BillerDetailRequest requestModel) {
String apiName = "FetchAllMasterAmountOption";
String apiName = BBPSConstant.API_FETCH_ALL_MASTER_AMOUNT_OPTION;
String requestId = requestModel.getReqId();
String mid = requestModel.getMid();
@@ -549,17 +575,19 @@ public class MasterDataServiceImpl implements MasterDataService {
helper.validateMerchant(mid);
String txnID = helper.generateTxnId(15);
String fullUrl = masterRegisterUrl + BBPSConstant.AMOUNT_OPTIONS + requestModel.getBillerId();
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST",
helper.convertObjectToJson(requestModel));
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
try {
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(),
BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel));
try {
LOGGER.info("[{}] Calling External API | URL={} | Method=GET", apiName, fullUrl);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
BBPSConstant.HTTP_GET, null);
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
LOGGER.info("Response" + apiResponse);
String responseData = apiResponse.get("data").toString();
String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString();
LOGGER.debug("[{}] API Response | reqId={} | data={}", apiName, requestId, responseData);
helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -568,12 +596,14 @@ public class MasterDataServiceImpl implements MasterDataService {
new TypeReference<Map<String, Object>>() {
});
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);
@@ -594,7 +624,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");
}
@@ -603,7 +633,7 @@ public class MasterDataServiceImpl implements MasterDataService {
@Override
public ResponseModel fetchPlanCategorie(BillerDetailRequest requestModel) {
String apiName = "FetchPlanCategorie";
String apiName = BBPSConstant.API_FETCH_PLAN_CATEGORIES;
String requestId = requestModel.getReqId();
String mid = requestModel.getMid();
LOGGER.info("[{}] START | reqId={} | mid={} | billerId={}", apiName, requestId, mid,
@@ -612,14 +642,18 @@ public class MasterDataServiceImpl implements MasterDataService {
helper.validateMerchant(requestModel.getMid());
String txnID = helper.generateTxnId(15);
String fullUrl = masterRegisterUrl + BBPSConstant.PLAN_CATEGORIES + requestModel.getBillerId();
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "GET",
helper.convertObjectToJson(requestModel));
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(),
BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel));
try {
LOGGER.info("[{}] Calling External API | URL={} | Method=GET", apiName, fullUrl);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
BBPSConstant.HTTP_GET, null);
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> 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);
@@ -627,12 +661,14 @@ public class MasterDataServiceImpl implements MasterDataService {
new TypeReference<Map<String, Object>>() {
});
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);
@@ -652,7 +688,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");
}
@@ -661,7 +697,7 @@ public class MasterDataServiceImpl implements MasterDataService {
@Override
public ResponseModel fetchInitiatingChannel(BillerDetailRequest requestModel) {
String apiName = "FetchInitiatingChannel";
String apiName = BBPSConstant.API_FETCH_INITIATING_CHANNEL;
String requestId = requestModel.getReqId();
String mid = requestModel.getMid();
@@ -670,17 +706,17 @@ public class MasterDataServiceImpl implements MasterDataService {
helper.validateMerchant(mid);
String txnID = helper.generateTxnId(15);
String fullUrl = masterRegisterUrl + BBPSConstant.INITIATING_CHANNEL;
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "GET",
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), BBPSConstant.HTTP_POST,
helper.convertObjectToJson(requestModel));
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", mid);
try {
LOGGER.info("[{}] Calling Master API | URL={} | Method=GET", apiName, fullUrl);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null);
LOGGER.info("Calling Master API: {}", fullUrl);
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
String responseData = apiResponse.get("data").toString();
LOGGER.debug("[{}] API Response | reqId={} | data={}", apiName, requestId, responseData);
LOGGER.info("Response" + apiResponse);
String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString();
helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -688,12 +724,12 @@ public class MasterDataServiceImpl implements MasterDataService {
new TypeReference<Map<String, Object>>() {
});
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);
@@ -709,7 +745,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");
}
@@ -717,7 +753,7 @@ public class MasterDataServiceImpl implements MasterDataService {
public ResponseModel fetchPlanByCategories(PlanRequest requestModel) {
String apiName = "FetchPlanByCategories";
String apiName = BBPSConstant.API_FETCH_PLAN_BY_CATEGORIES;
String requestId = requestModel.getReqId();
String mid = requestModel.getMid();
@@ -737,14 +773,16 @@ 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(), "GET",
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 {
LOGGER.info("[{}] Calling Master API | URL={} | Method=GET", apiName, url);
Map<String, String> apiResponse = httpService.getRequest(url);
String responseData = apiResponse.get("data");
LOGGER.debug("[{}] API Response | reqId={} | data={}", apiName, requestId, responseData);
String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY);
LOGGER.info("Response Data: {}", responseData);
// Update outbound log with response
helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -753,12 +791,13 @@ public class MasterDataServiceImpl implements MasterDataService {
new TypeReference<Map<String, Object>>() {
});
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
@@ -777,7 +816,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");
}
}
@@ -785,7 +824,8 @@ public class MasterDataServiceImpl implements MasterDataService {
@Override
public ResponseModel getTicketDispositions(DispositionRequest dispositionDetailRequest) {
String apiName = "GetTicketDispositionDetails";
String apiName = BBPSConstant.API_GET_TICKET_DISPOSITIONS;
String requestId = dispositionDetailRequest.getReqId();
String mid = dispositionDetailRequest.getMid();
@@ -795,28 +835,27 @@ public class MasterDataServiceImpl implements MasterDataService {
String txnID = helper.generateTxnId(15);
String fullUrl = masterRegisterUrl + BBPSConstant.TICKET_DISPOSTION_URL;
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName,
dispositionDetailRequest.getMid(), "GET", "N/A");
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET",
dispositionDetailRequest.getMid());
dispositionDetailRequest.getMid(), BBPSConstant.HTTP_GET, "N/A");
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null);
try {
LOGGER.info("[{}] Calling External API | URL={} | Method=GET", apiName, fullUrl);
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl);
String responseData = responseMap.get("data");
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
LOGGER.debug("[{}] API Response | reqId={} | data={}", apiName, requestId, responseData);
helper.updateOutboundLogResponse(outboundLog, responseData);
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() {
});
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,
@@ -836,9 +875,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");
}
}
}
}