Untitled

mail@pastecode.io avatar
unknown
plain_text
20 days ago
11 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.service.GlsOrJToExternalIdService;

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

public class Deal extends Translator{

    public Deal(GlsOrJToExternalIdService glsOrJToExternalIdService) {
        super(glsOrJToExternalIdService);
    }

    public void translate(CreateOperationRequest operationPublisher, CustomCreateOperationRequest operationRequest){
        if (null != operationRequest.getDeal()) {
            CreateDealRequest cdr = new CreateDealRequest();
            translateDealGeneralInformation(cdr, operationRequest);
            translateDealAdminAgent(cdr, operationRequest);
            translateDealBorrowers(cdr, operationRequest);
            translateDealPricings(cdr, operationRequest);
            translateDealFeePricingRules(cdr, operationRequest);
            translateDealCalendars(cdr, operationRequest);
            translateDealMisCodes(cdr, operationRequest);
            translateDealAddInfo(cdr, operationRequest);
            operationPublisher.setDeal(cdr);
        }
    }

    private void translateDealGeneralInformation(CreateDealRequest cdr, CustomCreateOperationRequest ccor){
        if(null != ccor.getDeal().getGeneralInformation()){
            GeneralInfoRequest generalInfoRequest = new GeneralInfoRequest();
            generalInfoRequest.setAgreementDate(ccor.getDeal().getGeneralInformation().getAgreementDate());
            generalInfoRequest.setBranch(ccor.getDeal().getGeneralInformation().getBranch());
            generalInfoRequest.setClassification(ccor.getDeal().getGeneralInformation().getClassification());
            generalInfoRequest.setCurrency(ccor.getDeal().getGeneralInformation().getCurrency());
            generalInfoRequest.setDealAlias(ccor.getDeal().getGeneralInformation().getAlias());
            generalInfoRequest.setDealName(ccor.getDeal().getGeneralInformation().getName());
            generalInfoRequest.setDepartment(ccor.getDeal().getGeneralInformation().getDepartment());
            generalInfoRequest.setExpenseCode(ccor.getDeal().getGeneralInformation().getExpenseCode());
            generalInfoRequest.setGlobalDealProposedCommitmentAmount(ccor.getDeal().getGeneralInformation().getGlobalProposedCommitmentAmount());
            generalInfoRequest.setGracePeriodNumberOfDays(ccor.getDeal().getGeneralInformation().getGracePeriodNumberOfDays());
            generalInfoRequest.setProcessingAreaCode(ccor.getDeal().getGeneralInformation().getProcessingAreaCode());
            generalInfoRequest.setProjectedCloseDate(ccor.getDeal().getGeneralInformation().getProjectedCloseDate());
            generalInfoRequest.setSoleLenderIndicator(ccor.getDeal().getGeneralInformation().getSoleLenderIndicator());
            cdr.setGeneralDealInformation(generalInfoRequest);
        }
    }

    private void translateDealAdminAgent(CreateDealRequest cdr, CustomCreateOperationRequest ccor){
        if(null != ccor.getDeal().getAdminAgent()){
            DealAdminAgentRequest dealAdminAgentRequest = new DealAdminAgentRequest();
            dealAdminAgentRequest.setCustomerExternalId(
                    glsOrJToExternalIdService.getXidFromGlsOrJ(
                            ccor.getDeal().getAdminAgent().getCustomerCode(),
                            cdr.getGeneralDealInformation().getBranch()));
            dealAdminAgentRequest.setAlias(ccor.getDeal().getAdminAgent().getAliasSg());
            dealAdminAgentRequest.setLocationCode(ccor.getDeal().getAdminAgent().getLocationCode());
            dealAdminAgentRequest.setProfileType(Constants.PROFILE_LENDER);
            cdr.setAdminAgent(dealAdminAgentRequest);
        }
    }

    private void translateDealBorrowers(CreateDealRequest cdr, CustomCreateOperationRequest ccor){
        if(null != ccor.getDeal().getBorrowers()){
            cdr.setAddDealBorrowers(new ArrayList<DealBorrowerRequest>());
            for(CustomDealBorrowerRequest cdbr : ccor.getDeal().getBorrowers()){
                DealBorrowerRequest dealBorrowerRequest = new DealBorrowerRequest();
                dealBorrowerRequest.setCustomerExternalId(
                        glsOrJToExternalIdService.getXidFromGlsOrJ(
                                cdbr.getCustomerCode(),
                                cdr.getGeneralDealInformation().getBranch()));
                dealBorrowerRequest.setAlias(cdbr.getAliasSg());
                dealBorrowerRequest.setLocationCode(cdbr.getLocationCode());
                dealBorrowerRequest.setProfileType(Constants.PROFILE_BORROWER);
                if(null != cdbr.getIsPrimary() && Constants.Y.equals(cdbr.getIsPrimary())){
                    cdr.setPrimaryBorrower(dealBorrowerRequest);
                }else{
                    cdr.getAddDealBorrowers().add(dealBorrowerRequest);
                }
            }
        }
    }
    private void translateDealPricings(CreateDealRequest cdr, CustomCreateOperationRequest ccor){
        if(null != ccor.getDeal().getPricings() && !ccor.getDeal().getPricings().isEmpty()){
            cdr.setDealPricing(new ArrayList<DealPricingRequest>());
            for(CustomDealPricingRequest cdpr : ccor.getDeal().getPricings()){
                DealPricingRequest dealPricingRequest = new DealPricingRequest();
                dealPricingRequest.setPricingOption(cdpr.getPricingOption());
                dealPricingRequest.setInterestDueUponRepricing(cdpr.getInterestDueUponRepricing());
                dealPricingRequest.setNonBusinessDayRule(cdpr.getNonBusinessDayRule());
                dealPricingRequest.setRacRepricingFrequencyMaximum(cdpr.getRacRepricingFrequencyMaximum());
                dealPricingRequest.setRateSettingAdvanceDays(cdpr.getRateSettingAdvanceDays());
                dealPricingRequest.setRoundingRulesDecimalPrecision(cdpr.getRoundingRulesDecimalPrecision());
                dealPricingRequest.setRoundingRulesDecimalRounding(cdpr.getRoundingRulesDecimalRounding());
                dealPricingRequest.setRoundingRulesFractionInitialRate(cdpr.getRoundingRulesFractionInitialRate());
                dealPricingRequest.setRoundingRulesFractionRounding(cdpr.getRoundingRulesFractionRounding());
                dealPricingRequest.setUtilizationImpact(cdpr.getUtilizationImpact());

                // 7.5.1.4
                dealPricingRequest.setAlternateReferenceRatesRateBasis(cdpr.getAlternateReferenceRatesRateBasis());
                dealPricingRequest.setLockoutDays(cdpr.getLockoutDays());
                dealPricingRequest.setLookbackDays(cdpr.getLookbackDays());
                dealPricingRequest.setObservPeriodShift(cdpr.getObservPeriodShift());

                cdr.getDealPricing().add(dealPricingRequest);
            }
        }
    }
    private void translateDealFeePricingRules(CreateDealRequest cdr, CustomCreateOperationRequest ccor){
        if(null != ccor.getDeal().getFeePricingRules() && !ccor.getDeal().getFeePricingRules().isEmpty()){
            cdr.setFeePricingRules(new ArrayList<FeePricingRulesRequest>());
            for(CustomFeePricingRulesRequest cfprr : ccor.getDeal().getFeePricingRules()){
                FeePricingRulesRequest feePricingRulesRequest = new FeePricingRulesRequest();
                feePricingRulesRequest.setBillingNumberOfDays(cfprr.getBillingNumberOfDays());
                feePricingRulesRequest.setFeeType(cfprr.getFeeType());
                feePricingRulesRequest.setMatrixChangeMethod(cfprr.getMatrixChangeMethod());
                feePricingRulesRequest.setNonBusinessDayRule(cfprr.getNonBusinessDayRule());
                cdr.getFeePricingRules().add(feePricingRulesRequest);
            }
        }
    }
    private void translateDealCalendars(CreateDealRequest cdr, CustomCreateOperationRequest ccor){
        if(null != ccor.getDeal().getCalendars() && !ccor.getDeal().getCalendars().isEmpty()){
            cdr.setCalendars(new ArrayList<CalendarRequest>());
            for(CustomCalendarRequest ccr : ccor.getDeal().getCalendars()){
                CalendarRequest calendarRequest = new CalendarRequest();
                calendarRequest.setBillingIndicator(ccr.getBillingIndicator());
                calendarRequest.setBorrowerIntentNoticeIndicator(ccr.getBorrowerIntentNoticeIndicator());
                calendarRequest.setCode(ccr.getCode());
                calendarRequest.setEffectiveDateIndicator(ccr.getEffectiveDateIndicator());
                calendarRequest.setFxRateSettingIndicator(ccr.getFxRateSettingIndicator());
                calendarRequest.setInterestRateSettingNoticeIndicator(ccr.getInterestRateSettingNoticeIndicator());
                calendarRequest.setPaymentAdviceDatesIndicator(ccr.getPaymentAdviceDatesIndicator());
                cdr.getCalendars().add(calendarRequest);
            }
        }
    }
    private void translateDealMisCodes(CreateDealRequest cdr, CustomCreateOperationRequest ccor){
        if(null != ccor.getDeal().getMisCodes() && !ccor.getDeal().getMisCodes().isEmpty()){
            cdr.setMisCodes(new ArrayList<MISCodeRequest>());
            for(CustomMISCodeRequest cmcr : ccor.getDeal().getMisCodes()){
                MISCodeRequest mISCodeRequest = new MISCodeRequest();
                mISCodeRequest.setType(cmcr.getType());
                mISCodeRequest.setValueType(cmcr.getValueType());
                cdr.getMisCodes().add(mISCodeRequest);
            }
        }
    }

    private void translateDealAddInfo(CreateDealRequest cdr, CustomCreateOperationRequest ccor) {
        if(null != ccor.getDeal().getAdditionalFields() && !ccor.getDeal().getAdditionalFields().isEmpty()) {
            cdr.setDealAdditionalFields(new UpdateAdditionalFieldsRequest());
            cdr.getDealAdditionalFields().setAdditionalFieldsGeneralData(new AdditionalFieldsGeneralData());

            List<AdditionalFieldRequest> li = new ArrayList<>();
            cdr.getDealAdditionalFields().setAdditionalFieldsRequests(li);
            cdr.getDealAdditionalFields().getAdditionalFieldsGeneralData().setOwnerType(Constants.DEA);
            for(CustomAdditionalFieldRequest cadd : ccor.getDeal().getAdditionalFields()) {
                AdditionalFieldRequest additional = new AdditionalFieldRequest();
                additional.setDeleteIndicator(cadd.getDeleteIndicator());
                additional.setFieldType(cadd.getFieldType());
                additional.setFieldValue(cadd.getFieldValue());

                cdr.getDealAdditionalFields().getAdditionalFieldsRequests().add(additional);
            }
        }
    }
}
Leave a Comment