From b5e5eb14d7e3aa1bd221c582dace39753d5c2737 Mon Sep 17 00:00:00 2001 From: Guillaume Kergreis Date: Tue, 30 Jun 2020 20:31:23 +0200 Subject: [PATCH] feature/Add getCounterpartyByIbanAndBankAccountId connector method This new connector method is used to target precisely a counterparty linked to an account. This method should be used to replace the old one (getCounterpartyByIban) --- .../src/main/scala/code/api/util/NewStyle.scala | 14 ++++++++++++++ .../main/scala/code/api/v4_0_0/APIMethods400.scala | 2 +- .../main/scala/code/bankconnectors/Connector.scala | 2 ++ .../code/bankconnectors/LocalMappedConnector.scala | 4 ++++ .../metadata/counterparties/Counterparties.scala | 4 ++++ .../counterparties/MapperCounterparties.scala | 8 ++++++++ .../counterparties/MongoCounterparties.scala | 4 +++- .../code/remotedata/RemotedataCounterparties.scala | 4 ++++ .../code/api/v2_1_0/TransactionRequestsTest.scala | 4 ++-- .../code/api/v4_0_0/TransactionRequestsTest.scala | 4 ++-- .../code/setup/LocalMappedConnectorTestSetup.scala | 4 ++-- .../test/scala/code/setup/TestConnectorSetup.scala | 2 +- 12 files changed, 47 insertions(+), 9 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/NewStyle.scala b/obp-api/src/main/scala/code/api/util/NewStyle.scala index 82ca4c358..6b1af5c7e 100644 --- a/obp-api/src/main/scala/code/api/util/NewStyle.scala +++ b/obp-api/src/main/scala/code/api/util/NewStyle.scala @@ -815,6 +815,20 @@ object NewStyle { } } + + def getCounterpartyByIbanAndBankAccountId(iban: String, bankId: BankId, accountId: AccountId, callContext: Option[CallContext]) : OBPReturnType[CounterpartyTrait] = + { + Connector.connector.vend.getCounterpartyByIbanAndBankAccountId(iban: String, bankId: BankId, accountId: AccountId, callContext: Option[CallContext]) map { i => + (unboxFullOrFail( + i._1, + callContext, + s"$CounterpartyNotFoundByIban. Please check how do you create Counterparty, " + + s"set the proper Iban value to `other_account_secondary_routing_address`. Current Iban = $iban. " + + s"Check also the bankId and the accountId, Current BankId = ${bankId.value}, Current AccountId = ${accountId.value}", + 404), + i._2) + } + } def getTransactionRequestImpl(transactionRequestId: TransactionRequestId, callContext: Option[CallContext]): OBPReturnType[TransactionRequest] = { diff --git a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala index a76c9b710..125176d67 100644 --- a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala +++ b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala @@ -842,7 +842,7 @@ trait APIMethods400 { json.extract[TransactionRequestBodySEPAJsonV400] } toIban = transDetailsSEPAJson.to.iban - (toCounterparty, callContext) <- NewStyle.function.getCounterpartyByIban(toIban, cc.callContext) + (toCounterparty, callContext) <- NewStyle.function.getCounterpartyByIbanAndBankAccountId(toIban, fromAccount.bankId, fromAccount.accountId, cc.callContext) toAccount <- NewStyle.function.getBankAccountFromCounterparty(toCounterparty, true, callContext) _ <- Helper.booleanToFuture(s"$CounterpartyBeneficiaryPermit") { toCounterparty.isBeneficiary diff --git a/obp-api/src/main/scala/code/bankconnectors/Connector.scala b/obp-api/src/main/scala/code/bankconnectors/Connector.scala index fe098f54d..a37be0cc7 100644 --- a/obp-api/src/main/scala/code/bankconnectors/Connector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/Connector.scala @@ -541,6 +541,8 @@ trait Connector extends MdcLoggable { */ def getCounterpartyByIban(iban: String, callContext: Option[CallContext]) : OBPReturnType[Box[CounterpartyTrait]] = Future {(Failure(setUnimplementedError), callContext)} + def getCounterpartyByIbanAndBankAccountId(iban: String, bankId: BankId, accountId: AccountId, callContext: Option[CallContext]) : OBPReturnType[Box[CounterpartyTrait]] = Future {(Failure(setUnimplementedError), callContext)} + def getCounterpartiesLegacy(thisBankId: BankId, thisAccountId: AccountId, viewId :ViewId, callContext: Option[CallContext] = None): Box[(List[CounterpartyTrait], Option[CallContext])]= Failure(setUnimplementedError) def getCounterparties(thisBankId: BankId, thisAccountId: AccountId, viewId: ViewId, callContext: Option[CallContext] = None): OBPReturnType[Box[List[CounterpartyTrait]]] = Future {(Failure(setUnimplementedError), callContext)} diff --git a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala index 4251de3a0..c05f215bb 100644 --- a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala @@ -793,6 +793,10 @@ object LocalMappedConnector extends Connector with MdcLoggable { Future(Counterparties.counterparties.vend.getCounterpartyByIban(iban), callContext) } + override def getCounterpartyByIbanAndBankAccountId(iban: String, bankId: BankId, accountId: AccountId, callContext: Option[CallContext]) = { + Future(Counterparties.counterparties.vend.getCounterpartyByIbanAndBankAccountId(iban, bankId, accountId), callContext) + } + override def getPhysicalCardsForUser(user: User): Box[List[PhysicalCard]] = { val list = code.cards.PhysicalCard.physicalCardProvider.vend.getPhysicalCards(user) diff --git a/obp-api/src/main/scala/code/metadata/counterparties/Counterparties.scala b/obp-api/src/main/scala/code/metadata/counterparties/Counterparties.scala index a6c7ba04d..a95cf2fcc 100644 --- a/obp-api/src/main/scala/code/metadata/counterparties/Counterparties.scala +++ b/obp-api/src/main/scala/code/metadata/counterparties/Counterparties.scala @@ -36,6 +36,8 @@ trait Counterparties { def getCounterpartyByIban(iban : String): Box[CounterpartyTrait] + def getCounterpartyByIbanAndBankAccountId(iban: String, bankId: BankId, accountId: AccountId): Box[CounterpartyTrait] + def getCounterparties(thisBankId: BankId, thisAccountId: AccountId, viewId: ViewId): Box[List[CounterpartyTrait]] def createCounterparty( @@ -97,6 +99,8 @@ class RemotedataCounterpartiesCaseClasses { case class getCounterpartyByIban(iban: String) + case class getCounterpartyByIbanAndBankAccountId(iban: String, bankId: BankId, accountId: AccountId) + case class getCounterparties(thisBankId: BankId, thisAccountId: AccountId, viewId: ViewId) case class createCounterparty( diff --git a/obp-api/src/main/scala/code/metadata/counterparties/MapperCounterparties.scala b/obp-api/src/main/scala/code/metadata/counterparties/MapperCounterparties.scala index d4804e389..47693735f 100644 --- a/obp-api/src/main/scala/code/metadata/counterparties/MapperCounterparties.scala +++ b/obp-api/src/main/scala/code/metadata/counterparties/MapperCounterparties.scala @@ -133,6 +133,14 @@ object MapperCounterparties extends Counterparties with MdcLoggable { ) } + def getCounterpartyByIbanAndBankAccountId(iban : String, bankId: BankId, accountId: AccountId) = { + MappedCounterparty.find( + By(MappedCounterparty.mOtherAccountSecondaryRoutingAddress, iban), + By(MappedCounterparty.mThisBankId, bankId.value), + By(MappedCounterparty.mThisAccountId, accountId.value) + ) + } + override def getCounterparties(thisBankId: BankId, thisAccountId: AccountId, viewId: ViewId): Box[List[CounterpartyTrait]] = { Full(MappedCounterparty.findAll(By(MappedCounterparty.mThisAccountId, thisAccountId.value), By(MappedCounterparty.mThisBankId, thisBankId.value), diff --git a/obp-api/src/main/scala/code/metadata/counterparties/MongoCounterparties.scala b/obp-api/src/main/scala/code/metadata/counterparties/MongoCounterparties.scala index 1e2a50485..005ccc6e1 100644 --- a/obp-api/src/main/scala/code/metadata/counterparties/MongoCounterparties.scala +++ b/obp-api/src/main/scala/code/metadata/counterparties/MongoCounterparties.scala @@ -109,7 +109,9 @@ object MongoCounterparties extends Counterparties with MdcLoggable { override def getCounterparty(counterpartyId : String): Box[CounterpartyTrait] = Empty - override def getCounterpartyByIban(counterpartyId : String): Box[CounterpartyTrait] = Empty + override def getCounterpartyByIban(iban : String): Box[CounterpartyTrait] = Empty + + override def getCounterpartyByIbanAndBankAccountId(iban : String, bankId: BankId, accountId: AccountId): Box[CounterpartyTrait] = Empty override def createCounterparty( createdByUserId: String, diff --git a/obp-api/src/main/scala/code/remotedata/RemotedataCounterparties.scala b/obp-api/src/main/scala/code/remotedata/RemotedataCounterparties.scala index 42290bd95..662855253 100644 --- a/obp-api/src/main/scala/code/remotedata/RemotedataCounterparties.scala +++ b/obp-api/src/main/scala/code/remotedata/RemotedataCounterparties.scala @@ -36,6 +36,10 @@ object RemotedataCounterparties extends ObpActorInit with Counterparties { (actor ? cc.getCounterpartyByIban(iban: String)).mapTo[Box[CounterpartyTrait]] ) + override def getCounterpartyByIbanAndBankAccountId(iban: String, bankId: BankId, accountId: AccountId): Box[CounterpartyTrait] = getValueFromFuture( + (actor ? cc.getCounterpartyByIbanAndBankAccountId(iban: String, bankId: BankId, accountId: AccountId)).mapTo[Box[CounterpartyTrait]] + ) + override def getCounterparties(thisBankId: BankId, thisAccountId: AccountId, viewId: ViewId): Box[List[CounterpartyTrait]] = getValueFromFuture( (actor ? cc.getCounterparties(thisBankId, thisAccountId, viewId)).mapTo[Box[List[CounterpartyTrait]]] ) diff --git a/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala b/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala index ca38322a0..e03562a12 100644 --- a/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala +++ b/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala @@ -100,9 +100,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, true, UUID.randomUUID.toString); + val counterpartySEPA = createCounterparty(bankId.value, accountId1.value, accountId2.value, true, UUID.randomUUID.toString); //For Counterpart local mapper, the mOtherAccountRoutingScheme='OBP' and mOtherBankRoutingScheme = 'OBP' - val counterpartyCounterparty = createCounterparty(bankId.value, accountId2.value, true, UUID.randomUUID.toString); + val counterpartyCounterparty = createCounterparty(bankId.value, accountId1.value, accountId2.value, true, UUID.randomUUID.toString); var transactionRequestBodySEPA = TransactionRequestBodySEPAJSON(bodyValue, IbanJson(counterpartySEPA.otherAccountSecondaryRoutingAddress), description, sharedChargePolicy) diff --git a/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestsTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestsTest.scala index f584fe318..d94765d0e 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestsTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestsTest.scala @@ -113,9 +113,9 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers { //prepare for counterparty and SEPA stuff //For SEPA, otherAccountRoutingScheme must be 'IBAN' - val counterpartySEPA = createCounterparty(bankId.value, accountId2.value, true, UUID.randomUUID.toString); + val counterpartySEPA = createCounterparty(bankId.value, accountId1.value, accountId2.value, true, UUID.randomUUID.toString); //For Counterpart local mapper, the mOtherAccountRoutingScheme='OBP' and mOtherBankRoutingScheme = 'OBP' - val counterpartyCounterparty = createCounterparty(bankId.value, accountId2.value, true, UUID.randomUUID.toString); + val counterpartyCounterparty = createCounterparty(bankId.value, accountId1.value, accountId2.value, true, UUID.randomUUID.toString); var transactionRequestBodySEPA = TransactionRequestBodySEPAJSON(bodyValue, IbanJson(counterpartySEPA.otherAccountSecondaryRoutingAddress), description, sharedChargePolicy) diff --git a/obp-api/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala b/obp-api/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala index 9f2a817e0..be63b0085 100644 --- a/obp-api/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala +++ b/obp-api/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala @@ -35,7 +35,7 @@ trait LocalMappedConnectorTestSetup extends TestConnectorSetupWithStandardPermis .saveMe } - override protected def createCounterparty(bankId: String, accountId: String, isBeneficiary: Boolean, createdByUserId:String): CounterpartyTrait = { + override protected def createCounterparty(bankId: String, accountId: String, counterpartyObpRoutingAddress: String, isBeneficiary: Boolean, createdByUserId:String): CounterpartyTrait = { Counterparties.counterparties.vend.createCounterparty( createdByUserId = createdByUserId, thisBankId = bankId, @@ -43,7 +43,7 @@ trait LocalMappedConnectorTestSetup extends TestConnectorSetupWithStandardPermis thisViewId = "", name = APIUtil.generateUUID(), otherAccountRoutingScheme = "OBP", - otherAccountRoutingAddress = accountId, + otherAccountRoutingAddress = counterpartyObpRoutingAddress, otherBankRoutingScheme = "OBP", otherBankRoutingAddress = bankId, otherBranchRoutingScheme ="OBP", diff --git a/obp-api/src/test/scala/code/setup/TestConnectorSetup.scala b/obp-api/src/test/scala/code/setup/TestConnectorSetup.scala index 18b66ef1b..57063b756 100644 --- a/obp-api/src/test/scala/code/setup/TestConnectorSetup.scala +++ b/obp-api/src/test/scala/code/setup/TestConnectorSetup.scala @@ -21,7 +21,7 @@ trait TestConnectorSetup { protected def createTransactionRequest(account: BankAccount): List[MappedTransactionRequest] protected def updateAccountCurrency(bankId: BankId, accountId : AccountId, currency : String) : BankAccount - protected def createCounterparty(bankId: String, accountId: String, isBeneficiary: Boolean, createdByUserId:String): CounterpartyTrait + protected def createCounterparty(bankId: String, accountId: String, counterpartyObpRoutingAddress: String, isBeneficiary: Boolean, createdByUserId:String): CounterpartyTrait /** * This method, will do 4 things: