Fixed loading the renamed TanMethodTypes

This commit is contained in:
dankito 2024-10-18 05:34:02 +02:00
parent 98f15d3a8d
commit b5116604c1
1 changed files with 18 additions and 2 deletions

View File

@ -37,6 +37,13 @@ expect fun createSqlDriverDriver(dbName: String, schema: SqlSchema<QueryResult.A
open class SqliteBankingRepository : BankingRepository { open class SqliteBankingRepository : BankingRepository {
companion object {
val TanMethodTypesToMigrate = mapOf(
"ChipTanManuell" to TanMethodType.ChipTanManual.name,
"ChipTanFlickercode" to TanMethodType.ChipTanFlickerCode.name
)
}
private val schema = BankmeisterDb.Schema private val schema = BankmeisterDb.Schema
private val sqlDriver = createSqlDriverDriver("Bankmeister.db", schema, 2L) private val sqlDriver = createSqlDriverDriver("Bankmeister.db", schema, 2L)
@ -251,7 +258,7 @@ open class SqliteBankingRepository : BankingRepository {
bankId, bankId,
displayName, displayName,
mapToEnum(type, TanMethodType.entries), mapToEnum(type, TanMethodType.entries, TanMethodTypesToMigrate),
identifier, identifier,
mapToInt(maxTanInputLength), mapToInt(maxTanInputLength),
mapToEnum(allowedTanFormat, AllowedTanFormat.entries), mapToEnum(allowedTanFormat, AllowedTanFormat.entries),
@ -597,7 +604,16 @@ open class SqliteBankingRepository : BankingRepository {
private fun <E : Enum<E>> mapEnum(enum: Enum<E>): String = enum.name private fun <E : Enum<E>> mapEnum(enum: Enum<E>): String = enum.name
private fun <E : Enum<E>> mapToEnum(enumName: String, values: EnumEntries<E>): E = private fun <E : Enum<E>> mapToEnum(enumName: String, values: EnumEntries<E>): E =
values.first { it.name == enumName } try {
values.first { it.name == enumName }
} catch (e: Throwable) {
log.error(e) { "Could not map enumName '$enumName' to ${values.first()::class}"}
throw e
}
private fun <E : Enum<E>> mapToEnum(enumName: String, values: EnumEntries<E>, enumNamesToMigrate: Map<String, String>): E =
mapToEnum(enumNamesToMigrate[enumName] ?: enumName, values)
private fun <E : Enum<E>> mapToEnumNullable(enumName: String, values: EnumEntries<E>): E? { private fun <E : Enum<E>> mapToEnumNullable(enumName: String, values: EnumEntries<E>): E? {
val mapped = values.firstOrNull { it.name == enumName } val mapped = values.firstOrNull { it.name == enumName }