Search in sources :

Example 6 with FRCustomerInfo

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

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));
}
Also used : FRUserData(com.forgerock.openbanking.common.model.data.FRUserData) FRCustomerInfo(com.forgerock.openbanking.common.model.data.FRCustomerInfo) Test(org.junit.Test)

Example 8 with FRCustomerInfo

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();
}
Also used : FRAccountAccessConsent(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccountAccessConsent) CustomerInfoConsentDetails(com.forgerock.openbanking.common.model.rcs.consentdetails.CustomerInfoConsentDetails) FRCustomerInfo(com.forgerock.openbanking.common.model.data.FRCustomerInfo) Test(org.junit.Test)

Example 9 with FRCustomerInfo

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());
}
Also used : FRAccountAccessConsent(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccountAccessConsent) AccountRequest(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountRequest) Tpp(com.forgerock.openbanking.model.Tpp) FRCustomerInfo(com.forgerock.openbanking.common.model.data.FRCustomerInfo) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException)

Example 10 with FRCustomerInfo

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

Aggregations

FRCustomerInfo (com.forgerock.openbanking.common.model.data.FRCustomerInfo)12 Test (org.junit.Test)5 FRUserData (com.forgerock.openbanking.common.model.data.FRUserData)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ReadCustomerInfo (uk.org.openbanking.datamodel.customerinfo.ReadCustomerInfo)3 FRAccountData (com.forgerock.openbanking.common.model.data.FRAccountData)2 FRAccountAccessConsent (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccountAccessConsent)2 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)2 CustomerInfo (uk.org.openbanking.datamodel.customerinfo.CustomerInfo)2 FRCustomerInfoAddress (com.forgerock.openbanking.common.model.data.FRCustomerInfoAddress)1 FRFinancialAccount (com.forgerock.openbanking.common.model.openbanking.domain.account.FRFinancialAccount)1 FRPartyData (com.forgerock.openbanking.common.model.openbanking.domain.account.FRPartyData)1 AccountRequest (com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountRequest)1 CustomerInfoConsentDetails (com.forgerock.openbanking.common.model.rcs.consentdetails.CustomerInfoConsentDetails)1 FRPartyConverter.toFRPartyData (com.forgerock.openbanking.common.services.openbanking.converter.account.FRPartyConverter.toFRPartyData)1 OBErrorException (com.forgerock.openbanking.exceptions.OBErrorException)1 Tpp (com.forgerock.openbanking.model.Tpp)1 DateTime (org.joda.time.DateTime)1 ResponseEntity (org.springframework.http.ResponseEntity)1 ResponseStatusException (org.springframework.web.server.ResponseStatusException)1