From c890fa60e1474aca7856b1ea4275b395d6117ac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Fri, 30 Sep 2022 11:50:43 +0200 Subject: [PATCH 01/11] feature/Delete Bank Cascade does not delete Bank Entitlements --- obp-api/src/main/scala/deletion/DeleteAccountCascade.scala | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/obp-api/src/main/scala/deletion/DeleteAccountCascade.scala b/obp-api/src/main/scala/deletion/DeleteAccountCascade.scala index 21b9a9c1a..9a79f0e38 100644 --- a/obp-api/src/main/scala/deletion/DeleteAccountCascade.scala +++ b/obp-api/src/main/scala/deletion/DeleteAccountCascade.scala @@ -6,6 +6,7 @@ import code.api.util.APIUtil.fullBoxOrException import code.api.util.ErrorMessages.CouldNotDeleteCascade import code.bankconnectors.Connector import code.cards.MappedPhysicalCard +import code.entitlement.MappedEntitlement import code.model.dataAccess.{BankAccountRouting, MappedBankAccount, MappedBankAccountData} import code.views.system.{AccountAccess, ViewDefinition} import code.webhook.MappedAccountWebhook @@ -31,6 +32,7 @@ object DeleteAccountCascade { deleteCards(accountId) :: deleteAccountRoutings(bankId, accountId) :: deleteAccount(bankId, accountId) :: + deleteEntitlements(bankId) :: Nil doneTasks.forall(_ == true) } @@ -51,6 +53,11 @@ object DeleteAccountCascade { By(MappedBankAccount.theAccountId, accountId.value) ) } + private def deleteEntitlements(bankId: BankId): Boolean = { + MappedEntitlement.bulkDelete_!!( + By(MappedEntitlement.mBankId, bankId.value) + ) + } private def deleteCards(accountId: AccountId): Boolean = { MappedBankAccount.findAll( From f4a09a090dc3b1f4bd9b3440d3100c6db8e47a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Fri, 30 Sep 2022 12:05:41 +0200 Subject: [PATCH 02/11] feature/Add Endpoint Customer Overview WIP 7 --- obp-api/src/main/scala/code/api/v5_0_0/JSONFactory5.0.0.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/obp-api/src/main/scala/code/api/v5_0_0/JSONFactory5.0.0.scala b/obp-api/src/main/scala/code/api/v5_0_0/JSONFactory5.0.0.scala index c26259b3c..9d450e0e9 100644 --- a/obp-api/src/main/scala/code/api/v5_0_0/JSONFactory5.0.0.scala +++ b/obp-api/src/main/scala/code/api/v5_0_0/JSONFactory5.0.0.scala @@ -131,6 +131,7 @@ case class AccountAttributeResponseJson500( case class AccountResponseJson500(account_id: String, label: String, + product_code: String, balance : AmountOfMoneyJsonV121, branch_id: String, account_routings: List[AccountRouting], @@ -401,6 +402,7 @@ object JSONFactory500 { AccountResponseJson500( account_id = account._1.accountId.value, label = account._1.label, + product_code = account._1.accountType, balance = AmountOfMoneyJsonV121(account._1.balance.toString(), account._1.currency), branch_id = account._1.branchId, account_routings = account._1.accountRoutings, From e53e6836bb08282ebded76893d682c6cceb30913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Fri, 30 Sep 2022 15:47:49 +0200 Subject: [PATCH 03/11] test/Fix delete product cascade test --- .../src/main/scala/deletion/DeleteAccountCascade.scala | 10 ++++++---- .../code/api/v4_0_0/DeleteProductCascadeTest.scala | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/obp-api/src/main/scala/deletion/DeleteAccountCascade.scala b/obp-api/src/main/scala/deletion/DeleteAccountCascade.scala index 9a79f0e38..ea095de6a 100644 --- a/obp-api/src/main/scala/deletion/DeleteAccountCascade.scala +++ b/obp-api/src/main/scala/deletion/DeleteAccountCascade.scala @@ -14,7 +14,7 @@ import com.openbankproject.commons.model.{AccountId, BankId} import deletion.DeletionUtil.databaseAtomicTask import net.liftweb.common.{Box, Empty, Full} import net.liftweb.db.DB -import net.liftweb.mapper.By +import net.liftweb.mapper.{By, ByList} import net.liftweb.util.DefaultConnectionIdentifier import scala.collection.immutable.List @@ -24,6 +24,7 @@ object DeleteAccountCascade { def delete(bankId: BankId, accountId: AccountId): Boolean = { val doneTasks = deleteTransactions(bankId, accountId) :: + deleteEntitlements(bankId, accountId) :: deleteAccountAccess(bankId, accountId) :: deleteCustomViews(bankId, accountId) :: deleteAccountAttributes(bankId, accountId) :: @@ -32,7 +33,6 @@ object DeleteAccountCascade { deleteCards(accountId) :: deleteAccountRoutings(bankId, accountId) :: deleteAccount(bankId, accountId) :: - deleteEntitlements(bankId) :: Nil doneTasks.forall(_ == true) } @@ -53,9 +53,11 @@ object DeleteAccountCascade { By(MappedBankAccount.theAccountId, accountId.value) ) } - private def deleteEntitlements(bankId: BankId): Boolean = { + private def deleteEntitlements(bankId: BankId, accountId: AccountId): Boolean = { + val userIds = AccountAccess.findAll(By(AccountAccess.account_id, accountId.value)).map(_.user_fk.foreign.map(_.userId).getOrElse("")) MappedEntitlement.bulkDelete_!!( - By(MappedEntitlement.mBankId, bankId.value) + By(MappedEntitlement.mBankId, bankId.value), + ByList(MappedEntitlement.mUserId, userIds) ) } diff --git a/obp-api/src/test/scala/code/api/v4_0_0/DeleteProductCascadeTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/DeleteProductCascadeTest.scala index 500d47c48..fb2d07b32 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/DeleteProductCascadeTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/DeleteProductCascadeTest.scala @@ -84,7 +84,7 @@ class DeleteProductCascadeTest extends V400ServerSetup { makeDeleteRequest(request400).code should equal(200) When("We try to delete one more time") - makeDeleteRequest(request400).code should equal(404) + makeDeleteRequest(request400).code should equal(403) } } From 96e29097bae09774f046f84546edc9b3cecec446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Mon, 3 Oct 2022 06:48:17 +0200 Subject: [PATCH 04/11] docfix/Update db.url in case of H2 database v.2.1.214 --- obp-api/src/main/resources/props/sample.props.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/obp-api/src/main/resources/props/sample.props.template b/obp-api/src/main/resources/props/sample.props.template index 2256099b7..447f46fa6 100644 --- a/obp-api/src/main/resources/props/sample.props.template +++ b/obp-api/src/main/resources/props/sample.props.template @@ -172,7 +172,7 @@ write_connector_metrics=true ## You can use a no config needed h2 database by setting db.driver=org.h2.Driver and not including db.url # See the README for how to use the H2 browser / console. db.driver=org.h2.Driver -db.url=jdbc:h2:./lift_proto.db;DB_CLOSE_ON_EXIT=FALSE +db.url=jdbc:h2:./lift_proto.db;NON_KEYWORDS=VALUE;DB_CLOSE_ON_EXIT=FALSE #If you want to use the postgres , be sure to create your database and update the line below! From 18092a420844adc632d9fee7ab44453f98135e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Mon, 3 Oct 2022 08:45:27 +0200 Subject: [PATCH 05/11] refactor/Get rid of debug code --- .../scala/com/openbankproject/commons/util/JsonUtils.scala | 3 --- 1 file changed, 3 deletions(-) diff --git a/obp-commons/src/main/scala/com/openbankproject/commons/util/JsonUtils.scala b/obp-commons/src/main/scala/com/openbankproject/commons/util/JsonUtils.scala index 7544146c6..abdab4125 100644 --- a/obp-commons/src/main/scala/com/openbankproject/commons/util/JsonUtils.scala +++ b/obp-commons/src/main/scala/com/openbankproject/commons/util/JsonUtils.scala @@ -688,9 +688,6 @@ object JsonUtils { transformField(jValue){ case (jField, path) => buffer += (jField.name -> jField.value.toString) - if(jField.name == "face_image") { - 1 - } jField } From 30b4f5abd1173d0ddcdd9a05445d626a52e409b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Mon, 3 Oct 2022 12:00:10 +0200 Subject: [PATCH 06/11] feature/Endpoint createProduct v5.0.0;Change default value of the Last OK Date --- obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala b/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala index 477786a05..aa90209cc 100644 --- a/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala +++ b/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala @@ -1,5 +1,7 @@ package code.api.v5_0_0 +import java.util.Date + import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._ import code.api.util.APIUtil._ import code.api.util.ApiRole._ @@ -1002,7 +1004,7 @@ trait APIMethods500 { postedData.highest_education_attained.getOrElse(""), postedData.employment_status.getOrElse(""), postedData.kyc_status.getOrElse(false), - postedData.last_ok_date.getOrElse(null), + postedData.last_ok_date.getOrElse(new Date()), // TODO Consider use of this field in Get Customers Endpoints postedData.credit_rating.map(i => CreditRating(i.rating, i.source)), postedData.credit_limit.map(i => CreditLimit(i.currency, i.amount)), postedData.title.getOrElse(""), From 0a297adbc1bd8b9b0566754c53861a2000351801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Tue, 4 Oct 2022 08:30:04 +0200 Subject: [PATCH 07/11] feature/Set epoch time as default value in case of from_date --- obp-api/src/main/scala/code/api/util/APIUtil.scala | 5 ++--- obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala | 2 +- .../main/scala/code/customer/MappedCustomerProvider.scala | 4 ++-- 3 files changed, 5 insertions(+), 6 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 d6d802386..ab51a247b 100644 --- a/obp-api/src/main/scala/code/api/util/APIUtil.scala +++ b/obp-api/src/main/scala/code/api/util/APIUtil.scala @@ -867,9 +867,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ case (_, Full(right)) => parseObpStandardDate(right.head) case _ => - Full(DefaultFromDate) + Full(new Date(0)) // Set epoch time. The Unix epoch is 00:00:00 UTC on 1 January 1970. } - date.map(OBPFromDate(_)) } @@ -911,7 +910,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ Full(OBPLimit(right)) case (_, Failure(m, e, c)) => Failure(m, e, c) - case _ => Full(OBPLimit(50)) + case _ => Full(OBPLimit(500)) } } diff --git a/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala b/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala index aa90209cc..149e991ed 100644 --- a/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala +++ b/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala @@ -1004,7 +1004,7 @@ trait APIMethods500 { postedData.highest_education_attained.getOrElse(""), postedData.employment_status.getOrElse(""), postedData.kyc_status.getOrElse(false), - postedData.last_ok_date.getOrElse(new Date()), // TODO Consider use of this field in Get Customers Endpoints + postedData.last_ok_date.getOrElse(null), postedData.credit_rating.map(i => CreditRating(i.rating, i.source)), postedData.credit_limit.map(i => CreditLimit(i.currency, i.amount)), postedData.title.getOrElse(""), diff --git a/obp-api/src/main/scala/code/customer/MappedCustomerProvider.scala b/obp-api/src/main/scala/code/customer/MappedCustomerProvider.scala index 445a659d8..eda7c0880 100644 --- a/obp-api/src/main/scala/code/customer/MappedCustomerProvider.scala +++ b/obp-api/src/main/scala/code/customer/MappedCustomerProvider.scala @@ -35,8 +35,8 @@ object MappedCustomerProvider extends CustomerProvider with MdcLoggable { private def getOptionalParams(queryParams: List[OBPQueryParam]) = { val limit = queryParams.collect { case OBPLimit(value) => MaxRows[MappedCustomer](value) }.headOption val offset = queryParams.collect { case OBPOffset(value) => StartAt[MappedCustomer](value) }.headOption - val fromDate = queryParams.collect { case OBPFromDate(date) => By_>=(MappedCustomer.mLastOkDate, date) }.headOption - val toDate = queryParams.collect { case OBPToDate(date) => By_<=(MappedCustomer.mLastOkDate, date) }.headOption + val fromDate = queryParams.collect { case OBPFromDate(date) => By_>=(MappedCustomer.updatedAt, date) }.headOption + val toDate = queryParams.collect { case OBPToDate(date) => By_<=(MappedCustomer.updatedAt, date) }.headOption val ordering = queryParams.collect { case OBPOrdering(_, direction) => direction match { From 93c3dd4f3cbf9c99962c4d0a770369a312d58964 Mon Sep 17 00:00:00 2001 From: hongwei Date: Tue, 4 Oct 2022 09:52:13 +0200 Subject: [PATCH 08/11] refactor/tweaked the last_ok_date example value to last year --- .../SwaggerDefinitionsJSON.scala | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) 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 c9892039d..3e57a3054 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 @@ -1285,7 +1285,7 @@ object SwaggerDefinitionsJSON { highest_education_attained = ExampleValue.highestEducationAttainedExample.value, employment_status = ExampleValue.employmentStatusExample.value, kyc_status = ExampleValue.kycStatusExample.value.toBoolean, - last_ok_date = DateWithDayExampleObject + last_ok_date = DefaultFromDate ) val customerJsonV140 = CustomerJsonV140( @@ -1302,7 +1302,7 @@ object SwaggerDefinitionsJSON { highest_education_attained = ExampleValue.highestEducationAttainedExample.value, employment_status = ExampleValue.employmentStatusExample.value, kyc_status = ExampleValue.kycStatusExample.value.toBoolean, - last_ok_date = DateWithDayExampleObject + last_ok_date = DefaultFromDate ) val customersJsonV140 = CustomersJsonV140( @@ -2006,7 +2006,7 @@ object SwaggerDefinitionsJSON { highest_education_attained = ExampleValue.highestEducationAttainedExample.value, employment_status = ExampleValue.employmentStatusExample.value, kyc_status = ExampleValue.kycStatusExample.value.toBoolean, - last_ok_date = DateWithDayExampleObject + last_ok_date = DefaultFromDate ) val transactionRequestJsonV200 = TransactionRequestJsonV200( @@ -2142,7 +2142,7 @@ object SwaggerDefinitionsJSON { highest_education_attained = ExampleValue.highestEducationAttainedExample.value, employment_status = ExampleValue.employmentStatusExample.value, kyc_status = ExampleValue.kycStatusExample.value.toBoolean, - last_ok_date = DateWithDayExampleObject + last_ok_date = DefaultFromDate ) val customerJSONs = CustomerJSONs(customers = List(customerJsonV210)) @@ -2178,7 +2178,7 @@ object SwaggerDefinitionsJSON { highest_education_attained = ExampleValue.highestEducationAttainedExample.value, employment_status = ExampleValue.employmentStatusExample.value, kyc_status = ExampleValue.kycStatusExample.value.toBoolean, - last_ok_date = DateWithDayExampleObject + last_ok_date = DefaultFromDate ) val customerJsonV300 = CustomerJsonV300( @@ -2198,7 +2198,7 @@ object SwaggerDefinitionsJSON { highest_education_attained = ExampleValue.highestEducationAttainedExample.value, employment_status = ExampleValue.employmentStatusExample.value, kyc_status = ExampleValue.kycStatusExample.value.toBoolean, - last_ok_date = DateWithDayExampleObject, + last_ok_date = DefaultFromDate, title = ExampleValue.titleExample.value, branch_id = ExampleValue.branchIdExample.value, name_suffix = ExampleValue.nameSuffixExample.value @@ -2227,7 +2227,7 @@ object SwaggerDefinitionsJSON { highest_education_attained = ExampleValue.highestEducationAttainedExample.value, employment_status = ExampleValue.employmentStatusExample.value, kyc_status = ExampleValue.kycStatusExample.value.toBoolean, - last_ok_date = DateWithDayExampleObject, + last_ok_date = DefaultFromDate, title = ExampleValue.titleExample.value, branch_id = ExampleValue.branchIdExample.value, name_suffix = ExampleValue.nameSuffixExample.value @@ -2247,7 +2247,7 @@ object SwaggerDefinitionsJSON { highest_education_attained = Some(ExampleValue.highestEducationAttainedExample.value), employment_status = Some(ExampleValue.employmentStatusExample.value), kyc_status = Some(ExampleValue.kycStatusExample.value.toBoolean), - last_ok_date = Some(DateWithDayExampleObject), + last_ok_date = Some(DefaultFromDate), title = Some(ExampleValue.titleExample.value), branch_id = Some(ExampleValue.branchIdExample.value), name_suffix = Some(ExampleValue.nameSuffixExample.value) @@ -2270,7 +2270,7 @@ object SwaggerDefinitionsJSON { highest_education_attained = ExampleValue.highestEducationAttainedExample.value, employment_status = ExampleValue.employmentStatusExample.value, kyc_status = ExampleValue.kycStatusExample.value.toBoolean, - last_ok_date = DateWithDayExampleObject, + last_ok_date = DefaultFromDate, title = ExampleValue.titleExample.value, branch_id = ExampleValue.branchIdExample.value, name_suffix = ExampleValue.nameSuffixExample.value @@ -2300,7 +2300,7 @@ object SwaggerDefinitionsJSON { highest_education_attained = ExampleValue.highestEducationAttainedExample.value, employment_status = ExampleValue.employmentStatusExample.value, kyc_status = ExampleValue.kycStatusExample.value.toBoolean, - last_ok_date = DateWithDayExampleObject, + last_ok_date = DefaultFromDate, title = ExampleValue.titleExample.value, branch_id = ExampleValue.branchIdExample.value, name_suffix = ExampleValue.nameSuffixExample.value, @@ -2324,7 +2324,7 @@ object SwaggerDefinitionsJSON { highest_education_attained = ExampleValue.highestEducationAttainedExample.value, employment_status = ExampleValue.employmentStatusExample.value, kyc_status = ExampleValue.kycStatusExample.value.toBoolean, - last_ok_date = DateWithDayExampleObject, + last_ok_date = DefaultFromDate, title = ExampleValue.titleExample.value, branch_id = ExampleValue.branchIdExample.value, name_suffix = ExampleValue.nameSuffixExample.value, From 0bafe376540908a4ee364fa4a422776b74ebe604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Tue, 4 Oct 2022 09:58:34 +0200 Subject: [PATCH 09/11] test/Fix tests regarding default from_date --- obp-api/src/main/scala/code/api/util/APIUtil.scala | 10 ++++++---- obp-api/src/test/scala/code/util/APIUtilTest.scala | 5 +++-- 2 files changed, 9 insertions(+), 6 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 ab51a247b..94a1c2362 100644 --- a/obp-api/src/main/scala/code/api/util/APIUtil.scala +++ b/obp-api/src/main/scala/code/api/util/APIUtil.scala @@ -159,13 +159,15 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ oneYearAgo.getTime() } def DefaultToDate = new Date() - def DefaultFromDate = oneYearAgo(DefaultToDate) + def oneYearAgoFromDate = oneYearAgo(DefaultToDate) def formatDate(date : Date) : String = { CustomJsonFormats.losslessFormats.dateFormat.format(date) } - def DefaultFromDateString = formatDate(DefaultFromDate) + def oneYearAgoFromDateString = formatDate(oneYearAgoFromDate) def DefaultToDateString = formatDate(DefaultToDate) + + val epochTime = new Date(0) // Set epoch time. The Unix epoch is 00:00:00 UTC on 1 January 1970. implicit def errorToJson(error: ErrorMessage): JValue = Extraction.decompose(error) val headers = ("Access-Control-Allow-Origin","*") :: Nil @@ -867,7 +869,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ case (_, Full(right)) => parseObpStandardDate(right.head) case _ => - Full(new Date(0)) // Set epoch time. The Unix epoch is 00:00:00 UTC on 1 January 1970. + Full(epochTime) // Set epoch time. The Unix epoch is 00:00:00 UTC on 1 January 1970. } date.map(OBPFromDate(_)) } @@ -1920,7 +1922,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ val dateParameter = if(containsDate){ s""" | - |* from_date=DATE => example value: $DefaultFromDateString. NOTE! The default value is one year ago ($DefaultFromDateString). + |* from_date=DATE => example value: $oneYearAgoFromDateString. NOTE! The default value is one year ago ($oneYearAgoFromDateString). |* to_date=DATE => example value: $DefaultToDateString. NOTE! The default value is now ($DefaultToDateString). | |Date format parameter: $DateWithMs($DateWithMsExampleString) ==> time zone is UTC. diff --git a/obp-api/src/test/scala/code/util/APIUtilTest.scala b/obp-api/src/test/scala/code/util/APIUtilTest.scala index cebb40c52..871786f31 100644 --- a/obp-api/src/test/scala/code/util/APIUtilTest.scala +++ b/obp-api/src/test/scala/code/util/APIUtilTest.scala @@ -49,6 +49,7 @@ class APIUtilTest extends FeatureSpec with Matchers with GivenWhenThen with Prop val DefaultToDateString = APIUtil.DefaultToDateString val startDateObject: Date = DateWithMsFormat.parse(DefaultFromDateString) val endDateObject: Date = DateWithMsFormat.parse(DefaultToDateString) + val epochTime = new Date(0) // Set epoch time. The Unix epoch is 00:00:00 UTC on 1 January 1970. ZonedDateTime.now(ZoneId.of("UTC")) feature("test APIUtil.dateRangesOverlap method") { @@ -235,7 +236,7 @@ class APIUtilTest extends FeatureSpec with Matchers with GivenWhenThen with Prop scenario("test the wrong case: wrong name (wrongName) in HTTPParam") { val httpParams: List[HTTPParam] = List(HTTPParam("wrongName", List(s"$DateWithMsExampleString"))) - val startTime = OBPFromDate(DefaultFromDate) + val startTime = OBPFromDate(epochTime) val returnValue = getFromDate(httpParams) returnValue shouldBe a[Full[OBPFromDate]] @@ -247,7 +248,7 @@ class APIUtilTest extends FeatureSpec with Matchers with GivenWhenThen with Prop scenario("test the wrong case: wrong name (wrongName) and wrong values (wrongValue) in HTTPParam") { val httpParams: List[HTTPParam] = List(HTTPParam("wrongName", List("wrongValue"))) - val startTime = OBPFromDate(DefaultFromDate) + val startTime = OBPFromDate(epochTime) val returnValue = getFromDate(httpParams) returnValue shouldBe a[Full[OBPFromDate]] From 2221d5900b13dd5a334e5932412911e753ef459e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Tue, 4 Oct 2022 09:59:37 +0200 Subject: [PATCH 10/11] test/Fix tests regarding default from_date --- obp-api/src/main/scala/code/api/util/OBPParam.scala | 2 +- .../src/main/scala/code/api/v3_1_0/APIMethods310.scala | 8 ++++---- .../bankconnectors/akka/AkkaConnector_vDec2018.scala | 2 +- .../vSept2018/KafkaMappedConnector_vSept2018.scala | 4 ++-- .../code/api/v1_4_0/TransactionRequestsTest.scala | 2 +- .../code/api/v2_0_0/TransactionRequestsTest.scala | 10 +++++----- .../code/api/v2_1_0/TransactionRequestsTest.scala | 4 ++-- .../code/api/v4_0_0/TransactionRequestsTest.scala | 4 ++-- obp-api/src/test/scala/code/util/APIUtilTest.scala | 9 ++++----- 9 files changed, 22 insertions(+), 23 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/OBPParam.scala b/obp-api/src/main/scala/code/api/util/OBPParam.scala index db455c4b1..bcb475ae2 100644 --- a/obp-api/src/main/scala/code/api/util/OBPParam.scala +++ b/obp-api/src/main/scala/code/api/util/OBPParam.scala @@ -53,7 +53,7 @@ object OBPQueryParam { val FROM_DATE = "fromDate" val TO_DATE = "toDate" - private val defaultFromDate = APIUtil.DateWithMsFormat.format(APIUtil.DefaultFromDate) + private val defaultFromDate = APIUtil.DateWithMsFormat.format(APIUtil.oneYearAgoFromDate) private val defaultToDate = APIUtil.DateWithMsFormat.format(APIUtil.DefaultToDate) def getLimit(queryParams: List[OBPQueryParam]) : Int = { 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 87d619dec..23008d59c 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 @@ -258,13 +258,13 @@ trait APIMethods310 { | |Should be able to filter on the following fields | - |eg: /management/metrics/top-apis?from_date=$DefaultFromDateString&to_date=$DefaultToDateString&consumer_id=5 + |eg: /management/metrics/top-apis?from_date=$oneYearAgoFromDateString&to_date=$DefaultToDateString&consumer_id=5 |&user_id=66214b8e-259e-44ad-8868-3eb47be70646&implemented_by_partial_function=getTransactionsForBankAccount |&implemented_in_version=v3.0.0&url=/obp/v3.0.0/banks/gh.29.uk/accounts/8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0/owner/transactions |&verb=GET&anon=false&app_name=MapperPostman |&exclude_app_names=API-EXPLORER,API-Manager,SOFI,null | - |1 from_date (defaults to the one year ago): eg:from_date=$DefaultFromDateString + |1 from_date (defaults to the one year ago): eg:from_date=$oneYearAgoFromDateString | |2 to_date (defaults to the current date) eg:to_date=$DefaultToDateString | @@ -344,14 +344,14 @@ trait APIMethods310 { | |Should be able to filter on the following fields | - |e.g.: /management/metrics/top-consumers?from_date=$DefaultFromDateString&to_date=$DefaultToDateString&consumer_id=5 + |e.g.: /management/metrics/top-consumers?from_date=$oneYearAgoFromDateString&to_date=$DefaultToDateString&consumer_id=5 |&user_id=66214b8e-259e-44ad-8868-3eb47be70646&implemented_by_partial_function=getTransactionsForBankAccount |&implemented_in_version=v3.0.0&url=/obp/v3.0.0/banks/gh.29.uk/accounts/8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0/owner/transactions |&verb=GET&anon=false&app_name=MapperPostman |&exclude_app_names=API-EXPLORER,API-Manager,SOFI,null |&limit=100 | - |1 from_date (defaults to the one year ago): eg:from_date=$DefaultFromDateString + |1 from_date (defaults to the one year ago): eg:from_date=$oneYearAgoFromDateString | |2 to_date (defaults to the current date) eg:to_date=$DefaultToDateString | diff --git a/obp-api/src/main/scala/code/bankconnectors/akka/AkkaConnector_vDec2018.scala b/obp-api/src/main/scala/code/bankconnectors/akka/AkkaConnector_vDec2018.scala index 8c0ed2a9f..09e0cfa69 100644 --- a/obp-api/src/main/scala/code/bankconnectors/akka/AkkaConnector_vDec2018.scala +++ b/obp-api/src/main/scala/code/bankconnectors/akka/AkkaConnector_vDec2018.scala @@ -268,7 +268,7 @@ object AkkaConnector_vDec2018 extends Connector with AkkaConnectorActorInit { override def getTransactions(bankId: BankId, accountId: AccountId, callContext: Option[CallContext], queryParams: List[OBPQueryParam]): OBPReturnType[Box[List[Transaction]]] = { val limit = queryParams.collect { case OBPLimit(value) => value }.headOption.getOrElse(100) val offset = queryParams.collect { case OBPOffset(value) => value }.headOption.getOrElse(0) - val fromDate = queryParams.collect { case OBPFromDate(date) => APIUtil.DateWithMsFormat.format(date) }.headOption.getOrElse(APIUtil.DefaultFromDate.toString) + val fromDate = queryParams.collect { case OBPFromDate(date) => APIUtil.DateWithMsFormat.format(date) }.headOption.getOrElse(APIUtil.oneYearAgoFromDate.toString) val toDate = queryParams.collect { case OBPToDate(date) => APIUtil.DateWithMsFormat.format(date) }.headOption.getOrElse(APIUtil.DefaultToDate.toString) val req = OutBoundGetTransactions(callContext.map(_.toOutboundAdapterCallContext).get, bankId, accountId, limit, offset, fromDate, toDate) 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 89c5ecfda..7f047f0e3 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 @@ -763,7 +763,7 @@ trait KafkaMappedConnector_vSept2018 extends Connector with KafkaHelper with Mdc // TODO Get rid on these param lookups and document. override def getTransactionsLegacy(bankId: BankId, accountId: AccountId, callContext: Option[CallContext], queryParams: List[OBPQueryParam]) = saveConnectorMetric { val limit = queryParams.collect { case OBPLimit(value) => value }.headOption.getOrElse(100) - val fromDate = queryParams.collect { case OBPFromDate(date) => date.toString }.headOption.getOrElse(APIUtil.DefaultFromDate.toString) + val fromDate = queryParams.collect { case OBPFromDate(date) => date.toString }.headOption.getOrElse(APIUtil.oneYearAgoFromDate.toString) val toDate = queryParams.collect { case OBPToDate(date) => date.toString }.headOption.getOrElse(APIUtil.DefaultToDate.toString) // TODO What about offset? @@ -825,7 +825,7 @@ trait KafkaMappedConnector_vSept2018 extends Connector with KafkaHelper with Mdc CacheKeyFromArguments.buildCacheKey {Caching.memoizeSyncWithProvider(Some(cacheKey.toString()))(transactionsTTL second) { val limit = queryParams.collect { case OBPLimit(value) => value}.headOption.getOrElse(100) - val fromDate = queryParams.collect { case OBPFromDate(date) => date.toString}.headOption.getOrElse(APIUtil.DefaultFromDate.toString) + val fromDate = queryParams.collect { case OBPFromDate(date) => date.toString}.headOption.getOrElse(APIUtil.oneYearAgoFromDate.toString) val toDate = queryParams.collect { case OBPToDate(date) => date.toString}.headOption.getOrElse(APIUtil.DefaultToDate.toString) val req = OutboundGetTransactions( diff --git a/obp-api/src/test/scala/code/api/v1_4_0/TransactionRequestsTest.scala b/obp-api/src/test/scala/code/api/v1_4_0/TransactionRequestsTest.scala index 1a39810f4..d9376b06d 100644 --- a/obp-api/src/test/scala/code/api/v1_4_0/TransactionRequestsTest.scala +++ b/obp-api/src/test/scala/code/api/v1_4_0/TransactionRequestsTest.scala @@ -127,7 +127,7 @@ class TransactionRequestsTest extends V140ServerSetup with DefaultUsers { //check that we created a new transaction (since no challenge) request = (v1_4Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@(user1) - response = makeGetRequest(request, List(("from_date", APIUtil.DefaultFromDateString),("to_date", APIUtil.DefaultToDateString))) + response = makeGetRequest(request, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) Then("we should get a 200 ok code") response.code should equal(200) diff --git a/obp-api/src/test/scala/code/api/v2_0_0/TransactionRequestsTest.scala b/obp-api/src/test/scala/code/api/v2_0_0/TransactionRequestsTest.scala index 57a0ca302..d6fe861ee 100644 --- a/obp-api/src/test/scala/code/api/v2_0_0/TransactionRequestsTest.scala +++ b/obp-api/src/test/scala/code/api/v2_0_0/TransactionRequestsTest.scala @@ -287,7 +287,7 @@ class TransactionRequestsTest extends V200ServerSetup with DefaultUsers { //check that we created a new transaction (since no challenge) request = (v1_4Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@(user1) - response = makeGetRequest(request, List(("from_date", APIUtil.DefaultFromDateString),("to_date", APIUtil.DefaultToDateString))) + response = makeGetRequest(request, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) Then("we should get a 200 ok code") response.code should equal(200) @@ -551,7 +551,7 @@ class TransactionRequestsTest extends V200ServerSetup with DefaultUsers { //check that we created a new transaction (since no challenge) request = (v2_0Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@(user1) - response = makeGetRequest(request, List(("from_date", APIUtil.DefaultFromDateString),("to_date", APIUtil.DefaultToDateString))) + response = makeGetRequest(request, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) Then("we should get a 200 ok code") response.code should equal(200) @@ -586,7 +586,7 @@ class TransactionRequestsTest extends V200ServerSetup with DefaultUsers { //check that we created a new transaction (since no challenge) request = (v2_0Request / "banks" / testBank.bankId.value / "accounts" / toAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@(user1) - response = makeGetRequest(request, List(("from_date", APIUtil.DefaultFromDateString),("to_date", APIUtil.DefaultToDateString))) + response = makeGetRequest(request, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) Then("we should get a 200 ok code") response.code should equal(200) @@ -989,7 +989,7 @@ class TransactionRequestsTest extends V200ServerSetup with DefaultUsers { //check that we created a new transaction (since no challenge) request = (v2_0Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@(user1) - response = makeGetRequest(request, List(("from_date", APIUtil.DefaultFromDateString),("to_date", APIUtil.DefaultToDateString))) + response = makeGetRequest(request, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) Then("we should get a 200 ok code") response.code should equal(200) @@ -1024,7 +1024,7 @@ class TransactionRequestsTest extends V200ServerSetup with DefaultUsers { //check that we created a new transaction request = (v2_0Request / "banks" / testBank.bankId.value / "accounts" / toAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@(user1) - response = makeGetRequest(request, List(("from_date", APIUtil.DefaultFromDateString),("to_date", APIUtil.DefaultToDateString))) + response = makeGetRequest(request, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) Then("we should get a 200 ok code") response.code should equal(200) diff --git a/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala b/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala index b14ecac54..b3f5a0aa8 100644 --- a/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala +++ b/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala @@ -171,7 +171,7 @@ class TransactionRequestsTest extends V210ServerSetup with DefaultUsers { var getTransReqRequest = (v2_1Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transaction-requests").GET <@ (user1) - def makeGetTransReqRequest = makeGetRequest(getTransReqRequest, List(("from_date", APIUtil.DefaultFromDateString),("to_date", APIUtil.DefaultToDateString))) + def makeGetTransReqRequest = makeGetRequest(getTransReqRequest, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) def checkAllGetTransReqResBodyField(getTransactionRequestResponse: APIResponse, withChellenge: Boolean): Unit = { Then("we should get a 200 created code") @@ -207,7 +207,7 @@ class TransactionRequestsTest extends V210ServerSetup with DefaultUsers { */ var getTransactionRequest = (v2_1Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@ (user1) - def makeGetTransRequest = makeGetRequest(getTransactionRequest, List(("from_date", APIUtil.DefaultFromDateString),("to_date", APIUtil.DefaultToDateString))) + def makeGetTransRequest = makeGetRequest(getTransactionRequest, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) def checkAllGetTransResBodyField(getTransactionResponse: APIResponse, withChellenge: Boolean): Unit = { Then("we should get a 200 created code") 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 0573e22a3..b128080fd 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 @@ -231,7 +231,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers { var getTransReqRequest = (v4_0_0_Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transaction-requests").GET <@ (user1) - def makeGetTransReqRequest = makeGetRequest(getTransReqRequest, List(("from_date", APIUtil.DefaultFromDateString),("to_date", APIUtil.DefaultToDateString))) + def makeGetTransReqRequest = makeGetRequest(getTransReqRequest, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) def checkAllGetTransReqResBodyField(getTransactionRequestResponse: APIResponse, withChellenge: Boolean): Unit = { Then("we should get a 200 created code") @@ -267,7 +267,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers { */ var getTransactionRequest = (v4_0_0_Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@ (user1) - def makeGetTransRequest = makeGetRequest(getTransactionRequest, List(("from_date", APIUtil.DefaultFromDateString),("to_date", APIUtil.DefaultToDateString))) + def makeGetTransRequest = makeGetRequest(getTransactionRequest, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) def checkAllGetTransResBodyField(getTransactionResponse: APIResponse, withChellenge: Boolean): Unit = { Then("we should get a 200 created code") diff --git a/obp-api/src/test/scala/code/util/APIUtilTest.scala b/obp-api/src/test/scala/code/util/APIUtilTest.scala index 871786f31..dc8296a5d 100644 --- a/obp-api/src/test/scala/code/util/APIUtilTest.scala +++ b/obp-api/src/test/scala/code/util/APIUtilTest.scala @@ -30,7 +30,7 @@ package code.util import java.time.format.DateTimeFormatter import java.time.{ZoneId, ZonedDateTime} import java.util.Date -import code.api.util.APIUtil.{DateWithMsFormat, DefaultFromDate, DefaultToDate, _} +import code.api.util.APIUtil.{DateWithMsFormat, oneYearAgoFromDate, DefaultToDate, _} import code.api.util.ErrorMessages._ import code.api.util._ import code.setup.PropsReset @@ -45,11 +45,10 @@ class APIUtilTest extends FeatureSpec with Matchers with GivenWhenThen with Prop val endDateString = DefaultToDateString val endDateStringWrongFormat = "Wrong Date Format" val inputStringDateFormat = DateWithMsFormat - val DefaultFromDateString = APIUtil.DefaultFromDateString + val DefaultFromDateString = APIUtil.oneYearAgoFromDateString val DefaultToDateString = APIUtil.DefaultToDateString val startDateObject: Date = DateWithMsFormat.parse(DefaultFromDateString) val endDateObject: Date = DateWithMsFormat.parse(DefaultToDateString) - val epochTime = new Date(0) // Set epoch time. The Unix epoch is 00:00:00 UTC on 1 January 1970. ZonedDateTime.now(ZoneId.of("UTC")) feature("test APIUtil.dateRangesOverlap method") { @@ -240,7 +239,7 @@ class APIUtilTest extends FeatureSpec with Matchers with GivenWhenThen with Prop val returnValue = getFromDate(httpParams) returnValue shouldBe a[Full[OBPFromDate]] - val currentTime = OBPFromDate(DefaultFromDate) + val currentTime = OBPFromDate(oneYearAgoFromDate) val beWithinTolerance = be >= startTime and be <= currentTime returnValue.orNull should beWithinTolerance } @@ -252,7 +251,7 @@ class APIUtilTest extends FeatureSpec with Matchers with GivenWhenThen with Prop val returnValue = getFromDate(httpParams) returnValue shouldBe a[Full[OBPFromDate]] - val currentTime = OBPFromDate(DefaultFromDate) + val currentTime = OBPFromDate(oneYearAgoFromDate) val beWithinTolerance = be >= startTime and be <= currentTime returnValue.orNull should beWithinTolerance } From b0abf361a4613a9c1c5d528fa4614af031d556bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Tue, 4 Oct 2022 10:22:58 +0200 Subject: [PATCH 11/11] feature/Use the epoch time instead of one year ago --- obp-api/src/main/scala/code/api/util/APIUtil.scala | 10 ++++------ obp-api/src/main/scala/code/api/util/OBPParam.scala | 2 +- .../main/scala/code/api/v3_1_0/APIMethods310.scala | 8 ++++---- .../bankconnectors/akka/AkkaConnector_vDec2018.scala | 2 +- .../vSept2018/KafkaMappedConnector_vSept2018.scala | 4 ++-- .../code/api/v1_4_0/TransactionRequestsTest.scala | 2 +- .../code/api/v2_0_0/TransactionRequestsTest.scala | 10 +++++----- .../code/api/v2_1_0/TransactionRequestsTest.scala | 4 ++-- .../code/api/v4_0_0/TransactionRequestsTest.scala | 4 ++-- obp-api/src/test/scala/code/util/APIUtilTest.scala | 12 ++++++------ 10 files changed, 28 insertions(+), 30 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 94a1c2362..7910bf430 100644 --- a/obp-api/src/main/scala/code/api/util/APIUtil.scala +++ b/obp-api/src/main/scala/code/api/util/APIUtil.scala @@ -159,15 +159,13 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ oneYearAgo.getTime() } def DefaultToDate = new Date() - def oneYearAgoFromDate = oneYearAgo(DefaultToDate) + val theEpochTime: Date = new Date(0) // Set epoch time. The Unix epoch is 00:00:00 UTC on 1 January 1970. def formatDate(date : Date) : String = { CustomJsonFormats.losslessFormats.dateFormat.format(date) } - def oneYearAgoFromDateString = formatDate(oneYearAgoFromDate) + def epochTimeString = formatDate(theEpochTime) def DefaultToDateString = formatDate(DefaultToDate) - - val epochTime = new Date(0) // Set epoch time. The Unix epoch is 00:00:00 UTC on 1 January 1970. implicit def errorToJson(error: ErrorMessage): JValue = Extraction.decompose(error) val headers = ("Access-Control-Allow-Origin","*") :: Nil @@ -869,7 +867,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ case (_, Full(right)) => parseObpStandardDate(right.head) case _ => - Full(epochTime) // Set epoch time. The Unix epoch is 00:00:00 UTC on 1 January 1970. + Full(theEpochTime) // Set epoch time. The Unix epoch is 00:00:00 UTC on 1 January 1970. } date.map(OBPFromDate(_)) } @@ -1922,7 +1920,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ val dateParameter = if(containsDate){ s""" | - |* from_date=DATE => example value: $oneYearAgoFromDateString. NOTE! The default value is one year ago ($oneYearAgoFromDateString). + |* from_date=DATE => example value: $epochTimeString. NOTE! The default value is one year ago ($epochTimeString). |* to_date=DATE => example value: $DefaultToDateString. NOTE! The default value is now ($DefaultToDateString). | |Date format parameter: $DateWithMs($DateWithMsExampleString) ==> time zone is UTC. diff --git a/obp-api/src/main/scala/code/api/util/OBPParam.scala b/obp-api/src/main/scala/code/api/util/OBPParam.scala index bcb475ae2..6c01526b9 100644 --- a/obp-api/src/main/scala/code/api/util/OBPParam.scala +++ b/obp-api/src/main/scala/code/api/util/OBPParam.scala @@ -53,7 +53,7 @@ object OBPQueryParam { val FROM_DATE = "fromDate" val TO_DATE = "toDate" - private val defaultFromDate = APIUtil.DateWithMsFormat.format(APIUtil.oneYearAgoFromDate) + private val defaultFromDate = APIUtil.DateWithMsFormat.format(APIUtil.theEpochTime) private val defaultToDate = APIUtil.DateWithMsFormat.format(APIUtil.DefaultToDate) def getLimit(queryParams: List[OBPQueryParam]) : Int = { 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 23008d59c..f62c23c21 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 @@ -258,13 +258,13 @@ trait APIMethods310 { | |Should be able to filter on the following fields | - |eg: /management/metrics/top-apis?from_date=$oneYearAgoFromDateString&to_date=$DefaultToDateString&consumer_id=5 + |eg: /management/metrics/top-apis?from_date=$epochTimeString&to_date=$DefaultToDateString&consumer_id=5 |&user_id=66214b8e-259e-44ad-8868-3eb47be70646&implemented_by_partial_function=getTransactionsForBankAccount |&implemented_in_version=v3.0.0&url=/obp/v3.0.0/banks/gh.29.uk/accounts/8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0/owner/transactions |&verb=GET&anon=false&app_name=MapperPostman |&exclude_app_names=API-EXPLORER,API-Manager,SOFI,null | - |1 from_date (defaults to the one year ago): eg:from_date=$oneYearAgoFromDateString + |1 from_date (defaults to the one year ago): eg:from_date=$epochTimeString | |2 to_date (defaults to the current date) eg:to_date=$DefaultToDateString | @@ -344,14 +344,14 @@ trait APIMethods310 { | |Should be able to filter on the following fields | - |e.g.: /management/metrics/top-consumers?from_date=$oneYearAgoFromDateString&to_date=$DefaultToDateString&consumer_id=5 + |e.g.: /management/metrics/top-consumers?from_date=$epochTimeString&to_date=$DefaultToDateString&consumer_id=5 |&user_id=66214b8e-259e-44ad-8868-3eb47be70646&implemented_by_partial_function=getTransactionsForBankAccount |&implemented_in_version=v3.0.0&url=/obp/v3.0.0/banks/gh.29.uk/accounts/8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0/owner/transactions |&verb=GET&anon=false&app_name=MapperPostman |&exclude_app_names=API-EXPLORER,API-Manager,SOFI,null |&limit=100 | - |1 from_date (defaults to the one year ago): eg:from_date=$oneYearAgoFromDateString + |1 from_date (defaults to the one year ago): eg:from_date=$epochTimeString | |2 to_date (defaults to the current date) eg:to_date=$DefaultToDateString | diff --git a/obp-api/src/main/scala/code/bankconnectors/akka/AkkaConnector_vDec2018.scala b/obp-api/src/main/scala/code/bankconnectors/akka/AkkaConnector_vDec2018.scala index 09e0cfa69..806f1ab05 100644 --- a/obp-api/src/main/scala/code/bankconnectors/akka/AkkaConnector_vDec2018.scala +++ b/obp-api/src/main/scala/code/bankconnectors/akka/AkkaConnector_vDec2018.scala @@ -268,7 +268,7 @@ object AkkaConnector_vDec2018 extends Connector with AkkaConnectorActorInit { override def getTransactions(bankId: BankId, accountId: AccountId, callContext: Option[CallContext], queryParams: List[OBPQueryParam]): OBPReturnType[Box[List[Transaction]]] = { val limit = queryParams.collect { case OBPLimit(value) => value }.headOption.getOrElse(100) val offset = queryParams.collect { case OBPOffset(value) => value }.headOption.getOrElse(0) - val fromDate = queryParams.collect { case OBPFromDate(date) => APIUtil.DateWithMsFormat.format(date) }.headOption.getOrElse(APIUtil.oneYearAgoFromDate.toString) + val fromDate = queryParams.collect { case OBPFromDate(date) => APIUtil.DateWithMsFormat.format(date) }.headOption.getOrElse(APIUtil.theEpochTime.toString) val toDate = queryParams.collect { case OBPToDate(date) => APIUtil.DateWithMsFormat.format(date) }.headOption.getOrElse(APIUtil.DefaultToDate.toString) val req = OutBoundGetTransactions(callContext.map(_.toOutboundAdapterCallContext).get, bankId, accountId, limit, offset, fromDate, toDate) 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 7f047f0e3..967317129 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 @@ -763,7 +763,7 @@ trait KafkaMappedConnector_vSept2018 extends Connector with KafkaHelper with Mdc // TODO Get rid on these param lookups and document. override def getTransactionsLegacy(bankId: BankId, accountId: AccountId, callContext: Option[CallContext], queryParams: List[OBPQueryParam]) = saveConnectorMetric { val limit = queryParams.collect { case OBPLimit(value) => value }.headOption.getOrElse(100) - val fromDate = queryParams.collect { case OBPFromDate(date) => date.toString }.headOption.getOrElse(APIUtil.oneYearAgoFromDate.toString) + val fromDate = queryParams.collect { case OBPFromDate(date) => date.toString }.headOption.getOrElse(APIUtil.theEpochTime.toString) val toDate = queryParams.collect { case OBPToDate(date) => date.toString }.headOption.getOrElse(APIUtil.DefaultToDate.toString) // TODO What about offset? @@ -825,7 +825,7 @@ trait KafkaMappedConnector_vSept2018 extends Connector with KafkaHelper with Mdc CacheKeyFromArguments.buildCacheKey {Caching.memoizeSyncWithProvider(Some(cacheKey.toString()))(transactionsTTL second) { val limit = queryParams.collect { case OBPLimit(value) => value}.headOption.getOrElse(100) - val fromDate = queryParams.collect { case OBPFromDate(date) => date.toString}.headOption.getOrElse(APIUtil.oneYearAgoFromDate.toString) + val fromDate = queryParams.collect { case OBPFromDate(date) => date.toString}.headOption.getOrElse(APIUtil.theEpochTime.toString) val toDate = queryParams.collect { case OBPToDate(date) => date.toString}.headOption.getOrElse(APIUtil.DefaultToDate.toString) val req = OutboundGetTransactions( diff --git a/obp-api/src/test/scala/code/api/v1_4_0/TransactionRequestsTest.scala b/obp-api/src/test/scala/code/api/v1_4_0/TransactionRequestsTest.scala index d9376b06d..1c28ea02f 100644 --- a/obp-api/src/test/scala/code/api/v1_4_0/TransactionRequestsTest.scala +++ b/obp-api/src/test/scala/code/api/v1_4_0/TransactionRequestsTest.scala @@ -127,7 +127,7 @@ class TransactionRequestsTest extends V140ServerSetup with DefaultUsers { //check that we created a new transaction (since no challenge) request = (v1_4Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@(user1) - response = makeGetRequest(request, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) + response = makeGetRequest(request, List(("from_date", APIUtil.epochTimeString),("to_date", APIUtil.DefaultToDateString))) Then("we should get a 200 ok code") response.code should equal(200) diff --git a/obp-api/src/test/scala/code/api/v2_0_0/TransactionRequestsTest.scala b/obp-api/src/test/scala/code/api/v2_0_0/TransactionRequestsTest.scala index d6fe861ee..17f67c0d2 100644 --- a/obp-api/src/test/scala/code/api/v2_0_0/TransactionRequestsTest.scala +++ b/obp-api/src/test/scala/code/api/v2_0_0/TransactionRequestsTest.scala @@ -287,7 +287,7 @@ class TransactionRequestsTest extends V200ServerSetup with DefaultUsers { //check that we created a new transaction (since no challenge) request = (v1_4Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@(user1) - response = makeGetRequest(request, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) + response = makeGetRequest(request, List(("from_date", APIUtil.epochTimeString),("to_date", APIUtil.DefaultToDateString))) Then("we should get a 200 ok code") response.code should equal(200) @@ -551,7 +551,7 @@ class TransactionRequestsTest extends V200ServerSetup with DefaultUsers { //check that we created a new transaction (since no challenge) request = (v2_0Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@(user1) - response = makeGetRequest(request, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) + response = makeGetRequest(request, List(("from_date", APIUtil.epochTimeString),("to_date", APIUtil.DefaultToDateString))) Then("we should get a 200 ok code") response.code should equal(200) @@ -586,7 +586,7 @@ class TransactionRequestsTest extends V200ServerSetup with DefaultUsers { //check that we created a new transaction (since no challenge) request = (v2_0Request / "banks" / testBank.bankId.value / "accounts" / toAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@(user1) - response = makeGetRequest(request, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) + response = makeGetRequest(request, List(("from_date", APIUtil.epochTimeString),("to_date", APIUtil.DefaultToDateString))) Then("we should get a 200 ok code") response.code should equal(200) @@ -989,7 +989,7 @@ class TransactionRequestsTest extends V200ServerSetup with DefaultUsers { //check that we created a new transaction (since no challenge) request = (v2_0Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@(user1) - response = makeGetRequest(request, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) + response = makeGetRequest(request, List(("from_date", APIUtil.epochTimeString),("to_date", APIUtil.DefaultToDateString))) Then("we should get a 200 ok code") response.code should equal(200) @@ -1024,7 +1024,7 @@ class TransactionRequestsTest extends V200ServerSetup with DefaultUsers { //check that we created a new transaction request = (v2_0Request / "banks" / testBank.bankId.value / "accounts" / toAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@(user1) - response = makeGetRequest(request, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) + response = makeGetRequest(request, List(("from_date", APIUtil.epochTimeString),("to_date", APIUtil.DefaultToDateString))) Then("we should get a 200 ok code") response.code should equal(200) diff --git a/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala b/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala index b3f5a0aa8..a93f14bf1 100644 --- a/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala +++ b/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala @@ -171,7 +171,7 @@ class TransactionRequestsTest extends V210ServerSetup with DefaultUsers { var getTransReqRequest = (v2_1Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transaction-requests").GET <@ (user1) - def makeGetTransReqRequest = makeGetRequest(getTransReqRequest, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) + def makeGetTransReqRequest = makeGetRequest(getTransReqRequest, List(("from_date", APIUtil.epochTimeString),("to_date", APIUtil.DefaultToDateString))) def checkAllGetTransReqResBodyField(getTransactionRequestResponse: APIResponse, withChellenge: Boolean): Unit = { Then("we should get a 200 created code") @@ -207,7 +207,7 @@ class TransactionRequestsTest extends V210ServerSetup with DefaultUsers { */ var getTransactionRequest = (v2_1Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@ (user1) - def makeGetTransRequest = makeGetRequest(getTransactionRequest, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) + def makeGetTransRequest = makeGetRequest(getTransactionRequest, List(("from_date", APIUtil.epochTimeString),("to_date", APIUtil.DefaultToDateString))) def checkAllGetTransResBodyField(getTransactionResponse: APIResponse, withChellenge: Boolean): Unit = { Then("we should get a 200 created code") 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 b128080fd..e0d1b0e5f 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 @@ -231,7 +231,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers { var getTransReqRequest = (v4_0_0_Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transaction-requests").GET <@ (user1) - def makeGetTransReqRequest = makeGetRequest(getTransReqRequest, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) + def makeGetTransReqRequest = makeGetRequest(getTransReqRequest, List(("from_date", APIUtil.epochTimeString),("to_date", APIUtil.DefaultToDateString))) def checkAllGetTransReqResBodyField(getTransactionRequestResponse: APIResponse, withChellenge: Boolean): Unit = { Then("we should get a 200 created code") @@ -267,7 +267,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers { */ var getTransactionRequest = (v4_0_0_Request / "banks" / testBank.bankId.value / "accounts" / fromAccount.accountId.value / CUSTOM_OWNER_VIEW_ID / "transactions").GET <@ (user1) - def makeGetTransRequest = makeGetRequest(getTransactionRequest, List(("from_date", APIUtil.oneYearAgoFromDateString),("to_date", APIUtil.DefaultToDateString))) + def makeGetTransRequest = makeGetRequest(getTransactionRequest, List(("from_date", APIUtil.epochTimeString),("to_date", APIUtil.DefaultToDateString))) def checkAllGetTransResBodyField(getTransactionResponse: APIResponse, withChellenge: Boolean): Unit = { Then("we should get a 200 created code") diff --git a/obp-api/src/test/scala/code/util/APIUtilTest.scala b/obp-api/src/test/scala/code/util/APIUtilTest.scala index dc8296a5d..ad1a4ede7 100644 --- a/obp-api/src/test/scala/code/util/APIUtilTest.scala +++ b/obp-api/src/test/scala/code/util/APIUtilTest.scala @@ -30,7 +30,7 @@ package code.util import java.time.format.DateTimeFormatter import java.time.{ZoneId, ZonedDateTime} import java.util.Date -import code.api.util.APIUtil.{DateWithMsFormat, oneYearAgoFromDate, DefaultToDate, _} +import code.api.util.APIUtil.{DateWithMsFormat, theEpochTime, DefaultToDate, _} import code.api.util.ErrorMessages._ import code.api.util._ import code.setup.PropsReset @@ -45,7 +45,7 @@ class APIUtilTest extends FeatureSpec with Matchers with GivenWhenThen with Prop val endDateString = DefaultToDateString val endDateStringWrongFormat = "Wrong Date Format" val inputStringDateFormat = DateWithMsFormat - val DefaultFromDateString = APIUtil.oneYearAgoFromDateString + val DefaultFromDateString = APIUtil.epochTimeString val DefaultToDateString = APIUtil.DefaultToDateString val startDateObject: Date = DateWithMsFormat.parse(DefaultFromDateString) val endDateObject: Date = DateWithMsFormat.parse(DefaultToDateString) @@ -235,11 +235,11 @@ class APIUtilTest extends FeatureSpec with Matchers with GivenWhenThen with Prop scenario("test the wrong case: wrong name (wrongName) in HTTPParam") { val httpParams: List[HTTPParam] = List(HTTPParam("wrongName", List(s"$DateWithMsExampleString"))) - val startTime = OBPFromDate(epochTime) + val startTime = OBPFromDate(theEpochTime) val returnValue = getFromDate(httpParams) returnValue shouldBe a[Full[OBPFromDate]] - val currentTime = OBPFromDate(oneYearAgoFromDate) + val currentTime = OBPFromDate(theEpochTime) val beWithinTolerance = be >= startTime and be <= currentTime returnValue.orNull should beWithinTolerance } @@ -247,11 +247,11 @@ class APIUtilTest extends FeatureSpec with Matchers with GivenWhenThen with Prop scenario("test the wrong case: wrong name (wrongName) and wrong values (wrongValue) in HTTPParam") { val httpParams: List[HTTPParam] = List(HTTPParam("wrongName", List("wrongValue"))) - val startTime = OBPFromDate(epochTime) + val startTime = OBPFromDate(theEpochTime) val returnValue = getFromDate(httpParams) returnValue shouldBe a[Full[OBPFromDate]] - val currentTime = OBPFromDate(oneYearAgoFromDate) + val currentTime = OBPFromDate(theEpochTime) val beWithinTolerance = be >= startTime and be <= currentTime returnValue.orNull should beWithinTolerance }