Implemented BankFinder
This commit is contained in:
parent
564e7cef7d
commit
8fd0df7c18
|
@ -0,0 +1,61 @@
|
|||
package net.dankito.fints.banks
|
||||
|
||||
import net.dankito.fints.model.BankInfo
|
||||
import net.dankito.utils.serialization.JacksonJsonSerializer
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
|
||||
open class BankFinder {
|
||||
|
||||
companion object {
|
||||
private val log = LoggerFactory.getLogger(BankFinder::class.java)
|
||||
}
|
||||
|
||||
|
||||
protected var bankListField: List<BankInfo>? = null
|
||||
|
||||
|
||||
open fun findBankByBankCode(query: String): List<BankInfo> {
|
||||
return getBankList().filter { it.bankCode.startsWith(query) }
|
||||
}
|
||||
|
||||
open fun findBankByNameBankCodeOrCity(query: String): List<BankInfo> {
|
||||
val queryLowerCase = query.toLowerCase()
|
||||
|
||||
return getBankList().filter {
|
||||
it.name.toLowerCase().contains(queryLowerCase)
|
||||
|| it.bankCode.startsWith(query)
|
||||
|| it.city.contains(queryLowerCase)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
open fun getBankList(): List<BankInfo> {
|
||||
bankListField?.let {
|
||||
return it
|
||||
}
|
||||
|
||||
val bankList = loadBankList()
|
||||
|
||||
this.bankListField = bankList
|
||||
|
||||
return bankList
|
||||
}
|
||||
|
||||
protected open fun loadBankList(): List<BankInfo> {
|
||||
try {
|
||||
val inputStream = BankFinder::class.java.classLoader.getResourceAsStream("BankList.json")
|
||||
|
||||
val bankListString = inputStream.bufferedReader().readText()
|
||||
|
||||
JacksonJsonSerializer().deserializeList(bankListString, BankInfo::class.java)?.let {
|
||||
return it
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
log.error("Could not load bank list", e)
|
||||
}
|
||||
|
||||
return listOf()
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,43 @@
|
|||
package net.dankito.fints.banks
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Test
|
||||
|
||||
class BankFinderTest {
|
||||
|
||||
private val underTest = BankFinder()
|
||||
|
||||
|
||||
@Test
|
||||
fun findBankByBankCode_10000000() {
|
||||
|
||||
// when
|
||||
val result = underTest.findBankByBankCode("10000000")
|
||||
|
||||
// then
|
||||
assertThat(result).hasSize(1)
|
||||
assertThat(result[0].name).isEqualTo("Bundesbank")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findBankByNameBankCodeOrCity_starnberg() {
|
||||
|
||||
// when
|
||||
val result = underTest.findBankByNameBankCodeOrCity("starnberg")
|
||||
|
||||
// then
|
||||
assertThat(result).hasSize(66)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findBankByNameBankCodeOrCity_mizUh() {
|
||||
|
||||
// when
|
||||
val result = underTest.findBankByNameBankCodeOrCity("mizUh")
|
||||
|
||||
// then
|
||||
assertThat(result).hasSize(1)
|
||||
assertThat(result[0].name).isEqualTo("Mizuho Bank Filiale Düsseldorf")
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue