All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.adorsys.multibanking.bg.BankingGatewayMapperImpl Maven / Gradle / Ivy

There is a newer version: 5.5.43
Show newest version
package de.adorsys.multibanking.bg;

import de.adorsys.multibanking.banking_gateway_b2c.model.AccountAccessTO;
import de.adorsys.multibanking.banking_gateway_b2c.model.AccountReferenceTO;
import de.adorsys.multibanking.banking_gateway_b2c.model.ChallengeDataTO;
import de.adorsys.multibanking.banking_gateway_b2c.model.ConsentTO;
import de.adorsys.multibanking.banking_gateway_b2c.model.CreateConsentResponseTO;
import de.adorsys.multibanking.banking_gateway_b2c.model.MessageTO;
import de.adorsys.multibanking.banking_gateway_b2c.model.MessageTO.SeverityEnum;
import de.adorsys.multibanking.banking_gateway_b2c.model.ResourceUpdateAuthResponseTO;
import de.adorsys.multibanking.banking_gateway_b2c.model.ResourceUpdateAuthResponseTO.ScaApproachEnum;
import de.adorsys.multibanking.banking_gateway_b2c.model.ResourceUpdateAuthResponseTO.ScaStatusEnum;
import de.adorsys.multibanking.banking_gateway_b2c.model.ScaMethodTO;
import de.adorsys.multibanking.banking_gateway_b2c.model.ScaMethodTO.AuthenticationTypeEnum;
import de.adorsys.multibanking.banking_gateway_b2c.model.SelectPsuAuthenticationMethodRequestTO;
import de.adorsys.multibanking.banking_gateway_b2c.model.TransactionAuthorisationRequestTO;
import de.adorsys.multibanking.banking_gateway_b2c.model.UpdatePsuAuthenticationRequestTO;
import de.adorsys.multibanking.domain.AccountReference;
import de.adorsys.multibanking.domain.AuthenticationType;
import de.adorsys.multibanking.domain.Balance;
import de.adorsys.multibanking.domain.Balance.BalanceBuilder;
import de.adorsys.multibanking.domain.BankAccount;
import de.adorsys.multibanking.domain.Booking;
import de.adorsys.multibanking.domain.ChallengeData;
import de.adorsys.multibanking.domain.Consent;
import de.adorsys.multibanking.domain.Credentials;
import de.adorsys.multibanking.domain.ScaApproach;
import de.adorsys.multibanking.domain.ScaStatus;
import de.adorsys.multibanking.domain.TanTransportType;
import de.adorsys.multibanking.domain.TanTransportType.TanTransportTypeBuilder;
import de.adorsys.multibanking.domain.exception.Message;
import de.adorsys.multibanking.domain.exception.Message.MessageBuilder;
import de.adorsys.multibanking.domain.exception.Message.Severity;
import de.adorsys.multibanking.domain.request.SelectPsuAuthenticationMethodRequest;
import de.adorsys.multibanking.domain.request.TransactionAuthorisationRequest;
import de.adorsys.multibanking.domain.response.CreateConsentResponse;
import de.adorsys.multibanking.domain.response.UpdateAuthResponse;
import de.adorsys.multibanking.xs2a_adapter.model.AccountDetails;
import de.adorsys.multibanking.xs2a_adapter.model.Amount;
import de.adorsys.multibanking.xs2a_adapter.model.TppMessage400AIS;
import de.adorsys.multibanking.xs2a_adapter.model.TppMessageCategory;
import de.adorsys.multibanking.xs2a_adapter.model.TransactionDetails;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Generated;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    date = "2020-07-01T12:18:03+0000",
    comments = "version: 1.3.0.Final, compiler: javac, environment: Java 1.8.0_252 (Private Build)"
)
class BankingGatewayMapperImpl implements BankingGatewayMapper {

    @Override
    public ConsentTO toConsentTO(Consent consentTemplate) {
        if ( consentTemplate == null ) {
            return null;
        }

        ConsentTO consentTO = new ConsentTO();

        consentTO.setAccess( consentToAccountAccessTO( consentTemplate ) );
        consentTO.setPsuAccount( consentTemplate.getPsuAccountIban() );
        consentTO.setRecurringIndicator( consentTemplate.isRecurringIndicator() );
        consentTO.setValidUntil( consentTemplate.getValidUntil() );
        consentTO.setFrequencyPerDay( consentTemplate.getFrequencyPerDay() );
        consentTO.setPsuId( consentTemplate.getPsuId() );

        return consentTO;
    }

    @Override
    public Consent toConsent(ConsentTO consentTO) {
        if ( consentTO == null ) {
            return null;
        }

        Consent consent = new Consent();

        List balances = consentTOAccessBalances( consentTO );
        consent.setBalances( accountReferenceTOListToAccountReferenceList( balances ) );
        consent.setPsuAccountIban( consentTO.getPsuAccount() );
        List accounts = consentTOAccessAccounts( consentTO );
        consent.setAccounts( accountReferenceTOListToAccountReferenceList( accounts ) );
        List transactions = consentTOAccessTransactions( consentTO );
        consent.setTransactions( accountReferenceTOListToAccountReferenceList( transactions ) );
        consent.setConsentId( consentTO.getConsentId() );
        consent.setPsuId( consentTO.getPsuId() );
        if ( consentTO.isRecurringIndicator() != null ) {
            consent.setRecurringIndicator( consentTO.isRecurringIndicator() );
        }
        consent.setValidUntil( consentTO.getValidUntil() );
        if ( consentTO.getFrequencyPerDay() != null ) {
            consent.setFrequencyPerDay( consentTO.getFrequencyPerDay() );
        }

        return consent;
    }

    @Override
    public CreateConsentResponse toCreateConsentResponse(CreateConsentResponseTO consentResponse) {
        if ( consentResponse == null ) {
            return null;
        }

        CreateConsentResponse createConsentResponse = new CreateConsentResponse();

        createConsentResponse.setScaApproach( scaApproachEnumToScaApproach( consentResponse.getScaApproach() ) );
        createConsentResponse.setConsentId( consentResponse.getConsentId() );
        createConsentResponse.setAuthorisationId( consentResponse.getAuthorisationId() );
        createConsentResponse.setRedirectUrl( consentResponse.getRedirectUrl() );
        createConsentResponse.setOauthRedirectUrl( consentResponse.getOauthRedirectUrl() );

        return createConsentResponse;
    }

    @Override
    public UpdatePsuAuthenticationRequestTO toUpdatePsuAuthenticationRequestTO(Credentials credentials) {
        if ( credentials == null ) {
            return null;
        }

        UpdatePsuAuthenticationRequestTO updatePsuAuthenticationRequestTO = new UpdatePsuAuthenticationRequestTO();

        updatePsuAuthenticationRequestTO.setPassword( credentials.getPin() );
        updatePsuAuthenticationRequestTO.setPsuCorporateId( credentials.getUserId() );
        updatePsuAuthenticationRequestTO.setPsuId( credentials.getCustomerId() );

        return updatePsuAuthenticationRequestTO;
    }

    @Override
    public UpdateAuthResponse toUpdateAuthResponse(ResourceUpdateAuthResponseTO resourceUpdateAuthResponseTO, UpdateAuthResponse updateAuthResponse) {
        if ( resourceUpdateAuthResponseTO == null ) {
            return null;
        }

        if ( updateAuthResponse.getScaMethods() != null ) {
            List list = scaMethodTOListToTanTransportTypeList( resourceUpdateAuthResponseTO.getScaMethods() );
            if ( list != null ) {
                updateAuthResponse.getScaMethods().clear();
                updateAuthResponse.getScaMethods().addAll( list );
            }
            else {
                updateAuthResponse.setScaMethods( null );
            }
        }
        else {
            List list = scaMethodTOListToTanTransportTypeList( resourceUpdateAuthResponseTO.getScaMethods() );
            if ( list != null ) {
                updateAuthResponse.setScaMethods( list );
            }
        }
        updateAuthResponse.setChallenge( toChallengeData( resourceUpdateAuthResponseTO.getChallenge() ) );

        return updateAuthResponse;
    }

    @Override
    public SelectPsuAuthenticationMethodRequestTO toSelectPsuAuthenticationMethodRequestTO(SelectPsuAuthenticationMethodRequest selectPsuAuthenticationMethod) {
        if ( selectPsuAuthenticationMethod == null ) {
            return null;
        }

        SelectPsuAuthenticationMethodRequestTO selectPsuAuthenticationMethodRequestTO = new SelectPsuAuthenticationMethodRequestTO();

        selectPsuAuthenticationMethodRequestTO.setAuthenticationMethodId( selectPsuAuthenticationMethod.getAuthenticationMethodId() );

        return selectPsuAuthenticationMethodRequestTO;
    }

    @Override
    public TransactionAuthorisationRequestTO toTransactionAuthorisationRequestTO(TransactionAuthorisationRequest transactionAuthorisation) {
        if ( transactionAuthorisation == null ) {
            return null;
        }

        TransactionAuthorisationRequestTO transactionAuthorisationRequestTO = new TransactionAuthorisationRequestTO();

        transactionAuthorisationRequestTO.setScaAuthenticationData( transactionAuthorisation.getScaAuthenticationData() );

        return transactionAuthorisationRequestTO;
    }

    @Override
    public TanTransportType toTanTransportType(ScaMethodTO scaMethodTO) {
        if ( scaMethodTO == null ) {
            return null;
        }

        TanTransportTypeBuilder tanTransportType = TanTransportType.builder();

        tanTransportType.inputInfo( scaMethodTO.getExplanation() );
        tanTransportType.id( scaMethodTO.getAuthenticationMethodId() );
        tanTransportType.medium( scaMethodTO.getName() );
        tanTransportType.type( authenticationTypeEnumToAuthenticationType( scaMethodTO.getAuthenticationType() ) );
        tanTransportType.name( scaMethodTO.getName() );

        return tanTransportType.build();
    }

    @Override
    public List toBankAccounts(List accountDetails) {
        if ( accountDetails == null ) {
            return null;
        }

        List list = new ArrayList( accountDetails.size() );
        for ( AccountDetails accountDetails1 : accountDetails ) {
            list.add( toBankAccount( accountDetails1 ) );
        }

        return list;
    }

    @Override
    public BankAccount toBankAccount(AccountDetails accountDetails) {
        if ( accountDetails == null ) {
            return null;
        }

        BankAccount bankAccount = new BankAccount();

        bankAccount.setCurrency( accountDetails.getCurrency() );
        bankAccount.setName( accountDetails.getName() );
        bankAccount.setIban( accountDetails.getIban() );

        bankAccount.setExternalIdMap( getExternalIdMap(accountDetails.getResourceId()) );
        bankAccount.setBlz( getBlz(accountDetails) );
        bankAccount.setAccountNumber( getAccountNumber(accountDetails) );
        bankAccount.setType( getAccounType(accountDetails.getCashAccountType()) );

        return bankAccount;
    }

    @Override
    public List toBookings(List transactionDetails) {
        if ( transactionDetails == null ) {
            return null;
        }

        List list = new ArrayList( transactionDetails.size() );
        for ( TransactionDetails transactionDetails1 : transactionDetails ) {
            list.add( toBooking( transactionDetails1 ) );
        }

        return list;
    }

    @Override
    public Balance toBalance(de.adorsys.multibanking.xs2a_adapter.model.Balance balance) {
        if ( balance == null ) {
            return null;
        }

        BalanceBuilder balance1 = Balance.builder();

        balance1.date( balance.getReferenceDate() );
        String amount = balanceBalanceAmountAmount( balance );
        if ( amount != null ) {
            balance1.amount( new BigDecimal( amount ) );
        }
        balance1.currency( balanceBalanceAmountCurrency( balance ) );

        return balance1.build();
    }

    @Override
    public List toMessagesFromTppMessage400AIS(List messages) {
        if ( messages == null ) {
            return null;
        }

        List list = new ArrayList( messages.size() );
        for ( TppMessage400AIS tppMessage400AIS : messages ) {
            list.add( toMessage( tppMessage400AIS ) );
        }

        return list;
    }

    @Override
    public List toMessages(List messageTOList) {
        if ( messageTOList == null ) {
            return null;
        }

        List list = new ArrayList( messageTOList.size() );
        for ( MessageTO messageTO : messageTOList ) {
            list.add( messageTOToMessage( messageTO ) );
        }

        return list;
    }

    @Override
    public Message toMessage(TppMessage400AIS tppMessage400AIS) {
        if ( tppMessage400AIS == null ) {
            return null;
        }

        MessageBuilder message = Message.builder();

        message.severity( tppMessageCategoryToSeverity( tppMessage400AIS.getCategory() ) );
        message.renderedMessage( tppMessage400AIS.getText() );
        if ( tppMessage400AIS.getCode() != null ) {
            message.key( tppMessage400AIS.getCode().name() );
        }

        return message.build();
    }

    @Override
    public ScaApproach toScaApproach(ScaApproachEnum scaApproach) {
        if ( scaApproach == null ) {
            return null;
        }

        ScaApproach scaApproach1;

        switch ( scaApproach ) {
            case EMBEDDED: scaApproach1 = ScaApproach.EMBEDDED;
            break;
            case REDIRECT: scaApproach1 = ScaApproach.REDIRECT;
            break;
            case DECOUPLED: scaApproach1 = ScaApproach.DECOUPLED;
            break;
            case OAUTH: scaApproach1 = ScaApproach.OAUTH;
            break;
            case OAUTH_PRESTEP: scaApproach1 = ScaApproach.OAUTH_PRESTEP;
            break;
            default: throw new IllegalArgumentException( "Unexpected enum constant: " + scaApproach );
        }

        return scaApproach1;
    }

    @Override
    public ScaStatus toScaStatus(ScaStatusEnum scaStatus) {
        if ( scaStatus == null ) {
            return null;
        }

        ScaStatus scaStatus1;

        switch ( scaStatus ) {
            case RECEIVED: scaStatus1 = ScaStatus.RECEIVED;
            break;
            case STARTED: scaStatus1 = ScaStatus.STARTED;
            break;
            case PSUIDENTIFIED: scaStatus1 = ScaStatus.PSUIDENTIFIED;
            break;
            case PSUAUTHENTICATED: scaStatus1 = ScaStatus.PSUAUTHENTICATED;
            break;
            case SCAMETHODSELECTED: scaStatus1 = ScaStatus.SCAMETHODSELECTED;
            break;
            case FINALISED: scaStatus1 = ScaStatus.FINALISED;
            break;
            case FAILED: scaStatus1 = ScaStatus.FAILED;
            break;
            case EXEMPTED: scaStatus1 = ScaStatus.EXEMPTED;
            break;
            default: throw new IllegalArgumentException( "Unexpected enum constant: " + scaStatus );
        }

        return scaStatus1;
    }

    @Override
    public ChallengeData toChallengeData(ChallengeDataTO challengeData) {
        if ( challengeData == null ) {
            return null;
        }

        ChallengeData challengeData1 = new ChallengeData();

        List list = challengeData.getData();
        if ( list != null ) {
            challengeData1.setData( new ArrayList( list ) );
        }
        challengeData1.setImageLink( challengeData.getImageLink() );
        if ( challengeData.getOtpMaxLength() != null ) {
            challengeData1.setOtpMaxLength( challengeData.getOtpMaxLength() );
        }
        challengeData1.setOtpFormat( challengeData.getOtpFormat() );
        challengeData1.setAdditionalInformation( challengeData.getAdditionalInformation() );

        challengeData1.setImage( encodeBase64(challengeData.getImage()) );

        return challengeData1;
    }

    protected AccountReferenceTO accountReferenceToAccountReferenceTO(AccountReference accountReference) {
        if ( accountReference == null ) {
            return null;
        }

        AccountReferenceTO accountReferenceTO = new AccountReferenceTO();

        accountReferenceTO.setIban( accountReference.getIban() );
        accountReferenceTO.setCurrency( accountReference.getCurrency() );

        return accountReferenceTO;
    }

    protected List accountReferenceListToAccountReferenceTOList(List list) {
        if ( list == null ) {
            return null;
        }

        List list1 = new ArrayList( list.size() );
        for ( AccountReference accountReference : list ) {
            list1.add( accountReferenceToAccountReferenceTO( accountReference ) );
        }

        return list1;
    }

    protected AccountAccessTO consentToAccountAccessTO(Consent consent) {
        if ( consent == null ) {
            return null;
        }

        AccountAccessTO accountAccessTO = new AccountAccessTO();

        accountAccessTO.setTransactions( accountReferenceListToAccountReferenceTOList( consent.getTransactions() ) );
        accountAccessTO.setBalances( accountReferenceListToAccountReferenceTOList( consent.getBalances() ) );
        accountAccessTO.setAccounts( accountReferenceListToAccountReferenceTOList( consent.getAccounts() ) );

        return accountAccessTO;
    }

    private List consentTOAccessBalances(ConsentTO consentTO) {
        if ( consentTO == null ) {
            return null;
        }
        AccountAccessTO access = consentTO.getAccess();
        if ( access == null ) {
            return null;
        }
        List balances = access.getBalances();
        if ( balances == null ) {
            return null;
        }
        return balances;
    }

    protected AccountReference accountReferenceTOToAccountReference(AccountReferenceTO accountReferenceTO) {
        if ( accountReferenceTO == null ) {
            return null;
        }

        AccountReference accountReference = new AccountReference();

        accountReference.setIban( accountReferenceTO.getIban() );
        accountReference.setCurrency( accountReferenceTO.getCurrency() );

        return accountReference;
    }

    protected List accountReferenceTOListToAccountReferenceList(List list) {
        if ( list == null ) {
            return null;
        }

        List list1 = new ArrayList( list.size() );
        for ( AccountReferenceTO accountReferenceTO : list ) {
            list1.add( accountReferenceTOToAccountReference( accountReferenceTO ) );
        }

        return list1;
    }

    private List consentTOAccessAccounts(ConsentTO consentTO) {
        if ( consentTO == null ) {
            return null;
        }
        AccountAccessTO access = consentTO.getAccess();
        if ( access == null ) {
            return null;
        }
        List accounts = access.getAccounts();
        if ( accounts == null ) {
            return null;
        }
        return accounts;
    }

    private List consentTOAccessTransactions(ConsentTO consentTO) {
        if ( consentTO == null ) {
            return null;
        }
        AccountAccessTO access = consentTO.getAccess();
        if ( access == null ) {
            return null;
        }
        List transactions = access.getTransactions();
        if ( transactions == null ) {
            return null;
        }
        return transactions;
    }

    protected ScaApproach scaApproachEnumToScaApproach(de.adorsys.multibanking.banking_gateway_b2c.model.CreateConsentResponseTO.ScaApproachEnum scaApproachEnum) {
        if ( scaApproachEnum == null ) {
            return null;
        }

        ScaApproach scaApproach;

        switch ( scaApproachEnum ) {
            case EMBEDDED: scaApproach = ScaApproach.EMBEDDED;
            break;
            case REDIRECT: scaApproach = ScaApproach.REDIRECT;
            break;
            case DECOUPLED: scaApproach = ScaApproach.DECOUPLED;
            break;
            case OAUTH: scaApproach = ScaApproach.OAUTH;
            break;
            case OAUTH_PRESTEP: scaApproach = ScaApproach.OAUTH_PRESTEP;
            break;
            default: throw new IllegalArgumentException( "Unexpected enum constant: " + scaApproachEnum );
        }

        return scaApproach;
    }

    protected List scaMethodTOListToTanTransportTypeList(List list) {
        if ( list == null ) {
            return null;
        }

        List list1 = new ArrayList( list.size() );
        for ( ScaMethodTO scaMethodTO : list ) {
            list1.add( toTanTransportType( scaMethodTO ) );
        }

        return list1;
    }

    protected AuthenticationType authenticationTypeEnumToAuthenticationType(AuthenticationTypeEnum authenticationTypeEnum) {
        if ( authenticationTypeEnum == null ) {
            return null;
        }

        AuthenticationType authenticationType;

        switch ( authenticationTypeEnum ) {
            case SMS_OTP: authenticationType = AuthenticationType.SMS_OTP;
            break;
            case CHIP_OTP: authenticationType = AuthenticationType.CHIP_OTP;
            break;
            case PHOTO_OTP: authenticationType = AuthenticationType.PHOTO_OTP;
            break;
            case PUSH_OTP: authenticationType = AuthenticationType.PUSH_OTP;
            break;
            case EMAIL: authenticationType = AuthenticationType.EMAIL;
            break;
            case APP_OTP: authenticationType = AuthenticationType.APP_OTP;
            break;
            default: throw new IllegalArgumentException( "Unexpected enum constant: " + authenticationTypeEnum );
        }

        return authenticationType;
    }

    private String balanceBalanceAmountAmount(de.adorsys.multibanking.xs2a_adapter.model.Balance balance) {
        if ( balance == null ) {
            return null;
        }
        Amount balanceAmount = balance.getBalanceAmount();
        if ( balanceAmount == null ) {
            return null;
        }
        String amount = balanceAmount.getAmount();
        if ( amount == null ) {
            return null;
        }
        return amount;
    }

    private String balanceBalanceAmountCurrency(de.adorsys.multibanking.xs2a_adapter.model.Balance balance) {
        if ( balance == null ) {
            return null;
        }
        Amount balanceAmount = balance.getBalanceAmount();
        if ( balanceAmount == null ) {
            return null;
        }
        String currency = balanceAmount.getCurrency();
        if ( currency == null ) {
            return null;
        }
        return currency;
    }

    protected Severity severityEnumToSeverity(SeverityEnum severityEnum) {
        if ( severityEnum == null ) {
            return null;
        }

        Severity severity;

        switch ( severityEnum ) {
            case ERROR: severity = Severity.ERROR;
            break;
            case WARNING: severity = Severity.WARNING;
            break;
            case INFO: severity = Severity.INFO;
            break;
            default: throw new IllegalArgumentException( "Unexpected enum constant: " + severityEnum );
        }

        return severity;
    }

    protected Message messageTOToMessage(MessageTO messageTO) {
        if ( messageTO == null ) {
            return null;
        }

        MessageBuilder message = Message.builder();

        message.key( messageTO.getKey() );
        message.severity( severityEnumToSeverity( messageTO.getSeverity() ) );
        message.field( messageTO.getField() );
        message.renderedMessage( messageTO.getRenderedMessage() );
        Map map = messageTO.getParamsMap();
        if ( map != null ) {
            message.paramsMap( new HashMap( map ) );
        }

        return message.build();
    }

    protected Severity tppMessageCategoryToSeverity(TppMessageCategory tppMessageCategory) {
        if ( tppMessageCategory == null ) {
            return null;
        }

        Severity severity;

        switch ( tppMessageCategory ) {
            case ERROR: severity = Severity.ERROR;
            break;
            case WARNING: severity = Severity.WARNING;
            break;
            default: throw new IllegalArgumentException( "Unexpected enum constant: " + tppMessageCategory );
        }

        return severity;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy