Assignment: Create REST application for sending money between accounts without full-blown frameworks like Spring.
Note 1: If not specified module is written in Kotlin.
Note 2: JavaDoc or KotlinDoc is intentionally not present.
- contains main CLI class
BankApplication
- generated
.jar
has manifest with main class specified - you can run it withjava -jar bank.jar
command - default host is
localhost
- default port is
8080
- default H2 DB directory is current dir
.
- run it with
--help
parameter to see all parameters - module also contains End-to-end integration test
- contains main business logic (usually with start of DB transaction)
BankInitializer
to initialize bank internal accounts for Top-up and Withdrawal actionsAccountService
for working with accounts itselfcreatePersonalAccount
- for creatingPERSONAL
account with specifiedname
and zerobalance
createTopUpAccount
- for creating bank internalTOP_UP
accountcreateWithdrawalAccount
- for creating bank internalWITHDRAWAL
accountfindAccount
- for finding account by it'sid
findTopUpAccount
- for finding most suitable top-up accountfindWithdrawalAccount
- for finding most suitable withdrawal account
PaymentOrderService
for creating payment requests and returning data about payment ordersreceivePaymentRequest
- for creating payment requests between accountstopUpRequest
- for topping up accountswithdrawalRequest
- for withdrawal requestspaymentOrderState
- to get state of particular payment orderlistItemsForPersonalAccounts
- to list all payment order of specified personal accountlistItemsToProcess
- to list requests that could be processed (they are inRECEIVED
state)
TransactionService
for some helper methodscalculateBalance
- to calculate balance of account from credit/debit side of amount (to check if account'sbalance
is correct)findAccountTransactions
- to list all transactions of specified account
Coordinator
is used to coordinate which payment orders and when they will be processed- it polls database for data to process and sends them to
Transactor
- it polls database for data to process and sends them to
Transactor
is used to process payment request- it uses optimistic locking to fail when concurrent access to data is detected by
VERSION
database column - when concurrent processing occurs only first commit wins
- it uses optimistic locking to fail when concurrent access to data is detected by
- contain DAO classes to access all three DB tables
account
table for storing information about account and it's balancepayment-order
for storing payment requests between accountstransaction
for storing actual money transactions
- JOOQ is used as SQL abstraction
- also optimistic locking is used for keeping data consistency when money transfer occurred
- contains domain data classes
Account
- for storing information about account like it'stype
,name
,dateOpened
, and currentbalance
- types are
PERSONAL
,TOP_UP
for cash/card top-ups,WITHDRAWAL
for eg. ATM withdrawals
- types are
PaymentOrder
- for storing information about payment order request likefromAccount
andtoAccount
transfer,amount
of money to transfer,state
of order, anddateCreated
when order has been created- states are
RECEIVED
,OK
, andNO_FUNDS
when personal account does not have enough funds to finish transaction
- states are
Transaction
- for actual transaction. It contains reference topaymentOrder
anddateTransacted
information.- fields
fromAccount
,toAccount
, andamount
are kind of duplicates to similar filed inPaymentOrder
and are here for demo purposes
- fields
- contains Jersey definition of REST endpoints
- also defines
ApplicationServletContextListener
which is used as starting point for application-context- inspired by Spring-web module
RestApplication
registers endpoints into Jersey context and configures Jackson JSON (de)serialization.- every endpoint has to implement
Endpoint
interface withservletContext
field which is used to lookup application context - endpoints are:
POST /api/account
- to create accountGET /api/account/{id}
- to get info about accountGET /api/account/{id}/calculated-balance
- to get calculated balance for accountGET /api/account/{id}/transactions
- to find all transaction for particular accountPOST /payment-order/transfer
- to create transfer request between accountsPOST /payment-order/top-up
- to create account top-up requestPOST /payment-order/withdrawal
- to create account withdrawal requestGET /payment-order/{id}/state
- to find state of particular payment order
- inspired by Spring's IOC
- contains interface
ApplicationContext
with definition of all beans - beans uses constructor injection
- beans are lazy created because of
.start()
and.stop()
nature of context itself
- written in Java
- wraps Hikari connection pool and H2 database using
Database
interface- before use
.start()
method has to be called - to free database resources
.stop()
has to be called
- before use
- method
.getDataSource()
is used with cooperation ofTransactional
interface from "tx module" - this module also contains
database.sql
file with DDL scripts- and generated JOOQ meta-model from database
- written in Java and implementation is inspired by Spring's
TransactionTemplate
class - main interface is
Transactional
which runs actions inside current transaction - transaction is bound to current connection from Hikari pool and saved to
ThreadLocal
holder - when we do not have current transaction/connection bound to thread new one is obtained from pool
- and returned after end of helper callback methods
- written in Java and inspired by Spring-Boot
- how it internally run selected embedded Servlet container
- wraps Undertow HTTP server into
RestServer
class with.start()
and.stop()
methods - using constructor you can specify:
host
(localhost
is used as default)requestedPort
(when0
random port is selected)servletContextListener
- usually contain application contextapplicationClass
- Jersey application class to start Rest endpoints