added logging methods in helper
This commit is contained in:
+119
-146
@@ -87,53 +87,6 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
|
||||
}
|
||||
|
||||
/* ---------- Trace helper methods ---------- */
|
||||
private InboundTraceLog createInboundLog(String requestId, String txnId, String apiName, String mid,
|
||||
String httpMethod, String requestPayload) {
|
||||
InboundTraceLog inboundLog = new InboundTraceLog(requestId, txnId, apiName, mid == null ? "N/A" : mid,
|
||||
"BBPS_ORG", httpMethod, requestPayload == null ? "N/A" : requestPayload);
|
||||
inboundTraceLogRepository.save(inboundLog);
|
||||
return inboundLog;
|
||||
}
|
||||
|
||||
private void updateInboundLogSuccess(InboundTraceLog inboundLog, String responsePayload, String responseCode) {
|
||||
if (inboundLog == null)
|
||||
return;
|
||||
inboundLog.setResponsePayload(responsePayload);
|
||||
inboundLog.setResponseCode(responseCode);
|
||||
inboundLog.setStatus("SUCCESS");
|
||||
inboundLog.setResponseTime(LocalDateTime.now());
|
||||
inboundTraceLogRepository.save(inboundLog);
|
||||
}
|
||||
|
||||
private void updateInboundLogFailure(InboundTraceLog inboundLog, String responsePayload, String responseCode) {
|
||||
if (inboundLog == null)
|
||||
return;
|
||||
inboundLog.setResponsePayload(responsePayload);
|
||||
inboundLog.setResponseCode(responseCode);
|
||||
inboundLog.setStatus("FAILED");
|
||||
inboundLog.setResponseTime(LocalDateTime.now());
|
||||
inboundTraceLogRepository.save(inboundLog);
|
||||
}
|
||||
|
||||
private OutboundTraceLog createOutboundLog(String txnId, String requestId, String apiName, String url,
|
||||
String httpMethod, String requestPayload) {
|
||||
OutboundTraceLog outboundLog = new OutboundTraceLog(txnId, requestId, apiName, url, httpMethod,
|
||||
requestPayload == null ? "N/A" : requestPayload);
|
||||
outboundTraceLogRepository.save(outboundLog);
|
||||
return outboundLog;
|
||||
}
|
||||
|
||||
private void updateOutboundLogResponse(OutboundTraceLog outboundLog, String responsePayload) {
|
||||
if (outboundLog == null)
|
||||
return;
|
||||
outboundLog.setResponsePayload(responsePayload);
|
||||
outboundLog.setResponseReceiveTime(LocalDateTime.now());
|
||||
outboundTraceLogRepository.save(outboundLog);
|
||||
}
|
||||
|
||||
/* ---------- End helpers ---------- */
|
||||
|
||||
@Override
|
||||
public ResponseModel getMasterData(MasterRequest masterRequest) {
|
||||
LOGGER.info("Request DTO: {}", masterRequest);
|
||||
@@ -142,10 +95,10 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
String apiName = "GetMasterData";
|
||||
String requestId = masterRequest.getReqId();
|
||||
String requestJson = helper.convertObjectToJson(masterRequest);
|
||||
|
||||
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), "POST",
|
||||
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), "POST",
|
||||
requestJson);
|
||||
|
||||
|
||||
try {
|
||||
// Merchant Validation
|
||||
helper.validateMerchant(masterRequest.getMid());
|
||||
@@ -159,7 +112,7 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
log.info("Response -: " + headersData);
|
||||
if (headersData == null) {
|
||||
updateInboundLogFailure(inboundLog, "Tenant Id Is Null", "NOT_FOUND");
|
||||
helper.updateInboundLogFailure(inboundLog, "Tenant Id Is Null", "NOT_FOUND");
|
||||
return new ResponseModel("Tenant Id Is Null", "Not Found", BBPSConstant.BADREQUEST, headersData);
|
||||
}
|
||||
|
||||
@@ -167,20 +120,20 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
String fullUrl = masterRegisterUrl + BBPSConstant.MASTER_CATEGORY_URL + headersData.getTenantId();
|
||||
LOGGER.info("Calling external API: {}", fullUrl);
|
||||
|
||||
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
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);
|
||||
|
||||
updateOutboundLogResponse(outboundLog, responseData);
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
||||
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
|
||||
@@ -194,13 +147,13 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
|
||||
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
|
||||
return responseModel;
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
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());
|
||||
@@ -210,7 +163,7 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
|
||||
@Override
|
||||
public ResponseModel getBillerByBillerId(BillerDetailRequest billerDetailRequest) {
|
||||
|
||||
|
||||
helper.validateMerchant(billerDetailRequest.getMid());
|
||||
String txnID = helper.generateTxnId(15);
|
||||
String apiName = "GetBillerByBillerId";
|
||||
@@ -219,16 +172,16 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
String fullUrl = masterRegisterUrl + BBPSConstant.BILLER_DATA_FETCH_URL + billerId;
|
||||
|
||||
String requestJson = helper.convertObjectToJson(billerDetailRequest);
|
||||
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName, billerDetailRequest.getMid(), "POST",
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, billerDetailRequest.getMid(), "POST",
|
||||
requestJson);
|
||||
|
||||
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
||||
String responseData = responseMap.get("data");
|
||||
log.info("data is :{}", responseData);
|
||||
|
||||
updateOutboundLogResponse(outboundLog, responseData);
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
try {
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
@@ -236,7 +189,7 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
});
|
||||
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
||||
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")));
|
||||
@@ -253,12 +206,12 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
|
||||
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
|
||||
return responseModel;
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
|
||||
@@ -271,7 +224,7 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
String apiName = "GetCustomerParamByBillerId";
|
||||
String requestId = customerParamRequest.getReqId();
|
||||
String requestJson = helper.convertObjectToJson(customerParamRequest);
|
||||
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName, customerParamRequest.getMid(), "POST",
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, customerParamRequest.getMid(), "POST",
|
||||
requestJson);
|
||||
|
||||
try {
|
||||
@@ -285,19 +238,19 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
String billerId = customerParamRequest.getBillerId();
|
||||
String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMPARAM_URL + billerId;
|
||||
|
||||
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
||||
String responseData = responseMap.get("data");
|
||||
log.info("data is :{}", responseData);
|
||||
|
||||
updateOutboundLogResponse(outboundLog, responseData);
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
||||
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)
|
||||
@@ -310,12 +263,12 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
|
||||
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
|
||||
return responseModel;
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
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());
|
||||
@@ -338,7 +291,7 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
String apiName = "FetchMasterDataCategoryWise";
|
||||
String requestId = masterRequest.getReqId();
|
||||
String requestJson = helper.convertObjectToJson(masterRequest);
|
||||
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), "POST",
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), "POST",
|
||||
requestJson);
|
||||
|
||||
try {
|
||||
@@ -348,20 +301,20 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
BBPSConstant.BILLER_URL, masterRequest.getBillerName(), masterRequest.getCategory(),
|
||||
masterRequest.getPageStart(), masterRequest.getPageEnd());
|
||||
|
||||
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
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);
|
||||
|
||||
updateOutboundLogResponse(outboundLog, responseData);
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
||||
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
|
||||
@@ -375,12 +328,12 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
|
||||
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
|
||||
return responseModel;
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
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());
|
||||
@@ -394,15 +347,15 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
String apiName = "GetDispositionDetails";
|
||||
String requestId = dispositionDetailRequest.getReqId();
|
||||
;
|
||||
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName, dispositionDetailRequest.getMid(),
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, dispositionDetailRequest.getMid(),
|
||||
"GET", "N/A");
|
||||
|
||||
String fullUrl = masterRegisterUrl + BBPSConstant.DISPOSTION_URL;
|
||||
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
||||
String responseData = responseMap.get("data");
|
||||
|
||||
updateOutboundLogResponse(outboundLog, responseData);
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
try {
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
@@ -411,7 +364,7 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
||||
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)
|
||||
@@ -437,12 +390,12 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
|
||||
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
|
||||
return responseModel;
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
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());
|
||||
@@ -457,25 +410,25 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
String txnID = helper.generateTxnId(15);
|
||||
String apiName = "FetchCustomerParamGroup";
|
||||
String requestId = requestModel.getReqId();
|
||||
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST",
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST",
|
||||
helper.convertObjectToJson(requestModel));
|
||||
|
||||
try {
|
||||
helper.validateMerchant(requestModel.getMid());
|
||||
|
||||
String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMER_PARAM_GROUP + requestModel.getBillerId();
|
||||
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
|
||||
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
|
||||
String responseData = apiResponse.get("data").toString();
|
||||
updateOutboundLogResponse(outboundLog, responseData);
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
||||
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)
|
||||
@@ -489,13 +442,13 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
|
||||
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
|
||||
return responseModel;
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
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());
|
||||
@@ -511,27 +464,27 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
String txnID = helper.generateTxnId(15);
|
||||
String apiName = "FetchAllMasterAmountOption";
|
||||
String requestId = requestModel.getReqId();
|
||||
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST",
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST",
|
||||
helper.convertObjectToJson(requestModel));
|
||||
|
||||
try {
|
||||
helper.validateMerchant(requestModel.getMid());
|
||||
|
||||
String fullUrl = masterRegisterUrl + BBPSConstant.AMOUNT_OPTIONS + requestModel.getBillerId();
|
||||
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
|
||||
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
|
||||
log.info("Response" + apiResponse);
|
||||
String responseData = apiResponse.get("data").toString();
|
||||
|
||||
updateOutboundLogResponse(outboundLog, responseData);
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
||||
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)
|
||||
@@ -544,13 +497,13 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
|
||||
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
|
||||
return responseModel;
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
} catch (CustomException e) {
|
||||
LOGGER.error("Custom Exception: {}", e.getMessage());
|
||||
@@ -566,27 +519,27 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
String txnID = helper.generateTxnId(15);
|
||||
String apiName = "FetchPlanCategorie";
|
||||
String requestId = requestModel.getReqId();
|
||||
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST",
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST",
|
||||
helper.convertObjectToJson(requestModel));
|
||||
|
||||
try {
|
||||
helper.validateMerchant(requestModel.getMid());
|
||||
|
||||
String fullUrl = masterRegisterUrl + BBPSConstant.PLAN_CATEGORIES + requestModel.getBillerId();
|
||||
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
|
||||
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
|
||||
log.info("Response" + apiResponse);
|
||||
String responseData = apiResponse.get("data").toString();
|
||||
|
||||
updateOutboundLogResponse(outboundLog, responseData);
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
||||
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)
|
||||
@@ -599,13 +552,13 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
|
||||
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
|
||||
return responseModel;
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
} catch (CustomException e) {
|
||||
LOGGER.error("Custom Exception: {}", e.getMessage());
|
||||
@@ -620,7 +573,7 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
String txnID = helper.generateTxnId(15);
|
||||
String apiName = "FetchInitiatingChannel";
|
||||
String requestId = requestModel.getReqId();
|
||||
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST",
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST",
|
||||
helper.convertObjectToJson(requestModel));
|
||||
|
||||
try {
|
||||
@@ -629,20 +582,20 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
String fullUrl = masterRegisterUrl + BBPSConstant.INITIATING_CHANNEL;
|
||||
LOGGER.info("Calling Master API: {}", fullUrl);
|
||||
|
||||
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
||||
|
||||
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
|
||||
log.info("Response" + apiResponse);
|
||||
String responseData = apiResponse.get("data").toString();
|
||||
|
||||
updateOutboundLogResponse(outboundLog, responseData);
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
||||
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)
|
||||
@@ -655,13 +608,13 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
|
||||
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
|
||||
return responseModel;
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
} catch (CustomException e) {
|
||||
LOGGER.error("Custom Exception: {}", e.getMessage());
|
||||
@@ -669,58 +622,78 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseModel fetchPlanByCategories(PlanRequest requestModel) {
|
||||
LOGGER.info("Fetching Initiating Fetch Plan Category By Bidder Id for MID={}", requestModel.getMid());
|
||||
try {
|
||||
helper.validateMerchant(requestModel.getMid());
|
||||
LOGGER.info("Fetching Initiating Fetch Plan Category By Biller Id for MID={}", requestModel.getMid());
|
||||
|
||||
// if (!"Valid".equalsIgnoreCase(validateMerchant)) {
|
||||
// LOGGER.warn("Merchant validation failed: {}", validateMerchant);
|
||||
// return new ResponseModel("Merchant validation failed", validateMerchant, BBPSConstant.BADREQUEST, null);
|
||||
// }
|
||||
String txnID = helper.generateTxnId(15);
|
||||
String apiName = "FetchPlanByCategories";
|
||||
String requestId = requestModel.getReqId();
|
||||
|
||||
String url = String.format("%s%s?billerId=%s%s%s%s&page=%d&pagesize=%d", masterRegisterUrl,
|
||||
BBPSConstant.PLANS_URL, requestModel.getBillerId(),
|
||||
requestModel.getCategory() != null ? "&category=" + requestModel.getCategory() : "",
|
||||
requestModel.getAmountInRupees() != null ? "&amountInRupees=" + requestModel.getAmountInRupees()
|
||||
: "",
|
||||
requestModel.getCircle() != null ? "&circle=" + requestModel.getCircle() : "",
|
||||
requestModel.getPage(), requestModel.getPagesize());
|
||||
helper.validateMerchant(requestModel.getMid());
|
||||
|
||||
// String fullUrl = masterRegisterUrl + BBPSConstant.PLANS_URL + url;
|
||||
LOGGER.info("Calling Master API: {}", url);
|
||||
String url = String.format("%s%s?billerId=%s%s%s%s&page=%d&pagesize=%d",
|
||||
masterRegisterUrl,
|
||||
BBPSConstant.PLANS_URL,
|
||||
requestModel.getBillerId(),
|
||||
requestModel.getCategory() != null ? "&category=" + requestModel.getCategory() : "",
|
||||
requestModel.getAmountInRupees() != null ? "&amountInRupees=" + requestModel.getAmountInRupees() : "",
|
||||
requestModel.getCircle() != null ? "&circle=" + requestModel.getCircle() : "",
|
||||
requestModel.getPage(),
|
||||
requestModel.getPagesize()
|
||||
);
|
||||
|
||||
Map<String, String> apiResponse = httpService.getRequest(url);
|
||||
log.info("Response" + apiResponse);
|
||||
String responseData = apiResponse.get("data").toString();
|
||||
LOGGER.info("Calling Master API: {}", url);
|
||||
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
// Convert request to JSON and create inbound & outbound logs
|
||||
String requestJson = helper.convertObjectToJson(requestModel);
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST", requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, "GET", null);
|
||||
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
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")));
|
||||
}
|
||||
try {
|
||||
Map<String, String> apiResponse = httpService.getRequest(url);
|
||||
String responseData = apiResponse.get("data");
|
||||
log.info("Response Data: {}", responseData);
|
||||
|
||||
PlanResponse responseWrapper = objectMapper.convertValue(dataMap, PlanResponse.class);
|
||||
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
||||
// Update outbound log with response
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
|
||||
|
||||
return responseModel;
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
// 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"))
|
||||
);
|
||||
}
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
} catch (CustomException e) {
|
||||
LOGGER.error("Custom Exception: {}", e.getMessage());
|
||||
throw e; // Rethrow custom exceptions to be handled by the controller
|
||||
}
|
||||
// Success response
|
||||
PlanResponse responseWrapper = objectMapper.convertValue(dataMap, PlanResponse.class);
|
||||
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
||||
|
||||
ResponseModel responseModel = new ResponseModel(
|
||||
generalResp.getMessage(),
|
||||
generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()),
|
||||
responseWrapper
|
||||
);
|
||||
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
return responseModel;
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
} catch (CustomException e) {
|
||||
|
||||
LOGGER.error("Custom Exception: {}", e.getMessage());
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "Custom_exception");
|
||||
throw e; // Rethrow for controller-level handling
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user