mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 15:27:01 +00:00
Centralized generation of UUIDs
This commit is contained in:
parent
da42e49779
commit
fde48b8cb9
@ -67,7 +67,7 @@ trait APIMethods_APIBuilder { self: RestHelper =>
|
||||
}
|
||||
object APIBuilder_Connector {
|
||||
val allAPIBuilderModels = List(MappedTemplate_4824100653501473508)
|
||||
def createTemplate(createTemplateJson: CreateTemplateJson) = Full(MappedTemplate_4824100653501473508.create.mTemplateId(UUID.randomUUID().toString).mAuthor(createTemplateJson.author).mPages(createTemplateJson.pages).mPoints(createTemplateJson.points).saveMe())
|
||||
def createTemplate(createTemplateJson: CreateTemplateJson) = Full(MappedTemplate_4824100653501473508.create.mTemplateId(generateUUID()).mAuthor(createTemplateJson.author).mPages(createTemplateJson.pages).mPoints(createTemplateJson.points).saveMe())
|
||||
def getTemplates() = Full(MappedTemplate_4824100653501473508.findAll())
|
||||
def getTemplateById(templateId: String) = MappedTemplate_4824100653501473508.find(By(MappedTemplate_4824100653501473508.mTemplateId, templateId))
|
||||
def deleteTemplate(templateId: String) = MappedTemplate_4824100653501473508.find(By(MappedTemplate_4824100653501473508.mTemplateId, templateId)).map(_.delete_!)
|
||||
|
||||
@ -1449,7 +1449,7 @@ Returns a string showed to the developer
|
||||
* @return - the HTTP session ID
|
||||
*/
|
||||
def updateCallContextSessionId(callContext: Option[CallContext]): Option[CallContext] = {
|
||||
val sessionId = UUID.randomUUID().toString
|
||||
val sessionId = generateUUID()
|
||||
val gatewayLoginRequestPayloadNew = callContext.map(_.gatewayLoginRequestPayload.map(_.copy(session_id = Some(sessionId)))).flatten
|
||||
callContext.map(_.copy(gatewayLoginRequestPayload = gatewayLoginRequestPayloadNew))
|
||||
}
|
||||
@ -2133,7 +2133,7 @@ Returns a string showed to the developer
|
||||
* Create the explicit CounterpartyId, (Used in `Create counterparty for an account` endpoint ).
|
||||
* This is just a UUID, use both in Counterparty.counterpartyId and CounterpartyMetadata.counterpartyId
|
||||
*/
|
||||
def createExplicitCounterpartyId()= UUID.randomUUID().toString
|
||||
def createExplicitCounterpartyId()= generateUUID()
|
||||
|
||||
/**
|
||||
* Create the implicit CounterpartyId, we can only get limit data from Adapter. (Used in `getTransactions` endpoint, we create the counterparty implicitly.)
|
||||
@ -2268,4 +2268,10 @@ Returns a string showed to the developer
|
||||
json.parse(jsonStringFromFile)
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is used to centralize generation of UUID values
|
||||
* @return UUID as a String value
|
||||
*/
|
||||
def generateUUID(): String = UUID.randomUUID().toString
|
||||
|
||||
}
|
||||
@ -64,7 +64,7 @@ object RateLimitUtil extends MdcLoggable {
|
||||
|
||||
def isRedisAvailable() = {
|
||||
try {
|
||||
val uuid = UUID.randomUUID().toString()
|
||||
val uuid = APIUtil.generateUUID()
|
||||
jedis.connect()
|
||||
jedis.set(uuid, "10")
|
||||
jedis.exists(uuid) == true
|
||||
|
||||
@ -899,8 +899,8 @@ trait APIMethods220 {
|
||||
u <- cc.user ?~! UserNotLoggedIn
|
||||
_ <- booleanToBox(hasEntitlement("", u.userId, ApiRole.canCreateConsumer), UserHasMissingRoles + CanCreateConsumer )
|
||||
postedJson <- tryo {json.extract[ConsumerPostJSON]} ?~! InvalidJsonFormat
|
||||
consumer <- Consumers.consumers.vend.createConsumer(Some(UUID.randomUUID().toString),
|
||||
Some(UUID.randomUUID().toString),
|
||||
consumer <- Consumers.consumers.vend.createConsumer(Some(generateUUID()),
|
||||
Some(generateUUID()),
|
||||
Some(postedJson.enabled),
|
||||
Some(postedJson.app_name),
|
||||
None,
|
||||
|
||||
@ -483,7 +483,7 @@ trait Connector extends MdcLoggable{
|
||||
isPositiveAmtToSend <- booleanToBox(rawAmt > BigDecimal("0"), s"Can't send a payment with a value of 0 or less. (${rawAmt})")
|
||||
// Version 200 below has more support for charge
|
||||
charge = TransactionRequestCharge("Charge for completed transaction", AmountOfMoney(body.value.currency, "0.00"))
|
||||
transactionRequest <- createTransactionRequestImpl(TransactionRequestId(java.util.UUID.randomUUID().toString), transactionRequestType, fromAccount, toAccount, body, status.toString, charge)
|
||||
transactionRequest <- createTransactionRequestImpl(TransactionRequestId(generateUUID()), transactionRequestType, fromAccount, toAccount, body, status.toString, charge)
|
||||
} yield transactionRequest
|
||||
|
||||
//make sure we get something back
|
||||
@ -509,7 +509,7 @@ trait Connector extends MdcLoggable{
|
||||
}
|
||||
} else {
|
||||
//if challenge necessary, create a new one
|
||||
val challenge = TransactionRequestChallenge(id = java.util.UUID.randomUUID().toString, allowed_attempts = 3, challenge_type = TransactionChallengeTypes.SANDBOX_TAN.toString)
|
||||
val challenge = TransactionRequestChallenge(id = generateUUID(), allowed_attempts = 3, challenge_type = TransactionChallengeTypes.SANDBOX_TAN.toString)
|
||||
saveTransactionRequestChallenge(result.id, challenge)
|
||||
result = result.copy(challenge = challenge)
|
||||
}
|
||||
@ -542,7 +542,7 @@ trait Connector extends MdcLoggable{
|
||||
chargeValue <- tryo {(BigDecimal(body.value.amount) * 0.0001).setScale(10, BigDecimal.RoundingMode.HALF_UP).toDouble} ?~! s"could not create charge for ${body.value.amount}"
|
||||
charge = TransactionRequestCharge("Total charges for completed transaction", AmountOfMoney(body.value.currency, chargeValue.toString()))
|
||||
|
||||
transactionRequest <- createTransactionRequestImpl(TransactionRequestId(java.util.UUID.randomUUID().toString), transactionRequestType, fromAccount, toAccount, body, status.toString, charge)
|
||||
transactionRequest <- createTransactionRequestImpl(TransactionRequestId(generateUUID()), transactionRequestType, fromAccount, toAccount, body, status.toString, charge)
|
||||
} yield transactionRequest
|
||||
|
||||
//make sure we get something back
|
||||
@ -577,7 +577,7 @@ trait Connector extends MdcLoggable{
|
||||
}
|
||||
} else {
|
||||
//if challenge necessary, create a new one
|
||||
val challenge = TransactionRequestChallenge(id = java.util.UUID.randomUUID().toString, allowed_attempts = 3, challenge_type = TransactionChallengeTypes.SANDBOX_TAN.toString)
|
||||
val challenge = TransactionRequestChallenge(id = generateUUID(), allowed_attempts = 3, challenge_type = TransactionChallengeTypes.SANDBOX_TAN.toString)
|
||||
saveTransactionRequestChallenge(result.id, challenge)
|
||||
result = result.copy(challenge = challenge)
|
||||
}
|
||||
@ -654,7 +654,7 @@ trait Connector extends MdcLoggable{
|
||||
chargeValue <- getChargeValue(chargeLevelAmount,transactionRequestCommonBodyAmount) ?~! GetChargeValueException
|
||||
charge = TransactionRequestCharge("Total charges for completed transaction", AmountOfMoney(transactionRequestCommonBody.value.currency, chargeValue))
|
||||
// Always create a new Transaction Request
|
||||
transactionRequest <- createTransactionRequestImpl210(TransactionRequestId(java.util.UUID.randomUUID().toString), transactionRequestType, fromAccount, toAccount, transactionRequestCommonBody, detailsPlain, status.toString, charge, chargePolicy) ?~! InvalidConnectorResponseForCreateTransactionRequestImpl210
|
||||
transactionRequest <- createTransactionRequestImpl210(TransactionRequestId(generateUUID()), transactionRequestType, fromAccount, toAccount, transactionRequestCommonBody, detailsPlain, status.toString, charge, chargePolicy) ?~! InvalidConnectorResponseForCreateTransactionRequestImpl210
|
||||
|
||||
// If no challenge necessary, create Transaction immediately and put in data store and object to return
|
||||
newTransactionRequest <- status match {
|
||||
@ -687,7 +687,7 @@ trait Connector extends MdcLoggable{
|
||||
challengeAnswer <- createChallenge(fromAccount.bankId, fromAccount.accountId, initiator.userId, transactionRequestType: TransactionRequestType, transactionRequest.id.value
|
||||
) ?~! "OBP-40xxx : createTransactionRequestv300.createChallenge exception !"
|
||||
|
||||
challengeId = UUID.randomUUID().toString
|
||||
challengeId = generateUUID()
|
||||
salt = BCrypt.gensalt()
|
||||
challengeAnswerHashed = BCrypt.hashpw(challengeAnswer, salt).substring(0, 44)
|
||||
|
||||
|
||||
@ -735,7 +735,7 @@ object KafkaMappedConnector extends Connector with KafkaHelper with MdcLoggable
|
||||
//TODO: pass in currency as a parameter?
|
||||
val account = createAccountIfNotExisting(
|
||||
bank.bankId,
|
||||
AccountId(UUID.randomUUID().toString),
|
||||
AccountId(APIUtil.generateUUID()),
|
||||
accountNumber,
|
||||
accountType,
|
||||
accountLabel,
|
||||
|
||||
@ -876,7 +876,7 @@ object KafkaMappedConnector_JVMcompatible extends Connector with KafkaHelper wit
|
||||
fromAccountBankId = fromAccount.bankId.value , //"00100", //need fill 3
|
||||
fromAccountCurrency = fromAccount.currency,//"XAF", //need fill 4
|
||||
//transaction detail
|
||||
transactionId = UUID.randomUUID().toString.take(35), //need fill 5
|
||||
transactionId = APIUtil.generateUUID().take(35), //need fill 5
|
||||
transactionRequestType = transactionRequestType.value,
|
||||
transactionCurrency = "XAF", //need fill 6
|
||||
transactionAmount = amount.toString(), //"3001", //need fill 7
|
||||
@ -1014,7 +1014,7 @@ object KafkaMappedConnector_JVMcompatible extends Connector with KafkaHelper wit
|
||||
//TODO: pass in currency as a parameter?
|
||||
val account = createAccountIfNotExisting(
|
||||
bank.bankId,
|
||||
AccountId(UUID.randomUUID().toString),
|
||||
AccountId(APIUtil.generateUUID()),
|
||||
accountNumber,
|
||||
accountType,
|
||||
accountLabel,
|
||||
|
||||
@ -782,7 +782,7 @@ object LocalMappedConnector extends Connector with MdcLoggable {
|
||||
//TODO: pass in currency as a parameter?
|
||||
val account = createAccountIfNotExisting(
|
||||
bank.bankId,
|
||||
AccountId(UUID.randomUUID().toString),
|
||||
AccountId(APIUtil.generateUUID()),
|
||||
accountNumber, accountType,
|
||||
accountLabel, currency,
|
||||
0L, accountHolderName,
|
||||
|
||||
@ -462,7 +462,7 @@ private object LocalRecordConnector extends Connector with MdcLoggable {
|
||||
}
|
||||
}
|
||||
|
||||
val createdAccount = createAccount(hostedBank, AccountId(UUID.randomUUID().toString),
|
||||
val createdAccount = createAccount(hostedBank, AccountId(APIUtil.generateUUID()),
|
||||
accountNumber, accountType, accountLabel, currency, BigDecimal("0.00"), accountHolderName)
|
||||
|
||||
Full((hostedBank, createdAccount))
|
||||
|
||||
@ -620,7 +620,7 @@ object ObpJvmMappedConnector extends Connector with MdcLoggable {
|
||||
|
||||
val userId = AuthUser.getCurrentResourceUserUserId
|
||||
val postedDate = ZonedDateTime.now
|
||||
val transactionUUID = UUID.randomUUID().toString
|
||||
val transactionUUID = APIUtil.generateUUID()
|
||||
// Remove last "-" from UUIID to make it 35-character
|
||||
// long string (8-4-4-4-12 -> 8-4-4-16)
|
||||
val transactionId = transactionUUID.patch(transactionUUID.lastIndexOf('-'), "", 1)
|
||||
@ -764,7 +764,7 @@ object ObpJvmMappedConnector extends Connector with MdcLoggable {
|
||||
//TODO: pass in currency as a parameter?
|
||||
val account = createAccountIfNotExisting(
|
||||
bank.bankId,
|
||||
AccountId(UUID.randomUUID().toString),
|
||||
AccountId(APIUtil.generateUUID()),
|
||||
accountNumber,
|
||||
accountType,
|
||||
accountLabel,
|
||||
|
||||
@ -1019,7 +1019,7 @@ trait KafkaMappedConnector_vMar2017 extends Connector with KafkaHelper with MdcL
|
||||
chargePolicy: String): Box[TransactionId] = {
|
||||
|
||||
val postedDate = APIUtil.DateWithMsFormat.format(now)
|
||||
val transactionId = UUID.randomUUID().toString
|
||||
val transactionId = APIUtil.generateUUID()
|
||||
|
||||
val req = OutboundSaveTransactionBase(
|
||||
messageFormat = messageFormat,
|
||||
@ -1358,7 +1358,7 @@ trait KafkaMappedConnector_vMar2017 extends Connector with KafkaHelper with MdcL
|
||||
//TODO: pass in currency as a parameter?
|
||||
val account = createAccountIfNotExisting(
|
||||
bank.bankId,
|
||||
AccountId(UUID.randomUUID().toString),
|
||||
AccountId(APIUtil.generateUUID()),
|
||||
accountNumber,
|
||||
accountType,
|
||||
accountLabel,
|
||||
|
||||
@ -36,7 +36,7 @@ class KafkaStreamsHelperActor extends Actor with ObpActorInit with ObpActorHelpe
|
||||
*Random select the partitions number from 0 to kafka.partitions value
|
||||
*The specified partition number will be inside the Key.
|
||||
*/
|
||||
private def keyAndPartition = scala.util.Random.nextInt(partitions) + "_" + UUID.randomUUID().toString
|
||||
private def keyAndPartition = scala.util.Random.nextInt(partitions) + "_" + APIUtil.generateUUID()
|
||||
|
||||
private val producerSettings = if (APIUtil.getPropsValue("kafka.use.ssl").getOrElse("false") == "true") {
|
||||
ProducerSettings(system, new StringSerializer, new StringSerializer)
|
||||
|
||||
@ -350,7 +350,7 @@ class Consumer extends LongKeyedMapper[Consumer] with CreatedUpdated{
|
||||
//For now consumerId is only used in Gateway Login, all other cases, we should use the id instead `consumerId`.
|
||||
object id extends MappedLongIndex(this)
|
||||
object consumerId extends MappedString(this, 250) { // Introduced to cover gateway login functionality
|
||||
override def defaultValue = UUID.randomUUID().toString
|
||||
override def defaultValue = APIUtil.generateUUID()
|
||||
}
|
||||
|
||||
private def minLength3(field: MappedString[Consumer])( s : String) = {
|
||||
|
||||
@ -600,7 +600,7 @@ import net.liftweb.util.Helpers._
|
||||
.email(extEmail)
|
||||
.username(extUsername)
|
||||
// No need to store password, so store dummy string instead
|
||||
.password(UUID.randomUUID().toString)
|
||||
.password(generateUUID())
|
||||
.provider(extProvider)
|
||||
.validated(true)
|
||||
// Save the user in order to be able to log in
|
||||
|
||||
@ -21,7 +21,7 @@ class MappedTransaction extends LongKeyedMapper[MappedTransaction] with IdPK wit
|
||||
object bank extends MappedString(this, 255)
|
||||
object account extends AccountIdString(this)
|
||||
object transactionId extends MappedString(this, 255) {
|
||||
override def defaultValue = UUID.randomUUID().toString
|
||||
override def defaultValue = APIUtil.generateUUID()
|
||||
}
|
||||
|
||||
//TODO: review the need for this
|
||||
@ -222,7 +222,7 @@ object MappedTransaction extends MappedTransaction with LongKeyedMetaMapper[Mapp
|
||||
override def afterSave = List(
|
||||
t =>
|
||||
tryo {
|
||||
val eventId = UUID.randomUUID().toString()
|
||||
val eventId = APIUtil.generateUUID()
|
||||
val actor = ObpLookupSystem.getWebHookActor()
|
||||
actor ! WebHookActor.Request(
|
||||
ApiTrigger.onBalanceChange,
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
package code.util
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
import code.api.util.APIUtil.generateUUID
|
||||
import net.liftweb.mapper.{MappedString, Mapper}
|
||||
|
||||
class MappedUUID[T <: Mapper[T]] (override val fieldOwner : T) extends MappedString(fieldOwner, 36) {
|
||||
override def defaultValue = UUID.randomUUID().toString
|
||||
override def defaultValue = generateUUID()
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import java.text.SimpleDateFormat
|
||||
import java.util.{Date, UUID}
|
||||
|
||||
import code.api.util.APIUtil.OAuth._
|
||||
import code.api.util.ApiRole
|
||||
import code.api.util.{APIUtil, ApiRole}
|
||||
import code.api.v1_4_0.JSONFactory1_4_0.CustomerFaceImageJson
|
||||
import code.api.v1_4_0.V140ServerSetup
|
||||
import code.api.v2_0_0.CreateCustomerJson
|
||||
@ -70,7 +70,7 @@ class MappedCustomerProviderTest extends V140ServerSetup with DefaultUsers {
|
||||
}
|
||||
|
||||
scenario("Customer exists and we try to get it") {
|
||||
val customerId = createCustomer(testBankId1, resourceUser1, UUID.randomUUID().toString, user1)
|
||||
val customerId = createCustomer(testBankId1, resourceUser1, APIUtil.generateUUID(), user1)
|
||||
Given("MappedCustomer exists for a user")
|
||||
When("We try to get it")
|
||||
val foundOpt = Customer.customerProvider.vend.getCustomerByUserId(testBankId1, resourceUser1.userId)
|
||||
|
||||
@ -196,7 +196,7 @@ object PostCustomer extends SendServerRequests {
|
||||
|
||||
val url = s"/v2.1.0/banks/${b.id}/customers"
|
||||
|
||||
val customerId: String = UUID.randomUUID().toString
|
||||
val customerId: String = APIUtil.generateUUID()
|
||||
|
||||
val customerFaceImageJson = CustomerFaceImageJson(url = c.face_image.url, date = c.face_image.date)
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ trait LocalMappedConnectorTestSetup extends TestConnectorSetupWithStandardPermis
|
||||
thisBankId = bankId,
|
||||
thisAccountId = accountId,
|
||||
thisViewId = "",
|
||||
name = UUID.randomUUID().toString,
|
||||
name = APIUtil.generateUUID(),
|
||||
otherAccountRoutingScheme = otherAccountRoutingScheme,
|
||||
otherAccountRoutingAddress = accountId,
|
||||
otherBankRoutingScheme = "OBP",
|
||||
@ -138,7 +138,7 @@ trait LocalMappedConnectorTestSetup extends TestConnectorSetupWithStandardPermis
|
||||
override protected def createTransactionRequest(account: BankAccount) = {
|
||||
|
||||
MappedTransactionRequest.create
|
||||
.mTransactionRequestId(UUID.randomUUID().toString)
|
||||
.mTransactionRequestId(APIUtil.generateUUID())
|
||||
.mType("SANDBOX_TAN")
|
||||
.mFrom_BankId(account.bankId.value)
|
||||
.mFrom_AccountId(account.accountId.value)
|
||||
@ -153,7 +153,7 @@ trait LocalMappedConnectorTestSetup extends TestConnectorSetupWithStandardPermis
|
||||
.saveMe
|
||||
|
||||
MappedTransactionRequest.create
|
||||
.mTransactionRequestId(UUID.randomUUID().toString)
|
||||
.mTransactionRequestId(APIUtil.generateUUID())
|
||||
.mType("SANDBOX_TAN")
|
||||
.mFrom_BankId(account.bankId.value)
|
||||
.mFrom_AccountId(account.accountId.value)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user