Merge branch 'develop' of https://github.com/OpenBankProject/OBP-API into develop

This commit is contained in:
Simon Redfern 2017-03-29 15:45:13 +02:00
commit 16a0cd3486
6 changed files with 39 additions and 6 deletions

View File

@ -29,6 +29,7 @@ import code.model.{BankAccount, BankId, ViewId, _}
import code.products.Products.ProductCode
import code.transactionrequests.TransactionRequests
import code.usercustomerlinks.UserCustomerLink
import code.users.Users
import code.util.Helper.booleanToBox
import net.liftweb.http.{Req, S}
import net.liftweb.json.Extraction
@ -716,8 +717,7 @@ trait APIMethods210 {
consumerIdToLong <- tryo{consumerId.toLong} ?~! ErrorMessages.InvalidConsumerId
consumer <- Consumers.consumers.vend.getConsumerByConsumerId(consumerIdToLong)
} yield {
// Format the data as json
val json = ConsumerJSON(consumer.id, consumer.name, consumer.appType.toString(), consumer.description, consumer.developerEmail, consumer.redirectURL, consumer.createdByUserId, consumer.isActive, consumer.createdAt)
val json = createConsumerJSON(consumer)
// Return
successJsonResponse(Extraction.decompose(json))
}

View File

@ -49,6 +49,7 @@ import code.metrics.APIMetric
import net.liftweb.common.{Box, Full}
import net.liftweb.json.JValue
import code.products.Products.Product
import code.users.Users
@ -173,6 +174,14 @@ case class TransactionRequestWithChargeJSONs210(
)
case class PutEnabledJSON(enabled: Boolean)
case class ResourceUserJSON(user_id: String,
email: String,
provider_id: String,
provider: String,
username: String
)
case class ConsumerJSON(consumer_id: Long,
app_name: String,
app_type: String,
@ -180,6 +189,7 @@ case class ConsumerJSON(consumer_id: Long,
developer_email: String,
redirect_url: String,
created_by_user_id: String,
created_by_user: ResourceUserJSON,
enabled: Boolean,
created: Date
)
@ -480,6 +490,18 @@ object JSONFactory210{
}
def createConsumerJSON(c: Consumer): ConsumerJSON = {
val resourceUserJSON = Users.users.vend.getUserByUserId(c.createdByUserId.toString()) match {
case Full(resourceUser) => ResourceUserJSON(
user_id = resourceUser.userId,
email = resourceUser.emailAddress,
provider_id = resourceUser.idGivenByProvider,
provider = resourceUser.provider,
username = resourceUser.name
)
case _ => null
}
ConsumerJSON(consumer_id=c.id,
app_name=c.name,
app_type=c.appType.toString(),
@ -487,6 +509,7 @@ object JSONFactory210{
developer_email=c.developerEmail,
redirect_url=c.redirectURL,
created_by_user_id =c.createdByUserId,
created_by_user =resourceUserJSON,
enabled=c.isActive,
created=c.createdAt
)

View File

@ -60,7 +60,7 @@ object KafkaMappedConnector extends Connector with Loggable {
type AccountType = KafkaBankAccount
// Local TTL Cache
val cacheTTL = Props.get("connector.cache.ttl.seconds", "0").toInt
val cacheTTL = Props.get("connector.cache.ttl.seconds", "10").toInt
val cachedUser = TTLCache[KafkaInboundValidatedUser](cacheTTL)
val cachedBank = TTLCache[KafkaInboundBank](cacheTTL)
val cachedAccount = TTLCache[KafkaInboundAccount](cacheTTL)

View File

@ -67,7 +67,7 @@ object KafkaMappedConnector_vMar2017 extends Connector with Loggable {
type AccountType = BankAccount2
// Local TTL Cache
val cacheTTL = Props.get("connector.cache.ttl.seconds", "0").toInt
val cacheTTL = Props.get("connector.cache.ttl.seconds", "10").toInt
val cachedUser = TTLCache[InboundValidatedUser](cacheTTL)
val cachedBank = TTLCache[InboundBank](cacheTTL)
val cachedAccount = TTLCache[InboundAccount](cacheTTL)

View File

@ -283,9 +283,16 @@ import net.liftweb.util.Helpers._
return ""
}
/**
* Find current ResourceUser_UserId from AuthUser, it is only used for Consumer registration form to save the USER_ID when register new consumer.
* Find current ResourceUser_UserId from AuthUser, reference the @getCurrentUserUsername
* This method has no parameters, it depends on different login types:
* AuthUser: AuthUser.currentUser
* OAuthHandshake: OAuthHandshake.getUser
* DirectLogin: DirectLogin.getUser
* to get the current Resourceuser.userId feild.
*
* Note: resourceuser has two ids: id(Long) and userid_(String),
* This method return userid_(String).
*/
//TODO may not be a good idea, need modify after refactoring User Models.
def getCurrentResourceUserUserId: String = {
for {
current <- AuthUser.currentUser

View File

@ -16,12 +16,15 @@ object Users extends SimpleInjector {
}
trait Users {
//resourceuser has two ids: id(Long)and userid_(String), this method use id(Long)
def getUserByResourceUserId(id : Long) : Box[User]
//resourceuser has two ids: id(Long)and userid_(String), this method use id(Long)
def getResourceUserByResourceUserId(id : Long) : Box[ResourceUser]
def getUserByProviderId(provider : String, idGivenByProvider : String) : Box[User]
//resourceuser has two ids: id(Long)and userid_(String), this method use userid_(String)
def getUserByUserId(userId : String) : Box[User]
def getUserByUserName(userName: String) : Box[ResourceUser]