feature/Bump H2 library; 1.4.141 -> 2.1.214

This commit is contained in:
Marko Milić 2022-07-15 15:03:16 +02:00
parent f55c818daf
commit fcb9866654
21 changed files with 106 additions and 76 deletions

View File

@ -115,7 +115,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.191</version>
<version>2.1.214</version>
<scope>runtime</scope>
</dependency>
<dependency>

View File

@ -66,10 +66,11 @@ tests.port=8016
End of minimum settings
####################################
#if connector is mapped, set a database backend. If not set, this will be set to an in-memory h2 database by default
#you can use a no config needed h2 database by setting db.driver=org.h2.Driver and not including db.url
# if connector is mapped, set a database backend. If not set, this will be set to an in-memory h2 database by default
# you can use a no config needed h2 database by setting db.driver=org.h2.Driver and not including db.url
# Please note that since update o version 2.1.214 we use NON_KEYWORDS=VALUE to bypass reserved word issue in SQL statements
#db.driver=org.h2.Driver
#db.url=jdbc:h2:./lift_proto.db;DB_CLOSE_ON_EXIT=FALSE
#db.url=jdbc:h2:./lift_proto.db;NON_KEYWORDS=VALUE;DB_CLOSE_ON_EXIT=FALSE
#set this to false if you don't want the api payments call to work
payments_enabled=false

View File

@ -246,14 +246,14 @@ class Boot extends MdcLoggable {
case Props.RunModes.Test =>
new StandardDBVendor(
driver,
APIUtil.getPropsValue("db.url") openOr "jdbc:h2:mem:OBPTest;DB_CLOSE_DELAY=-1",
APIUtil.getPropsValue("db.url") openOr Constant.h2DatabaseDefaultUrlValue,
APIUtil.getPropsValue("db.user").orElse(Empty),
APIUtil.getPropsValue("db.password").orElse(Empty)
)
case _ =>
new StandardDBVendor(
driver,
"jdbc:h2:mem:OBPTest;DB_CLOSE_DELAY=-1",
h2DatabaseDefaultUrlValue,
Empty, Empty)
}

View File

@ -8,6 +8,8 @@ import com.openbankproject.commons.util.ApiStandards
// Note: Import this with: import code.api.Constant._
object Constant extends MdcLoggable {
logger.info("Instantiating Constants")
final val h2DatabaseDefaultUrlValue = "jdbc:h2:mem:OBPTest_H2_v2.1.214;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=10"
final val HostName = APIUtil.getPropsValue("hostname").openOrThrowException(ErrorMessages.HostnameNotSpecified)
def localIdentityProvider = APIUtil.getPropsValue("local_identity_provider", HostName)

View File

@ -64,15 +64,15 @@ object Migration extends MdcLoggable {
addAccountAccessConsumerId()
populateTableViewDefinition()
populateTableAccountAccess()
generateAndPopulateMissingCustomerUUIDs()
generateAndPopulateMissingConsumersUUIDs()
generateAndPopulateMissingCustomerUUIDs(startedBeforeSchemifier)
generateAndPopulateMissingConsumersUUIDs(startedBeforeSchemifier)
populateTableRateLimiting()
updateTableViewDefinition()
bankAccountHoldersAndOwnerViewAccessInfo()
alterTableMappedConsent()
alterColumnChallengeAtTableMappedConsent()
alterTableOpenIDConnectToken()
alterTableMappedUserAuthContext()
alterTableMappedUserAuthContext(startedBeforeSchemifier)
alterTableMappedUserAuthContextUpdate()
populateNameAndAppTypeFieldsAtConsumerTable()
populateAzpAndSubFieldsAtConsumerTable()
@ -80,7 +80,7 @@ object Migration extends MdcLoggable {
populateSettlementBankAccounts()
alterColumnStatusAtTableMappedConsent()
alterColumnDetailsAtTableTransactionRequest()
deleteDuplicatedRowsInTheTableUserAuthContext()
deleteDuplicatedRowsInTheTableUserAuthContext(startedBeforeSchemifier)
populateTheFieldDeletedAtResourceUser(startedBeforeSchemifier)
populateTheFieldIsActiveAtProductAttribute(startedBeforeSchemifier)
alterColumnUsernameProviderFirstnameAndLastnameAtAuthUser(startedBeforeSchemifier)
@ -124,36 +124,47 @@ object Migration extends MdcLoggable {
}
}
private def generateAndPopulateMissingCustomerUUIDs(): Boolean = {
val name = nameOf(generateAndPopulateMissingCustomerUUIDs)
runOnce(name) {
val startDate = System.currentTimeMillis()
val commitId: String = APIUtil.gitCommit
val isSuccessful = CustomerX.customerProvider.vend.populateMissingUUIDs()
val endDate = System.currentTimeMillis()
private def generateAndPopulateMissingCustomerUUIDs(startedBeforeSchemifier: Boolean): Boolean = {
if(startedBeforeSchemifier == true) {
logger.warn(s"Migration.database.generateAndPopulateMissingCustomerUUIDs(true) cannot be run before Schemifier.")
true
} else {
val name = nameOf(generateAndPopulateMissingCustomerUUIDs(startedBeforeSchemifier))
runOnce(name) {
val startDate = System.currentTimeMillis()
val commitId: String = APIUtil.gitCommit
val isSuccessful = CustomerX.customerProvider.vend.populateMissingUUIDs()
val endDate = System.currentTimeMillis()
val comment: String =
s"""Execute `generateAndPopulateMissingCustomerUUIDs`
|Duration: ${endDate - startDate} ms;
val comment: String =
s"""Execute `generateAndPopulateMissingCustomerUUIDs`
|Duration: ${endDate - startDate} ms;
""".stripMargin
saveLog(name, commitId, isSuccessful, startDate, endDate, comment)
isSuccessful
saveLog(name, commitId, isSuccessful, startDate, endDate, comment)
isSuccessful
}
}
}
private def generateAndPopulateMissingConsumersUUIDs(): Boolean = {
val name = nameOf(generateAndPopulateMissingConsumersUUIDs)
runOnce(name) {
val startDate = System.currentTimeMillis()
val commitId: String = APIUtil.gitCommit
val isSuccessful = Consumers.consumers.vend.populateMissingUUIDs()
val endDate = System.currentTimeMillis()
val comment: String =
s"""Execute `generateAndPopulateMissingConsumersUUIDs`
|Duration: ${endDate - startDate} ms;
private def generateAndPopulateMissingConsumersUUIDs(startedBeforeSchemifier: Boolean): Boolean = {
if(startedBeforeSchemifier == true) {
logger.warn(s"Migration.database.generateAndPopulateMissingConsumersUUIDs(true) cannot be run before Schemifier.")
true
} else {
val name = nameOf(generateAndPopulateMissingConsumersUUIDs(startedBeforeSchemifier))
runOnce(name) {
val startDate = System.currentTimeMillis()
val commitId: String = APIUtil.gitCommit
val isSuccessful = Consumers.consumers.vend.populateMissingUUIDs()
val endDate = System.currentTimeMillis()
val comment: String =
s"""Execute `generateAndPopulateMissingConsumersUUIDs`
|Duration: ${endDate - startDate} ms;
""".stripMargin
saveLog(name, commitId, isSuccessful, startDate, endDate, comment)
isSuccessful
saveLog(name, commitId, isSuccessful, startDate, endDate, comment)
isSuccessful
}
}
}
@ -208,10 +219,15 @@ object Migration extends MdcLoggable {
MigrationOfConsumer.populateAzpAndSub(name)
}
}
private def alterTableMappedUserAuthContext(): Boolean = {
val name = nameOf(alterTableMappedUserAuthContext)
runOnce(name) {
MigrationOfMappedUserAuthContext.dropUniqueIndex(name)
private def alterTableMappedUserAuthContext(startedBeforeSchemifier: Boolean): Boolean = {
if(startedBeforeSchemifier == true) {
logger.warn(s"Migration.database.alterTableMappedUserAuthContext(true) cannot be run before Schemifier.")
true
} else {
val name = nameOf(alterTableMappedUserAuthContext(startedBeforeSchemifier))
runOnce(name) {
MigrationOfMappedUserAuthContext.dropUniqueIndex(name)
}
}
}
private def alterTableMappedUserAuthContextUpdate(): Boolean = {
@ -244,10 +260,15 @@ object Migration extends MdcLoggable {
MigrationOfTransactionRequerst.alterColumnDetails(name)
}
}
private def deleteDuplicatedRowsInTheTableUserAuthContext(): Boolean = {
val name = nameOf(deleteDuplicatedRowsInTheTableUserAuthContext)
runOnce(name) {
MigrationOfUserAuthContext.removeDuplicates(name)
private def deleteDuplicatedRowsInTheTableUserAuthContext(startedBeforeSchemifier: Boolean): Boolean = {
if(startedBeforeSchemifier == true) {
logger.warn(s"Migration.database.deleteDuplicatedRowsInTheTableUserAuthContext(true) cannot be run before Schemifier.")
true
} else {
val name = nameOf(deleteDuplicatedRowsInTheTableUserAuthContext(startedBeforeSchemifier))
runOnce(name) {
MigrationOfUserAuthContext.removeDuplicates(name)
}
}
}
private def populateTheFieldDeletedAtResourceUser(startedBeforeSchemifier: Boolean): Boolean = {

View File

@ -8,10 +8,11 @@ import net.liftweb.mapper.{DB, Schemifier}
import net.liftweb.util.DefaultConnectionIdentifier
import scalikejdbc.DB.CPContext
import scalikejdbc._
import java.time.format.DateTimeFormatter
import java.time.{ZoneId, ZonedDateTime}
import code.api.Constant
object MigrationOfConsentAuthContextDropIndex {
val oneDayAgo = ZonedDateTime.now(ZoneId.of("UTC")).minusDays(1)
@ -19,7 +20,7 @@ object MigrationOfConsentAuthContextDropIndex {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'")
private lazy val getDbConnectionParameters: (String, String, String) = {
val dbUrl = APIUtil.getPropsValue("db.url") openOr "jdbc:h2:mem:OBPTest;DB_CLOSE_DELAY=-1"
val dbUrl = APIUtil.getPropsValue("db.url") openOr Constant.h2DatabaseDefaultUrlValue
val username = dbUrl.split(";").filter(_.contains("user")).toList.headOption.map(_.split("=")(1))
val password = dbUrl.split(";").filter(_.contains("password")).toList.headOption.map(_.split("=")(1))
val dbUser = APIUtil.getPropsValue("db.user").orElse(username)

View File

@ -3,6 +3,7 @@ package code.api.util.migration
import java.time.format.DateTimeFormatter
import java.time.{ZoneId, ZonedDateTime}
import code.api.Constant
import code.api.util.APIUtil
import code.api.util.migration.Migration.{DbFunction, saveLog}
import code.context.MappedUserAuthContext
@ -20,7 +21,7 @@ object MigrationOfUserAuthContext {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'")
private lazy val getDbConnectionParameters: (String, String, String) = {
val dbUrl = APIUtil.getPropsValue("db.url") openOr "jdbc:h2:mem:OBPTest;DB_CLOSE_DELAY=-1"
val dbUrl = APIUtil.getPropsValue("db.url") openOr Constant.h2DatabaseDefaultUrlValue
val username = dbUrl.split(";").filter(_.contains("user")).toList.headOption.map(_.split("=")(1))
val password = dbUrl.split(";").filter(_.contains("password")).toList.headOption.map(_.split("=")(1))
val dbUser = APIUtil.getPropsValue("db.user").orElse(username)
@ -51,6 +52,8 @@ object MigrationOfUserAuthContext {
// Make back up
DbFunction.makeBackUpOfTable(MappedUserAuthContext)
MappedUserAuthContext.findAll()
val startDate = System.currentTimeMillis()
val commitId: String = APIUtil.gitCommit

View File

@ -37,7 +37,7 @@ object BankAttributeProvider extends BankAttributeProviderTrait {
attribute.BankId_(bankId.value)
.Name(name)
.Type(attributType.toString)
.Value(value)
.`Value`(value)
.IsActive(isActive.getOrElse(true))
.saveMe()
}
@ -50,7 +50,7 @@ object BankAttributeProvider extends BankAttributeProviderTrait {
.BankId_(bankId.value)
.Name(name)
.Type(attributType.toString())
.Value(value)
.`Value`(value)
.IsActive(isActive.getOrElse(true))
.saveMe()
}
@ -73,7 +73,7 @@ class BankAttribute extends BankAttributeTrait with LongKeyedMapper[BankAttribut
object BankAttributeId extends MappedUUID(this)
object Name extends MappedString(this, 50)
object Type extends MappedString(this, 50)
object Value extends MappedString(this, 255)
object `Value` extends MappedString(this, 255)
object IsActive extends MappedBoolean(this) {
override def defaultValue = true
}
@ -83,7 +83,7 @@ class BankAttribute extends BankAttributeTrait with LongKeyedMapper[BankAttribut
override def bankAttributeId: String = BankAttributeId.get
override def name: String = Name.get
override def attributeType: BankAttributeType.Value = BankAttributeType.withName(Type.get)
override def value: String = Value.get
override def value: String = `Value`.get
override def isActive: Option[Boolean] = if (IsActive.jdbcFriendly(IsActive.calcFieldName) == null) { None } else Some(IsActive.get)
}

View File

@ -10,6 +10,7 @@ import code.accountapplication.AccountApplicationX
import code.accountattribute.AccountAttributeX
import code.accountholders.{AccountHolders, MapperAccountHolders}
import code.api.BerlinGroup.{AuthenticationType, ScaStatus}
import code.api.Constant
import code.api.Constant.{INCOMING_SETTLEMENT_ACCOUNT_ID, OUTGOING_SETTLEMENT_ACCOUNT_ID}
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON
import code.api.attributedefinition.{AttributeDefinition, AttributeDefinitionDI}
@ -840,7 +841,7 @@ object LocalMappedConnector extends Connector with MdcLoggable {
}
private lazy val getDbConnectionParameters: (String, String, String) = {
val dbUrl = APIUtil.getPropsValue("db.url") openOr "jdbc:h2:mem:OBPTest;DB_CLOSE_DELAY=-1"
val dbUrl = APIUtil.getPropsValue("db.url") openOr Constant.h2DatabaseDefaultUrlValue
val username = dbUrl.split(";").filter(_.contains("user")).toList.headOption.map(_.split("=")(1))
val password = dbUrl.split(";").filter(_.contains("password")).toList.headOption.map(_.split("=")(1))
val dbUser = APIUtil.getPropsValue("db.user").orElse(username)

View File

@ -11,11 +11,11 @@ class MappedConsentAuthContext extends ConsentAuthContext with LongKeyedMapper[M
object ConsentAuthContextId extends MappedUUID(this)
object ConsentId extends UUIDString(this)
object Key extends MappedString(this, 255)
object Value extends MappedString(this, 255)
object `Value` extends MappedString(this, 255)
override def consentId = ConsentId.get
override def key = Key.get
override def value = Value.get
override def value = `Value`.get
override def consentAuthContextId = ConsentAuthContextId.get
override def timeStamp = createdAt.get
}

View File

@ -19,7 +19,7 @@ object MappedConsentAuthContextProvider extends ConsentAuthContextProvider with
}
def createConsentAuthContextAkka(consentId: String, key: String, value: String): Box[MappedConsentAuthContext] =
tryo {
MappedConsentAuthContext.create.ConsentId(consentId).Key(key).Value(value).saveMe()
MappedConsentAuthContext.create.ConsentId(consentId).Key(key).`Value`(value).saveMe()
}
override def getConsentAuthContexts(consentId: String): Future[Box[List[MappedConsentAuthContext]]] = Future {
@ -50,11 +50,11 @@ object MappedConsentAuthContextProvider extends ConsentAuthContextProvider with
By(MappedConsentAuthContext.ConsentId, consentId),
By(MappedConsentAuthContext.Key, authContext.key)
).map( authContext =>
authContext.Key(authContext.key).Value(authContext.value).saveMe()
authContext.Key(authContext.key).`Value`(authContext.value).saveMe()
)
)
val created = create.map( authContext =>
MappedConsentAuthContext.create.ConsentId(consentId).Key(authContext.key).Value(authContext.value).saveMe()
MappedConsentAuthContext.create.ConsentId(consentId).Key(authContext.key).`Value`(authContext.value).saveMe()
)
tryo {
updated ::: created

View File

@ -4,6 +4,7 @@ import java.sql.{PreparedStatement, Timestamp}
import java.util.Date
import java.util.UUID.randomUUID
import code.api.Constant
import code.api.cache.Caching
import code.api.util._
import code.model.MappedConsumersProvider
@ -65,7 +66,7 @@ object MappedMetrics extends APIMetrics with MdcLoggable{
}
private lazy val getDbConnectionParameters: (String, String, String) = {
val dbUrl = APIUtil.getPropsValue("db.url") openOr "jdbc:h2:mem:OBPTest;DB_CLOSE_DELAY=-1"
val dbUrl = APIUtil.getPropsValue("db.url") openOr Constant.h2DatabaseDefaultUrlValue
val username = dbUrl.split(";").filter(_.contains("user")).toList.headOption.map(_.split("=")(1))
val password = dbUrl.split(";").filter(_.contains("password")).toList.headOption.map(_.split("=")(1))
val dbUser = APIUtil.getPropsValue("db.user").orElse(username)

View File

@ -716,7 +716,7 @@ object MappedNonceProvider extends NoncesProvider {
case None =>
}
value match {
case Some(v) => n.value(v)
case Some(v) => n.`value`(v)
case None =>
}
val nonce = n.saveMe()
@ -733,7 +733,7 @@ object MappedNonceProvider extends NoncesProvider {
timestamp: Date,
value: String): Long = {
Nonce.count(
By(Nonce.value, value),
By(Nonce.`value`, value),
By(Nonce.tokenKey, tokenKey),
By(Nonce.consumerkey, consumerKey),
By(Nonce.timestamp, timestamp)
@ -763,7 +763,7 @@ class Nonce extends LongKeyedMapper[Nonce] {
timestamp.get.getTime().toString()
}
}
object value extends MappedString(this,250)
object `value` extends MappedString(this,250)
}
object Nonce extends Nonce with LongKeyedMetaMapper[Nonce]{}

View File

@ -99,7 +99,7 @@ object MappedTransactionRequestAttributeProvider extends TransactionRequestAttri
.TransactionRequestId(transactionRequestId.value)
.Name(name)
.Type(attributeType.toString)
.Value(value)
.`Value`(value)
.saveMe()
}
case _ => Empty
@ -112,7 +112,7 @@ object MappedTransactionRequestAttributeProvider extends TransactionRequestAttri
.TransactionRequestId(transactionRequestId.value)
.Name(name)
.Type(attributeType.toString())
.Value(value)
.`Value`(value)
.saveMe()
}
}
@ -131,7 +131,7 @@ object MappedTransactionRequestAttributeProvider extends TransactionRequestAttri
.BankId(bankId.value)
.Name(transactionRequestAttribute.name)
.Type(transactionRequestAttribute.attributeType.toString())
.Value(transactionRequestAttribute.value)
.`Value`(transactionRequestAttribute.value)
.saveMe()
}
}

View File

@ -21,7 +21,7 @@ class TransactionRequestAttribute extends TransactionRequestAttributeTrait with
override def attributeType: TransactionRequestAttributeType.Value = TransactionRequestAttributeType.withName(Type.get)
override def value: String = Value.get
override def value: String = `Value`.get
object BankId extends UUIDString(this) // combination of this
@ -33,7 +33,7 @@ class TransactionRequestAttribute extends TransactionRequestAttributeTrait with
object Type extends MappedString(this, 50)
object Value extends MappedString(this, 255)
object `Value` extends MappedString(this, 255)
}

View File

@ -39,7 +39,7 @@ object MappedUserAttributeProvider extends UserAttributeProvider {
.UserId(userId)
.Name(name)
.Type(attributeType.toString)
.Value(value)
.`Value`(value)
.saveMe()
}
case _ => Empty
@ -51,7 +51,7 @@ object MappedUserAttributeProvider extends UserAttributeProvider {
.UserId(userId)
.Name(name)
.Type(attributeType.toString())
.Value(value)
.`Value`(value)
.saveMe()
}
}
@ -67,13 +67,13 @@ class UserAttribute extends UserAttributeTrait with LongKeyedMapper[UserAttribut
object UserId extends MappedUUID(this)
object Name extends MappedString(this, 50)
object Type extends MappedString(this, 50)
object Value extends MappedString(this, 255)
object `Value` extends MappedString(this, 255)
override def userAttributeId: String = UserAttributeId.get
override def userId: String = UserId.get
override def name: String = Name.get
override def attributeType: UserAttributeType.Value = UserAttributeType.withName(Type.get)
override def value: String = Value.get
override def value: String = `Value`.get
override def insertDate: Date = createdAt.get
}

View File

@ -14,12 +14,12 @@ trait NewAttributeQueryTrait {
// TODO Should we rename this column to attributeName
private lazy val nameColumn = Name.dbColumnName
// TODO Should we rename this column to attributeValue
private lazy val valueColumn = Value.dbColumnName
private lazy val valueColumn = `Value`.dbColumnName
private lazy val parentIdColumn = ParentId.dbColumnName
private lazy val bankIdColumn = BankId.dbColumnName
val BankId: BaseMappedField
val Name: BaseMappedField
val Value: BaseMappedField
val `Value`: BaseMappedField
/**
* Attribute entity's parent id, for example: CustomerAttribute.customerId,
* need implemented in companion object

View File

@ -23,7 +23,7 @@ object MappedWebUiPropsProvider extends WebUiPropsProvider {
override def createOrUpdate(webUiProps: WebUiPropsT): Box[WebUiPropsT] = {
WebUiProps.find(By(WebUiProps.Name, webUiProps.name))
.or(Full(WebUiProps.create))
.map(_.Name(webUiProps.name).Value(webUiProps.value).saveMe())
.map(_.Name(webUiProps.name).Value1(webUiProps.value).saveMe())
}
override def delete(webUiPropsId: String):Box[Boolean] = WebUiProps.find(By(WebUiProps.WebUiPropsId, webUiPropsId)) match {
@ -60,11 +60,11 @@ class WebUiProps extends WebUiPropsT with LongKeyedMapper[WebUiProps] with IdPK
object WebUiPropsId extends MappedUUID(this)
object Name extends MappedString(this, 255)
object Value extends MappedText(this)
object Value1 extends MappedText(this)
override def webUiPropsId: Option[String] = Option(WebUiPropsId.get)
override def name: String = Name.get
override def value: String = Value.get
override def value: String = Value1.get
}
object WebUiProps extends WebUiProps with LongKeyedMetaMapper[WebUiProps] {

View File

@ -105,7 +105,7 @@ class MappedAtmsProviderTest extends ServerSetup {
atms.size should equal(3)
And("they should be the licensed ones")
atms should equal (expectedAtms)
atms.sortBy(_.atmId.value) should equal (expectedAtms.sortBy(_.atmId.value))
}
scenario("We try to get atms for a bank that doesn't have any") {

View File

@ -104,7 +104,7 @@ class MappedBranchesProviderTest extends ServerSetup {
branches.size should equal(3)
And("they should be the licensed ones")
branches should equal (expectedBranches)
branches.sortBy(_.branchId.value) should equal (expectedBranches.sortBy(_.branchId.value))
}
scenario("We try to get branches for a bank that doesn't have any") {

View File

@ -93,7 +93,7 @@ class MappedProductsProviderTest extends ServerSetup {
products.size should equal(3)
And("they should be the licensed ones")
products should equal (expectedProducts)
products.sortBy(_.code.value) should equal (expectedProducts.sortBy(_.code.value))
}
scenario("We try to get Products for a bank that doesn't have any") {