#48: BankAccountBalanceDao.kt

plugins/org.projectforge.plugins.banking/src/main/kotlin/org/projectforge/plugins/banking/BankAccountBalanceDao.kt

Path: ./plugins/org.projectforge.plugins.banking/.../BankAccountBalanceDao.kt · Type: Kotlin source (DAO) · Lines: 84 · Source: GitHub

84 lines · 54 code · 23 comments · 7 blank

What it does

The Data Access Object for bank account balances — the first actual Kotlin source file in the documentation. Follows the standard ProjectForge DAO pattern: GPLv3 header (lines 1-22), extends BaseDao<T> (line 38), implements hasAccess() for authorization (lines 42-69), provides a named query method getByTimePeriod() (lines 75-83). Annotated @Service for Spring dependency injection.

Architecture

38 class BankAccountBalanceDao : BaseDao<BankAccountBalanceDO>(BankAccountBalanceDO::class.java)

BaseDao is ProjectForge's core persistence framework — provides CRUD operations, access checking infrastructure, and named query execution. Every entity in the system has a matching DAO that extends this base class, overriding hasAccess() and newInstance().

Authorization chain (lines 42-69)

42 override fun hasAccess(user, obj, oldObj, operationType, throwException): Boolean {
49   val bankAccount = obj?.bankAccount
50   if (obj != null && bankAccount == null)
51     return BaseDOPersistenceService.returnFalseOrThrowException(...)  ← #1: missing bank account
58   if (!accessChecker.isLoggedInUserMemberOfGroup(ProjectForgeGroup.FINANCE_GROUP))
60     return BaseDOPersistenceService.returnFalseOrThrowException(...)  ← #2: not in finance group
68   return bankAccountDao.hasAccess(user, bankAccount, oldBankAccount, ...) ← #3: delegate to parent
69 }

Three-step access check:

StepCheckFailure message
1Object has a bank account reference"Bank account not given."
2User is member of FINANCE_GROUP"User not member of financial staff."
3Delegates to bankAccountDao.hasAccess() — checks access to the parent bank account objectAs determined by BankAccountDao

Named query (lines 75-83)

75 fun getByTimePeriod(accountId: Int): List<BankAccountBalanceDO> {
76   val account = bankAccountDao.find(accountId)!!
78   return persistenceService.executeNamedQuery(
79     BankAccountBalanceDO.FIND_BY_BANK_ACCOUNT, ...)
Line 76: !! operator — will throw NullPointerException if bankAccountDao.find(accountId) returns null (bank account not found). The comment says "For access checking" — the find() call implicitly validates the account exists before fetching balances.

Key takeaways