mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 13:46:49 +00:00
refactor/Add new error messages and optimise update requests
This commit is contained in:
parent
78b7a650a6
commit
a7a3ed0cb4
@ -8,7 +8,7 @@
|
||||
<groupId>com.tesobe</groupId>
|
||||
<artifactId>obp-parent</artifactId>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
<version>1.6.4</version>
|
||||
<version>1.7.0</version>
|
||||
</parent>
|
||||
<artifactId>obp-api</artifactId>
|
||||
<packaging>war</packaging>
|
||||
|
||||
@ -287,7 +287,10 @@ object ErrorMessages {
|
||||
val AttributeNotFound = "OBP-30071: Attribute Definition not found. Please specify a valid value for ATTRIBUTE_DEFINITION_ID."
|
||||
|
||||
val CreateCounterpartyError = "OBP-30072: Could not create the Counterparty."
|
||||
|
||||
|
||||
val BankAccountNotFoundByAccountRouting = "OBP-30073: Bank Account not found. Please specify valid values for account routing scheme and address."
|
||||
val BankAccountNotFoundByIban = "OBP-30074: Bank Account not found. Please specify a valid value for iban."
|
||||
|
||||
// Meetings
|
||||
val MeetingsNotSupported = "OBP-30101: Meetings are not supported on this server."
|
||||
val MeetingApiKeyNotConfigured = "OBP-30102: Meeting provider API Key is not configured."
|
||||
|
||||
@ -218,13 +218,13 @@ object NewStyle {
|
||||
|
||||
def getBankAccountByRouting(scheme: String, address: String, callContext: Option[CallContext]) : OBPReturnType[BankAccount] = {
|
||||
Future(Connector.connector.vend.getBankAccountByRouting(scheme: String, address : String, callContext: Option[CallContext])) map { i =>
|
||||
unboxFullOrFail(i, callContext,s"${BankAccountNotFound.replaceAll("BANK_ID and ACCOUNT_ID. ", s"scheme and address.")} Current scheme is $scheme, current address is $address", 404 )
|
||||
unboxFullOrFail(i, callContext,s"$BankAccountNotFoundByAccountRouting Current scheme is $scheme, current address is $address", 404 )
|
||||
}
|
||||
}
|
||||
|
||||
def getBankAccountByIban(iban : String, callContext: Option[CallContext]) : OBPReturnType[BankAccount] = {
|
||||
Connector.connector.vend.getBankAccountByIban(iban : String, callContext: Option[CallContext]) map { i =>
|
||||
(unboxFullOrFail(i._1, callContext,s"${BankAccountNotFound.replaceAll("BANK_ID and ACCOUNT_ID. ", "IBAN.")} Current IBAN is $iban", 404 ), i._2)
|
||||
(unboxFullOrFail(i._1, callContext,s"$BankAccountNotFoundByIban Current IBAN is $iban", 404 ), i._2)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4821,9 +4821,11 @@ trait APIMethods310 {
|
||||
case _ => None
|
||||
} fallbackTo Future.successful(None)
|
||||
))
|
||||
alreadyExistingAccountRouting = alreadyExistAccountRoutings.find(_.nonEmpty).flatten
|
||||
_ <- Helper.booleanToFuture(s"$AccountRoutingAlreadyExist (${alreadyExistingAccountRouting.map(_.scheme).getOrElse("")}, ${alreadyExistingAccountRouting.map(_.address).getOrElse("")})") {
|
||||
alreadyExistAccountRoutings.forall(_.isEmpty)
|
||||
alreadyExistingAccountRouting = alreadyExistAccountRoutings.collect {
|
||||
case Some(accountRouting) => s"scheme: ${accountRouting.scheme}, address: ${accountRouting.address}"
|
||||
}
|
||||
_ <- Helper.booleanToFuture(s"$AccountRoutingAlreadyExist (${alreadyExistingAccountRouting.mkString("; ")})") {
|
||||
alreadyExistingAccountRouting.isEmpty
|
||||
}
|
||||
(bankAccount,callContext) <- NewStyle.function.updateBankAccount(
|
||||
bankId,
|
||||
@ -5478,9 +5480,11 @@ trait APIMethods310 {
|
||||
alreadyExistAccountRoutings <- Future.sequence(createAccountJson.account_routings.map(accountRouting =>
|
||||
NewStyle.function.getBankAccountByRouting(accountRouting.scheme, accountRouting.address, callContext).map(_ => Some(accountRouting)).fallbackTo(Future.successful(None))
|
||||
))
|
||||
alreadyExistingAccountRouting = alreadyExistAccountRoutings.find(_.nonEmpty).flatten
|
||||
_ <- Helper.booleanToFuture(s"$AccountRoutingAlreadyExist (${alreadyExistingAccountRouting.map(_.scheme).getOrElse("")}, ${alreadyExistingAccountRouting.map(_.address).getOrElse("")})") {
|
||||
alreadyExistAccountRoutings.forall(_.isEmpty)
|
||||
alreadyExistingAccountRouting = alreadyExistAccountRoutings.collect {
|
||||
case Some(accountRouting) => s"scheme: ${accountRouting.scheme}, address: ${accountRouting.address}"
|
||||
}
|
||||
_ <- Helper.booleanToFuture(s"$AccountRoutingAlreadyExist (${alreadyExistingAccountRouting.mkString("; ")})") {
|
||||
alreadyExistingAccountRouting.isEmpty
|
||||
}
|
||||
(bankAccount,callContext) <- NewStyle.function.createBankAccount(
|
||||
bankId,
|
||||
|
||||
@ -1269,9 +1269,11 @@ trait APIMethods400 {
|
||||
alreadyExistAccountRoutings <- Future.sequence(createAccountJson.account_routings.map(accountRouting =>
|
||||
NewStyle.function.getBankAccountByRouting(accountRouting.scheme, accountRouting.address, callContext).map(_ => Some(accountRouting)).fallbackTo(Future.successful(None))
|
||||
))
|
||||
alreadyExistingAccountRouting = alreadyExistAccountRoutings.find(_.nonEmpty).flatten
|
||||
_ <- Helper.booleanToFuture(s"$AccountRoutingAlreadyExist (${alreadyExistingAccountRouting.map(_.scheme).getOrElse("")}, ${alreadyExistingAccountRouting.map(_.address).getOrElse("")})") {
|
||||
alreadyExistAccountRoutings.forall(_.isEmpty)
|
||||
alreadyExistingAccountRouting = alreadyExistAccountRoutings.collect {
|
||||
case Some(accountRouting) => s"scheme: ${accountRouting.scheme}, address: ${accountRouting.address}"
|
||||
}
|
||||
_ <- Helper.booleanToFuture(s"$AccountRoutingAlreadyExist (${alreadyExistingAccountRouting.mkString("; ")})") {
|
||||
alreadyExistingAccountRouting.isEmpty
|
||||
}
|
||||
(bankAccount,callContext) <- NewStyle.function.addBankAccount(
|
||||
bankId,
|
||||
|
||||
@ -1297,18 +1297,14 @@ object LocalMappedConnector extends Connector with MdcLoggable {
|
||||
callContext: Option[CallContext]
|
||||
): OBPReturnType[Box[BankAccount]] = Future {
|
||||
|
||||
val oldAccountRoutings = BankAccountRouting.findAll(By(BankAccountRouting.BankId, bankId.value),
|
||||
val oldAccountRoutings: List[BankAccountRouting] = BankAccountRouting.findAll(By(BankAccountRouting.BankId, bankId.value),
|
||||
By(BankAccountRouting.AccountId, accountId.value))
|
||||
.map(_.accountRouting)
|
||||
|
||||
// Add or update new routing schemes
|
||||
accountRoutings.foreach(accountRouting =>
|
||||
oldAccountRoutings.find(_.scheme == accountRouting.scheme) match {
|
||||
case Some(_) =>
|
||||
BankAccountRouting
|
||||
.find(By(BankAccountRouting.BankId, bankId.value), By(BankAccountRouting.AccountId, accountId.value),
|
||||
By(BankAccountRouting.AccountRoutingScheme, accountRouting.scheme))
|
||||
.map(_.AccountRoutingAddress(accountRouting.address).saveMe())
|
||||
oldAccountRoutings.find(_.accountRouting.scheme == accountRouting.scheme) match {
|
||||
case Some(updatedAccountRouting) =>
|
||||
updatedAccountRouting.AccountRoutingAddress(accountRouting.address).saveMe()
|
||||
case None =>
|
||||
BankAccountRouting.create
|
||||
.BankId(bankId.value)
|
||||
@ -1320,18 +1316,11 @@ object LocalMappedConnector extends Connector with MdcLoggable {
|
||||
)
|
||||
|
||||
// Delete non-present routing schemes
|
||||
oldAccountRoutings.foreach(accountRouting =>
|
||||
accountRoutings.find(_.scheme == accountRouting.scheme)
|
||||
.getOrElse(
|
||||
BankAccountRouting
|
||||
.find(By(BankAccountRouting.BankId, bankId.value), By(BankAccountRouting.AccountId, accountId.value),
|
||||
By(BankAccountRouting.AccountRoutingScheme, accountRouting.scheme))
|
||||
.map(_.delete_!)
|
||||
)
|
||||
)
|
||||
oldAccountRoutings.filterNot(accountRouting => accountRoutings.exists(_.scheme == accountRouting.accountRouting.scheme))
|
||||
.foreach(_.delete_!)
|
||||
|
||||
(for {
|
||||
(account, callContext) <- LocalMappedConnector.getBankAccountCommon(bankId, accountId, callContext)
|
||||
(account, _) <- LocalMappedConnector.getBankAccountCommon(bankId, accountId, callContext)
|
||||
} yield {
|
||||
account
|
||||
.kind(accountType)
|
||||
|
||||
@ -3,7 +3,7 @@ package code.api.berlin.group.v1_3
|
||||
import com.openbankproject.commons.model.ErrorMessage
|
||||
import code.api.builder.ConfirmationOfFundsServicePIISApi.APIMethods_ConfirmationOfFundsServicePIISApi
|
||||
import code.api.util.APIUtil.OAuth._
|
||||
import code.api.util.ErrorMessages.{BankAccountNotFound, InvalidJsonContent, InvalidJsonFormat}
|
||||
import code.api.util.ErrorMessages.{BankAccountNotFound, BankAccountNotFoundByIban, InvalidJsonContent, InvalidJsonFormat}
|
||||
import code.model.dataAccess.{BankAccountRouting, MappedBankAccount}
|
||||
import code.setup.{APIResponse, DefaultUsers}
|
||||
import com.github.dwickern.macros.NameOf.nameOf
|
||||
@ -34,7 +34,7 @@ class ConfirmationOfFundsServicePIISApiTest extends BerlinGroupServerSetupV1_3 w
|
||||
Then("We should get a 404 ")
|
||||
response.code should equal(404)
|
||||
response.body.extract[ErrorMessage]
|
||||
.message should startWith(s"${BankAccountNotFound.replaceAll("BANK_ID and ACCOUNT_ID. ", "IBAN.")}")
|
||||
.message should startWith(BankAccountNotFoundByIban)
|
||||
}
|
||||
|
||||
scenario("Failed Case, invalid post json", BerlinGroupV1_3, PIIS, checkAvailabilityOfFunds) {
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<groupId>com.tesobe</groupId>
|
||||
<artifactId>obp-parent</artifactId>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
<version>1.6.4</version>
|
||||
<version>1.7.0</version>
|
||||
</parent>
|
||||
<artifactId>obp-commons</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user