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