getBranches v3.0.0 written as New Style Endpoint

This commit is contained in:
constantine2nd 2017-12-19 16:04:43 +01:00
parent 068195833e
commit 78dce5332b
10 changed files with 39 additions and 28 deletions

View File

@ -172,7 +172,8 @@ trait OBPRestHelper extends RestHelper with MdcLoggable {
(nameOf(Implementations3_0_0.privateAccountsAtOneBank), ApiVersion.v3_0_0.toString),
(nameOf(Implementations3_0_0.getCoreAccountById), ApiVersion.v3_0_0.toString),
(nameOf(Implementations3_0_0.accountById), ApiVersion.v3_0_0.toString),
(nameOf(Implementations3_0_0.getAtm), ApiVersion.v3_0_0.toString)
(nameOf(Implementations3_0_0.getAtm), ApiVersion.v3_0_0.toString),
(nameOf(Implementations3_0_0.getBranch), ApiVersion.v3_0_0.toString)
)
/**
* Function which inspect does an Endpoint use Akka's Future in non-blocking way i.e. without using Await.result

View File

@ -42,6 +42,7 @@ import code.api.JSONFactoryGateway.PayloadOfJwtJSON
import code.api.OAuthHandshake._
import code.api.{DirectLogin, _}
import code.api.util.APIUtil.ApiVersion.ApiVersion
import code.api.util.APIUtil.canGet
import code.api.v1_2.ErrorMessage
import code.bankconnectors._
import code.consumer.Consumers
@ -1463,8 +1464,8 @@ Returns a string showed to the developer
}
def canGetAtm(atmsIsPublic: Boolean, user: Box[User]): Boolean = {
atmsIsPublic match {
def canGet(condition: Boolean, user: Box[User]): Boolean = {
condition match {
case true =>
true
case false =>
@ -1477,6 +1478,15 @@ Returns a string showed to the developer
}
}
def canGetBranch(branchesIsPublic: Boolean, user: Box[User]): Boolean = {
canGet(branchesIsPublic, user)
}
def canGetAtm(atmsIsPublic: Boolean, user: Box[User]): Boolean = {
canGet(atmsIsPublic, user)
}
def getDisabledVersions() : List[String] = Props.get("api_disabled_versions").getOrElse("").replace("[", "").replace("]", "").split(",").toList.filter(_.nonEmpty)
def getDisabledEndpoints() : List[String] = Props.get("api_disabled_endpoints").getOrElse("").replace("[", "").replace("]", "").split(",").toList.filter(_.nonEmpty)

View File

@ -850,27 +850,21 @@ trait APIMethods300 {
// TODO Rewrite as New Style Endpoint
lazy val getBranch: PartialFunction[Req, Box[User] => Box[JsonResponse]] = {
case "banks" :: BankId(bankId) :: "branches" :: BranchId(branchId) :: Nil JsonGet _ => {
user => {
_ => {
for {
u <- if (getBranchesIsPublic)
Box(Some(1))
else
user ?~! UserNotLoggedIn
_ <- Bank(bankId) ?~! {BankNotFound}
branch <- Box(Branches.branchesProvider.vend.getBranch(bankId, branchId)) ?~! s"${BranchNotFoundByBranchId}, or License may not be set. meta.license.id and meta.license.name can not be empty"
// branches <- { Branches.branchesProvider.vend.getBranches(bankId) match {
// case Some(l) => Full(l)
// case _ => Empty
// }} ?~! s"${BranchNotFoundByBranchId}, or License may not be set. meta.license.id and eta.license.name can not be empty"
// branch <- Box(branches.filter(_.branchId.value==branchId.value)) ?~!
// s"${BranchNotFoundByBranchId}, or License may not be set. meta.license.id and eta.license.name can not be empty"
(user, sessioContext) <- extractCallContext()
_ <- Helper.booleanToFuture(failMsg = UserNotLoggedIn) {
canGetBranch(getBranchesIsPublic, user)
}
_ <- Future { Bank(bankId) } map {
x => fullBoxOrException(x ?~! BankNotFound)
}
branch <- Connector.connector.vend.getBranchFuture(bankId, branchId) map {
val msg: String = s"${BranchNotFoundByBranchId}, or License may not be set. meta.license.id and meta.license.name can not be empty"
x => fullBoxOrException(x ?~! msg)
} map { unboxFull(_) }
} yield {
// Format the data as json
val json = JSONFactory300.createBranchJsonV300(branch)
successJsonResponse(Extraction.decompose(json))
(JSONFactory300.createBranchJsonV300(branch), getGatewayLoginHeader(sessioContext))
}
}
}

View File

@ -1108,6 +1108,9 @@ trait Connector extends MdcLoggable{
def getBranch(bankId : BankId, branchId: BranchId) : Box[BranchT] = Failure(NotImplemented + currentMethodName)
def getBranchFuture(bankId : BankId, branchId: BranchId) : Future[Box[BranchT]] = Future {
Failure(NotImplemented + currentMethodName)
}
def getAtm(bankId : BankId, atmId: AtmId) : Box[AtmT] = Failure(NotImplemented + currentMethodName)
def getAtmFuture(bankId : BankId, atmId: AtmId) : Future[Box[AtmT]] = Future {

View File

@ -1044,7 +1044,6 @@ object KafkaMappedConnector extends Connector with KafkaHelper with MdcLoggable
bankRoutingAddress: String
): Box[Bank] = Empty
override def getBranch(bankId : BankId, branchId: BranchId) : Box[MappedBranch]= Empty
// get the latest FXRate specified by fromCurrencyCode and toCurrencyCode.
override def getCurrentFxRate(bankId: BankId, fromCurrencyCode: String, toCurrencyCode: String): Box[FXRate] = {

View File

@ -1259,6 +1259,10 @@ object KafkaMappedConnector_JVMcompatible extends Connector with KafkaHelper wit
LocalMappedConnector.getBranch(bankId, branchId)
}
override def getBranchFuture(bankId : BankId, branchId: BranchId) : Future[Box[BranchT]]= {
LocalMappedConnector.getBranchFuture(bankId, branchId)
}
override def createOrUpdateAtm(atm: Atms.Atm): Box[AtmT] = {
LocalMappedConnector.createOrUpdateAtm(atm)
}

View File

@ -1423,7 +1423,11 @@ object LocalMappedConnector extends Connector with MdcLoggable {
)
}
override def getBranchFuture(bankId : BankId, branchId: BranchId) : Future[Box[MappedBranch]]= {
Future {
getBranch(bankId, branchId)
}
}
override def getAtm(bankId : BankId, atmId: AtmId) : Box[MappedAtm]= {
MappedAtm

View File

@ -623,8 +623,6 @@ private object LocalRecordConnector extends Connector with MdcLoggable {
override def getProduct(bankId: BankId, productCode: ProductCode): Box[Product] = Empty
override def createOrUpdateBranch(branch: Branch): Box[BranchT] = Empty
override def getBranch(bankId: BankId, branchId: BranchId): Box[MappedBranch] = Empty
override def getCurrentFxRate(bankId: BankId, fromCurrencyCode: String, toCurrencyCode: String): Box[FXRate] = Empty

View File

@ -1399,7 +1399,6 @@ object ObpJvmMappedConnector extends Connector with MdcLoggable {
bankRoutingAddress: String
): Box[Bank] = Empty
override def getBranch(bankId : BankId, branchId: BranchId) : Box[MappedBranch]= Empty
override def getCurrentFxRate(bankId: BankId, fromCurrencyCode: String, toCurrencyCode: String): Box[FXRate] = Empty

View File

@ -1704,7 +1704,6 @@ trait KafkaMappedConnector_vMar2017 extends Connector with KafkaHelper with MdcL
bankRoutingAddress: String
): Box[Bank] = Empty
override def getBranch(bankId : BankId, branchId: BranchId) : Box[MappedBranch]= Empty
override def getEmptyBankAccount(): Box[AccountType] = {
Full(new BankAccount2(