Merge remote-tracking branch 'Simon/develop' into develop

This commit is contained in:
hongwei 2022-10-04 11:13:58 +02:00
commit b3ff1474ff
17 changed files with 47 additions and 38 deletions

View File

@ -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!

View File

@ -159,12 +159,12 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
oneYearAgo.getTime()
}
def DefaultToDate = new Date()
def DefaultFromDate = 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 DefaultFromDateString = formatDate(DefaultFromDate)
def epochTimeString = formatDate(theEpochTime)
def DefaultToDateString = formatDate(DefaultToDate)
implicit def errorToJson(error: ErrorMessage): JValue = Extraction.decompose(error)
@ -867,9 +867,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
case (_, Full(right)) =>
parseObpStandardDate(right.head)
case _ =>
Full(DefaultFromDate)
Full(theEpochTime) // 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))
}
}
@ -1921,7 +1920,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: $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.

View File

@ -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.theEpochTime)
private val defaultToDate = APIUtil.DateWithMsFormat.format(APIUtil.DefaultToDate)
def getLimit(queryParams: List[OBPQueryParam]) : Int = {

View File

@ -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=$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=$DefaultFromDateString
|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=$DefaultFromDateString&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=$DefaultFromDateString
|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
|

View File

@ -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._

View File

@ -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,

View File

@ -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.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)

View File

@ -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.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.DefaultFromDate.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(

View File

@ -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 {

View File

@ -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
@ -13,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
@ -23,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) ::
@ -51,6 +53,13 @@ object DeleteAccountCascade {
By(MappedBankAccount.theAccountId, accountId.value)
)
}
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),
ByList(MappedEntitlement.mUserId, userIds)
)
}
private def deleteCards(accountId: AccountId): Boolean = {
MappedBankAccount.findAll(

View File

@ -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.epochTimeString),("to_date", APIUtil.DefaultToDateString)))
Then("we should get a 200 ok code")
response.code should equal(200)

View File

@ -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.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.DefaultFromDateString),("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.DefaultFromDateString),("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.DefaultFromDateString),("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.DefaultFromDateString),("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)

View File

@ -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.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.DefaultFromDateString),("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")

View File

@ -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)
}
}

View File

@ -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.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.DefaultFromDateString),("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")

View File

@ -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, 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.DefaultFromDateString
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(DefaultFromDate)
val startTime = OBPFromDate(theEpochTime)
val returnValue = getFromDate(httpParams)
returnValue shouldBe a[Full[OBPFromDate]]
val currentTime = OBPFromDate(DefaultFromDate)
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(DefaultFromDate)
val startTime = OBPFromDate(theEpochTime)
val returnValue = getFromDate(httpParams)
returnValue shouldBe a[Full[OBPFromDate]]
val currentTime = OBPFromDate(DefaultFromDate)
val currentTime = OBPFromDate(theEpochTime)
val beWithinTolerance = be >= startTime and be <= currentTime
returnValue.orNull should beWithinTolerance
}

View File

@ -688,9 +688,6 @@ object JsonUtils {
transformField(jValue){
case (jField, path) =>
buffer += (jField.name -> jField.value.toString)
if(jField.name == "face_image") {
1
}
jField
}