mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 13:26:51 +00:00
Merge pull request #138 from pbozin/develop
Fixes #117 and #81 - Account Label is now stored in mapper
This commit is contained in:
commit
500a53e6c0
4
mvn.sh
4
mvn.sh
@ -1,5 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m -Xms512m"
|
||||
# Deprecated option -XX:MaxPermSize=256m is kept
|
||||
# just in case someone still uses java 1.7
|
||||
export MAVEN_OPTS="-Xmx1024m -Xms1024m -Xss1024k -XX:MaxPermSize=256m"
|
||||
|
||||
mvn $1 $2 $3 $4
|
||||
|
||||
6
pom.xml
6
pom.xml
@ -121,6 +121,12 @@
|
||||
<version>9.2.15.v20160210</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.manub</groupId>
|
||||
<artifactId>scalatest-embedded-kafka_${scala.version}</artifactId>
|
||||
<version>0.7.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.liftweb</groupId>
|
||||
<artifactId>lift-mongodb_${scala.version}</artifactId>
|
||||
|
||||
@ -422,5 +422,6 @@ object ToSchemify {
|
||||
MappedTransactionType,
|
||||
MappedMeeting,
|
||||
MappedUserCustomerLink,
|
||||
MappedKafkaBankAccountData,
|
||||
MappedEntitlement)
|
||||
}
|
||||
|
||||
@ -1002,8 +1002,8 @@ trait APIMethods200 {
|
||||
|
|
||||
|If USER_ID is not specified the account will be owned by the logged in User.
|
||||
|
|
||||
|Note: Type is currently ignored and the Amount must be zero. You can update the account label with another call (see 1_2_1-updateAccountLabel)""".stripMargin,
|
||||
Extraction.decompose(CreateAccountJSON("A user_id","CURRENT", AmountOfMoneyJSON121("EUR", "0"))),
|
||||
|Note: The Amount must be zero.""".stripMargin,
|
||||
Extraction.decompose(CreateAccountJSON("A user_id","CURRENT", "Label", AmountOfMoneyJSON121("EUR", "0"))),
|
||||
emptyObjectJson,
|
||||
emptyObjectJson :: Nil,
|
||||
false,
|
||||
@ -1035,13 +1035,14 @@ trait APIMethods200 {
|
||||
isAllowed <- booleanToBox(hasEntitlement(bankId.value, loggedInUser.userId, CanCreateAccount) == true || (user_id == loggedInUser.userId) , s"User must either create account for self or have role $CanCreateAccount")
|
||||
initialBalanceAsString <- tryo (jsonBody.balance.amount) ?~ ErrorMessages.InvalidAccountBalanceAmount
|
||||
accountType <- tryo(jsonBody.`type`) ?~ ErrorMessages.InvalidAccountType
|
||||
accountLabel <- tryo(jsonBody.`type`) //?~ ErrorMessages.InvalidAccountLabel
|
||||
initialBalanceAsNumber <- tryo {BigDecimal(initialBalanceAsString)} ?~! ErrorMessages.InvalidAccountInitalBalance
|
||||
isTrue <- booleanToBox(0 == initialBalanceAsNumber) ?~ s"Initial balance must be zero"
|
||||
currency <- tryo (jsonBody.balance.currency) ?~ ErrorMessages.InvalidAccountBalanceCurrency
|
||||
// TODO Since this is a PUT, we should replace the resource if it already exists but will need to check persmissions
|
||||
accountDoesNotExist <- booleanToBox(BankAccount(bankId, accountId).isEmpty,
|
||||
s"Account with id $accountId already exists at bank $bankId")
|
||||
bankAccount <- Connector.connector.vend.createSandboxBankAccount(bankId, accountId, currency, initialBalanceAsNumber, postedOrLoggedInUser.name)
|
||||
bankAccount <- Connector.connector.vend.createSandboxBankAccount(bankId, accountId, accountType, accountLabel, currency, initialBalanceAsNumber, postedOrLoggedInUser.name)
|
||||
} yield {
|
||||
BankAccountCreation.setAsOwner(bankId, accountId, postedOrLoggedInUser)
|
||||
|
||||
|
||||
@ -35,16 +35,16 @@ import java.net.URL
|
||||
import java.util.Date
|
||||
|
||||
import code.TransactionTypes.TransactionType.TransactionType
|
||||
import code.meetings.Meeting
|
||||
import code.entitlement.Entitlement
|
||||
import code.meetings.Meeting
|
||||
import code.model.dataAccess.OBPUser
|
||||
import code.transactionrequests.TransactionRequests._
|
||||
import net.liftweb.common.{Full, Box}
|
||||
import net.liftweb.common.{Box, Full}
|
||||
|
||||
// import code.api.util.APIUtil.ApiLink
|
||||
|
||||
import code.api.v1_2_1.{AmountOfMoneyJSON, JSONFactory => JSONFactory121, MinimalBankJSON => MinimalBankJSON121, OtherAccountJSON => OtherAccountJSON121, ThisAccountJSON => ThisAccountJSON121, TransactionDetailsJSON => TransactionDetailsJSON121, UserJSON => UserJSON121, ViewJSON => ViewJSON121}
|
||||
import code.api.v1_4_0.JSONFactory1_4_0.{CustomerFaceImageJson, ChallengeJSON, TransactionRequestAccountJSON}
|
||||
import code.api.v1_4_0.JSONFactory1_4_0.{ChallengeJSON, CustomerFaceImageJson, TransactionRequestAccountJSON}
|
||||
import code.kycchecks.KycCheck
|
||||
import code.kycdocuments.KycDocument
|
||||
import code.kycmedias.KycMedia
|
||||
@ -143,6 +143,7 @@ case class BasicAccountJSON(
|
||||
// Json used in account creation
|
||||
case class CreateAccountJSON(
|
||||
user_id : String,
|
||||
label : String,
|
||||
`type` : String,
|
||||
balance : AmountOfMoneyJSON
|
||||
)
|
||||
|
||||
@ -8,7 +8,6 @@ import code.api.util.ErrorMessages
|
||||
import code.fx.fx
|
||||
import code.management.ImporterAPI.ImporterTransaction
|
||||
import code.model.{OtherBankAccount, Transaction, User, _}
|
||||
import code.tesobe.CashTransaction
|
||||
import code.transactionrequests.TransactionRequests
|
||||
import code.transactionrequests.TransactionRequests._
|
||||
import code.util.Helper._
|
||||
@ -522,10 +521,11 @@ trait Connector {
|
||||
*/
|
||||
|
||||
//creates a bank account (if it doesn't exist) and creates a bank (if it doesn't exist)
|
||||
def createBankAndAccount(bankName : String, bankNationalIdentifier : String, accountNumber : String, accountHolderName : String) : (Bank, BankAccount)
|
||||
def createBankAndAccount(bankName : String, bankNationalIdentifier : String, accountNumber : String,
|
||||
accountType: String, accountLabel:String, currency: String, accountHolderName : String) : (Bank, BankAccount)
|
||||
|
||||
//generates an unused account number and then creates the sandbox account using that number
|
||||
def createSandboxBankAccount(bankId : BankId, accountId : AccountId, currency : String, initialBalance : BigDecimal, accountHolderName : String) : Box[BankAccount] = {
|
||||
def createSandboxBankAccount(bankId : BankId, accountId : AccountId, accountType: String, accountLabel: String, currency : String, initialBalance : BigDecimal, accountHolderName : String) : Box[BankAccount] = {
|
||||
val uniqueAccountNumber = {
|
||||
def exists(number : String) = Connector.connector.vend.accountExists(bankId, number)
|
||||
|
||||
@ -540,12 +540,23 @@ trait Connector {
|
||||
appendUntilOkay(firstTry)
|
||||
}
|
||||
|
||||
createSandboxBankAccount(bankId, accountId, uniqueAccountNumber, currency, initialBalance, accountHolderName)
|
||||
createSandboxBankAccount(
|
||||
bankId,
|
||||
accountId,
|
||||
uniqueAccountNumber,
|
||||
accountType,
|
||||
accountLabel,
|
||||
currency,
|
||||
initialBalance,
|
||||
accountHolderName
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
//creates a bank account for an existing bank, with the appropriate values set. Can fail if the bank doesn't exist
|
||||
def createSandboxBankAccount(bankId : BankId, accountId : AccountId, accountNumber: String,
|
||||
currency : String, initialBalance : BigDecimal, accountHolderName : String) : Box[BankAccount]
|
||||
accountType: String, accountLabel: String, currency : String,
|
||||
initialBalance : BigDecimal, accountHolderName : String) : Box[BankAccount]
|
||||
|
||||
//sets a user as an account owner/holder
|
||||
def setAccountHolder(bankAccountUID: BankAccountUID, user : User) : Unit
|
||||
|
||||
@ -289,6 +289,8 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
|
||||
val acc = List((bankId, accountID)).toSet
|
||||
if ((accResp diff acc).size > 0) throw new Exception(ErrorMessages.InvalidGetBankAccountConnectorResponse)
|
||||
|
||||
createMappedAccountDataIfNotExisting(r.bank, r.id, r.label)
|
||||
|
||||
Full(new KafkaBankAccount(r))
|
||||
}
|
||||
|
||||
@ -311,7 +313,9 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
|
||||
}
|
||||
if ((accRes.toSet diff accts.toSet).size > 0) throw new Exception(ErrorMessages.InvalidGetBankAccountsConnectorResponse)
|
||||
|
||||
r.map { t => new KafkaBankAccount(t) }
|
||||
r.map { t =>
|
||||
createMappedAccountDataIfNotExisting(t.bank, t.id, t.label)
|
||||
new KafkaBankAccount(t) }
|
||||
}
|
||||
|
||||
private def getAccountByNumber(bankId : BankId, number : String) : Box[AccountType] = {
|
||||
@ -327,6 +331,7 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
|
||||
val r = {
|
||||
cachedAccount.getOrElseUpdate( argList.toString, () => process(reqId, "getBankAccount", argList).extract[KafkaInboundAccount])
|
||||
}
|
||||
createMappedAccountDataIfNotExisting(r.bank, r.id, r.label)
|
||||
Full(new KafkaBankAccount(r))
|
||||
}
|
||||
|
||||
@ -563,9 +568,10 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
|
||||
|
||||
//creates a bank account (if it doesn't exist) and creates a bank (if it doesn't exist)
|
||||
//again assume national identifier is unique
|
||||
override def createBankAndAccount(bankName: String, bankNationalIdentifier: String, accountNumber: String, accountHolderName: String): (Bank, BankAccount) = {
|
||||
override def createBankAndAccount(bankName: String, bankNationalIdentifier: String, accountNumber: String,
|
||||
accountType: String, accountLabel: String, currency: String, accountHolderName: String): (Bank, BankAccount) = {
|
||||
//don't require and exact match on the name, just the identifier
|
||||
val bank = MappedBank.find(By(MappedBank.national_identifier, bankNationalIdentifier)) match {
|
||||
val bank: Bank = MappedBank.find(By(MappedBank.national_identifier, bankNationalIdentifier)) match {
|
||||
case Full(b) =>
|
||||
logger.info(s"bank with id ${b.bankId} and national identifier ${b.nationalIdentifier} found")
|
||||
b
|
||||
@ -581,7 +587,16 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
|
||||
}
|
||||
|
||||
//TODO: pass in currency as a parameter?
|
||||
val account = createAccountIfNotExisting(bank.bankId, AccountId(UUID.randomUUID().toString), accountNumber, "EUR", 0L, accountHolderName)
|
||||
val account = createAccountIfNotExisting(
|
||||
bank.bankId,
|
||||
AccountId(UUID.randomUUID().toString),
|
||||
accountNumber,
|
||||
accountType,
|
||||
accountLabel,
|
||||
currency,
|
||||
0L,
|
||||
accountHolderName
|
||||
)
|
||||
|
||||
(bank, account)
|
||||
}
|
||||
@ -661,14 +676,15 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
|
||||
|
||||
//creates a bank account for an existing bank, with the appropriate values set. Can fail if the bank doesn't exist
|
||||
override def createSandboxBankAccount(bankId: BankId, accountID: AccountId, accountNumber: String,
|
||||
currency: String, initialBalance: BigDecimal, accountHolderName: String): Box[BankAccount] = {
|
||||
accountType: String, accountLabel: String, currency: String,
|
||||
initialBalance: BigDecimal, accountHolderName: String): Box[BankAccount] = {
|
||||
|
||||
for {
|
||||
bank <- getBank(bankId) //bank is not really used, but doing this will ensure account creations fails if the bank doesn't
|
||||
} yield {
|
||||
|
||||
val balanceInSmallestCurrencyUnits = Helper.convertToSmallestCurrencyUnits(initialBalance, currency)
|
||||
createAccountIfNotExisting(bankId, accountID, accountNumber, currency, balanceInSmallestCurrencyUnits, accountHolderName)
|
||||
createAccountIfNotExisting(bankId, accountID, accountNumber, accountType, accountLabel, currency, balanceInSmallestCurrencyUnits, accountHolderName)
|
||||
}
|
||||
|
||||
}
|
||||
@ -679,7 +695,8 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
|
||||
}
|
||||
|
||||
private def createAccountIfNotExisting(bankId: BankId, accountID: AccountId, accountNumber: String,
|
||||
currency: String, balanceInSmallestCurrencyUnits: Long, accountHolderName: String) : BankAccount = {
|
||||
accountType: String, accountLabel: String, currency: String,
|
||||
balanceInSmallestCurrencyUnits: Long, accountHolderName: String) : BankAccount = {
|
||||
getBankAccount(bankId, accountID) match {
|
||||
case Full(a) =>
|
||||
logger.info(s"account with id $accountID at bank with id $bankId already exists. No need to create a new one.")
|
||||
@ -690,6 +707,8 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
|
||||
.bank(bankId.value)
|
||||
.theAccountId(accountID.value)
|
||||
.accountNumber(accountNumber)
|
||||
.accountType(accountType)
|
||||
.accountLabel(accountLabel)
|
||||
.accountCurrency(currency)
|
||||
.accountBalance(balanceInSmallestCurrencyUnits)
|
||||
.holder(accountHolderName)
|
||||
@ -698,17 +717,26 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
|
||||
}
|
||||
}
|
||||
|
||||
private def createMappedAccountDataIfNotExisting(bankId: String, accountId: String, label: String) : Boolean = {
|
||||
MappedKafkaBankAccountData.find(By(MappedKafkaBankAccountData.accountId, accountId),
|
||||
By(MappedKafkaBankAccountData.bankId, bankId)) match {
|
||||
case Empty =>
|
||||
val data = new MappedKafkaBankAccountData
|
||||
data.setAccountId(accountId)
|
||||
data.setBankId(bankId)
|
||||
data.setLabel(label)
|
||||
data.save()
|
||||
true
|
||||
case _ =>
|
||||
logger.info(s"account data with id $accountId at bank with id $bankId already exists. No need to create a new one.")
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
End of bank account creation
|
||||
*/
|
||||
|
||||
/*
|
||||
Cash api
|
||||
*/
|
||||
|
||||
/*
|
||||
End of cash api
|
||||
*/
|
||||
|
||||
/*
|
||||
Transaction importer api
|
||||
@ -830,11 +858,11 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
|
||||
val result = for {
|
||||
acc <- getBankAccount(bankId, accountID)
|
||||
bank <- getBank(bankId)
|
||||
d <- MappedKafkaBankAccountData.find(By(MappedKafkaBankAccountData.accountId, accountID.value), By(MappedKafkaBankAccountData.bankId, bank.bankId.value))
|
||||
} yield {
|
||||
//acc.label = label
|
||||
true
|
||||
}
|
||||
|
||||
d.setLabel(label)
|
||||
d.save()
|
||||
}
|
||||
result.getOrElse(false)
|
||||
}
|
||||
|
||||
@ -936,13 +964,20 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
|
||||
def balance : BigDecimal = BigDecimal(r.balance.amount)
|
||||
def currency : String = r.balance.currency
|
||||
def name : String = r.owners.head
|
||||
def label : String = r.number // Temp (label should be writable so customer can change)
|
||||
def swift_bic : Option[String] = Some("swift_bic") //TODO
|
||||
def iban : Option[String] = Some(r.IBAN)
|
||||
def number : String = r.number
|
||||
def bankId : BankId = BankId(r.bank)
|
||||
def lastUpdate : Date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH).parse(today.getTime.toString)
|
||||
def accountHolder : String = r.owners.head
|
||||
|
||||
// Fields modifiable from OBP are stored in mapper
|
||||
def label : String = (for {
|
||||
d <- MappedKafkaBankAccountData.find(By(MappedKafkaBankAccountData.accountId, r.id))
|
||||
} yield {
|
||||
d.getLabel
|
||||
}).getOrElse(r.number)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@ import code.management.ImporterAPI.ImporterTransaction
|
||||
import code.metadata.counterparties.{Counterparties, Metadata, MongoCounterparties}
|
||||
import code.model._
|
||||
import code.model.dataAccess._
|
||||
import code.tesobe.CashTransaction
|
||||
import code.transactionrequests.TransactionRequests._
|
||||
import code.util.Helper
|
||||
import com.mongodb.QueryBuilder
|
||||
@ -23,7 +22,6 @@ import org.bson.types.ObjectId
|
||||
|
||||
import scala.concurrent.ExecutionContext.Implicits.global
|
||||
import scala.concurrent._
|
||||
import scala.math.BigDecimal.RoundingMode
|
||||
|
||||
private object LocalConnector extends Connector with Loggable {
|
||||
|
||||
@ -353,7 +351,8 @@ private object LocalConnector extends Connector with Loggable {
|
||||
}
|
||||
|
||||
//Need to pass in @hostedBank because the Account model doesn't have any references to BankId, just to the mongo id of the Bank object (which itself does have the bank id)
|
||||
private def createAccount(hostedBank : HostedBank, accountId : AccountId, accountNumber: String, currency : String, initialBalance : BigDecimal, holderName : String) : BankAccount = {
|
||||
private def createAccount(hostedBank : HostedBank, accountId : AccountId, accountNumber: String,
|
||||
accountType: String, accountLabel: String, currency : String, initialBalance : BigDecimal, holderName : String) : BankAccount = {
|
||||
import net.liftweb.mongodb.BsonDSL._
|
||||
Account.find(
|
||||
(Account.accountNumber.name -> accountNumber)~
|
||||
@ -371,11 +370,11 @@ private object LocalConnector extends Connector with Loggable {
|
||||
.accountBalance(initialBalance)
|
||||
.holder(holderName)
|
||||
.accountNumber(accountNumber)
|
||||
.kind("current")
|
||||
.kind(accountType)
|
||||
.accountLabel(accountLabel)
|
||||
.accountName("")
|
||||
.permalink(accountId.value)
|
||||
.bankID(hostedBank.id.is)
|
||||
.accountLabel("")
|
||||
.accountCurrency(currency)
|
||||
.accountIban("")
|
||||
.accountLastUpdate(now)
|
||||
@ -386,7 +385,7 @@ private object LocalConnector extends Connector with Loggable {
|
||||
}
|
||||
|
||||
//creates a bank account (if it doesn't exist) and creates a bank (if it doesn't exist)
|
||||
override def createBankAndAccount(bankName : String, bankNationalIdentifier : String, accountNumber : String, accountHolderName : String): (Bank, BankAccount) = {
|
||||
override def createBankAndAccount(bankName : String, bankNationalIdentifier : String, accountNumber : String, accountType: String, accountLabel: String, currency: String, accountHolderName : String): (Bank, BankAccount) = {
|
||||
|
||||
// TODO: use a more unique id for the long term
|
||||
val hostedBank = {
|
||||
@ -414,7 +413,7 @@ private object LocalConnector extends Connector with Loggable {
|
||||
}
|
||||
|
||||
val createdAccount = createAccount(hostedBank, AccountId(UUID.randomUUID().toString),
|
||||
accountNumber, "EUR", BigDecimal("0.00"), accountHolderName)
|
||||
accountNumber, accountType, accountLabel, currency, BigDecimal("0.00"), accountHolderName)
|
||||
|
||||
(hostedBank, createdAccount)
|
||||
}
|
||||
@ -456,9 +455,10 @@ private object LocalConnector extends Connector with Loggable {
|
||||
|
||||
//creates a bank account for an existing bank, with the appropriate values set
|
||||
override def createSandboxBankAccount(bankId: BankId, accountId: AccountId, accountNumber: String,
|
||||
currency: String, initialBalance: BigDecimal, accountHolderName: String): Box[BankAccount] = {
|
||||
accountType: String, accountLabel: String, currency: String,
|
||||
initialBalance: BigDecimal, accountHolderName: String): Box[BankAccount] = {
|
||||
HostedBank.find(bankId) match {
|
||||
case Full(b) => Full(createAccount(b, accountId, accountNumber, currency, initialBalance, accountHolderName))
|
||||
case Full(b) => Full(createAccount(b, accountId, accountNumber, accountType, accountLabel, currency, initialBalance, accountHolderName))
|
||||
case _ => Failure(s"Bank with id ${bankId.value} not found. Cannot create account at non-existing bank.")
|
||||
}
|
||||
|
||||
|
||||
@ -331,7 +331,7 @@ object LocalMappedConnector extends Connector with Loggable {
|
||||
|
||||
//creates a bank account (if it doesn't exist) and creates a bank (if it doesn't exist)
|
||||
//again assume national identifier is unique
|
||||
override def createBankAndAccount(bankName: String, bankNationalIdentifier: String, accountNumber: String, accountHolderName: String): (Bank, BankAccount) = {
|
||||
override def createBankAndAccount(bankName: String, bankNationalIdentifier: String, accountNumber: String, accountType: String, accountLabel: String, currency: String, accountHolderName: String): (Bank, BankAccount) = {
|
||||
//don't require and exact match on the name, just the identifier
|
||||
val bank = MappedBank.find(By(MappedBank.national_identifier, bankNationalIdentifier)) match {
|
||||
case Full(b) =>
|
||||
@ -349,7 +349,7 @@ object LocalMappedConnector extends Connector with Loggable {
|
||||
}
|
||||
|
||||
//TODO: pass in currency as a parameter?
|
||||
val account = createAccountIfNotExisting(bank.bankId, AccountId(UUID.randomUUID().toString), accountNumber, "EUR", 0L, accountHolderName)
|
||||
val account = createAccountIfNotExisting(bank.bankId, AccountId(UUID.randomUUID().toString), accountNumber, accountType, accountLabel, currency, 0L, accountHolderName)
|
||||
|
||||
(bank, account)
|
||||
}
|
||||
@ -434,6 +434,7 @@ object LocalMappedConnector extends Connector with Loggable {
|
||||
|
||||
//creates a bank account for an existing bank, with the appropriate values set. Can fail if the bank doesn't exist
|
||||
override def createSandboxBankAccount(bankId: BankId, accountId: AccountId, accountNumber: String,
|
||||
accountType: String, accountLabel: String,
|
||||
currency: String, initialBalance: BigDecimal, accountHolderName: String): Box[BankAccount] = {
|
||||
|
||||
for {
|
||||
@ -441,7 +442,7 @@ object LocalMappedConnector extends Connector with Loggable {
|
||||
} yield {
|
||||
|
||||
val balanceInSmallestCurrencyUnits = Helper.convertToSmallestCurrencyUnits(initialBalance, currency)
|
||||
createAccountIfNotExisting(bankId, accountId, accountNumber, currency, balanceInSmallestCurrencyUnits, accountHolderName)
|
||||
createAccountIfNotExisting(bankId, accountId, accountNumber, accountType, accountLabel, currency, balanceInSmallestCurrencyUnits, accountHolderName)
|
||||
}
|
||||
|
||||
}
|
||||
@ -452,7 +453,8 @@ object LocalMappedConnector extends Connector with Loggable {
|
||||
}
|
||||
|
||||
private def createAccountIfNotExisting(bankId: BankId, accountId: AccountId, accountNumber: String,
|
||||
currency: String, balanceInSmallestCurrencyUnits: Long, accountHolderName: String) : BankAccount = {
|
||||
accountType: String, accountLabel: String, currency: String,
|
||||
balanceInSmallestCurrencyUnits: Long, accountHolderName: String) : BankAccount = {
|
||||
getBankAccount(bankId, accountId) match {
|
||||
case Full(a) =>
|
||||
logger.info(s"account with id $accountId at bank with id $bankId already exists. No need to create a new one.")
|
||||
@ -462,6 +464,8 @@ object LocalMappedConnector extends Connector with Loggable {
|
||||
.bank(bankId.value)
|
||||
.theAccountId(accountId.value)
|
||||
.accountNumber(accountNumber)
|
||||
.kind(accountType)
|
||||
.accountLabel(accountLabel)
|
||||
.accountCurrency(currency)
|
||||
.accountBalance(balanceInSmallestCurrencyUnits)
|
||||
.holder(accountHolderName)
|
||||
|
||||
@ -139,12 +139,17 @@ import com.tesobe.model.{CreateBankAccount, UpdateBankAccount}
|
||||
case msg@AMQPMessage(message: CreateBankAccount) => {
|
||||
logger.info(s"got message to create account/bank: ${message.accountNumber} / ${message.bankIdentifier}")
|
||||
|
||||
//TODO: Revise those dummy values
|
||||
val accountType = "AMPQ"
|
||||
val accountLabel = message.accountNumber
|
||||
val currency = "EUR"
|
||||
|
||||
val foundUser = Users.users.vend.getUserByProviderId(message.accountOwnerProvider, message.accountOwnerId)
|
||||
val result = for {
|
||||
user <- foundUser ?~!
|
||||
s"user ${message.accountOwnerId} at ${message.accountOwnerProvider} not found. Could not create the account with owner view"
|
||||
} yield {
|
||||
val (_, bankAccount) = Connector.connector.vend.createBankAndAccount(message.bankName, message.bankIdentifier, message.accountNumber, user.name)
|
||||
val (_, bankAccount) = Connector.connector.vend.createBankAndAccount(message.bankName, message.bankIdentifier, message.accountNumber, accountType, accountLabel, currency, user.name)
|
||||
logger.info(s"created account with id ${bankAccount.bankId.value} with number ${bankAccount.number} at bank with identifier ${message.bankIdentifier}")
|
||||
BankAccountCreation.setAsOwner(bankAccount.bankId, bankAccount.accountId, user)
|
||||
}
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
package code.model.dataAccess
|
||||
|
||||
import net.liftweb.mapper._
|
||||
|
||||
class MappedKafkaBankAccountData extends LongKeyedMapper[MappedKafkaBankAccountData] with IdPK with CreatedUpdated {
|
||||
|
||||
override def getSingleton = MappedKafkaBankAccountData
|
||||
|
||||
object bankId extends MappedString(this, 255)
|
||||
def getBankId = bankId.get
|
||||
def setBankId(value: String) = bankId.set(value)
|
||||
|
||||
object accountId extends MappedString(this, 255)
|
||||
def getAccountId = accountId.get
|
||||
def setAccountId(value: String) = accountId.set(value)
|
||||
|
||||
object accountLabel extends MappedString(this, 255)
|
||||
def getLabel = accountLabel.get
|
||||
def setLabel(value: String) = accountLabel.set(value)
|
||||
|
||||
}
|
||||
|
||||
object MappedKafkaBankAccountData extends MappedKafkaBankAccountData with LongKeyedMetaMapper[MappedKafkaBankAccountData] {
|
||||
override def dbIndexes = UniqueIndex(bankId, accountId) :: super.dbIndexes
|
||||
}
|
||||
@ -20,9 +20,11 @@ object CreateTestAccountForm{
|
||||
var bankId = ""
|
||||
var currency = ""
|
||||
var initialBalance = ""
|
||||
var accountType = ""
|
||||
var accountLabel = ""
|
||||
|
||||
val processForm : () => JsCmd = () => {
|
||||
val createdAccount = createAccount(AccountId(accountId), BankId(bankId), currency, initialBalance)
|
||||
val createdAccount = createAccount(AccountId(accountId), BankId(bankId), accountType, accountLabel, currency, initialBalance)
|
||||
createdAccount match {
|
||||
case Full(acc) => showSuccess(acc)
|
||||
case Failure(msg, _, _) => showError(msg)
|
||||
@ -66,7 +68,7 @@ object CreateTestAccountForm{
|
||||
* Attempts to create a new account, based on form params
|
||||
* @return a box containing the created account or reason for account creation failure
|
||||
*/
|
||||
def createAccount(accountId : AccountId, bankId : BankId, currency : String, initialBalance : String) : Box[BankAccount] = {
|
||||
def createAccount(accountId : AccountId, bankId : BankId, accountType: String, accountLabel: String, currency : String, initialBalance : String) : Box[BankAccount] = {
|
||||
if(accountId.value == "") Failure("Account id cannot be empty")
|
||||
else if(bankId.value == "") Failure("Bank id cannot be empty")
|
||||
else if(currency == "") Failure("Currency cannot be empty")
|
||||
@ -79,7 +81,7 @@ object CreateTestAccountForm{
|
||||
bank <- Bank(bankId) ?~ s"Bank $bankId not found"
|
||||
accountDoesNotExist <- booleanToBox(BankAccount(bankId, accountId).isEmpty,
|
||||
s"Account with id $accountId already exists at bank $bankId")
|
||||
bankAccount <- Connector.connector.vend.createSandboxBankAccount(bankId, accountId, currency, initialBalanceAsNumber, user.name)
|
||||
bankAccount <- Connector.connector.vend.createSandboxBankAccount(bankId, accountId, accountType, accountLabel, currency, initialBalanceAsNumber, user.name)
|
||||
} yield {
|
||||
BankAccountCreation.setAsOwner(bankId, accountId, user)
|
||||
bankAccount
|
||||
|
||||
@ -7,7 +7,6 @@ import code.api.{DefaultUsers, ServerSetup}
|
||||
import code.bankconnectors.{Connector, OBPQueryParam}
|
||||
import code.management.ImporterAPI.ImporterTransaction
|
||||
import code.model.{PhysicalCard, Consumer => OBPConsumer, Token => OBPToken, _}
|
||||
import code.tesobe.CashTransaction
|
||||
import code.transactionrequests.TransactionRequests._
|
||||
import net.liftweb.common.{Box, Empty, Failure, Loggable}
|
||||
|
||||
@ -111,8 +110,9 @@ class PhysicalCardsTest extends ServerSetup with DefaultUsers {
|
||||
Failure("not supported")
|
||||
}
|
||||
|
||||
override def createBankAndAccount(bankName : String, bankNationalIdentifier : String,
|
||||
accountNumber : String, accountHolderName : String): (Bank, BankAccount) = ???
|
||||
override def createBankAndAccount(bankName : String, bankNationalIdentifier : String, accountNumber : String,
|
||||
accountType: String, accountLabel: String, currency: String,
|
||||
accountHolderName : String): (Bank, BankAccount) = ???
|
||||
|
||||
//sets a user as an account owner/holder
|
||||
override def setAccountHolder(bankAccountUID: BankAccountUID, user: User): Unit = ???
|
||||
@ -123,8 +123,8 @@ class PhysicalCardsTest extends ServerSetup with DefaultUsers {
|
||||
override def removeAccount(bankId: BankId, accountId: AccountId) : Boolean = ???
|
||||
|
||||
//creates a bank account for an existing bank, with the appropriate values set. Can fail if the bank doesn't exist
|
||||
override def createSandboxBankAccount(bankId: BankId, accountId: AccountId,
|
||||
accountNumber: String, currency: String,
|
||||
override def createSandboxBankAccount(bankId: BankId, accountId: AccountId, accountNumber: String,
|
||||
accountType: String, accountLabel: String, currency: String,
|
||||
initialBalance: BigDecimal, accountHolderName: String): Box[AccountType] = ???
|
||||
|
||||
//used by transaction import api call to check for duplicates
|
||||
|
||||
@ -18,6 +18,7 @@ class AccountTest extends V200ServerSetup with DefaultUsers {
|
||||
|
||||
val mockBankId = BankId("testBank1")
|
||||
val newAccountId1 = "NEW_ACCOUNT_ID_01"
|
||||
val newAccountLabel1 = "NEW_ACCOUNT_LABEL_01"
|
||||
|
||||
|
||||
override def beforeAll() {
|
||||
@ -36,7 +37,7 @@ class AccountTest extends V200ServerSetup with DefaultUsers {
|
||||
val testBank = mockBankId
|
||||
|
||||
Then("We create an private account at the bank")
|
||||
val accountPutJSON = CreateAccountJSON(obpuser1.userId,"CURRENT", AmountOfMoneyJSON121("EUR", "0"))
|
||||
val accountPutJSON = CreateAccountJSON(obpuser1.userId, "CURRENT", newAccountLabel1, AmountOfMoneyJSON121("EUR", "0"))
|
||||
val requestPut = (v2_0Request / "banks" / testBank.value / "accounts" / newAccountId1).PUT <@ (user1)
|
||||
val responsePut = makePutRequest(requestPut, write(accountPutJSON))
|
||||
|
||||
@ -84,7 +85,7 @@ class AccountTest extends V200ServerSetup with DefaultUsers {
|
||||
val testBank = mockBankId
|
||||
|
||||
Then("We create an private account at the bank")
|
||||
val accountPutJSON = CreateAccountJSON(obpuser1.userId,"CURRENT", AmountOfMoneyJSON121("EUR", "0"))
|
||||
val accountPutJSON = CreateAccountJSON(obpuser1.userId,"CURRENT", newAccountLabel1, AmountOfMoneyJSON121("EUR", "0"))
|
||||
val requestPut = (v2_0Request / "banks" / testBank.value / "accounts" / newAccountId1).PUT <@ (user1)
|
||||
val responsePut = makePutRequest(requestPut, write(accountPutJSON))
|
||||
|
||||
|
||||
@ -24,6 +24,9 @@ class BankAccountCreationTest extends ServerSetup with DefaultUsers with Default
|
||||
|
||||
val accountNumber = "12313213"
|
||||
val accountHolderName = "Rolf Rolfson"
|
||||
val accountLabel = accountNumber + " " + accountHolderName
|
||||
val accountType = "some-type"
|
||||
val currency = "EUR"
|
||||
|
||||
// scenario("Creating a duplicate bank should fail") {
|
||||
//
|
||||
@ -58,7 +61,7 @@ class BankAccountCreationTest extends ServerSetup with DefaultUsers with Default
|
||||
Connector.connector.vend.getBanks.size should equal(0)
|
||||
|
||||
When("We create an account at that bank")
|
||||
val (_, returnedAccount) = Connector.connector.vend.createBankAndAccount(bankName, bankNationalIdentifier, accountNumber, accountHolderName)
|
||||
val (_, returnedAccount) = Connector.connector.vend.createBankAndAccount(bankName, bankNationalIdentifier, accountNumber, accountType, accountLabel, currency, accountHolderName)
|
||||
|
||||
Then("A bank should now exist, with the correct parameters")
|
||||
val allBanks = Connector.connector.vend.getBanks
|
||||
@ -86,7 +89,7 @@ class BankAccountCreationTest extends ServerSetup with DefaultUsers with Default
|
||||
|
||||
|
||||
When("We create an account at that bank")
|
||||
val (_, returnedAccount) = Connector.connector.vend.createBankAndAccount(existingBank.fullName, existingBank.nationalIdentifier, accountNumber, accountHolderName)
|
||||
val (_, returnedAccount) = Connector.connector.vend.createBankAndAccount(existingBank.fullName, existingBank.nationalIdentifier, accountNumber, accountType, accountLabel, currency, accountHolderName)
|
||||
|
||||
Then("No new bank should be created")
|
||||
val allBanksAfter = Connector.connector.vend.getBanks
|
||||
@ -113,13 +116,15 @@ class BankAccountCreationTest extends ServerSetup with DefaultUsers with Default
|
||||
val initialBalance = BigDecimal("1000.00")
|
||||
val accountHolderName = "Some Person"
|
||||
val defaultAccountNumber = "1231213213"
|
||||
val accountType = "some-type"
|
||||
val accountLabel = defaultAccountNumber + " " + accountHolderName
|
||||
|
||||
scenario("Creating a bank account when the associated bank does not exist") {
|
||||
Given("A bank that doesn't exist")
|
||||
Connector.connector.vend.getBank(bankId).isDefined should equal(false)
|
||||
|
||||
When("We try to create an account at that bank")
|
||||
Connector.connector.vend.createSandboxBankAccount(bankId, accountId, defaultAccountNumber, currency, initialBalance, accountHolderName)
|
||||
Connector.connector.vend.createSandboxBankAccount(bankId, accountId, defaultAccountNumber, accountType, accountLabel, currency, initialBalance, accountHolderName)
|
||||
|
||||
Then("No account is created")
|
||||
Connector.connector.vend.getBankAccount(bankId, accountId).isDefined should equal(false)
|
||||
@ -132,7 +137,7 @@ class BankAccountCreationTest extends ServerSetup with DefaultUsers with Default
|
||||
Connector.connector.vend.getBank(bankId).isDefined should equal(true)
|
||||
|
||||
When("We try to create an account at that bank")
|
||||
Connector.connector.vend.createSandboxBankAccount(bankId, accountId, defaultAccountNumber, currency, initialBalance, accountHolderName)
|
||||
Connector.connector.vend.createSandboxBankAccount(bankId, accountId, defaultAccountNumber, accountType, accountLabel, currency, initialBalance, accountHolderName)
|
||||
|
||||
Then("An account with the proper parameters should be created")
|
||||
val createdAccBox = Connector.connector.vend.getBankAccount(bankId, accountId)
|
||||
@ -153,7 +158,7 @@ class BankAccountCreationTest extends ServerSetup with DefaultUsers with Default
|
||||
Connector.connector.vend.getBank(bankId).isDefined should equal(true)
|
||||
|
||||
When("We try to create an account at that bank")
|
||||
Connector.connector.vend.createSandboxBankAccount(bankId, accountId, currency, initialBalance, accountHolderName)
|
||||
Connector.connector.vend.createSandboxBankAccount(bankId, accountId, accountType, accountLabel, currency, initialBalance, accountHolderName)
|
||||
|
||||
Then("An account with the proper parameters should be created")
|
||||
val createdAccBox = Connector.connector.vend.getBankAccount(bankId, accountId)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user