diff --git a/obp-api/src/main/scala/code/api/util/APIUtil.scala b/obp-api/src/main/scala/code/api/util/APIUtil.scala index 682c2c4b5..405486d37 100644 --- a/obp-api/src/main/scala/code/api/util/APIUtil.scala +++ b/obp-api/src/main/scala/code/api/util/APIUtil.scala @@ -3783,7 +3783,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ *A Version 1 UUID is a universally unique identifier that is generated using * a timestamp and the MAC address of the computer on which it was generated. */ - def checkIfStringIsUUIDVersion1(value: String): Boolean = { + def checkIfStringIsUUID(value: String): Boolean = { Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$") .matcher(value).matches() } diff --git a/obp-api/src/main/scala/code/api/util/ConsentUtil.scala b/obp-api/src/main/scala/code/api/util/ConsentUtil.scala index e94ba0c73..6a05bebe8 100644 --- a/obp-api/src/main/scala/code/api/util/ConsentUtil.scala +++ b/obp-api/src/main/scala/code/api/util/ConsentUtil.scala @@ -440,7 +440,7 @@ object Consent extends MdcLoggable { } def getConsentJwtValueByConsentId(consentId: String): Option[MappedConsent] = { - APIUtil.checkIfStringIsUUIDVersion1(consentId) match { + APIUtil.checkIfStringIsUUID(consentId) match { case true => // String is a UUID Consents.consentProvider.vend.getConsentByConsentId(consentId) match { case Full(consent) => Some(consent) diff --git a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala index caffed20b..b9e27ab9a 100644 --- a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala @@ -897,10 +897,31 @@ object LocalMappedConnector extends Connector with MdcLoggable { } } - def getBankAccountCommon(bankId: BankId, accountId: AccountId, callContext: Option[CallContext]) = { - MappedBankAccount - .find(By(MappedBankAccount.bank, bankId.value), By(MappedBankAccount.theAccountId, accountId.value)) - .map(bankAccount => (bankAccount, callContext)) + def getBankAccountCommon(bankId: BankId, accountId: AccountId, callContext: Option[CallContext]): Box[(MappedBankAccount, Option[CallContext])] = { + + def getByBankAndAccount(): Box[(MappedBankAccount, Option[CallContext])] = { + MappedBankAccount + .find(By(MappedBankAccount.bank, bankId.value), By(MappedBankAccount.theAccountId, accountId.value)) + .map(bankAccount => (bankAccount, callContext)) + } + + if(APIUtil.checkIfStringIsUUID(accountId.value)) { + // Find bank accounts by accountId first + val bankAccounts = MappedBankAccount.findAll(By(MappedBankAccount.theAccountId, accountId.value)) + + // If exactly one account is found, return it, else filter by bankId + bankAccounts match { + case account :: Nil => + // If exactly one account is found, return it + Some(account, callContext) + case _ => + // If multiple or no accounts are found, filter by bankId + getByBankAndAccount() + } + } else { + getByBankAndAccount() + } + } override def getBankAccounts(bankIdAccountIds: List[BankIdAccountId], callContext: Option[CallContext]): OBPReturnType[Box[List[BankAccount]]] = {