createCounterparty over Kafka -- in process

step4: fixed MappedCounterparty table, and all the methods paramters
This commit is contained in:
hongwei1 2017-10-16 15:09:52 +02:00
parent 77f3c20b71
commit c6c431f09a
19 changed files with 268 additions and 154 deletions

View File

@ -58,7 +58,7 @@ import code.loginattempts.MappedBadLoginAttempt
import code.management.{AccountsAPI, ImporterAPI}
import code.meetings.MappedMeeting
import code.metadata.comments.MappedComment
import code.metadata.counterparties.{MappedCounterparty, MappedCounterpartyMetadata, MappedCounterpartyWhereTag}
import code.metadata.counterparties.{MappedCounterparty, MappedCounterpartyBespoke, MappedCounterpartyMetadata, MappedCounterpartyWhereTag}
import code.metadata.narrative.MappedNarrative
import code.metadata.tags.MappedTag
import code.metadata.transactionimages.MappedTransactionImage
@ -84,7 +84,7 @@ import net.liftweb.sitemap.Loc._
import net.liftweb.sitemap._
import net.liftweb.util.Helpers._
import net.liftweb.util.{Helpers, Props, Schedule, _}
import code.api.util.APIUtil.{enableVersionIfAllowed, ApiVersion}
import code.api.util.APIUtil.{ApiVersion, enableVersionIfAllowed}
/**
@ -469,6 +469,7 @@ object ToSchemify {
Token,
Nonce,
MappedCounterparty,
MappedCounterpartyBespoke,
MappedCounterpartyMetadata,
MappedCounterpartyWhereTag,
MappedTransactionRequest,

View File

@ -1629,7 +1629,7 @@ object SwaggerDefinitionsJSON {
value = "englishDescription"
)
//CM need to move into V220
val postCounterpartyJSON = PostCounterpartyJSON(
name = "CounterpartyName",
description ="My landlord",
@ -1757,19 +1757,23 @@ object SwaggerDefinitionsJSON {
)
val counterpartyJsonV220 = CounterpartyJsonV220(
name = "b2dd6c2c-7ebd-4014-9c73-b7d28cc71fe1",
name = postCounterpartyJSON.name,
description = postCounterpartyJSON.description,
created_by_user_id = "49e1e147-64c1-4823-ad9f-89efcd02a9fa",
this_bank_id = "gh.29.uk",
this_account_id = "8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0",
this_view_id = "owner",
counterparty_id = "1d65db7c-a7b2-4839-af41-958276ab7790",
other_bank_routing_scheme = "test",
other_bank_routing_address = "test",
other_branch_routing_scheme = "OBP",
other_branch_routing_address = "Berlin",
other_account_routing_scheme = "IBAN",
other_account_routing_address = "DE89 3704 0044 0532 0130 00",
is_beneficiary = true
other_bank_routing_scheme = postCounterpartyJSON.other_bank_routing_scheme,
other_bank_routing_address = postCounterpartyJSON.other_bank_routing_scheme,
other_branch_routing_scheme = postCounterpartyJSON.other_bank_routing_scheme,
other_branch_routing_address = postCounterpartyJSON.other_bank_routing_scheme,
other_account_routing_scheme = postCounterpartyJSON.other_bank_routing_scheme,
other_account_routing_address = postCounterpartyJSON.other_bank_routing_scheme,
is_beneficiary = true,
other_account_secondary_routing_scheme = postCounterpartyJSON.other_bank_routing_scheme,
other_account_secondary_routing_address= postCounterpartyJSON.other_bank_routing_scheme,
bespoke = postCounterpartyJSON.bespoke
)
val counterpartiesJsonV220 = CounterpartiesJsonV220(

View File

@ -1285,109 +1285,6 @@ trait APIMethods210 {
}
}
resourceDocs += ResourceDoc(
createCounterparty,
apiVersion,
"createCounterparty",
"POST",
"/banks/BANK_ID/accounts/ACCOUNT_ID/VIEW_ID/counterparties",
"Create counterparty for an account",
s"""Create counterparty.
|
|Counterparties are created for the account / view
|They are how the user of the view (e.g. account owner) refers to the other side of the transaction
|
|name is the human readable name (e.g. Piano teacher, Miss Nipa)
|
|other_bank_id is an (internal) ID for the bank of the bank of the counterparty (if known)
|
|other_account_id is an (internal) ID for the bank account of the counterparty (if known)
|
|other_account_provider is a code that tells the system where that bank is hosted. Will be OBP if its known to the API. Usage of this flag (in API / connectors) is work in progress.
|
|account_routing_scheme is a code that dictates the nature of the account_routing_address e.g. IBAN
|
|account_routing_address is an instance of account_routing_scheme that can be used to route payments to external systems. e.g. an IBAN number
|
|bank_routing_scheme is a code that dictates the nature of the bank_routing_address e.g. "BIC",
|
|bank_routing_address is an instance of bank_routing_scheme
|
|is_beneficiary must be set to true in order to send payments to this counterparty
|
|The view specified by VIEW_ID must have the canAddCounterparty permission
|
|${authenticationRequiredMessage(true)}
|""",
postCounterpartyJSON,
counterpartyJsonV220,
List(
UserNotLoggedIn,
InvalidAccountIdFormat,
InvalidBankIdFormat,
BankNotFound,
AccountNotFound,
InvalidJsonFormat,
ViewNotFound,
CounterpartyAlreadyExists,
UnknownError
),
Catalogs(notCore, notPSD2, notOBWG),
List(apiTagCounterparty, apiTagAccount))
lazy val createCounterparty: PartialFunction[Req, Box[User] => Box[JsonResponse]] = {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "counterparties" :: Nil JsonPost json -> _ => {
user =>
for {
u <- user ?~! UserNotLoggedIn
isValidAccountIdFormat <- tryo(assert(isValidID(accountId.value)))?~! InvalidAccountIdFormat
isValidBankIdFormat <- tryo(assert(isValidID(bankId.value)))?~! InvalidBankIdFormat
bank <- Bank(bankId) ?~! BankNotFound
account <- BankAccount(bankId, AccountId(accountId.value)) ?~! {AccountNotFound}
postJson <- tryo {json.extract[PostCounterpartyJSON]} ?~! {InvalidJsonFormat+PostCounterpartyJSON}
availableViews <- Full(account.permittedViews(user))
view <- View.fromUrl(viewId, account) ?~! {ViewNotFound}
canUserAccessView <- tryo(availableViews.find(_ == viewId)) ?~! {"Current user does not have access to the view " + viewId}
canAddCounterparty <- booleanToBox(view.canAddCounterparty == true, "The current view does not have can_add_counterparty permission. Please use a view with that permission or add the permission to this view.")
checkAvailable <- tryo(assert(Counterparties.counterparties.vend.
checkCounterpartyAvailable(postJson.name,bankId.value, accountId.value,viewId.value) == true)
) ?~! CounterpartyAlreadyExists
counterparty <- Connector.connector.vend.createCounterparty(
name=postJson.name,
description=postJson.description,
createdByUserId=u.userId,
thisBankId=bankId.value,
thisAccountId=accountId.value,
thisViewId = viewId.value,
otherAccountRoutingScheme=postJson.other_account_routing_scheme,
otherAccountRoutingAddress=postJson.other_account_routing_address,
otherAccountSecondaryRoutingScheme=postJson.other_account_secondary_routing_scheme,
otherAccountSecondaryRoutingAddress=postJson.other_account_secondary_routing_address,
otherBankRoutingScheme=postJson.other_bank_routing_scheme,
otherBankRoutingAddress=postJson.other_bank_routing_address,
otherBranchRoutingScheme=postJson.other_branch_routing_scheme,
otherBranchRoutingAddress=postJson.other_branch_routing_address,
isBeneficiary=postJson.is_beneficiary,
bespoke=postJson.bespoke
)
// Now just comment the following lines, keep the same return tpyle of V220 "getCounterpartiesForAccount".
// metadata <- Counterparties.counterparties.vend.getMetadata(bankId, accountId, counterparty.counterpartyId) ?~! "Cannot find the metadata"
// moderated <- Connector.connector.vend.getCounterparty(bankId, accountId, counterparty.counterpartyId).flatMap(oAcc => view.moderate(oAcc))
} yield {
val list = JSONFactory220.createCounterpartyJSON(counterparty)
// Now just comment the following lines, keep the same return tpyle of V220 "getCounterpartiesForAccount".
// val list = createCounterpartJSON(moderated, metadata, couterparty)
successJsonResponse(Extraction.decompose(list))
}
}
}
val createCustomerEntitlementsRequiredForSpecificBank = CanCreateCustomer ::
CanCreateUserCustomerLink ::
Nil

View File

@ -200,7 +200,6 @@ object OBPAPI2_1_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w
Implementations2_1_0.addCardForBank ::
Implementations2_1_0.getUsers ::
Implementations2_1_0.createTransactionType ::
Implementations2_1_0.createCounterparty ::
Implementations2_1_0.getAtm ::
Implementations2_1_0.getBranch ::
Implementations2_1_0.updateBranch ::

View File

@ -14,6 +14,7 @@ import code.api.v2_2_0.JSONFactory220.transformV220ToBranch
import code.bankconnectors._
import code.bankconnectors.vMar2017.JsonFactory_vMar2017
import code.consumer.Consumers
import code.metadata.counterparties.Counterparties
import code.metrics.{ConnectorMetric, ConnectorMetricsProvider}
import code.model.dataAccess.BankAccountCreation
import code.model.{BankId, ViewId, _}
@ -933,6 +934,104 @@ trait APIMethods220 {
}
}
}
resourceDocs += ResourceDoc(
createCounterparty,
implmentedInApiVersion,
"createCounterparty",
"POST",
"/banks/BANK_ID/accounts/ACCOUNT_ID/VIEW_ID/counterparties",
"Create counterparty for an account",
s"""Create counterparty.
|
|Counterparties are created for the account / view
|They are how the user of the view (e.g. account owner) refers to the other side of the transaction
|
|name is the human readable name (e.g. Piano teacher, Miss Nipa)
|
|other_bank_id is an (internal) ID for the bank of the bank of the counterparty (if known)
|
|other_account_id is an (internal) ID for the bank account of the counterparty (if known)
|
|other_account_provider is a code that tells the system where that bank is hosted. Will be OBP if its known to the API. Usage of this flag (in API / connectors) is work in progress.
|
|account_routing_scheme is a code that dictates the nature of the account_routing_address e.g. IBAN
|
|account_routing_address is an instance of account_routing_scheme that can be used to route payments to external systems. e.g. an IBAN number
|
|bank_routing_scheme is a code that dictates the nature of the bank_routing_address e.g. "BIC",
|
|bank_routing_address is an instance of bank_routing_scheme
|
|is_beneficiary must be set to true in order to send payments to this counterparty
|
|The view specified by VIEW_ID must have the canAddCounterparty permission
|
|${authenticationRequiredMessage(true)}
|""",
postCounterpartyJSON,
counterpartyJsonV220,
List(
UserNotLoggedIn,
InvalidAccountIdFormat,
InvalidBankIdFormat,
BankNotFound,
AccountNotFound,
InvalidJsonFormat,
ViewNotFound,
CounterpartyAlreadyExists,
UnknownError
),
Catalogs(notCore, notPSD2, notOBWG),
List(apiTagCounterparty, apiTagAccount))
lazy val createCounterparty: PartialFunction[Req, Box[User] => Box[JsonResponse]] = {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "counterparties" :: Nil JsonPost json -> _ => {
user =>
for {
u <- user ?~! UserNotLoggedIn
isValidAccountIdFormat <- tryo(assert(isValidID(accountId.value)))?~! InvalidAccountIdFormat
isValidBankIdFormat <- tryo(assert(isValidID(bankId.value)))?~! InvalidBankIdFormat
bank <- Bank(bankId) ?~! BankNotFound
account <- BankAccount(bankId, AccountId(accountId.value)) ?~! {AccountNotFound}
postJson <- tryo {json.extract[PostCounterpartyJSON]} ?~! {InvalidJsonFormat+PostCounterpartyJSON}
availableViews <- Full(account.permittedViews(user))
view <- View.fromUrl(viewId, account) ?~! {ViewNotFound}
canUserAccessView <- tryo(availableViews.find(_ == viewId)) ?~! {"Current user does not have access to the view " + viewId}
canAddCounterparty <- booleanToBox(view.canAddCounterparty == true, "The current view does not have can_add_counterparty permission. Please use a view with that permission or add the permission to this view.")
checkAvailable <- tryo(assert(Counterparties.counterparties.vend.
checkCounterpartyAvailable(postJson.name,bankId.value, accountId.value,viewId.value) == true)
) ?~! CounterpartyAlreadyExists
counterparty <- Connector.connector.vend.createCounterparty(
name=postJson.name,
description=postJson.description,
createdByUserId=u.userId,
thisBankId=bankId.value,
thisAccountId=accountId.value,
thisViewId = viewId.value,
otherAccountRoutingScheme=postJson.other_account_routing_scheme,
otherAccountRoutingAddress=postJson.other_account_routing_address,
otherAccountSecondaryRoutingScheme=postJson.other_account_secondary_routing_scheme,
otherAccountSecondaryRoutingAddress=postJson.other_account_secondary_routing_address,
otherBankRoutingScheme=postJson.other_bank_routing_scheme,
otherBankRoutingAddress=postJson.other_bank_routing_address,
otherBranchRoutingScheme=postJson.other_branch_routing_scheme,
otherBranchRoutingAddress=postJson.other_branch_routing_address,
isBeneficiary=postJson.is_beneficiary,
bespoke=postJson.bespoke
)
// Now just comment the following lines, keep the same return tpyle of V220 "getCounterpartiesForAccount".
// metadata <- Counterparties.counterparties.vend.getMetadata(bankId, accountId, counterparty.counterpartyId) ?~! "Cannot find the metadata"
// moderated <- Connector.connector.vend.getCounterparty(bankId, accountId, counterparty.counterpartyId).flatMap(oAcc => view.moderate(oAcc))
} yield {
val list = JSONFactory220.createCounterpartyJSON(counterparty)
// Now just comment the following lines, keep the same return tpyle of V220 "getCounterpartiesForAccount".
// val list = createCounterpartJSON(moderated, metadata, couterparty)
successJsonResponse(Extraction.decompose(list))
}
}
}
/*

View File

@ -36,12 +36,12 @@ import java.util.Date
import code.api.v1_2_1.{AccountRoutingJsonV121, AmountOfMoneyJsonV121, BankRoutingJsonV121}
import code.api.v1_4_0.JSONFactory1_4_0._
import code.api.v2_1_0.{MetricJson, MetricsJson, ResourceUserJSON}
import code.api.v2_1_0.{MetricJson, MetricsJson, PostCounterpartyBespoke, ResourceUserJSON}
import code.atms.Atms.{Atm, AtmId, AtmT}
import code.branches.Branches._
import code.common.{Address, Location, Meta}
import code.customer.Customer
import code.model.dataAccess.{ResourceUser, AuthUser}
import code.model.dataAccess.{AuthUser, ResourceUser}
import code.products.Products.Product
import code.fx.FXRate
import code.metadata.counterparties.CounterpartyTrait
@ -147,6 +147,7 @@ case class FXRateJsonV220(
case class CounterpartyJsonV220(
name: String,
description: String,
created_by_user_id: String,
this_bank_id: String,
this_account_id: String,
@ -158,7 +159,10 @@ case class CounterpartyJsonV220(
other_branch_routing_address: String,
other_account_routing_scheme: String,
other_account_routing_address: String,
is_beneficiary: Boolean
other_account_secondary_routing_scheme: String,
other_account_secondary_routing_address: String,
is_beneficiary: Boolean,
bespoke:List[PostCounterpartyBespoke]
)
case class CounterpartiesJsonV220(
@ -438,18 +442,22 @@ object JSONFactory220{
def createCounterpartyJSON(counterparty: CounterpartyTrait): CounterpartyJsonV220 = {
CounterpartyJsonV220(
name = counterparty.name,
description = counterparty.description,
created_by_user_id = counterparty.createdByUserId,
this_bank_id = counterparty.thisBankId,
this_account_id = counterparty.thisAccountId,
this_view_id = counterparty.thisViewId,
counterparty_id = counterparty.counterpartyId,
other_bank_routing_scheme = counterparty.otherBankRoutingScheme,
other_account_routing_scheme = counterparty.otherAccountRoutingScheme,
other_bank_routing_address = counterparty.otherBankRoutingAddress,
other_account_routing_scheme = counterparty.otherAccountRoutingScheme,
other_account_routing_address = counterparty.otherAccountRoutingAddress,
other_account_secondary_routing_scheme = counterparty.otherAccountSecondaryRoutingScheme,
other_account_secondary_routing_address = counterparty.otherAccountSecondaryRoutingAddress,
other_branch_routing_scheme = counterparty.otherBranchRoutingScheme,
other_branch_routing_address =counterparty.otherBranchRoutingAddress,
is_beneficiary = counterparty.isBeneficiary
is_beneficiary = counterparty.isBeneficiary,
bespoke= counterparty.bespoke
)
}

View File

@ -200,7 +200,6 @@ object OBPAPI2_2_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w
Implementations2_1_0.addCardForBank ::
Implementations2_1_0.getUsers ::
Implementations2_1_0.createTransactionType ::
Implementations2_1_0.createCounterparty ::
Implementations2_1_0.getAtm ::
Implementations2_1_0.getBranch ::
Implementations2_1_0.updateBranch ::
@ -230,6 +229,7 @@ object OBPAPI2_2_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w
Implementations2_2_0.getConnectorMetrics ::
Implementations2_2_0.createConsumer ::
Implementations2_2_0.createProduct ::
Implementations2_2_0.createCounterparty ::
Nil
val allResourceDocs = Implementations2_2_0.resourceDocs ++

View File

@ -202,7 +202,6 @@ object OBPAPI3_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w
Implementations2_1_0.addCardForBank ::
Implementations2_1_0.getUsers ::
Implementations2_1_0.createTransactionType ::
Implementations2_1_0.createCounterparty ::
// Implementations2_1_0.getAtm :: //now in V300
// Implementations2_1_0.getBranch :: //now in V300
Implementations2_1_0.updateBranch ::
@ -226,6 +225,7 @@ object OBPAPI3_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w
Implementations2_2_0.createProduct ::
Implementations2_2_0.config ::
Implementations2_2_0.getConnectorMetrics ::
Implementations2_2_0.createCounterparty ::
Nil

View File

@ -28,7 +28,7 @@ import java.util.{Date, Locale, UUID}
import code.accountholder.AccountHolders
import code.api.util.ErrorMessages
import code.api.v2_1_0.TransactionRequestCommonBodyJSON
import code.api.v2_1_0.{PostCounterpartyBespoke, TransactionRequestCommonBodyJSON}
import code.atms.Atms.AtmId
import code.atms.MappedAtm
import code.bankconnectors.vMar2017.{InboundAdapterInfo, KafkaMappedConnector_vMar2017}
@ -1246,6 +1246,10 @@ object KafkaMappedConnector extends Connector with KafkaHelper with MdcLoggable
def otherBranchRoutingScheme: String = counterparty.other_branch_routing_scheme
def otherBranchRoutingAddress: String = counterparty.other_branch_routing_address
def isBeneficiary : Boolean = counterparty.is_beneficiary
def description: String = ""
def otherAccountSecondaryRoutingScheme: String = ""
def otherAccountSecondaryRoutingAddress: String = ""
def bespoke: List[PostCounterpartyBespoke] = Nil
}
case class KafkaTransactionRequestTypeCharge(kafkaInboundTransactionRequestTypeCharge: KafkaInboundTransactionRequestTypeCharge) extends TransactionRequestTypeCharge{

View File

@ -33,7 +33,7 @@ import code.accountholder.AccountHolders
import code.api.util.APIUtil.saveConnectorMetric
import code.api.util.ErrorMessages
import code.api.util.ErrorMessages._
import code.api.v2_1_0.TransactionRequestCommonBodyJSON
import code.api.v2_1_0.{PostCounterpartyBespoke, TransactionRequestCommonBodyJSON}
import code.atms.Atms.{AtmId, AtmT}
import code.atms.{Atms, MappedAtm}
import code.bankconnectors.vMar2017.{InboundAdapterInfo, KafkaMappedConnector_vMar2017}
@ -1462,6 +1462,10 @@ object KafkaMappedConnector_JVMcompatible extends Connector with KafkaHelper wit
def otherBranchRoutingScheme: String = counterparty.other_branch_routing_scheme
def otherBranchRoutingAddress: String = counterparty.other_branch_routing_address
def isBeneficiary : Boolean = counterparty.is_beneficiary
def description: String = ""
def otherAccountSecondaryRoutingScheme: String = ""
def otherAccountSecondaryRoutingAddress: String = ""
def bespoke: List[PostCounterpartyBespoke] = Nil
}
case class KafkaTransactionRequestTypeCharge(kafkaInboundTransactionRequestTypeCharge: KafkaInboundTransactionRequestTypeCharge) extends TransactionRequestTypeCharge{

View File

@ -1496,6 +1496,10 @@ object LocalMappedConnector extends Connector with MdcLoggable {
otherBankRoutingAddress = otherBankRoutingAddress,
otherBranchRoutingScheme = otherBranchRoutingScheme,
otherBranchRoutingAddress = otherBranchRoutingAddress,
isBeneficiary = isBeneficiary
isBeneficiary = isBeneficiary,
otherAccountSecondaryRoutingScheme = otherAccountSecondaryRoutingScheme,
otherAccountSecondaryRoutingAddress = otherAccountSecondaryRoutingAddress,
description = description,
bespoke = bespoke
)
}

View File

@ -35,6 +35,7 @@ import java.text.SimpleDateFormat
import java.util.{Date, Locale}
import code.api.util.APIUtil.{InboundMessageBase, MessageDoc, OutboundMessageBase}
import code.api.v2_1_0.PostCounterpartyBespoke
import code.bankconnectors.InboundUser
import code.fx.FXRate
import code.metadata.counterparties.CounterpartyTrait
@ -296,6 +297,10 @@ case class CounterpartyTrait2(counterparty: InboundCounterparty) extends Counter
def otherBranchRoutingScheme: String = counterparty.otherBranchRoutingScheme
def otherBranchRoutingAddress: String = counterparty.otherBranchRoutingAddress
def isBeneficiary: Boolean = counterparty.isBeneficiary
def description: String = ""
def otherAccountSecondaryRoutingScheme: String = ""
def otherAccountSecondaryRoutingAddress: String = ""
def bespoke: List[PostCounterpartyBespoke] = Nil
}
case class InboundStatusMessage(

View File

@ -2,6 +2,7 @@ package code.metadata.counterparties
import java.util.Date
import code.api.v2_1_0.PostCounterpartyBespoke
import code.model._
import code.remotedata.RemotedataCounterparties
import net.liftweb.common.Box
@ -46,7 +47,11 @@ trait Counterparties {
otherBankRoutingAddress: String,
otherBranchRoutingScheme: String,
otherBranchRoutingAddress: String,
isBeneficiary:Boolean
isBeneficiary:Boolean,
otherAccountSecondaryRoutingScheme: String,
otherAccountSecondaryRoutingAddress: String,
description: String,
bespoke: List[PostCounterpartyBespoke]
): Box[CounterpartyTrait]
def checkCounterpartyAvailable(
@ -79,18 +84,21 @@ trait Counterparties {
trait CounterpartyTrait {
def createdByUserId: String
def name: String
def description: String
def thisBankId: String
def thisAccountId: String
def thisViewId: String
def counterpartyId: String
def otherAccountRoutingScheme: String
def otherAccountRoutingAddress: String
def otherAccountSecondaryRoutingScheme: String
def otherAccountSecondaryRoutingAddress: String
def otherBankRoutingScheme: String
def otherBankRoutingAddress: String
def otherBranchRoutingScheme: String
def otherBranchRoutingAddress: String
def isBeneficiary : Boolean
def bespoke: List[PostCounterpartyBespoke]
}
class RemotedataCounterpartiesCaseClasses {
@ -112,7 +120,12 @@ class RemotedataCounterpartiesCaseClasses {
otherAccountRoutingScheme: String,
otherAccountRoutingAddress: String, otherBankRoutingScheme: String,
otherBranchRoutingScheme: String, otherBranchRoutingAddress: String,
otherBankRoutingAddress: String, isBeneficiary: Boolean)
otherBankRoutingAddress: String, isBeneficiary: Boolean,
otherAccountSecondaryRoutingScheme: String,
otherAccountSecondaryRoutingAddress: String,
description: String,
bespoke: List[PostCounterpartyBespoke]
)
case class checkCounterpartyAvailable(name: String, thisBankId: String, thisAccountId: String, thisViewId: String)

View File

@ -9,7 +9,7 @@ import code.users.Users
import code.util._
import net.liftweb.common.{Box, Full}
import code.util.Helper.MdcLoggable
import net.liftweb.mapper.{By, _}
import net.liftweb.mapper.{By, MappedString, _}
import net.liftweb.util.Helpers.tryo
object MapperCounterparties extends Counterparties with MdcLoggable {
@ -138,16 +138,19 @@ object MapperCounterparties extends Counterparties with MdcLoggable {
otherBankRoutingAddress : String,
otherBranchRoutingScheme: String,
otherBranchRoutingAddress: String,
isBeneficiary: Boolean
isBeneficiary: Boolean,
otherAccountSecondaryRoutingScheme: String,
otherAccountSecondaryRoutingAddress: String,
description: String,
bespoke: List[PostCounterpartyBespoke]
): Box[CounterpartyTrait] = {
val metadata = MappedCounterpartyMetadata.create
.thisBankId(thisBankId)
.thisAccountId(thisAccountId)
.holder(name)
.saveMe
Some(
MappedCounterparty.create
val mappedCounterparty = MappedCounterparty.create
.mCounterPartyId(metadata.metadataId)
.mName(name)
.mCreatedByUserId(createdByUserId)
@ -161,8 +164,25 @@ object MapperCounterparties extends Counterparties with MdcLoggable {
.mOtherBranchRoutingAddress(otherBranchRoutingAddress)
.mOtherBranchRoutingScheme(otherBranchRoutingScheme)
.mIsBeneficiary(isBeneficiary)
.mDescription(description)
.mOtherAccountSecondaryRoutingScheme(otherAccountSecondaryRoutingScheme)
.mOtherAccountSecondaryRoutingAddress(otherAccountSecondaryRoutingAddress)
.saveMe()
// This is especially for OneToMany table, to save a List to database.
bespoke.map(mBespoke => MappedCounterpartyBespoke.create
.mKey(mBespoke.key)
.mVaule(mBespoke.value)
.saveMe()
).map(
mappedBespoke =>
mappedCounterparty.mBespoke += mappedBespoke
)
Some(
mappedCounterparty
)
}
override def checkCounterpartyAvailable(
@ -392,7 +412,7 @@ class MappedCounterpartyWhereTag extends GeoTag with LongKeyedMapper[MappedCount
object MappedCounterpartyWhereTag extends MappedCounterpartyWhereTag with LongKeyedMetaMapper[MappedCounterpartyWhereTag]
class MappedCounterparty extends CounterpartyTrait with LongKeyedMapper[MappedCounterparty] with IdPK with CreatedUpdated {
class MappedCounterparty extends CounterpartyTrait with LongKeyedMapper[MappedCounterparty] with IdPK with CreatedUpdated with OneToMany[Long, MappedCounterparty] {
def getSingleton = MappedCounterparty
object mCreatedByUserId extends MappedString(this, 36)
@ -408,8 +428,10 @@ class MappedCounterparty extends CounterpartyTrait with LongKeyedMapper[MappedCo
object mOtherBranchRoutingScheme extends MappedString(this, 255)
object mOtherBranchRoutingAddress extends MappedString(this, 255)
object mIsBeneficiary extends MappedBoolean(this)
object mDescription extends MappedString(this, 36)
object mOtherAccountSecondaryRoutingScheme extends MappedString(this, 255)
object mOtherAccountSecondaryRoutingAddress extends MappedString(this, 255)
object mBespoke extends MappedOneToMany(MappedCounterpartyBespoke, MappedCounterpartyBespoke.mCounterparty, OrderBy(MappedCounterpartyBespoke.id, Ascending))
override def createdByUserId = mCreatedByUserId.get
override def name = mName.get
@ -424,8 +446,21 @@ class MappedCounterparty extends CounterpartyTrait with LongKeyedMapper[MappedCo
override def otherBranchRoutingAddress: String = mOtherBranchRoutingAddress.get
override def otherBankRoutingAddress: String = mOtherBankRoutingAddress.get
override def isBeneficiary: Boolean = mIsBeneficiary.get
override def description: String = mDescription.get
override def otherAccountSecondaryRoutingScheme: String = mOtherAccountSecondaryRoutingScheme.get
override def otherAccountSecondaryRoutingAddress: String = mOtherAccountSecondaryRoutingAddress.get
override def bespoke: List[PostCounterpartyBespoke] = mBespoke.map(a=>PostCounterpartyBespoke(a.mKey.get,a.mVaule.get)).toList
}
object MappedCounterparty extends MappedCounterparty with LongKeyedMetaMapper[MappedCounterparty] {
override def dbIndexes = UniqueIndex(mCounterPartyId) :: UniqueIndex(mName, mThisBankId, mThisAccountId, mThisViewId) :: super.dbIndexes
}
class MappedCounterpartyBespoke extends LongKeyedMapper[MappedCounterpartyBespoke] with IdPK {
def getSingleton = MappedCounterpartyBespoke
object mCounterparty extends MappedLongForeignKey(this, MappedCounterparty)
object mKey extends MappedString(this, 255)
object mVaule extends MappedString(this, 255)
}
object MappedCounterpartyBespoke extends MappedCounterpartyBespoke with LongKeyedMetaMapper[MappedCounterpartyBespoke]{}

View File

@ -2,6 +2,7 @@ package code.metadata.counterparties
import java.util.Date
import code.api.v2_1_0.PostCounterpartyBespoke
import code.model._
import net.liftweb.common.{Box, Empty}
import code.util.Helper.MdcLoggable
@ -120,7 +121,11 @@ object MongoCounterparties extends Counterparties with MdcLoggable {
otherBankRoutingAddress: String,
otherBranchRoutingScheme: String,
otherBranchRoutingAddress: String,
isBeneficiary: Boolean
isBeneficiary: Boolean,
otherAccountSecondaryRoutingScheme: String,
otherAccountSecondaryRoutingAddress: String,
description: String,
bespoke: List[PostCounterpartyBespoke]
): Box[CounterpartyTrait] = Empty
override def checkCounterpartyAvailable(

View File

@ -1,11 +1,14 @@
package code.remotedata
import java.util.Date
import akka.pattern.ask
import code.actorsystem.ObpActorInit
import code.api.v2_1_0.PostCounterpartyBespoke
import code.metadata.counterparties.{Counterparties, CounterpartyTrait, RemotedataCounterpartiesCaseClasses}
import code.model._
import net.liftweb.common.Box
import scala.collection.immutable.List
@ -42,7 +45,11 @@ object RemotedataCounterparties extends ObpActorInit with Counterparties {
otherBankRoutingAddress: String,
otherBranchRoutingScheme: String,
otherBranchRoutingAddress: String,
isBeneficiary: Boolean): Box[CounterpartyTrait] =
isBeneficiary: Boolean,
otherAccountSecondaryRoutingScheme: String,
otherAccountSecondaryRoutingAddress: String,
description: String,
bespoke: List[PostCounterpartyBespoke]): Box[CounterpartyTrait] =
extractFutureToBox(actor ? cc.createCounterparty( createdByUserId, thisBankId,
thisAccountId, thisViewId, name,
otherAccountRoutingScheme,
@ -51,7 +58,11 @@ object RemotedataCounterparties extends ObpActorInit with Counterparties {
otherBankRoutingAddress,
otherBranchRoutingScheme,
otherBranchRoutingAddress,
isBeneficiary))
isBeneficiary,
otherAccountSecondaryRoutingScheme,
otherAccountSecondaryRoutingAddress,
description,
bespoke))
override def checkCounterpartyAvailable(name: String, thisBankId: String, thisAccountId: String, thisViewId: String): Boolean =
extractFuture(actor ? cc.checkCounterpartyAvailable(name: String, thisBankId: String, thisAccountId: String, thisViewId: String))

View File

@ -4,6 +4,7 @@ import java.util.Date
import akka.actor.Actor
import code.actorsystem.ObpActorHelper
import code.api.v2_1_0.PostCounterpartyBespoke
import code.metadata.counterparties.{MapperCounterparties, RemotedataCounterpartiesCaseClasses}
import code.model._
import code.util.Helper.MdcLoggable
@ -24,15 +25,33 @@ class RemotedataCounterpartiesActor extends Actor with ObpActorHelper with MdcLo
name, otherAccountRoutingScheme,
otherAccountRoutingAddress, otherBankRoutingScheme,
otherBranchRoutingScheme, otherBranchRoutingAddress,
otherBankRoutingAddress, isBeneficiary) =>
otherBankRoutingAddress, isBeneficiary,
otherAccountSecondaryRoutingScheme: String,
otherAccountSecondaryRoutingAddress: String,
description: String,
bespoke: List[PostCounterpartyBespoke]
) =>
logger.debug("createCounterparty(" + createdByUserId + ", " + thisBankId + ", " + thisAccountId + ", " + thisViewId + ", " + name + ", "
+ otherAccountRoutingScheme +", "+ otherAccountRoutingAddress +", "+ otherBankRoutingScheme +", "+ otherBankRoutingAddress +", "+ otherBranchRoutingScheme+
", "+ otherBranchRoutingAddress+ ", "+ isBeneficiary+")")
sender ! extractResult(mapper.createCounterparty(createdByUserId, thisBankId, thisAccountId, thisViewId,
name, otherAccountRoutingScheme,
otherAccountRoutingAddress, otherBankRoutingScheme,
otherBranchRoutingScheme, otherBranchRoutingAddress,
otherBankRoutingAddress, isBeneficiary))
", "+ otherBranchRoutingAddress+ ", "+ isBeneficiary+", "+ otherAccountSecondaryRoutingScheme+", "+ otherAccountSecondaryRoutingAddress+", "+ description+", "+ bespoke+")")
sender ! extractResult(mapper.createCounterparty(
createdByUserId: String,
thisBankId: String,
thisAccountId : String,
thisViewId : String,
name: String,
otherAccountRoutingScheme : String,
otherAccountRoutingAddress : String,
otherBankRoutingScheme : String,
otherBankRoutingAddress : String,
otherBranchRoutingScheme: String,
otherBranchRoutingAddress: String,
isBeneficiary: Boolean,
otherAccountSecondaryRoutingScheme: String,
otherAccountSecondaryRoutingAddress: String,
description: String,
bespoke: List[PostCounterpartyBespoke]
))
case cc.getOrCreateMetadata(originalPartyBankId: BankId, originalPartyAccountId: AccountId, otherParty: Counterparty) =>
logger.debug("getOrCreateMetadata(" + originalPartyBankId +", " +originalPartyAccountId+otherParty+")")

View File

@ -1,14 +1,14 @@
package code.api.v2_1_0
package code.api.v2_2_0
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON
import code.api.util.APIUtil.OAuth._
import code.api.util.ErrorMessages
import code.model.{AccountId, ViewId}
import code.setup.DefaultUsers
import net.liftweb.json.JsonAST.{JField, JObject, JString}
import net.liftweb.json.JsonAST.{JArray, JField, JObject, JString}
import net.liftweb.json.Serialization.write
class CreateCounterpartyTest extends V210ServerSetup with DefaultUsers {
class CreateCounterpartyTest extends V220ServerSetup with DefaultUsers {
//The test Body should use the varible in SwaggerDefinitionsJson,
// Because this body will be used in API-Explorer
@ -38,7 +38,7 @@ class CreateCounterpartyTest extends V210ServerSetup with DefaultUsers {
val bankAccount = createAccountAndOwnerView(Some(resourceUser1), bankId, accountId, "EUR")
When("We make the request Create counterparty for an account")
val requestPost = (v2_1Request / "banks" / bankId.value / "accounts" / accountId.value / viewId.value / "counterparties" ).POST <@ (user1)
val requestPost = (v2_2Request / "banks" / bankId.value / "accounts" / accountId.value / viewId.value / "counterparties" ).POST <@ (user1)
val responsePost = makePostRequest(requestPost, write(counterpartyPostJSON))
Then("We should get a 200 and check all the fields")
@ -48,7 +48,8 @@ class CreateCounterpartyTest extends V210ServerSetup with DefaultUsers {
case JString(i) => i
case _ => ""
}
accountRoutingAddress should equal(counterpartyPostJSON.other_account_routing_address)
accountRoutingAddress should equal(counterpartyPostJSON.other_account_routing_address)
}
@ -62,7 +63,7 @@ class CreateCounterpartyTest extends V210ServerSetup with DefaultUsers {
val ownerView = createOwnerView(bankId, accountId)
grantAccessToView(resourceUser1, ownerView)
val requestPost = (v2_1Request / "banks" / bankId.value / "accounts" / accountId.value / viewId.value / "counterparties" ).POST <@ (user1)
val requestPost = (v2_2Request / "banks" / bankId.value / "accounts" / accountId.value / viewId.value / "counterparties" ).POST <@ (user1)
val responsePost = makePostRequest(requestPost, write(counterpartyPostJSON))
Then("We should get a 400")
responsePost.code should equal(400)
@ -80,7 +81,7 @@ class CreateCounterpartyTest extends V210ServerSetup with DefaultUsers {
val bankAccount = createAccountAndOwnerView(Some(resourceUser1), bankId, accountId, "EUR")
When("We make the request Create counterparty for an account")
val requestPost = (v2_1Request / "banks" / bankId.value / "accounts" / accountId.value / viewId.value / "counterparties" ).POST <@ (user1)
val requestPost = (v2_2Request / "banks" / bankId.value / "accounts" / accountId.value / viewId.value / "counterparties" ).POST <@ (user1)
var responsePost = makePostRequest(requestPost, write(counterpartyPostJSON))
Then("We make the request again, the same name/bank_id/account_id/view_id")

View File

@ -4,6 +4,7 @@ import java.util.{Date, UUID}
import bootstrap.liftweb.ToSchemify
import code.accountholder.AccountHolders
import code.api.v2_1_0.PostCounterpartyBespoke
import code.entitlement.Entitlement
import code.metadata.counterparties.{Counterparties, CounterpartyTrait}
import code.model._
@ -46,7 +47,11 @@ trait LocalMappedConnectorTestSetup extends TestConnectorSetupWithStandardPermis
otherBankRoutingAddress = bankId,
otherBranchRoutingScheme ="OBP",
otherBranchRoutingAddress ="Berlin",
isBeneficiary = isBeneficiary
isBeneficiary = isBeneficiary,
otherAccountSecondaryRoutingScheme ="String",
otherAccountSecondaryRoutingAddress ="String",
description = "String",
bespoke = Nil
).openOrThrowException("Attempted to open an empty Box.")
}