use of com.forgerock.openbanking.common.model.data.FRCustomerInfo 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.FRCustomerInfo 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.FRCustomerInfo in project openbanking-aspsp by OpenBankingToolkit.
the class RCSCustomerInfoDetailsApiTest method shouldReturnCustomerInfoDetails.
@Test
public void shouldReturnCustomerInfoDetails() throws OBErrorException {
FRAccountAccessConsent frAccountAccessConsent = JMockData.mock(FRAccountAccessConsent.class);
frAccountAccessConsent.setConsentId(IntentType.CUSTOMER_INFO_CONSENT.generateIntentId());
FRCustomerInfo customerInfo = JMockData.mock(FRCustomerInfo.class);
given(tppStoreService.findById(frAccountAccessConsent.getAispId())).willReturn(Optional.of(Tpp.builder().clientId(frAccountAccessConsent.getClientId()).build()));
given(accountRequestStoreService.get(any())).willReturn(Optional.ofNullable(frAccountAccessConsent));
given(customerInfoRepository.findByUserID(any())).willReturn(customerInfo);
ResponseEntity<CustomerInfoConsentDetails> response = api.consentDetails("asdfas", Collections.EMPTY_LIST, frAccountAccessConsent.getUserId(), frAccountAccessConsent.getConsentId(), frAccountAccessConsent.getClientId());
CustomerInfoConsentDetails details = response.getBody();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(details.getCustomerInfo()).isNotNull();
}
use of com.forgerock.openbanking.common.model.data.FRCustomerInfo in project openbanking-aspsp by OpenBankingToolkit.
the class RCSCustomerInfoDetailsApi method consentDetails.
@Override
public ResponseEntity consentDetails(String remoteConsentRequest, List<AccountWithBalance> accounts, String username, String consentId, String clientId) throws OBErrorException {
log.debug("Received a Customer info account consent request with consent_request='{}'", remoteConsentRequest);
log.debug("=> The Customer info account consent id '{}'", consentId);
Optional<AccountRequest> isCustomerInfoConsent = accountRequestStoreService.get(consentId);
if (!isCustomerInfoConsent.isPresent()) {
log.error("The AISP '{}' is referencing an customer info account request {} that doesn't exist", clientId, consentId);
return rcsErrorService.error(OBRIErrorType.RCS_CONSENT_REQUEST_UNKNOWN_ACCOUNT_REQUEST, clientId, consentId);
}
FRAccountAccessConsent customerInfoAccountConsent = (FRAccountAccessConsent) isCustomerInfoConsent.get();
// Verify the aisp is the same than the one that created this customer info accountRequest ^
if (!clientId.equals(customerInfoAccountConsent.getClientId())) {
log.error("The AISP '{}' created the customer info account request '{}' but it's AISP '{}' that is " + "trying to get consent for it.", customerInfoAccountConsent.getClientId(), consentId, clientId);
return rcsErrorService.error(OBRIErrorType.RCS_CONSENT_REQUEST_INVALID_CONSENT, customerInfoAccountConsent.getClientId(), clientId, consentId);
}
Optional<Tpp> isTpp = tppStoreService.findById(customerInfoAccountConsent.getAispId());
if (!isTpp.isPresent()) {
log.error("The TPP '{}' (Client ID {}) that created this customer info account consent id '{}' " + "doesn't exist anymore.", customerInfoAccountConsent.getAispId(), clientId, customerInfoAccountConsent.getId());
return rcsErrorService.error(OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, customerInfoAccountConsent.getId());
}
Tpp tpp = isTpp.get();
log.debug("Populate the customer info model with details data");
customerInfoAccountConsent.setUserId(username);
accountRequestStoreService.save(customerInfoAccountConsent);
log.debug("Populate the model with the customer info and consent data");
log.debug("get the customer info to add it in account consent data.");
FRCustomerInfo customerInfo = customerInfoRepository.findByUserID(username);
log.debug("customer info data {}", customerInfo);
if (customerInfo == null) {
return rcsErrorService.invalidConsentError(remoteConsentRequest, new OBErrorException(OBRIErrorType.CUSTOMER_INFO_NOT_FOUND));
}
customerInfoAccountConsent.setCustomerInfo(customerInfo);
log.debug("customer info to added in account consent data {}", consentId);
return ok(CustomerInfoConsentDetails.builder().username(username).merchantName(customerInfoAccountConsent.getAispName()).logo(tpp.getLogo()).clientId(clientId).customerInfo(customerInfoAccountConsent.getCustomerInfo()).build());
}
use of com.forgerock.openbanking.common.model.data.FRCustomerInfo 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);
}
Aggregations