diff --git a/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala b/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala index 64702823b..de8a60f40 100644 --- a/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala +++ b/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala @@ -1798,7 +1798,23 @@ object SwaggerDefinitionsJSON { val counterpartyMetadataJson = CounterpartyMetadataJson(publicAlias = "String") val counterpartyWithMetadataJson = CounterpartyWithMetadataJson( - counterparty = counterpartyJsonV220, + 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 = 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, metadata = counterpartyMetadataJson ) diff --git a/src/main/scala/code/api/v2_2_0/APIMethods220.scala b/src/main/scala/code/api/v2_2_0/APIMethods220.scala index c83642785..b1b0f700b 100644 --- a/src/main/scala/code/api/v2_2_0/APIMethods220.scala +++ b/src/main/scala/code/api/v2_2_0/APIMethods220.scala @@ -302,6 +302,9 @@ trait APIMethods220 { canAddCounterparty <- booleanToBox(view.canAddCounterparty == true, s"${ViewNoPermission}canAddCounterparty") canUserAccessView <- Full(account.permittedViews(user).find(_ == viewId)) ?~! UserNoPermissionAccessView counterparties <- Connector.connector.vend.getCounterparties(bankId,accountId,viewId) + //Here we need create the metadata for all the explicit counterparties. maybe show them in json response. + //Note: actually we need update all the counterparty metadata when they from adapter. Some counterparties may be the first time to api, there is no metadata. + _ <- tryo {for{counterparty <-counterparties}Counterparties.counterparties.vend.getOrCreateMetadata(bankId, accountId, counterparty.counterpartyId, counterparty.name)} ?~! CreateOrUpdateCounterpartyMetadataError } yield { val counterpartiesJson = JSONFactory220.createCounterpartiesJSON(counterparties) successJsonResponse(Extraction.decompose(counterpartiesJson)) @@ -1050,12 +1053,7 @@ trait APIMethods220 { 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, @@ -1073,6 +1071,9 @@ trait APIMethods220 { isBeneficiary=postJson.is_beneficiary, bespoke=postJson.bespoke ) + + counterpartyMetadata <- Counterparties.counterparties.vend.getOrCreateMetadata(bankId, accountId, counterparty.counterpartyId, postJson.name) ?~! CreateOrUpdateCounterpartyMetadataError + } yield { val list = JSONFactory220.createCounterpartyWithMetadataJSON(counterparty,counterpartyMetadata) successJsonResponse(Extraction.decompose(list)) diff --git a/src/main/scala/code/api/v2_2_0/JSONFactory2.2.0.scala b/src/main/scala/code/api/v2_2_0/JSONFactory2.2.0.scala index 6591343b2..09842933e 100644 --- a/src/main/scala/code/api/v2_2_0/JSONFactory2.2.0.scala +++ b/src/main/scala/code/api/v2_2_0/JSONFactory2.2.0.scala @@ -146,7 +146,23 @@ case class FXRateJsonV220( ) case class CounterpartyWithMetadataJson( - counterparty: CounterpartyJsonV220, + name: String, + description: String, + created_by_user_id: String, + this_bank_id: String, + this_account_id: String, + this_view_id: String, + counterparty_id: String, + other_bank_routing_scheme: String, + other_bank_routing_address: String, + other_branch_routing_scheme: String, + other_branch_routing_address: String, + other_account_routing_scheme: String, + other_account_routing_address: String, + other_account_secondary_routing_scheme: String, + other_account_secondary_routing_address: String, + is_beneficiary: Boolean, + bespoke:List[PostCounterpartyBespoke], metadata: CounterpartyMetadataJson ) case class CounterpartyJsonV220( @@ -455,7 +471,6 @@ object JSONFactory220{ def createCounterpartyWithMetadataJSON(counterparty: CounterpartyTrait, counterpartyMetadata: CounterpartyMetadata): CounterpartyWithMetadataJson = { CounterpartyWithMetadataJson( - CounterpartyJsonV220( name = counterparty.name, description = counterparty.description, created_by_user_id = counterparty.createdByUserId, @@ -472,9 +487,8 @@ object JSONFactory220{ other_branch_routing_scheme = counterparty.otherBranchRoutingScheme, other_branch_routing_address =counterparty.otherBranchRoutingAddress, is_beneficiary = counterparty.isBeneficiary, - bespoke= counterparty.bespoke - ), - CounterpartyMetadataJson( + bespoke= counterparty.bespoke, + metadata=CounterpartyMetadataJson( publicAlias = counterpartyMetadata.getPublicAlias ) ) diff --git a/src/main/scala/code/bankconnectors/Connector.scala b/src/main/scala/code/bankconnectors/Connector.scala index 830c1ee5c..35c471698 100644 --- a/src/main/scala/code/bankconnectors/Connector.scala +++ b/src/main/scala/code/bankconnectors/Connector.scala @@ -1227,7 +1227,6 @@ trait Connector extends MdcLoggable{ } def createCounterparty( - counterpartyId: String, name: String, description: String, createdByUserId: String, diff --git a/src/main/scala/code/bankconnectors/LocalMappedConnector.scala b/src/main/scala/code/bankconnectors/LocalMappedConnector.scala index 64247dbbc..7afbc345d 100644 --- a/src/main/scala/code/bankconnectors/LocalMappedConnector.scala +++ b/src/main/scala/code/bankconnectors/LocalMappedConnector.scala @@ -1538,7 +1538,6 @@ object LocalMappedConnector extends Connector with MdcLoggable { } override def createCounterparty( - counterpartyId: String, name: String, description: String, createdByUserId: String, @@ -1557,7 +1556,6 @@ object LocalMappedConnector extends Connector with MdcLoggable { bespoke: List[PostCounterpartyBespoke] ): Box[CounterpartyTrait] = Counterparties.counterparties.vend.createCounterparty( - counterpartyId = counterpartyId, createdByUserId = createdByUserId, thisBankId = thisBankId, thisAccountId = thisAccountId, diff --git a/src/main/scala/code/bankconnectors/vJune2017/KafkaJsonFactory_vJune2017.scala b/src/main/scala/code/bankconnectors/vJune2017/KafkaJsonFactory_vJune2017.scala index 5bd02f6b0..67d73df02 100644 --- a/src/main/scala/code/bankconnectors/vJune2017/KafkaJsonFactory_vJune2017.scala +++ b/src/main/scala/code/bankconnectors/vJune2017/KafkaJsonFactory_vJune2017.scala @@ -187,7 +187,6 @@ case class InternalGetTransactionRequests( ) case class OutboundCounterparty( - counterpartyId: String, name: String, description: String, createdByUserId: String, diff --git a/src/main/scala/code/bankconnectors/vJune2017/KafkaMappedConnector_vJune2017.scala b/src/main/scala/code/bankconnectors/vJune2017/KafkaMappedConnector_vJune2017.scala index 81241680a..d61b4b99c 100644 --- a/src/main/scala/code/bankconnectors/vJune2017/KafkaMappedConnector_vJune2017.scala +++ b/src/main/scala/code/bankconnectors/vJune2017/KafkaMappedConnector_vJune2017.scala @@ -989,7 +989,6 @@ trait KafkaMappedConnector_vJune2017 extends Connector with KafkaHelper with Mdc OutboundCreateCounterparty( authInfoExample, OutboundCounterparty( - counterpartyId= "String", name = "name", description = "description", createdByUserId = "createdByUserId", @@ -1040,7 +1039,6 @@ trait KafkaMappedConnector_vJune2017 extends Connector with KafkaHelper with Mdc ) ) override def createCounterparty( - counterpartyId: String, name: String, description: String, createdByUserId: String, @@ -1061,7 +1059,6 @@ 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, diff --git a/src/main/scala/code/metadata/counterparties/Counterparties.scala b/src/main/scala/code/metadata/counterparties/Counterparties.scala index 0b4fac2ff..a56c3f31d 100644 --- a/src/main/scala/code/metadata/counterparties/Counterparties.scala +++ b/src/main/scala/code/metadata/counterparties/Counterparties.scala @@ -36,7 +36,6 @@ trait Counterparties { def getCounterparties(thisBankId: BankId, thisAccountId: AccountId, viewId: ViewId): Box[List[CounterpartyTrait]] def createCounterparty( - counterpartyId: String, createdByUserId: String, thisBankId: String, thisAccountId: String, @@ -116,7 +115,7 @@ class RemotedataCounterpartiesCaseClasses { case class getCounterparties(thisBankId: BankId, thisAccountId: AccountId, viewId: ViewId) case class createCounterparty( - counterpartyId: String,createdByUserId: String, thisBankId: String, thisAccountId: String, thisViewId: String, + createdByUserId: String, thisBankId: String, thisAccountId: String, thisViewId: String, name: String, otherAccountRoutingScheme: String, otherAccountRoutingAddress: String, otherBankRoutingScheme: String, diff --git a/src/main/scala/code/metadata/counterparties/MapperCounterparties.scala b/src/main/scala/code/metadata/counterparties/MapperCounterparties.scala index 3a3ff5fcf..f1b75dc10 100644 --- a/src/main/scala/code/metadata/counterparties/MapperCounterparties.scala +++ b/src/main/scala/code/metadata/counterparties/MapperCounterparties.scala @@ -129,7 +129,7 @@ object MapperCounterparties extends Counterparties with MdcLoggable { By(MappedCounterparty.mThisViewId, viewId.value))) } - override def createCounterparty(counterpartyId: String, + override def createCounterparty( createdByUserId: String, thisBankId: String, thisAccountId : String, @@ -148,13 +148,8 @@ object MapperCounterparties extends Counterparties with MdcLoggable { bespoke: List[PostCounterpartyBespoke] ): Box[CounterpartyTrait] = { - val counterpartyId = APIUtil.createExplicitCounterpartyId() - - //This is the `EXPLICIT` Counterparty, we also create the metaData for it - val metadata = Counterparties.counterparties.vend.getOrCreateMetadata(BankId(thisBankId), AccountId(thisAccountId), counterpartyId, name).openOrThrowException("Can not getOrCreateMetadata !") - val mappedCounterparty = MappedCounterparty.create - .mCounterPartyId(metadata.getCounterpartyId) + .mCounterPartyId(APIUtil.createExplicitCounterpartyId) //We create the Counterparty_Id here, it means, it will be create in each connnector. .mName(name) .mCreatedByUserId(createdByUserId) .mThisBankId(thisBankId) diff --git a/src/main/scala/code/metadata/counterparties/MongoCounterparties.scala b/src/main/scala/code/metadata/counterparties/MongoCounterparties.scala index 9c9ca2501..73d4ee444 100644 --- a/src/main/scala/code/metadata/counterparties/MongoCounterparties.scala +++ b/src/main/scala/code/metadata/counterparties/MongoCounterparties.scala @@ -112,7 +112,6 @@ 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, diff --git a/src/main/scala/code/remotedata/RemotedataCounterparties.scala b/src/main/scala/code/remotedata/RemotedataCounterparties.scala index 78e3689ef..a2a08f8cb 100644 --- a/src/main/scala/code/remotedata/RemotedataCounterparties.scala +++ b/src/main/scala/code/remotedata/RemotedataCounterparties.scala @@ -34,7 +34,7 @@ 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(counterpartyId: String, + override def createCounterparty( createdByUserId: String, thisBankId: String, thisAccountId: String, @@ -51,7 +51,7 @@ object RemotedataCounterparties extends ObpActorInit with Counterparties { otherAccountSecondaryRoutingAddress: String, description: String, bespoke: List[PostCounterpartyBespoke]): Box[CounterpartyTrait] = - extractFutureToBox(actor ? cc.createCounterparty( counterpartyId, createdByUserId, thisBankId, + extractFutureToBox(actor ? cc.createCounterparty(createdByUserId, thisBankId, thisAccountId, thisViewId, name, otherAccountRoutingScheme, otherAccountRoutingAddress, diff --git a/src/main/scala/code/remotedata/RemotedataCounterpartiesActor.scala b/src/main/scala/code/remotedata/RemotedataCounterpartiesActor.scala index 2f59fd0b5..026ee2684 100644 --- a/src/main/scala/code/remotedata/RemotedataCounterpartiesActor.scala +++ b/src/main/scala/code/remotedata/RemotedataCounterpartiesActor.scala @@ -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(counterpartyId, createdByUserId, thisBankId, thisAccountId, thisViewId, + case cc.createCounterparty(createdByUserId, thisBankId, thisAccountId, thisViewId, name, otherAccountRoutingScheme, otherAccountRoutingAddress, otherBankRoutingScheme, otherBranchRoutingScheme, otherBranchRoutingAddress, @@ -31,11 +31,10 @@ class RemotedataCounterpartiesActor extends Actor with ObpActorHelper with MdcLo description: String, bespoke: List[PostCounterpartyBespoke] ) => - logger.debug("createCounterparty(" +counterpartyId +createdByUserId + ", " + thisBankId + ", " + thisAccountId + ", " + thisViewId + ", " + name + ", " + logger.debug("createCounterparty(" +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, diff --git a/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala b/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala index fd6ffca24..f7a3173e4 100644 --- a/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala +++ b/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala @@ -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, UUID.randomUUID.toString); + val counterPartySEPA = createCounterparty(bankId.value, accountId2.value, "IBAN", "IBAN", true, 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, UUID.randomUUID.toString); + val counterPartyCounterparty = createCounterparty(bankId.value, accountId2.value, "IBAN", "OBP", true, UUID.randomUUID.toString); var transactionRequestBodySEPA = TransactionRequestBodySEPAJSON(bodyValue, IbanJson(counterPartySEPA.otherAccountRoutingAddress), discription, sharedChargePolicy) diff --git a/src/test/scala/code/api/v2_2_0/CreateCounterpartyTest.scala b/src/test/scala/code/api/v2_2_0/CreateCounterpartyTest.scala index 92755a48f..2eaf869bc 100644 --- a/src/test/scala/code/api/v2_2_0/CreateCounterpartyTest.scala +++ b/src/test/scala/code/api/v2_2_0/CreateCounterpartyTest.scala @@ -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 \ "counterparty" \ "other_account_routing_address" ) match { + var accountRoutingAddress = (responsePost.body \ "other_account_routing_address" ) match { case JString(i) => i case _ => "" } accountRoutingAddress should equal(counterpartyPostJSON.other_account_routing_address) - val counterpartyId = (responsePost.body \ "counterparty" \ "counterparty_id" ) match { + val counterpartyId = (responsePost.body \ "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 \ "counterparty" \ "other_account_routing_address" ) match { + val accountRoutingAddressGet = (responsePost.body \ "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" \ "counterparty_id" ) match { + val counterpartyIdGet = (responsePost.body \ "counterparty_id" ) match { case JString(i) => i case _ => "" } diff --git a/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala b/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala index 951e43518..0f81268e0 100644 --- a/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala +++ b/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala @@ -35,9 +35,8 @@ trait LocalMappedConnectorTestSetup extends TestConnectorSetupWithStandardPermis .saveMe } - override protected def createCounterparty(bankId: String, accountId: String, accountRoutingAddress: String, otherAccountRoutingScheme: String, isBeneficiary: Boolean, counterpartyId: String, createdByUserId:String): CounterpartyTrait = { + override protected def createCounterparty(bankId: String, accountId: String, accountRoutingAddress: String, otherAccountRoutingScheme: String, isBeneficiary: Boolean, createdByUserId:String): CounterpartyTrait = { Counterparties.counterparties.vend.createCounterparty( - counterpartyId= counterpartyId, createdByUserId = createdByUserId, thisBankId = bankId, thisAccountId = accountId, diff --git a/src/test/scala/code/setup/TestConnectorSetup.scala b/src/test/scala/code/setup/TestConnectorSetup.scala index 36abeda88..f8c7cffa0 100644 --- a/src/test/scala/code/setup/TestConnectorSetup.scala +++ b/src/test/scala/code/setup/TestConnectorSetup.scala @@ -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, createdByUserId:String): CounterpartyTrait + protected def createCounterparty(bankId: String, accountId: String, accountRoutingAddress: String, otherAccountRoutingScheme: String, isBeneficiary: Boolean, createdByUserId:String): CounterpartyTrait /** * This method, will do three things: