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
@@ -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));
}
}
}
}