Search in sources :

Example 6 with FRUserData

use of com.forgerock.openbanking.common.model.data.FRUserData in project openbanking-aspsp by OpenBankingToolkit.

the class DataApiControllerIT method shouldReturnPayloadTooLargeWhenCreatingNewDataUsingUpdate.

@Test
public void shouldReturnPayloadTooLargeWhenCreatingNewDataUsingUpdate() throws Exception {
    // Given
    OBAccount6 account = new OBAccount6().accountId(UUID.randomUUID().toString());
    List<FRAccountData> accountDatas = Collections.singletonList(FRAccountData.builder().account(account).balances(Arrays.asList(new OBCashBalance1().type(OBBalanceType1Code.INTERIMAVAILABLE), new OBCashBalance1().type(OBBalanceType1Code.INTERIMBOOKED))).build());
    FRAccount savedAccount = frAccountRepository.save(FRAccount.builder().id(account.getAccountId()).userID(UUID.randomUUID().toString()).build());
    FRUserData userData = new FRUserData();
    userData.setAccountDatas(accountDatas);
    userData.setUserName(savedAccount.getUserID());
    // When
    mockMvc.perform(put("/api/data/user").content(mapper.writeValueAsString(userData)).contentType("application/json")).andExpect(status().isPayloadTooLarge());
}
Also used : FRUserData(com.forgerock.openbanking.common.model.data.FRUserData) OBCashBalance1(uk.org.openbanking.datamodel.account.OBCashBalance1) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRAccountData(com.forgerock.openbanking.common.model.data.FRAccountData) OBAccount6(uk.org.openbanking.datamodel.account.OBAccount6) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with FRUserData

use of com.forgerock.openbanking.common.model.data.FRUserData in project openbanking-aspsp by OpenBankingToolkit.

the class DataApiControllerIT method shouldCreateNewData.

@Test
public void shouldCreateNewData() throws Exception {
    // Given
    OBAccount6 account = new OBAccount6().accountId(UUID.randomUUID().toString());
    List<FRAccountData> accountDatas = Collections.singletonList(FRAccountData.builder().account(account).balances(Collections.singletonList(new OBCashBalance1())).build());
    FRCustomerInfo frCustomerInfo = FRCustomerInfoTestHelper.aValidFRCustomerInfo();
    FRUserData userData = new FRUserData();
    userData.setAccountDatas(accountDatas);
    userData.setUserName(UUID.randomUUID().toString());
    frCustomerInfo.setUserID(UUID.randomUUID().toString());
    userData.setCustomerInfo(frCustomerInfo);
    // When
    mockMvc.perform(post("/api/data/user").content(mapper.writeValueAsString(userData)).contentType("application/json")).andExpect(status().isOk());
}
Also used : FRUserData(com.forgerock.openbanking.common.model.data.FRUserData) OBCashBalance1(uk.org.openbanking.datamodel.account.OBCashBalance1) FRCustomerInfo(com.forgerock.openbanking.common.model.data.FRCustomerInfo) FRAccountData(com.forgerock.openbanking.common.model.data.FRAccountData) OBAccount6(uk.org.openbanking.datamodel.account.OBAccount6) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with FRUserData

use of com.forgerock.openbanking.common.model.data.FRUserData in project openbanking-aspsp by OpenBankingToolkit.

the class DataUpdaterTest method updateCustomerInfoShouldThrowIfIDsDontMatch.

@Test
public void updateCustomerInfoShouldThrowIfIDsDontMatch() {
    // Given
    FRCustomerInfo newCustomerInfo = FRCustomerInfoTestHelper.aValidFRCustomerInfo();
    FRCustomerInfo existingCustomerInfo = FRCustomerInfoTestHelper.aValidFRCustomerInfo();
    existingCustomerInfo.setId(UUID.randomUUID().toString());
    FRUserData userData = new FRUserData();
    userData.setUserName(newCustomerInfo.getUserID());
    userData.setCustomerInfo(newCustomerInfo);
    given(customerInfoRepository.findByUserID(newCustomerInfo.getUserID())).willReturn(existingCustomerInfo);
    assertThatThrownBy(// When
    () -> dataUpdater.updateCustomerInfo(userData)).satisfies(t -> assertThat(((ResponseStatusException) t).getStatus()).isEqualTo(HttpStatus.UNAUTHORIZED));
}
Also used : FRUserData(com.forgerock.openbanking.common.model.data.FRUserData) FRCustomerInfo(com.forgerock.openbanking.common.model.data.FRCustomerInfo) Test(org.junit.Test)

Example 9 with FRUserData

use of com.forgerock.openbanking.common.model.data.FRUserData 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)

Example 10 with FRUserData

use of com.forgerock.openbanking.common.model.data.FRUserData in project openbanking-aspsp by OpenBankingToolkit.

the class DataApiController method exportUserData.

@Override
public ResponseEntity<FRUserData> exportUserData(@RequestParam("userId") String userId) {
    FRUserData userData = new FRUserData(userId);
    for (FRAccount account : accountsRepository.findByUserID(userId)) {
        userData.addAccountData(getAccount(account));
    }
    FRCustomerInfo customerInfo = customerInfoRepository.findByUserID(userId);
    userData.setCustomerInfo(customerInfo);
    FRParty byUserId = partyRepository.findByUserId(userId);
    if (byUserId != null) {
        userData.setParty(toOBParty2(byUserId.getParty()));
    }
    return ResponseEntity.ok(userData);
}
Also used : FRUserData(com.forgerock.openbanking.common.model.data.FRUserData) FRCustomerInfo(com.forgerock.openbanking.common.model.data.FRCustomerInfo)

Aggregations

FRUserData (com.forgerock.openbanking.common.model.data.FRUserData)13 FRAccountData (com.forgerock.openbanking.common.model.data.FRAccountData)6 Test (org.junit.Test)6 FRCustomerInfo (com.forgerock.openbanking.common.model.data.FRCustomerInfo)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 OBAccount6 (uk.org.openbanking.datamodel.account.OBAccount6)5 OBCashBalance1 (uk.org.openbanking.datamodel.account.OBCashBalance1)5 URI (java.net.URI)4 HttpEntity (org.springframework.http.HttpEntity)4 HttpHeaders (org.springframework.http.HttpHeaders)4 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)4 FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 FRAccountRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.accounts.FRAccountRepository)1 FRBalanceRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.balances.FRBalanceRepository)1 FRBeneficiaryRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.beneficiaries.FRBeneficiaryRepository)1 FRDirectDebitRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.directdebits.FRDirectDebitRepository)1 FROfferRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.offers.FROfferRepository)1 FRPartyRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.party.FRPartyRepository)1 FRProductRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.products.FRProductRepository)1