From 96edbf75b828844a423901dfc3c25c7317bc7c87 Mon Sep 17 00:00:00 2001 From: hongwei Date: Tue, 4 Jun 2024 14:59:20 +0200 Subject: [PATCH 01/23] refactor/rename value to dbDriver for migrations code --- .../code/api/util/migration/MigrationOfAuthUser.scala | 6 +++--- .../util/migration/MigrationOfCustomerAttributes.scala | 4 ++-- .../api/util/migration/MigrationOfMappedConsent.scala | 10 +++++----- ...ionOfMappedExpectedChallengeAnswerFieldLength.scala | 2 +- .../migration/MigrationOfMappedUserAuthContext.scala | 2 +- .../MigrationOfMappedUserAuthContextUpdate.scala | 4 ++-- .../api/util/migration/MigrationOfMetricTable.scala | 2 +- .../util/migration/MigrationOfOpnIDConnectToken.scala | 8 ++++---- .../api/util/migration/MigrationOfProductFee.scala | 2 +- .../api/util/migration/MigrationOfResourceUser.scala | 2 +- .../migration/MigrationOfResourceUserIsDeleted.scala | 2 +- .../migration/MigrationOfTransactionRequerst.scala | 2 +- ...ransactionRequestChallengeChallengeTypeLength.scala | 2 +- .../MigrationOfUserAttributeNameFieldLength.scala | 2 +- .../MigrationOfUserAuthContextFieldLength.scala | 6 +++--- .../migration/MigrationOfWebhookUrlFieldLength.scala | 2 +- 16 files changed, 29 insertions(+), 29 deletions(-) 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 668764de7b..037b3ed9bc 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 @@ -27,10 +27,10 @@ object MigrationOfAuthUser { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => s""" - |${Helper.dropIndexIfExists(value,"authUser", "authuser_username_provider")} + |${Helper.dropIndexIfExists(dbDriver,"authUser", "authuser_username_provider")} | |ALTER TABLE authuser ALTER COLUMN username varchar(100); |ALTER TABLE authuser ALTER COLUMN provider varchar(100); @@ -38,7 +38,7 @@ object MigrationOfAuthUser { |ALTER TABLE authuser ALTER COLUMN lastname varchar(100); |ALTER TABLE authuser ALTER COLUMN email varchar(100); | - |${Helper.createIndexIfNotExists(value,"authUser", "authuser_username_provider")} + |${Helper.createIndexIfNotExists(dbDriver,"authUser", "authuser_username_provider")} |""".stripMargin case _ => () => 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 908ffde0f1..624aebd205 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 @@ -27,9 +27,9 @@ object MigrationOfCustomerAttributes { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE mappedcustomerattribute ALTER COLUMN mvalue varchar(2000);" - case Full(value) if value.contains("com.mysql.cj.jdbc.Driver") => // MySQL + case Full(dbDriver) if dbDriver.contains("com.mysql.cj.jdbc.Driver") => // MySQL () => "ALTER TABLE mappedcustomerattribute MODIFY COLUMN mvalue varchar(2000);" case _ => () => "ALTER TABLE mappedcustomerattribute ALTER COLUMN mvalue type varchar(2000);" 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 97407ddfb1..412b279320 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 @@ -26,9 +26,9 @@ object MigrationOfMappedConsent { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE mappedconsent ALTER COLUMN mjsonwebtoken text;" - case Full(value) if value.contains("com.mysql.cj.jdbc.Driver") => // MySQL + case Full(dbDriver) if dbDriver.contains("com.mysql.cj.jdbc.Driver") => // MySQL () => "ALTER TABLE mappedconsent MODIFY COLUMN mjsonwebtoken TEXT;" case _ => () => "ALTER TABLE mappedconsent ALTER COLUMN mjsonwebtoken type text;" @@ -66,11 +66,11 @@ object MigrationOfMappedConsent { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => """ALTER TABLE mappedconsent ALTER COLUMN mchallenge varchar(50); |""".stripMargin - case Full(value) if value.contains("com.mysql.cj.jdbc.Driver") => // MySQL + case Full(dbDriver) if dbDriver.contains("com.mysql.cj.jdbc.Driver") => // MySQL () => """ALTER TABLE mappedconsent MODIFY COLUMN mchallenge varchar(50); |""".stripMargin @@ -112,7 +112,7 @@ object MigrationOfMappedConsent { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => """ALTER TABLE mappedconsent ALTER COLUMN mstatus varchar(40); |""".stripMargin 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 ef5de1ecd7..cace88f422 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 @@ -27,7 +27,7 @@ object MigrationOfMappedExpectedChallengeAnswerFieldLength { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => """ |ALTER TABLE ExpectedChallengeAnswer ALTER COLUMN ChallengeType varchar(100); 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 4ba5df22ad..026539964b 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 @@ -26,7 +26,7 @@ object MigrationOfMappedUserAuthContext { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "DROP INDEX IF EXISTS mappeduserauthcontext_muserid_mkey ON mappeduserauthcontext;" case _ => () => "DROP INDEX IF EXISTS mappeduserauthcontext_muserid_mkey;" 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 c8756cdec1..43c4c515e9 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 @@ -26,9 +26,9 @@ object MigrationOfMappedUserAuthContextUpdate { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "DROP INDEX IF EXISTS mappeduserauthcontextupdate_muserid_mkey ON mappeduserauthcontextupdate;" - case Full(value) if value.contains("com.mysql.cj.jdbc.Driver") => // MySQL + case Full(dbDriver) if dbDriver.contains("com.mysql.cj.jdbc.Driver") => // MySQL () => "DROP INDEX mappeduserauthcontextupdate_muserid_mkey ON mappeduserauthcontextupdate;" case _ => () => "DROP INDEX IF EXISTS mappeduserauthcontextupdate_muserid_mkey;" 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 8046960966..431de1766a 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 @@ -27,7 +27,7 @@ object MigrationOfMetricTable { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => """ |ALTER TABLE metric ALTER COLUMN correlationid varchar(256); 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 a6bba3ff24..787f3de480 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 @@ -26,9 +26,9 @@ object MigrationOfOpnIDConnectToken { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE openidconnecttoken ALTER COLUMN accesstoken text;" - case Full(value) if value.contains("com.mysql.cj.jdbc.Driver") => + case Full(dbDriver) if dbDriver.contains("com.mysql.cj.jdbc.Driver") => () => "ALTER TABLE openidconnecttoken MODIFY COLUMN accesstoken text;" case _ => () => "ALTER TABLE openidconnecttoken ALTER COLUMN accesstoken type text;" @@ -65,9 +65,9 @@ object MigrationOfOpnIDConnectToken { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE openidconnecttoken ALTER COLUMN refreshtoken text;" - case Full(value) if value.contains("com.mysql.cj.jdbc.Driver") => // MySQL + case Full(dbDriver) if dbDriver.contains("com.mysql.cj.jdbc.Driver") => // MySQL () => "ALTER TABLE openidconnecttoken MODIFY COLUMN refreshtoken text;" case _ => () => "ALTER TABLE openidconnecttoken ALTER COLUMN refreshtoken type text;" 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 f7484682e0..7d9b150525 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 @@ -25,7 +25,7 @@ object MigrationOfProductFee { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => """ |ALTER TABLE ProductFee ALTER COLUMN name varchar(100); 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 363d078b86..ee4f04cf6a 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 @@ -65,7 +65,7 @@ object MigrationOfResourceUser { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => """ALTER TABLE resourceuser ALTER COLUMN email varchar(100); |""".stripMargin 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 index 7d5fe428e6..3617cf7840 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUserIsDeleted.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUserIsDeleted.scala @@ -65,7 +65,7 @@ object MigrationOfResourceUserIsDeleted { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => """ALTER TABLE resourceuser ALTER COLUMN email varchar(100); |""".stripMargin 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 1235728859..0ce0cc0bed 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 @@ -26,7 +26,7 @@ object MigrationOfTransactionRequerst { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE mappedtransactionrequest ALTER COLUMN mdetails text;" case _ => () => "ALTER TABLE mappedtransactionrequest ALTER COLUMN mdetails type 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 4fbe1a1e5b..3fd11c9f64 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 @@ -26,7 +26,7 @@ object MigrationOfTransactionRequestChallengeChallengeTypeLength { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE mappedtransactionrequest ALTER COLUMN mChallenge_ChallengeType varchar(100);" case _ => () => "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 d646d61134..3df6666ad1 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 @@ -26,7 +26,7 @@ object MigrationOfUserAttributeNameFieldLength { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => """ |ALTER TABLE UserAttribute ALTER COLUMN name varchar(255); 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 8025e2c17f..8c7145bae7 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 @@ -26,15 +26,15 @@ object MigrationOfUserAuthContextFieldLength { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => s""" - |${Helper.dropIndexIfExists(value,"mappeduserauthcontext", "mappeduserauthcontext_muserid_mkey_createdat")} + |${Helper.dropIndexIfExists(dbDriver,"mappeduserauthcontext", "mappeduserauthcontext_muserid_mkey_createdat")} | |ALTER TABLE MappedUserAuthContext ALTER COLUMN mKey varchar(4000); |ALTER TABLE MappedUserAuthContext ALTER COLUMN mValue varchar(4000); | - |${Helper.createIndexIfNotExists(value, "mappeduserauthcontext", "mappeduserauthcontext_muserid_mkey_createdat")} + |${Helper.createIndexIfNotExists(dbDriver, "mappeduserauthcontext", "mappeduserauthcontext_muserid_mkey_createdat")} | |""".stripMargin case _ => 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 3ffa94a9b6..612483f190 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 @@ -30,7 +30,7 @@ object MigrationOfWebhookUrlFieldLength { val executedSql = DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { - case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => """ |ALTER TABLE SystemAccountNotificationWebhook ALTER COLUMN Url varchar(1024); From bb9a2bc0b6fcc41a42d2c0d512a9d612defebbf9 Mon Sep 17 00:00:00 2001 From: hongwei Date: Tue, 4 Jun 2024 23:41:45 +0200 Subject: [PATCH 02/23] bugfix/migration issue - fixed makeBackUpOfTable method --- .../main/scala/code/api/util/migration/Migration.scala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 ed5458dfb2..5d22ef0831 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 @@ -584,7 +584,13 @@ object Migration extends MdcLoggable { val tableName = table.dbTableName val sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_SSS") val resultDate = new Date(System.currentTimeMillis()) - DB.prepareStatement(s"CREATE TABLE ${tableName}_backup_${sdf.format(resultDate)} AS (SELECT * FROM $tableName); ", conn){ + val dbDriver = APIUtil.getPropsValue("db.driver","org.h2.Driver") + val sqlQuery = if (dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver")) { + s"SELECT * INTO ${tableName}_backup_${sdf.format(resultDate)} FROM $tableName;" + }else{ + s"CREATE TABLE ${tableName}_backup_${sdf.format(resultDate)} AS (SELECT * FROM $tableName);" + } + DB.prepareStatement(sqlQuery, conn){ stmt => stmt.executeQuery() } true From 93653219aa7fa846a312882031cddaa08c7f9573 Mon Sep 17 00:00:00 2001 From: hongwei Date: Wed, 5 Jun 2024 00:05:21 +0200 Subject: [PATCH 03/23] bugfix/use execute instead of executeQuery --- obp-api/src/main/scala/code/api/util/migration/Migration.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 5d22ef0831..03c6f24c11 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 @@ -591,7 +591,8 @@ object Migration extends MdcLoggable { s"CREATE TABLE ${tableName}_backup_${sdf.format(resultDate)} AS (SELECT * FROM $tableName);" } DB.prepareStatement(sqlQuery, conn){ - stmt => stmt.executeQuery() + stmt => stmt.execute() //statement.executeQuery() expects a resultset and you don't get one. + // Use statement.execute() for an ALTER-statement to avoid this issue. } true } catch { From a315653c8477e1d6dec9146d7a20dc1a636dca6e Mon Sep 17 00:00:00 2001 From: hongwei Date: Thu, 6 Jun 2024 13:16:50 +0200 Subject: [PATCH 04/23] bugfix/added a new method findAuthUserByUsernameAndProvider --- .../bankconnectors/LocalMappedConnector.scala | 4 ++-- .../scala/code/model/dataAccess/AuthUser.scala | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala index 631bac4fdf..5b105a37f2 100644 --- a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala @@ -52,7 +52,7 @@ import code.metadata.transactionimages.TransactionImages import code.metadata.wheretags.WhereTags import code.metrics.MappedMetric import code.model._ -import code.model.dataAccess.AuthUser.findAuthUserByUsernameLocally +import code.model.dataAccess.AuthUser.findAuthUserByUsernameLocallyLegacy import code.model.dataAccess._ import code.productAttributeattribute.MappedProductAttribute import code.productattribute.ProductAttributeX @@ -5793,7 +5793,7 @@ object LocalMappedConnector extends Connector with MdcLoggable { //NOTE: this method is not for mapped connector, we put it here for the star default implementation. // : we call that method only when we set external authentication and provider is not OBP-API override def checkExternalUserExists(username: String, callContext: Option[CallContext]): Box[InboundExternalUser] = { - findAuthUserByUsernameLocally(username).map(user => + findAuthUserByUsernameLocallyLegacy(username).map(user => InboundExternalUser(aud = "", exp = "", iat = "", diff --git a/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala b/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala index c5e3a8947c..c1db0029be 100644 --- a/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala +++ b/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala @@ -591,7 +591,7 @@ import net.liftweb.util.Helpers._ * Overridden to use the hostname set in the props file */ override def sendPasswordReset(name: String) { - findAuthUserByUsernameLocally(name).toList ::: findUsersByEmailLocally(name) map { + findAuthUserByUsernameLocallyLegacy(name).toList ::: findUsersByEmailLocally(name) map { // reason of case parameter name is "u" instead of "user": trait AuthUser have constant mumber name is "user" // So if the follow case paramter name is "user" will cause compile warnings case u if u.validated_? => @@ -840,7 +840,7 @@ import net.liftweb.util.Helpers._ def getResourceUserId(username: String, password: String): Box[Long] = { - findAuthUserByUsernameLocally(username) match { + findAuthUserByUsernameLocallyLegacy(username) match { // We have a user from the local provider. case Full(user) if (user.getProvider() == Constant.localIdentityProvider) => if ( @@ -918,7 +918,7 @@ import net.liftweb.util.Helpers._ Connector.connector.vend.getUser(name, password) match { case Full(InboundUser(extEmail, extPassword, extUsername)) => { val extProvider = connector - val user = findAuthUserByUsernameLocally(name) match { + val user = findAuthUserByUsernameLocallyLegacy(name) match { // Check if the external user is already created locally case Full(user) if user.validated_? // && user.provider == extProvider @@ -961,7 +961,7 @@ import net.liftweb.util.Helpers._ def checkExternalUserViaConnector(username: String, password: String):Box[AuthUser] = { Connector.connector.vend.checkExternalUserCredentials(username, password, None) match { case Full(InboundExternalUser(aud, exp, iat, iss, sub, azp, email, emailVerified, name, userAuthContexts)) => - val user = findAuthUserByUsernameLocally(sub) match { // Check if the external user is already created locally + val user = findAuthUserByUsernameAndProvider(sub, iss) match { // Check if the external user is already created locally case Full(user) if user.validated_? => // Return existing user if found logger.debug("external user already exists locally, using that one") userAuthContexts match { @@ -1118,7 +1118,7 @@ def restoreSomeSessions(): Unit = { if(passwordEmptyField) S.error("login-form-password-error", Helper.i18n("please.enter.your.password")) case false => - findAuthUserByUsernameLocally(usernameFromGui) match { + findAuthUserByUsernameLocallyLegacy(usernameFromGui) match { case Full(user) if !user.validated_? => S.error(S.?("account.validation.error")) @@ -1575,7 +1575,8 @@ def restoreSomeSessions(): Unit = { * Only search at the local database. * Please note that provider is implicitly defined i.e. not provided via a parameter */ - def findAuthUserByUsernameLocally(name: String): Box[TheUserType] = { + @deprecated("AuthUser unique key is username and provider, please use @findAuthUserByUsernameAndProvider instead.","06.06.2024") + def findAuthUserByUsernameLocallyLegacy(name: String): Box[TheUserType] = { // 1st try is provider with local_identity_provider or hostname value find(By(this.username, name), By(this.provider, Constant.localIdentityProvider)) // 2nd try is provider with null value @@ -1583,6 +1584,10 @@ def restoreSomeSessions(): Unit = { // 3rd try is provider with empty string value .or(find(By(this.username, name), By(this.provider, ""))) } + + def findAuthUserByUsernameAndProvider(name: String, provider: String): Box[TheUserType] = { + find(By(this.username, name), By(this.provider, provider)) + } def findAuthUserByPrimaryKey(key: Long): Box[TheUserType] = { find(By(this.user, key)) } From 03a6774543a0585fd3f8fc928b75b0263748941c Mon Sep 17 00:00:00 2001 From: hongwei Date: Fri, 7 Jun 2024 12:14:23 +0200 Subject: [PATCH 05/23] bugfix/fixed the bug for getUserId method --- obp-api/src/main/scala/code/api/OAuth2.scala | 4 ++-- obp-api/src/main/scala/code/api/directlogin.scala | 11 +++-------- .../main/scala/code/bankconnectors/Connector.scala | 2 +- .../code/bankconnectors/LocalMappedConnector.scala | 2 +- .../vSept2018/KafkaMappedConnector_vSept2018.scala | 2 +- obp-api/src/main/scala/code/model/User.scala | 2 +- .../scala/code/model/dataAccess/AuthUser.scala | 14 +++++++------- .../scala/code/remotedata/RemotedataUsers.scala | 2 +- .../code/remotedata/RemotedataUsersActor.scala | 4 ++-- .../main/scala/code/sandbox/OBPDataImport.scala | 2 +- .../main/scala/code/snippet/UserInvitation.scala | 2 +- .../scala/code/userlocks/UserLocksProvider.scala | 6 +++--- obp-api/src/main/scala/code/users/LiftUsers.scala | 4 ++-- obp-api/src/main/scala/code/users/Users.scala | 4 ++-- 14 files changed, 28 insertions(+), 33 deletions(-) diff --git a/obp-api/src/main/scala/code/api/OAuth2.scala b/obp-api/src/main/scala/code/api/OAuth2.scala index 396cd89e19..441ac95679 100644 --- a/obp-api/src/main/scala/code/api/OAuth2.scala +++ b/obp-api/src/main/scala/code/api/OAuth2.scala @@ -180,8 +180,8 @@ object OAuth2Login extends RestHelper with MdcLoggable { // In case a user is created via OpenID Connect flow implies provider = hydraPublicUrl // In case a user is created via GUI of OBP-API implies provider = Constant.localIdentityProvider - val user = Users.users.vend.getUserByUserName(introspectOAuth2Token.getIss, introspectOAuth2Token.getSub).or( - Users.users.vend.getUserByUserName(Constant.localIdentityProvider, introspectOAuth2Token.getSub) + val user = Users.users.vend.getUserByProviderAndUsername(introspectOAuth2Token.getIss, introspectOAuth2Token.getSub).or( + Users.users.vend.getUserByProviderAndUsername(Constant.localIdentityProvider, introspectOAuth2Token.getSub) ) user match { case Full(u) => diff --git a/obp-api/src/main/scala/code/api/directlogin.scala b/obp-api/src/main/scala/code/api/directlogin.scala index 576ce7511e..23ccea7a24 100644 --- a/obp-api/src/main/scala/code/api/directlogin.scala +++ b/obp-api/src/main/scala/code/api/directlogin.scala @@ -491,14 +491,9 @@ object DirectLogin extends RestHelper with MdcLoggable { val username = directLoginParameters.getOrElse("username", "") val password = directLoginParameters.getOrElse("password", "") - var userId = for {id <- AuthUser.getResourceUserId(username, password)} yield id - - if (userId.isEmpty) { - if ( ! AuthUser.externalUserHelper(username, password).isEmpty) - userId = for {id <- AuthUser.getResourceUserId(username, password)} yield id - } - - userId + //we first try to get the userId from local, if not find, we try to get it from external + AuthUser.getResourceUserId(username, password) + .or(AuthUser.externalUserHelper(username, password).map(_.user.get)) } diff --git a/obp-api/src/main/scala/code/bankconnectors/Connector.scala b/obp-api/src/main/scala/code/bankconnectors/Connector.scala index 077c481c68..df74a14dbd 100644 --- a/obp-api/src/main/scala/code/bankconnectors/Connector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/Connector.scala @@ -1580,7 +1580,7 @@ trait Connector extends MdcLoggable { @deprecated("we create new code.model.dataAccess.AuthUser.updateUserAccountViews for June2017 connector, try to use new instead of this","11 September 2018") def setAccountHolder(owner : String, bankId: BankId, accountId: AccountId, account_owners: List[String]) : Unit = { // if (account_owners.contains(owner)) { // No need for now, fix it later - val resourceUserOwner = Users.users.vend.getUserByUserName(localIdentityProvider, owner) + val resourceUserOwner = Users.users.vend.getUserByProviderAndUsername(localIdentityProvider, owner) resourceUserOwner match { case Full(owner) => { if ( ! accountOwnerExists(owner, bankId, accountId).openOrThrowException(attemptedToOpenAnEmptyBox)) { diff --git a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala index 5b105a37f2..79d1d964b7 100644 --- a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala @@ -5695,7 +5695,7 @@ object LocalMappedConnector extends Connector with MdcLoggable { @deprecated("we create new code.model.dataAccess.AuthUser.updateUserAccountViews for June2017 connector, try to use new instead of this", "11 September 2018") override def setAccountHolder(owner: String, bankId: BankId, accountId: AccountId, account_owners: List[String]): Unit = { // if (account_owners.contains(owner)) { // No need for now, fix it later - val resourceUserOwner = Users.users.vend.getUserByUserName(localIdentityProvider, owner) + val resourceUserOwner = Users.users.vend.getUserByProviderAndUsername(localIdentityProvider, owner) resourceUserOwner match { case Full(owner) => { if (!accountOwnerExists(owner, bankId, accountId).openOrThrowException(attemptedToOpenAnEmptyBox)) { diff --git a/obp-api/src/main/scala/code/bankconnectors/vSept2018/KafkaMappedConnector_vSept2018.scala b/obp-api/src/main/scala/code/bankconnectors/vSept2018/KafkaMappedConnector_vSept2018.scala index 2ca46c5709..259baecf12 100644 --- a/obp-api/src/main/scala/code/bankconnectors/vSept2018/KafkaMappedConnector_vSept2018.scala +++ b/obp-api/src/main/scala/code/bankconnectors/vSept2018/KafkaMappedConnector_vSept2018.scala @@ -102,7 +102,7 @@ trait KafkaMappedConnector_vSept2018 extends Connector with KafkaHelper with Mdc basicUserAuthContexts <- cc.gatewayLoginRequestPayload match { case None => for{ - user <- Users.users.vend.getUserByUserName(provider,username) ?~! "getAuthInfoFirstCbsCall: can not get user object here." + user <- Users.users.vend.getUserByProviderAndUsername(provider,username) ?~! "getAuthInfoFirstCbsCall: can not get user object here." userAuthContexts<- UserAuthContextProvider.userAuthContextProvider.vend.getUserAuthContextsBox(user.userId)?~! "getAuthInfoFirstCbsCall: can not get userAuthContexts object here." basicUserAuthContexts = JsonFactory_vSept2018.createBasicUserAuthContextJson(userAuthContexts) } yield diff --git a/obp-api/src/main/scala/code/model/User.scala b/obp-api/src/main/scala/code/model/User.scala index 10c70b84f4..891cc1f839 100644 --- a/obp-api/src/main/scala/code/model/User.scala +++ b/obp-api/src/main/scala/code/model/User.scala @@ -141,7 +141,7 @@ object UserX { } def findByUserName(provider: String, userName: String) = { - Users.users.vend.getUserByUserName(provider, userName) + Users.users.vend.getUserByProviderAndUsername(provider, userName) } def findByEmail(email: String) = { diff --git a/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala b/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala index c1db0029be..9b7b9bd486 100644 --- a/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala +++ b/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala @@ -350,8 +350,8 @@ class AuthUser extends MegaProtoUser[AuthUser] with CreatedUpdated with MdcLogga } } - def getResourceUserByUsername(provider: String, username: String) : Box[User] = { - Users.users.vend.getUserByUserName(provider, username) + def getResourceUserByProviderAndUsername(provider: String, username: String) : Box[User] = { + Users.users.vend.getUserByProviderAndUsername(provider, username) } override def save(): Boolean = { @@ -509,7 +509,7 @@ import net.liftweb.util.Helpers._ Constant.localIdentityProvider else user.provider.get - Users.users.vend.getUserByUserName(provider, user.username.get) + Users.users.vend.getUserByProviderAndUsername(provider, user.username.get) } else if (directLogin.isDefined) // Direct Login DirectLogin.getUser else if (hasDirectLoginHeader(authorization)) // Direct Login Deprecated @@ -655,7 +655,7 @@ import net.liftweb.util.Helpers._ } def grantDefaultEntitlementsToAuthUser(user: TheUserType) = { - tryo{getResourceUserByUsername(user.getProvider(), user.username.get).head.userId} match { + tryo{getResourceUserByProviderAndUsername(user.getProvider(), user.username.get).head.userId} match { case Full(userId)=>APIUtil.grantDefaultEntitlementsToNewUser(userId) case _ => logger.error("Can not getResourceUserByUsername here, so it breaks the grantDefaultEntitlementsToNewUser process.") } @@ -1255,14 +1255,14 @@ def restoreSomeSessions(): Unit = { if (connector.startsWith("kafka") ) { for { user <- getUserFromConnector(name, password) - u <- Users.users.vend.getUserByUserName(user.getProvider(), name) + u <- Users.users.vend.getUserByProviderAndUsername(user.getProvider(), name) } yield { user } } else { for { user <- checkExternalUserViaConnector(name, password) - u <- Users.users.vend.getUserByUserName(user.getProvider(), name) + u <- Users.users.vend.getUserByProviderAndUsername(user.getProvider(), name) } yield { user } @@ -1276,7 +1276,7 @@ def restoreSomeSessions(): Unit = { def registeredUserHelper(provider: String, username: String) = { if (connector.startsWith("kafka")) { for { - u <- Users.users.vend.getUserByUserName(provider, username) + u <- Users.users.vend.getUserByProviderAndUsername(provider, username) } yield { refreshUserLegacy(u, None) } diff --git a/obp-api/src/main/scala/code/remotedata/RemotedataUsers.scala b/obp-api/src/main/scala/code/remotedata/RemotedataUsers.scala index 0979fa52b3..58b51e30c8 100644 --- a/obp-api/src/main/scala/code/remotedata/RemotedataUsers.scala +++ b/obp-api/src/main/scala/code/remotedata/RemotedataUsers.scala @@ -50,7 +50,7 @@ object RemotedataUsers extends ObpActorInit with Users { def getUsersByUserIdsFuture(userIds : List[String]) : Future[List[User]] = (actor ? cc.getUsersByUserIdsFuture(userIds)).mapTo[List[User]] - def getUserByUserName(provider : String, userName : String) : Box[ResourceUser] = getValueFromFuture( + def getUserByProviderAndUsername(provider : String, userName : String) : Box[ResourceUser] = getValueFromFuture( (actor ? cc.getUserByUserName(provider, userName)).mapTo[Box[ResourceUser]] ) diff --git a/obp-api/src/main/scala/code/remotedata/RemotedataUsersActor.scala b/obp-api/src/main/scala/code/remotedata/RemotedataUsersActor.scala index 537df1dda6..5a54c7a5db 100644 --- a/obp-api/src/main/scala/code/remotedata/RemotedataUsersActor.scala +++ b/obp-api/src/main/scala/code/remotedata/RemotedataUsersActor.scala @@ -59,11 +59,11 @@ class RemotedataUsersActor extends Actor with ObpActorHelper with MdcLoggable { case cc.getUserByUserName(provider: String, userName: String) => logger.debug("getUserByUserName("+provider + userName +")") - sender ! (mapper.getUserByUserName(provider, userName)) + sender ! (mapper.getUserByProviderAndUsername(provider, userName)) case cc.getUserByUserNameFuture(provider: String, userName: String) => logger.debug("getUserByUserNameFuture("+provider + userName +")") - sender ! (mapper.getUserByUserName(provider, userName)) + sender ! (mapper.getUserByProviderAndUsername(provider, userName)) case cc.getUserByEmail(email: String) => logger.debug("getUserByEmail(" + email +")") diff --git a/obp-api/src/main/scala/code/sandbox/OBPDataImport.scala b/obp-api/src/main/scala/code/sandbox/OBPDataImport.scala index ade31aca4a..0aa94b9b21 100644 --- a/obp-api/src/main/scala/code/sandbox/OBPDataImport.scala +++ b/obp-api/src/main/scala/code/sandbox/OBPDataImport.scala @@ -125,7 +125,7 @@ trait OBPDataImport extends MdcLoggable { protected def createSaveableUser(u : SandboxUserImport) : Box[Saveable[ResourceUser]] protected def createUsers(toImport : List[SandboxUserImport]) : Box[List[Saveable[ResourceUser]]] = { - val existingResourceUsers = toImport.flatMap(u => Users.users.vend.getUserByUserName(localIdentityProvider, u.user_name)) + val existingResourceUsers = toImport.flatMap(u => Users.users.vend.getUserByProviderAndUsername(localIdentityProvider, u.user_name)) val allUsernames = toImport.map(_.user_name) val duplicateUsernames = allUsernames diff allUsernames.distinct diff --git a/obp-api/src/main/scala/code/snippet/UserInvitation.scala b/obp-api/src/main/scala/code/snippet/UserInvitation.scala index eab34b28a2..700b754fa8 100644 --- a/obp-api/src/main/scala/code/snippet/UserInvitation.scala +++ b/obp-api/src/main/scala/code/snippet/UserInvitation.scala @@ -99,7 +99,7 @@ class UserInvitation extends MdcLoggable { else if(userInvitation.map(_.status != "CREATED").getOrElse(false)) showErrorsForStatus() else if(timeDifference.abs.getSeconds > ttl) showErrorsForTtl() else if(AuthUser.currentUser.isDefined) showErrorYouMustBeLoggedOff() - else if(Users.users.vend.getUserByUserName(localIdentityProvider, usernameVar.is).isDefined) showErrorsForUsername() + else if(Users.users.vend.getUserByProviderAndUsername(localIdentityProvider, usernameVar.is).isDefined) showErrorsForUsername() else if(privacyCheckboxVar.is == false) showErrorsForPrivacyConditions() else if(termsCheckboxVar.is == false) showErrorsForTermsAndConditions() else if(personalDataCollectionConsentCountryWaiverList.exists(_.toLowerCase == countryVar.is.toLowerCase) == false && consentForCollectingCheckboxVar.is == false) showErrorsForConsentForCollectingPersonalData() diff --git a/obp-api/src/main/scala/code/userlocks/UserLocksProvider.scala b/obp-api/src/main/scala/code/userlocks/UserLocksProvider.scala index 79148196f4..d020128739 100644 --- a/obp-api/src/main/scala/code/userlocks/UserLocksProvider.scala +++ b/obp-api/src/main/scala/code/userlocks/UserLocksProvider.scala @@ -8,7 +8,7 @@ import net.liftweb.util.Helpers._ object UserLocksProvider extends MdcLoggable { def isLocked(provider: String, username: String): Boolean = { - Users.users.vend.getUserByUserName(provider, username) match { + Users.users.vend.getUserByProviderAndUsername(provider, username) match { case Full(user) => UserLocks.find(By(UserLocks.UserId, user.userId)) match { case Full(_) => true @@ -18,7 +18,7 @@ object UserLocksProvider extends MdcLoggable { } } def lockUser(provider: String, username: String): Box[UserLocks] = { - Users.users.vend.getUserByUserName(provider, username) match { + Users.users.vend.getUserByProviderAndUsername(provider, username) match { case Full(user) => UserLocks.find(By(UserLocks.UserId, user.userId)) match { case Full(userLocks) => @@ -41,7 +41,7 @@ object UserLocksProvider extends MdcLoggable { } } def unlockUser(provider: String, username: String): Box[Boolean] = { - Users.users.vend.getUserByUserName(provider, username) match { + Users.users.vend.getUserByProviderAndUsername(provider, username) match { case Full(user) => UserLocks.find(By(UserLocks.UserId, user.userId)) match { case Full(userLocks) => Some(userLocks.delete_!) diff --git a/obp-api/src/main/scala/code/users/LiftUsers.scala b/obp-api/src/main/scala/code/users/LiftUsers.scala index 2a88ff44b8..585ee1d336 100644 --- a/obp-api/src/main/scala/code/users/LiftUsers.scala +++ b/obp-api/src/main/scala/code/users/LiftUsers.scala @@ -92,7 +92,7 @@ object LiftUsers extends Users with MdcLoggable{ Future(getUsersByUserIds(userIds)) } - override def getUserByUserName(provider : String, userName: String): Box[User] = { + override def getUserByProviderAndUsername(provider : String, userName: String): Box[User] = { ResourceUser.find( By(ResourceUser.provider_, provider), By(ResourceUser.name_, userName) @@ -101,7 +101,7 @@ object LiftUsers extends Users with MdcLoggable{ override def getUserByProviderAndUsernameFuture(provider: String, username: String): Future[Box[User]] = { Future { - getUserByUserName(provider, username) + getUserByProviderAndUsername(provider, username) } } diff --git a/obp-api/src/main/scala/code/users/Users.scala b/obp-api/src/main/scala/code/users/Users.scala index c9ce68ee68..bc586762f9 100644 --- a/obp-api/src/main/scala/code/users/Users.scala +++ b/obp-api/src/main/scala/code/users/Users.scala @@ -42,8 +42,8 @@ trait Users { def getUserByUserIdFuture(userId : String) : Future[Box[User]] def getUsersByUserIdsFuture(userIds : List[String]) : Future[List[User]] - // find ResourceUser by Resourceuser user name - def getUserByUserName(provider: String, userName: String) : Box[User] + // find ResourceUser by Resourceuser username + def getUserByProviderAndUsername(provider: String, userName: String) : Box[User] def getUserByProviderAndUsernameFuture(provider: String, username: String): Future[Box[User]] def getUserByEmail(email: String) : Box[List[ResourceUser]] From c15e502214b96a1ac6213d04e0d8ab6d31f169dd Mon Sep 17 00:00:00 2001 From: hongwei Date: Mon, 10 Jun 2024 12:47:51 +0200 Subject: [PATCH 06/23] bugfix/fixed the userId issue for refreshUser --- obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala b/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala index 77f64364be..b7a29a7d88 100644 --- a/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala +++ b/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala @@ -1924,7 +1924,7 @@ trait APIMethods310 { cc => implicit val ec = EndpointContext(Some(cc)) for { (Full(u), callContext) <- authenticatedAccess(cc) - _ <- NewStyle.function.hasEntitlement("", userId, canRefreshUser, callContext) + _ <- NewStyle.function.hasEntitlement("", u.userId, canRefreshUser, callContext) startTime <- Future{Helpers.now} (user, callContext) <- NewStyle.function.findByUserId(userId, callContext) _ <- AuthUser.refreshUser(user, callContext) From ffa60e853c0ed0e7119b79b05954595b398926a5 Mon Sep 17 00:00:00 2001 From: hongwei Date: Mon, 10 Jun 2024 14:18:06 +0200 Subject: [PATCH 07/23] feature/added the new views to ALL_SYSTEM_VIEWS_CREATED_FROM_CBS --- .../scala/code/api/constant/constant.scala | 15 +++++++- .../scala/code/api/util/ErrorMessages.scala | 8 +---- .../scala/code/sandbox/OBPDataImport.scala | 2 +- .../main/scala/code/views/MapperViews.scala | 34 ++++--------------- 4 files changed, 23 insertions(+), 36 deletions(-) diff --git a/obp-api/src/main/scala/code/api/constant/constant.scala b/obp-api/src/main/scala/code/api/constant/constant.scala index 86a601cfe8..56b4cfb845 100644 --- a/obp-api/src/main/scala/code/api/constant/constant.scala +++ b/obp-api/src/main/scala/code/api/constant/constant.scala @@ -79,7 +79,20 @@ object Constant extends MdcLoggable { SYSTEM_READ_ACCOUNTS_BERLIN_GROUP_VIEW_ID, SYSTEM_READ_BALANCES_BERLIN_GROUP_VIEW_ID, SYSTEM_READ_TRANSACTIONS_BERLIN_GROUP_VIEW_ID - ) + ) + + final val ALL_SYSTEM_VIEWS_CREATED_FROM_CBS = List( + SYSTEM_OWNER_VIEW_ID, + SYSTEM_ACCOUNTANT_VIEW_ID, + SYSTEM_AUDITOR_VIEW_ID, + SYSTEM_STAGE_ONE_VIEW_ID, + SYSTEM_STANDARD_VIEW_ID, + SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID, + SYSTEM_READ_ACCOUNTS_BERLIN_GROUP_VIEW_ID, + SYSTEM_READ_BALANCES_BERLIN_GROUP_VIEW_ID, + SYSTEM_READ_TRANSACTIONS_BERLIN_GROUP_VIEW_ID + ) + //These are the default incoming and outgoing account ids. we will create both during the boot.scala. final val INCOMING_SETTLEMENT_ACCOUNT_ID = "OBP-INCOMING-SETTLEMENT-ACCOUNT" final val OUTGOING_SETTLEMENT_ACCOUNT_ID = "OBP-OUTGOING-SETTLEMENT-ACCOUNT" diff --git a/obp-api/src/main/scala/code/api/util/ErrorMessages.scala b/obp-api/src/main/scala/code/api/util/ErrorMessages.scala index 500c7c97de..472752db3f 100644 --- a/obp-api/src/main/scala/code/api/util/ErrorMessages.scala +++ b/obp-api/src/main/scala/code/api/util/ErrorMessages.scala @@ -337,13 +337,7 @@ object ErrorMessages { val UpdateCardError = "OBP-30033: Could not update the Card" val ViewIdNotSupported = s"OBP-30034: This ViewId is not supported. Only the following can be used: " + - s"$SYSTEM_OWNER_VIEW_ID, " + - s"$SYSTEM_ACCOUNTANT_VIEW_ID, " + - s"$SYSTEM_AUDITOR_VIEW_ID, " + - s"$SYSTEM_STAGE_ONE_VIEW_ID, " + - s"$SYSTEM_STANDARD_VIEW_ID, " + - s"$SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID, " + - s"$CUSTOM_PUBLIC_VIEW_ID." + code.api.Constant.ALL_SYSTEM_VIEWS_CREATED_FROM_CBS.mkString(", ") val UserCustomerLinkNotFound = "OBP-30035: User Customer Link not found" diff --git a/obp-api/src/main/scala/code/sandbox/OBPDataImport.scala b/obp-api/src/main/scala/code/sandbox/OBPDataImport.scala index 0aa94b9b21..2e0cae640c 100644 --- a/obp-api/src/main/scala/code/sandbox/OBPDataImport.scala +++ b/obp-api/src/main/scala/code/sandbox/OBPDataImport.scala @@ -5,7 +5,7 @@ import java.util.UUID import code.accountholders.AccountHolders import code.api.Constant -import code.api.Constant.{SYSTEM_ACCOUNTANT_VIEW_ID, SYSTEM_AUDITOR_VIEW_ID, SYSTEM_FIREHOSE_VIEW_ID, SYSTEM_OWNER_VIEW_ID, SYSTEM_READ_ACCOUNTS_BASIC_VIEW_ID, SYSTEM_READ_ACCOUNTS_BERLIN_GROUP_VIEW_ID, SYSTEM_READ_ACCOUNTS_DETAIL_VIEW_ID, SYSTEM_READ_BALANCES_BERLIN_GROUP_VIEW_ID, SYSTEM_READ_BALANCES_VIEW_ID, SYSTEM_READ_TRANSACTIONS_BASIC_VIEW_ID, SYSTEM_READ_TRANSACTIONS_BERLIN_GROUP_VIEW_ID, SYSTEM_READ_TRANSACTIONS_DEBITS_VIEW_ID, SYSTEM_READ_TRANSACTIONS_DETAIL_VIEW_ID, localIdentityProvider} +import code.api.Constant._ import code.api.util.APIUtil._ import code.api.util.{APIUtil, ApiPropsWithAlias, ErrorMessages} import code.bankconnectors.Connector diff --git a/obp-api/src/main/scala/code/views/MapperViews.scala b/obp-api/src/main/scala/code/views/MapperViews.scala index 783a124d82..cfead6ea9e 100644 --- a/obp-api/src/main/scala/code/views/MapperViews.scala +++ b/obp-api/src/main/scala/code/views/MapperViews.scala @@ -607,34 +607,14 @@ object MapperViews extends Views with MdcLoggable { def getOrCreateSystemViewFromCbs(viewId: String): Box[View] = { logger.debug(s"-->getOrCreateSystemViewFromCbs--- start--${viewId} ") - - val ownerView = SYSTEM_OWNER_VIEW_ID.equals(viewId.toLowerCase) - val accountantsView = SYSTEM_ACCOUNTANT_VIEW_ID.equals(viewId.toLowerCase) - val auditorsView = SYSTEM_AUDITOR_VIEW_ID.equals(viewId.toLowerCase) - val standardView = SYSTEM_STANDARD_VIEW_ID.equals(viewId.toLowerCase) - val stageOneView = SYSTEM_STAGE_ONE_VIEW_ID.toLowerCase.equals(viewId.toLowerCase) - val manageCustomViews = SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID.toLowerCase.equals(viewId.toLowerCase) - - val theView = - if (ownerView) - getOrCreateSystemView(SYSTEM_OWNER_VIEW_ID) - else if (accountantsView) - getOrCreateSystemView(SYSTEM_ACCOUNTANT_VIEW_ID) - else if (auditorsView) - getOrCreateSystemView(SYSTEM_AUDITOR_VIEW_ID) - else if (standardView) - getOrCreateSystemView(SYSTEM_STANDARD_VIEW_ID) - else if (stageOneView) - getOrCreateSystemView(SYSTEM_STAGE_ONE_VIEW_ID) - else if (manageCustomViews) - getOrCreateSystemView(SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID) - else { - logger.error(ViewIdNotSupported+ s"Your input viewId is :$viewId") - Failure(ViewIdNotSupported+ s"Your input viewId is :$viewId") - } - + + val theView = if (ALL_SYSTEM_VIEWS_CREATED_FROM_CBS.contains(viewId)) { + getOrCreateSystemView(viewId) + } else { + logger.error(ViewIdNotSupported + s"Your input viewId is :$viewId") + Failure(ViewIdNotSupported + s"Your input viewId is :$viewId") + } logger.debug(s"-->getOrCreateSystemViewFromCbs --- finish.${viewId } : ${theView} ") - theView } From 37ef303651c24d217963527a17a1bdc3cc01a32b Mon Sep 17 00:00:00 2001 From: hongwei Date: Wed, 12 Jun 2024 13:09:21 +0200 Subject: [PATCH 08/23] bugfix/removed the getBankAccountByAccountId from connector --- obp-api/src/main/scala/code/bankconnectors/Connector.scala | 1 - .../main/scala/code/bankconnectors/LocalMappedConnector.scala | 4 ---- 2 files changed, 5 deletions(-) diff --git a/obp-api/src/main/scala/code/bankconnectors/Connector.scala b/obp-api/src/main/scala/code/bankconnectors/Connector.scala index df74a14dbd..5883cef31d 100644 --- a/obp-api/src/main/scala/code/bankconnectors/Connector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/Connector.scala @@ -542,7 +542,6 @@ trait Connector extends MdcLoggable { //This one just added the callContext in parameters. def getBankAccountLegacy(bankId : BankId, accountId : AccountId, callContext: Option[CallContext]) : Box[(BankAccount, Option[CallContext])]= Failure(setUnimplementedError) - def getBankAccountByAccountId(accountId : AccountId, callContext: Option[CallContext]) : OBPReturnType[Box[BankAccount]]= Future{(Failure(setUnimplementedError),callContext)} def getBankAccountByIban(iban : String, callContext: Option[CallContext]) : OBPReturnType[Box[BankAccount]]= Future{(Failure(setUnimplementedError),callContext)} def getBankAccountByRoutingLegacy(bankId: Option[BankId], scheme : String, address : String, callContext: Option[CallContext]) : Box[(BankAccount, Option[CallContext])]= Failure(setUnimplementedError) def getBankAccountByRouting(bankId: Option[BankId], scheme : String, address : String, callContext: Option[CallContext]) : OBPReturnType[Box[BankAccount]]= Future{(Failure(setUnimplementedError), callContext)} diff --git a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala index 79d1d964b7..980e180278 100644 --- a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala @@ -802,10 +802,6 @@ object LocalMappedConnector extends Connector with MdcLoggable { getBankAccountCommon(bankId, accountId, callContext) } - override def getBankAccountByAccountId(accountId : AccountId, callContext: Option[CallContext]): OBPReturnType[Box[BankAccount]] = Future { - getBankAccountByAccountIdLegacy(accountId : AccountId, callContext: Option[CallContext]) - } - def getBankAccountByAccountIdLegacy(accountId : AccountId, callContext: Option[CallContext]): Box[(BankAccount, Option[CallContext])] = { MappedBankAccount.find( By(MappedBankAccount.theAccountId, accountId.value) From 4b83ffd5052112e6184f21818111032db7f83f73 Mon Sep 17 00:00:00 2001 From: hongwei Date: Wed, 12 Jun 2024 13:15:53 +0200 Subject: [PATCH 09/23] bugfix/removed the getBankAccountByAccountId from connector -step2 --- obp-api/src/main/scala/code/api/util/NewStyle.scala | 2 +- .../scala/code/bankconnectors/LocalMappedConnector.scala | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/NewStyle.scala b/obp-api/src/main/scala/code/api/util/NewStyle.scala index a8b459b185..c895a84a40 100644 --- a/obp-api/src/main/scala/code/api/util/NewStyle.scala +++ b/obp-api/src/main/scala/code/api/util/NewStyle.scala @@ -410,7 +410,7 @@ object NewStyle extends MdcLoggable{ } def getBankAccountByAccountId(accountId : AccountId, callContext: Option[CallContext]) : OBPReturnType[BankAccount] = { - Connector.connector.vend.getBankAccountByAccountId(accountId : AccountId, callContext: Option[CallContext]) map { i => + Connector.connector.vend.checkBankAccountExists(BankId(defaultBankId), accountId : AccountId, callContext: Option[CallContext]) map { i => (unboxFullOrFail(i._1, callContext,s"$BankAccountNotFoundByAccountId Current account_id is $accountId", 404 ), i._2) } } diff --git a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala index 980e180278..e73eaecc0b 100644 --- a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala @@ -802,12 +802,6 @@ object LocalMappedConnector extends Connector with MdcLoggable { getBankAccountCommon(bankId, accountId, callContext) } - def getBankAccountByAccountIdLegacy(accountId : AccountId, callContext: Option[CallContext]): Box[(BankAccount, Option[CallContext])] = { - MappedBankAccount.find( - By(MappedBankAccount.theAccountId, accountId.value) - ).map(bankAccount => (bankAccount, callContext)) - } - override def getBankAccountByIban(iban: String, callContext: Option[CallContext]): OBPReturnType[Box[BankAccount]] = Future { getBankAccountByRoutingLegacy(None, "IBAN", iban, callContext) } From 53d4302032c8f4a3504182146dcf920c20714328 Mon Sep 17 00:00:00 2001 From: hongwei Date: Wed, 12 Jun 2024 13:46:49 +0200 Subject: [PATCH 10/23] bugfix/use :: instead of List for Constant --- .../scala/code/api/constant/constant.scala | 56 +++++++++---------- .../main/scala/code/api/util/APIUtil.scala | 2 +- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/obp-api/src/main/scala/code/api/constant/constant.scala b/obp-api/src/main/scala/code/api/constant/constant.scala index 56b4cfb845..4d7df1a2ef 100644 --- a/obp-api/src/main/scala/code/api/constant/constant.scala +++ b/obp-api/src/main/scala/code/api/constant/constant.scala @@ -62,36 +62,34 @@ object Constant extends MdcLoggable { final val SYSTEM_READ_TRANSACTIONS_BERLIN_GROUP_VIEW_ID = "ReadTransactionsBerlinGroup" //TODO, this need to be double check - final val ALL_SYSTEM_VIEWS_CREATED_FROM_BOOT = List( - SYSTEM_OWNER_VIEW_ID, - SYSTEM_AUDITOR_VIEW_ID, - SYSTEM_ACCOUNTANT_VIEW_ID, - SYSTEM_FIREHOSE_VIEW_ID, - SYSTEM_STANDARD_VIEW_ID, - SYSTEM_STAGE_ONE_VIEW_ID, - SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID, - SYSTEM_READ_ACCOUNTS_BASIC_VIEW_ID, - SYSTEM_READ_ACCOUNTS_DETAIL_VIEW_ID, - SYSTEM_READ_BALANCES_VIEW_ID, - SYSTEM_READ_TRANSACTIONS_BASIC_VIEW_ID, - SYSTEM_READ_TRANSACTIONS_DEBITS_VIEW_ID, - SYSTEM_READ_TRANSACTIONS_DETAIL_VIEW_ID, - SYSTEM_READ_ACCOUNTS_BERLIN_GROUP_VIEW_ID, - SYSTEM_READ_BALANCES_BERLIN_GROUP_VIEW_ID, - SYSTEM_READ_TRANSACTIONS_BERLIN_GROUP_VIEW_ID - ) + final val ALL_SYSTEM_VIEWS_CREATED_FROM_BOOT = + SYSTEM_OWNER_VIEW_ID:: + SYSTEM_AUDITOR_VIEW_ID:: + SYSTEM_ACCOUNTANT_VIEW_ID:: + SYSTEM_FIREHOSE_VIEW_ID:: + SYSTEM_STANDARD_VIEW_ID:: + SYSTEM_STAGE_ONE_VIEW_ID:: + SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID:: + SYSTEM_READ_ACCOUNTS_BASIC_VIEW_ID:: + SYSTEM_READ_ACCOUNTS_DETAIL_VIEW_ID:: + SYSTEM_READ_BALANCES_VIEW_ID:: + SYSTEM_READ_TRANSACTIONS_BASIC_VIEW_ID:: + SYSTEM_READ_TRANSACTIONS_DEBITS_VIEW_ID:: + SYSTEM_READ_TRANSACTIONS_DETAIL_VIEW_ID:: + SYSTEM_READ_ACCOUNTS_BERLIN_GROUP_VIEW_ID:: + SYSTEM_READ_BALANCES_BERLIN_GROUP_VIEW_ID:: + SYSTEM_READ_TRANSACTIONS_BERLIN_GROUP_VIEW_ID :: Nil - final val ALL_SYSTEM_VIEWS_CREATED_FROM_CBS = List( - SYSTEM_OWNER_VIEW_ID, - SYSTEM_ACCOUNTANT_VIEW_ID, - SYSTEM_AUDITOR_VIEW_ID, - SYSTEM_STAGE_ONE_VIEW_ID, - SYSTEM_STANDARD_VIEW_ID, - SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID, - SYSTEM_READ_ACCOUNTS_BERLIN_GROUP_VIEW_ID, - SYSTEM_READ_BALANCES_BERLIN_GROUP_VIEW_ID, - SYSTEM_READ_TRANSACTIONS_BERLIN_GROUP_VIEW_ID - ) + final val ALL_SYSTEM_VIEWS_CREATED_FROM_CBS = + SYSTEM_OWNER_VIEW_ID:: + SYSTEM_ACCOUNTANT_VIEW_ID:: + SYSTEM_AUDITOR_VIEW_ID:: + SYSTEM_STAGE_ONE_VIEW_ID:: + SYSTEM_STANDARD_VIEW_ID:: + SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID:: + SYSTEM_READ_ACCOUNTS_BERLIN_GROUP_VIEW_ID:: + SYSTEM_READ_BALANCES_BERLIN_GROUP_VIEW_ID:: + SYSTEM_READ_TRANSACTIONS_BERLIN_GROUP_VIEW_ID :: Nil //These are the default incoming and outgoing account ids. we will create both during the boot.scala. final val INCOMING_SETTLEMENT_ACCOUNT_ID = "OBP-INCOMING-SETTLEMENT-ACCOUNT" diff --git a/obp-api/src/main/scala/code/api/util/APIUtil.scala b/obp-api/src/main/scala/code/api/util/APIUtil.scala index eb9c718990..9aeaa82d93 100644 --- a/obp-api/src/main/scala/code/api/util/APIUtil.scala +++ b/obp-api/src/main/scala/code/api/util/APIUtil.scala @@ -148,7 +148,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ val DateWithMonthFormat = new SimpleDateFormat(DateWithMonth) val DateWithDayFormat = new SimpleDateFormat(DateWithDay) val DateWithSecondsFormat = new SimpleDateFormat(DateWithSeconds) - val DateWithMsFormat = new SimpleDateFormat(DateWithMs) + lazy val DateWithMsFormat = new SimpleDateFormat(DateWithMs) val DateWithMsRollbackFormat = new SimpleDateFormat(DateWithMsRollback) val DateWithYearExampleString: String = "1100" From f7595a98cfd446f2bafe521ed1aee6a40f0aa07f Mon Sep 17 00:00:00 2001 From: hongwei Date: Wed, 12 Jun 2024 14:39:34 +0200 Subject: [PATCH 11/23] feature/added new connector method getBankAccountBalances to StoredProcedureConnector_vDec2019 --- .../main/scala/code/api/util/APIUtil.scala | 2 +- .../scala/code/api/util/ErrorMessages.scala | 3 +- .../bankconnectors/ConnectorBuilderUtil.scala | 1 + .../StoredProcedureConnector_vDec2019.scala | 43 +++++++++++++++++-- .../main/scala/code/views/MapperViews.scala | 5 ++- .../commons/dto/JsonsTransfer.scala | 5 +++ 6 files changed, 51 insertions(+), 8 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/APIUtil.scala b/obp-api/src/main/scala/code/api/util/APIUtil.scala index 9aeaa82d93..eb9c718990 100644 --- a/obp-api/src/main/scala/code/api/util/APIUtil.scala +++ b/obp-api/src/main/scala/code/api/util/APIUtil.scala @@ -148,7 +148,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ val DateWithMonthFormat = new SimpleDateFormat(DateWithMonth) val DateWithDayFormat = new SimpleDateFormat(DateWithDay) val DateWithSecondsFormat = new SimpleDateFormat(DateWithSeconds) - lazy val DateWithMsFormat = new SimpleDateFormat(DateWithMs) + val DateWithMsFormat = new SimpleDateFormat(DateWithMs) val DateWithMsRollbackFormat = new SimpleDateFormat(DateWithMsRollback) val DateWithYearExampleString: String = "1100" diff --git a/obp-api/src/main/scala/code/api/util/ErrorMessages.scala b/obp-api/src/main/scala/code/api/util/ErrorMessages.scala index 472752db3f..2c6e1a0544 100644 --- a/obp-api/src/main/scala/code/api/util/ErrorMessages.scala +++ b/obp-api/src/main/scala/code/api/util/ErrorMessages.scala @@ -336,8 +336,7 @@ object ErrorMessages { val CreateCardError = "OBP-30032: Could not insert the Card" val UpdateCardError = "OBP-30033: Could not update the Card" - val ViewIdNotSupported = s"OBP-30034: This ViewId is not supported. Only the following can be used: " + - code.api.Constant.ALL_SYSTEM_VIEWS_CREATED_FROM_CBS.mkString(", ") + val ViewIdNotSupported = s"OBP-30034: This ViewId is not supported. Only the following can be used: " val UserCustomerLinkNotFound = "OBP-30035: User Customer Link not found" diff --git a/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala b/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala index 70610ebaec..033b33302d 100644 --- a/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala +++ b/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala @@ -234,6 +234,7 @@ object ConnectorBuilderUtil { "getBankAccountsForUser", "getUser", "getBankAccountsBalances", + "getBankAccountBalances", "getCoreBankAccounts", "getBankAccountsHeld", "getCounterpartyTrait", diff --git a/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureConnector_vDec2019.scala b/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureConnector_vDec2019.scala index 9ab651e8e6..8b21fe9254 100644 --- a/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureConnector_vDec2019.scala +++ b/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureConnector_vDec2019.scala @@ -75,7 +75,7 @@ trait StoredProcedureConnector_vDec2019 extends Connector with MdcLoggable { val connectorName = "stored_procedure_vDec2019" //---------------- dynamic start -------------------please don't modify this line -// ---------- created on 2024-01-29T13:58:37Z +// ---------- created on 2024-06-12T14:42:25Z messageDocs += getAdapterInfoDoc def getAdapterInfoDoc = MessageDoc( @@ -1051,6 +1051,43 @@ trait StoredProcedureConnector_vDec2019 extends Connector with MdcLoggable { response.map(convertToTuple[AccountsBalances](callContext)) } + messageDocs += getBankAccountBalancesDoc + def getBankAccountBalancesDoc = MessageDoc( + process = "obp.getBankAccountBalances", + messageFormat = messageFormat, + description = "Get Bank Account Balances", + outboundTopic = None, + inboundTopic = None, + exampleOutboundMessage = ( + OutBoundGetBankAccountBalances(outboundAdapterCallContext=MessageDocsSwaggerDefinitions.outboundAdapterCallContext, + bankIdAccountId= BankIdAccountId(bankId=BankId(bankIdExample.value), + accountId=AccountId(accountIdExample.value))) + ), + exampleInboundMessage = ( + InBoundGetBankAccountBalances(inboundAdapterCallContext=MessageDocsSwaggerDefinitions.inboundAdapterCallContext, + status=MessageDocsSwaggerDefinitions.inboundStatus, + data= AccountBalances(id=idExample.value, + label=labelExample.value, + bankId=bankIdExample.value, + accountRoutings=List( AccountRouting(scheme=accountRoutingSchemeExample.value, + address=accountRoutingAddressExample.value)), + balances=List( BankAccountBalance(balance= AmountOfMoney(currency=balanceCurrencyExample.value, + amount=balanceAmountExample.value), + balanceType="string")), + overallBalance= AmountOfMoney(currency=currencyExample.value, + amount=amountExample.value), + overallBalanceDate=toDate(overallBalanceDateExample))) + ), + adapterImplementation = Some(AdapterImplementation("- Core", 1)) + ) + + override def getBankAccountBalances(bankIdAccountId: BankIdAccountId, callContext: Option[CallContext]): OBPReturnType[Box[AccountBalances]] = { + import com.openbankproject.commons.dto.{InBoundGetBankAccountBalances => InBound, OutBoundGetBankAccountBalances => OutBound} + val req = OutBound(callContext.map(_.toOutboundAdapterCallContext).orNull, bankIdAccountId) + val response: Future[Box[InBound]] = sendRequest[InBound]("obp_get_bank_account_balances", req, callContext) + response.map(convertToTuple[AccountBalances](callContext)) + } + messageDocs += getCoreBankAccountsDoc def getCoreBankAccountsDoc = MessageDoc( process = "obp.getCoreBankAccounts", @@ -6587,8 +6624,8 @@ trait StoredProcedureConnector_vDec2019 extends Connector with MdcLoggable { response.map(convertToTuple[Boolean](callContext)) } -// ---------- created on 2024-01-29T13:58:37Z -//---------------- dynamic end ---------------------please don't modify this line +// ---------- created on 2024-06-12T14:42:25Z +//---------------- dynamic end ---------------------please don't modify this line private val availableOperation = DynamicEntityOperation.values.map(it => s""""$it"""").mkString("[", ", ", "]") diff --git a/obp-api/src/main/scala/code/views/MapperViews.scala b/obp-api/src/main/scala/code/views/MapperViews.scala index cfead6ea9e..82e160d4a9 100644 --- a/obp-api/src/main/scala/code/views/MapperViews.scala +++ b/obp-api/src/main/scala/code/views/MapperViews.scala @@ -611,8 +611,9 @@ object MapperViews extends Views with MdcLoggable { val theView = if (ALL_SYSTEM_VIEWS_CREATED_FROM_CBS.contains(viewId)) { getOrCreateSystemView(viewId) } else { - logger.error(ViewIdNotSupported + s"Your input viewId is :$viewId") - Failure(ViewIdNotSupported + s"Your input viewId is :$viewId") + val errorMessage = ViewIdNotSupported + code.api.Constant.ALL_SYSTEM_VIEWS_CREATED_FROM_CBS.mkString(", ") + s"Your input viewId is :$viewId" + logger.error(errorMessage) + Failure(errorMessage) } logger.debug(s"-->getOrCreateSystemViewFromCbs --- finish.${viewId } : ${theView} ") theView diff --git a/obp-commons/src/main/scala/com/openbankproject/commons/dto/JsonsTransfer.scala b/obp-commons/src/main/scala/com/openbankproject/commons/dto/JsonsTransfer.scala index 16e932fc73..1fee77e881 100644 --- a/obp-commons/src/main/scala/com/openbankproject/commons/dto/JsonsTransfer.scala +++ b/obp-commons/src/main/scala/com/openbankproject/commons/dto/JsonsTransfer.scala @@ -112,6 +112,11 @@ case class OutBoundGetBankAccountsBalances(outboundAdapterCallContext: OutboundA case class InBoundGetBankAccountsBalances(inboundAdapterCallContext: InboundAdapterCallContext, status: Status, data: AccountsBalances) extends InBoundTrait[AccountsBalances] +case class OutBoundGetBankAccountBalances(outboundAdapterCallContext: OutboundAdapterCallContext, + bankIdAccountId: BankIdAccountId) extends TopicTrait + +case class InBoundGetBankAccountBalances(inboundAdapterCallContext: InboundAdapterCallContext, status: Status, data: AccountBalances) extends InBoundTrait[AccountBalances] + case class OutBoundGetCoreBankAccountsHeld(outboundAdapterCallContext: OutboundAdapterCallContext, bankIdAccountIds: List[BankIdAccountId]) extends TopicTrait case class InBoundGetCoreBankAccountsHeld(inboundAdapterCallContext: InboundAdapterCallContext, status: Status, data: List[AccountHeld]) extends InBoundTrait[List[AccountHeld]] From 5998b41ae11e5f91009d62faa5996c040dbfa6f8 Mon Sep 17 00:00:00 2001 From: hongwei Date: Thu, 13 Jun 2024 14:55:52 +0200 Subject: [PATCH 12/23] refactor/added a test code for owner view --- obp-api/src/main/scala/code/views/MapperViews.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/obp-api/src/main/scala/code/views/MapperViews.scala b/obp-api/src/main/scala/code/views/MapperViews.scala index 82e160d4a9..c4bc494ed2 100644 --- a/obp-api/src/main/scala/code/views/MapperViews.scala +++ b/obp-api/src/main/scala/code/views/MapperViews.scala @@ -608,7 +608,11 @@ object MapperViews extends Views with MdcLoggable { def getOrCreateSystemViewFromCbs(viewId: String): Box[View] = { logger.debug(s"-->getOrCreateSystemViewFromCbs--- start--${viewId} ") - val theView = if (ALL_SYSTEM_VIEWS_CREATED_FROM_CBS.contains(viewId)) { + val ownerView = SYSTEM_OWNER_VIEW_ID.equals(viewId.toLowerCase) + + val theView = if (ownerView) { + getOrCreateSystemView(SYSTEM_OWNER_VIEW_ID) + } else if (ALL_SYSTEM_VIEWS_CREATED_FROM_CBS.contains(viewId)) { getOrCreateSystemView(viewId) } else { val errorMessage = ViewIdNotSupported + code.api.Constant.ALL_SYSTEM_VIEWS_CREATED_FROM_CBS.mkString(", ") + s"Your input viewId is :$viewId" From 62a14196e6a14530099df92b9e07f9dcf3487317 Mon Sep 17 00:00:00 2001 From: hongwei Date: Fri, 14 Jun 2024 12:23:51 +0200 Subject: [PATCH 13/23] refactor/use Constant.SYSTEM_OWNER_VIEW_ID instead of "owner" --- .../resources/i18n/lift-core_es_ES.properties | 2 +- obp-api/src/main/scala/code/api/OAuth2.scala | 1 - .../MessageDocsSwaggerDefinitions.scala | 3 +- .../SwaggerDefinitionsJSON.scala | 14 ++++---- .../v1_3/PaymentInitiationServicePISApi.scala | 3 +- .../scala/code/api/util/ExampleValue.scala | 9 +++--- .../main/scala/code/api/util/Glossary.scala | 4 +-- .../MigrationInfoOfAccoutHolders.scala | 3 +- .../scala/code/api/v3_1_0/APIMethods310.scala | 8 ++--- .../scala/code/api/v4_0_0/APIMethods400.scala | 4 +-- .../KafkaMappedConnector_vSept2018.scala | 3 +- .../scala/code/sandbox/OBPDataImport.scala | 2 +- .../scala/code/api/v1_2_0/API12Test.scala | 32 +++++++++---------- .../scala/code/api/v2_2_0/AccountTest.scala | 3 +- .../scala/code/api/v3_0_0/FirehoseTest.scala | 11 ++++--- .../scala/code/api/v3_1_0/ConsentTest.scala | 3 +- .../api/v3_1_0/TransactionRequestTest.scala | 4 +-- .../code/api/v3_1_0/TransactionTest.scala | 14 ++++---- .../api/v4_0_0/DeleteAccountCascadeTest.scala | 3 +- .../api/v4_0_0/DeleteBankCascadeTest.scala | 3 +- .../v4_0_0/DoubleEntryTransactionTest.scala | 3 +- .../v4_0_0/TransactionAttributesTest.scala | 6 ++-- .../TransactionRequestAttributesTest.scala | 5 +-- .../api/v4_0_0/TransactionRequestsTest.scala | 9 +++--- .../code/api/v5_0_0/ConsentRequestTest.scala | 3 +- .../scala/code/api/v5_1_0/ConsentsTest.scala | 3 +- .../code/connector/MockedCbsConnector.scala | 5 +-- .../scala/code/views/MappedViewsTest.scala | 7 ++-- 28 files changed, 93 insertions(+), 77 deletions(-) diff --git a/obp-api/src/main/resources/i18n/lift-core_es_ES.properties b/obp-api/src/main/resources/i18n/lift-core_es_ES.properties index 3d3dd7a07c..c8b54ad520 100644 --- a/obp-api/src/main/resources/i18n/lift-core_es_ES.properties +++ b/obp-api/src/main/resources/i18n/lift-core_es_ES.properties @@ -718,7 +718,7 @@ OBP-30030 = se pudo insertar el Producto OBP-30031 = se ha podido actualizar el Producto OBP-30032 = se pudo insertar la tarjeta OBP-30033 = se ha podido actualizar la tarjeta -OBP-30034 = ViewId no es soportado. Sólo admite cuatro ahora': Owner, Accountant, Auditor, _Public. +OBP-30034 = ViewId no es soportado. Sólo admite cuatro ahora': owner, accountant, auditor, _public. OBP-30035 = se ha encontrado el enlace con el cliente OBP-30036 = se ha podido crear o actualizar CounterpartyMetadata OBP-30037 = se han encontrado los metadatos de la contraparte. Por favor, especifique valores válidos para BANK_ID, ACCOUNT_ID y COUNTERPARTY_ID. diff --git a/obp-api/src/main/scala/code/api/OAuth2.scala b/obp-api/src/main/scala/code/api/OAuth2.scala index 441ac95679..f40c5e5f03 100644 --- a/obp-api/src/main/scala/code/api/OAuth2.scala +++ b/obp-api/src/main/scala/code/api/OAuth2.scala @@ -27,7 +27,6 @@ TESOBE (http://www.tesobe.com/) package code.api import java.net.URI -import java.util import code.api.util.ErrorMessages._ import code.api.util.{APIUtil, CallContext, JwtUtil} import code.consumer.Consumers diff --git a/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/MessageDocsSwaggerDefinitions.scala b/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/MessageDocsSwaggerDefinitions.scala index 65fb3f51c7..6fbd7001e4 100644 --- a/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/MessageDocsSwaggerDefinitions.scala +++ b/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/MessageDocsSwaggerDefinitions.scala @@ -1,5 +1,6 @@ package code.api.ResourceDocs1_4_0 +import code.api.Constant import java.util.Date import code.api.util.APIUtil._ @@ -23,7 +24,7 @@ object MessageDocsSwaggerDefinitions balanceAmount = balanceAmountExample.value, balanceCurrency = currencyExample.value, owners = List(owner1Example.value), - viewsToGenerate = List("Owner", "Accountant", "Auditor"), + viewsToGenerate = List(Constant.SYSTEM_OWNER_VIEW_ID, Constant.SYSTEM_ACCOUNTANT_VIEW_ID,Constant.SYSTEM_AUDITOR_VIEW_ID), bankRoutingScheme = bankRoutingSchemeExample.value, bankRoutingAddress = bankRoutingAddressExample.value, branchRoutingScheme = branchRoutingSchemeExample.value, diff --git a/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala b/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala index c4e3fd69bb..549dd5c70e 100644 --- a/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala +++ b/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala @@ -323,8 +323,8 @@ object SwaggerDefinitionsJSON { hide_metadata_if_alias_used = false, allowed_actions = allowedActionsV500, // Version 5.0.0 - can_grant_access_to_views = Some(List("owner")), - can_revoke_access_to_views = Some(List("owner")) + can_grant_access_to_views = Some(List(Constant.SYSTEM_OWNER_VIEW_ID)), + can_revoke_access_to_views = Some(List(Constant.SYSTEM_OWNER_VIEW_ID)) ) val updateViewJsonV300 = UpdateViewJsonV300( @@ -416,8 +416,8 @@ object SwaggerDefinitionsJSON { hide_metadata_if_alias_used = true, allowed_actions = allowedActionsV500, // Version 5.0.0 - can_grant_access_to_views = Some(List("owner")), - can_revoke_access_to_views = Some(List("owner")) + can_grant_access_to_views = Some(List(Constant.SYSTEM_OWNER_VIEW_ID)), + can_revoke_access_to_views = Some(List(Constant.SYSTEM_OWNER_VIEW_ID)) ) lazy val updateSystemViewJson500 = updateViewJsonV500.copy(is_public = false, is_firehose = Some(false)) @@ -3048,15 +3048,15 @@ object SwaggerDefinitionsJSON { can_see_bank_account_credit_limit = true, can_create_direct_debit = true, can_create_standing_order = true, - can_grant_access_to_views = List("Owner"), - can_revoke_access_to_views = List("Owner") + can_grant_access_to_views = List(Constant.SYSTEM_OWNER_VIEW_ID), + can_revoke_access_to_views = List(Constant.SYSTEM_OWNER_VIEW_ID) ) val viewsJsonV500 = ViewsJsonV500( views = List(viewJsonV500) ) - val viewIdJsonV500 = ViewIdJsonV500(id = "owner") + val viewIdJsonV500 = ViewIdJsonV500(id = Constant.SYSTEM_OWNER_VIEW_ID) val viewIdsJsonV500 = ViewsIdsJsonV500( views = List(viewIdJsonV500) ) diff --git a/obp-api/src/main/scala/code/api/berlin/group/v1_3/PaymentInitiationServicePISApi.scala b/obp-api/src/main/scala/code/api/berlin/group/v1_3/PaymentInitiationServicePISApi.scala index d2d26ad118..bce50fbdb1 100644 --- a/obp-api/src/main/scala/code/api/berlin/group/v1_3/PaymentInitiationServicePISApi.scala +++ b/obp-api/src/main/scala/code/api/berlin/group/v1_3/PaymentInitiationServicePISApi.scala @@ -1,5 +1,6 @@ package code.api.builder.PaymentInitiationServicePISApi +import code.api.Constant import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.sepaCreditTransfersBerlinGroupV13 import code.api.berlin.group.v1_3.JSONFactory_BERLIN_GROUP_1_3.{CancelPaymentResponseJson, CancelPaymentResponseLinks, LinkHrefJson, UpdatePaymentPsuDataJson, checkUpdatePsuAuthentication,checkAuthorisationConfirmation, @@ -590,7 +591,7 @@ Check the transaction status of a payment initiation.""", for { (createdTransactionRequest, callContext) <- NewStyle.function.createTransactionRequestv400( u, - ViewId("Owner"), //This is the default + ViewId(Constant.SYSTEM_OWNER_VIEW_ID), //This is the default fromAccount, toAccount, TransactionRequestType(transactionRequestTypes.toString), diff --git a/obp-api/src/main/scala/code/api/util/ExampleValue.scala b/obp-api/src/main/scala/code/api/util/ExampleValue.scala index 2ce0791848..14a61098a6 100644 --- a/obp-api/src/main/scala/code/api/util/ExampleValue.scala +++ b/obp-api/src/main/scala/code/api/util/ExampleValue.scala @@ -1,6 +1,7 @@ package code.api.util +import code.api.Constant import code.api.util.APIUtil.{DateWithMs, DateWithMsExampleString, formatDate, oneYearAgo, oneYearAgoDate, parseDate} import code.api.util.ErrorMessages.{InvalidJsonFormat, UnknownError, UserHasMissingRoles, UserNotLoggedIn} import net.liftweb.json.JsonDSL._ @@ -331,10 +332,10 @@ object ExampleValue { lazy val owner1Example = ConnectorField("SusanSmith", "A username that is the owner of the account.") glossaryItems += makeGlossaryItem("Account.owner", owner1Example) - lazy val viewIdExample = ConnectorField("owner", "A viewId can be owner, accountant, public ....") + lazy val viewIdExample = ConnectorField(Constant.SYSTEM_OWNER_VIEW_ID, "A viewId can be owner, accountant ....") glossaryItems += makeGlossaryItem("view.id", viewIdExample) - lazy val viewNameExample = ConnectorField("Owner","A viewName can be Owner, Accountant, Public ....") + lazy val viewNameExample = ConnectorField(Constant.SYSTEM_OWNER_VIEW_ID,"A viewName can be owner, accountant ....") glossaryItems += makeGlossaryItem("view.name",viewNameExample) lazy val viewDescriptionExample = ConnectorField("This view is for the owner for the account.", "A description for this view.") @@ -1497,7 +1498,7 @@ object ExampleValue { glossaryItems += makeGlossaryItem("basket_id", basketIdExample) lazy val consentRequestPayloadExample = ConnectorField( - """{ + s"""{ | "everything": false, | "account_access": [ | { @@ -1505,7 +1506,7 @@ object ExampleValue { | "scheme": "AccountNumber", | "address": "4930396" | }, - | "view_id": "owner" + | "view_id": "${Constant.SYSTEM_OWNER_VIEW_ID}" | } | ], | "phone_number": "+44 07972 444 876", diff --git a/obp-api/src/main/scala/code/api/util/Glossary.scala b/obp-api/src/main/scala/code/api/util/Glossary.scala index be899fe1a6..5a02fcac85 100644 --- a/obp-api/src/main/scala/code/api/util/Glossary.scala +++ b/obp-api/src/main/scala/code/api/util/Glossary.scala @@ -1,7 +1,7 @@ package code.api.util import java.io.File - +import code.api.Constant import code.api.Constant.{PARAM_LOCALE, directLoginHeaderName} import code.api.util.APIUtil.{getObpApiRoot, getServerUrl} import code.api.util.ExampleValue.{accountIdExample, bankIdExample, customerIdExample, userIdExample} @@ -1752,7 +1752,7 @@ object Glossary extends MdcLoggable { | |Body: | -| { "everything":false, "views":[{ "bank_id":"gh.29.uk", "account_id":"8ca8a7e4-6d02-40e3-a129-0b2bf89de9f0", "view_id":"owner" }], "entitlements":[{ "bank_id":"gh.29.uk", "role_name":"CanGetCustomer" }], "consumer_id":"7uy8a7e4-6d02-40e3-a129-0b2bf89de8uh", "phone_number":"+44 07972 444 876", "valid_from":"2022-04-29T10:40:03Z", "time_to_live":3600} +| { "everything":false, "views":[{ "bank_id":"gh.29.uk", "account_id":"8ca8a7e4-6d02-40e3-a129-0b2bf89de9f0", "view_id":${Constant.SYSTEM_OWNER_VIEW_ID}], "entitlements":[{ "bank_id":"gh.29.uk", "role_name":"CanGetCustomer" }], "consumer_id":"7uy8a7e4-6d02-40e3-a129-0b2bf89de8uh", "phone_number":"+44 07972 444 876", "valid_from":"2022-04-29T10:40:03Z", "time_to_live":3600} | |Headers: | 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 321f33bf87..35f18d283f 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 @@ -1,5 +1,6 @@ package code.api.util.migration +import code.api.Constant import java.time.format.DateTimeFormatter import java.time.{ZoneId, ZonedDateTime} @@ -42,7 +43,7 @@ object BankAccountHoldersAndOwnerViewAccess { ownerViewAccess = AccountAccess.findAll( By(AccountAccess.bank_id, bankId), By(AccountAccess.account_id, accountId), - ByList(AccountAccess.view_id, List("owner", "_owner")) + ByList(AccountAccess.view_id, List(Constant.SYSTEM_OWNER_VIEW_ID, "_owner")) ) } yield { (bankId, accountId, ownerViewAccess.size > 0) diff --git a/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala b/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala index b7a29a7d88..7d2c74424b 100644 --- a/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala +++ b/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala @@ -3245,7 +3245,7 @@ trait APIMethods310 { | { | "bank_id": "GENODEM1GLS", | "account_id": "8ca8a7e4-6d02-40e3-a129-0b2bf89de9f0", - | "view_id": "owner" + | "view_id": "${Constant.SYSTEM_OWNER_VIEW_ID}" | } | ], | "entitlements": [ @@ -3316,7 +3316,7 @@ trait APIMethods310 { | { | "bank_id": "GENODEM1GLS", | "account_id": "8ca8a7e4-6d02-40e3-a129-0b2bf89de9f0", - | "view_id": "owner" + | "view_id": "${Constant.SYSTEM_OWNER_VIEW_ID}" | } | ], | "entitlements": [ @@ -3395,7 +3395,7 @@ trait APIMethods310 { | { | "bank_id": "GENODEM1GLS", | "account_id": "8ca8a7e4-6d02-40e3-a129-0b2bf89de9f0", - | "view_id": "owner" + | "view_id": "${Constant.SYSTEM_OWNER_VIEW_ID}" | } | ], | "entitlements": [ @@ -3474,7 +3474,7 @@ trait APIMethods310 { | { | "bank_id": "GENODEM1GLS", | "account_id": "8ca8a7e4-6d02-40e3-a129-0b2bf89de9f0", - | "view_id": "owner" + | "view_id": "${Constant.SYSTEM_OWNER_VIEW_ID}" | } | ], | "entitlements": [ 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 da72ce71f1..b548ca5635 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 @@ -1470,7 +1470,7 @@ trait APIMethods400 extends MdcLoggable { case "transaction-request-types" :: "CARD" :: "transaction-requests" :: Nil JsonPost json -> _ => cc => implicit val ec = EndpointContext(Some(cc)) val transactionRequestType = TransactionRequestType("CARD") - createTransactionRequest(BankId(""), AccountId(""), ViewId("owner"), transactionRequestType, json) + createTransactionRequest(BankId(""), AccountId(""), ViewId(Constant.SYSTEM_OWNER_VIEW_ID), transactionRequestType, json) } @@ -8338,7 +8338,7 @@ trait APIMethods400 extends MdcLoggable { createdByUserId=u.userId, thisBankId=bankId.value, thisAccountId=accountId.value, - thisViewId = "owner", + thisViewId = Constant.SYSTEM_OWNER_VIEW_ID, otherAccountRoutingScheme=postJson.other_account_routing_scheme, otherAccountRoutingAddress=postJson.other_account_routing_address, otherAccountSecondaryRoutingScheme=postJson.other_account_secondary_routing_scheme, diff --git a/obp-api/src/main/scala/code/bankconnectors/vSept2018/KafkaMappedConnector_vSept2018.scala b/obp-api/src/main/scala/code/bankconnectors/vSept2018/KafkaMappedConnector_vSept2018.scala index 259baecf12..412797bc83 100644 --- a/obp-api/src/main/scala/code/bankconnectors/vSept2018/KafkaMappedConnector_vSept2018.scala +++ b/obp-api/src/main/scala/code/bankconnectors/vSept2018/KafkaMappedConnector_vSept2018.scala @@ -23,6 +23,7 @@ Osloerstrasse 16/17 Berlin 13359, Germany */ +import code.api.Constant import java.text.SimpleDateFormat import java.util.Date import java.util.UUID.randomUUID @@ -193,7 +194,7 @@ trait KafkaMappedConnector_vSept2018 extends Connector with KafkaHelper with Mdc generalContext = Option(List(BasicGeneralContext(key = "string", value = "string")))) - val viewBasicExample = ViewBasic("owner","Owner", "This is the owner view") + val viewBasicExample = ViewBasic(Constant.SYSTEM_OWNER_VIEW_ID,Constant.SYSTEM_OWNER_VIEW_ID, "This is the owner view") val internalBasicCustomerExample = InternalBasicCustomer( bankId = ExampleValue.bankIdExample.value, diff --git a/obp-api/src/main/scala/code/sandbox/OBPDataImport.scala b/obp-api/src/main/scala/code/sandbox/OBPDataImport.scala index 2e0cae640c..d5760d2c94 100644 --- a/obp-api/src/main/scala/code/sandbox/OBPDataImport.scala +++ b/obp-api/src/main/scala/code/sandbox/OBPDataImport.scala @@ -295,7 +295,7 @@ trait OBPDataImport extends MdcLoggable { accId = AccountId(acc.id) bankId = BankId(acc.bank) //TODO Check the following logic which breaks sandbox tests after ViewsImpl refactoring - //ownerViewDoesNotExist <- Helper.booleanToBox(Views.views.vend.view(ViewUID(ViewId("owner"), bankId, accId)).isEmpty) ?~ { + //ownerViewDoesNotExist <- Helper.booleanToBox(Views.views.vend.view(ViewUID(ViewId(Constant.SYSTEM_OWNER_VIEW_ID), bankId, accId)).isEmpty) ?~ { // s"owner view for account ${acc.id} at bank ${acc.bank} already exists" //} //publicViewDoesNotExist <- Helper.booleanToBox(Views.views.vend.view(ViewUID(ViewId("public"), bankId, accId)).isEmpty) ?~ { diff --git a/obp-api/src/test/scala/code/api/v1_2_0/API12Test.scala b/obp-api/src/test/scala/code/api/v1_2_0/API12Test.scala index 056d6dbf89..c85d5d896b 100644 --- a/obp-api/src/test/scala/code/api/v1_2_0/API12Test.scala +++ b/obp-api/src/test/scala/code/api/v1_2_0/API12Test.scala @@ -167,7 +167,7 @@ // def randomViewPermalinkButNotOwner(bankId: String, account: AccountJSON) : String = { // val request = v1_2Request / "banks" / bankId / "accounts" / account.id / "views" <@(consumer, token1) // val reply = makeGetRequest(request) -// val possibleViewsPermalinksWithoutOwner = reply.body.extract[ViewsJSON].views.filterNot(_.is_public==true).filterNot(_.id == "owner") +// val possibleViewsPermalinksWithoutOwner = reply.body.extract[ViewsJSON].views.filterNot(_.is_public==true).filterNot(_.id == Constant.SYSTEM_OWNER_VIEW_ID) // val randomPosition = nextInt(possibleViewsPermalinksWithoutOwner.size) // possibleViewsPermalinksWithoutOwner(randomPosition).id // } @@ -1377,7 +1377,7 @@ // Given("We will use an access token") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val viewId = "owner" +// val viewId = Constant.SYSTEM_OWNER_VIEW_ID // val userId1 = resourceUser2.idGivenByProvider // val userId2 = resourceUser2.idGivenByProvider // grantUserAccessToView(bankId, bankAccount.id, userId1, viewId, user1) @@ -1395,7 +1395,7 @@ // Given("We will use an access token") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val viewId = ViewId("owner") +// val viewId = ViewId(Constant.SYSTEM_OWNER_VIEW_ID) // val view = Views.views.vend.view(BankIdAccountIdViewId(BankId(bankId), AccountId(bankAccount.id), viewId)).get // if(Views.views.vend.getOwners(view).toList.length == 0){ // val userId = resourceUser2.idGivenByProvider @@ -4122,7 +4122,7 @@ // Given("We will use an access token") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val view = "owner" +// val view = Constant.SYSTEM_OWNER_VIEW_ID // val transaction = randomTransaction(bankId, bankAccount.id, view) // When("the request is sent") // val randomNarrative = randomString(20) @@ -4140,7 +4140,7 @@ // Given("We will not use an access token") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val view = "owner" +// val view = Constant.SYSTEM_OWNER_VIEW_ID // val transaction = randomTransaction(bankId, bankAccount.id, view) // val randomNarrative = randomString(20) // When("the request is sent") @@ -4159,7 +4159,7 @@ // Given("We will use an access token") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val view = "owner" +// val view = Constant.SYSTEM_OWNER_VIEW_ID // val transaction = randomTransaction(bankId, bankAccount.id, view) // val randomNarrative = randomString(20) // When("the request is sent") @@ -4178,7 +4178,7 @@ // Given("We will use an access token") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val view = "owner" +// val view = Constant.SYSTEM_OWNER_VIEW_ID // val transaction = randomTransaction(bankId, bankAccount.id, view) // val randomNarrative = randomString(20) // When("the request is sent") @@ -4197,7 +4197,7 @@ // Given("We will use an access token") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val view = "owner" +// val view = Constant.SYSTEM_OWNER_VIEW_ID // val randomNarrative = randomString(20) // When("the request is sent") // val postReply = postNarrativeForOneTransaction(bankId, bankAccount.id, view, randomString(5), randomNarrative, user1) @@ -4213,7 +4213,7 @@ // Given("We will use an access token") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val view = "owner" +// val view = Constant.SYSTEM_OWNER_VIEW_ID // val transaction = randomTransaction(bankId, bankAccount.id, view) // When("the request is sent") // val randomNarrative = randomString(20) @@ -4231,7 +4231,7 @@ // Given("We will not use an access token") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val view = "owner" +// val view = Constant.SYSTEM_OWNER_VIEW_ID // val transaction = randomTransaction(bankId, bankAccount.id, view) // val randomNarrative = randomString(20) // When("the request is sent") @@ -4250,7 +4250,7 @@ // Given("We will use an access token") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val view = "owner" +// val view = Constant.SYSTEM_OWNER_VIEW_ID // val transaction = randomTransaction(bankId, bankAccount.id, view) // val randomNarrative = randomString(20) // When("the request is sent") @@ -4269,7 +4269,7 @@ // Given("We will use an access token") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val view = "owner" +// val view = Constant.SYSTEM_OWNER_VIEW_ID // val transactionId = randomString(5) // val randomNarrative = randomString(20) // When("the request is sent") @@ -4286,7 +4286,7 @@ // Given("We will use an access token and will set a narrative first") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val view = "owner" +// val view = Constant.SYSTEM_OWNER_VIEW_ID // val transaction = randomTransaction(bankId, bankAccount.id, view) // val randomNarrative = randomString(20) // postNarrativeForOneTransaction(bankId, bankAccount.id, view, transaction.id, randomNarrative, user1) @@ -4304,7 +4304,7 @@ // Given("We will not use an access token and will set a narrative first") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val view = "owner" +// val view = Constant.SYSTEM_OWNER_VIEW_ID // val transaction = randomTransaction(bankId, bankAccount.id, view) // val randomNarrative = randomString(20) // postNarrativeForOneTransaction(bankId, bankAccount.id, view, transaction.id, randomNarrative, user1) @@ -4322,7 +4322,7 @@ // Given("We will use an access token and will set a narrative first") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val view = "owner" +// val view = Constant.SYSTEM_OWNER_VIEW_ID // val transaction = randomTransaction(bankId, bankAccount.id, view) // val randomNarrative = randomString(20) // postNarrativeForOneTransaction(bankId, bankAccount.id, view, transaction.id, randomNarrative, user1) @@ -4340,7 +4340,7 @@ // Given("We will use an access token") // val bankId = randomBank // val bankAccount : AccountJSON = randomPrivateAccount(bankId) -// val view = "owner" +// val view = Constant.SYSTEM_OWNER_VIEW_ID // val randomNarrative = randomString(20) // When("the delete request is sent") // val deleteReply = deleteNarrativeForOneTransaction(bankId, bankAccount.id, view, randomString(5), user1) diff --git a/obp-api/src/test/scala/code/api/v2_2_0/AccountTest.scala b/obp-api/src/test/scala/code/api/v2_2_0/AccountTest.scala index a1a62b8791..4521df27f3 100644 --- a/obp-api/src/test/scala/code/api/v2_2_0/AccountTest.scala +++ b/obp-api/src/test/scala/code/api/v2_2_0/AccountTest.scala @@ -1,5 +1,6 @@ package code.api.v2_2_0 +import code.api.Constant import code.api.util.APIUtil.OAuth._ import code.api.util.APIUtil.extractErrorMessageCode import code.api.util.{ApiRole, ErrorMessages} @@ -156,7 +157,7 @@ class AccountTest extends V220ServerSetup with DefaultUsers { val accountViews = accountViewsResponse.body.extract[ViewsJSONV220] //Note: now when we create new account, will have the systemOwnerView access to this view. accountViews.views.length > 0 should be (true) - accountViews.views.map(_.id).toString() contains("owner") should be (true) + accountViews.views.map(_.id).toString() contains(Constant.SYSTEM_OWNER_VIEW_ID) should be (true) } scenario("We create an account, but with wrong format of account_id ") { diff --git a/obp-api/src/test/scala/code/api/v3_0_0/FirehoseTest.scala b/obp-api/src/test/scala/code/api/v3_0_0/FirehoseTest.scala index 870a6bc445..45e6b1b361 100644 --- a/obp-api/src/test/scala/code/api/v3_0_0/FirehoseTest.scala +++ b/obp-api/src/test/scala/code/api/v3_0_0/FirehoseTest.scala @@ -1,5 +1,6 @@ package code.api.v3_0_0 +import code.api.Constant import code.api.util.APIUtil.OAuth._ import code.api.util.ApiRole import code.api.util.ApiRole.{CanUseAccountFirehose, CanUseAccountFirehoseAtAnyBank} @@ -77,7 +78,7 @@ class FirehoseTest extends V300ServerSetup with PropsReset{ setPropsValues("enable.force_error"->"true") Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, ApiRole.CanUseAccountFirehoseAtAnyBank.toString) When("We send the request") - val request = (v3_0Request / "banks" / testBankId1.value /"firehose" / "accounts" / testAccountId1.value / "views"/"owner"/"transactions").GET <@ (user1) + val request = (v3_0Request / "banks" / testBankId1.value /"firehose" / "accounts" / testAccountId1.value / "views"/Constant.SYSTEM_OWNER_VIEW_ID/"transactions").GET <@ (user1) val response = makeGetRequest(request) Then("We should get a 200 and check the response body") response.code should equal(200) @@ -89,7 +90,7 @@ class FirehoseTest extends V300ServerSetup with PropsReset{ setPropsValues("enable.force_error" -> "true") Entitlement.entitlement.vend.addEntitlement(testBankId1.value, resourceUser1.userId, ApiRole.CanUseAccountFirehose.toString) When("We send the request") - val request = (v3_0Request / "banks" / testBankId1.value / "firehose" / "accounts" / testAccountId1.value / "views" / "owner" / "transactions").GET <@ (user1) + val request = (v3_0Request / "banks" / testBankId1.value / "firehose" / "accounts" / testAccountId1.value / "views" / Constant.SYSTEM_OWNER_VIEW_ID / "transactions").GET <@ (user1) val response = makeGetRequest(request) Then("We should get a 200 and check the response body") response.code should equal(200) @@ -100,7 +101,7 @@ class FirehoseTest extends V300ServerSetup with PropsReset{ setPropsValues("allow_firehose_views" -> "true") Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, ApiRole.CanUseAccountFirehoseAtAnyBank.toString) When("We send the request") - val request = (v3_0Request / "banks" / testBankId1.value /"firehose" / "accounts" / testAccountId1.value / "views"/"owner"/"transactions").GET <@ (user1) + val request = (v3_0Request / "banks" / testBankId1.value /"firehose" / "accounts" / testAccountId1.value / "views"/Constant.SYSTEM_OWNER_VIEW_ID/"transactions").GET <@ (user1) val response = makeGetRequest(request) Then("We should get a 200 and check the response body") response.code should equal(200) @@ -111,7 +112,7 @@ class FirehoseTest extends V300ServerSetup with PropsReset{ scenario("We will call the endpoint missing role", VersionOfApi, ApiEndpoint4) { setPropsValues("allow_account_firehose" -> "true") When("We send the request") - val request = (v3_0Request / "banks" / testBankId1.value / "firehose" / "accounts" / testAccountId1.value /"views" / "owner"/"transactions").GET <@ (user1) + val request = (v3_0Request / "banks" / testBankId1.value / "firehose" / "accounts" / testAccountId1.value /"views" / Constant.SYSTEM_OWNER_VIEW_ID/"transactions").GET <@ (user1) val response = makeGetRequest(request) Then("We should get a 403 and check the response body") response.code should equal(403) @@ -122,7 +123,7 @@ class FirehoseTest extends V300ServerSetup with PropsReset{ scenario("We will call the endpoint missing props ", VersionOfApi, ApiEndpoint4) { Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, ApiRole.CanUseAccountFirehoseAtAnyBank.toString) When("We send the request") - val request = (v3_0Request / "banks" / testBankId1.value /"firehose" / "accounts" / testAccountId1.value / "views"/"owner"/"transactions").GET <@ (user1) + val request = (v3_0Request / "banks" / testBankId1.value /"firehose" / "accounts" / testAccountId1.value / "views"/Constant.SYSTEM_OWNER_VIEW_ID/"transactions").GET <@ (user1) val response = makeGetRequest(request) Then("We should get a 400 and check the response body") response.code should equal(400) diff --git a/obp-api/src/test/scala/code/api/v3_1_0/ConsentTest.scala b/obp-api/src/test/scala/code/api/v3_1_0/ConsentTest.scala index ca2de8bb76..7bdb236473 100644 --- a/obp-api/src/test/scala/code/api/v3_1_0/ConsentTest.scala +++ b/obp-api/src/test/scala/code/api/v3_1_0/ConsentTest.scala @@ -25,6 +25,7 @@ TESOBE (http://www.tesobe.com/) */ package code.api.v3_1_0 +import code.api.Constant import code.api.RequestHeader import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON import code.api.util.{APIUtil, Consent} @@ -59,7 +60,7 @@ class ConsentTest extends V310ServerSetup { lazy val bankId = randomBankId lazy val bankAccount = randomPrivateAccount(bankId) lazy val entitlements = List(PostConsentEntitlementJsonV310("", CanGetAnyUser.toString())) - lazy val views = List(PostConsentViewJsonV310(bankId, bankAccount.id, "owner")) + lazy val views = List(PostConsentViewJsonV310(bankId, bankAccount.id, Constant.SYSTEM_OWNER_VIEW_ID)) lazy val postConsentEmailJsonV310 = SwaggerDefinitionsJSON.postConsentEmailJsonV310 .copy(entitlements=entitlements) .copy(consumer_id=Some(testConsumer.consumerId.get)) diff --git a/obp-api/src/test/scala/code/api/v3_1_0/TransactionRequestTest.scala b/obp-api/src/test/scala/code/api/v3_1_0/TransactionRequestTest.scala index cc8a23212a..0df2bfda97 100644 --- a/obp-api/src/test/scala/code/api/v3_1_0/TransactionRequestTest.scala +++ b/obp-api/src/test/scala/code/api/v3_1_0/TransactionRequestTest.scala @@ -55,7 +55,7 @@ class TransactionRequestTest extends V310ServerSetup { When("We make a request v3.1.0") val bankId = randomBankId val bankAccount = randomPrivateAccount(bankId) - val view = bankAccount.views_available.map(_.id).headOption.getOrElse("owner") + val view = bankAccount.views_available.map(_.id).headOption.getOrElse(Constant.SYSTEM_OWNER_VIEW_ID) val request310 = (v3_1_0_Request / "banks" / bankId / "accounts" / bankAccount.id / view / "transaction-requests").GET val response310 = makeGetRequest(request310) Then("We should get a 401") @@ -67,7 +67,7 @@ class TransactionRequestTest extends V310ServerSetup { When("We make a request v3.1.0") val bankId = randomBankId val bankAccount = randomPrivateAccount(bankId) - val view = bankAccount.views_available.map(_.id).headOption.getOrElse("owner") + val view = bankAccount.views_available.map(_.id).headOption.getOrElse(Constant.SYSTEM_OWNER_VIEW_ID) val request310 = (v3_1_0_Request / "banks" / bankId / "accounts" / bankAccount.id / view / "transaction-requests").GET <@(user1) val response310 = makeGetRequest(request310) Then("We should get a 200") diff --git a/obp-api/src/test/scala/code/api/v3_1_0/TransactionTest.scala b/obp-api/src/test/scala/code/api/v3_1_0/TransactionTest.scala index 11ce2163f1..f67ddc6246 100644 --- a/obp-api/src/test/scala/code/api/v3_1_0/TransactionTest.scala +++ b/obp-api/src/test/scala/code/api/v3_1_0/TransactionTest.scala @@ -80,7 +80,7 @@ class TransactionTest extends V310ServerSetup { When("We make a request v3.1.0") val bankId = randomBankId val bankAccount = randomPrivateAccount(bankId) - val view = bankAccount.views_available.map(_.id).headOption.getOrElse("owner") + val view = bankAccount.views_available.map(_.id).headOption.getOrElse(SYSTEM_OWNER_VIEW_ID) val transaction = randomTransaction(bankId, bankAccount.id, view) val request310 = (v3_1_0_Request / "banks" / bankId / "accounts" / bankAccount.id / view / "transactions" / transaction.id / "transaction").GET val response310 = makeGetRequest(request310) @@ -93,7 +93,7 @@ class TransactionTest extends V310ServerSetup { When("We make a request v3.1.0") val bankId = randomBankId val bankAccount = randomPrivateAccount(bankId) - val view = bankAccount.views_available.map(_.id).headOption.getOrElse("owner") + val view = bankAccount.views_available.map(_.id).headOption.getOrElse(SYSTEM_OWNER_VIEW_ID) val transaction = randomTransaction(bankId, bankAccount.id, view) val request310 = (v3_1_0_Request / "banks" / bankId / "accounts" / bankAccount.id / view / "transactions" / transaction.id / "transaction").GET <@(user1) val response310 = makeGetRequest(request310) @@ -214,7 +214,7 @@ class TransactionTest extends V310ServerSetup { val counterpartyPostJSON = SwaggerDefinitionsJSON.postCounterpartyJSON.copy(other_bank_routing_address=bankId2,other_account_routing_address=bankAccountId2) When(s"We make the request Create counterparty for an account $ApiEndpoint5") - val requestPost = (v3_1_0_Request / "banks" / bankId1 / "accounts" / bankAccountId1 / "owner" / "counterparties" ).POST <@ (user1) + val requestPost = (v3_1_0_Request / "banks" / bankId1 / "accounts" / bankAccountId1 / SYSTEM_OWNER_VIEW_ID / "counterparties" ).POST <@ (user1) val responsePost = makePostRequest(requestPost, write(counterpartyPostJSON)) Then("We should get a 201 and check all the fields") @@ -286,7 +286,7 @@ class TransactionTest extends V310ServerSetup { val counterpartyPostJSON = SwaggerDefinitionsJSON.postCounterpartyJSON.copy(other_bank_routing_address=bankId1,other_account_routing_address=bankAccountId1) When(s"We make the request Create counterparty for an account $ApiEndpoint5") - val requestPost = (v3_1_0_Request / "banks" / bankId2 / "accounts" / bankAccountId2 / "owner" / "counterparties" ).POST <@ (user1) + val requestPost = (v3_1_0_Request / "banks" / bankId2 / "accounts" / bankAccountId2 / SYSTEM_OWNER_VIEW_ID / "counterparties" ).POST <@ (user1) val responsePost = makePostRequest(requestPost, write(counterpartyPostJSON)) Then("We should get a 201 and check all the fields") @@ -358,7 +358,7 @@ class TransactionTest extends V310ServerSetup { val counterpartyPostJsonFrom = SwaggerDefinitionsJSON.postCounterpartyJSON.copy(other_bank_routing_address=bankId1,other_account_routing_address=bankAccountId1) When(s"We make the request Create counterparty for an account $ApiEndpoint5") - val requestPostFrom = (v3_1_0_Request / "banks" / bankId1 / "accounts" / bankAccountId1 / "owner" / "counterparties" ).POST <@ (user1) + val requestPostFrom = (v3_1_0_Request / "banks" / bankId1 / "accounts" / bankAccountId1 / SYSTEM_OWNER_VIEW_ID / "counterparties" ).POST <@ (user1) val responsePostFrom = makePostRequest(requestPostFrom, write(counterpartyPostJsonFrom)) Then("We should get a 201 and check all the fields") @@ -371,7 +371,7 @@ class TransactionTest extends V310ServerSetup { val counterpartyPostJsonTo = SwaggerDefinitionsJSON.postCounterpartyJSON.copy(other_bank_routing_address=bankId2,other_account_routing_address=bankAccountId2) When(s"We make the request Create counterparty for an account $ApiEndpoint5") - val requestPostTo = (v3_1_0_Request / "banks" / bankId2 / "accounts" / bankAccountId2 / "owner" / "counterparties" ).POST <@ (user1) + val requestPostTo = (v3_1_0_Request / "banks" / bankId2 / "accounts" / bankAccountId2 / SYSTEM_OWNER_VIEW_ID / "counterparties" ).POST <@ (user1) val responsePostTo = makePostRequest(requestPostTo, write(counterpartyPostJsonTo)) Then("We should get a 201 and check all the fields") @@ -429,7 +429,7 @@ class TransactionTest extends V310ServerSetup { val counterpartyPostJSON = SwaggerDefinitionsJSON.postCounterpartyJSON.copy(other_bank_routing_address=bankId2,other_account_routing_address=bankAccountId2) When(s"We make the request Create counterparty for an account $ApiEndpoint5") - val requestPost = (v3_1_0_Request / "banks" / bankId1 / "accounts" / bankAccountId1 / "owner" / "counterparties" ).POST <@ (user1) + val requestPost = (v3_1_0_Request / "banks" / bankId1 / "accounts" / bankAccountId1 / SYSTEM_OWNER_VIEW_ID / "counterparties" ).POST <@ (user1) val responsePost = makePostRequest(requestPost, write(counterpartyPostJSON)) Then("We should get a 201 and check all the fields") diff --git a/obp-api/src/test/scala/code/api/v4_0_0/DeleteAccountCascadeTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/DeleteAccountCascadeTest.scala index 78eb5eba9f..54998c885d 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/DeleteAccountCascadeTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/DeleteAccountCascadeTest.scala @@ -1,5 +1,6 @@ package code.api.v4_0_0 +import code.api.Constant import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.createViewJsonV300 import code.api.util.APIUtil.OAuth._ @@ -87,7 +88,7 @@ class DeleteAccountCascadeTest extends V400ServerSetup { account.account_id, resourceUser2.userId, user1, - PostViewJsonV400(view_id = "owner", is_system = true) + PostViewJsonV400(view_id = Constant.SYSTEM_OWNER_VIEW_ID, is_system = true) ) createWebhookViaEndpoint( diff --git a/obp-api/src/test/scala/code/api/v4_0_0/DeleteBankCascadeTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/DeleteBankCascadeTest.scala index 6d65c160fa..5f03e7ee9e 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/DeleteBankCascadeTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/DeleteBankCascadeTest.scala @@ -1,5 +1,6 @@ package code.api.v4_0_0 +import code.api.Constant import java.util.concurrent.TimeUnit import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON @@ -98,7 +99,7 @@ class DeleteBankCascadeTest extends V400ServerSetup { account.account_id, resourceUser2.userId, user1, - PostViewJsonV400(view_id = "owner", is_system = true) + PostViewJsonV400(view_id = Constant.SYSTEM_OWNER_VIEW_ID, is_system = true) ) createWebhookViaEndpoint( diff --git a/obp-api/src/test/scala/code/api/v4_0_0/DoubleEntryTransactionTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/DoubleEntryTransactionTest.scala index dc467f2268..cdfc3e8dc2 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/DoubleEntryTransactionTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/DoubleEntryTransactionTest.scala @@ -1,5 +1,6 @@ package code.api.v4_0_0 +import code.api.Constant import code.api.util.APIUtil.OAuth._ import code.api.util.ApiRole import code.api.util.ErrorMessages.{UserHasMissingRoles, UserNoPermissionAccessView, UserNotLoggedIn} @@ -15,7 +16,7 @@ class DoubleEntryTransactionTest extends V400ServerSetup { lazy val testBankId: BankId = testBankId1 lazy val testAccountId: AccountId = testAccountId1 - lazy val view = "owner" + lazy val view = Constant.SYSTEM_OWNER_VIEW_ID /** * Test tags diff --git a/obp-api/src/test/scala/code/api/v4_0_0/TransactionAttributesTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/TransactionAttributesTest.scala index 0389d5f891..1780b64362 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/TransactionAttributesTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/TransactionAttributesTest.scala @@ -1,6 +1,6 @@ package code.api.v4_0_0 - +import code.api.Constant import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON import code.api.util.APIUtil.OAuth._ import code.api.util.ApiRole._ @@ -33,7 +33,7 @@ class TransactionAttributesTest extends V400ServerSetup { lazy val accountId = testAccountId1.value lazy val postTransactionAttributeJsonV400 = SwaggerDefinitionsJSON.transactionAttributeJsonV400 lazy val putTransactionAttributeJsonV400 = SwaggerDefinitionsJSON.transactionAttributeJsonV400.copy(name="test") - lazy val view = "owner" + lazy val view = Constant.SYSTEM_OWNER_VIEW_ID @@ -72,7 +72,7 @@ class TransactionAttributesTest extends V400ServerSetup { lazy val accountId = bankAccount.id lazy val postTransactionAttributeJsonV400 = SwaggerDefinitionsJSON.transactionAttributeJsonV400 lazy val putTransactionAttributeJsonV400 = SwaggerDefinitionsJSON.transactionAttributeJsonV400.copy(name="test") - lazy val view = bankAccount.views_available.map(_.id).headOption.getOrElse("owner") + lazy val view = bankAccount.views_available.map(_.id).headOption.getOrElse(Constant.SYSTEM_OWNER_VIEW_ID) lazy val transaction = randomTransactionViaEndpoint(bankId, bankAccount.id, view) lazy val transactionId = transaction.id diff --git a/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestAttributesTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestAttributesTest.scala index 2dcbd4b121..b4b56e5c7f 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestAttributesTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestAttributesTest.scala @@ -1,5 +1,6 @@ package code.api.v4_0_0 +import code.api.Constant import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON import code.api.util.APIUtil import code.api.util.APIUtil.OAuth._ @@ -20,7 +21,7 @@ class TransactionRequestAttributesTest extends V400ServerSetup { lazy val accountId = testAccountId1.value lazy val postTransactionRequestAttributeJsonV400 = SwaggerDefinitionsJSON.transactionRequestAttributeJsonV400 lazy val putTransactionRequestAttributeJsonV400 = SwaggerDefinitionsJSON.transactionRequestAttributeJsonV400.copy(name = "test") - lazy val view = "owner" + lazy val view = Constant.SYSTEM_OWNER_VIEW_ID /** * Test tags @@ -86,7 +87,7 @@ class TransactionRequestAttributesTest extends V400ServerSetup { lazy val accountId = bankAccount.id lazy val postTransactionRequestAttributeJsonV400 = SwaggerDefinitionsJSON.transactionRequestAttributeJsonV400 lazy val putTransactionRequestAttributeJsonV400 = SwaggerDefinitionsJSON.transactionRequestAttributeJsonV400.copy(name = "test") - lazy val view = bankAccount.views_available.map(_.id).headOption.getOrElse("owner") + lazy val view = bankAccount.views_available.map(_.id).headOption.getOrElse(Constant.SYSTEM_OWNER_VIEW_ID) lazy val transactionRequest = randomTransactionRequestViaEndpoint(bankId, bankAccount.id, view, user1) lazy val transactionRequestId = transactionRequest.id diff --git a/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestsTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestsTest.scala index b0789e2aba..7a09a0a2d2 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestsTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestsTest.scala @@ -1,5 +1,6 @@ package code.api.v4_0_0 +import code.api.Constant import java.util.{Date, UUID} import code.api.ChargePolicy import code.api.Constant._ @@ -1184,7 +1185,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers { helper.accountId1.value, resourceUser2.userId, user1, - PostViewJsonV400(view_id = "owner", is_system = true) + PostViewJsonV400(view_id = Constant.SYSTEM_OWNER_VIEW_ID, is_system = true) ) Then("we call the 'V400 Create Transaction Request' endpoint") @@ -1432,7 +1433,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers { helper.accountId1.value, resourceUser2.userId, user1, - PostViewJsonV400(view_id = "owner", is_system = true) + PostViewJsonV400(view_id = Constant.SYSTEM_OWNER_VIEW_ID, is_system = true) ) Then("we call the 'V400 Create Transaction Request' endpoint") @@ -1697,7 +1698,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers { helper.accountId1.value, resourceUser2.userId, user1, - PostViewJsonV400(view_id = "owner", is_system = true) + PostViewJsonV400(view_id = Constant.SYSTEM_OWNER_VIEW_ID, is_system = true) ) Then("we call the 'V400 Create Transaction Request' endpoint") @@ -1750,7 +1751,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers { lazy val bankId = testBankId1.value lazy val accountId = testAccountId1.value - lazy val view = "owner" + lazy val view = Constant.SYSTEM_OWNER_VIEW_ID scenario("We will call the endpoint WITHOUT user credentials", ApiEndpoint1, VersionOfApi) { diff --git a/obp-api/src/test/scala/code/api/v5_0_0/ConsentRequestTest.scala b/obp-api/src/test/scala/code/api/v5_0_0/ConsentRequestTest.scala index 22a87d247e..61ed28f991 100644 --- a/obp-api/src/test/scala/code/api/v5_0_0/ConsentRequestTest.scala +++ b/obp-api/src/test/scala/code/api/v5_0_0/ConsentRequestTest.scala @@ -25,6 +25,7 @@ TESOBE (http://www.tesobe.com/) */ package code.api.v5_0_0 +import code.api.Constant import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON import code.api.util.APIUtil.OAuth._ import code.api.util.ApiRole._ @@ -68,7 +69,7 @@ class ConsentRequestTest extends V500ServerSetupAsync with PropsReset{ lazy val accountAccess = List(AccountAccessV500( account_routing = AccountRoutingJsonV121( scheme = "AccountId", - address = testAccountId1.value), "owner")) + address = testAccountId1.value), Constant.SYSTEM_OWNER_VIEW_ID)) lazy val postConsentRequestJsonV310 = SwaggerDefinitionsJSON.postConsentRequestJsonV500 .copy(entitlements=Some(entitlements)) .copy(consumer_id=None) diff --git a/obp-api/src/test/scala/code/api/v5_1_0/ConsentsTest.scala b/obp-api/src/test/scala/code/api/v5_1_0/ConsentsTest.scala index afaff87370..4dc53a08ab 100644 --- a/obp-api/src/test/scala/code/api/v5_1_0/ConsentsTest.scala +++ b/obp-api/src/test/scala/code/api/v5_1_0/ConsentsTest.scala @@ -25,6 +25,7 @@ TESOBE (http://www.tesobe.com/) */ package code.api.v5_1_0 +import code.api.Constant import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON import code.api.util.APIUtil.OAuth._ import code.api.util.ApiRole._ @@ -70,7 +71,7 @@ class ConsentsTest extends V510ServerSetup with PropsReset{ lazy val accountAccess = List(AccountAccessV500( account_routing = AccountRoutingJsonV121( scheme = "AccountId", - address = testAccountId1.value), "owner")) + address = testAccountId1.value), Constant.SYSTEM_OWNER_VIEW_ID)) lazy val postConsentRequestJsonV310 = SwaggerDefinitionsJSON.postConsentRequestJsonV500 .copy(entitlements=Some(entitlements)) .copy(consumer_id=None) diff --git a/obp-api/src/test/scala/code/connector/MockedCbsConnector.scala b/obp-api/src/test/scala/code/connector/MockedCbsConnector.scala index 49f3220ead..eb2d39ec45 100644 --- a/obp-api/src/test/scala/code/connector/MockedCbsConnector.scala +++ b/obp-api/src/test/scala/code/connector/MockedCbsConnector.scala @@ -1,5 +1,6 @@ package code.connector +import code.api.Constant import code.api.Constant.SYSTEM_STANDARD_VIEW_ID import code.api.util.{CallContext, CustomJsonFormats} import code.bankconnectors._ @@ -38,7 +39,7 @@ object MockedCbsConnector extends ServerSetup balanceAmount = "", balanceCurrency = "", owners = List(""), - viewsToGenerate = SYSTEM_STANDARD_VIEW_ID :: "Owner" :: "_Public" :: "Accountant" :: "Auditor" :: Nil, + viewsToGenerate = SYSTEM_STANDARD_VIEW_ID :: Constant.SYSTEM_OWNER_VIEW_ID :: "_Public" :: "Accountant" :: "Auditor" :: Nil, bankRoutingScheme = "", bankRoutingAddress = "", branchRoutingScheme = "", @@ -54,7 +55,7 @@ object MockedCbsConnector extends ServerSetup balanceAmount = "", balanceCurrency = "", owners = List(""), - viewsToGenerate = SYSTEM_STANDARD_VIEW_ID :: "Owner" :: "_Public" :: "Accountant" :: "Auditor" :: Nil, + viewsToGenerate = SYSTEM_STANDARD_VIEW_ID :: Constant.SYSTEM_OWNER_VIEW_ID :: "_Public" :: "Accountant" :: "Auditor" :: Nil, bankRoutingScheme = "", bankRoutingAddress = "", branchRoutingScheme = "", diff --git a/obp-api/src/test/scala/code/views/MappedViewsTest.scala b/obp-api/src/test/scala/code/views/MappedViewsTest.scala index c530e1f857..16b8a6b988 100644 --- a/obp-api/src/test/scala/code/views/MappedViewsTest.scala +++ b/obp-api/src/test/scala/code/views/MappedViewsTest.scala @@ -1,5 +1,6 @@ package code.views +import code.api.Constant import code.api.util.ErrorMessages.ViewIdNotSupported import code.setup.{DefaultUsers, ServerSetup} import code.views.system.ViewDefinition @@ -20,7 +21,7 @@ class MappedViewsTest extends ServerSetup with DefaultUsers{ val bankIdAccountId = BankIdAccountId(BankId("1"),AccountId("2")) - val viewIdOwner = "owner" + val viewIdOwner = Constant.SYSTEM_OWNER_VIEW_ID val viewIdAccountant = "accountant" val viewIdAuditor = "auditor" val viewIdNotSupport = "NotSupport" @@ -37,7 +38,7 @@ class MappedViewsTest extends ServerSetup with DefaultUsers{ var allExistingViewsForOneAccount = MapperViews.availableViewsForAccount(bankIdAccountId) Then("Check the result from database. it should have 4 views and with the right viewId") - viewOwner.head.viewId.value should equal("owner".toLowerCase()) + viewOwner.head.viewId.value should equal(Constant.SYSTEM_OWNER_VIEW_ID.toLowerCase()) viewAccountant.head.viewId.value should equal("accountant".toLowerCase()) viewAuditor.head.viewId.value should equal("auditor".toLowerCase()) allExistingViewsForOneAccount.length should equal(3) @@ -49,7 +50,7 @@ class MappedViewsTest extends ServerSetup with DefaultUsers{ allExistingViewsForOneAccount = MapperViews.availableViewsForAccount(bankIdAccountId) Then("Check the result from database again. it should have four views and with the right viewId, there should be not changed.") - viewOwner.head.viewId.value should equal("owner".toLowerCase()) + viewOwner.head.viewId.value should equal(Constant.SYSTEM_OWNER_VIEW_ID.toLowerCase()) viewAccountant.head.viewId.value should equal("accountant".toLowerCase()) viewAuditor.head.viewId.value should equal("auditor".toLowerCase()) allExistingViewsForOneAccount.length should equal(3) From 13d2b7ae146bf34f596ad4ef41b981a07316f811 Mon Sep 17 00:00:00 2001 From: hongwei Date: Tue, 18 Jun 2024 09:34:31 +0200 Subject: [PATCH 14/23] refactor/set the default limit = 50 --- obp-api/src/main/scala/code/api/constant/constant.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/obp-api/src/main/scala/code/api/constant/constant.scala b/obp-api/src/main/scala/code/api/constant/constant.scala index 4d7df1a2ef..69ac481743 100644 --- a/obp-api/src/main/scala/code/api/constant/constant.scala +++ b/obp-api/src/main/scala/code/api/constant/constant.scala @@ -13,7 +13,7 @@ object Constant extends MdcLoggable { object Pagination { final val offset = 0 - final val limit = 500 + final val limit = 50 } final val shortEndpointTimeoutInMillis = APIUtil.getPropsAsLongValue(nameOfProperty = "short_endpoint_timeout", 1L * 1000L) From b2ee741e5981624aa289b4d94be176cd976269f4 Mon Sep 17 00:00:00 2001 From: hongwei Date: Mon, 1 Jul 2024 12:09:22 +0200 Subject: [PATCH 15/23] feature/added new connector method validateChallengeAnswer2 --- obp-api/src/main/scala/code/api/util/NewStyle.scala | 9 ++++----- .../src/main/scala/code/api/v2_1_0/APIMethods210.scala | 5 ++--- .../src/main/scala/code/api/v4_0_0/APIMethods400.scala | 6 +++--- .../src/main/scala/code/bankconnectors/Connector.scala | 5 ++++- .../code/bankconnectors/LocalMappedConnector.scala | 8 ++++++++ .../openbankproject/commons/dto/JsonsTransfer.scala | 10 ++++++++++ .../commons/model/enums/Enumerations.scala | 7 +++++++ 7 files changed, 38 insertions(+), 12 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/NewStyle.scala b/obp-api/src/main/scala/code/api/util/NewStyle.scala index c895a84a40..f4fe46cf4a 100644 --- a/obp-api/src/main/scala/code/api/util/NewStyle.scala +++ b/obp-api/src/main/scala/code/api/util/NewStyle.scala @@ -3,7 +3,6 @@ package code.api.util import java.util.Date import java.util.UUID.randomUUID - import akka.http.scaladsl.model.HttpMethod import code.DynamicEndpoint.{DynamicEndpointProvider, DynamicEndpointT} import code.api.{APIFailureNewStyle, Constant, JsonResponseException} @@ -54,8 +53,8 @@ import net.liftweb.json.JsonDSL._ import net.liftweb.json.{JField, JInt, JNothing, JNull, JObject, JString, JValue, _} import net.liftweb.util.Helpers.tryo import org.apache.commons.lang3.StringUtils -import java.security.AccessControlException +import java.security.AccessControlException import scala.collection.immutable.{List, Nil} import scala.concurrent.Future import scala.math.BigDecimal @@ -80,6 +79,7 @@ import code.endpointMapping.{EndpointMappingProvider, EndpointMappingT} import code.endpointTag.EndpointTagT import code.util.Helper.MdcLoggable import code.views.system.AccountAccess +import com.openbankproject.commons.model.enums.SuppliedAnswerType.SuppliedAnswerType import net.liftweb.mapper.By object NewStyle extends MdcLoggable{ @@ -1302,9 +1302,8 @@ object NewStyle extends MdcLoggable{ } } - - def validateChallengeAnswer(challengeId: String, hashOfSuppliedAnswer: String, callContext: Option[CallContext]): OBPReturnType[Boolean] = - Connector.connector.vend.validateChallengeAnswer(challengeId: String, hashOfSuppliedAnswer: String, callContext: Option[CallContext]) map { i => + def validateChallengeAnswer(challengeId: String, suppliedAnswer: String, suppliedAnswerType:SuppliedAnswerType, callContext: Option[CallContext]): OBPReturnType[Boolean] = + Connector.connector.vend.validateChallengeAnswerV2(challengeId, suppliedAnswer, suppliedAnswerType, callContext) map { i => (unboxFullOrFail(i._1, callContext, s"${ InvalidChallengeAnswer .replace("answer may be expired.", s"answer may be expired (${transactionRequestChallengeTtl} seconds).") diff --git a/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala b/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala index 0de30b8d51..d778fef126 100644 --- a/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala +++ b/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala @@ -1,7 +1,6 @@ package code.api.v2_1_0 import java.util.Date - import code.TransactionTypes.TransactionType import code.api.util import code.api.util.ApiTag._ @@ -32,7 +31,7 @@ import code.util.Helper.booleanToBox import code.views.Views import code.views.system.ViewDefinition import com.openbankproject.commons.model._ -import com.openbankproject.commons.model.enums.ChallengeType +import com.openbankproject.commons.model.enums.{ChallengeType, SuppliedAnswerType} import com.openbankproject.commons.util.ApiVersion import net.liftweb.json.Extraction import net.liftweb.util.Helpers.tryo @@ -681,7 +680,7 @@ trait APIMethods210 { existingTransactionRequest.challenge.challenge_type == ChallengeType.OBP_TRANSACTION_REQUEST_CHALLENGE.toString } - (isChallengeAnswerValidated, callContext) <- NewStyle.function.validateChallengeAnswer(challengeAnswerJson.id, challengeAnswerJson.answer, callContext) + (isChallengeAnswerValidated, callContext) <- NewStyle.function.validateChallengeAnswer(challengeAnswerJson.id, challengeAnswerJson.answer, SuppliedAnswerType.PLAIN_TEXT_VALUE, callContext) _ <- Helper.booleanToFuture(s"${InvalidChallengeAnswer .replace("answer may be expired.", s"answer may be expired (${transactionRequestChallengeTtl} seconds).") 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 b548ca5635..9ec03fc57f 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 @@ -86,7 +86,7 @@ import com.openbankproject.commons.dto.GetProductsParam import com.openbankproject.commons.model.enums.ChallengeType.OBP_TRANSACTION_REQUEST_CHALLENGE import com.openbankproject.commons.model.enums.DynamicEntityOperation._ import com.openbankproject.commons.model.enums.{TransactionRequestStatus, _} -import com.openbankproject.commons.model.{ListResult, _} +import com.openbankproject.commons.model._ import com.openbankproject.commons.util.{ApiVersion, JsonUtils, ScannedApiVersion} import deletion._ import net.liftweb.common._ @@ -95,7 +95,7 @@ import net.liftweb.http.{JsonResponse, Req, S} import net.liftweb.json.JsonAST.JValue import net.liftweb.json.JsonDSL._ import net.liftweb.json.Serialization.write -import net.liftweb.json.{compactRender, prettyRender, _} +import net.liftweb.json._ import net.liftweb.mapper.By import net.liftweb.util.Helpers.{now, tryo} import net.liftweb.util.Mailer.{From, PlainMailBodyType, Subject, To, XHTMLMailBodyType} @@ -1637,7 +1637,7 @@ trait APIMethods400 extends MdcLoggable { case _ => for { - (challengeAnswerIsValidated, callContext) <- NewStyle.function.validateChallengeAnswer(challengeAnswerJson.id, challengeAnswerJson.answer, callContext) + (challengeAnswerIsValidated, callContext) <- NewStyle.function.validateChallengeAnswer(challengeAnswerJson.id, challengeAnswerJson.answer, SuppliedAnswerType.PLAIN_TEXT_VALUE,callContext) _ <- Helper.booleanToFuture(s"${InvalidChallengeAnswer .replace("answer may be expired.",s"answer may be expired (${transactionRequestChallengeTtl} seconds).") diff --git a/obp-api/src/main/scala/code/bankconnectors/Connector.scala b/obp-api/src/main/scala/code/bankconnectors/Connector.scala index 5883cef31d..3882591449 100644 --- a/obp-api/src/main/scala/code/bankconnectors/Connector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/Connector.scala @@ -2,7 +2,6 @@ package code.bankconnectors import java.util.Date import java.util.UUID.randomUUID - import _root_.akka.http.scaladsl.model.HttpMethod import code.accountholders.{AccountHolders, MapperAccountHolders} import code.api.Constant.{SYSTEM_ACCOUNTANT_VIEW_ID, SYSTEM_AUDITOR_VIEW_ID, SYSTEM_OWNER_VIEW_ID, localIdentityProvider} @@ -42,6 +41,7 @@ import com.openbankproject.commons.ExecutionContext.Implicits.global import com.openbankproject.commons.dto.{CustomerAndAttribute, GetProductsParam, InBoundTrait, ProductCollectionItemsTree} import com.openbankproject.commons.model.enums.StrongCustomerAuthentication.SCA import com.openbankproject.commons.model.enums.StrongCustomerAuthenticationStatus.SCAStatus +import com.openbankproject.commons.model.enums.SuppliedAnswerType.SuppliedAnswerType import com.openbankproject.commons.model.enums._ import com.openbankproject.commons.model.{AccountApplication, Bank, CounterpartyTrait, CustomerAddress, DirectDebitTrait, FXRate, Product, ProductCollection, ProductCollectionItem, TaxResidence, TransactionRequestStatus, TransactionRequestTypeCharge, UserAuthContext, UserAuthContextUpdate, _} import com.openbankproject.commons.util.Functions.lazyValue @@ -435,8 +435,11 @@ trait Connector extends MdcLoggable { callContext: Option[CallContext]) : OBPReturnType[Box[List[ChallengeTrait]]]= Future{(Failure(setUnimplementedError), callContext)} // Validates an answer for a challenge and returns if the answer is correct or not + @deprecated("Please use @validateChallengeAnswerV2 instead ","01.07.2024") def validateChallengeAnswer(challengeId: String, hashOfSuppliedAnswer: String, callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] = Future{(Full(true), callContext)} + def validateChallengeAnswerV2(challengeId: String, suppliedAnswer: String, suppliedAnswerType:SuppliedAnswerType, callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] = Future{(Full(true), callContext)} + def allChallengesSuccessfullyAnswered( bankId: BankId, accountId: AccountId, diff --git a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala index e73eaecc0b..8cdcbf285d 100644 --- a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala @@ -80,6 +80,7 @@ import com.openbankproject.commons.model.enums.ChallengeType.OBP_TRANSACTION_REQ import com.openbankproject.commons.model.enums.DynamicEntityOperation._ import com.openbankproject.commons.model.enums.StrongCustomerAuthentication.SCA import com.openbankproject.commons.model.enums.StrongCustomerAuthenticationStatus.SCAStatus +import com.openbankproject.commons.model.enums.SuppliedAnswerType.SuppliedAnswerType import com.openbankproject.commons.model.enums.{TransactionRequestStatus, _} import com.openbankproject.commons.model.{AccountApplication, AccountAttribute, ConsentImplicitSCAT, DirectDebitTrait, FXRate, Product, ProductAttribute, ProductCollectionItem, TaxResidence, TransactionRequestCommonBodyJSON, _} import com.tesobe.CacheKeyFromArguments @@ -485,6 +486,13 @@ object LocalMappedConnector extends Connector with MdcLoggable { override def getChallenge(challengeId: String, callContext: Option[CallContext]): OBPReturnType[Box[ChallengeTrait]] = Future {(Challenges.ChallengeProvider.vend.getChallenge(challengeId), callContext)} + override def validateChallengeAnswerV2(challengeId: String, suppliedAnswer: String, suppliedAnswerType:SuppliedAnswerType, callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] = + Future { + val userId = callContext.map(_.user.map(_.userId).openOrThrowException(s"$UserNotLoggedIn Can not find the userId here.")) + //In OBP, we only validateChallenge with SuppliedAnswerType.PLAN_TEXT, + (Full(Challenges.ChallengeProvider.vend.validateChallenge(challengeId, suppliedAnswer, userId).isDefined), callContext) + } + override def validateChallengeAnswer(challengeId: String, hashOfSuppliedAnswer: String, callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] = Future { val userId = callContext.map(_.user.map(_.userId).openOrThrowException(s"$UserNotLoggedIn Can not find the userId here.")) diff --git a/obp-commons/src/main/scala/com/openbankproject/commons/dto/JsonsTransfer.scala b/obp-commons/src/main/scala/com/openbankproject/commons/dto/JsonsTransfer.scala index 1fee77e881..321ebabd4b 100644 --- a/obp-commons/src/main/scala/com/openbankproject/commons/dto/JsonsTransfer.scala +++ b/obp-commons/src/main/scala/com/openbankproject/commons/dto/JsonsTransfer.scala @@ -859,6 +859,16 @@ case class InBoundValidateChallengeAnswer(inboundAdapterCallContext: InboundAdap status: Status, data: Boolean) extends InBoundTrait[Boolean] + +case class OutBoundValidateChallengeAnswerV2(outboundAdapterCallContext: OutboundAdapterCallContext, + challengeId: String, + suppliedAnswer: String, + suppliedAnswerType: String) extends TopicTrait + +case class InBoundValidateChallengeAnswerV2(inboundAdapterCallContext: InboundAdapterCallContext, + status: Status, + data: Boolean) extends InBoundTrait[Boolean] + //--------------------- diff --git a/obp-commons/src/main/scala/com/openbankproject/commons/model/enums/Enumerations.scala b/obp-commons/src/main/scala/com/openbankproject/commons/model/enums/Enumerations.scala index 35bd148f68..ffcad90bad 100644 --- a/obp-commons/src/main/scala/com/openbankproject/commons/model/enums/Enumerations.scala +++ b/obp-commons/src/main/scala/com/openbankproject/commons/model/enums/Enumerations.scala @@ -229,6 +229,13 @@ object AttributeCategory extends OBPEnumeration[AttributeCategory]{ object TransactionRequest extends Value } + +object SuppliedAnswerType extends Enumeration { + type SuppliedAnswerType = Value + val PLAIN_TEXT_VALUE, HASH_VALUE = Value +} + + object TransactionRequestStatus extends Enumeration { type TransactionRequestStatus = Value val INITIATED, PENDING, NEXT_CHALLENGE_PENDING, FAILED, COMPLETED, FORWARDED, REJECTED, CANCELLED, CANCELLATION_PENDING = Value From 867e15b78d195bc74daadab7e0cb82a34713b15c Mon Sep 17 00:00:00 2001 From: Hongwei Date: Mon, 1 Jul 2024 13:39:49 +0200 Subject: [PATCH 16/23] feature/added new connector method validateChallengeAnswer2- step2 --- obp-api/src/main/scala/code/api/util/NewStyle.scala | 7 +++++-- .../src/main/scala/code/bankconnectors/Connector.scala | 4 ++-- .../scala/code/bankconnectors/ConnectorBuilderUtil.scala | 1 + .../scala/code/bankconnectors/LocalMappedConnector.scala | 2 +- .../com/openbankproject/commons/dto/JsonsTransfer.scala | 5 +++-- .../commons/model/enums/Enumerations.scala | 8 ++++---- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/NewStyle.scala b/obp-api/src/main/scala/code/api/util/NewStyle.scala index f4fe46cf4a..fad386d52b 100644 --- a/obp-api/src/main/scala/code/api/util/NewStyle.scala +++ b/obp-api/src/main/scala/code/api/util/NewStyle.scala @@ -79,7 +79,7 @@ import code.endpointMapping.{EndpointMappingProvider, EndpointMappingT} import code.endpointTag.EndpointTagT import code.util.Helper.MdcLoggable import code.views.system.AccountAccess -import com.openbankproject.commons.model.enums.SuppliedAnswerType.SuppliedAnswerType +import com.openbankproject.commons.model.enums.SuppliedAnswerType import net.liftweb.mapper.By object NewStyle extends MdcLoggable{ @@ -1302,7 +1302,7 @@ object NewStyle extends MdcLoggable{ } } - def validateChallengeAnswer(challengeId: String, suppliedAnswer: String, suppliedAnswerType:SuppliedAnswerType, callContext: Option[CallContext]): OBPReturnType[Boolean] = + def validateChallengeAnswer(challengeId: String, suppliedAnswer: String, suppliedAnswerType:SuppliedAnswerType.Value, callContext: Option[CallContext]): OBPReturnType[Boolean] = Connector.connector.vend.validateChallengeAnswerV2(challengeId, suppliedAnswer, suppliedAnswerType, callContext) map { i => (unboxFullOrFail(i._1, callContext, s"${ InvalidChallengeAnswer @@ -1331,6 +1331,7 @@ object NewStyle extends MdcLoggable{ (unboxFullOrFail(i._1, callContext, s"$InvalidConnectorResponse() "), i._2) } + //At moment this method is used for Berlin Group Payments def validateChallengeAnswerC2( challengeType: ChallengeType.Value, transactionRequestId: Option[String], @@ -1359,6 +1360,8 @@ object NewStyle extends MdcLoggable{ } } } + + //At moment this method is used for Berlin Group SigningBasketsApi.scala def validateChallengeAnswerC3( challengeType: ChallengeType.Value, transactionRequestId: Option[String], diff --git a/obp-api/src/main/scala/code/bankconnectors/Connector.scala b/obp-api/src/main/scala/code/bankconnectors/Connector.scala index 3882591449..d3f741354e 100644 --- a/obp-api/src/main/scala/code/bankconnectors/Connector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/Connector.scala @@ -41,7 +41,7 @@ import com.openbankproject.commons.ExecutionContext.Implicits.global import com.openbankproject.commons.dto.{CustomerAndAttribute, GetProductsParam, InBoundTrait, ProductCollectionItemsTree} import com.openbankproject.commons.model.enums.StrongCustomerAuthentication.SCA import com.openbankproject.commons.model.enums.StrongCustomerAuthenticationStatus.SCAStatus -import com.openbankproject.commons.model.enums.SuppliedAnswerType.SuppliedAnswerType +import com.openbankproject.commons.model.enums.SuppliedAnswerType import com.openbankproject.commons.model.enums._ import com.openbankproject.commons.model.{AccountApplication, Bank, CounterpartyTrait, CustomerAddress, DirectDebitTrait, FXRate, Product, ProductCollection, ProductCollectionItem, TaxResidence, TransactionRequestStatus, TransactionRequestTypeCharge, UserAuthContext, UserAuthContextUpdate, _} import com.openbankproject.commons.util.Functions.lazyValue @@ -438,7 +438,7 @@ trait Connector extends MdcLoggable { @deprecated("Please use @validateChallengeAnswerV2 instead ","01.07.2024") def validateChallengeAnswer(challengeId: String, hashOfSuppliedAnswer: String, callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] = Future{(Full(true), callContext)} - def validateChallengeAnswerV2(challengeId: String, suppliedAnswer: String, suppliedAnswerType:SuppliedAnswerType, callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] = Future{(Full(true), callContext)} + def validateChallengeAnswerV2(challengeId: String, suppliedAnswer: String, suppliedAnswerType:SuppliedAnswerType.Value, callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] = Future{(Full(true), callContext)} def allChallengesSuccessfullyAnswered( bankId: BankId, diff --git a/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala b/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala index 033b33302d..95d7d4ed9f 100644 --- a/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala +++ b/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala @@ -373,6 +373,7 @@ object ConnectorBuilderUtil { "validateAndCheckIbanNumber", "validateChallengeAnswerC2", "validateChallengeAnswerC3", + "validateChallengeAnswerV2", "getCounterpartyByIbanAndBankAccountId", ).distinct diff --git a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala index 8cdcbf285d..aa30a7834a 100644 --- a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala @@ -80,7 +80,7 @@ import com.openbankproject.commons.model.enums.ChallengeType.OBP_TRANSACTION_REQ import com.openbankproject.commons.model.enums.DynamicEntityOperation._ import com.openbankproject.commons.model.enums.StrongCustomerAuthentication.SCA import com.openbankproject.commons.model.enums.StrongCustomerAuthenticationStatus.SCAStatus -import com.openbankproject.commons.model.enums.SuppliedAnswerType.SuppliedAnswerType +import com.openbankproject.commons.model.enums.SuppliedAnswerType import com.openbankproject.commons.model.enums.{TransactionRequestStatus, _} import com.openbankproject.commons.model.{AccountApplication, AccountAttribute, ConsentImplicitSCAT, DirectDebitTrait, FXRate, Product, ProductAttribute, ProductCollectionItem, TaxResidence, TransactionRequestCommonBodyJSON, _} import com.tesobe.CacheKeyFromArguments diff --git a/obp-commons/src/main/scala/com/openbankproject/commons/dto/JsonsTransfer.scala b/obp-commons/src/main/scala/com/openbankproject/commons/dto/JsonsTransfer.scala index 321ebabd4b..bb1b3f63fa 100644 --- a/obp-commons/src/main/scala/com/openbankproject/commons/dto/JsonsTransfer.scala +++ b/obp-commons/src/main/scala/com/openbankproject/commons/dto/JsonsTransfer.scala @@ -27,9 +27,10 @@ TESOBE (http://www.tesobe.com/) package com.openbankproject.commons.dto import java.util.Date -import com.openbankproject.commons.model.enums.{CardAttributeType, ChallengeType, CustomerAttributeType, DynamicEntityOperation, StrongCustomerAuthentication, TransactionAttributeType, TransactionRequestStatus} +import com.openbankproject.commons.model.enums.{CardAttributeType, ChallengeType, CustomerAttributeType, DynamicEntityOperation, StrongCustomerAuthentication, SuppliedAnswerType, TransactionAttributeType, TransactionRequestStatus} import com.openbankproject.commons.model.enums.StrongCustomerAuthentication.SCA import com.openbankproject.commons.model.enums.StrongCustomerAuthenticationStatus.SCAStatus +import com.openbankproject.commons.model.enums.SuppliedAnswerType import com.openbankproject.commons.model.{enums, _} import net.liftweb.json.{JObject, JValue} @@ -863,7 +864,7 @@ case class InBoundValidateChallengeAnswer(inboundAdapterCallContext: InboundAdap case class OutBoundValidateChallengeAnswerV2(outboundAdapterCallContext: OutboundAdapterCallContext, challengeId: String, suppliedAnswer: String, - suppliedAnswerType: String) extends TopicTrait + suppliedAnswerType: SuppliedAnswerType) extends TopicTrait case class InBoundValidateChallengeAnswerV2(inboundAdapterCallContext: InboundAdapterCallContext, status: Status, diff --git a/obp-commons/src/main/scala/com/openbankproject/commons/model/enums/Enumerations.scala b/obp-commons/src/main/scala/com/openbankproject/commons/model/enums/Enumerations.scala index ffcad90bad..b23ae9b95c 100644 --- a/obp-commons/src/main/scala/com/openbankproject/commons/model/enums/Enumerations.scala +++ b/obp-commons/src/main/scala/com/openbankproject/commons/model/enums/Enumerations.scala @@ -229,10 +229,10 @@ object AttributeCategory extends OBPEnumeration[AttributeCategory]{ object TransactionRequest extends Value } - -object SuppliedAnswerType extends Enumeration { - type SuppliedAnswerType = Value - val PLAIN_TEXT_VALUE, HASH_VALUE = Value +sealed trait SuppliedAnswerType extends EnumValue +object SuppliedAnswerType extends OBPEnumeration[SuppliedAnswerType]{ + object PLAIN_TEXT_VALUE extends Value + object HASH_VALUE extends Value } From a2b48b1a2d4215e86ebaa79cb9e676f30cfd447f Mon Sep 17 00:00:00 2001 From: Hongwei Date: Mon, 1 Jul 2024 13:40:47 +0200 Subject: [PATCH 17/23] feature/added new connector method validateChallengeAnswer2- step3 --- .../StoredProcedureConnector_vDec2019.scala | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureConnector_vDec2019.scala b/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureConnector_vDec2019.scala index 8b21fe9254..b5468c3e7b 100644 --- a/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureConnector_vDec2019.scala +++ b/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureConnector_vDec2019.scala @@ -75,7 +75,7 @@ trait StoredProcedureConnector_vDec2019 extends Connector with MdcLoggable { val connectorName = "stored_procedure_vDec2019" //---------------- dynamic start -------------------please don't modify this line -// ---------- created on 2024-06-12T14:42:25Z +// ---------- created on 2024-07-01T13:40:08Z messageDocs += getAdapterInfoDoc def getAdapterInfoDoc = MessageDoc( @@ -434,6 +434,34 @@ trait StoredProcedureConnector_vDec2019 extends Connector with MdcLoggable { response.map(convertToTuple[Boolean](callContext)) } + messageDocs += validateChallengeAnswerV2Doc + def validateChallengeAnswerV2Doc = MessageDoc( + process = "obp.validateChallengeAnswerV2", + messageFormat = messageFormat, + description = "Validate Challenge Answer V2", + outboundTopic = None, + inboundTopic = None, + exampleOutboundMessage = ( + OutBoundValidateChallengeAnswerV2(outboundAdapterCallContext=MessageDocsSwaggerDefinitions.outboundAdapterCallContext, + challengeId=challengeIdExample.value, + suppliedAnswer="string", + suppliedAnswerType=com.openbankproject.commons.model.enums.SuppliedAnswerType.example) + ), + exampleInboundMessage = ( + InBoundValidateChallengeAnswerV2(inboundAdapterCallContext=MessageDocsSwaggerDefinitions.inboundAdapterCallContext, + status=MessageDocsSwaggerDefinitions.inboundStatus, + data=true) + ), + adapterImplementation = Some(AdapterImplementation("- Core", 1)) + ) + + override def validateChallengeAnswerV2(challengeId: String, suppliedAnswer: String, suppliedAnswerType: SuppliedAnswerType.Value, callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] = { + import com.openbankproject.commons.dto.{InBoundValidateChallengeAnswerV2 => InBound, OutBoundValidateChallengeAnswerV2 => OutBound} + val req = OutBound(callContext.map(_.toOutboundAdapterCallContext).orNull, challengeId, suppliedAnswer, suppliedAnswerType) + val response: Future[Box[InBound]] = sendRequest[InBound]("obp_validate_challenge_answer_v2", req, callContext) + response.map(convertToTuple[Boolean](callContext)) + } + messageDocs += validateChallengeAnswerC2Doc def validateChallengeAnswerC2Doc = MessageDoc( process = "obp.validateChallengeAnswerC2", @@ -6624,8 +6652,8 @@ trait StoredProcedureConnector_vDec2019 extends Connector with MdcLoggable { response.map(convertToTuple[Boolean](callContext)) } -// ---------- created on 2024-06-12T14:42:25Z -//---------------- dynamic end ---------------------please don't modify this line +// ---------- created on 2024-07-01T13:40:08Z +//---------------- dynamic end ---------------------please don't modify this line private val availableOperation = DynamicEntityOperation.values.map(it => s""""$it"""").mkString("[", ", ", "]") From 0c68b19816965caba37e333916894e7cbad8f826 Mon Sep 17 00:00:00 2001 From: hongwei Date: Tue, 2 Jul 2024 12:14:00 +0200 Subject: [PATCH 18/23] refactor/update the pom java and plugin version --- obp-api/pom.xml | 4 ++-- pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/obp-api/pom.xml b/obp-api/pom.xml index 3fdc02716d..d6041cd5b1 100644 --- a/obp-api/pom.xml +++ b/obp-api/pom.xml @@ -552,7 +552,7 @@ org.apache.maven.plugins maven-war-plugin - 2.6 + 3.4.0 ${webXmlPath} @@ -639,7 +639,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.13.0 ${java.version} diff --git a/pom.xml b/pom.xml index b8f7e7923f..a0fb316aae 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ http://scala-tools.org/mvnsites/liftweb - 8 + 11 ${java.version} ${java.version} From aa64b7cca7b9f1ddaf0fa354bfb50882f21b697d Mon Sep 17 00:00:00 2001 From: Hongwei Date: Tue, 2 Jul 2024 14:13:27 +0200 Subject: [PATCH 19/23] feature/added canGetCustomView permission --- .../main/scala/code/api/v5_1_0/APIMethods510.scala | 4 ++-- .../scala/code/model/dataAccess/MappedView.scala | 4 ++++ obp-api/src/main/scala/code/views/MapperViews.scala | 12 ++++++++---- .../scala/code/views/system/ViewDefinition.scala | 4 ++++ .../test/scala/code/api/v5_1_0/CustomViewTest.scala | 10 +++++----- .../openbankproject/commons/model/ViewModel.scala | 1 + 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala b/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala index 7d1c52012e..721fe5a14a 100644 --- a/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala +++ b/obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala @@ -2665,9 +2665,9 @@ trait APIMethods510 { _ <- Helper.booleanToFuture(failMsg = InvalidCustomViewFormat + s"Current TARGET_VIEW_ID (${targetViewId.value})", cc = callContext) { isValidCustomViewId(targetViewId.value) } - failmsg = s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(view.canSeeAvailableViewsForBankAccount))}`permission on any your views. Current VIEW_ID (${viewId.value})" + failmsg = s"${ErrorMessages.ViewDoesNotPermitAccess} You need the `${StringHelpers.snakify(nameOf(view.canGetCustomView))}`permission on any your views. Current VIEW_ID (${viewId.value})" _ <- Helper.booleanToFuture(failmsg, cc = callContext) { - view.canSeeAvailableViewsForBankAccount + view.canGetCustomView } targetView <- NewStyle.function.customView(targetViewId, BankIdAccountId(bankId, accountId), callContext) } yield { diff --git a/obp-api/src/main/scala/code/model/dataAccess/MappedView.scala b/obp-api/src/main/scala/code/model/dataAccess/MappedView.scala index b949ab4cb6..c5c3c156b8 100644 --- a/obp-api/src/main/scala/code/model/dataAccess/MappedView.scala +++ b/obp-api/src/main/scala/code/model/dataAccess/MappedView.scala @@ -454,6 +454,9 @@ class ViewImpl extends View with LongKeyedMapper[ViewImpl] with ManyToMany with object canUpdateCustomView_ extends MappedBoolean(this){ override def defaultValue = false } + object canGetCustomView_ extends MappedBoolean(this){ + override def defaultValue = false + } object canRevokeAccessToCustomViews_ extends MappedBoolean(this) { override def defaultValue = false } @@ -582,6 +585,7 @@ class ViewImpl extends View with LongKeyedMapper[ViewImpl] with ManyToMany with def canCreateCustomView: Boolean = canCreateCustomView_.get def canDeleteCustomView: Boolean = canDeleteCustomView_.get def canUpdateCustomView: Boolean = canUpdateCustomView_.get + def canGetCustomView: Boolean = canGetCustomView_.get override def canGrantAccessToCustomViews: Boolean = canGrantAccessToCustomViews_.get override def canRevokeAccessToCustomViews: Boolean = canRevokeAccessToCustomViews_.get diff --git a/obp-api/src/main/scala/code/views/MapperViews.scala b/obp-api/src/main/scala/code/views/MapperViews.scala index 1fe2549b79..41144c9c57 100644 --- a/obp-api/src/main/scala/code/views/MapperViews.scala +++ b/obp-api/src/main/scala/code/views/MapperViews.scala @@ -720,6 +720,7 @@ object MapperViews extends Views with MdcLoggable { "canCreateCustomView", "canDeleteCustomView", "canUpdateCustomView", + "canGetCustomView", "canSeeViewsWithPermissionsForAllUsers", "canSeeViewsWithPermissionsForOneUser" ) @@ -912,9 +913,6 @@ object MapperViews extends Views with MdcLoggable { .canSeeTransactionRequests_(false) .canSeeTransactionRequestTypes_(false) .canUpdateBankAccountLabel_(false) - .canCreateCustomView_(false) - .canDeleteCustomView_(false) - .canUpdateCustomView_(false) .canSeeViewsWithPermissionsForOneUser_(false) .canSeeViewsWithPermissionsForAllUsers_(false) .canRevokeAccessToCustomViews_(false) @@ -922,6 +920,7 @@ object MapperViews extends Views with MdcLoggable { .canCreateCustomView_(false) .canDeleteCustomView_(false) .canUpdateCustomView_(false) + .canGetCustomView_(false) viewId match { case SYSTEM_OWNER_VIEW_ID | SYSTEM_STANDARD_VIEW_ID => @@ -945,6 +944,7 @@ object MapperViews extends Views with MdcLoggable { .canCreateCustomView_(true) .canDeleteCustomView_(true) .canUpdateCustomView_(true) + .canGetCustomView_(true) case SYSTEM_FIREHOSE_VIEW_ID => entity .isFirehose_(true) @@ -1046,7 +1046,11 @@ object MapperViews extends Views with MdcLoggable { canAddTransactionRequestToAnyAccount_(false). canSeeTransactionRequests_(false). canSeeTransactionRequestTypes_(false). - canUpdateBankAccountLabel_(false) + canUpdateBankAccountLabel_(false). + canCreateCustomView_(false). + canDeleteCustomView_(false). + canUpdateCustomView_(false). + canGetCustomView_(false) } def createAndSaveDefaultPublicCustomView(bankId : BankId, accountId: AccountId, description: String) : Box[View] = { diff --git a/obp-api/src/main/scala/code/views/system/ViewDefinition.scala b/obp-api/src/main/scala/code/views/system/ViewDefinition.scala index 336f03a69d..287f716ff9 100644 --- a/obp-api/src/main/scala/code/views/system/ViewDefinition.scala +++ b/obp-api/src/main/scala/code/views/system/ViewDefinition.scala @@ -325,6 +325,9 @@ class ViewDefinition extends View with LongKeyedMapper[ViewDefinition] with Many object canUpdateCustomView_ extends MappedBoolean(this){ override def defaultValue = false } + object canGetCustomView_ extends MappedBoolean(this){ + override def defaultValue = false + } object canSeeViewsWithPermissionsForAllUsers_ extends MappedBoolean(this){ override def defaultValue = false } @@ -591,6 +594,7 @@ class ViewDefinition extends View with LongKeyedMapper[ViewDefinition] with Many def canCreateCustomView: Boolean = canCreateCustomView_.get def canDeleteCustomView: Boolean = canDeleteCustomView_.get def canUpdateCustomView: Boolean = canUpdateCustomView_.get + def canGetCustomView: Boolean = canGetCustomView_.get //TODO: if you add new permissions here, remember to set them wherever views are created // (e.g. BankAccountCreationDispatcher) } diff --git a/obp-api/src/test/scala/code/api/v5_1_0/CustomViewTest.scala b/obp-api/src/test/scala/code/api/v5_1_0/CustomViewTest.scala index 2c03414fb1..1b081ba302 100644 --- a/obp-api/src/test/scala/code/api/v5_1_0/CustomViewTest.scala +++ b/obp-api/src/test/scala/code/api/v5_1_0/CustomViewTest.scala @@ -134,12 +134,12 @@ class CustomViewTest extends V510ServerSetup { } { - val request510 = (v5_1_0_Request / "banks" / bankId / "accounts" / accountId /"views" / SYSTEM_AUDITOR_VIEW_ID /"target-views" / targetViewId ).GET <@ (user1) + val request510 = (v5_1_0_Request / "banks" / bankId / "accounts" / accountId /"views" / ownerView /"target-views" / targetViewId ).GET <@ (user1) val response510 = makeGetRequest(request510) Then("We should get a 400") response510.code should equal(400) response510.body.extract[ErrorMessage].message contains (ViewDoesNotPermitAccess) shouldBe (true) - response510.body.extract[ErrorMessage].message contains ("can_see_available_views_for_bank_account") shouldBe (true) + response510.body.extract[ErrorMessage].message contains ("can_get_custom_view") shouldBe (true) } { @@ -169,7 +169,7 @@ class CustomViewTest extends V510ServerSetup { response510.body.extract[CustomViewJsonV510].allowed_permissions.sorted should equal(postCustomViewJson.allowed_permissions.sorted) { - val request510 = (v5_1_0_Request / "banks" / bankId / "accounts" / accountId / "views" / ownerView / "target-views" / targetViewId).GET <@ (user1) + val request510 = (v5_1_0_Request / "banks" / bankId / "accounts" / accountId / "views" / manageCustomView / "target-views" / targetViewId).GET <@ (user1) val response510 = makeGetRequest(request510) Then("We should get a 200") response510.code should equal(200) @@ -198,7 +198,7 @@ class CustomViewTest extends V510ServerSetup { } { - val request510 = (v5_1_0_Request / "banks" / bankId / "accounts" / accountId /"views" / ownerView /"target-views" / targetViewId ).GET <@ (user1) + val request510 = (v5_1_0_Request / "banks" / bankId / "accounts" / accountId /"views" / manageCustomView /"target-views" / targetViewId ).GET <@ (user1) val response510 = makeGetRequest(request510) Then("We should get a 200") response510.code should equal(200) @@ -217,7 +217,7 @@ class CustomViewTest extends V510ServerSetup { response510.code should equal(204) } { - val request510 = (v5_1_0_Request / "banks" / bankId / "accounts" / accountId / "views" / ownerView / "target-views" / targetViewId).GET <@ (user1) + val request510 = (v5_1_0_Request / "banks" / bankId / "accounts" / accountId / "views" / manageCustomView / "target-views" / targetViewId).GET <@ (user1) val response510 = makeGetRequest(request510) Then("We should get a 400") response510.code should equal(400) diff --git a/obp-commons/src/main/scala/com/openbankproject/commons/model/ViewModel.scala b/obp-commons/src/main/scala/com/openbankproject/commons/model/ViewModel.scala index 256ba39ec3..4cf6b06fbb 100644 --- a/obp-commons/src/main/scala/com/openbankproject/commons/model/ViewModel.scala +++ b/obp-commons/src/main/scala/com/openbankproject/commons/model/ViewModel.scala @@ -432,4 +432,5 @@ trait View { def canCreateCustomView: Boolean def canDeleteCustomView: Boolean def canUpdateCustomView: Boolean + def canGetCustomView: Boolean } \ No newline at end of file From e05a55f281952eb8956ab75f301f765c0f5de0f3 Mon Sep 17 00:00:00 2001 From: hongwei Date: Tue, 2 Jul 2024 12:14:00 +0200 Subject: [PATCH 20/23] refactor/update the pom java and plugin version -step2 --- obp-api/pom.xml | 6 +++--- pom.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/obp-api/pom.xml b/obp-api/pom.xml index 3fdc02716d..9e53ed861d 100644 --- a/obp-api/pom.xml +++ b/obp-api/pom.xml @@ -418,7 +418,7 @@ com.microsoft.sqlserver mssql-jdbc - 8.1.0.jre${java.version}-preview + 11.2.0.jre${java.version} @@ -552,7 +552,7 @@ org.apache.maven.plugins maven-war-plugin - 2.6 + 3.4.0 ${webXmlPath} @@ -639,7 +639,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.13.0 ${java.version} diff --git a/pom.xml b/pom.xml index b8f7e7923f..a0fb316aae 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ http://scala-tools.org/mvnsites/liftweb - 8 + 11 ${java.version} ${java.version} From 517986f71c2d7d8d6ea54ad2719db853a3377f86 Mon Sep 17 00:00:00 2001 From: Hongwei Date: Tue, 2 Jul 2024 16:19:28 +0200 Subject: [PATCH 21/23] refactor/update the pom java and plugin version -step3 --- obp-api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/obp-api/pom.xml b/obp-api/pom.xml index 9e53ed861d..5d991b3bde 100644 --- a/obp-api/pom.xml +++ b/obp-api/pom.xml @@ -530,7 +530,7 @@ org.codehaus.mojo build-helper-maven-plugin - 1.10 + 3.6.0 generate-sources From 3566c6b9cdebd70b6d483a3c9c93555c9c2d1973 Mon Sep 17 00:00:00 2001 From: Hongwei Date: Tue, 2 Jul 2024 23:27:32 +0200 Subject: [PATCH 22/23] test/fixed the failed tests --- .../code/bankconnectors/LocalMappedConnector.scala | 4 ++-- .../v1_3/AccountInformationServiceAISApiTest.scala | 14 +++++++++----- .../src/test/scala/code/setup/ServerSetup.scala | 2 +- .../test/scala/code/setup/TestConnectorSetup.scala | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala index c5bc13cb22..128c26d595 100644 --- a/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala +++ b/obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala @@ -10,7 +10,7 @@ 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, SYSTEM_ACCOUNTANT_VIEW_ID, SYSTEM_AUDITOR_VIEW_ID, SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID, SYSTEM_OWNER_VIEW_ID, localIdentityProvider} +import code.api.Constant._ import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON import code.api.attributedefinition.{AttributeDefinition, AttributeDefinitionDI} import code.api.cache.Caching @@ -618,7 +618,7 @@ object LocalMappedConnector extends Connector with MdcLoggable { */ override def getBankAccountsForUserLegacy(provider: String, username:String, callContext: Option[CallContext]): Box[(List[InboundAccount], Option[CallContext])] = { //1st: get the accounts from userAuthContext - val viewsToGenerate = List(SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID,SYSTEM_OWNER_VIEW_ID) //TODO, so far only set the `owner` view, later need to simulate other views. + val viewsToGenerate = List(SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID,SYSTEM_OWNER_VIEW_ID, SYSTEM_READ_ACCOUNTS_BERLIN_GROUP_VIEW_ID, SYSTEM_READ_BALANCES_BERLIN_GROUP_VIEW_ID, SYSTEM_READ_TRANSACTIONS_BERLIN_GROUP_VIEW_ID) //TODO, so far only set the `owner` view, later need to simulate other views. val user = Users.users.vend.getUserByProviderId(provider, username).getOrElse(throw new RuntimeException(s"$RefreshUserError at getBankAccountsForUserLegacy($username, ${callContext})")) val userId = user.userId tryo{net.liftweb.common.Logger(this.getClass).debug(s"getBankAccountsForUser.user says: provider($provider), username($username)")} diff --git a/obp-api/src/test/scala/code/api/berlin/group/v1_3/AccountInformationServiceAISApiTest.scala b/obp-api/src/test/scala/code/api/berlin/group/v1_3/AccountInformationServiceAISApiTest.scala index 053be11881..845f6c6e2a 100644 --- a/obp-api/src/test/scala/code/api/berlin/group/v1_3/AccountInformationServiceAISApiTest.scala +++ b/obp-api/src/test/scala/code/api/berlin/group/v1_3/AccountInformationServiceAISApiTest.scala @@ -4,6 +4,7 @@ import code.api.Constant import code.api.Constant.SYSTEM_READ_ACCOUNTS_BERLIN_GROUP_VIEW_ID import code.api.berlin.group.v1_3.JSONFactory_BERLIN_GROUP_1_3._ import code.api.builder.AccountInformationServiceAISApi.APIMethods_AccountInformationServiceAISApi +import code.api.util.APIUtil import code.api.util.APIUtil.OAuth._ import code.api.util.ErrorMessages._ import code.api.v4_0_0.PostViewJsonV400 @@ -83,7 +84,10 @@ class AccountInformationServiceAISApiTest extends BerlinGroupServerSetupV1_3 wit } scenario("Authentication User, test succeed", BerlinGroupV1_3, readAccountDetails) { - val (bankId, accountId) = MappedBankAccount.findAll().headOption.map(i => (i.bankId.value,i.accountId.value)).getOrElse(("", "")) + val bankId = APIUtil.defaultBankId + val accountId = testAccountId0.value + + grantUserAccessToViewViaEndpoint( bankId, accountId, @@ -103,7 +107,7 @@ class AccountInformationServiceAISApiTest extends BerlinGroupServerSetupV1_3 wit feature(s"BG v1.3 - $getBalances") { scenario("Authentication User, test succeed", BerlinGroupV1_3, getBalances) { - val bankId = MappedBankAccount.find(By(MappedBankAccount.theAccountId, testAccountId1.value)).map(_.bankId.value).getOrElse("") + val bankId = APIUtil.defaultBankId Then("We should get a 403 ") val requestGetFailed = (V1_3_BG / "accounts" / testAccountId1.value / "balances").GET <@ (user1) @@ -139,7 +143,7 @@ class AccountInformationServiceAISApiTest extends BerlinGroupServerSetupV1_3 wit responseGetFailed.code should equal(403) responseGetFailed.body.extract[ErrorMessagesBG].tppMessages.head.text should startWith(UserNoPermissionAccessView) - val bankId = MappedBankAccount.find(By(MappedBankAccount.theAccountId, testAccountId.value)).map(_.bankId.value).getOrElse("") + val bankId = APIUtil.defaultBankId grantUserAccessToViewViaEndpoint( bankId, testAccountId.value, @@ -168,7 +172,7 @@ class AccountInformationServiceAISApiTest extends BerlinGroupServerSetupV1_3 wit responseGetFailed.code should equal(403) responseGetFailed.body.extract[ErrorMessagesBG].tppMessages.head.text should startWith(UserNoPermissionAccessView) - val bankId = MappedBankAccount.find(By(MappedBankAccount.theAccountId, testAccountId.value)).map(_.bankId.value).getOrElse("") + val bankId = APIUtil.defaultBankId grantUserAccessToViewViaEndpoint( bankId, testAccountId.value, @@ -202,7 +206,7 @@ class AccountInformationServiceAISApiTest extends BerlinGroupServerSetupV1_3 wit responseGetFailed.code should equal(403) responseGetFailed.body.extract[ErrorMessagesBG].tppMessages.head.text should startWith(UserNoPermissionAccessView) - val bankId = MappedBankAccount.find(By(MappedBankAccount.theAccountId, testAccountId.value)).map(_.bankId.value).getOrElse("") + val bankId = APIUtil.defaultBankId grantUserAccessToViewViaEndpoint( bankId, testAccountId.value, diff --git a/obp-api/src/test/scala/code/setup/ServerSetup.scala b/obp-api/src/test/scala/code/setup/ServerSetup.scala index ab0675994a..b3a4e25fc2 100644 --- a/obp-api/src/test/scala/code/setup/ServerSetup.scala +++ b/obp-api/src/test/scala/code/setup/ServerSetup.scala @@ -72,7 +72,7 @@ trait ServerSetup extends FeatureSpec with SendServerRequests val exampleDate = DateWithSecondsExampleObject // @code.setup.TestConnectorSetup.createBanks we can know, the bankIds in test database. - val testBankId1 = BankId("testBank1") + val testBankId1 = BankId(APIUtil.defaultBankId) val testBankId2 = BankId("testBank2") // @code.setup.TestConnectorSetup.createAccounts we can know, the accountIds in test database. diff --git a/obp-api/src/test/scala/code/setup/TestConnectorSetup.scala b/obp-api/src/test/scala/code/setup/TestConnectorSetup.scala index 86b6c930e7..ae5fadd478 100644 --- a/obp-api/src/test/scala/code/setup/TestConnectorSetup.scala +++ b/obp-api/src/test/scala/code/setup/TestConnectorSetup.scala @@ -2,7 +2,7 @@ package code.setup import java.util.{Calendar, Date} import code.accountholders.AccountHolders -import code.api.Constant.{SYSTEM_ACCOUNTANT_VIEW_ID, SYSTEM_AUDITOR_VIEW_ID, SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID, SYSTEM_FIREHOSE_VIEW_ID, SYSTEM_OWNER_VIEW_ID} +import code.api.Constant._ import code.api.util.ErrorMessages.attemptedToOpenAnEmptyBox import code.api.util.{APIUtil, OBPLimit, OBPOffset} import code.bankconnectors.{Connector, LocalMappedConnector} From 3eb952659e364e1c5a10afcd553e938f3fe0f1ac Mon Sep 17 00:00:00 2001 From: Simon Redfern Date: Thu, 4 Jul 2024 17:03:36 +0200 Subject: [PATCH 23/23] Tweaking Consumer item in glossary --- obp-api/src/main/scala/code/api/util/Glossary.scala | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/obp-api/src/main/scala/code/api/util/Glossary.scala b/obp-api/src/main/scala/code/api/util/Glossary.scala index fee0a0b153..cb499e2bff 100644 --- a/obp-api/src/main/scala/code/api/util/Glossary.scala +++ b/obp-api/src/main/scala/code/api/util/Glossary.scala @@ -739,7 +739,16 @@ object Glossary extends MdcLoggable { s""" |The "consumer" of the API, i.e. the web, mobile or serverside "App" that calls on the OBP API on behalf of the end user (or system). | - |Each Consumer has a consumer key and secrect which allows it to enter into secure communication with the API server. + |Each Consumer has a consumer key and secret which allows it to enter into secure communication with the API server. + | + |A Consumer is given a Consumer ID (a UUID) which appears in logs and messages to the backend. + | + |A Consumer may be pinned to an mTLS certificate i.e. the consumer record in the database is given a field which matches the PEM representation of the certificate. + | + |After pinning, the consumer must present the certificate in all communication with the server. + | + |There is a one to one relationship between a Consumer and its certificate. i.e. OBP does not (currently) store the history of certificates bound to a Consumer. If a certificate expires, the third party provider (TPP) must generate a new consumer using a new certificate. In this case, related resources such as rate limits and scopes must be copied from the old consumer to the new consumer. In the future, OBP may store multiple certificates for a consumer, but a certificate will always identify only one consumer record. + | """) glossaryItems += GlossaryItem(