Search in sources :

Example 1 with FRAccountData

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

the class DataApiController method updateUserData.

@Override
public ResponseEntity updateUserData(@RequestBody FRUserData userData) {
    if (rsConfiguration.isCustomerInfoEnabled()) {
        dataUpdater.updateCustomerInfo(userData);
    }
    dataUpdater.updateParty(userData);
    Set<String> accountIds = accountsRepository.findByUserID(userData.getUserName()).stream().map(FRAccount::getId).collect(Collectors.toSet());
    for (FRAccountData accountDataDiff : userData.getAccountDatas()) {
        String accountId = accountDataDiff.getAccount().getAccountId();
        // Account
        Optional<FRAccount> isAccount = accountsRepository.findById(accountId);
        if (isAccount.isEmpty()) {
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Account ID '" + accountId + "' doesn't exist");
        }
        FRAccount account = isAccount.get();
        if (!account.getUserID().equals(userData.getUserName())) {
            return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Account ID '" + accountDataDiff.getAccount().getAccountId() + "' is not owned by user '" + userData.getUserName() + "'");
        }
        dataUpdater.updateAccount(accountDataDiff, account, accountIds);
        dataUpdater.updateBalances(accountDataDiff, accountIds);
        dataUpdater.updateProducts(accountDataDiff, accountIds);
        dataUpdater.updateParty(accountDataDiff, accountIds);
        dataUpdater.updateBeneficiaries(accountDataDiff, accountIds);
        dataUpdater.updateDirectDebits(accountDataDiff, accountIds);
        dataUpdater.updateStandingOrders(accountDataDiff, accountIds);
        dataUpdater.updateTransactions(accountDataDiff, accountIds);
        dataUpdater.updateStatements(accountDataDiff, accountIds);
        dataUpdater.updateScheduledPayments(accountDataDiff, accountIds);
        dataUpdater.updateOffers(accountDataDiff, accountIds);
    }
    return exportUserData(userData.getUserName());
}
Also used : FRAccountData(com.forgerock.openbanking.common.model.data.FRAccountData)

Example 2 with FRAccountData

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

the class DataApiControllerIT method shouldCreateNewDataUsingUpdate.

@Test
public void shouldCreateNewDataUsingUpdate() 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());
    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().isOk());
}
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 3 with FRAccountData

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

the class DataApiControllerIT method shouldReturnPayloadTooLargeWhenCreatingNewData.

@Test
public void shouldReturnPayloadTooLargeWhenCreatingNewData() 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(), new OBCashBalance1())).build());
    FRUserData userData = new FRUserData();
    userData.setAccountDatas(accountDatas);
    userData.setUserName(UUID.randomUUID().toString());
    // When
    mockMvc.perform(post("/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) 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 4 with FRAccountData

use of com.forgerock.openbanking.common.model.data.FRAccountData 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 5 with FRAccountData

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

Aggregations

FRAccountData (com.forgerock.openbanking.common.model.data.FRAccountData)43 Test (org.junit.Test)38 List (java.util.List)8 FRUserData (com.forgerock.openbanking.common.model.data.FRUserData)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 OBAccount6 (uk.org.openbanking.datamodel.account.OBAccount6)5 OBCashBalance1 (uk.org.openbanking.datamodel.account.OBCashBalance1)5 FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)3 FRCustomerInfo (com.forgerock.openbanking.common.model.data.FRCustomerInfo)2 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 Page (org.springframework.data.domain.Page)1