Various fixes and additions all over the tree
Add a method to obtain all active recurring transactions. Add and adjust unit and integration tests.
This commit is contained in:
@@ -29,16 +29,6 @@ public class AccountController {
|
||||
return this.accountService.getAll();
|
||||
}
|
||||
|
||||
@RequestMapping("getAccountTypes")
|
||||
public Iterable<String> getAccountTypes() {
|
||||
return this.accountService.getAccountTypes();
|
||||
}
|
||||
|
||||
@RequestMapping("getAccountStatus")
|
||||
public Iterable<String> getAccountStatus() {
|
||||
return this.accountService.getAccountStatus();
|
||||
}
|
||||
|
||||
@RequestMapping("createAccount")
|
||||
public ResponseEntity createAccount(String key, String type) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
|
||||
@@ -26,6 +26,11 @@ public class RecurringTransactionController {
|
||||
return this.recurringTransactionService.getAll();
|
||||
}
|
||||
|
||||
@RequestMapping("getAllActive")
|
||||
public Iterable<RecurringTransaction> getAllActive() {
|
||||
return this.recurringTransactionService.getAllActive();
|
||||
}
|
||||
|
||||
@RequestMapping("getAllForAccount")
|
||||
public Iterable<RecurringTransaction> getAllForAccount(String accountKey) {
|
||||
return this.recurringTransactionService.getAllForAccount(accountKey);
|
||||
|
||||
@@ -6,7 +6,11 @@ import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
public interface RecurringTransactionRepository extends CrudRepository<RecurringTransaction, Long> {
|
||||
Iterable<RecurringTransaction> findRecurringTransactionsByFromAccountOrToAccount(Account fromAccount, Account toAccount);
|
||||
|
||||
Iterable<RecurringTransaction> findByLastOccurrenceIsNullOrLastOccurrenceGreaterThanEqual(LocalDate lastOccurrence);
|
||||
}
|
||||
|
||||
@@ -40,20 +40,6 @@ public class AccountService {
|
||||
return this.accountRepository.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all possible account types as specified by the {@link AccountType} enumeration, never <code>null</code>
|
||||
*/
|
||||
public Iterable<String> getAccountTypes() {
|
||||
return Arrays.stream(AccountType.values()).map(AccountType::name).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all possible account status as specified by the {@link AccountStatus} enumeration, never <code>null</code>
|
||||
*/
|
||||
public Iterable<String> getAccountStatus() {
|
||||
return Arrays.stream(AccountStatus.values()).map(AccountStatus::name).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method saves the given account. It either updates the account if it already exists or inserts
|
||||
* it if it's new.
|
||||
|
||||
@@ -47,6 +47,11 @@ public class RecurringTransactionService {
|
||||
return this.recurringTransactionRepository.findAll();
|
||||
}
|
||||
|
||||
public Iterable<RecurringTransaction> getAllActive() {
|
||||
return this.recurringTransactionRepository
|
||||
.findByLastOccurrenceIsNullOrLastOccurrenceGreaterThanEqual(LocalDate.now());
|
||||
}
|
||||
|
||||
public Iterable<RecurringTransaction> getAllForAccount(String accountKey) {
|
||||
final Account account = this.accountService.getAccountByKey(accountKey);
|
||||
|
||||
@@ -73,8 +78,8 @@ public class RecurringTransactionService {
|
||||
|
||||
// Visible for unit tests
|
||||
/* package */ Iterable<RecurringTransaction> getAllDueToday(LocalDate now) {
|
||||
// TODO filter for lastOccurrence not in the past
|
||||
final Iterable<RecurringTransaction> allRecurringTransactions = this.recurringTransactionRepository.findAll();
|
||||
final Iterable<RecurringTransaction> allRecurringTransactions = this.recurringTransactionRepository
|
||||
.findByLastOccurrenceIsNullOrLastOccurrenceGreaterThanEqual(now);
|
||||
|
||||
//@formatter:off
|
||||
return IterableUtils.toList(allRecurringTransactions).stream()
|
||||
@@ -332,19 +337,19 @@ public class RecurringTransactionService {
|
||||
response = ResponseReason.MISSING_AMOUNT;
|
||||
} else if (amount == 0L) {
|
||||
response = ResponseReason.AMOUNT_ZERO;
|
||||
} else if (holidayWeekendType == null) {
|
||||
} else if (StringUtils.isEmpty(holidayWeekendType)) {
|
||||
response = ResponseReason.MISSING_HOLIDAY_WEEKEND_TYPE;
|
||||
} else if (!HolidayWeekendType.isValidType(holidayWeekendType)) {
|
||||
response = ResponseReason.INVALID_HOLIDAY_WEEKEND_TYPE;
|
||||
} else if (intervalType == null) {
|
||||
} else if (StringUtils.isEmpty(intervalType)) {
|
||||
response = ResponseReason.MISSING_INTERVAL_TYPE;
|
||||
} else if (!IntervalType.isValidType(intervalType)) {
|
||||
response = ResponseReason.INVALID_INTERVAL_TYPE;
|
||||
} else if (firstOccurrence == null) {
|
||||
} else if (StringUtils.isEmpty(firstOccurrence)) {
|
||||
response = ResponseReason.MISSING_FIRST_OCCURRENCE;
|
||||
}
|
||||
|
||||
if (response == null && firstOccurrence != null) {
|
||||
if (response == null && StringUtils.isNotEmpty(firstOccurrence)) {
|
||||
try {
|
||||
LocalDate.parse(firstOccurrence, DateTimeFormatter.ofPattern(this.financerConfig.getDateFormat()));
|
||||
} catch (DateTimeParseException e) {
|
||||
@@ -352,7 +357,7 @@ public class RecurringTransactionService {
|
||||
}
|
||||
}
|
||||
|
||||
if (response == null && lastOccurrence != null) {
|
||||
if (response == null && StringUtils.isNotEmpty(lastOccurrence)) {
|
||||
try {
|
||||
LocalDate.parse(lastOccurrence, DateTimeFormatter.ofPattern(this.financerConfig.getDateFormat()));
|
||||
} catch (DateTimeParseException e) {
|
||||
@@ -407,8 +412,7 @@ public class RecurringTransactionService {
|
||||
|
||||
try {
|
||||
this.recurringTransactionRepository.deleteById(Long.valueOf(recurringTransactionId));
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Could not delete recurring transaction!", e);
|
||||
|
||||
response = ResponseReason.UNKNOWN_ERROR;
|
||||
|
||||
@@ -4,8 +4,10 @@ import de.financer.ResponseReason;
|
||||
import de.financer.config.FinancerConfig;
|
||||
import de.financer.dba.TransactionRepository;
|
||||
import de.financer.model.Account;
|
||||
import de.financer.model.AccountType;
|
||||
import de.financer.model.RecurringTransaction;
|
||||
import de.financer.model.Transaction;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -87,8 +89,17 @@ public class TransactionService {
|
||||
|
||||
fromAccount.setCurrentBalance(fromAccount.getCurrentBalance() + (this.ruleService
|
||||
.getMultiplierFromAccount(fromAccount) * amount));
|
||||
toAccount.setCurrentBalance(toAccount.getCurrentBalance() + (this.ruleService
|
||||
.getMultiplierToAccount(toAccount) * amount));
|
||||
|
||||
// Special case: if we do the initial bookings, and the booking is to introduce a liability,
|
||||
// the balance of the liability account must increase
|
||||
if (AccountType.START.equals(fromAccount.getType()) && AccountType.LIABILITY.equals(toAccount.getType())) {
|
||||
toAccount.setCurrentBalance(toAccount.getCurrentBalance() + (this.ruleService
|
||||
.getMultiplierToAccount(toAccount) * amount * -1));
|
||||
}
|
||||
else {
|
||||
toAccount.setCurrentBalance(toAccount.getCurrentBalance() + (this.ruleService
|
||||
.getMultiplierToAccount(toAccount) * amount));
|
||||
}
|
||||
|
||||
this.transactionRepository.save(transaction);
|
||||
|
||||
@@ -158,9 +169,9 @@ public class TransactionService {
|
||||
response = ResponseReason.MISSING_AMOUNT;
|
||||
} else if (amount == 0L) {
|
||||
response = ResponseReason.AMOUNT_ZERO;
|
||||
} else if (date == null) {
|
||||
} else if (StringUtils.isEmpty(date)) {
|
||||
response = ResponseReason.MISSING_DATE;
|
||||
} else if (date != null) {
|
||||
} else if (StringUtils.isNotEmpty(date)) {
|
||||
try {
|
||||
LocalDate.parse(date, DateTimeFormatter.ofPattern(this.financerConfig.getDateFormat()));
|
||||
} catch (DateTimeParseException e) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
spring.profiles.active=@activeProfiles@
|
||||
|
||||
server.servlet.context-path=/financer-server
|
||||
server.port=8089
|
||||
|
||||
spring.jpa.hibernate.ddl-auto=validate
|
||||
|
||||
|
||||
Reference in New Issue
Block a user