|
1 | 1 | package code.bankaccountbalance |
2 | 2 |
|
3 | 3 | import code.model.dataAccess.MappedBankAccount |
| 4 | +import code.util.Helper.MdcLoggable |
4 | 5 | import code.util.{Helper, MappedUUID} |
5 | 6 | import com.openbankproject.commons.model.{AccountId, BalanceId, BankAccountBalanceTrait, BankId} |
| 7 | +import net.liftweb.common.{Empty, Failure, Full} |
6 | 8 | import net.liftweb.mapper._ |
7 | 9 | import net.liftweb.util.Helpers.tryo |
8 | 10 |
|
9 | 11 | import java.util.Date |
10 | 12 |
|
11 | | -class BankAccountBalance extends BankAccountBalanceTrait with KeyedMapper[String, BankAccountBalance] with CreatedUpdated { |
| 13 | +class BankAccountBalance extends BankAccountBalanceTrait |
| 14 | + with KeyedMapper[String, BankAccountBalance] |
| 15 | + with CreatedUpdated |
| 16 | + with MdcLoggable { |
12 | 17 |
|
13 | 18 | override def getSingleton = BankAccountBalance |
14 | 19 |
|
@@ -36,8 +41,29 @@ class BankAccountBalance extends BankAccountBalanceTrait with KeyedMapper[String |
36 | 41 | override def balanceType: String = BalanceType.get |
37 | 42 | override def balanceAmount: BigDecimal = Helper.smallestCurrencyUnitToBigDecimal(BalanceAmount.get, foreignMappedBankAccountCurrency) |
38 | 43 | override def lastChangeDateTime: Option[Date] = Some(this.updatedAt.get) |
39 | | - override def referenceDate: Option[String] = Option(ReferenceDate.get).map(_.toString) |
40 | | - |
| 44 | + override def referenceDate: Option[String] = { |
| 45 | + net.liftweb.util.Helpers.tryo { |
| 46 | + Option(ReferenceDate.get) match { |
| 47 | + case Some(d) => Some(d.toString) |
| 48 | + case None => |
| 49 | + logger.warn(s"ReferenceDate is missing for BalanceId=${BalanceId_.get}, AccountId=${AccountId_.get}, BankId=${BankId_.get}") |
| 50 | + None |
| 51 | + } |
| 52 | + } match { |
| 53 | + case Full(v) => v |
| 54 | + case f: Failure => |
| 55 | + // extract throwable if present; otherwise create one from the message |
| 56 | + val t = f.exception.openOr(new RuntimeException(f.msg)) |
| 57 | + logger.error(s"Error while retrieving referenceDate for BalanceId=${BalanceId_.get}, AccountId=${AccountId_.get}, BankId=${BankId_.get}: ${f.msg}", t) |
| 58 | + None |
| 59 | + case Empty => |
| 60 | + // Defensive: treat as missing |
| 61 | + None |
| 62 | + } |
| 63 | + } |
41 | 64 | } |
42 | 65 |
|
43 | | -object BankAccountBalance extends BankAccountBalance with KeyedMetaMapper[String, BankAccountBalance] with CreatedUpdated {} |
| 66 | +object BankAccountBalance |
| 67 | + extends BankAccountBalance |
| 68 | + with KeyedMetaMapper[String, BankAccountBalance] |
| 69 | + with CreatedUpdated {} |
0 commit comments