use of com.forgerock.openbanking.common.model.openbanking.domain.account.FRPartyData 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