Untitled

 avatar
user_0111432
plain_text
25 days ago
3.5 kB
4
Indexable
Never
/**
 * Controller class for the brokerTransactionsPanel LWC.
 * 
 * This class must be added to the Permission Set: Aura Enabled Classes - F1C1R1
 *
 * @author  matt.tm
 * @jira    TRPF-2320
 * @test    BrokerTransactionsPanelControllerTest
 */
public with sharing class BrokerTransactionsPanelController
{
    private static final String EMPTY_PAYLOAD = '{\"brokerTransactions\":{\"transactions\":[]}}';

    @AuraEnabled
    public static String getBankAccounts(String accountId) {
        System.debug(LoggingLevel.INFO, 'BrokerTransactionsPanelController.getBankAccounts(): accountId->' + accountId);

        LoanManagementSystemDelegate delegate = new LoanManagementSystemDelegate(ProspaContractHelper.LOAN_MANAGEMENT_SYSTEM_CLOUD_LENDING);

        String jsonPayload = delegate.getBankAccounts(accountId);

        return jsonPayload;
    }

    @AuraEnabled
    public static String getBrokerTransactions(String accountId, Integer nClPage, Integer nMambuPage, Integer nLimit) {
        System.debug(LoggingLevel.INFO, 'BrokerTransactionsPanelController.getBrokerTransactions(): accountId->' + accountId + ' nClPage->' + nClPage + ' nMambuPage->' + nMambuPage + ' nLimit->' + nLimit);

        LoanManagementSystemDelegate delegateCloudLending = new LoanManagementSystemDelegate(ProspaContractHelper.LOAN_MANAGEMENT_SYSTEM_CLOUD_LENDING);
        LoanManagementSystemDelegate delegateMambu        = new LoanManagementSystemDelegate(ProspaContractHelper.LOAN_MANAGEMENT_SYSTEM_MAMBU);

        String payloadCloudLending = (nClPage == -1) ? null : delegateCloudLending.getBrokerTransactions(accountId, nClPage, nLimit);
        String payloadMambu        = (nMambuPage == -1) ? null : delegateMambu.getBrokerTransactions(accountId, nMambuPage, nLimit);

        String jsonPayload = '{';

        jsonPayload += '\"cloudLending\":' + ((String.isBlank(payloadCloudLending)) ? EMPTY_PAYLOAD : payloadCloudLending);
        jsonPayload += ',\"mambu\":' + ((String.isBlank(payloadMambu)) ? EMPTY_PAYLOAD : payloadMambu);

        if (String.isNotBlank(payloadMambu)) {
            jsonPayload = jsonPayload.removeEnd('}') + ',' + getCalloutConfigurations('Mambu Loan Query Callout') + '}';
        }

        jsonPayload += '}';

        return jsonPayload;
    }

    private static String getCalloutConfigurations(String label) {
        Boolean isProduction = (GlobalUtility.isSandbox() == false) ? true : false;

        List<External_WebService_Config__mdt> configurationList = [
            SELECT Id,
                   DeveloperName,
                   Host_Url__c,
                   Product_Type__c,
                   Is_Production__c
            FROM   External_WebService_Config__mdt
            WHERE  Label = :label
                AND Is_Active__c = TRUE
                AND Is_Production__c = :isProduction
        ];

        String payload = '\"baseUrls\":{';

        for (External_WebService_Config__mdt configuration : configurationList) {
            if      (configuration.Product_Type__c == 'Line of Credit') { payload += '\"lineOfCredit\":\"' + configuration.Host_Url__c + '\",'; }
            else if (configuration.Product_Type__c == 'Simple Loan')    { payload += '\"simpleLoan\":\"' + configuration.Host_Url__c + '\",'; }
            else                                                        { throw new CustomException('Unknown Product Type encountered: ' + configuration.Product_Type__c); }
        }

        payload = payload.removeEnd(',') + '}'; 

        return payload;
    }
}
Leave a Comment