diff --git a/src/main/scala/code/api/util/APIUtil.scala b/src/main/scala/code/api/util/APIUtil.scala index 5db572496..585f508d6 100644 --- a/src/main/scala/code/api/util/APIUtil.scala +++ b/src/main/scala/code/api/util/APIUtil.scala @@ -106,9 +106,12 @@ object ErrorMessages { val InvalidAccountType = "OBP-30108: Invalid Account Type." val InitialBalanceMustBeZero = "OBP-30109: Initial Balance of Account must be Zero (0)." + + val ConnectorEmptyResponse = "OBP-30200: Connector cannot return the data we requested." val InvalidGetBankAccountsConnectorResponse = "OBP-30201: Connector did not return the set of accounts we requested." val InvalidGetBankAccountConnectorResponse = "OBP-30202: Connector did not return the account we requested." val InvalidGetTransactionConnectorResponse = "OBP-30203: Connector did not return the transaction we requested." + val InvalidGetTransactionsConnectorResponse = "OBP-30204: Connector did not return the set of transactions we requested." diff --git a/src/main/scala/code/bankconnectors/KafkaMappedConnector.scala b/src/main/scala/code/bankconnectors/KafkaMappedConnector.scala index dd67242d5..8c6131148 100644 --- a/src/main/scala/code/bankconnectors/KafkaMappedConnector.scala +++ b/src/main/scala/code/bankconnectors/KafkaMappedConnector.scala @@ -223,10 +223,14 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable "transactionId" -> transactionId.toString ) // Since result is single account, we need only first list entry implicit val formats = net.liftweb.json.DefaultFormats - val r = process(reqId, "getTransaction", argList).extract[KafkaInboundTransaction] - // Check does the response data match the requested data - if (transactionId.value != r.id) throw new Exception(ErrorMessages.InvalidGetTransactionConnectorResponse) - createNewTransaction(r) + val r = process(reqId, "getTransaction", argList).extractOpt[KafkaInboundTransaction] + r match { + // Check does the response data match the requested data + case Some(x) if transactionId.value != x.id => Failure(ErrorMessages.InvalidGetTransactionConnectorResponse, Empty, Empty) + case Some(x) if transactionId.value == x.id => createNewTransaction(x) + case _ => Failure(ErrorMessages.ConnectorEmptyResponse, Empty, Empty) + } + } override def getTransactions(bankId: BankId, accountID: AccountId, queryParams: OBPQueryParam*): Box[List[Transaction]] = { @@ -252,6 +256,9 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable "queryParams" -> queryParams.toString ) implicit val formats = net.liftweb.json.DefaultFormats val rList = process(reqId, "getTransactions", argList).extract[List[KafkaInboundTransaction]] + // Check does the response data match the requested data + val isCorrect = rList.forall(x=>x.this_account.id == accountID.value && x.this_account.bank == bankId.value) + if (!isCorrect) throw new Exception(ErrorMessages.InvalidGetTransactionsConnectorResponse) // Populate fields and generate result val res = for { r <- rList