refactor/added new fields: max_number_of_transactions and max_total_amount to CounterpartyLimit

This commit is contained in:
hongwei 2024-12-06 09:13:16 +01:00
parent 8e41e7124f
commit d44bb7f6f3
6 changed files with 71 additions and 45 deletions

View File

@ -506,7 +506,7 @@ object ErrorMessages {
val CreateCounterpartyLimitError = "OBP-30261: Could not create the counterparty limit."
val UpdateCounterpartyLimitError = "OBP-30262: Could not update the counterparty limit."
val GetCounterpartyLimitError = "OBP-30263: Counterparty limit not found. Please specify a valid value for BANK_ID, ACCOUNT_ID, VIEW_ID or COUNTERPARTY_ID."
val CounterpartyLimitAlreadyExists = "OBP-30264: Counterparty limit already exists. Please specify a different value for BANK_ID, ACCOUNT_ID, VIEW_ID or COUNTERPARTY_ID."
val CounterpartyLimitAlreadyExists = "OBP-30264: Counterparty limit already exists. Please specify a different value for BANK_ID, ACCOUNT_ID, VIEW_ID or COUNTERPARTY_ID."
val DeleteCounterpartyLimitError = "OBP-30265: Could not delete the counterparty limit."
val CustomViewAlreadyExistsError = "OBP-30266: The custom view is already exists."
val UserDoesNotHavePermission = "OBP-30267: The user does not have the permission:"

View File

@ -12431,11 +12431,6 @@ object APIMethods400 extends RestHelper with APIMethods400 {
isValidCurrencyISOCode(transDetailsJson.value.currency)
}
// Prevent default value for transaction request type (at least).
_ <- Helper.booleanToFuture(s"${InvalidISOCurrencyCode} Current input is: '${transDetailsJson.value.currency}'", cc=callContext) {
isValidCurrencyISOCode(transDetailsJson.value.currency)
}
(createdTransactionRequest, callContext) <- transactionRequestTypeValue match {
case REFUND => {
for {
@ -12692,16 +12687,16 @@ object APIMethods400 extends RestHelper with APIMethods400 {
_ <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError maxSingleAmount is $maxSingleAmount ${fromAccount.currency}, " +
s"but current transaction body amount is ${transactionRequestBodyCounterparty.value.amount} ${transactionRequestBodyCounterparty.value.currency}, " +
s"which is $currentTransactionAmountWithFxApplied ${fromAccount.currency}. ", cc = callContext) {
BigDecimal(maxSingleAmount) >= currentTransactionAmountWithFxApplied
maxSingleAmount >= currentTransactionAmountWithFxApplied
}
_ <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError maxMonthlyAmount is $maxSingleAmount, but current monthly amount is ${sumOfTransactionsFromAccountToCounterpartyMonthly.amount}", cc = callContext) {
BigDecimal(maxMonthlyAmount) >= BigDecimal(sumOfTransactionsFromAccountToCounterpartyMonthly.amount)
maxMonthlyAmount >= BigDecimal(sumOfTransactionsFromAccountToCounterpartyMonthly.amount)
}
_ <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError maxNumberOfMonthlyTransactions is $maxSingleAmount, but current count of monthly transactions is ${countOfTransactionsFromAccountToCounterpartyMonthly}", cc = callContext) {
maxNumberOfMonthlyTransactions >= countOfTransactionsFromAccountToCounterpartyMonthly
}
_ <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError maxYearlyAmount is $maxYearlyAmount, but current yearly amount is ${sumOfTransactionsFromAccountToCounterpartyYearly.amount}", cc = callContext) {
BigDecimal(maxYearlyAmount) >= BigDecimal(sumOfTransactionsFromAccountToCounterpartyYearly.amount)
maxYearlyAmount >= BigDecimal(sumOfTransactionsFromAccountToCounterpartyYearly.amount)
}
result <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError maxNumberOfYearlyTransactions is $maxNumberOfYearlyTransactions, but current count of yearly transaction is ${countOfTransactionsFromAccountToCounterpartyYearly}", cc = callContext) {
maxNumberOfYearlyTransactions >= countOfTransactionsFromAccountToCounterpartyYearly

View File

@ -2893,9 +2893,12 @@ trait APIMethods510 {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "views" :: ViewId(viewId) ::"counterparties" :: CounterpartyId(counterpartyId) ::"limits" :: Nil JsonPost json -> _ => {
cc => implicit val ec = EndpointContext(Some(cc))
for {
postCounterpartyLimitV510 <- NewStyle.function.tryons(s"$InvalidJsonFormat The Json body should be the ${classOf[AtmJsonV510]}", 400, cc.callContext) {
postCounterpartyLimitV510 <- NewStyle.function.tryons(s"$InvalidJsonFormat The Json body should be the ${classOf[PostCounterpartyLimitV510]}", 400, cc.callContext) {
json.extract[PostCounterpartyLimitV510]
}
_ <- Helper.booleanToFuture(s"${InvalidISOCurrencyCode} Current input is: '${postCounterpartyLimitV510.currency}'", cc=cc.callContext) {
isValidCurrencyISOCode(postCounterpartyLimitV510.currency)
}
(counterpartyLimitBox, callContext) <- Connector.connector.vend.getCounterpartyLimit(
bankId.value,
accountId.value,
@ -2921,7 +2924,6 @@ trait APIMethods510 {
cc.callContext
)
} yield {
(counterpartyLimit.toJValue, HttpCode.`201`(callContext))
}
}
@ -2952,9 +2954,12 @@ trait APIMethods510 {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "views" :: ViewId(viewId) ::"counterparties" :: CounterpartyId(counterpartyId) ::"limits" :: Nil JsonPut json -> _ => {
cc => implicit val ec = EndpointContext(Some(cc))
for {
postCounterpartyLimitV510 <- NewStyle.function.tryons(s"$InvalidJsonFormat The Json body should be the ${classOf[AtmJsonV510]}", 400, cc.callContext) {
postCounterpartyLimitV510 <- NewStyle.function.tryons(s"$InvalidJsonFormat The Json body should be the ${classOf[PostCounterpartyLimitV510]}", 400, cc.callContext) {
json.extract[PostCounterpartyLimitV510]
}
_ <- Helper.booleanToFuture(s"${InvalidISOCurrencyCode} Current input is: '${postCounterpartyLimitV510.currency}'", cc=cc.callContext) {
isValidCurrencyISOCode(postCounterpartyLimitV510.currency)
}
(counterpartyLimit,callContext) <- NewStyle.function.createOrUpdateCounterpartyLimit(
bankId.value,
accountId.value,

View File

@ -7,11 +7,14 @@ import net.liftweb.util.Helpers.tryo
import com.openbankproject.commons.ExecutionContext.Implicits.global
import net.liftweb.json
import net.liftweb.json.Formats
import net.liftweb.json.JsonAST.{JValue,JString}
import net.liftweb.json.JsonAST.{JString, JValue}
import net.liftweb.json.JsonDSL._
import scala.concurrent.Future
import com.openbankproject.commons.model.CounterpartyLimitTrait
import java.math.MathContext
object MappedCounterpartyLimitProvider extends CounterpartyLimitProviderTrait {
def getCounterpartyLimit(
@ -105,22 +108,34 @@ class CounterpartyLimit extends CounterpartyLimitTrait with LongKeyedMapper[Coun
object Currency extends MappedString(this, 255)
object MaxSingleAmount extends MappedInt(this) {
override def defaultValue = -1
object MaxSingleAmount extends MappedDecimal(this, MathContext.DECIMAL64, 10){
override def defaultValue = BigDecimal(0) // Default value for Amount
}
object MaxMonthlyAmount extends MappedInt(this) {
override def defaultValue = -1
object MaxMonthlyAmount extends MappedDecimal(this, MathContext.DECIMAL64, 10){
override def defaultValue = BigDecimal(0) // Default value for Amount
}
object MaxNumberOfMonthlyTransactions extends MappedInt(this) {
override def defaultValue = -1
}
object MaxYearlyAmount extends MappedInt(this) {
override def defaultValue = -1
object MaxYearlyAmount extends MappedDecimal(this, MathContext.DECIMAL64, 10){
override def defaultValue = BigDecimal(0) // Default value for Amount
}
object MaxNumberOfYearlyTransactions extends MappedInt(this) {
override def defaultValue = -1
}
object MaxTotalAmount extends MappedDecimal(this, MathContext.DECIMAL64, 10){
override def defaultValue = BigDecimal(0) // Default value for Amount
}
object MaxNumberOfTransactions extends MappedInt(this) {
override def defaultValue = -1
}
def counterpartyLimitId: String = CounterpartyLimitId.get
def bankId: String = BankId.get
@ -129,13 +144,15 @@ class CounterpartyLimit extends CounterpartyLimitTrait with LongKeyedMapper[Coun
def counterpartyId: String = CounterpartyId.get
def currency: String = Currency.get
def maxSingleAmount: Int = MaxSingleAmount.get
def maxMonthlyAmount: Int = MaxMonthlyAmount.get
def maxSingleAmount: BigDecimal = MaxSingleAmount.get
def maxMonthlyAmount: BigDecimal = MaxMonthlyAmount.get
def maxNumberOfMonthlyTransactions: Int = MaxNumberOfMonthlyTransactions.get
def maxYearlyAmount: Int = MaxYearlyAmount.get
def maxYearlyAmount: BigDecimal = MaxYearlyAmount.get
def maxNumberOfYearlyTransactions: Int = MaxNumberOfYearlyTransactions.get
def maxTotalAmount: BigDecimal = MaxTotalAmount.get
def maxNumberOfTransactions: Int = MaxNumberOfTransactions.get
override def toJValue(implicit format: Formats): JValue ={
override def toJValue(implicit format: Formats): JValue = {
("counterparty_limit_id", counterpartyLimitId) ~
("bank_id", bankId) ~
("account_id",accountId) ~
@ -146,7 +163,9 @@ class CounterpartyLimit extends CounterpartyLimitTrait with LongKeyedMapper[Coun
("max_monthly_amount", maxMonthlyAmount) ~
("max_number_of_monthly_transactions", maxNumberOfMonthlyTransactions) ~
("max_yearly_amount", maxYearlyAmount) ~
("max_number_of_yearly_transactions", maxNumberOfYearlyTransactions)
("max_number_of_yearly_transactions", maxNumberOfYearlyTransactions) ~
("max_total_amount", maxTotalAmount) ~
("max_number_of_transactions", maxNumberOfTransactions)
}
}

View File

@ -33,22 +33,11 @@ import com.openbankproject.commons.model.enums._
import com.openbankproject.commons.util.{ReflectUtils, optional}
import net.liftweb.json.JsonAST.{JObject, JValue}
import net.liftweb.json.{Formats, JInt, JString}
import net.liftweb.json.JsonDSL._
import java.lang
import scala.collection.immutable.List
import scala.reflect.runtime.universe._
//import code.customeraddress.CustomerAddress
//import code.bankconnectors.InboundAccountCommon
//import code.branches.Branches.BranchT
//import code.context.UserAuthContext
//import code.meetings.Meeting
//import code.taxresidence.TaxResidence
//import code.productcollectionitem.ProductCollectionItem
//import code.productcollection.ProductCollection
//import code.atms.Atms.AtmT
//import code.productattribute.ProductAttribute.ProductAttribute
//import code.accountattribute.AccountAttribute.AccountAttribute
//import code.accountapplication.AccountApplication
abstract class Converter[T, D <% T: TypeTag]{
//this method declared as common method to avoid conflict with Predf#$confirms
@ -621,13 +610,29 @@ case class CounterpartyLimitTraitCommons(
viewId: String,
counterpartyId: String,
currency: String,
maxSingleAmount: Int,
maxMonthlyAmount: Int,
maxSingleAmount: BigDecimal,
maxMonthlyAmount: BigDecimal,
maxNumberOfMonthlyTransactions: Int,
maxYearlyAmount: Int,
maxNumberOfYearlyTransactions: Int
maxYearlyAmount: BigDecimal,
maxNumberOfYearlyTransactions: Int,
maxTotalAmount: BigDecimal,
maxNumberOfTransactions: Int,
) extends CounterpartyLimitTrait {
override def toJValue(implicit format: Formats): JValue = ???
override def toJValue(implicit format: Formats): JValue = {
("counterparty_limit_id", counterpartyLimitId) ~
("bank_id", bankId) ~
("account_id",accountId) ~
("view_id",viewId) ~
("counterparty_id",counterpartyId) ~
("currency",currency) ~
("max_single_amount", maxSingleAmount) ~
("max_monthly_amount", maxMonthlyAmount) ~
("max_number_of_monthly_transactions", maxNumberOfMonthlyTransactions) ~
("max_yearly_amount", maxYearlyAmount) ~
("max_number_of_yearly_transactions", maxNumberOfYearlyTransactions) ~
("max_total_amount", maxTotalAmount) ~
("max_number_of_transactions", maxNumberOfTransactions)
}
}
object CounterpartyLimitTraitCommons extends Converter[CounterpartyLimitTrait, CounterpartyLimitTraitCommons]

View File

@ -663,11 +663,13 @@ trait CounterpartyLimitTrait extends JsonAble{
def counterpartyId: String
def currency: String
def maxSingleAmount: Int
def maxMonthlyAmount: Int
def maxSingleAmount: BigDecimal
def maxMonthlyAmount: BigDecimal
def maxNumberOfMonthlyTransactions: Int
def maxYearlyAmount: Int
def maxYearlyAmount: BigDecimal
def maxNumberOfYearlyTransactions: Int
def maxTotalAmount: BigDecimal
def maxNumberOfTransactions: Int
}
trait EndpointTagT {