Search in sources :

Example 1 with FRPartyData

use of com.forgerock.openbanking.common.model.openbanking.domain.account.FRPartyData in project openbanking-aspsp by OpenBankingToolkit.

the class DataApiController method importUserData.

@Override
public ResponseEntity importUserData(@RequestBody FRUserData userData) {
    String username = userData.getUserName();
    log.debug("importUserData() called with data for user '{}'", userData);
    FRUserData userDataResponse = new FRUserData(username);
    if (rsConfiguration.isCustomerInfoEnabled()) {
        FRCustomerInfo requestCustomerInfo = userData.getCustomerInfo();
        if (userData.getCustomerInfo() != null) {
            FRCustomerInfo existingCustomerInfo = customerInfoRepository.findByUserID(username);
            if (existingCustomerInfo != null) {
                requestCustomerInfo.setId(existingCustomerInfo.getId());
            }
            FRCustomerInfo savedCustomerInfo = customerInfoRepository.save(requestCustomerInfo);
            userDataResponse.setCustomerInfo(savedCustomerInfo);
        }
    }
    if (userData.getParty() != null) {
        FRParty existingParty = partyRepository.findByUserId(username);
        // Party
        if (existingParty != null) {
            userData.getParty().setPartyId(existingParty.getId());
        }
        FRParty newParty = new FRParty();
        newParty.setUserId(username);
        newParty.setParty(toFRPartyData(userData.getParty()));
        newParty.setId(userData.getParty().getPartyId());
        FRPartyData newPartyData = partyRepository.save(newParty).getParty();
        userDataResponse.setParty(toOBParty2(newPartyData));
    }
    Set<String> existingAccountIds = accountsRepository.findByUserID(username).stream().map(FRAccount::getId).collect(Collectors.toSet());
    for (FRAccountData accountData : userData.getAccountDatas()) {
        FRAccountData accountDataResponse = new FRAccountData();
        // Account
        if (accountData.getAccount() != null) {
            FRFinancialAccount frAccount = dataCreator.createAccount(accountData, username).getAccount();
            accountDataResponse.setAccount(toOBAccount6(frAccount));
            existingAccountIds.add(accountDataResponse.getAccount().getAccountId());
        }
        // Product
        dataCreator.createProducts(accountData, existingAccountIds).ifPresent(accountDataResponse::setProduct);
        // Party
        dataCreator.createParty(accountData).ifPresent(p -> accountDataResponse.setParty(toOBParty2(p)));
        // Balance
        dataCreator.createBalances(accountData, existingAccountIds).forEach(b -> accountDataResponse.addBalance(toOBCashBalance1(b.getBalance())));
        // Beneficiaries
        dataCreator.createBeneficiaries(accountData, existingAccountIds).forEach(b -> accountDataResponse.addBeneficiary(toOBBeneficiary5(b.getBeneficiary())));
        // Direct debits
        dataCreator.createDirectDebits(accountData, existingAccountIds).forEach(d -> accountDataResponse.addDirectDebit(toOBReadDirectDebit2DataDirectDebit(d.getDirectDebit())));
        // Standing orders
        dataCreator.createStandingOrders(accountData, existingAccountIds).forEach(d -> accountDataResponse.addStandingOrder(toOBStandingOrder6(d.getStandingOrder())));
        // Transactions
        dataCreator.createTransactions(accountData, existingAccountIds).forEach(d -> accountDataResponse.addTransaction(toOBTransaction6(d.getTransaction())));
        // Statements
        dataCreator.createStatements(accountData, existingAccountIds).forEach(d -> accountDataResponse.addStatement(toOBStatement2(d.getStatement())));
        // Scheduled payments
        dataCreator.createScheduledPayments(accountData, existingAccountIds).forEach(d -> accountDataResponse.addScheduledPayment(toOBScheduledPayment3(d.getScheduledPayment())));
        // offers
        dataCreator.createOffers(accountData, existingAccountIds).forEach(d -> accountDataResponse.addOffer(toOBOffer1(d.getOffer())));
        userDataResponse.addAccountData(accountDataResponse);
    }
    return ResponseEntity.ok(userDataResponse);
}
Also used : FRUserData(com.forgerock.openbanking.common.model.data.FRUserData) FRPartyConverter.toFRPartyData(com.forgerock.openbanking.common.services.openbanking.converter.account.FRPartyConverter.toFRPartyData) FRPartyData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRPartyData) FRCustomerInfo(com.forgerock.openbanking.common.model.data.FRCustomerInfo) FRAccountData(com.forgerock.openbanking.common.model.data.FRAccountData) FRFinancialAccount(com.forgerock.openbanking.common.model.openbanking.domain.account.FRFinancialAccount)

Aggregations

FRAccountData (com.forgerock.openbanking.common.model.data.FRAccountData)1 FRCustomerInfo (com.forgerock.openbanking.common.model.data.FRCustomerInfo)1 FRUserData (com.forgerock.openbanking.common.model.data.FRUserData)1 FRFinancialAccount (com.forgerock.openbanking.common.model.openbanking.domain.account.FRFinancialAccount)1 FRPartyData (com.forgerock.openbanking.common.model.openbanking.domain.account.FRPartyData)1 FRPartyConverter.toFRPartyData (com.forgerock.openbanking.common.services.openbanking.converter.account.FRPartyConverter.toFRPartyData)1