Create call for POST Counterparty (aka Other Account) #201, renamed OtherBankAccount -> Counterparty

This commit is contained in:
Marko Milic 2016-11-04 11:42:07 +01:00
parent b7b5a6c459
commit 6ba7a2a6b9
14 changed files with 43 additions and 43 deletions

View File

@ -105,9 +105,9 @@ trait Connector {
def getBankAccount(bankId : BankId, accountId : AccountId) : Box[AccountType]
def getOtherBankAccount(bankId: BankId, accountID : AccountId, otherAccountID : String) : Box[OtherBankAccount]
def getOtherBankAccount(bankId: BankId, accountID : AccountId, otherAccountID : String) : Box[Counterparty]
def getOtherBankAccounts(bankId: BankId, accountID : AccountId): List[OtherBankAccount]
def getOtherBankAccounts(bankId: BankId, accountID : AccountId): List[Counterparty]
def getTransactions(bankId: BankId, accountID: AccountId, queryParams: OBPQueryParam*): Box[List[Transaction]]

View File

@ -362,7 +362,7 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
Full(new KafkaBankAccount(r))
}
def getOtherBankAccount(thisAccountBankId : BankId, thisAccountId : AccountId, metadata : OtherBankAccountMetadata) : Box[OtherBankAccount] = {
def getOtherBankAccount(thisAccountBankId : BankId, thisAccountId : AccountId, metadata : CounterpartyMetadata) : Box[Counterparty] = {
//because we don't have a db backed model for OtherBankAccounts, we need to construct it from an
//OtherBankAccountMetadata and a transaction
val t = getTransactions(thisAccountBankId, thisAccountId).map { t =>
@ -374,7 +374,7 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
}
}.get.head
val res = new OtherBankAccount(
val res = new Counterparty(
//counterparty id is defined to be the id of its metadata as we don't actually have an id for the counterparty itself
id = metadata.metadataId,
label = metadata.getHolder,
@ -431,11 +431,11 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
// Get all counterparties related to an account
override def getOtherBankAccounts(bankId: BankId, accountID: AccountId): List[OtherBankAccount] =
override def getOtherBankAccounts(bankId: BankId, accountID: AccountId): List[Counterparty] =
Counterparties.counterparties.vend.getMetadatas(bankId, accountID).flatMap(getOtherBankAccount(bankId, accountID, _))
// Get one counterparty related to a bank account
override def getOtherBankAccount(bankId: BankId, accountID: AccountId, otherAccountID: String): Box[OtherBankAccount] =
override def getOtherBankAccount(bankId: BankId, accountID: AccountId, otherAccountID: String): Box[Counterparty] =
// Get the metadata and pass it to getOtherBankAccount to construct the other account.
Counterparties.counterparties.vend.getMetadata(bankId, accountID, otherAccountID).flatMap(getOtherBankAccount(bankId, accountID, _))
@ -958,8 +958,8 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable
}
// Helper for creating other bank account
def createOtherBankAccount(c: KafkaInboundTransactionCounterparty, o: KafkaBankAccount, alreadyFoundMetadata : Option[OtherBankAccountMetadata]) = {
new OtherBankAccount(
def createOtherBankAccount(c: KafkaInboundTransactionCounterparty, o: KafkaBankAccount, alreadyFoundMetadata : Option[CounterpartyMetadata]) = {
new Counterparty(
id = alreadyFoundMetadata.map(_.metadataId).getOrElse(""),
label = c.account_number.getOrElse(c.name.getOrElse("")),
nationalIdentifier = "",

View File

@ -51,7 +51,7 @@ private object LocalConnector extends Connector with Loggable {
}
override def getOtherBankAccount(bankId: BankId, accountId : AccountId, otherAccountID : String): Box[OtherBankAccount] = {
override def getOtherBankAccount(bankId: BankId, accountId : AccountId, otherAccountID : String): Box[Counterparty] = {
/**
* In this implementation (for legacy reasons), the "otherAccountID" is actually the mongodb id of the
@ -84,7 +84,7 @@ private object LocalConnector extends Connector with Loggable {
}
}
override def getOtherBankAccounts(bankId: BankId, accountId : AccountId): List[OtherBankAccount] = {
override def getOtherBankAccounts(bankId: BankId, accountId : AccountId): List[Counterparty] = {
/**
* In this implementation (for legacy reasons), the "otherAccountID" is actually the mongodb id of the
@ -190,7 +190,7 @@ private object LocalConnector extends Connector with Loggable {
otherAccount_.number.get)
}
val otherAccount = new OtherBankAccount(
val otherAccount = new Counterparty(
id = metadata.metadataId,
label = otherAccount_.holder.get,
nationalIdentifier = otherAccount_.bank.get.national_identifier.get,
@ -339,8 +339,8 @@ private object LocalConnector extends Connector with Loggable {
private def createOtherBankAccount(originalPartyBankId: BankId, originalPartyAccountId: AccountId,
otherAccount : OtherBankAccountMetadata, otherAccountFromTransaction : OBPAccount) : OtherBankAccount = {
new OtherBankAccount(
otherAccount : CounterpartyMetadata, otherAccountFromTransaction : OBPAccount) : Counterparty = {
new Counterparty(
id = otherAccount.metadataId,
label = otherAccount.getHolder,
nationalIdentifier = otherAccountFromTransaction.bank.get.national_identifier.get,

View File

@ -129,7 +129,7 @@ object LocalMappedConnector extends Connector with Loggable {
By(MappedAccountHolder.accountPermalink, accountID.value)).map(accHolder => accHolder.user.obj).flatten.toSet
def getOtherBankAccount(thisAccountBankId : BankId, thisAccountId : AccountId, metadata : OtherBankAccountMetadata) : Box[OtherBankAccount] = {
def getOtherBankAccount(thisAccountBankId : BankId, thisAccountId : AccountId, metadata : CounterpartyMetadata) : Box[Counterparty] = {
//because we don't have a db backed model for OtherBankAccounts, we need to construct it from an
//OtherBankAccountMetadata and a transaction
for { //find a transaction with this counterparty
@ -139,7 +139,7 @@ object LocalMappedConnector extends Connector with Loggable {
By(MappedTransaction.counterpartyAccountHolder, metadata.getHolder),
By(MappedTransaction.counterpartyAccountNumber, metadata.getAccountNumber))
} yield {
new OtherBankAccount(
new Counterparty(
//counterparty id is defined to be the id of its metadata as we don't actually have an id for the counterparty itself
id = metadata.metadataId,
label = metadata.getHolder,
@ -157,11 +157,11 @@ object LocalMappedConnector extends Connector with Loggable {
}
// Get all counterparties related to an account
override def getOtherBankAccounts(bankId: BankId, accountID: AccountId): List[OtherBankAccount] =
override def getOtherBankAccounts(bankId: BankId, accountID: AccountId): List[Counterparty] =
Counterparties.counterparties.vend.getMetadatas(bankId, accountID).flatMap(getOtherBankAccount(bankId, accountID, _))
// Get one counterparty related to a bank account
override def getOtherBankAccount(bankId: BankId, accountID: AccountId, otherAccountID: String): Box[OtherBankAccount] =
override def getOtherBankAccount(bankId: BankId, accountID: AccountId, otherAccountID: String): Box[Counterparty] =
// Get the metadata and pass it to getOtherBankAccount to construct the other account.
Counterparties.counterparties.vend.getMetadata(bankId, accountID, otherAccountID).flatMap(getOtherBankAccount(bankId, accountID, _))

View File

@ -2,7 +2,7 @@ package code.metadata.counterparties
import net.liftweb.common.Box
import net.liftweb.util.SimpleInjector
import code.model.{AccountId, BankId, OtherBankAccountMetadata, OtherBankAccount}
import code.model.{AccountId, BankId, CounterpartyMetadata, Counterparty}
object Counterparties extends SimpleInjector {
@ -14,10 +14,10 @@ object Counterparties extends SimpleInjector {
trait Counterparties {
def getOrCreateMetadata(originalPartyBankId: BankId, originalPartyAccountId : AccountId, otherParty : OtherBankAccount) : OtherBankAccountMetadata
def getOrCreateMetadata(originalPartyBankId: BankId, originalPartyAccountId : AccountId, otherParty : Counterparty) : CounterpartyMetadata
//get all counterparty metadatas for a single OBP account
def getMetadatas(originalPartyBankId: BankId, originalPartyAccountId : AccountId) : List[OtherBankAccountMetadata]
def getMetadatas(originalPartyBankId: BankId, originalPartyAccountId : AccountId) : List[CounterpartyMetadata]
def getMetadata(originalPartyBankId: BankId, originalPartyAccountId : AccountId, counterpartyMetadataId : String) : Box[OtherBankAccountMetadata]
def getMetadata(originalPartyBankId: BankId, originalPartyAccountId : AccountId, counterpartyMetadataId : String) : Box[CounterpartyMetadata]
}

View File

@ -10,7 +10,7 @@ import net.liftweb.mapper._
import net.liftweb.util.Helpers.tryo
object MapperCounterparties extends Counterparties with Loggable {
override def getOrCreateMetadata(originalPartyBankId: BankId, originalPartyAccountId: AccountId, otherParty: OtherBankAccount): OtherBankAccountMetadata = {
override def getOrCreateMetadata(originalPartyBankId: BankId, originalPartyAccountId: AccountId, otherParty: Counterparty): CounterpartyMetadata = {
/**
* Generates a new alias name that is guaranteed not to collide with any existing public alias names
@ -48,7 +48,7 @@ object MapperCounterparties extends Counterparties with Loggable {
//can't find by MappedCounterpartyMetadata.counterpartyId = otherParty.id because in this implementation
//if the metadata doesn't exist, the id field of the OtherBankAccount is not known yet, and will be empty
def findMappedCounterpartyMetadata(originalPartyBankId: BankId, originalPartyAccountId: AccountId,
otherParty: OtherBankAccount) : Box[MappedCounterpartyMetadata] = {
otherParty: Counterparty) : Box[MappedCounterpartyMetadata] = {
MappedCounterpartyMetadata.find(
By(MappedCounterpartyMetadata.thisAccountBankId, originalPartyBankId.value),
By(MappedCounterpartyMetadata.thisAccountId, originalPartyAccountId.value),
@ -80,14 +80,14 @@ object MapperCounterparties extends Counterparties with Loggable {
}
// Get all counterparty metadata for a single OBP account
override def getMetadatas(originalPartyBankId: BankId, originalPartyAccountId: AccountId): List[OtherBankAccountMetadata] = {
override def getMetadatas(originalPartyBankId: BankId, originalPartyAccountId: AccountId): List[CounterpartyMetadata] = {
MappedCounterpartyMetadata.findAll(
By(MappedCounterpartyMetadata.thisAccountBankId, originalPartyBankId.value),
By(MappedCounterpartyMetadata.thisAccountId, originalPartyAccountId.value)
)
}
override def getMetadata(originalPartyBankId: BankId, originalPartyAccountId: AccountId, counterpartyMetadataId: String): Box[OtherBankAccountMetadata] = {
override def getMetadata(originalPartyBankId: BankId, originalPartyAccountId: AccountId, counterpartyMetadataId: String): Box[CounterpartyMetadata] = {
/**
* This particular implementation requires the metadata id to be the same as the otherParty (OtherBankAccount) id
*/
@ -99,7 +99,7 @@ object MapperCounterparties extends Counterparties with Loggable {
}
}
class MappedCounterpartyMetadata extends OtherBankAccountMetadata with LongKeyedMapper[MappedCounterpartyMetadata] with IdPK with CreatedUpdated {
class MappedCounterpartyMetadata extends CounterpartyMetadata with LongKeyedMapper[MappedCounterpartyMetadata] with IdPK with CreatedUpdated {
override def getSingleton = MappedCounterpartyMetadata
object counterpartyId extends MappedUUID(this)

View File

@ -1,6 +1,6 @@
package code.metadata.counterparties
import code.model.{AccountId, BankId, OtherBankAccountMetadata, OtherBankAccount}
import code.model.{AccountId, BankId, CounterpartyMetadata, Counterparty}
import net.liftweb.common.{Box, Loggable}
import com.mongodb.QueryBuilder
import net.liftweb.util.Helpers.tryo
@ -10,12 +10,12 @@ import org.bson.types.ObjectId
object MongoCounterparties extends Counterparties with Loggable {
def getMetadatas(originalPartyBankId: BankId, originalPartyAccountId : AccountId) : List[OtherBankAccountMetadata] = {
def getMetadatas(originalPartyBankId: BankId, originalPartyAccountId : AccountId) : List[CounterpartyMetadata] = {
val query = QueryBuilder.start("originalPartyBankId").is(originalPartyBankId.value).put("originalPartyAccountId").is(originalPartyAccountId.value).get
Metadata.findAll(query)
}
def getMetadata(originalPartyBankId: BankId, originalPartyAccountId : AccountId, counterpartyMetadataId : String) : Box[OtherBankAccountMetadata] = {
def getMetadata(originalPartyBankId: BankId, originalPartyAccountId : AccountId, counterpartyMetadataId : String) : Box[CounterpartyMetadata] = {
/**
* This particular implementation requires the metadata id to be the same as the otherParty (OtherBankAccount) id
*/
@ -27,7 +27,7 @@ object MongoCounterparties extends Counterparties with Loggable {
} yield m
}
def getOrCreateMetadata(originalPartyBankId: BankId, originalPartyAccountId : AccountId, otherParty : OtherBankAccount) : OtherBankAccountMetadata = {
def getOrCreateMetadata(originalPartyBankId: BankId, originalPartyAccountId : AccountId, otherParty : Counterparty) : CounterpartyMetadata = {
/**
* This particular implementation requires the metadata id to be the same as the otherParty (OtherBankAccount) id

View File

@ -5,9 +5,9 @@ import code.util.Helper
import net.liftweb.mongodb.record.{BsonMetaRecord, BsonRecord, MongoMetaRecord, MongoRecord}
import net.liftweb.mongodb.record.field.ObjectIdPk
import net.liftweb.record.field.StringField
import code.model.{OtherBankAccountMetadata, UserId, ViewId, GeoTag}
import code.model.{CounterpartyMetadata, UserId, ViewId, GeoTag}
//TODO: this should be private
class Metadata private() extends OtherBankAccountMetadata with MongoRecord[Metadata] with ObjectIdPk[Metadata] {
class Metadata private() extends CounterpartyMetadata with MongoRecord[Metadata] with ObjectIdPk[Metadata] {
import net.liftweb.mongodb.record.field.BsonRecordField
import java.util.Date

View File

@ -570,7 +570,7 @@ The other bank account or counterparty in a transaction
as see from the perspective of the original party.
*/
class OtherBankAccount(
class Counterparty(
val id : String,
val label : String, // Reference given to the counterparty by the original party.
val nationalIdentifier : String, // National identifier for a bank account (how is this different to number below?)
@ -581,10 +581,10 @@ class OtherBankAccount(
val kind : String, // Type of bank account.
val originalPartyBankId: BankId, //bank id of the party for which this OtherBankAccount is the counterparty
val originalPartyAccountId: AccountId, //account id of the party for which this OtherBankAccount is the counterparty
val alreadyFoundMetadata : Option[OtherBankAccountMetadata]
val alreadyFoundMetadata : Option[CounterpartyMetadata]
) {
val metadata : OtherBankAccountMetadata = {
val metadata : CounterpartyMetadata = {
// If we already have alreadyFoundMetadata, return it, else get or create it.
alreadyFoundMetadata match {
case Some(meta) =>
@ -607,7 +607,7 @@ class Transaction(
//id is unique for transactions of @thisAccount
val id : TransactionId,
val thisAccount : BankAccount,
val otherAccount : OtherBankAccount,
val otherAccount : Counterparty,
//E.g. cash withdrawal, electronic payment, etc.
val transactionType : String,
val amount : BigDecimal,

View File

@ -103,7 +103,7 @@ trait TransactionImage {
/*
Counterparty metadata
*/
trait OtherBankAccountMetadata {
trait CounterpartyMetadata {
def metadataId: String
def getHolder: String
def getAccountNumber: String

View File

@ -489,7 +489,7 @@ trait View {
None
}
def moderate(otherBankAccount : OtherBankAccount) : Option[ModeratedOtherBankAccount] = {
def moderate(otherBankAccount : Counterparty) : Option[ModeratedOtherBankAccount] = {
if (canSeeTransactionOtherBankAccount)
{
//other account data

View File

@ -44,7 +44,7 @@ trait OBPDataImport extends Loggable {
type BankType <: Bank
type AccountType <: BankAccount
type MetadataType <: OtherBankAccountMetadata
type MetadataType <: CounterpartyMetadata
type ViewType <: View
type TransactionType <: TransactionUUID
type AccountOwnerUsername = String

View File

@ -84,8 +84,8 @@ class MappedTransaction extends LongKeyedMapper[MappedTransaction] with IdPK wit
val amt = Helper.smallestCurrencyUnitToBigDecimal(amount.get, transactionCurrency)
val newBalance = Helper.smallestCurrencyUnitToBigDecimal(newAccountBalance.get, transactionCurrency)
def createOtherBankAccount(alreadyFoundMetadata : Option[OtherBankAccountMetadata]) = {
new OtherBankAccount(
def createOtherBankAccount(alreadyFoundMetadata : Option[CounterpartyMetadata]) = {
new Counterparty(
id = alreadyFoundMetadata.map(_.metadataId).getOrElse(""),
label = counterpartyAccountHolder.get,
nationalIdentifier = counterpartyNationalId.get,

View File

@ -56,9 +56,9 @@ class PhysicalCardsTest extends ServerSetup with DefaultUsers {
override def getBank(bankId : BankId) : Box[Bank] = Empty
override def getBanks : List[Bank] = Nil
override def getBankAccount(bankId : BankId, accountId : AccountId) : Box[BankAccount] = Empty
override def getOtherBankAccount(bankId: BankId, accountID : AccountId, otherAccountID : String) : Box[OtherBankAccount] =
override def getOtherBankAccount(bankId: BankId, accountID : AccountId, otherAccountID : String) : Box[Counterparty] =
Empty
override def getOtherBankAccounts(bankId: BankId, accountID : AccountId): List[OtherBankAccount] =
override def getOtherBankAccounts(bankId: BankId, accountID : AccountId): List[Counterparty] =
Nil
override def getTransactions(bankId: BankId, accountID: AccountId, queryParams: OBPQueryParam*): Box[List[Transaction]] =
Empty