Search in sources :

Example 1 with FRUserData

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

the class FakeDataApiController method generateFakeData.

@Override
public ResponseEntity generateFakeData(@RequestParam("userId") String userId, @RequestParam("username") String username, @RequestParam(name = "profile", required = false) String profile) throws OBErrorException {
    log.debug("generateFakeData called for userId/username '{}:{}', with profile '{}' ", userId, username, profile);
    if (RANDOM_PROFILE_ID.equals(profile)) {
        log.debug("generateFakeData() generating random data");
        return ResponseEntity.status(HttpStatus.CREATED).body(generateRandomData(userId, username));
    } else {
        log.debug("generateFakeData() generating from profile '{}'", profile);
        Optional<DataConfigurationProperties.DataTemplateProfile> any = dataConfig.getProfiles().stream().filter(t -> t.getId().equals(profile)).findAny();
        if (!any.isPresent()) {
            throw new OBErrorException(OBRIErrorType.DATA_INVALID_REQUEST, "Profile '" + profile + "' doesn't exist.");
        }
        DataConfigurationProperties.DataTemplateProfile dataTemplateProfile = any.get();
        FRUserData template = getTemplate(dataTemplateProfile.getTemplate(), username);
        template.setUserName(username);
        return dataController.importUserData(template);
    }
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) FRStatementRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.statements.FRStatementRepository) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) BigDecimal(java.math.BigDecimal) FRCustomerInfo(com.forgerock.openbanking.common.model.data.FRCustomerInfo) OBReadProduct2DataProduct(uk.org.openbanking.datamodel.account.OBReadProduct2DataProduct) FRCreditDebitIndicator(com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator) DataConfigurationProperties(com.forgerock.openbanking.common.conf.data.DataConfigurationProperties) FRBeneficiaryRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.beneficiaries.FRBeneficiaryRepository) FRStandingOrderRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.standingorders.FRStandingOrderRepository) FRAccountSubTypeCode(com.forgerock.openbanking.common.model.openbanking.domain.account.FRFinancialAccount.FRAccountSubTypeCode) FRBalanceType(com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRBalanceType) com.forgerock.openbanking.common.model.openbanking.domain.account(com.forgerock.openbanking.common.model.openbanking.domain.account) Resource(org.springframework.core.io.Resource) RoundingMode(java.math.RoundingMode) DateTimeFormat(org.joda.time.format.DateTimeFormat) FRScheduledPaymentRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.scheduledpayments.FRScheduledPaymentRepository) FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) FRProductRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.products.FRProductRepository) Slf4j(lombok.extern.slf4j.Slf4j) FROfferRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.offers.FROfferRepository) OBExternalStatementAmountType1Code(uk.org.openbanking.datamodel.account.OBExternalStatementAmountType1Code) FRBalanceRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.balances.FRBalanceRepository) FRStatementType(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStatementData.FRStatementType) FRDirectDebitStatus(com.forgerock.openbanking.common.model.openbanking.domain.account.FRDirectDebitData.FRDirectDebitStatus) java.util(java.util) FRCustomerInfoAddress(com.forgerock.openbanking.common.model.data.FRCustomerInfoAddress) ClassPathResource(org.springframework.core.io.ClassPathResource) Controller(org.springframework.stereotype.Controller) ScheduledPaymentStatus(com.forgerock.openbanking.common.model.openbanking.status.ScheduledPaymentStatus) NumberFormat(java.text.NumberFormat) OBExternalAccountIdentification4Code(uk.org.openbanking.datamodel.account.OBExternalAccountIdentification4Code) Charset(java.nio.charset.Charset) FRDirectDebitRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.directdebits.FRDirectDebitRepository) FRPartyRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.party.FRPartyRepository) FRAddressTypeCode(com.forgerock.openbanking.common.model.data.FRAddressTypeCode) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) OBExternalAccountIdentification2Code(uk.org.openbanking.datamodel.payment.OBExternalAccountIdentification2Code) FRAccountTypeCode(com.forgerock.openbanking.common.model.openbanking.domain.account.FRFinancialAccount.FRAccountTypeCode) com.forgerock.openbanking.common.model.openbanking.persistence.account(com.forgerock.openbanking.common.model.openbanking.persistence.account) StreamUtils(org.springframework.util.StreamUtils) Logger(org.slf4j.Logger) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FRAccountRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.accounts.FRAccountRepository) DateTime(org.joda.time.DateTime) DecimalFormat(java.text.DecimalFormat) FRUserData(com.forgerock.openbanking.common.model.data.FRUserData) FRAccountStatusCode(com.forgerock.openbanking.common.model.openbanking.domain.account.FRFinancialAccount.FRAccountStatusCode) FRCustomerInfoRepository(com.forgerock.openbanking.common.repositories.customerinfo.FRCustomerInfoRepository) OBRIErrorType(com.forgerock.openbanking.model.error.OBRIErrorType) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) LocalDate(org.joda.time.LocalDate) FRStandingOrderStatus(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData.FRStandingOrderStatus) HttpStatus(org.springframework.http.HttpStatus) FRTransactionRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.transactions.FRTransactionRepository) ResponseEntity(org.springframework.http.ResponseEntity) BufferedReader(java.io.BufferedReader) InputStream(java.io.InputStream) FRUserData(com.forgerock.openbanking.common.model.data.FRUserData) DataConfigurationProperties(com.forgerock.openbanking.common.conf.data.DataConfigurationProperties) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException)

Example 2 with FRUserData

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

the class UserDataService method generateUserData.

public FRUserData generateUserData(String userId, String profile) {
    LOGGER.debug("Generate data for user {}", userId);
    HttpEntity request = new HttpEntity<>(null, new HttpHeaders());
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(rsStoreRoot + "/api/fake-data/generate");
    builder.queryParam("userId", userId);
    builder.queryParam("username", userId);
    builder.queryParam("profile", profile);
    URI uri = builder.build().encode().toUri();
    return restTemplate.exchange(uri, HttpMethod.POST, request, FRUserData.class).getBody();
}
Also used : FRUserData(com.forgerock.openbanking.common.model.data.FRUserData) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) URI(java.net.URI)

Example 3 with FRUserData

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

the class UserDataService method updateUserData.

public FRUserData updateUserData(FRUserData userData) {
    LOGGER.debug("Update data for w user {}", userData);
    HttpEntity request = new HttpEntity<>(userData, new HttpHeaders());
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(rsStoreRoot + "/api/data/user");
    URI uri = builder.build().encode().toUri();
    return restTemplate.exchange(uri, HttpMethod.PUT, request, FRUserData.class).getBody();
}
Also used : FRUserData(com.forgerock.openbanking.common.model.data.FRUserData) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) URI(java.net.URI)

Example 4 with FRUserData

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

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

Aggregations

FRUserData (com.forgerock.openbanking.common.model.data.FRUserData)13 FRAccountData (com.forgerock.openbanking.common.model.data.FRAccountData)6 Test (org.junit.Test)6 FRCustomerInfo (com.forgerock.openbanking.common.model.data.FRCustomerInfo)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 OBAccount6 (uk.org.openbanking.datamodel.account.OBAccount6)5 OBCashBalance1 (uk.org.openbanking.datamodel.account.OBCashBalance1)5 URI (java.net.URI)4 HttpEntity (org.springframework.http.HttpEntity)4 HttpHeaders (org.springframework.http.HttpHeaders)4 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)4 FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 FRAccountRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.accounts.FRAccountRepository)1 FRBalanceRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.balances.FRBalanceRepository)1 FRBeneficiaryRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.beneficiaries.FRBeneficiaryRepository)1 FRDirectDebitRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.directdebits.FRDirectDebitRepository)1 FROfferRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.offers.FROfferRepository)1 FRPartyRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.party.FRPartyRepository)1 FRProductRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.products.FRProductRepository)1