10-11-25 after conflict

This commit is contained in:
Mohd-Arham
2025-11-10 11:56:29 +05:30
77 changed files with 1600 additions and 572 deletions
@@ -13,6 +13,9 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.billpaymentservice.bbps.dto.CustomerParamGroupsDTO;
import com.billpaymentservice.bbps.dto.CustomParamDTO;
import com.billpaymentservice.bbps.dto.GeneralResp;
import com.billpaymentservice.bbps.dto.MasterApiResponse;
import com.billpaymentservice.bbps.dto.ResponseModel;
@@ -35,12 +38,14 @@ import com.billpaymentservice.bbps.dto.response.PlaneCategoriesResponse;
import com.billpaymentservice.bbps.entites.BharatConnectMaster;
import com.billpaymentservice.bbps.entites.BillerCategoryWise;
import com.billpaymentservice.bbps.entites.BillerDetails;
import com.billpaymentservice.bbps.entites.CustomParam;
import com.billpaymentservice.bbps.entites.DispositionDetails;
import com.billpaymentservice.bbps.entites.InboundTraceLog;
import com.billpaymentservice.bbps.entites.OutboundTraceLog;
import com.billpaymentservice.bbps.exception.CustomException;
import com.billpaymentservice.bbps.repository.BharatConnectMasterRepository;
import com.billpaymentservice.bbps.repository.BillerDataRepository;
import com.billpaymentservice.bbps.repository.CustomParamRepository;
import com.billpaymentservice.bbps.repository.DispositionRepository;
import com.billpaymentservice.bbps.repository.InboundTraceLogRepository;
import com.billpaymentservice.bbps.repository.MerchantRepository;
@@ -68,17 +73,17 @@ public class MasterDataServiceImpl implements MasterDataService {
private final DispositionRepository dispositionRepository;
private final Helper helper;
private final BillerDataRepository billerDataRespository;
private static final Logger log = LoggerFactory.getLogger(MasterDataServiceImpl.class);
private final HttpService httpService;
private final ObjectMapper objectMapper = new ObjectMapper();
private final InboundTraceLogRepository inboundTraceLogRepository;
private final OutboundTraceLogRepository outboundTraceLogRepository;
private final CustomParamRepository customParamReposiotory;
public MasterDataServiceImpl(MerchantRepository merchantRegisterRepo, HttpService httpService,
HttpClientApi httpClientApi, Helper helper, BillerDataRepository billerDataRespository,
DispositionRepository dispositionRepository, BharatConnectMasterRepository beneficiaryDetailsRepository,
InboundTraceLogRepository inboundTraceLogRepository, OutboundTraceLogRepository outboundTraceLogRepository,
BillerMapperHelper mapperHelper) {
BillerMapperHelper mapperHelper, CustomParamRepository customParamReposiotory) {
this.merchantRegisterRepo = merchantRegisterRepo;
this.httpService = httpService;
this.httpClientApi = httpClientApi;
@@ -89,54 +94,39 @@ public class MasterDataServiceImpl implements MasterDataService {
this.inboundTraceLogRepository = inboundTraceLogRepository;
this.outboundTraceLogRepository = outboundTraceLogRepository;
this.mapperHelper = mapperHelper;
this.customParamReposiotory = customParamReposiotory;
}
@Override
public ResponseModel getMasterData(MasterRequest masterRequest) {
LOGGER.info("Request DTO: {}", masterRequest);
LOGGER.info("Fetching Master Data for ReqId={} and MID={}", masterRequest.getReqId(), masterRequest.getMid());
String txnID = helper.generateTxnId(15);
String apiName = "GetMasterData";
String requestId = masterRequest.getReqId();
String requestJson = helper.convertObjectToJson(masterRequest);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), "POST",
requestJson);
try {
// Merchant Validation
helper.validateMerchant(masterRequest.getMid());
// if (!"Valid".equalsIgnoreCase(validateMerchant)) {
// LOGGER.warn("Merchant validation failed: {}", validateMerchant);
// return new ResponseModel("Merchant validation failed", validateMerchant, BBPSConstant.BADREQUEST, null);
// }
// check Tender Id is present DB
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
log.info("Response -: " + headersData);
if (headersData == null) {
helper.updateInboundLogFailure(inboundLog, "Tenant Id Is Null", "NOT_FOUND");
return new ResponseModel("Tenant Id Is Null", "Not Found", BBPSConstant.BADREQUEST, headersData);
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, "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,
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
@@ -157,14 +147,17 @@ public class MasterDataServiceImpl implements MasterDataService {
return responseModel;
} catch (JsonProcessingException e) {
log.error("Error parsing responseData JSON: {}", e.getMessage());
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
}
@Override
public ResponseModel getBillerByBillerId(BillerDetailRequest billerDetailRequest) {
LOGGER.info("Fetching Biller Detail By Biller Id for ReqId={} and MID={}", billerDetailRequest.getReqId(),
billerDetailRequest.getMid());
helper.validateMerchant(billerDetailRequest.getMid());
String txnID = helper.generateTxnId(15);
@@ -172,56 +165,50 @@ public class MasterDataServiceImpl implements MasterDataService {
String requestId = billerDetailRequest.getReqId();
String billerId = billerDetailRequest.getBillerId();
String fullUrl = masterRegisterUrl + BBPSConstant.BILLER_DATA_FETCH_URL + billerId;
String requestJson = helper.convertObjectToJson(billerDetailRequest);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, billerDetailRequest.getMid(),
"POST", requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl);
String responseData = responseMap.get("data");
log.info("data is :{}", responseData);
LOGGER.info("fetched data from api is :{}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData);
try {
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")));
}
BillerDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillerDataResponse.class);
GeneralResp generalResp = responseWrapper.getGeneralResp();
ModelMapper mapper = new ModelMapper();
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
BillerDetails entity = mapper.map(responseWrapper.getBillerDAO(), BillerDetails.class);
EntityRelationshipUtil.linkBillerRelationships(entity);
EntityRelationshipUtil.linkBillerRelationships(entity);// linking nesting entity foreign key
helper.saveOrUpdateBillerData(entity);
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());
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
}
@Override
public ResponseModel getCustomerParamByBillerId(CustomParamRequest customerParamRequest) {
LOGGER.info("Fetching Customer Param By Biller Id for ReqId={} and MID={}", customerParamRequest.getReqId(),
customerParamRequest.getMid());
String txnID = helper.generateTxnId(15);
String apiName = "GetCustomerParamByBillerId";
String requestId = customerParamRequest.getReqId();
@@ -231,20 +218,14 @@ public class MasterDataServiceImpl implements MasterDataService {
try {
helper.validateMerchant(customerParamRequest.getMid());
// if (!"Valid".equalsIgnoreCase(validateMerchant)) {
// LOGGER.warn("Merchant validation failed: {}", validateMerchant);
// return new ResponseModel("Merchant validation failed", validateMerchant, BBPSConstant.BADREQUEST, null);
// }
String billerId = customerParamRequest.getBillerId();
String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMPARAM_URL + billerId;
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl);
String responseData = responseMap.get("data");
log.info("data is :{}", responseData);
LOGGER.info("data is :{}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -260,26 +241,34 @@ public class MasterDataServiceImpl implements MasterDataService {
}
CustomParamResp responseWrapper = objectMapper.convertValue(dataMap, CustomParamResp.class);
List<CustomParamDTO> customParams = responseWrapper.getCustomParamResp();
GeneralResp generalResp = responseWrapper.getGeneralResp();
List<CustomParamDTO> customParam = responseWrapper.getCustomParamResp();
ModelMapper mapper = new ModelMapper();
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
// Map DTOs to entities
List<CustomParam> entities = customParams.stream().map(dto -> mapper.map(dto, CustomParam.class))
.collect(Collectors.toList());
// Save all to DB
customParamReposiotory.saveAll(entities);
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());
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
}
@Override
public ResponseModel getContactMaster(ContactMasterRequest contactMasterRequest) {
return new ResponseModel();
return new ResponseModel(); // things not comming from api
}
@Override
@@ -292,10 +281,8 @@ public class MasterDataServiceImpl implements MasterDataService {
String requestJson = helper.convertObjectToJson(masterRequest);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), "POST",
requestJson);
try {
helper.validateMerchant(masterRequest.getMid());
String fullUrl = String.format("%s%s?billerName=%s&category=%s&page=%d&pagesize=%d", masterRegisterUrl,
BBPSConstant.BILLER_URL, masterRequest.getBillerName(), masterRequest.getCategory(),
masterRequest.getPageStart(), masterRequest.getPageEnd());
@@ -334,7 +321,7 @@ public class MasterDataServiceImpl implements MasterDataService {
return responseModel;
} catch (JsonProcessingException e) {
log.error("Error parsing responseData JSON: {}", e.getMessage());
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
@@ -342,15 +329,19 @@ public class MasterDataServiceImpl implements MasterDataService {
@Override
public ResponseModel getDispositionDetails(DispositionRequest dispositionDetailRequest) {
LOGGER.info("Fetching Disposition Details for ReqId={} and MID={}", dispositionDetailRequest.getReqId(),
dispositionDetailRequest.getMid());
String txnID = helper.generateTxnId(15);
String apiName = "GetDispositionDetails";
String requestId = dispositionDetailRequest.getReqId();
;
helper.validateMerchant(dispositionDetailRequest.getMid());
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName,
dispositionDetailRequest.getMid(), "GET", "N/A");
String fullUrl = masterRegisterUrl + BBPSConstant.DISPOSTION_URL;
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl);
String responseData = responseMap.get("data");
@@ -393,16 +384,17 @@ public class MasterDataServiceImpl implements MasterDataService {
return responseModel;
} catch (JsonProcessingException e) {
log.error("Error parsing responseData JSON: {}", e.getMessage());
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
}
@Override
public ResponseModel fetchCustomerParamGroup(BillerDetailRequest requestModel) {
LOGGER.info("Fetching Master Data CategoryResponseList-wise for MID={}", requestModel.getMid());
LOGGER.info("Fetching Customer Param Group for ReqId={} and MID={}", requestModel.getReqId(),
requestModel.getMid());
String txnID = helper.generateTxnId(15);
String apiName = "FetchCustomerParamGroup";
String requestId = requestModel.getReqId();
@@ -414,7 +406,7 @@ public class MasterDataServiceImpl implements MasterDataService {
String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMER_PARAM_GROUP + requestModel.getBillerId();
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
String responseData = apiResponse.get("data").toString();
helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -446,7 +438,7 @@ public class MasterDataServiceImpl implements MasterDataService {
return responseModel;
} catch (JsonProcessingException e) {
log.error("Error parsing responseData JSON: {}", e.getMessage());
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
@@ -455,8 +447,9 @@ public class MasterDataServiceImpl implements MasterDataService {
@Override
public ResponseModel fetchAllMasterAmountOption(BillerDetailRequest requestModel) {
LOGGER.info("Fetching Master Data Amount List for MID={}", requestModel.getMid());
LOGGER.info("Fetching Master Data Amount List for ReqId={} and MID={}", requestModel.getReqId(),
requestModel.getMid());
String txnID = helper.generateTxnId(15);
String apiName = "FetchAllMasterAmountOption";
String requestId = requestModel.getReqId();
@@ -468,9 +461,9 @@ public class MasterDataServiceImpl implements MasterDataService {
String fullUrl = masterRegisterUrl + BBPSConstant.AMOUNT_OPTIONS + requestModel.getBillerId();
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
log.info("Response" + apiResponse);
LOGGER.info("Response" + apiResponse);
String responseData = apiResponse.get("data").toString();
helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -502,7 +495,7 @@ public class MasterDataServiceImpl implements MasterDataService {
return responseModel;
} catch (JsonProcessingException e) {
log.error("Error parsing responseData JSON: {}", e.getMessage());
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
@@ -511,8 +504,7 @@ public class MasterDataServiceImpl implements MasterDataService {
@Override
public ResponseModel fetchPlanCategorie(BillerDetailRequest requestModel) {
LOGGER.info("Fetching Master Data Amount List for MID={}", requestModel.getMid());
LOGGER.info("Fetching Plan Categories for ReqId={} and MID={}", requestModel.getReqId(), requestModel.getMid());
String txnID = helper.generateTxnId(15);
String apiName = "FetchPlanCategorie";
String requestId = requestModel.getReqId();
@@ -524,9 +516,9 @@ public class MasterDataServiceImpl implements MasterDataService {
String fullUrl = masterRegisterUrl + BBPSConstant.PLAN_CATEGORIES + requestModel.getBillerId();
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
log.info("Response" + apiResponse);
LOGGER.info("Response" + apiResponse);
String responseData = apiResponse.get("data").toString();
helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -556,16 +548,17 @@ public class MasterDataServiceImpl implements MasterDataService {
return responseModel;
} catch (JsonProcessingException e) {
log.error("Error parsing responseData JSON: {}", e.getMessage());
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
}
@Override
public ResponseModel fetchInitiatingChannel(BillerDetailRequest requestModel) {
LOGGER.info("Fetching Initiating Channel List for MID={}", requestModel.getMid());
LOGGER.info("Fetching Initiating Channel for ReqId={} and MID={}", requestModel.getReqId(),
requestModel.getMid());
String txnID = helper.generateTxnId(15);
String apiName = "FetchInitiatingChannel";
String requestId = requestModel.getReqId();
@@ -576,12 +569,11 @@ public class MasterDataServiceImpl implements MasterDataService {
helper.validateMerchant(requestModel.getMid());
String fullUrl = masterRegisterUrl + BBPSConstant.INITIATING_CHANNEL;
LOGGER.info("Calling Master API: {}", fullUrl);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
LOGGER.info("Calling Master API: {}", fullUrl);
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
log.info("Response" + apiResponse);
LOGGER.info("Response" + apiResponse);
String responseData = apiResponse.get("data").toString();
helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -609,16 +601,17 @@ public class MasterDataServiceImpl implements MasterDataService {
return responseModel;
} catch (JsonProcessingException e) {
log.error("Error parsing responseData JSON: {}", e.getMessage());
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
}
public ResponseModel fetchPlanByCategories(PlanRequest requestModel) {
LOGGER.info("Fetching Initiating Fetch Plan CategoryResponseList By Biller Id for MID={}",
requestModel.getMid());
LOGGER.info("Fetching Plan By Categories for ReqId={} and MID={}", requestModel.getReqId(),
requestModel.getMid());
String txnID = helper.generateTxnId(15);
String apiName = "FetchPlanByCategories";
String requestId = requestModel.getReqId();
@@ -639,11 +632,10 @@ public class MasterDataServiceImpl implements MasterDataService {
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST",
requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, "GET", null);
try {
Map<String, String> apiResponse = httpService.getRequest(url);
String responseData = apiResponse.get("data");
log.info("Response Data: {}", responseData);
LOGGER.info("Response Data: {}", responseData);
// Update outbound log with response
helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -672,7 +664,7 @@ public class MasterDataServiceImpl implements MasterDataService {
return responseModel;
} catch (JsonProcessingException e) {
log.error("Error parsing responseData JSON: {}", e.getMessage());
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}