Merge pull request #864 from hongwei1/develop

fixed the create Explicit Counterparty added the metadata for it
This commit is contained in:
Simon Redfern 2017-12-13 11:25:18 +01:00 committed by GitHub
commit 9d1cedcd63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 105 additions and 35 deletions

View File

@ -1649,7 +1649,6 @@ object SwaggerDefinitionsJSON {
value = "englishDescription"
)
//CM need to move into V220
val postCounterpartyJSON = PostCounterpartyJSON(
name = "CounterpartyName",
description ="My landlord",
@ -1795,6 +1794,13 @@ object SwaggerDefinitionsJSON {
other_account_secondary_routing_address= postCounterpartyJSON.other_bank_routing_scheme,
bespoke = postCounterpartyJSON.bespoke
)
val counterpartyMetadataJson = CounterpartyMetadataJson(publicAlias = "String")
val counterpartyWithMetadataJson = CounterpartyWithMetadataJson(
counterparty = counterpartyJsonV220,
metadata = counterpartyMetadataJson
)
val counterpartiesJsonV220 = CounterpartiesJsonV220(
counterparties = List(counterpartyJsonV220)

View File

@ -488,6 +488,7 @@ object SwaggerJSONFactory {
case Some(List(f,_*)) => "\"" + key + """": {"type": "array", "items":{"$ref": "#/definitions/""" +f.getClass.getSimpleName ++"\"}}"
//Single object
case Some(f) => "\"" + key + """": {"$ref":"#/definitions/""" +f.getClass.getSimpleName +"\"}"
case null => "unknown"
case f => "\"" + key + """": {"$ref":"#/definitions/""" +f.getClass.getSimpleName +"\"}"
case _ => "unknown"
}

View File

@ -229,9 +229,10 @@ val dateformat = new java.text.SimpleDateFormat("yyyy-MM-dd")
val ViewIdNotSupported = "OBP-30034: This ViewId is do not supported. Only support four now: Owner, Public, Accountant, Auditor."
val UserCustomerLinkNotFound = "OBP-30035: User Customer Link not found"
val CreateOrUpdateCounterpartyMetadataError = "OBP-30036: Could not create or update CounterpartyMetadata"
val CounterpartyMetadataNotFound = "OBP-30037: CounterpartyMetadata not found. Please specify valid values for BANK_ID, ACCOUNT_ID and COUNTERPARTY_ID. "
// Meetings

View File

@ -5,14 +5,12 @@ import java.util.{Date, Locale, UUID}
import code.actorsystem.ObpActorConfig
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._
import code.api.util.APIUtil.{emptyObjectJson, _}
import code.api.util.APIUtil._
import code.api.util.ApiRole._
import code.api.util.ApiSession.updateSessionContext
import code.api.util.ErrorMessages.{BankAccountNotFound, _}
import code.api.util.{ApiRole, ErrorMessages}
import code.api.util.{APIUtil, ApiRole, ErrorMessages}
import code.api.v2_1_0._
import code.api.v2_2_0.JSONFactory220.transformV220ToBranch
import code.api.v3_0_0.JSONFactory300
import code.bankconnectors._
import code.bankconnectors.vMar2017.JsonFactory_vMar2017
import code.consumer.Consumers
@ -31,8 +29,6 @@ import net.liftweb.util.Props
import scala.collection.immutable.Nil
import scala.collection.mutable.ArrayBuffer
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
@ -325,7 +321,7 @@ trait APIMethods220 {
|
|${authenticationRequiredMessage(true)}""",
emptyObjectJson,
counterpartyJsonV220,
counterpartyWithMetadataJson,
List(UserNotLoggedIn, BankNotFound, UnknownError),
Catalogs(Core, PSD2, OBWG),
List(apiTagAccount)
@ -341,9 +337,10 @@ trait APIMethods220 {
view <- View.fromUrl(viewId, account)?~! ViewNotFound
canAddCounterparty <- booleanToBox(view.canAddCounterparty == true, s"${ViewNoPermission}canAddCounterparty")
canUserAccessView <- Full(account.permittedViews(user).find(_ == viewId)) ?~! UserNoPermissionAccessView
counterpartyMetadata <- Counterparties.counterparties.vend.getMetadata(bankId, accountId, counterpartyId.value) ?~! CounterpartyMetadataNotFound
counterparty <- Connector.connector.vend.getCounterpartyByCounterpartyId(counterpartyId)
} yield {
val counterpartyJson = JSONFactory220.createCounterpartyJSON(counterparty)
val counterpartyJson = JSONFactory220.createCounterpartyWithMetadataJSON(counterparty,counterpartyMetadata)
successJsonResponse(Extraction.decompose(counterpartyJson))
}
}
@ -1019,7 +1016,7 @@ trait APIMethods220 {
|${authenticationRequiredMessage(true)}
|""",
postCounterpartyJSON,
counterpartyJsonV220,
counterpartyWithMetadataJson,
List(
UserNotLoggedIn,
InvalidAccountIdFormat,
@ -1052,7 +1049,13 @@ trait APIMethods220 {
checkAvailable <- tryo(assert(Counterparties.counterparties.vend.
checkCounterpartyAvailable(postJson.name,bankId.value, accountId.value,viewId.value) == true)
) ?~! CounterpartyAlreadyExists
//This is the `EXPLICIT` Counterparty, we also create the metaData for it
counterpartyId <- Full(APIUtil.createExplicitCounterpartyId())
counterpartyMetadata <- Counterparties.counterparties.vend.getOrCreateMetadata(bankId, accountId, counterpartyId, postJson.name) ?~! CreateOrUpdateCounterpartyMetadataError
counterparty <- Connector.connector.vend.createCounterparty(
counterpartyId=counterpartyMetadata.getCounterpartyId,
name=postJson.name,
description=postJson.description,
createdByUserId=u.userId,
@ -1070,13 +1073,8 @@ trait APIMethods220 {
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)
val list = JSONFactory220.createCounterpartyWithMetadataJSON(counterparty,counterpartyMetadata)
successJsonResponse(Extraction.decompose(list))
}
}

View File

@ -46,7 +46,7 @@ import code.products.Products.Product
import code.fx.FXRate
import code.metadata.counterparties.CounterpartyTrait
import code.metrics.{APIMetric, ConnectorMetric}
import code.model._
import code.model.{CounterpartyMetadata, _}
import code.users.Users
import net.liftweb.common.{Box, Full}
//import net.liftweb.common.Box
@ -145,6 +145,10 @@ case class FXRateJsonV220(
effective_date: Date
)
case class CounterpartyWithMetadataJson(
counterparty: CounterpartyJsonV220,
metadata: CounterpartyMetadataJson
)
case class CounterpartyJsonV220(
name: String,
description: String,
@ -165,6 +169,16 @@ case class CounterpartyJsonV220(
bespoke:List[PostCounterpartyBespoke]
)
case class CounterpartyMetadataJson(
publicAlias : String, // Only have this value when we create explict counterparty
moreInfo : String = null,
url : String = null,
imageURL : String = null,
openCorporatesURL : String = null,
corporateLocation : GeoTag = null,
physicalLocation : GeoTag = null,
privateAlias : String = null
)
case class CounterpartiesJsonV220(
counterparties: List[CounterpartyJsonV220]
)
@ -439,8 +453,9 @@ object JSONFactory220{
)
}
def createCounterpartyJSON(counterparty: CounterpartyTrait): CounterpartyJsonV220 = {
CounterpartyJsonV220(
def createCounterpartyWithMetadataJSON(counterparty: CounterpartyTrait, counterpartyMetadata: CounterpartyMetadata): CounterpartyWithMetadataJson = {
CounterpartyWithMetadataJson(
CounterpartyJsonV220(
name = counterparty.name,
description = counterparty.description,
created_by_user_id = counterparty.createdByUserId,
@ -458,8 +473,34 @@ object JSONFactory220{
other_branch_routing_address =counterparty.otherBranchRoutingAddress,
is_beneficiary = counterparty.isBeneficiary,
bespoke= counterparty.bespoke
),
CounterpartyMetadataJson(
publicAlias = counterpartyMetadata.getPublicAlias
)
)
}
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_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,
bespoke= counterparty.bespoke
)
}
def createCounterpartiesJSON(counterparties : List[CounterpartyTrait]) : CounterpartiesJsonV220 = {
val list : List[CounterpartyJsonV220] = counterparties.map(createCounterpartyJSON)

View File

@ -1227,6 +1227,7 @@ trait Connector extends MdcLoggable{
}
def createCounterparty(
counterpartyId: String,
name: String,
description: String,
createdByUserId: String,

View File

@ -1538,6 +1538,7 @@ object LocalMappedConnector extends Connector with MdcLoggable {
}
override def createCounterparty(
counterpartyId: String,
name: String,
description: String,
createdByUserId: String,
@ -1556,6 +1557,7 @@ object LocalMappedConnector extends Connector with MdcLoggable {
bespoke: List[PostCounterpartyBespoke]
): Box[CounterpartyTrait] =
Counterparties.counterparties.vend.createCounterparty(
counterpartyId = counterpartyId,
createdByUserId = createdByUserId,
thisBankId = thisBankId,
thisAccountId = thisAccountId,

View File

@ -187,6 +187,7 @@ case class InternalGetTransactionRequests(
)
case class OutboundCounterparty(
counterpartyId: String,
name: String,
description: String,
createdByUserId: String,

View File

@ -989,6 +989,7 @@ trait KafkaMappedConnector_vJune2017 extends Connector with KafkaHelper with Mdc
OutboundCreateCounterparty(
authInfoExample,
OutboundCounterparty(
counterpartyId= "String",
name = "name",
description = "description",
createdByUserId = "createdByUserId",
@ -1039,6 +1040,7 @@ trait KafkaMappedConnector_vJune2017 extends Connector with KafkaHelper with Mdc
)
)
override def createCounterparty(
counterpartyId: String,
name: String,
description: String,
createdByUserId: String,
@ -1059,6 +1061,7 @@ trait KafkaMappedConnector_vJune2017 extends Connector with KafkaHelper with Mdc
val req = OutboundCreateCounterparty(
authInfo = AuthInfo(currentResourceUserId, getUsername, getCbsToken),
counterparty = OutboundCounterparty(
counterpartyId: String,
name: String,
description: String,
createdByUserId: String,

View File

@ -36,6 +36,7 @@ trait Counterparties {
def getCounterparties(thisBankId: BankId, thisAccountId: AccountId, viewId: ViewId): Box[List[CounterpartyTrait]]
def createCounterparty(
counterpartyId: String,
createdByUserId: String,
thisBankId: String,
thisAccountId: String,
@ -115,7 +116,7 @@ class RemotedataCounterpartiesCaseClasses {
case class getCounterparties(thisBankId: BankId, thisAccountId: AccountId, viewId: ViewId)
case class createCounterparty(
createdByUserId: String, thisBankId: String, thisAccountId: String, thisViewId: String,
counterpartyId: String,createdByUserId: String, thisBankId: String, thisAccountId: String, thisViewId: String,
name: String,
otherAccountRoutingScheme: String,
otherAccountRoutingAddress: String, otherBankRoutingScheme: String,

View File

@ -129,7 +129,8 @@ object MapperCounterparties extends Counterparties with MdcLoggable {
By(MappedCounterparty.mThisViewId, viewId.value)))
}
override def createCounterparty(createdByUserId: String,
override def createCounterparty(counterpartyId: String,
createdByUserId: String,
thisBankId: String,
thisAccountId : String,
thisViewId : String,

View File

@ -112,6 +112,7 @@ object MongoCounterparties extends Counterparties with MdcLoggable {
override def getCounterpartyByIban(counterPartyId : String): Box[CounterpartyTrait] = Empty
override def createCounterparty(
counterpartyId: String,
createdByUserId: String,
thisBankId: String,
thisAccountId: String,

View File

@ -34,7 +34,8 @@ object RemotedataCounterparties extends ObpActorInit with Counterparties {
override def getCounterparties(thisBankId: BankId, thisAccountId: AccountId, viewId: ViewId): Box[List[CounterpartyTrait]] =
extractFutureToBox(actor ? cc.getCounterparties(thisBankId, thisAccountId, viewId))
override def createCounterparty(createdByUserId: String,
override def createCounterparty(counterpartyId: String,
createdByUserId: String,
thisBankId: String,
thisAccountId: String,
thisViewId: String,
@ -50,7 +51,7 @@ object RemotedataCounterparties extends ObpActorInit with Counterparties {
otherAccountSecondaryRoutingAddress: String,
description: String,
bespoke: List[PostCounterpartyBespoke]): Box[CounterpartyTrait] =
extractFutureToBox(actor ? cc.createCounterparty( createdByUserId, thisBankId,
extractFutureToBox(actor ? cc.createCounterparty( counterpartyId, createdByUserId, thisBankId,
thisAccountId, thisViewId, name,
otherAccountRoutingScheme,
otherAccountRoutingAddress,

View File

@ -21,7 +21,7 @@ class RemotedataCounterpartiesActor extends Actor with ObpActorHelper with MdcLo
logger.debug("checkCounterpartyAvailable(" + name +", "+ thisBankId +", "+ thisAccountId +", "+ thisViewId +")")
sender ! extractResult(mapper.checkCounterpartyAvailable(name: String, thisBankId: String, thisAccountId: String, thisViewId: String))
case cc.createCounterparty(createdByUserId, thisBankId, thisAccountId, thisViewId,
case cc.createCounterparty(counterpartyId, createdByUserId, thisBankId, thisAccountId, thisViewId,
name, otherAccountRoutingScheme,
otherAccountRoutingAddress, otherBankRoutingScheme,
otherBranchRoutingScheme, otherBranchRoutingAddress,
@ -31,10 +31,11 @@ class RemotedataCounterpartiesActor extends Actor with ObpActorHelper with MdcLo
description: String,
bespoke: List[PostCounterpartyBespoke]
) =>
logger.debug("createCounterparty(" + createdByUserId + ", " + thisBankId + ", " + thisAccountId + ", " + thisViewId + ", " + name + ", "
logger.debug("createCounterparty(" +counterpartyId +createdByUserId + ", " + thisBankId + ", " + thisAccountId + ", " + thisViewId + ", " + name + ", "
+ otherAccountRoutingScheme +", "+ otherAccountRoutingAddress +", "+ otherBankRoutingScheme +", "+ otherBankRoutingAddress +", "+ otherBranchRoutingScheme+
", "+ otherBranchRoutingAddress+ ", "+ isBeneficiary+", "+ otherAccountSecondaryRoutingScheme+", "+ otherAccountSecondaryRoutingAddress+", "+ description+", "+ bespoke+")")
sender ! extractResult(mapper.createCounterparty(
counterpartyId:String,
createdByUserId: String,
thisBankId: String,
thisAccountId : String,

View File

@ -0,0 +1,3 @@
ALTER TABLE "mappedcounterpartymetadata" ALTER COLUMN "counterpartyid" type varchar(44);
ALTER TABLE "mappedcounterparty" ALTER COLUMN "mcounterpartyid" type varchar(44);
ALTER TABLE "mappedtransaction" ALTER COLUMN "cpcounterpartyid" type varchar(44);

View File

@ -24,6 +24,12 @@ class SwaggerFactoryUnitTest extends FlatSpec
logger.debug("{"+translateCaseClassToSwaggerFormatString+"}")
translateCaseClassToSwaggerFormatString should not include("$colon")
}
it should ("Procee `null` in translateEntity function") in{
val translateCaseClassToSwaggerFormatString: String = SwaggerJSONFactory.translateEntity(SwaggerDefinitionsJSON.counterpartyMetadataJson)
logger.debug("{"+translateCaseClassToSwaggerFormatString+"}")
translateCaseClassToSwaggerFormatString should not include("$colon")
}
it should ("Test all the case classes in SwaggerDefinitionsJSON") in{
val allSwaggerDefinitionCaseClasses = SwaggerDefinitionsJSON.allFields

View File

@ -95,9 +95,9 @@ class TransactionRequestsTest extends V210ServerSetup with DefaultUsers {
//prepare for counterparty and SEPA stuff
//For SEPA, otherAccountRoutingScheme must be 'IBAN'
val counterPartySEPA = createCounterparty(bankId.value, accountId2.value, "IBAN", "IBAN", true, UUID.randomUUID.toString);
val counterPartySEPA = createCounterparty(bankId.value, accountId2.value, "IBAN", "IBAN", true, UUID.randomUUID.toString, UUID.randomUUID.toString);
//For Counterpart local mapper, the mOtherAccountRoutingScheme='OBP' and mOtherBankRoutingScheme = 'OBP'
val counterPartyCounterparty = createCounterparty(bankId.value, accountId2.value, "IBAN", "OBP", true, UUID.randomUUID.toString);
val counterPartyCounterparty = createCounterparty(bankId.value, accountId2.value, "IBAN", "OBP", true, UUID.randomUUID.toString, UUID.randomUUID.toString);
var transactionRequestBodySEPA = TransactionRequestBodySEPAJSON(bodyValue, IbanJson(counterPartySEPA.otherAccountRoutingAddress), discription, sharedChargePolicy)

View File

@ -44,14 +44,14 @@ class CreateCounterpartyTest extends V220ServerSetup with DefaultUsers {
Then("We should get a 200 and check all the fields")
responsePost.code should equal(200)
var accountRoutingAddress = (responsePost.body \ "other_account_routing_address" ) match {
var accountRoutingAddress = (responsePost.body \ "counterparty" \ "other_account_routing_address" ) match {
case JString(i) => i
case _ => ""
}
accountRoutingAddress should equal(counterpartyPostJSON.other_account_routing_address)
val counterpartyId = (responsePost.body \ "counterparty_id" ) match {
val counterpartyId = (responsePost.body \ "counterparty" \ "counterparty_id" ) match {
case JString(i) => i
case _ => ""
}
@ -65,7 +65,7 @@ class CreateCounterpartyTest extends V220ServerSetup with DefaultUsers {
Then("We should get a 200 and check all the fields")
responsePost.code should equal(200)
val accountRoutingAddressGet = (responsePost.body \ "other_account_routing_address" ) match {
val accountRoutingAddressGet = (responsePost.body \ "counterparty" \ "other_account_routing_address" ) match {
case JString(i) => i
case _ => ""
}
@ -73,7 +73,7 @@ class CreateCounterpartyTest extends V220ServerSetup with DefaultUsers {
accountRoutingAddressGet should equal(counterpartyPostJSON.other_account_routing_address)
val counterpartyIdGet = (responsePost.body \ "counterparty_id" ) match {
val counterpartyIdGet = (responsePost.body \ "counterparty" \ "counterparty_id" ) match {
case JString(i) => i
case _ => ""
}

View File

@ -35,8 +35,10 @@ trait LocalMappedConnectorTestSetup extends TestConnectorSetupWithStandardPermis
.saveMe
}
override protected def createCounterparty(bankId: String, accountId: String, accountRoutingAddress: String, otherAccountRoutingScheme: String, isBeneficiary: Boolean, createdByUserId: String): CounterpartyTrait = {
Counterparties.counterparties.vend.createCounterparty(createdByUserId = createdByUserId,
override protected def createCounterparty(bankId: String, accountId: String, accountRoutingAddress: String, otherAccountRoutingScheme: String, isBeneficiary: Boolean, counterpartyId: String, createdByUserId:String): CounterpartyTrait = {
Counterparties.counterparties.vend.createCounterparty(
counterpartyId= counterpartyId,
createdByUserId = createdByUserId,
thisBankId = bankId,
thisAccountId = accountId,
thisViewId = "",

View File

@ -15,7 +15,7 @@ trait TestConnectorSetup {
protected def createTransaction(account : BankAccount, startDate : Date, finishDate : Date)
protected def updateAccountCurrency(bankId: BankId, accountId : AccountId, currency : String) : BankAccount
protected def createCounterparty(bankId: String, accountId: String, accountRoutingAddress: String, otherAccountRoutingScheme: String, isBeneficiary: Boolean, counterpartyId: String): CounterpartyTrait
protected def createCounterparty(bankId: String, accountId: String, accountRoutingAddress: String, otherAccountRoutingScheme: String, isBeneficiary: Boolean, counterpartyId: String, createdByUserId:String): CounterpartyTrait
/**
* This method, will do three things: