Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ object JSONFactory_MXOF_0_0_1 extends CustomJsonFormats {
final val BANK_ATTRIBUTE_LICENSE = "ATM_META_LICENCE"
final val BANK_ATTRIBUTE_TERMSOFUSE = "ATM_META_TERMS_OF_USE"

def createGetAtmsResponse (banks: List[Bank], atms: List[AtmT], attributes:List[BankAttribute]) :GetAtmsResponseJson = {
def createGetAtmsResponse (banks: List[Bank], atms: List[AtmT], attributes:List[BankAttributeTrait]) :GetAtmsResponseJson = {
def access24HoursIndicator (atm: AtmT) = {
atm.OpeningTimeOnMonday.equals(Some("00:00")) && atm.ClosingTimeOnMonday.equals(Some("23:59"))
atm.OpeningTimeOnTuesday.equals(Some("00:00")) && atm.ClosingTimeOnTuesday.equals(Some("23:59"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5482,6 +5482,33 @@ object SwaggerDefinitionsJSON {
max_total_amount = maxTotalAmountExample.value,
max_number_of_transactions = maxNumberOfTransactionsExample.value.toInt
)

val counterpartyLimitStatus = CounterpartyLimitStatus(
currency_status = currencyExample.value,
max_monthly_amount_status = maxSingleAmountExample.value,
max_number_of_monthly_transactions_status = maxNumberOfMonthlyTransactionsExample.value.toInt,
max_yearly_amount_status = maxYearlyAmountExample.value,
max_number_of_yearly_transactions_status = maxNumberOfYearlyTransactionsExample.value.toInt,
max_total_amount_status = maxTotalAmountExample.value,
max_number_of_transactions_status = maxNumberOfTransactionsExample.value.toInt
)

val counterpartyLimitStatusV510 = CounterpartyLimitStatusV510(
counterparty_limit_id = counterpartyLimitIdExample.value,
bank_id = bankIdExample.value,
account_id = accountIdExample.value,
view_id = viewIdExample.value,
counterparty_id = counterpartyIdExample.value,
currency = currencyExample.value,
max_single_amount = maxSingleAmountExample.value,
max_monthly_amount = maxMonthlyAmountExample.value,
max_number_of_monthly_transactions = maxNumberOfMonthlyTransactionsExample.value.toInt,
max_yearly_amount = maxYearlyAmountExample.value,
max_number_of_yearly_transactions = maxNumberOfYearlyTransactionsExample.value.toInt,
max_total_amount = maxTotalAmountExample.value,
max_number_of_transactions = maxNumberOfTransactionsExample.value.toInt,
status = counterpartyLimitStatus
)

val atmsJsonV510 = AtmsJsonV510(
atms = List(atmJsonV510)
Expand Down
4 changes: 2 additions & 2 deletions obp-api/src/main/scala/code/api/util/NewStyle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1813,9 +1813,9 @@ object NewStyle extends MdcLoggable{
}
}

def getBankAttributesByBank(bank: BankId,callContext: Option[CallContext]): OBPReturnType[List[BankAttribute]] = {
def getBankAttributesByBank(bankId: BankId,callContext: Option[CallContext]): OBPReturnType[List[BankAttributeTrait]] = {
Connector.connector.vend.getBankAttributesByBank(
bank: BankId,
bankId: BankId,
callContext: Option[CallContext]
) map {
i => (connectorEmptyResponse(i._1, callContext), i._2)
Expand Down
4 changes: 2 additions & 2 deletions obp-api/src/main/scala/code/api/v3_0_0/JSONFactory3.0.0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,8 @@ object JSONFactory300{
}

//stated -- Transaction relevant methods /////
def createTransactionsJson(moderatedTansactionsWithAttributes: List[ModeratedTransactionWithAttributes]) : TransactionsJsonV300 = {
TransactionsJsonV300(moderatedTansactionsWithAttributes.map(t => createTransactionJSON(t.transaction, t.transactionAttributes)))
def createTransactionsJson(moderatedTransactionsWithAttributes: List[ModeratedTransactionWithAttributes]) : TransactionsJsonV300 = {
TransactionsJsonV300(moderatedTransactionsWithAttributes.map(t => createTransactionJSON(t.transaction, t.transactionAttributes)))
}

def createTransactionJSON(transaction : ModeratedTransaction, transactionAttributes: List[TransactionAttribute]) : TransactionJsonV300 = {
Expand Down
24 changes: 12 additions & 12 deletions obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12526,23 +12526,23 @@ object APIMethods400 extends RestHelper with APIMethods400 {
s"which is $currentTransactionAmountWithFxApplied ${fromAccount.currency}. ", cc = callContext) {
maxSingleAmount >= currentTransactionAmountWithFxApplied
}
_ <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError max_monthly_amount is $maxSingleAmount, but current monthly amount is ${sumOfTransactionsFromAccountToCounterpartyMonthly.amount}", cc = callContext) {
maxMonthlyAmount >= BigDecimal(sumOfTransactionsFromAccountToCounterpartyMonthly.amount)
_ <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError max_monthly_amount is $maxMonthlyAmount, but current monthly amount is ${BigDecimal(sumOfTransactionsFromAccountToCounterpartyMonthly.amount)+currentTransactionAmountWithFxApplied}", cc = callContext) {
maxMonthlyAmount >= BigDecimal(sumOfTransactionsFromAccountToCounterpartyMonthly.amount)+currentTransactionAmountWithFxApplied
}
_ <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError max_number_of_monthly_transactions is $maxSingleAmount, but current count of monthly transactions is ${countOfTransactionsFromAccountToCounterpartyMonthly}", cc = callContext) {
maxNumberOfMonthlyTransactions >= countOfTransactionsFromAccountToCounterpartyMonthly
_ <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError max_number_of_monthly_transactions is $maxNumberOfMonthlyTransactions, but current count of monthly transactions is ${countOfTransactionsFromAccountToCounterpartyMonthly+1}", cc = callContext) {
maxNumberOfMonthlyTransactions >= countOfTransactionsFromAccountToCounterpartyMonthly+1
}
_ <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError max_yearly_amount is $maxYearlyAmount, but current yearly amount is ${sumOfTransactionsFromAccountToCounterpartyYearly.amount}", cc = callContext) {
maxYearlyAmount >= BigDecimal(sumOfTransactionsFromAccountToCounterpartyYearly.amount)
_ <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError max_yearly_amount is $maxYearlyAmount, but current yearly amount is ${BigDecimal(sumOfTransactionsFromAccountToCounterpartyYearly.amount)+currentTransactionAmountWithFxApplied}", cc = callContext) {
maxYearlyAmount >= BigDecimal(sumOfTransactionsFromAccountToCounterpartyYearly.amount)+currentTransactionAmountWithFxApplied
}
result <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError max_number_of_yearly_transactions is $maxNumberOfYearlyTransactions, but current count of yearly transaction is ${countOfTransactionsFromAccountToCounterpartyYearly}", cc = callContext) {
maxNumberOfYearlyTransactions >= countOfTransactionsFromAccountToCounterpartyYearly
result <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError max_number_of_yearly_transactions is $maxNumberOfYearlyTransactions, but current count of yearly transaction is ${countOfTransactionsFromAccountToCounterpartyYearly+1}", cc = callContext) {
maxNumberOfYearlyTransactions >= countOfTransactionsFromAccountToCounterpartyYearly+1
}
_ <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError max_total_amount is $maxTotalAmount, but current amount is ${sumOfAllTransactionsFromAccountToCounterparty.amount}", cc = callContext) {
maxTotalAmount >= BigDecimal(sumOfAllTransactionsFromAccountToCounterparty.amount)
_ <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError max_total_amount is $maxTotalAmount, but current amount is ${BigDecimal(sumOfAllTransactionsFromAccountToCounterparty.amount)+currentTransactionAmountWithFxApplied}", cc = callContext) {
maxTotalAmount >= BigDecimal(sumOfAllTransactionsFromAccountToCounterparty.amount)+currentTransactionAmountWithFxApplied
}
result <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError max_number_of_transactions is $maxNumberOfTransactions, but current count of all transactions is ${countOfAllTransactionsFromAccountToCounterparty}", cc = callContext) {
maxNumberOfTransactions >= countOfAllTransactionsFromAccountToCounterparty
result <- Helper.booleanToFuture(s"$CounterpartyLimitValidationError max_number_of_transactions is $maxNumberOfTransactions, but current count of all transactions is ${countOfAllTransactionsFromAccountToCounterparty+1}", cc = callContext) {
maxNumberOfTransactions >= countOfAllTransactionsFromAccountToCounterparty+1
}
}yield{
result
Expand Down
7 changes: 3 additions & 4 deletions obp-api/src/main/scala/code/api/v4_0_0/JSONFactory4.0.0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import code.api.v3_1_0.{AccountAttributeResponseJson, CustomerJsonV310, JSONFact
import code.apicollection.ApiCollectionTrait
import code.apicollectionendpoint.ApiCollectionEndpointTrait
import code.atms.Atms.Atm
import code.bankattribute.BankAttribute
import code.consent.MappedConsent
import code.entitlement.Entitlement
import code.loginattempts.LoginAttempt
Expand Down Expand Up @@ -1200,7 +1199,7 @@ object JSONFactory400 {

}

def createBankJSON400(bank: Bank, attributes: List[BankAttribute] = Nil): BankJson400 = {
def createBankJSON400(bank: Bank, attributes: List[BankAttributeTrait] = Nil): BankJson400 = {
val obp = BankRoutingJsonV121("OBP", bank.bankId.value)
val bic = BankRoutingJsonV121("BIC", bank.swiftBic)
val routings = bank.bankRoutingScheme match {
Expand Down Expand Up @@ -1814,7 +1813,7 @@ object JSONFactory400 {
value = productAttribute.value,
is_active = productAttribute.isActive
)
def createBankAttributeJson(bankAttribute: BankAttribute): BankAttributeResponseJsonV400 =
def createBankAttributeJson(bankAttribute: BankAttributeTrait): BankAttributeResponseJsonV400 =
BankAttributeResponseJsonV400(
bank_id = bankAttribute.bankId.value,
bank_attribute_id = bankAttribute.bankAttributeId,
Expand All @@ -1823,7 +1822,7 @@ object JSONFactory400 {
value = bankAttribute.value,
is_active = bankAttribute.isActive
)
def createBankAttributesJson(bankAttributes: List[BankAttribute]): BankAttributesResponseJsonV400 =
def createBankAttributesJson(bankAttributes: List[BankAttributeTrait]): BankAttributesResponseJsonV400 =
BankAttributesResponseJsonV400(bankAttributes.map(createBankAttributeJson))


Expand Down
14 changes: 6 additions & 8 deletions obp-api/src/main/scala/code/api/v5_0_0/JSONFactory5.0.0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,17 @@ import code.api.v1_3_0.JSONFactory1_3_0.{cardActionsToString, createAccountJson,
import code.api.v1_3_0.{PinResetJSON, ReplacementJSON}
import code.api.v1_4_0.JSONFactory1_4_0.{CustomerFaceImageJson, MetaJsonV140}
import code.api.v2_1_0.CustomerCreditRatingJSON
import code.api.v3_0_0.{AdapterInfoJsonV300, CustomerAttributeResponseJsonV300, JSONFactory300}
import code.api.v3_1_0.{AccountAttributeResponseJson, AccountBasicV310, CustomerWithAttributesJsonV310, PhysicalCardWithAttributesJsonV310, PostConsentEntitlementJsonV310}
import code.api.v3_0_0.{CustomerAttributeResponseJsonV300, JSONFactory300}
import code.api.v3_1_0.{AccountBasicV310,PostConsentEntitlementJsonV310}
import code.api.v4_0_0.{APIInfoJson400, BankAttributeBankResponseJsonV400, EnergySource400, HostedAt400, HostedBy400}
import code.bankattribute.BankAttribute
import code.consent.ConsentRequest
import com.openbankproject.commons.model.CustomerAccountLinkTrait
import com.openbankproject.commons.model.{AccountAttribute, AccountRouting, AccountRoutingJsonV121, AmountOfMoneyJsonV121, Bank, BankAccount, CardAttribute, CreateViewJson, Customer, CustomerAttribute, InboundAdapterInfoInternal, InboundStatusMessage, PhysicalCardTrait, UpdateViewJSON, User, UserAuthContext, UserAuthContextUpdate, View, ViewBasic}
import com.openbankproject.commons.model.{CustomerAccountLinkTrait,BankAttributeTrait}
import com.openbankproject.commons.model.{AccountAttribute, AccountRoutingJsonV121, AmountOfMoneyJsonV121, Bank, BankAccount, CardAttribute, CreateViewJson, Customer, CustomerAttribute, InboundAdapterInfoInternal,
InboundStatusMessage, PhysicalCardTrait, UpdateViewJSON, User, UserAuthContext, UserAuthContextUpdate, View, ViewBasic}
import com.openbankproject.commons.util.ApiVersion
import net.liftweb.json.JsonAST.JValue
import net.liftweb.util.Helpers

import scala.collection.immutable.List

case class PostBankJson500(
id: Option[String],
bank_code: String,
Expand Down Expand Up @@ -599,7 +597,7 @@ object JSONFactory500 {
)
}

def createBankJSON500(bank: Bank, attributes: List[BankAttribute] = Nil): BankJson500 = {
def createBankJSON500(bank: Bank, attributes: List[BankAttributeTrait] = Nil): BankJson500 = {
val obp = BankRoutingJsonV121("OBP", bank.bankId.value)
val bic = BankRoutingJsonV121("BIC", bank.swiftBic)
val routings = bank.bankRoutingScheme match {
Expand Down
144 changes: 144 additions & 0 deletions obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import net.liftweb.mapper.By
import net.liftweb.util.Helpers.tryo
import net.liftweb.util.{Helpers, StringHelpers}

import java.time.{LocalDate, ZoneId}
import java.util.Date
import scala.collection.immutable.{List, Nil}
import scala.collection.mutable.ArrayBuffer
Expand Down Expand Up @@ -3117,6 +3118,149 @@ trait APIMethods510 {
}
}


staticResourceDocs += ResourceDoc(
getCounterpartyLimitStatus,
implementedInApiVersion,
nameOf(getCounterpartyLimitStatus),
"GET",
"/banks/BANK_ID/accounts/ACCOUNT_ID/views/VIEW_ID/counterparties/COUNTERPARTY_ID/limit-status",
"Get Counterparty Limit Status",
s"""Get Counterparty Limit Status.""",
EmptyBody,
counterpartyLimitStatusV510,
List(
$UserNotLoggedIn,
$BankNotFound,
$BankAccountNotFound,
$UserNoPermissionAccessView,
$CounterpartyNotFoundByCounterpartyId,
InvalidJsonFormat,
UnknownError
),
List(apiTagCounterpartyLimits),
)
lazy val getCounterpartyLimitStatus: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "views" :: ViewId(viewId) ::"counterparties" :: CounterpartyId(counterpartyId) ::"limit-status" :: Nil JsonGet _ => {
cc => implicit val ec = EndpointContext(Some(cc))
for {
(counterpartyLimit, callContext) <- NewStyle.function.getCounterpartyLimit(
bankId.value,
accountId.value,
viewId.value,
counterpartyId.value,
cc.callContext
)
// Get the first day of the current month
firstDayOfMonth: LocalDate = LocalDate.now().withDayOfMonth(1)

// Get the last day of the current month
lastDayOfMonth: LocalDate = LocalDate.now().withDayOfMonth(
LocalDate.now().lengthOfMonth()
)
// Get the first day of the current year
firstDayOfYear: LocalDate = LocalDate.now().withDayOfYear(1)

// Get the last day of the current year
lastDayOfYear: LocalDate = LocalDate.now().withDayOfYear(
LocalDate.now().lengthOfYear()
)

(fromBankAccount, callContext) <- NewStyle.function.getBankAccount(bankId, accountId, callContext)
// Convert LocalDate to Date
zoneId: ZoneId = ZoneId.systemDefault()
firstCurrentMonthDate: Date = Date.from(firstDayOfMonth.atStartOfDay(zoneId).toInstant)
lastCurrentMonthDate: Date = Date.from(lastDayOfMonth.atStartOfDay(zoneId).toInstant)

firstCurrentYearDate: Date = Date.from(firstDayOfYear.atStartOfDay(zoneId).toInstant)
lastCurrentYearDate: Date = Date.from(lastDayOfYear.atStartOfDay(zoneId).toInstant)

defaultFromDate: Date = theEpochTime
defaultToDate: Date = APIUtil.ToDateInFuture

(sumOfTransactionsFromAccountToCounterpartyMonthly, callContext) <- NewStyle.function.getSumOfTransactionsFromAccountToCounterparty(
bankId,
accountId,
counterpartyId,
firstCurrentMonthDate: Date,
lastCurrentMonthDate: Date,
callContext: Option[CallContext]
)

(countOfTransactionsFromAccountToCounterpartyMonthly, callContext) <- NewStyle.function.getCountOfTransactionsFromAccountToCounterparty(
bankId,
accountId,
counterpartyId,
firstCurrentMonthDate: Date,
lastCurrentMonthDate: Date,
callContext: Option[CallContext]
)

(sumOfTransactionsFromAccountToCounterpartyYearly, callContext) <- NewStyle.function.getSumOfTransactionsFromAccountToCounterparty(
bankId,
accountId,
counterpartyId,
firstCurrentYearDate: Date,
lastCurrentYearDate: Date,
callContext: Option[CallContext]
)

(countOfTransactionsFromAccountToCounterpartyYearly, callContext) <- NewStyle.function.getCountOfTransactionsFromAccountToCounterparty(
bankId,
accountId,
counterpartyId,
firstCurrentYearDate: Date,
lastCurrentYearDate: Date,
callContext: Option[CallContext]
)

(sumOfAllTransactionsFromAccountToCounterparty, callContext) <- NewStyle.function.getSumOfTransactionsFromAccountToCounterparty(
bankId,
accountId,
counterpartyId,
defaultFromDate: Date,
defaultToDate: Date,
callContext: Option[CallContext]
)

(countOfAllTransactionsFromAccountToCounterparty, callContext) <- NewStyle.function.getCountOfTransactionsFromAccountToCounterparty(
bankId,
accountId,
counterpartyId,
defaultFromDate: Date,
defaultToDate: Date,
callContext: Option[CallContext]
)

} yield {
(CounterpartyLimitStatusV510(
counterparty_limit_id = counterpartyLimit.counterpartyLimitId: String,
bank_id = counterpartyLimit.bankId: String,
account_id = counterpartyLimit.accountId: String,
view_id = counterpartyLimit.viewId: String,
counterparty_id = counterpartyLimit.counterpartyId: String,
currency = counterpartyLimit.currency: String,
max_single_amount = counterpartyLimit.maxSingleAmount.toString(),
max_monthly_amount = counterpartyLimit.maxMonthlyAmount.toString(),
max_number_of_monthly_transactions = counterpartyLimit.maxNumberOfMonthlyTransactions: Int,
max_yearly_amount = counterpartyLimit.maxYearlyAmount.toString(),
max_number_of_yearly_transactions = counterpartyLimit.maxNumberOfYearlyTransactions: Int,
max_total_amount = counterpartyLimit.maxTotalAmount.toString(),
max_number_of_transactions = counterpartyLimit.maxNumberOfTransactions: Int,
status = CounterpartyLimitStatus(
currency_status = fromBankAccount.currency,
max_monthly_amount_status = sumOfTransactionsFromAccountToCounterpartyMonthly.amount,
max_number_of_monthly_transactions_status = countOfTransactionsFromAccountToCounterpartyMonthly,
max_yearly_amount_status = sumOfTransactionsFromAccountToCounterpartyYearly.amount,
max_number_of_yearly_transactions_status = countOfTransactionsFromAccountToCounterpartyYearly,
max_total_amount_status = sumOfAllTransactionsFromAccountToCounterparty.amount,
max_number_of_transactions_status = countOfAllTransactionsFromAccountToCounterparty
)
), HttpCode.`200`(callContext))
}
}
}

staticResourceDocs += ResourceDoc(
deleteCounterpartyLimit,
implementedInApiVersion,
Expand Down
Loading
Loading