- Add reference from Transaction to the RecurringTransaction that created the transaction
- Add BANK as valid booking target of a BANK account - Remove EXPENSE as valid booking target of a LIABILITY account - Fix a bug in the getMultiplierFromAccount and getMultiplierToAccount methods that caused the result to always be the default case - Adjust init SQL script to reflect the changes done - Add a sample integration test - Add unit tests for the RuleService - Configure surefire plugin - Add a profile for integration test running
This commit is contained in:
@@ -18,6 +18,8 @@ public class Transaction {
|
||||
private Date date;
|
||||
private String description;
|
||||
private Long amount;
|
||||
@OneToOne(fetch = FetchType.EAGER)
|
||||
private RecurringTransaction recurringTransaction;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
@@ -62,4 +64,12 @@ public class Transaction {
|
||||
public void setAmount(Long amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public RecurringTransaction getRecurringTransaction() {
|
||||
return recurringTransaction;
|
||||
}
|
||||
|
||||
public void setRecurringTransaction(RecurringTransaction recurringTransaction) {
|
||||
this.recurringTransaction = recurringTransaction;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ public class RuleService implements InitializingBean {
|
||||
// The key is the from account and the value is a list of valid
|
||||
// to accounts for this from account
|
||||
this.bookingRules.put(INCOME, Arrays.asList(BANK, CASH));
|
||||
this.bookingRules.put(BANK, Arrays.asList(CASH, EXPENSE, LIABILITY));
|
||||
this.bookingRules.put(BANK, Arrays.asList(BANK, CASH, EXPENSE, LIABILITY));
|
||||
this.bookingRules.put(CASH, Arrays.asList(BANK, EXPENSE, LIABILITY));
|
||||
this.bookingRules.put(EXPENSE, Collections.emptyList());
|
||||
this.bookingRules.put(LIABILITY, Arrays.asList(BANK, CASH, EXPENSE));
|
||||
this.bookingRules.put(LIABILITY, Arrays.asList(BANK, CASH));
|
||||
this.bookingRules.put(START, Arrays.asList(BANK, CASH, LIABILITY));
|
||||
}
|
||||
|
||||
@@ -51,19 +51,21 @@ public class RuleService implements InitializingBean {
|
||||
// There is no multiplier if the from account is an EXPENSE account because
|
||||
// it's not a valid from account type
|
||||
|
||||
if (INCOME.equals(fromAccount)) {
|
||||
final AccountType accountType = fromAccount.getType();
|
||||
|
||||
if (INCOME.equals(accountType)) {
|
||||
return 1L;
|
||||
}
|
||||
else if (BANK.equals(fromAccount)) {
|
||||
else if (BANK.equals(accountType)) {
|
||||
return -1L;
|
||||
}
|
||||
else if (CASH.equals(fromAccount)) {
|
||||
else if (CASH.equals(accountType)) {
|
||||
return -1L;
|
||||
}
|
||||
else if (LIABILITY.equals(fromAccount)) {
|
||||
else if (LIABILITY.equals(accountType)) {
|
||||
return 1L;
|
||||
}
|
||||
else if (START.equals(fromAccount)) {
|
||||
else if (START.equals(accountType)) {
|
||||
return 1L;
|
||||
}
|
||||
|
||||
@@ -83,16 +85,18 @@ public class RuleService implements InitializingBean {
|
||||
// There are no multipliers for INCOME and START accounts
|
||||
// because they are not valid to account types
|
||||
|
||||
if (BANK.equals(toAccount)) {
|
||||
final AccountType accountType = toAccount.getType();
|
||||
|
||||
if (BANK.equals(accountType)) {
|
||||
return 1L;
|
||||
}
|
||||
else if (CASH.equals(toAccount)) {
|
||||
else if (CASH.equals(accountType)) {
|
||||
return 1L;
|
||||
}
|
||||
else if (LIABILITY.equals(toAccount)) {
|
||||
else if (LIABILITY.equals(accountType)) {
|
||||
return -1L;
|
||||
}
|
||||
else if (EXPENSE.equals(toAccount)) {
|
||||
else if (EXPENSE.equals(accountType)) {
|
||||
return 1L;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ CREATE TABLE account (
|
||||
status VARCHAR(255) NOT NULL,
|
||||
current_balance BIGINT NOT NULL,
|
||||
|
||||
CONSTRAINT c_u_name_key UNIQUE ("key")
|
||||
CONSTRAINT un_account_name_key UNIQUE ("key")
|
||||
);
|
||||
|
||||
INSERT INTO account ("key", type, status, current_balance)
|
||||
@@ -25,20 +25,7 @@ VALUES ('accounts.cash', 'CASH', 'OPEN', 0);
|
||||
INSERT INTO account ("key", type, status, current_balance)
|
||||
VALUES ('accounts.start', 'START', 'OPEN', 0);
|
||||
|
||||
-- Transaction table
|
||||
CREATE TABLE "transaction" ( --escape keyword "transaction"
|
||||
id BIGINT NOT NULL PRIMARY KEY IDENTITY,
|
||||
from_account_id BIGINT NOT NULL,
|
||||
to_account_id BIGINT NOT NULL,
|
||||
"date" DATE NOT NULL, --escape keyword "date"
|
||||
description VARCHAR(1000),
|
||||
amount BIGINT NOT NULL,
|
||||
|
||||
CONSTRAINT fk_from_account FOREIGN KEY (from_account_id) REFERENCES account (id),
|
||||
CONSTRAINT fk_to_account FOREIGN KEY (to_account_id) REFERENCES account (id)
|
||||
);
|
||||
|
||||
-- Transaction table
|
||||
-- Recurring transaction table
|
||||
CREATE TABLE recurring_transaction (
|
||||
id BIGINT NOT NULL PRIMARY KEY IDENTITY,
|
||||
from_account_id BIGINT NOT NULL,
|
||||
@@ -50,6 +37,21 @@ CREATE TABLE recurring_transaction (
|
||||
last_occurrence DATE,
|
||||
holiday_weekend_type VARCHAR(255) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_from_account FOREIGN KEY (from_account_id) REFERENCES account (id),
|
||||
CONSTRAINT fk_to_account FOREIGN KEY (to_account_id) REFERENCES account (id)
|
||||
CONSTRAINT fk_recurring_transaction_from_account FOREIGN KEY (from_account_id) REFERENCES account (id),
|
||||
CONSTRAINT fk_recurring_transaction_to_account FOREIGN KEY (to_account_id) REFERENCES account (id)
|
||||
);
|
||||
|
||||
-- Transaction table
|
||||
CREATE TABLE "transaction" ( --escape keyword "transaction"
|
||||
id BIGINT NOT NULL PRIMARY KEY IDENTITY,
|
||||
from_account_id BIGINT NOT NULL,
|
||||
to_account_id BIGINT NOT NULL,
|
||||
"date" DATE NOT NULL, --escape keyword "date"
|
||||
description VARCHAR(1000),
|
||||
amount BIGINT NOT NULL,
|
||||
recurring_transaction_id BIGINT NOT NULL,
|
||||
|
||||
CONSTRAINT fk_transaction_from_account FOREIGN KEY (from_account_id) REFERENCES account (id),
|
||||
CONSTRAINT fk_transaction_to_account FOREIGN KEY (to_account_id) REFERENCES account (id),
|
||||
CONSTRAINT fk_transaction_recurring_transaction FOREIGN KEY (recurring_transaction_id) REFERENCES recurring_transaction (id)
|
||||
);
|
||||
Reference in New Issue
Block a user