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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations