Untitled

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

import es.isban.api.loaniq.constants.Constants;
import es.isban.api.loaniq.model.web.*;
import es.isban.api.loaniq.model.web.functional.*;
import es.isban.api.loaniq.repository.loandb.VlsHostBankCustomRepository;
import es.isban.api.loaniq.service.GlsOrJToExternalIdService;
import es.isban.api.loaniq.service.TrimService;

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

public class Guarantor extends Translator{

    private final TrimService trimService;
    private final VlsHostBankCustomRepository vlsHostBankCustomRepository;

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

    public void translate(CreateOperationRequest operationPublisher, CustomCreateOperationRequest operationRequest){
        operationPublisher.setGuarantors(new ArrayList<>());
        if(null != operationRequest.getGuarantors() && !operationRequest.getGuarantors().isEmpty()){
            for(CustomUpdateGuarantorsRequest cugr : operationRequest.getGuarantors()){
                UpdateGuarantorsRequest ugr = new UpdateGuarantorsRequest();
                if(null != cugr.getGuarantorsRequest()){
                    GuarantorsRequest gsr = new GuarantorsRequest();

                    // BusinessObjectRequest
                    BusinessObjectRequest bor = new BusinessObjectRequest();
                    CustomBusinessObjectRequest cbor = cugr.getGuarantorsRequest().getBusinessObject();
                    if(null != cbor){
                        bor.setBusinessObjectClass(cbor.getBusinessObjectClass());
                        bor.setIdentifier(""); // Se setea en la orquestacion
                        bor.setIdentifierType(Constants.BC_ID);
                        bor.setAliasDealOrFacilityName(cbor.getAliasDealOrFacilityName());
                    }
                    gsr.setBusinessObject(bor);



                    List<GuarantorRequest> grL = new ArrayList<>();
                    List<CustomGuarantorRequest> cgrL = cugr.getGuarantorsRequest().getUpdateGuarantors();
                    if(null != cgrL && !cgrL.isEmpty()){
                        for(CustomGuarantorRequest cgr : cgrL){
                            GuarantorRequest gr = new GuarantorRequest();
                            // Get External ID from J or GLS
                            if(null == cgr.getIsBeneficiaryHostBank() || Constants.EMPTY.equals(cgr.getIsBeneficiaryHostBank()) || !Constants.Y.equals(cgr.getIsBeneficiaryHostBank())){
                                gr.setBeneficiaryExternalId(glsOrJToExternalIdService.getXidFromGlsOrJ(
                                        cgr.getBeneficiaryCode(),
                                        operationPublisher.getDeal().getGeneralDealInformation().getBranch()));
                                // Get Branch host bank external Id
                            } else {
                                gr.setBeneficiaryExternalId(trimService.trimIfNotNull(vlsHostBankCustomRepository.findByBrnCdeBranch(operationPublisher.getDeal().getGeneralDealInformation().getBranch()).getCustLiqCode()));
                            }

                            gr.setCounterIndemnityIndicator(cgr.getCounterIndemnityIndicator());
                            gr.setCounterIndemnityRefNumber(cgr.getCounterIndemnityRefNumber());
                            gr.setCurrency(cgr.getCurrency());
                            gr.setCustomerExternalId(glsOrJToExternalIdService.getXidFromGlsOrJ(
                                    cgr.getCustomerCode(),
                                    operationPublisher.getDeal().getGeneralDealInformation().getBranch()));
                            gr.setGuaranteeType(cgr.getGuaranteeType());
                            gr.setGuarantorRefNumber(cgr.getGuarantorRefNumber());
                            gr.setPriority(cgr.getPriority());
                            gr.setRelationship(cgr.getRelationship());
                            gr.setRemoveIndicator(cgr.getRemoveIndicator());
                            gr.setRiskBasis(cgr.getRiskBasis());
                            gr.setSecured(cgr.getSecured());
                            gr.setServicingGroupAlias(cgr.getServicingGroupAlias());

                            CustomGuarantorCommercialRiskRequest cgcrr = cgr.getGuarantorCommercialRiskRequest();
                            if(null != cgcrr){
                                gr.setGuarantorCommercialRiskRequest(new GuarantorCommercialRiskRequest());
                                gr.getGuarantorCommercialRiskRequest().setCeiling(cgcrr.getCeiling());
                                gr.getGuarantorCommercialRiskRequest().setEffectiveDate(cgcrr.getEffectiveDate());
                                gr.getGuarantorCommercialRiskRequest().setExpiryDate(cgcrr.getExpiryDate());
                                gr.getGuarantorCommercialRiskRequest().setGlobalAmount(cgcrr.getGlobalAmount());
                                gr.getGuarantorCommercialRiskRequest().setGlobalPercentage(cgcrr.getGlobalPercentage());
                            }

                            CustomGuarantorPoliticalRiskRequest cgprr = cgr.getGuarantorPoliticalRiskRequest();
                            if(null != cgprr){
                                gr.setGuarantorPoliticalRiskRequest(new GuarantorPoliticalRiskRequest());
                                gr.getGuarantorPoliticalRiskRequest().setCeiling(cgprr.getCeiling());
                                gr.getGuarantorPoliticalRiskRequest().setEffectiveDate(cgprr.getEffectiveDate());
                                gr.getGuarantorPoliticalRiskRequest().setExpiryDate(cgprr.getExpiryDate());
                                gr.getGuarantorPoliticalRiskRequest().setGlobalAmount(cgprr.getGlobalAmount());
                                gr.getGuarantorPoliticalRiskRequest().setGlobalPercentage(cgprr.getGlobalPercentage());
                            }

                            grL.add(gr);
                        }
                    }
                    gsr.setUpdateGuarantors(grL);
                    ugr.setGuarantorsRequest(gsr);
                }
                operationPublisher.getGuarantors().add(ugr);
            }
        }
    }

}
Leave a Comment