Implemented BankingModelService to filter out duplicates in retrieved AccountTransactions
This commit is contained in:
parent
85b66aa040
commit
7f60e02340
|
@ -0,0 +1,24 @@
|
||||||
|
package net.codinux.banking.client.service
|
||||||
|
|
||||||
|
import net.codinux.banking.client.model.AccountTransaction
|
||||||
|
|
||||||
|
open class BankingModelService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It's not possible to retrieve only new transactions from bank server (almost no bank implements HKKAN job). So
|
||||||
|
* for updating account transactions we start at the date of latest account transactions retrieval time (e.g.
|
||||||
|
* transactions have at last been fetched at 01. September 12:00, then there may have been some other transactions
|
||||||
|
* been booked on September 1st after 12:00 o'clock).
|
||||||
|
*
|
||||||
|
* Therefore retrieved account transactions may contain transactions that we already have locally. This method filters
|
||||||
|
* from [retrievedTransactions] those already in [existingTransactions] and returns only that ones, that are not in
|
||||||
|
* [existingTransactions].
|
||||||
|
*/
|
||||||
|
open fun findNewTransactions(retrievedTransactions: List<AccountTransaction>, existingTransactions: List<AccountTransaction>): List<AccountTransaction> {
|
||||||
|
val existingTransactionsByIdentifier = existingTransactions.associateBy { it.identifier }
|
||||||
|
val existingTransactionsIdentifiers = existingTransactionsByIdentifier.keys
|
||||||
|
|
||||||
|
return retrievedTransactions.filter { transaction -> existingTransactionsIdentifiers.contains(transaction.identifier) == false }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue