diff --git a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala index 06e882cd20..4e207267aa 100644 --- a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala +++ b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala @@ -144,7 +144,7 @@ import net.liftweb.http.LiftRules.DispatchPF import net.liftweb.http._ import net.liftweb.http.provider.HTTPCookie import net.liftweb.json.Extraction -import net.liftweb.mapper._ +import net.liftweb.mapper.{DefaultConnectionIdentifier=>_, _} import net.liftweb.sitemap.Loc._ import net.liftweb.sitemap._ import net.liftweb.util.Helpers._ @@ -255,22 +255,22 @@ class Boot extends MdcLoggable { schemifyAll() - logger.info("Mapper database info: " + Migration.DbFunction.mapperDatabaseInfo(APIUtil.vendor)) - - // DbFunction.tableExists(ResourceUser, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { - // case true => // DB already exist - // // Migration Scripts are used to update the model of OBP-API DB to a latest version. - // // Please note that migration scripts are executed before Lift Mapper Schemifier - //// Migration.database.executeScripts(startedBeforeSchemifier = true) - // logger.info("The Mapper database already exits. The scripts are executed BEFORE Lift Mapper Schemifier.") - // case false => // DB is still not created. The scripts will be executed after Lift Mapper Schemifier - // logger.info("The Mapper database is still not created. The scripts are going to be executed AFTER Lift Mapper Schemifier.") - // } + logger.info("Mapper database info: " + Migration.DbFunction.mapperDatabaseInfo) + + DbFunction.tableExists(ResourceUser) match { + case true => // DB already exist + // Migration Scripts are used to update the model of OBP-API DB to a latest version. + // Please note that migration scripts are executed before Lift Mapper Schemifier + Migration.database.executeScripts(startedBeforeSchemifier = true) + logger.info("The Mapper database already exits. The scripts are executed BEFORE Lift Mapper Schemifier.") + case false => // DB is still not created. The scripts will be executed after Lift Mapper Schemifier + logger.info("The Mapper database is still not created. The scripts are going to be executed AFTER Lift Mapper Schemifier.") + } // Migration Scripts are used to update the model of OBP-API DB to a latest version. // Please note that migration scripts are executed after Lift Mapper Schemifier - //Migration.database.executeScripts(startedBeforeSchemifier = false) + Migration.database.executeScripts(startedBeforeSchemifier = false) if (APIUtil.getPropsAsBoolValue("create_system_views_at_boot", true)) { // Create system views @@ -285,18 +285,6 @@ class Boot extends MdcLoggable { Views.views.vend.getOrCreateSystemView(SYSTEM_FIREHOSE_VIEW_ID).isDefined else Empty.isDefined - val comment: String = - s""" - |System view ${SYSTEM_OWNER_VIEW_ID} exists/created at the instance: ${owner} - |System view ${SYSTEM_AUDITOR_VIEW_ID} exists/created at the instance: ${auditor} - |System view ${SYSTEM_ACCOUNTANT_VIEW_ID} exists/created at the instance: ${accountant} - |System view ${SYSTEM_FIREHOSE_VIEW_ID} exists/created at the instance: ${accountFirehose} - |System view ${SYSTEM_STANDARD_VIEW_ID} exists/created at the instance: ${standard} - |System view ${SYSTEM_STAGE_ONE_VIEW_ID} exists/created at the instance: ${stageOne} - |System view ${SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID} exists/created at the instance: ${manageCustomViews} - |""".stripMargin - logger.info(comment) - APIUtil.getPropsValue("additional_system_views") match { case Full(value) => val viewSetUKOpenBanking = value.split(",").map(_.trim).toList @@ -313,8 +301,6 @@ class Boot extends MdcLoggable { if viewsUKOpenBanking.exists(_ == systemView) } { Views.views.vend.getOrCreateSystemView(systemView) - val comment = s"System view ${systemView} exists/created at the instance" - logger.info(comment) } case _ => // Do nothing } diff --git a/obp-api/src/main/scala/code/api/util/migration/Migration.scala b/obp-api/src/main/scala/code/api/util/migration/Migration.scala index ef5bb8d3cf..ed5458dfb2 100644 --- a/obp-api/src/main/scala/code/api/util/migration/Migration.scala +++ b/obp-api/src/main/scala/code/api/util/migration/Migration.scala @@ -2,11 +2,10 @@ package code.api.util.migration import bootstrap.liftweb.CustomDBVendor -import java.sql.{ResultSet, SQLException} +import java.sql.{Connection, ResultSet, SQLException} import java.text.SimpleDateFormat import java.util.Date import code.api.util.APIUtil.{getPropsAsBoolValue, getPropsValue} -import code.api.util.ErrorMessages.DatabaseConnectionClosedError import code.api.util.{APIUtil, ApiPropsWithAlias} import code.api.v4_0_0.DatabaseInfoJson import code.consumer.Consumers @@ -17,7 +16,7 @@ import code.util.Helper.MdcLoggable import com.github.dwickern.macros.NameOf.nameOf import com.zaxxer.hikari.pool.ProxyConnection import net.liftweb.mapper.Schemifier.getDefaultSchemaName -import net.liftweb.mapper.{BaseMetaMapper, DB, SuperConnection} +import net.liftweb.mapper.{BaseMetaMapper, DB, DefaultConnectionIdentifier, SuperConnection} import scala.collection.immutable import scala.collection.mutable.HashMap @@ -492,33 +491,43 @@ object Migration extends MdcLoggable { * This function is copied from the module "net.liftweb.mapper.Schemifier". * The purpose is to provide answer does a table exist at a database instance. * For instance migration scripts needs to differentiate update of an instance from build a new one from scratch. + * note: 07.05.2024 now. we get the connection from HikariDatasource.ds instead of Liftweb. */ - def tableExists (table: BaseMetaMapper, connection: SuperConnection, actualTableNames: HashMap[String, String] = new HashMap[String, String]()): Boolean = { - val md = connection.getMetaData - using(md.getTables(null, getDefaultSchemaName(connection), null, null)){ rs => - def hasTable(rs: ResultSet): Boolean = - if (!rs.next) false - else rs.getString(3) match { - case s if s.toLowerCase == table._dbTableNameLC.toLowerCase => actualTableNames(table._dbTableNameLC) = s; true - case _ => hasTable(rs) + def tableExists (table: BaseMetaMapper, actualTableNames: HashMap[String, String] = new HashMap[String, String]()): Boolean = { + DB.use(net.liftweb.util.DefaultConnectionIdentifier) { + conn => + val md = conn.getMetaData + val schema = getDefaultSchemaName(conn) + + using(md.getTables(null, schema, null, null)){ rs => + def hasTable(rs: ResultSet): Boolean = + if (!rs.next) false + else rs.getString(3) match { + case s if s.toLowerCase == table._dbTableNameLC.toLowerCase => actualTableNames(table._dbTableNameLC) = s; true + case _ => hasTable(rs) + } + + hasTable(rs) } - - hasTable(rs) } } /** * The purpose is to provide answer does a procedure exist at a database instance. */ - def procedureExists(name: String, connection: SuperConnection): Boolean = { - val md = connection.getMetaData - using(md.getProcedures(null, getDefaultSchemaName(connection), null)){ rs => - def hasProcedure(rs: ResultSet): Boolean = - if (!rs.next) false - else rs.getString(3) match { - case s if s.toLowerCase == name => true - case _ => hasProcedure(rs) + def procedureExists(name: String): Boolean = { + DB.use(net.liftweb.util.DefaultConnectionIdentifier) { + conn => + val md = conn.getMetaData + val schema = getDefaultSchemaName(conn) + using(md.getProcedures(null, schema, null)){ rs => + def hasProcedure(rs: ResultSet): Boolean = + if (!rs.next) false + else rs.getString(3) match { + case s if s.toLowerCase == name => true + case _ => hasProcedure(rs) + } + hasProcedure(rs) } - hasProcedure(rs) } } @@ -526,21 +535,14 @@ object Migration extends MdcLoggable { /** * The purpose is to provide info about the database in mapper mode. */ - def mapperDatabaseInfo(vendor: CustomDBVendor): DatabaseInfoJson = { - val connection = vendor.createOne.openOrThrowException(DatabaseConnectionClosedError) - try { - val md = connection.getMetaData - val productName = md.getDatabaseProductName() - val productVersion = md.getDatabaseProductVersion() - DatabaseInfoJson(product_name = productName, product_version = productVersion) - } finally { - try { - connection.asInstanceOf[ProxyConnection].close() - } catch { - case t: Throwable => logger.error(s"mapperDatabaseInfo.close connection throw exception, detail is: $t") - } + def mapperDatabaseInfo: DatabaseInfoJson = { + DB.use(net.liftweb.util.DefaultConnectionIdentifier) { + conn => + val md = conn.getMetaData + val productName = md.getDatabaseProductName() + val productVersion = md.getDatabaseProductVersion() + DatabaseInfoJson(product_name = productName, product_version = productVersion) } - } /** @@ -555,16 +557,19 @@ object Migration extends MdcLoggable { * * @return SQL command. */ - def maybeWrite(performWrite: Boolean, logFunc: (=> AnyRef) => Unit, connection: SuperConnection) (makeSql: () => String) : String ={ - val ct = makeSql() - logger.trace("maybeWrite DDL: "+ct) - if (performWrite) { - logFunc(ct) - val st = connection.createStatement - st.execute(ct) - st.close - } - ct + def maybeWrite(performWrite: Boolean, logFunc: (=> AnyRef) => Unit) (makeSql: () => String) : String ={ + DB.use(net.liftweb.util.DefaultConnectionIdentifier) { + conn => + val ct = makeSql() + logger.trace("maybeWrite DDL: " + ct) + if (performWrite) { + logFunc(ct) + val st = conn.createStatement + st.execute(ct) + st.close + } + ct + } } /** diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationInfoOfAccoutHolders.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationInfoOfAccoutHolders.scala index 01e98c1140..321f33bf87 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationInfoOfAccoutHolders.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationInfoOfAccoutHolders.scala @@ -18,7 +18,7 @@ object BankAccountHoldersAndOwnerViewAccess { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def saveInfoBankAccountHoldersAndOwnerViewAccessInfo(name: String): Boolean = { - DbFunction.tableExists(MapperAccountHolders, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MapperAccountHolders) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccess.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccess.scala index 0aad03910d..34ebe8c32a 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccess.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccess.scala @@ -9,7 +9,7 @@ import net.liftweb.util.DefaultConnectionIdentifier object TableAccountAccess { def populate(name: String): Boolean = { - DbFunction.tableExists(ViewPrivileges, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ViewPrivileges) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccessAddedConsumerId.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccessAddedConsumerId.scala index 9c056190ec..71b97a164c 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccessAddedConsumerId.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccessAddedConsumerId.scala @@ -18,14 +18,14 @@ object MigrationOfAccountAccessAddedConsumerId { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def addAccountAccessConsumerId(name: String): Boolean = { - DbFunction.tableExists(AccountAccess, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(AccountAccess) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountRoutings.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountRoutings.scala index 070e076f1c..999f38119f 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountRoutings.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountRoutings.scala @@ -17,7 +17,7 @@ object MigrationOfAccountRoutings { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def populate(name: String): Boolean = { - DbFunction.tableExists(BankAccountRouting, (DB.use(DefaultConnectionIdentifier) { conn => conn })) match { + DbFunction.tableExists(BankAccountRouting) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAuthUser.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAuthUser.scala index 90f61b1599..c1733fbe5f 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAuthUser.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAuthUser.scala @@ -17,14 +17,14 @@ object MigrationOfAuthUser { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnUsernameProviderEmailFirstnameAndLastname(name: String): Boolean = { - DbFunction.tableExists(AuthUser, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(AuthUser) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => @@ -70,14 +70,14 @@ object MigrationOfAuthUser { } def dropIndexAtColumnUsername(name: String): Boolean = { - DbFunction.tableExists(AuthUser, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(AuthUser) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case _ => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsentAuthContextDropIndex.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsentAuthContextDropIndex.scala index 3a25f41d2d..1f105ae6a0 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsentAuthContextDropIndex.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsentAuthContextDropIndex.scala @@ -38,14 +38,14 @@ object MigrationOfConsentAuthContextDropIndex { } def dropUniqueIndex(name: String): Boolean = { - DbFunction.tableExists(MappedConsentAuthContext, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedConsentAuthContext) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case _ => () => "DROP INDEX IF EXISTS consentauthcontext_consentid_key_c;" diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumer.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumer.scala index 27e30d7bbd..47e7e2ff60 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumer.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumer.scala @@ -16,7 +16,7 @@ object MigrationOfConsumer { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def populateNamAndAppType(name: String): Boolean = { - DbFunction.tableExists(Consumer, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(Consumer) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit @@ -62,7 +62,7 @@ object MigrationOfConsumer { } } def populateAzpAndSub(name: String): Boolean = { - DbFunction.tableExists(Consumer, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(Consumer) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumerRateLimiting.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumerRateLimiting.scala index 3bb5a9dff5..eacfb3c0b8 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumerRateLimiting.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumerRateLimiting.scala @@ -19,7 +19,7 @@ object TableRateLmiting { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def populate(name: String): Boolean = { - DbFunction.tableExists(RateLimiting, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(RateLimiting) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfCustomerAttributes.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfCustomerAttributes.scala index 89fee0eb2f..908ffde0f1 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfCustomerAttributes.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfCustomerAttributes.scala @@ -18,14 +18,14 @@ object MigrationOfCustomerAttributes { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnValue(name: String): Boolean = { - DbFunction.tableExists(MappedCustomerAttribute, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedCustomerAttribute) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE mappedcustomerattribute ALTER COLUMN mvalue varchar(2000);" @@ -57,7 +57,7 @@ object MigrationOfCustomerAttributes { } } def populateAzpAndSub(name: String): Boolean = { - DbFunction.tableExists(Consumer, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(Consumer) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseMaterializedView.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseMaterializedView.scala index 8184288b73..d923dff7a7 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseMaterializedView.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseMaterializedView.scala @@ -17,7 +17,7 @@ object MigrationOfFastFireHoseMaterializedView { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def addFastFireHoseMaterializedView(name: String): Boolean = { - DbFunction.tableExists(ProductFee, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ProductFee) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit @@ -75,7 +75,7 @@ object MigrationOfFastFireHoseMaterializedView { | ON (mappedbankaccount.bank = mapperaccountholders.accountbankpermalink and mappedbankaccount.theaccountid = mapperaccountholders.accountpermalink); |""".stripMargin val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") openOr("org.h2.Driver") match { case value if value.contains("org.h2.Driver") => () => migrationSql(false)//Note: H2 database, do not support the MATERIALIZED view diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseView.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseView.scala index 90c97f55fb..f949ddbe58 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseView.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseView.scala @@ -16,14 +16,14 @@ object MigrationOfFastFireHoseView { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def addFastFireHoseView(name: String): Boolean = { - DbFunction.tableExists(ProductFee, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ProductFee) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { () => """ |CREATE VIEW v_fast_firehose_accounts AS select diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedBadLoginAttemptDropIndex.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedBadLoginAttemptDropIndex.scala index 4f6ceb1f61..a3b124edaa 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedBadLoginAttemptDropIndex.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedBadLoginAttemptDropIndex.scala @@ -36,14 +36,14 @@ object MigrationOfMappedBadLoginAttemptDropIndex { } def dropUniqueIndex(name: String): Boolean = { - DbFunction.tableExists(MappedBadLoginAttempt, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedBadLoginAttempt) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case _ => () => "DROP INDEX IF EXISTS mappedbadloginattempt_musername;" diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedConsent.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedConsent.scala index b2fa9c7b84..97407ddfb1 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedConsent.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedConsent.scala @@ -17,14 +17,14 @@ object MigrationOfMappedConsent { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnJsonWebToken(name: String): Boolean = { - DbFunction.tableExists(MappedConsent, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedConsent) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE mappedconsent ALTER COLUMN mjsonwebtoken text;" @@ -57,14 +57,14 @@ object MigrationOfMappedConsent { } def alterColumnChallenge(name: String): Boolean = { - DbFunction.tableExists(MappedConsent, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedConsent) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => @@ -103,14 +103,14 @@ object MigrationOfMappedConsent { } } def alterColumnStatus(name: String): Boolean = { - DbFunction.tableExists(MappedConsent, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedConsent) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala index e29e8881e3..ef5de1ecd7 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala @@ -17,7 +17,7 @@ object MigrationOfMappedExpectedChallengeAnswerFieldLength { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnLength(name: String): Boolean = { - DbFunction.tableExists(MappedExpectedChallengeAnswer, (DB.use(DefaultConnectionIdentifier){ conn => conn})) + DbFunction.tableExists(MappedExpectedChallengeAnswer) match { case true => val startDate = System.currentTimeMillis() @@ -25,17 +25,17 @@ object MigrationOfMappedExpectedChallengeAnswerFieldLength { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => """ - |ALTER TABLE MappedExpectedChallengeAnswer ALTER COLUMN mChallengeType varchar(100); + |ALTER TABLE ExpectedChallengeAnswer ALTER COLUMN ChallengeType varchar(100); |""".stripMargin case _ => () => """ - |ALTER TABLE MappedExpectedChallengeAnswer ALTER COLUMN mChallengeType TYPE character varying(100); + |ALTER TABLE ExpectedChallengeAnswer ALTER COLUMN ChallengeType TYPE varchar(100); |""".stripMargin } } diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContext.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContext.scala index 4aa75adc94..4ba5df22ad 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContext.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContext.scala @@ -17,14 +17,14 @@ object MigrationOfMappedUserAuthContext { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def dropUniqueIndex(name: String): Boolean = { - DbFunction.tableExists(MappedUserAuthContext, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedUserAuthContext) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "DROP INDEX IF EXISTS mappeduserauthcontext_muserid_mkey ON mappeduserauthcontext;" diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContextUpdate.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContextUpdate.scala index d817828b48..c8756cdec1 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContextUpdate.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContextUpdate.scala @@ -17,14 +17,14 @@ object MigrationOfMappedUserAuthContextUpdate { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def dropUniqueIndex(name: String): Boolean = { - DbFunction.tableExists(MappedUserAuthContextUpdate, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedUserAuthContextUpdate) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "DROP INDEX IF EXISTS mappeduserauthcontextupdate_muserid_mkey ON mappeduserauthcontextupdate;" diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMetricTable.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMetricTable.scala index e2985093a1..8046960966 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMetricTable.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMetricTable.scala @@ -17,7 +17,7 @@ object MigrationOfMetricTable { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnCorrelationidLength(name: String): Boolean = { - DbFunction.tableExists(MappedMetric, (DB.use(DefaultConnectionIdentifier){ conn => conn})) + DbFunction.tableExists(MappedMetric) match { case true => val startDate = System.currentTimeMillis() @@ -25,7 +25,7 @@ object MigrationOfMetricTable { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfOpnIDConnectToken.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfOpnIDConnectToken.scala index 3c638c2588..a6bba3ff24 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfOpnIDConnectToken.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfOpnIDConnectToken.scala @@ -17,14 +17,14 @@ object MigrationOfOpnIDConnectToken { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnAccessToken(name: String): Boolean = { - DbFunction.tableExists(OpenIDConnectToken, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(OpenIDConnectToken) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE openidconnecttoken ALTER COLUMN accesstoken text;" @@ -56,14 +56,14 @@ object MigrationOfOpnIDConnectToken { } } def alterColumnRefreshToken(name: String): Boolean = { - DbFunction.tableExists(OpenIDConnectToken, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(OpenIDConnectToken) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE openidconnecttoken ALTER COLUMN refreshtoken text;" diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductAttribute.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductAttribute.scala index a47576f108..94ad8fde24 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductAttribute.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductAttribute.scala @@ -17,7 +17,7 @@ object MigrationOfProductAttribute { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def populateTheFieldIsActive(name: String): Boolean = { - DbFunction.tableExists(MappedProductAttribute, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedProductAttribute) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductFee.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductFee.scala index bbd5890505..f7484682e0 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductFee.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductFee.scala @@ -16,14 +16,14 @@ object MigrationOfProductFee { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnProductFeeName(name: String): Boolean = { - DbFunction.tableExists(ProductFee, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ProductFee) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUser.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUser.scala index ab8cfe1764..363d078b86 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUser.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUser.scala @@ -18,7 +18,7 @@ object MigrationOfResourceUser { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def populateNewFieldIsDeleted(name: String): Boolean = { - DbFunction.tableExists(ResourceUser, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ResourceUser) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit @@ -56,14 +56,14 @@ object MigrationOfResourceUser { } def alterColumnEmail(name: String): Boolean = { - DbFunction.tableExists(ResourceUser, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ResourceUser) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUserIsDeleted.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUserIsDeleted.scala new file mode 100644 index 0000000000..7d5fe428e6 --- /dev/null +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUserIsDeleted.scala @@ -0,0 +1,101 @@ +package code.api.util.migration + +import code.api.util.APIUtil +import code.api.util.migration.Migration.{DbFunction, saveLog} +import code.model.Consumer +import code.model.dataAccess.ResourceUser +import net.liftweb.common.Full +import net.liftweb.mapper.{DB, Schemifier} +import net.liftweb.util.DefaultConnectionIdentifier + +import java.time.format.DateTimeFormatter +import java.time.{ZoneId, ZonedDateTime} + +object MigrationOfResourceUserIsDeleted { + + val oneDayAgo = ZonedDateTime.now(ZoneId.of("UTC")).minusDays(1) + val oneYearInFuture = ZonedDateTime.now(ZoneId.of("UTC")).plusYears(1) + val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") + + def populateNewFieldIsDeleted(name: String): Boolean = { + DbFunction.tableExists(ResourceUser) match { + case true => + val startDate = System.currentTimeMillis() + val commitId: String = APIUtil.gitCommit + var isSuccessful = false + + // Make back up + DbFunction.makeBackUpOfTable(ResourceUser) + + val emptyDeletedField = + for { + user <- ResourceUser.findAll() if user.isDeleted.getOrElse(false) == false + } yield { + user.IsDeleted(false).saveMe() + } + + val endDate = System.currentTimeMillis() + val comment: String = + s"""Updated number of rows: + |${emptyDeletedField.size} + |""".stripMargin + isSuccessful = true + saveLog(name, commitId, isSuccessful, startDate, endDate, comment) + isSuccessful + + case false => + val startDate = System.currentTimeMillis() + val commitId: String = APIUtil.gitCommit + val isSuccessful = false + val endDate = System.currentTimeMillis() + val comment: String = + s"""${Consumer._dbTableNameLC} table does not exist""".stripMargin + saveLog(name, commitId, isSuccessful, startDate, endDate, comment) + isSuccessful + } + } + + def alterColumnEmail(name: String): Boolean = { + DbFunction.tableExists(ResourceUser) match { + case true => + val startDate = System.currentTimeMillis() + val commitId: String = APIUtil.gitCommit + var isSuccessful = false + + val executedSql = + DbFunction.maybeWrite(true, Schemifier.infoF _) { + APIUtil.getPropsValue("db.driver") match { + case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + () => + """ALTER TABLE resourceuser ALTER COLUMN email varchar(100); + |""".stripMargin + case _ => + () => + """ALTER TABLE resourceuser ALTER COLUMN email type varchar(100); + |""".stripMargin + } + + } + + val endDate = System.currentTimeMillis() + val comment: String = + s"""Executed SQL: + |$executedSql + |""".stripMargin + isSuccessful = true + saveLog(name, commitId, isSuccessful, startDate, endDate, comment) + isSuccessful + + case false => + val startDate = System.currentTimeMillis() + val commitId: String = APIUtil.gitCommit + val isSuccessful = false + val endDate = System.currentTimeMillis() + val comment: String = + s"""${ResourceUser._dbTableNameLC} table does not exist""".stripMargin + saveLog(name, commitId, isSuccessful, startDate, endDate, comment) + isSuccessful + } + } + +} diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfSystemViewsToCustomViews.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfSystemViewsToCustomViews.scala index a4252eb699..a3daf1897f 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfSystemViewsToCustomViews.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfSystemViewsToCustomViews.scala @@ -16,7 +16,7 @@ object UpdateTableViewDefinition { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def populate(name: String): Boolean = { - DbFunction.tableExists(ViewDefinition, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ViewDefinition) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequerst.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequerst.scala index 405f510940..1235728859 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequerst.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequerst.scala @@ -17,14 +17,14 @@ object MigrationOfTransactionRequerst { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnDetails(name: String): Boolean = { - DbFunction.tableExists(MappedTransactionRequest, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedTransactionRequest) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE mappedtransactionrequest ALTER COLUMN mdetails text;" diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala index 62ef7dbb39..4fbe1a1e5b 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala @@ -17,19 +17,19 @@ object MigrationOfTransactionRequestChallengeChallengeTypeLength { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnChallengeChallengeTypeLength(name: String): Boolean = { - DbFunction.tableExists(MappedTransactionRequest, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedTransactionRequest) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE mappedtransactionrequest ALTER COLUMN mChallenge_ChallengeType varchar(100);" case _ => - () => "ALTER TABLE mappedtransactionrequest ALTER COLUMN mChallenge_ChallengeType TYPE character varying(100);" + () => "ALTER TABLE mappedtransactionrequest ALTER COLUMN mChallenge_ChallengeType type varchar(100);" } } diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAttributeNameFieldLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAttributeNameFieldLength.scala index 7a8f0e3bc1..d646d61134 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAttributeNameFieldLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAttributeNameFieldLength.scala @@ -17,14 +17,14 @@ object MigrationOfUserAttributeNameFieldLength { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterNameLength(name: String): Boolean = { - DbFunction.tableExists(UserAttribute, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(UserAttribute) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAuthContextFieldLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAuthContextFieldLength.scala index d38aa41a1d..d0629fb4ee 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAuthContextFieldLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAuthContextFieldLength.scala @@ -16,14 +16,14 @@ object MigrationOfUserAuthContextFieldLength { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnKeyAndValueLength(name: String): Boolean = { - DbFunction.tableExists(MappedUserAuthContext, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedUserAuthContext) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinition.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinition.scala index 64f9b01d28..6771437630 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinition.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinition.scala @@ -9,7 +9,7 @@ import net.liftweb.util.DefaultConnectionIdentifier object TableViewDefinition { def populate(name: String): Boolean = { - DbFunction.tableExists(ViewImpl, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ViewImpl) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala index 5711385c86..dd98763de1 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala @@ -9,7 +9,7 @@ import net.liftweb.util.DefaultConnectionIdentifier object MigrationOfViewDefinitionPermissions { def populate(name: String): Boolean = { - DbFunction.tableExists(ViewDefinition, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ViewDefinition) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit @@ -34,7 +34,7 @@ object MigrationOfViewDefinitionPermissions { .canGrantAccessToViews_(ALL_SYSTEM_VIEWS_CREATED_FROM_BOOT.mkString(",")) .canRevokeAccessToViews_(ALL_SYSTEM_VIEWS_CREATED_FROM_BOOT.mkString(",")) .save - ).head + ) val standardView = ViewDefinition.find( NullRef(ViewDefinition.bank_id), @@ -57,10 +57,10 @@ object MigrationOfViewDefinitionPermissions { .canGrantAccessToViews_(ALL_SYSTEM_VIEWS_CREATED_FROM_BOOT.mkString(",")) .canRevokeAccessToViews_(ALL_SYSTEM_VIEWS_CREATED_FROM_BOOT.mkString(",")) .save - ).head + ) - val isSuccessful = ownerView && standardView + val isSuccessful = ownerView.isDefined && standardView.isDefined val endDate = System.currentTimeMillis() val comment: String = @@ -82,6 +82,7 @@ object MigrationOfViewDefinitionPermissions { """.stripMargin saveLog(name, commitId, isSuccessful, startDate, endDate, comment) isSuccessful + case false => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfWebhookUrlFieldLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfWebhookUrlFieldLength.scala index 77b6f2c1ce..3ffa94a9b6 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfWebhookUrlFieldLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfWebhookUrlFieldLength.scala @@ -18,9 +18,9 @@ object MigrationOfWebhookUrlFieldLength { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnUrlLength(name: String): Boolean = { - DbFunction.tableExists(SystemAccountNotificationWebhook, (DB.use(DefaultConnectionIdentifier){ conn => conn})) && - DbFunction.tableExists(BankAccountNotificationWebhook, (DB.use(DefaultConnectionIdentifier){ conn => conn}))&& - DbFunction.tableExists(MappedAccountWebhook, (DB.use(DefaultConnectionIdentifier){ conn => conn})) + DbFunction.tableExists(SystemAccountNotificationWebhook) && + DbFunction.tableExists(BankAccountNotificationWebhook)&& + DbFunction.tableExists(MappedAccountWebhook) match { case true => val startDate = System.currentTimeMillis() @@ -28,7 +28,7 @@ object MigrationOfWebhookUrlFieldLength { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala index c91f0edbaa..da72ce71f1 100644 --- a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala +++ b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala @@ -151,7 +151,7 @@ trait APIMethods400 extends MdcLoggable { cc => implicit val ec = EndpointContext(Some(cc)) Future { - (Migration.DbFunction.mapperDatabaseInfo(APIUtil.vendor), HttpCode.`200`(cc.callContext)) + (Migration.DbFunction.mapperDatabaseInfo, HttpCode.`200`(cc.callContext)) } } } diff --git a/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureUtils.scala b/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureUtils.scala index 7669c4627a..7ca06811c7 100644 --- a/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureUtils.scala +++ b/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureUtils.scala @@ -73,7 +73,7 @@ object StoredProcedureUtils extends MdcLoggable{ object StoredProceduresMockedData { def createOrDropMockedPostgresStoredProcedures() = { def create(): String = { - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { () => """CREATE OR REPLACE FUNCTION public.get_banks(p_out_bound_json text, INOUT in_bound_json text) | RETURNS text | LANGUAGE plpgsql @@ -113,13 +113,13 @@ object StoredProceduresMockedData { } } def drop(): String = { - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { () => "DROP FUNCTION public.get_banks(text, text);" } } val mapperDB = APIUtil.getPropsValue("stored_procedure_connector.driver") val connectorDB = APIUtil.getPropsValue("db.driver") - val thereIsTheProcedure = Migration.DbFunction.procedureExists("get_banks", DB.use(DefaultConnectionIdentifier){ conn => conn}) + val thereIsTheProcedure = Migration.DbFunction.procedureExists("get_banks") (mapperDB, connectorDB) match { case (Full(mapper), Full(connector)) if(mapper == connector && mapper == "org.postgresql.Driver" && thereIsTheProcedure) => drop()