separate AdapterCallContext to outboundAdapterCallContext and inboundAdapterCallContext --step2

This commit is contained in:
hongwei 2019-04-24 09:58:05 +02:00
parent 24c01b10d9
commit d5b80798f3
5 changed files with 48 additions and 356 deletions

View File

@ -49,9 +49,10 @@ case class CallContext(
//This is only used to connect the back adapter. not useful for sandbox mode.
def toAdapterCallContext: OutboundAdapterCallContext= {
for{
user <- this.user
username <- tryo(user.name)
currentResourceUserId <- Some(user.userId)
user <- this.user //If there is no user, then will go to `.openOr` method, to return anonymousAccess box.
username <- tryo(Some(user.name))
currentResourceUserId <- tryo(Some(user.userId))
consumerId <- this.consumer.map(_.consumerId.get) //If there is no consumer, then will go to `.openOr` method, to return anonymousAccess box.
permission <- Views.views.vend.getPermissionForUser(user)
views <- tryo(permission.views)
linkedCustomers <- tryo(Customer.customerProvider.vend.getCustomersByUserId(user.userId))
@ -77,19 +78,18 @@ case class CallContext(
OutboundAdapterCallContext(
correlationId = this.correlationId,
sessionId = this.sessionId,
None,
Some(OutboundAdapterAuthInfo(
currentResourceUserId,
username,
likedCustomersBasic,
basicUserAuthContexts,
generalContext = None, //Not sure how to use this field yet.
if (authViews.isEmpty) None else Some(authViews))))
consumerId = Some(consumerId),
generalContext = None,
outboundAdapterAuthInfo = Some(OutboundAdapterAuthInfo(
userId = currentResourceUserId,
username = username,
linkedCustomers = likedCustomersBasic,
userAuthContext = basicUserAuthContexts,
if (authViews.isEmpty) None else Some(authViews)))
)
}}.openOr(OutboundAdapterCallContext( //For anonymousAccess endpoints, there are no user info
correlationId = this.correlationId,
sessionId = this.sessionId,
None,
None))
this.correlationId,
this.sessionId))
def toLight: CallContextLight = {
CallContextLight(
@ -250,50 +250,4 @@ object ApiSession {
}
}
}
object App1 extends App{
val a = OutboundAdapterCallContext(
correlationId = "1",
sessionId = Some("1"), //Only this value must be used for cache key !!!
consumerId = Some("2"),
outboundAdapterAuthInfo = Some(OutboundAdapterAuthInfo(
linkedCustomers = Some(List(BasicLindedCustomer("customerIdExample.value","customerNumberExample.value","legalNameExample.value"))),
userAuthContext = Some(List(BasicUserAuthContext("keyExample.value","valueExample.value"))), //be set by obp from some endpoints.
generalContext= Some(List(BasicGeneralContext("keyExample.value","valueExample.value"))), //be set by backend, send it back to the header? not finish yet.
authViews = Some(List(AuthView(
view = ViewBasic(
id = "viewIdExample.value",
name = "viewNameExample.value",
description = "viewDescriptionExample.value",
),
account = AccountBasic(
id = "accountIdExample.value",
accountRoutings =List(AccountRouting(
scheme = "accountRoutingSchemeExample.value",
address = "accountRoutingAddressExample.value"
)),
customerOwners = List(InternalBasicCustomer(
bankId = "bankIdExample.value",
customerId = "customerIdExample.value",
customerNumber = "customerNumberExample.value",
legalName = "legalNameExample.value",
dateOfBirth = new Date(),
)),
userOwners = List(InternalBasicUser(
userId = "userIdExample.value",
emailAddress = "emailExample.value",
name = "usernameExample.value"
)))))))))
import net.liftweb.json._
implicit val formats = net.liftweb.json.DefaultFormats
val jValueToStringCompact: String = compactRender(Extraction.decompose(a))
println(jValueToStringCompact)
}
}

View File

@ -36,6 +36,9 @@ object ExampleValue {
val customerIdExample = ConnectorField("7uy8a7e4-6d02-40e3-a129-0b2bf89de8uh", s"A non human friendly string that identifies the customer and is used in URLs. This SHOULD NOT be the customer number. The combination of customerId and bankId MUST be unique on an OBP instance. customerId SHOULD be unique on an OBP instance. Ideally customerId is a UUID. A mapping between customer number and customer id is kept in OBP.")
glossaryItems += makeGlossaryItem("Adapter.customerId", customerIdExample)
val consumerIdExample = ConnectorField("7uy8a7e4-6d02-40e3-a129-0b2bf89de8uh", s"A non human friendly string that identifies the consumer. It is the app which calls the apis")
glossaryItems += makeGlossaryItem("Adapter.consumerId", consumerIdExample)
val nameSuffixExample = ConnectorField("Sr", s"suffix of the name")
glossaryItems += makeGlossaryItem("Adapter.nameSuffix", nameSuffixExample)

View File

@ -27,45 +27,45 @@ class SouthSideActorOfAkkaConnector extends Actor with ActorLogging with MdcLogg
case OutBoundGetAdapterInfoFuture(cc) =>
val result =
InBoundGetAdapterInfoFuture(
cc,
InboundAdapterCallContext(cc.correlationId,cc.sessionId,cc.generalContext),
inboundAdapterInfoInternal
)
sender ! result
case OutBoundGetBanksFuture(cc) =>
val result: Box[List[MappedBank]] = getBanks(None).map(r => r._1)
sender ! InBoundGetBanksFuture(cc, result.map(l => l.map(Transformer.bank(_))).openOrThrowException(attemptedToOpenAnEmptyBox))
sender ! InBoundGetBanksFuture(InboundAdapterCallContext(cc.correlationId,cc.sessionId,cc.generalContext), result.map(l => l.map(Transformer.bank(_))).openOrThrowException(attemptedToOpenAnEmptyBox))
case OutBoundGetBankFuture(cc, bankId) =>
val result: Box[MappedBank] = getBank(bankId, None).map(r => r._1)
sender ! InBoundGetBankFuture(cc, result.map(Transformer.bank(_)).openOrThrowException(attemptedToOpenAnEmptyBox) )
sender ! InBoundGetBankFuture(InboundAdapterCallContext(cc.correlationId,cc.sessionId,cc.generalContext),result.map(Transformer.bank(_)).openOrThrowException(attemptedToOpenAnEmptyBox) )
case OutBoundCheckBankAccountExistsFuture(cc, bankId, accountId) =>
val result: Box[BankAccount] = checkBankAccountExists(bankId, accountId, None).map(r => r._1)
sender ! InBoundCheckBankAccountExistsFuture(cc, result.map(Transformer.bankAccount(_)).openOrThrowException(attemptedToOpenAnEmptyBox))
sender ! InBoundCheckBankAccountExistsFuture(InboundAdapterCallContext(cc.correlationId,cc.sessionId,cc.generalContext),result.map(Transformer.bankAccount(_)).openOrThrowException(attemptedToOpenAnEmptyBox))
case OutBoundGetBankAccountFuture(cc, bankId, accountId) =>
val result: Box[BankAccount] = getBankAccount(bankId, accountId, None).map(r => r._1)
org.scalameta.logger.elem(result)
sender ! InBoundGetBankAccountFuture(cc, result.map(Transformer.bankAccount(_)).openOrThrowException(attemptedToOpenAnEmptyBox))
sender ! InBoundGetBankAccountFuture(InboundAdapterCallContext(cc.correlationId,cc.sessionId,cc.generalContext),result.map(Transformer.bankAccount(_)).openOrThrowException(attemptedToOpenAnEmptyBox))
case OutBoundGetCoreBankAccountsFuture(cc, bankIdAccountIds) =>
val result: Box[List[CoreAccount]] = getCoreBankAccounts(bankIdAccountIds, None).map(r => r._1)
sender ! InBoundGetCoreBankAccountsFuture(cc, result.map(l => l.map(Transformer.coreAccount(_))).openOrThrowException(attemptedToOpenAnEmptyBox))
sender ! InBoundGetCoreBankAccountsFuture(InboundAdapterCallContext(cc.correlationId,cc.sessionId,cc.generalContext),result.map(l => l.map(Transformer.coreAccount(_))).openOrThrowException(attemptedToOpenAnEmptyBox))
case OutBoundGetCustomersByUserIdFuture(cc, userId) =>
val result: Box[List[Customer]] = getCustomersByUserId(userId, None).map(r => r._1)
sender ! InBoundGetCustomersByUserIdFuture(cc, result.map(l => l.map(Transformer.toInternalCustomer(_))).openOrThrowException(attemptedToOpenAnEmptyBox))
sender ! InBoundGetCustomersByUserIdFuture(InboundAdapterCallContext(cc.correlationId,cc.sessionId,cc.generalContext),result.map(l => l.map(Transformer.toInternalCustomer(_))).openOrThrowException(attemptedToOpenAnEmptyBox))
case OutBoundGetTransactionsFuture(cc, bankId, accountId, limit, fromDate, toDate) =>
val from = APIUtil.DateWithMsFormat.parse(fromDate)
val to = APIUtil.DateWithMsFormat.parse(toDate)
val result = getTransactions(bankId, accountId, None, List(OBPLimit(limit), OBPFromDate(from), OBPToDate(to)): _*).map(r => r._1)
sender ! InBoundGetTransactionsFuture(cc, result.getOrElse(Nil).map(Transformer.toInternalTransaction(_)))
sender ! InBoundGetTransactionsFuture(InboundAdapterCallContext(cc.correlationId,cc.sessionId,cc.generalContext),result.getOrElse(Nil).map(Transformer.toInternalTransaction(_)))
case OutBoundGetTransactionFuture(cc, bankId, accountId, transactionId) =>
val result = getTransaction(bankId, accountId, transactionId, None).map(r => r._1)
sender ! InBoundGetTransactionFuture(cc, result.map(Transformer.toInternalTransaction(_)).openOrThrowException(attemptedToOpenAnEmptyBox))
sender ! InBoundGetTransactionFuture(InboundAdapterCallContext(cc.correlationId,cc.sessionId,cc.generalContext),result.map(Transformer.toInternalTransaction(_)).openOrThrowException(attemptedToOpenAnEmptyBox))
case message =>
logger.warn("[AKKA ACTOR ERROR - REQUEST NOT RECOGNIZED] " + message)

View File

@ -101,34 +101,7 @@ trait RestConnector_vMar2019 extends Connector with KafkaHelper with MdcLoggable
}
}
}("getAdapterInfo")
messageDocs += MessageDoc(
process = "obp.get.Banks",
messageFormat = messageFormat,
description = "Gets the banks list on this OBP installation.",
outboundTopic = Some(OutBoundGetBanksFuture.getClass.getSimpleName.replace("$", "")),
inboundTopic = Some(InBoundGetBanksFuture.getClass.getSimpleName.replace("$", "")),
exampleOutboundMessage = (
OutBoundGetBanksFuture(OutboundAdapterCallContext(outboundAdapterAuthInfo = None))
),
exampleInboundMessage = (
InBoundGetBanksFuture(
InboundAdapterCallContext(outboundAdapterAuthInfo = None),
List(BankCommons(
bankId = BankId(bankIdExample.value),
shortName = "The Royal Bank of Scotland",
fullName = "The Royal Bank of Scotland",
logoUrl = "http://www.red-bank-shoreditch.com/logo.gif",
websiteUrl = "http://www.red-bank-shoreditch.com",
bankRoutingScheme = "OBP",
bankRoutingAddress = "rbs",
swiftBic = "",
nationalIdentifier =""
)))
),
adapterImplementation = Some(AdapterImplementation("- Core", 1))
)
// url example: /getAdapterInfoFuture
override def getAdapterInfoFuture(callContext: Option[CallContext]): Future[Box[(InboundAdapterInfoInternal, Option[CallContext])]] = saveConnectorMetric {
/**
@ -152,78 +125,6 @@ trait RestConnector_vMar2019 extends Connector with KafkaHelper with MdcLoggable
}
}("getAdapterInfoFuture")
messageDocs += MessageDoc(
process = "obp.get.AmountOfMoney",
messageFormat = messageFormat,
description = "Get Challenge Threshold",
outboundTopic = None,
inboundTopic = None,
exampleOutboundMessage = (
OutBoundGetChallengeThreshold(adapterCallContext = OutboundAdapterCallContext(correlationId = "string",
sessionId = Option("string"),
adapterAuthInfo = Option(AdapterAuthInfo(userId = "string",
username = "string",
linkedCustomers = Option(List(BasicLindedCustomer(customerId = "string",
customerNumber = "string",
legalName = "string"))),
userAuthContexts = Option(List(BasicUserAuthContext(key = "string",
value = "string"))),
userCbsContexts = Option(List(BasicUserCbsContext(key = "string",
value = "string"))),
authViews = Option(List(AuthView(view = ViewBasic(id = "string",
name = "string",
description = "string"),
account = AccountBasic(id = "string",
accountRoutings = List(AccountRouting(scheme = "string",
address = "string")),
customerOwners = List(InternalBasicCustomer(bankId = "string",
customerId = "string",
customerNumber = "string",
legalName = "string",`
dateOfBirth = new Date())),
userOwners = List(InternalBasicUser(userId = "string",
emailAddress = "string",
name = "string"))))))))),
bankId = "string",
accountId = "string",
viewId = "string",
transactionRequestType = "string",
currency = "string",
userId = "string",
userName = "string")
),
exampleInboundMessage = (
InBoundGetChallengeThreshold(adapterCallContext = OutboundAdapterCallContext(correlationId = "string",
sessionId = Option("string"),
adapterAuthInfo = Option(AdapterAuthInfo(userId = "string",
username = "string",
linkedCustomers = Option(List(BasicLindedCustomer(customerId = "string",
customerNumber = "string",
legalName = "string"))),
userAuthContexts = Option(List(BasicUserAuthContext(key = "string",
value = "string"))),
userCbsContexts = Option(List(BasicUserCbsContext(key = "string",
value = "string"))),
authViews = Option(List(AuthView(view = ViewBasic(id = "string",
name = "string",
description = "string"),
account = AccountBasic(id = "string",
accountRoutings = List(AccountRouting(scheme = "string",
address = "string")),
customerOwners = List(InternalBasicCustomer(bankId = "string",
customerId = "string",
customerNumber = "string",
legalName = "string",
dateOfBirth = new Date())),
userOwners = List(InternalBasicUser(userId = "string",
emailAddress = "string",
name = "string"))))))))),
data = AmountOfMoney(currency = "string",
amount = "string"))
),
adapterImplementation = Some(AdapterImplementation("- Core", 1))
)
// url example: /getChallengeThreshold/bankId/{bankId}/accountId/{accountId}/viewId/{viewId}/transactionRequestType/{transactionRequestType}/currency/{currency}/userId/{userId}/userName/{userName}
override def getChallengeThreshold(bankId: String, accountId: String, viewId: String, transactionRequestType: String, currency: String, userId: String, userName: String, callContext: Option[CallContext]): OBPReturnType[Box[AmountOfMoney]] = saveConnectorMetric {
/**
@ -249,161 +150,31 @@ trait RestConnector_vMar2019 extends Connector with KafkaHelper with MdcLoggable
}("getChallengeThreshold")
messageDocs += MessageDoc(
process = "obp.post.Challenge",
process = "obp.get.Banks",
messageFormat = messageFormat,
description = "Create Challenge",
outboundTopic = None,
inboundTopic = None,
description = "Gets the banks list on this OBP installation.",
outboundTopic = Some(OutBoundGetBanksFuture.getClass.getSimpleName.replace("$", "")),
inboundTopic = Some(InBoundGetBanksFuture.getClass.getSimpleName.replace("$", "")),
exampleOutboundMessage = (
OutBoundCreateChallenge(adapterCallContext = OutboundAdapterCallContext(correlationId = "string",
sessionId = Option("string"),
adapterAuthInfo = Option(AdapterAuthInfo(userId = "string",
username = "string",
linkedCustomers = Option(List(BasicLindedCustomer(customerId = "string",
customerNumber = "string",
legalName = "string"))),
userAuthContexts = Option(List(BasicUserAuthContext(key = "string",
value = "string"))),
userCbsContexts = Option(List(BasicUserCbsContext(key = "string",
value = "string"))),
authViews = Option(List(AuthView(view = ViewBasic(id = "string",
name = "string",
description = "string"),
account = AccountBasic(id = "string",
accountRoutings = List(AccountRouting(scheme = "string",
address = "string")),
customerOwners = List(InternalBasicCustomer(bankId = "string",
customerId = "string",
customerNumber = "string",
legalName = "string",
dateOfBirth = new Date())),
userOwners = List(InternalBasicUser(userId = "string",
emailAddress = "string",
name = "string"))))))))),
bankId = BankId(value = "string"),
accountId = AccountId(value = "string"),
userId = "string",
transactionRequestType = TransactionRequestType(value = "string"),
transactionRequestId = "string")
OutBoundGetBanksFuture(OutboundAdapterCallContext(outboundAdapterAuthInfo = None))
),
exampleInboundMessage = (
InBoundCreateChallenge(adapterCallContext = OutboundAdapterCallContext(correlationId = "string",
sessionId = Option("string"),
adapterAuthInfo = Option(AdapterAuthInfo(userId = "string",
username = "string",
linkedCustomers = Option(List(BasicLindedCustomer(customerId = "string",
customerNumber = "string",
legalName = "string"))),
userAuthContexts = Option(List(BasicUserAuthContext(key = "string",
value = "string"))),
userCbsContexts = Option(List(BasicUserCbsContext(key = "string",
value = "string"))),
authViews = Option(List(AuthView(view = ViewBasic(id = "string",
name = "string",
description = "string"),
account = AccountBasic(id = "string",
accountRoutings = List(AccountRouting(scheme = "string",
address = "string")),
customerOwners = List(InternalBasicCustomer(bankId = "string",
customerId = "string",
customerNumber = "string",
legalName = "string",
dateOfBirth = new Date())),
userOwners = List(InternalBasicUser(userId = "string",
emailAddress = "string",
name = "string"))))))))),
data = "string")
InBoundGetBanksFuture(
InboundAdapterCallContext(generalContext = None),
List(BankCommons(
bankId = BankId(bankIdExample.value),
shortName = "The Royal Bank of Scotland",
fullName = "The Royal Bank of Scotland",
logoUrl = "http://www.red-bank-shoreditch.com/logo.gif",
websiteUrl = "http://www.red-bank-shoreditch.com",
bankRoutingScheme = "OBP",
bankRoutingAddress = "rbs",
swiftBic = "",
nationalIdentifier =""
)))
),
adapterImplementation = Some(AdapterImplementation("- Core", 1))
)
// url example: /createChallenge
override def createChallenge(bankId: BankId, accountId: AccountId, userId: String, transactionRequestType: TransactionRequestType, transactionRequestId: String, callContext: Option[CallContext]): OBPReturnType[Box[String]] = {
val url = getUrl("createChallenge")
val jsonStr = write(OutBoundCreateChallenge(buildAdapterCallContext(callContext), bankId, accountId, userId, transactionRequestType, transactionRequestId))
sendPostRequest[InBoundCreateChallenge](url, callContext, jsonStr)
.map { boxedResult =>
boxedResult match {
case Full(result) => (Full(result.data), buildCallContext(result.inboundAdapterCallContext, callContext))
case result: EmptyBox => (result, callContext) // Empty and Failure all match this case
}
}
}
messageDocs += MessageDoc(
process = "obp.get.Bank",
messageFormat = messageFormat,
description = "Get Bank",
outboundTopic = None,
inboundTopic = None,
exampleOutboundMessage = (
OutBoundGetBank(adapterCallContext = OutboundAdapterCallContext(correlationId = "string",
sessionId = Option("string"),
adapterAuthInfo = Option(AdapterAuthInfo(userId = "string",
username = "string",
linkedCustomers = Option(List(BasicLindedCustomer(customerId = "string",
customerNumber = "string",
legalName = "string"))),
userAuthContexts = Option(List(BasicUserAuthContext(key = "string",
value = "string"))),
userCbsContexts = Option(List(BasicUserCbsContext(key = "string",
value = "string"))),
authViews = Option(List(AuthView(view = ViewBasic(id = "string",
name = "string",
description = "string"),
account = AccountBasic(id = "string",
accountRoutings = List(AccountRouting(scheme = "string",
address = "string")),
customerOwners = List(InternalBasicCustomer(bankId = "string",
customerId = "string",
customerNumber = "string",
legalName = "string",
dateOfBirth = new Date())),
userOwners = List(InternalBasicUser(userId = "string",
emailAddress = "string",
name = "string"))))))))),
bankId = BankId(value = "string"))
),
exampleInboundMessage = (
InBoundGetBank(adapterCallContext = OutboundAdapterCallContext(correlationId = "string",
sessionId = Option("string"),
adapterAuthInfo = Option(AdapterAuthInfo(userId = "string",
username = "string",
linkedCustomers = Option(List(BasicLindedCustomer(customerId = "string",
customerNumber = "string",
legalName = "string"))),
userAuthContexts = Option(List(BasicUserAuthContext(key = "string",
value = "string"))),
userCbsContexts = Option(List(BasicUserCbsContext(key = "string",
value = "string"))),
authViews = Option(List(AuthView(view = ViewBasic(id = "string",
name = "string",
description = "string"),
account = AccountBasic(id = "string",
accountRoutings = List(AccountRouting(scheme = "string",
address = "string")),
customerOwners = List(InternalBasicCustomer(bankId = "string",
customerId = "string",
customerNumber = "string",
legalName = "string",
dateOfBirth = new Date())),
userOwners = List(InternalBasicUser(userId = "string",
emailAddress = "string",
name = "string"))))))))),
data = BankCommons(bankId = BankId(value = "string"),
shortName = "string",
fullName = "string",
logoUrl = "string",
websiteUrl = "string",
bankRoutingScheme = "string",
bankRoutingAddress = "string",
swiftBic = "string",
nationalIdentifier = "string"))
),
adapterImplementation = Some(AdapterImplementation("- Core", 1))
)
// url example: /getBank/bankId/{bankId}
override def getBankFuture(bankId: BankId, callContext: Option[CallContext]): Future[Box[(Bank, Option[CallContext])]] = saveConnectorMetric {
/**
@ -443,42 +214,6 @@ trait RestConnector_vMar2019 extends Connector with KafkaHelper with MdcLoggable
}
}("getBanks")
messageDocs += MessageDoc(
process = "obp.get.getBankAccount",
messageFormat = messageFormat,
description = "Gets the Accounts.",
exampleOutboundMessage =
OutBoundGetBankAccountFuture(
OutboundAdapterCallContext(outboundAdapterAuthInfo = None),
BankId(bankIdExample.value),
AccountId(accountIdExample.value))
,
exampleInboundMessage =
InBoundGetBankAccountFuture(
OutboundAdapterCallContext(outboundAdapterAuthInfo = None),
BankAccountCommons(
accountId = AccountId(accountIdExample.value),
accountType = accountTypeExample.value,
balance = BigDecimal(balanceAmountExample.value),
currency = currencyExample.value,
name = "",
label = labelExample.value,
swift_bic = None,
iban = Some(ibanExample.value),
number = accountNumberExample.value,
bankId = BankId(bankIdExample.value),
lastUpdate = new Date(),
branchId = branchIdExample.value,
accountRoutingScheme = accountRoutingSchemeExample.value,
accountRoutingAddress = accountRoutingAddressExample.value,
accountRoutings = List(AccountRouting("","")),
accountRules = List(AccountRule("","")),
accountHolder = ""
)
),
adapterImplementation = Some(AdapterImplementation("- Core", 1))
)
// url example: /getBankAccount/bankId/{bankId}/accountId/{accountId}
override def getBankAccountFuture(bankId: BankId, accountId: AccountId, callContext: Option[CallContext]): OBPReturnType[Box[BankAccount]] = saveConnectorMetric {
/**

View File

@ -607,7 +607,7 @@ case class OutboundAdapterCallContext(
sessionId: Option[String] = None, //Only this value must be used for cache key !!!
consumerId: Option[String] = None,
generalContext: Option[List[BasicGeneralContext]]= None,
outboundAdapterAuthInfo: Option[OutboundAdapterAuthInfo]
outboundAdapterAuthInfo: Option[OutboundAdapterAuthInfo] = None,
)
case class BasicGeneralContext(