Untitled

mail@pastecode.io avatar
unknown
plain_text
10 days ago
27 kB
1
Indexable
Never
package es.isban.api.loaniq.service.kodokan;

import es.isban.api.loaniq.constants.Constants;
import es.isban.api.loaniq.model.loandb.VlsCustLocationCustom;
import es.isban.api.loaniq.model.web.*;
import es.isban.api.loaniq.model.web.functional.*;
import es.isban.api.loaniq.repository.loandb.VlsCustLocationCustomRepository;
import es.isban.api.loaniq.repository.loandb.VlsHostBankCustomRepository;
import es.isban.api.loaniq.service.GlsOrJToExternalIdService;
import es.isban.api.loaniq.service.TrimService;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;


public class Facility extends Translator {

    private final TrimService trimService;
    private final VlsHostBankCustomRepository vlsHostBankCustomRepository;
    private final VlsCustLocationCustomRepository vlsCustLocationCustomRepository;

    public Facility(GlsOrJToExternalIdService glsOrJToExternalIdService, TrimService trimService, VlsHostBankCustomRepository vlsHostBankCustomRepository, VlsCustLocationCustomRepository vlsCustLocationCustomRepository) {
        super(glsOrJToExternalIdService);
        this.trimService = trimService;
        this.vlsHostBankCustomRepository = vlsHostBankCustomRepository;
        this.vlsCustLocationCustomRepository = vlsCustLocationCustomRepository;
    }

    public void translate(CreateOperationRequest operationPublisher, CustomCreateOperationRequest operationRequest){
        if (null != operationRequest.getTramos() && !operationRequest.getTramos().isEmpty()) {
            operationPublisher.setFacilities(new ArrayList<>());
            for (CustomCreateFacilityRequest ccfr : operationRequest.getTramos()){
                CreateFacilityRequest cfr = new CreateFacilityRequest();

                translateFacilityGeneralData(cfr, ccfr, operationPublisher);
                translateFacilityServicingGroup(cfr, ccfr, operationPublisher);
                translateFacilityRisks(cfr, ccfr);
                translateFacilityProductCurrencies(cfr, ccfr);
                translateFacilityLoanPurposes(cfr, ccfr);
                translateFacilityMisCodes(cfr, ccfr);
                translateFacilityFeePricings(cfr, ccfr);
                translateFacilityInterestPricings(cfr, ccfr);
                translateFacilityOngoingFeeDates(cfr, ccfr);
                translateFacilityAmortizationSchedules(cfr, ccfr, operationPublisher);

                translateFacilityInterestPricingOption(cfr, ccfr);
                translateInterestPricingOptionFacility(cfr, ccfr);

                translateFacilitySublimits(cfr, ccfr);
                translateFacilityAddBorrowers(cfr, ccfr, operationPublisher);

                translateFacilityAdditionalFields(cfr, ccfr);

                operationPublisher.getFacilities().add(cfr);
            }
        }
    }
    private void translateFacilityGeneralData(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr, CreateOperationRequest cor){
        if(null != ccfr.getGeneralData()){
            String externalId = glsOrJToExternalIdService.getXidFromGlsOrJ(
                    ccfr.getGeneralData().getPrimaryBorrower(),
                    cor.getDeal().getGeneralDealInformation().getBranch());
            FacilityGeneralDataRequest facilityGeneralDataRequest = new FacilityGeneralDataRequest();

            facilityGeneralDataRequest.setAddWellKnownCurrenciesIndicator(ccfr.getGeneralData().getAddWellKnownCurrenciesIndicator());
            facilityGeneralDataRequest.setAgreementDate(ccfr.getGeneralData().getAgreementDate());
            facilityGeneralDataRequest.setAliasDealName(cor.getDeal().getGeneralDealInformation().getDealAlias());
            facilityGeneralDataRequest.setBranch(cor.getDeal().getGeneralDealInformation().getBranch());
            facilityGeneralDataRequest.setClosingCommitment(ccfr.getGeneralData().getClosingCommitment());
            facilityGeneralDataRequest.setCurrency(ccfr.getGeneralData().getCurrency());
            facilityGeneralDataRequest.setDealFXRate(ccfr.getGeneralData().getDealFXRate());
            facilityGeneralDataRequest.setEffectiveDate(ccfr.getGeneralData().getEffectiveDate());
            facilityGeneralDataRequest.setExpiryDate(ccfr.getGeneralData().getExpiryDate());
            facilityGeneralDataRequest.setFacilityName(ccfr.getGeneralData().getName());
            facilityGeneralDataRequest.setFacilityType(ccfr.getGeneralData().getType());
            facilityGeneralDataRequest.setFacilityControlNumber(null == ccfr.getGeneralData().getFacilityControlNumber() || ccfr.getGeneralData().getFacilityControlNumber().isEmpty() ? null : ccfr.getGeneralData().getFacilityControlNumber());
            facilityGeneralDataRequest.setFinalMaturityDate(ccfr.getGeneralData().getFinalMaturityDate());
            facilityGeneralDataRequest.setLoanRepricingFxToleranceRateForFacility(ccfr.getGeneralData().getLoanRepricingFxToleranceRate());
            facilityGeneralDataRequest.setMaximumCurrenciesOutstanding(ccfr.getGeneralData().getMaximumCurrenciesOutstanding());
            facilityGeneralDataRequest.setPerformingStatus(Constants.EMPTY.equals(ccfr.getGeneralData().getPerformingStatus()) ? null : ccfr.getGeneralData().getPerformingStatus());
            facilityGeneralDataRequest.setPrimaryBorrowerExternalId(externalId);
            facilityGeneralDataRequest.setProcessingAreaCode(cor.getDeal().getGeneralDealInformation().getProcessingAreaCode());
            facilityGeneralDataRequest.setProposedCommitmentAmount(ccfr.getGeneralData().getProposedCommitmentAmount());
            facilityGeneralDataRequest.setUnavailableCommitment(ccfr.getGeneralData().getUnavailableCommitment());

            cfr.setFacilityGeneralData(facilityGeneralDataRequest);
        }
    }

    private void translateFacilityServicingGroup(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr, CreateOperationRequest cor){
        if(null != ccfr.getServicingGroup()){
            ServicingGroupRequest sgr = new ServicingGroupRequest();
            sgr.setCustomerExternalId(trimService.trimIfNotNull(vlsHostBankCustomRepository.findByBrnCdeBranch(cor.getDeal().getGeneralDealInformation().getBranch()).getCustLiqCode()));
            sgr.setAlias(ccfr.getServicingGroup().getAliasSg());
            sgr.setLocationCode(ccfr.getServicingGroup().getLocationCode());
            sgr.setProfileType(Constants.PROFILE_LENDER);
            cfr.setServicingGroup(sgr);
        }
    }

    private void translateFacilityRisks(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr){
        if(null != ccfr.getRisks() && !ccfr.getRisks().isEmpty()){
            cfr.setRisks(new ArrayList<>());
            for(CustomRiskRequest crr : ccfr.getRisks()){
                RiskRequest riskRequest = new RiskRequest();
                riskRequest.setRiskTypeCode(crr.getRiskTypeCode());
                cfr.getRisks().add(riskRequest);
            }
        }
    }

    private void translateFacilityProductCurrencies(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr){
        if(null != ccfr.getProductCurrencies() && !ccfr.getProductCurrencies().isEmpty()){
            cfr.setProductCurrency(new ArrayList<>());
            for(CustomProductCurrencyRequest cpcr : ccfr.getProductCurrencies()){
                ProductCurrencyRequest productCurrencyRequest = new ProductCurrencyRequest();
                productCurrencyRequest.setCurrency(cpcr.getCurrency());
                productCurrencyRequest.setRacApplies(cpcr.getRacApplies());
                productCurrencyRequest.setServicingGroupId(getServicingGroupId(cfr));
                productCurrencyRequest.setOverrideFXRate(cpcr.getOverrideFXRate());
                cfr.getProductCurrency().add(productCurrencyRequest);
            }
        }
    }

    private void translateInterestPricingOptionFacility(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr){
        if(null != ccfr.getInterestPricingOptions() && !ccfr.getInterestPricingOptions().isEmpty()){
            cfr.setInterestPricingOptions(new ArrayList<>());
            for(CustomInterestPricingOptionFacilityRequest cipofr : ccfr.getInterestPricingOptions()){
                InterestPricingOptionFacilityRequest ipofr = new InterestPricingOptionFacilityRequest();
                ipofr.setAlternateReferenceRatesRateBasis(cipofr.getAlternateReferenceRatesRateBasis());
                ipofr.setLockoutDays(cipofr.getLockoutDays());
                ipofr.setLookbackDays(cipofr.getLookbackDays());
                ipofr.setObservPeriodShift(cipofr.getObservPeriodShift());
                ipofr.setPaymentMode(cipofr.getPaymentMode());

                cfr.getInterestPricingOptions().add(ipofr);
            }
        }
    }

    private void translateFacilityInterestPricingOption(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr){
        if(null != ccfr.getFacilityInterestPricingOptions() && !ccfr.getFacilityInterestPricingOptions().isEmpty()){
            cfr.setFacilityInterestPricingOptions(new ArrayList<>());
            for(CustomFacilityInterestPricingOptionRequest cfipor : ccfr.getFacilityInterestPricingOptions()){
                FacilityInterestPricingOptionRequest fipor = new FacilityInterestPricingOptionRequest();
                fipor.setAdjustedDueDateRule(cfipor.getAdjustedDueDateRule());
                fipor.setAlternateReferenceRatesRateBasis(cfipor.getAlternateReferenceRatesRateBasis());
                fipor.setCapAndFloorRateChangeMethod(cfipor.getCapAndFloorRateChangeMethod());
                fipor.setInterestScheduleForRepricingDates(cfipor.getInterestScheduleForRepricingDates());
                fipor.setLockoutDays(cfipor.getLockoutDays());
                fipor.setLookbackDays(cfipor.getLookbackDays());
                fipor.setMaximumDrawdownAmount(cfipor.getMaximumDrawdownAmount());
                fipor.setMessageID(cfipor.getMessageID());
                fipor.setMinimumAmountMultiples(cfipor.getMinimumAmountMultiples());
                fipor.setMinimumDrawdownAmount(cfipor.getMinimumDrawdownAmount());
                fipor.setMinimumLenderShareMultiples(cfipor.getMinimumLenderShareMultiples());
                fipor.setMinimumPaymentAmount(cfipor.getMinimumPaymentAmount());
                fipor.setObservPeriodShift(cfipor.getObservPeriodShift());
                fipor.setPercentOfRateFormulaUsage(cfipor.getPercentOfRateFormulaUsage());
                fipor.setPricingCurrency(cfipor.getPricingCurrency());
                fipor.setPricingOption(cfipor.getPricingOption());
                fipor.setRemoveOverrides(cfipor.getRemoveOverrides());
                fipor.setRepricingAnniversaryDateApplies(cfipor.getRepricingAnniversaryDateApplies());
                fipor.setRoundingApplicationMethod(cfipor.getRoundingApplicationMethod());
                fipor.setSynchronizeBillingIndicator(cfipor.getSynchronizeBillingIndicator());
                fipor.setPaymentMode(cfipor.getPaymentMode());
                cfr.getFacilityInterestPricingOptions().add(fipor);
            }
        }
    }

    private String getServicingGroupId(CreateFacilityRequest cfr) {
        ServicingGroupRequest sgr = cfr.getServicingGroup();
        List<VlsCustLocationCustom> listSgrIds = vlsCustLocationCustomRepository
                .findByCloCidCustIdAndFrgNmeAliasAndCloCdeLocation(
                        sgr.getCustomerExternalId(),
                        sgr.getLocationCode(),
                        sgr.getAlias());
        return listSgrIds.stream().filter(Objects::nonNull).findFirst().orElse(new VlsCustLocationCustom()).getFrgRidFaxGroup();
    }

    private void translateFacilityLoanPurposes(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr){
        if(null != ccfr.getLoanPurposes() && !ccfr.getLoanPurposes().isEmpty()){
            cfr.setLoanPurposes(new ArrayList<>());
            for(CustomLoanPurposeRequest clpr : ccfr.getLoanPurposes()){
                LoanPurposeRequest loanPurposeRequest = new LoanPurposeRequest();
                loanPurposeRequest.setLoanPurposeCode(clpr.getLoanPurposeCode());
                cfr.getLoanPurposes().add(loanPurposeRequest);
            }
        }
    }

    private void translateFacilityMisCodes(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr){
        if(null != ccfr.getMisCodes() && !ccfr.getMisCodes().isEmpty()){
            cfr.setMisCodes(new ArrayList<>());
            for(CustomMISCodeRequest cmiscr : ccfr.getMisCodes()){
                MISCodeRequest mISCodeRequest = new MISCodeRequest();
                mISCodeRequest.setType(cmiscr.getType());
                mISCodeRequest.setValueType(cmiscr.getValueType());
                cfr.getMisCodes().add(mISCodeRequest);
            }
        }
    }

    private void translateFacilityFeePricings(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr){
        if(null != ccfr.getFeePricings() && !ccfr.getFeePricings().isEmpty()){
            cfr.setFeePricings(new ArrayList<>());
            for(CustomFeePricingRequest cfpr : ccfr.getFeePricings()){
                FeePricingRequest feePricingRequest = new FeePricingRequest();
                feePricingRequest.setAccrualEndDate(cfpr.getAccrualEndDate());
                feePricingRequest.setAccrue(cfpr.getAccrue());
                feePricingRequest.setActualDueDate(cfpr.getActualDueDate());
                feePricingRequest.setActualExpiryDate(cfpr.getActualExpiryDate());
                feePricingRequest.setAdjustedDueDate(cfpr.getAdjustedDueDate());
                feePricingRequest.setCategory(cfpr.getCategory());
                feePricingRequest.setCycleFrequency(cfpr.getCycleFrequency());
                feePricingRequest.setEffectiveDate(cfpr.getEffectiveDate());
                feePricingRequest.setFloatRateStartDate(cfpr.getFloatRateStartDate());
                if(null != cfpr.getPayInArrears() && Constants.Y.equals(cfpr.getPayInArrears())){
                    feePricingRequest.setPayInAdvance(Constants.N);
                    feePricingRequest.setPayInArrears(Constants.Y);
                }else{
                    feePricingRequest.setPayInAdvance(Constants.Y);
                    feePricingRequest.setPayInArrears(Constants.N);
                }
                feePricingRequest.setRate(cfpr.getRate());
                feePricingRequest.setRateBasis(cfpr.getRateBasis());
                feePricingRequest.setType(cfpr.getType());
                cfr.getFeePricings().add(feePricingRequest);
            }
        }
    }

    private void translateFacilityInterestPricings(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr){
        if(null != ccfr.getInterestPricings() && !ccfr.getInterestPricings().isEmpty()){
            cfr.setFacilityInterestPricings(new ArrayList<>());
            for(CustomFacilityInterestPricingRequest cfipr : ccfr.getInterestPricings()){
                FacilityInterestPricingRequest facilityInterestPricingRequest = new FacilityInterestPricingRequest();
                facilityInterestPricingRequest.setBaseRate(cfipr.getBaseRate());
                facilityInterestPricingRequest.setOptionName(cfipr.getOptionName());
                facilityInterestPricingRequest.setRateBasis(cfipr.getRateBasis());
                facilityInterestPricingRequest.setSpread(cfipr.getSpread());
                cfr.getFacilityInterestPricings().add(facilityInterestPricingRequest);
            }
        }
    }

    private void translateFacilityOngoingFeeDates(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr){
        if(null != ccfr.getOngoingFeeDates() && !ccfr.getOngoingFeeDates().isEmpty()){
            cfr.setOngoingFeeDates(new ArrayList<>());
            for(CustomOngoingFeeDateRequest cofdr : ccfr.getOngoingFeeDates()){
                OngoingFeeDateRequest ongoingFeeDateRequest = new OngoingFeeDateRequest();
                ongoingFeeDateRequest.setAdjustedDueDate(cofdr.getAdjustedDueDate());
                ongoingFeeDateRequest.setDeleteIndicator(cofdr.getDeleteIndicator());
                ongoingFeeDateRequest.setEffectiveDate(cofdr.getEffectiveDate());
                ongoingFeeDateRequest.setFeeCode(cofdr.getFeeCode());
                cfr.getOngoingFeeDates().add(ongoingFeeDateRequest);
            }
        }
    }

    private void translateFacilityAmortizationSchedules(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr, CreateOperationRequest cor){
        if(null != ccfr.getAmortizationSchedule()){
            CreateFacilityAmortizationScheduleRequest cfasr = new CreateFacilityAmortizationScheduleRequest();

            // General
            cfasr.setFacilityAmortizationScheduleGeneralRequest(new FacilityAmortizationScheduleGeneralRequest());
            cfasr.getFacilityAmortizationScheduleGeneralRequest().setBulletAtMaturityInd(ccfr.getAmortizationSchedule().getGeneral().getBulletAtMaturityInd());
            cfasr.getFacilityAmortizationScheduleGeneralRequest().setAliasDealName(cor.getDeal().getGeneralDealInformation().getDealAlias());
            cfasr.getFacilityAmortizationScheduleGeneralRequest().setFacilityName(ccfr.getGeneralData().getName());

            // Schedule
            if(null != ccfr.getAmortizationSchedule().getSchedules() && !ccfr.getAmortizationSchedule().getSchedules().isEmpty()){
                cfasr.setAmortizationSchedule(new ArrayList<>());
                for(CustomAmortizationScheduleRequest casr : ccfr.getAmortizationSchedule().getSchedules()){
                    AmortizationScheduleRequest asr = new AmortizationScheduleRequest();
                    asr.setCreateTieredSegmentsIndicator(casr.getCreateTieredSegmentsIndicator());
                    asr.setCyclicalScheduleFrequency(casr.getCyclicalScheduleFrequency());
                    asr.setCyclicalScheduleFrequencyPeriod(casr.getCyclicalScheduleFrequencyPeriod());
                    asr.setEom(casr.getEom());
                    asr.setNonBusinessDayRule(casr.getNonBusinessDayRule());
                    asr.setSeparateFirstItemAmount(casr.getSeparateFirstItemAmount());
                    asr.setSeparateFirstItemDate(casr.getSeparateFirstItemDate());
                    asr.setSeparateLastItemAmount(casr.getSeparateLastItemAmount());
                    asr.setSeparateLastItemDate(casr.getSeparateLastItemDate());
                    asr.setTriggerDate(casr.getTriggerDate());

                    cfasr.getAmortizationSchedule().add(asr);
                }
            }

            // Segment
            if(null != ccfr.getAmortizationSchedule().getSegments() && !ccfr.getAmortizationSchedule().getSegments().isEmpty()){
                cfasr.setScheduleSegment(new ArrayList<>());
                for(CustomScheduleSegmentRequest cssr : ccfr.getAmortizationSchedule().getSegments()){
                    ScheduleSegmentRequest ssr = new ScheduleSegmentRequest();
                    ssr.setAmount(cssr.getAmount());
                    ssr.setNoOfItemsInSegment(cssr.getNoOfItemsInSegment());
                    ssr.setPercentCurrentBalance(cssr.getPercentCurrentBalance());

                    cfasr.getScheduleSegment().add(ssr);
                }
            }

            cfr.setFacilityAmortizationSchedule(cfasr);
        }
    }

    private void translateFacilitySublimits(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr){
        if(null != ccfr.getSublimits() && !ccfr.getSublimits().isEmpty()){
            ArrayList<FacilitySublimitRequest> fsrL = new ArrayList<>();
            for(CustomFacilitySublimitRequest cfsr : ccfr.getSublimits()){
                FacilitySublimitRequest fsr = new FacilitySublimitRequest();

                // General
                fsr.setAmount(cfsr.getAmount());
                fsr.setDelete(cfsr.getDelete());
                fsr.setDiscretionaryIndicator(cfsr.getDiscretionaryIndicator());
                fsr.setEffectiveDate(cfsr.getEffectiveDate());
                fsr.setExpiryDate(cfsr.getExpiryDate());
                fsr.setMaturityDate(cfsr.getMaturityDate());
                fsr.setName(cfsr.getName());

                // Sublimit risk
                if(null != cfsr.getSublimitRisks() && !cfsr.getSublimitRisks().isEmpty()){
                    ArrayList<FacilitySublimitRiskRequest> fsrrL = new ArrayList<>();
                    for(CustomFacilitySublimitRiskRequest cfsrr : cfsr.getSublimitRisks()){
                        FacilitySublimitRiskRequest fsrr = new FacilitySublimitRiskRequest();
                        fsrr.setRiskTypeCode(cfsrr.getRiskTypeCode());
                        fsrrL.add(fsrr);
                    }
                    fsr.setFacilitySublimitRisks(fsrrL);
                }

                // Sublimit Associations
                if(null != cfsr.getSublimitAssociations() && !cfsr.getSublimitAssociations().isEmpty()){
                    ArrayList<SublimitAssociationRequest> sarL = new ArrayList<>();
                    for(CustomSublimitAssociationRequest csar : cfsr.getSublimitAssociations()){
                        SublimitAssociationRequest sar = new SublimitAssociationRequest();
                        sar.setSubordinate(csar.getSubordinate());
                        sarL.add(sar);
                    }
                    fsr.setSublimitAssociations(sarL);
                }

                fsrL.add(fsr);
            }
            cfr.setFacilitySublimits(fsrL);
        }
    }

    private void translateFacilityAddBorrowers(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr, CreateOperationRequest cor){
        if(null != ccfr.getAddBorrowers() && !ccfr.getAddBorrowers().isEmpty()){
            ArrayList<AddFacilityBorrowerRequest> afbrL = new ArrayList<>();
            for(CustomAddFacilityBorrowerRequest cafbr : ccfr.getAddBorrowers()){
                AddFacilityBorrowerRequest afbr = new AddFacilityBorrowerRequest();

                // General
                // El rid de la Facility se setea en la orquestación porque no lo sabemos todavia
                afbr.setBorrowerExternalId(glsOrJToExternalIdService.getXidFromGlsOrJ(
                        cafbr.getCustomerCode(),
                        cor.getDeal().getGeneralDealInformation().getBranch()));
                afbr.setDealAliasName(cor.getDeal().getGeneralDealInformation().getDealAlias());
                afbr.setEffectiveDate(cafbr.getEffectiveDate());
                afbr.setGlobalLimit(cafbr.getGlobalLimit());
                afbr.setPrivateMaturityDate(cafbr.getPrivateMaturityDate());
                afbr.setUpperLimitPercentage(cafbr.getUpperLimitPercentage());

                // FacilityBorrowerCurrencyLimits
                ArrayList<FacilityBorrowerCurrencyLimitRequest> fbclrL = new ArrayList<>();
                if (!CollectionUtils.isEmpty(cafbr.getFacilityBorrowerCurrencyLimits())) {
                    for(CustomFacilityBorrowerCurrencyLimitRequest cfbclr : cafbr.getFacilityBorrowerCurrencyLimits()){
                        FacilityBorrowerCurrencyLimitRequest fbclr = new FacilityBorrowerCurrencyLimitRequest();
                        fbclr.setCurrency(cfbclr.getCurrency());
                        fbclr.setDeleteIndicator(cfbclr.getDeleteIndicator());
                        fbclr.setLimit(cfbclr.getLimit());
                        fbclrL.add(fbclr);
                    }
                }
                afbr.setFacilityBorrowerCurrencyLimits(fbclrL);

                // FacilityBorrowerRiskTypeLimits
                ArrayList<FacilityBorrowerRiskTypeLimitRequest> fbrtlrL = new ArrayList<>();
                if (!CollectionUtils.isEmpty(cafbr.getFacilityBorrowerRiskTypeLimits())) {
                    for(CustomFacilityBorrowerRiskTypeLimitRequest cfbrtlr : cafbr.getFacilityBorrowerRiskTypeLimits()){
                        FacilityBorrowerRiskTypeLimitRequest fbrtlr = new FacilityBorrowerRiskTypeLimitRequest();
                        fbrtlr.setDeleteIndicator(cfbrtlr.getDeleteIndicator());
                        fbrtlr.setLimit(cfbrtlr.getLimit());
                        fbrtlr.setRisktype(cfbrtlr.getRisktype());
                        fbrtlrL.add(fbrtlr);
                    }
                }
                afbr.setFacilityBorrowerRiskTypeLimits(fbrtlrL);

                // FacilityBorrowerSublimitLimits
                ArrayList<FacilityBorrowerSublimitLimitRequest> fbslrL = new ArrayList<>();
                if (!CollectionUtils.isEmpty(cafbr.getFacilityBorrowerSublimitLimits())) {
                    for(CustomFacilityBorrowerSublimitLimitRequest cfbslr : cafbr.getFacilityBorrowerSublimitLimits()){
                        FacilityBorrowerSublimitLimitRequest fbslr = new FacilityBorrowerSublimitLimitRequest();
                        fbslr.setDeleteIndicator(cfbslr.getDeleteIndicator());
                        fbslr.setLimit(cfbslr.getLimit());
                        fbslr.setSublimit(cfbslr.getSublimit());
                        fbslrL.add(fbslr);
                    }
                }
                afbr.setFacilityBorrowerSublimitLimits(fbslrL);

                afbrL.add(afbr);
            }
            cfr.setAddFacilityBorrowers(afbrL);
        }
    }

    private void translateFacilityAdditionalFields(CreateFacilityRequest cfr, CustomCreateFacilityRequest ccfr) {
        if(null != ccfr.getAdditionalFields() && !ccfr.getAdditionalFields().isEmpty()) {
            cfr.setFacilityAdditionalFields(new UpdateAdditionalFieldsRequest());
            cfr.getFacilityAdditionalFields().setAdditionalFieldsGeneralData(new AdditionalFieldsGeneralData());
            cfr.getFacilityAdditionalFields().getAdditionalFieldsGeneralData().setOwnerType(Constants.FAC);

            List<AdditionalFieldRequest> li = new ArrayList<>();
            cfr.getFacilityAdditionalFields().setAdditionalFieldsRequests(li);
            for(CustomAdditionalFieldRequest cadd : ccfr.getAdditionalFields()) {
                AdditionalFieldRequest additional = new AdditionalFieldRequest();
                additional.setDeleteIndicator(cadd.getDeleteIndicator());
                additional.setFieldType(cadd.getFieldType());
                additional.setFieldValue(cadd.getFieldValue());

                cfr.getFacilityAdditionalFields().getAdditionalFieldsRequests().add(additional);
            }
        }
    }

}
Leave a Comment