merging code arham1

This commit is contained in:
himanshu
2025-11-03 10:49:04 +05:30
parent 3f27b5272a
commit 680d05b5bd
7 changed files with 150 additions and 174 deletions
@@ -61,7 +61,6 @@ public class AgentServiceImpl implements AgentService {
headers.set("agentId", headersData.getAgentId());
headers.set("tenantId", headersData.getTenantId());
headers.setContentType(MediaType.APPLICATION_JSON);
ResponseModel responseModel = new ResponseModel();
try {
@@ -44,6 +44,7 @@ import com.billpaymentservice.bbps.repository.DispositionRepository;
import com.billpaymentservice.bbps.repository.MerchantRepository;
import com.billpaymentservice.bbps.service.MasterDataService;
import com.billpaymentservice.bbps.util.BBPSConstant;
import com.billpaymentservice.bbps.util.EntityRelationshipUtil;
import com.billpaymentservice.bbps.util.Helper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -62,10 +63,8 @@ public class MasterDataServiceImpl implements MasterDataService {
private MerchantRepository merchantRegisterRepo;
private HttpClientApi httpClientApi;
private final DispositionRepository dispositionRepository;
private Helper helper;
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();
@@ -109,69 +108,19 @@ public class MasterDataServiceImpl implements MasterDataService {
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int)
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);
// Manually set parent reference
if (entity.getBillerPaymentModes() != null) {
entity.getBillerPaymentModes().forEach(m -> m.setBiller(entity));
}
if (entity.getBillerPaymentChannels() != null) {
entity.getBillerPaymentChannels().forEach(c -> c.setBiller(entity));
}
if (entity.getBillerCustomerParams() != null) {
entity.getBillerCustomerParams().forEach(p -> p.setBiller(entity));
}
if (entity.getBillerAdditionalInfos() != null) {
entity.getBillerAdditionalInfos().forEach(a -> a.setBiller(entity));
}
if (entity.getInterchangeFees() != null) {
for (InterchangeFee fee : entity.getInterchangeFees()) {
fee.setBiller(entity); // link InterchangeFee → BillerDetails
if (fee.getInterchangeFeeDetails() != null) {
for (InterchangeFeeDetail detail : fee.getInterchangeFeeDetails()) {
detail.setInterchangeFee(fee); // link InterchangeFeeDetail → InterchangeFee
}
}
}
}
if (entity.getInterchangeFeeConves() != null) {
entity.getInterchangeFeeConves().forEach(fc -> fc.setBiller(entity));
}
// For OneToOne relationships
if (entity.getCustomerParamGroups() != null)
entity.getCustomerParamGroups().setBiller(entity);
if (entity.getBillerPlanResponseParams() != null)
entity.getBillerPlanResponseParams().setBiller(entity);
// 🔥🔥🔥 YEH MISSING CODE ADD KARO 🔥🔥🔥
if (entity.getBillerResponseParams() != null) {
BillerResponseParams responseParams = entity.getBillerResponseParams();
responseParams.setBiller(entity); // Parent reference
// 🔥 AMOUNT OPTIONS KE RELATIONSHIPS SET KARO
if (responseParams.getAmountOptions() != null) {
for (AmountOption option : responseParams.getAmountOptions()) {
option.setBillerResponseParams(responseParams); // YEH MISSING THA
}
}
}
billerDataRespository.save(entity);
EntityRelationshipUtil.linkBillerRelationships(entity);
// billerDataRespository.save(entity);
ResponseModel responseModel = new ResponseModel(
generalResp.getMessage(),
generalResp.getStatus(),
Integer.parseInt(generalResp.getStatusCode()),
responseWrapper
);
return responseModel;
} catch (JsonProcessingException e) {
@@ -216,7 +165,6 @@ public class MasterDataServiceImpl implements MasterDataService {
Integer.parseInt(generalResp.getStatusCode()),
responseWrapper
);
return responseModel;
} catch (JsonProcessingException e) {
@@ -59,7 +59,7 @@ public class PaymentServiceImpl implements PaymentService {
public ResponseModel initiatePayment(BillPaymentRequest billPaymentRequest) {
String url = paymentUrl + BBPSConstant.PAYMENT_URL;
System.out.println(url);
System.out.println(url);
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
@@ -102,6 +102,7 @@ public class PaymentServiceImpl implements PaymentService {
BillPaymentResponse billPaymentResponse = objectMapper.convertValue(dataMap, BillPaymentResponse.class);
System.out.print(billPaymentResponse);
GeneralResp generalResponse = billPaymentResponse.getGenericResponse();
//
// start a new thread here
/*
@@ -0,0 +1,66 @@
package com.billpaymentservice.bbps.util;
import com.billpaymentservice.bbps.entites.*;
public class EntityRelationshipUtil {
private EntityRelationshipUtil() {
// prevent instantiation
}
/**
* Links all parent-child relationships for BillerDetails and nested entities.
* Ensures bidirectional JPA relationships are correctly set before saving.
*/
public static void linkBillerRelationships(BillerDetails entity) {
if (entity == null) return;
if (entity.getBillerPaymentModes() != null) {
entity.getBillerPaymentModes().forEach(m -> m.setBiller(entity));
}
if (entity.getBillerPaymentChannels() != null) {
entity.getBillerPaymentChannels().forEach(c -> c.setBiller(entity));
}
if (entity.getBillerCustomerParams() != null) {
entity.getBillerCustomerParams().forEach(p -> p.setBiller(entity));
}
if (entity.getBillerAdditionalInfos() != null) {
entity.getBillerAdditionalInfos().forEach(a -> a.setBiller(entity));
}
if (entity.getInterchangeFees() != null) {
for (InterchangeFee fee : entity.getInterchangeFees()) {
fee.setBiller(entity);
if (fee.getInterchangeFeeDetails() != null) {
fee.getInterchangeFeeDetails().forEach(detail -> detail.setInterchangeFee(fee));
}
}
}
if (entity.getInterchangeFeeConves() != null) {
entity.getInterchangeFeeConves().forEach(fc -> fc.setBiller(entity));
}
if (entity.getCustomerParamGroups() != null)
entity.getCustomerParamGroups().setBiller(entity);
if (entity.getBillerPlanResponseParams() != null)
entity.getBillerPlanResponseParams().setBiller(entity);
if (entity.getBillerResponseParams() != null) {
BillerResponseParams responseParams = entity.getBillerResponseParams();
responseParams.setBiller(entity);
if (responseParams.getAmountOptions() != null) {
responseParams.getAmountOptions()
.forEach(option -> option.setBillerResponseParams(responseParams));
}
}
}
}