Removed database folder from BankingPresenter. Had to implement the logic to ensure folder exists in other places then.
This commit is contained in:
parent
e1d08d3304
commit
26da9448ab
|
@ -62,32 +62,40 @@ class BankingModule(private val applicationContext: Context) {
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named(DataFolderKey)
|
@Named(DataFolderKey)
|
||||||
fun provideDataFolder(applicationContext: Context) : File {
|
fun provideDataFolder(applicationContext: Context) : File {
|
||||||
return File(applicationContext.filesDir, "data")
|
return ensureFolderExists(applicationContext.filesDir, "data")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named(DatabaseFolderKey)
|
@Named(DatabaseFolderKey)
|
||||||
fun provideDatabaseFolder(@Named(DataFolderKey) dataFolder: File) : File {
|
fun provideDatabaseFolder(@Named(DataFolderKey) dataFolder: File) : File {
|
||||||
return File(dataFolder, "db")
|
return ensureFolderExists(dataFolder, "db")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named(IndexFolderKey)
|
@Named(IndexFolderKey)
|
||||||
fun provideIndexFolder(@Named(DataFolderKey) dataFolder: File) : File {
|
fun provideIndexFolder(@Named(DataFolderKey) dataFolder: File) : File {
|
||||||
return File(dataFolder, "index")
|
return ensureFolderExists(dataFolder, "index")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ensureFolderExists(parentFolder: File, folderName: String): File {
|
||||||
|
val folder = File(parentFolder, folderName)
|
||||||
|
|
||||||
|
folder.mkdirs()
|
||||||
|
|
||||||
|
return folder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideBankingPresenter(bankingClientCreator: IBankingClientCreator, bankFinder: IBankFinder,
|
fun provideBankingPresenter(bankingClientCreator: IBankingClientCreator, bankFinder: IBankFinder,
|
||||||
@Named(DatabaseFolderKey) databaseFolder: File, @Named(DataFolderKey) dataFolder: File,
|
@Named(DataFolderKey) dataFolder: File,
|
||||||
persister: IBankingPersistence, remitteeSearcher: IRemitteeSearcher, bankIconFinder: IBankIconFinder,
|
persister: IBankingPersistence, remitteeSearcher: IRemitteeSearcher, bankIconFinder: IBankIconFinder,
|
||||||
textExtractorRegistry: ITextExtractorRegistry, router: IRouter, invoiceDataExtractor: IInvoiceDataExtractor,
|
textExtractorRegistry: ITextExtractorRegistry, router: IRouter, invoiceDataExtractor: IInvoiceDataExtractor,
|
||||||
serializer: ISerializer, threadPool: IThreadPool) : BankingPresenter {
|
serializer: ISerializer, threadPool: IThreadPool) : BankingPresenter {
|
||||||
return BankingPresenter(bankingClientCreator, bankFinder, databaseFolder, dataFolder, persister,
|
return BankingPresenter(bankingClientCreator, bankFinder, dataFolder, persister,
|
||||||
remitteeSearcher, bankIconFinder, textExtractorRegistry, router, invoiceDataExtractor, serializer, threadPool)
|
remitteeSearcher, bankIconFinder, textExtractorRegistry, router, invoiceDataExtractor, serializer, threadPool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,11 @@ import java.io.File
|
||||||
|
|
||||||
class MainWindow : View(messages["application.title"]) {
|
class MainWindow : View(messages["application.title"]) {
|
||||||
|
|
||||||
private val dataFolder = File("data")
|
private val dataFolder = ensureFolderExists(File("."), "data")
|
||||||
|
|
||||||
private val databaseFolder = File(dataFolder, "db")
|
private val databaseFolder = ensureFolderExists(dataFolder, "db")
|
||||||
|
|
||||||
private val indexFolder = File(dataFolder, "index")
|
private val indexFolder = ensureFolderExists(dataFolder, "index")
|
||||||
|
|
||||||
private val tesseractTextExtractor = Tesseract4CommandlineImageTextExtractor(TesseractConfig(listOf(OcrLanguage.English, OcrLanguage.German)))
|
private val tesseractTextExtractor = Tesseract4CommandlineImageTextExtractor(TesseractConfig(listOf(OcrLanguage.English, OcrLanguage.German)))
|
||||||
|
|
||||||
|
@ -41,9 +41,9 @@ class MainWindow : View(messages["application.title"]) {
|
||||||
))
|
))
|
||||||
|
|
||||||
private val presenter = BankingPresenter(fints4kBankingClientCreator(OkHttpWebClient(), Base64ServiceJava8()),
|
private val presenter = BankingPresenter(fints4kBankingClientCreator(OkHttpWebClient(), Base64ServiceJava8()),
|
||||||
LuceneBankFinder(indexFolder), databaseFolder, dataFolder, LuceneBankingPersistence(indexFolder, databaseFolder),
|
LuceneBankFinder(indexFolder), dataFolder, LuceneBankingPersistence(indexFolder, databaseFolder),
|
||||||
LuceneRemitteeSearcher(indexFolder), BankIconFinder(), textExtractorRegistry, RouterJavaFx())
|
LuceneRemitteeSearcher(indexFolder), BankIconFinder(), textExtractorRegistry, RouterJavaFx())
|
||||||
// private val presenter = BankingPresenter(hbci4jBankingClientCreator(), LuceneBankFinder(indexFolder), databaseFolder,
|
// private val presenter = BankingPresenter(hbci4jBankingClientCreator(), LuceneBankFinder(indexFolder),
|
||||||
// dataFolder, LuceneBankingPersistence(indexFolder, databaseFolder), LuceneRemitteeSearcher(indexFolder),
|
// dataFolder, LuceneBankingPersistence(indexFolder, databaseFolder), LuceneRemitteeSearcher(indexFolder),
|
||||||
// BankIconFinder(), textExtractorRegistry, RouterJavaFx())
|
// BankIconFinder(), textExtractorRegistry, RouterJavaFx())
|
||||||
|
|
||||||
|
@ -68,4 +68,13 @@ class MainWindow : View(messages["application.title"]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun ensureFolderExists(parentFolder: File, folderName: String): File {
|
||||||
|
val folder = File(parentFolder, folderName)
|
||||||
|
|
||||||
|
folder.mkdirs()
|
||||||
|
|
||||||
|
return folder
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -46,7 +46,6 @@ import kotlin.collections.ArrayList
|
||||||
open class BankingPresenter(
|
open class BankingPresenter(
|
||||||
protected val bankingClientCreator: IBankingClientCreator,
|
protected val bankingClientCreator: IBankingClientCreator,
|
||||||
protected val bankFinder: IBankFinder,
|
protected val bankFinder: IBankFinder,
|
||||||
protected val databaseFolder: File,
|
|
||||||
protected val dataFolder: File,
|
protected val dataFolder: File,
|
||||||
protected val persister: IBankingPersistence,
|
protected val persister: IBankingPersistence,
|
||||||
protected val remitteeSearcher: IRemitteeSearcher,
|
protected val remitteeSearcher: IRemitteeSearcher,
|
||||||
|
@ -124,8 +123,6 @@ open class BankingPresenter(
|
||||||
|
|
||||||
protected open fun readPersistedAccounts() {
|
protected open fun readPersistedAccounts() {
|
||||||
try {
|
try {
|
||||||
databaseFolder.mkdirs()
|
|
||||||
|
|
||||||
val deserializedAccounts = persister.readPersistedAccounts()
|
val deserializedAccounts = persister.readPersistedAccounts()
|
||||||
|
|
||||||
deserializedAccounts.forEach { account ->
|
deserializedAccounts.forEach { account ->
|
||||||
|
@ -133,7 +130,7 @@ open class BankingPresenter(
|
||||||
val bankInfo = BankInfo(bank.name, bank.bankCode, bank.bic, "", "", "", bank.finTsServerAddress, "FinTS V3.0", null)
|
val bankInfo = BankInfo(bank.name, bank.bankCode, bank.bic, "", "", "", bank.finTsServerAddress, "FinTS V3.0", null)
|
||||||
|
|
||||||
val newClient = bankingClientCreator.createClient(bankInfo, account.customerId, account.password,
|
val newClient = bankingClientCreator.createClient(bankInfo, account.customerId, account.password,
|
||||||
databaseFolder, threadPool, callback)
|
dataFolder, threadPool, callback)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
newClient.restoreData()
|
newClient.restoreData()
|
||||||
|
@ -161,7 +158,7 @@ open class BankingPresenter(
|
||||||
// TODO: move BankInfo out of fints4k
|
// TODO: move BankInfo out of fints4k
|
||||||
open fun addAccountAsync(bankInfo: BankInfo, customerId: String, pin: String, callback: (AddAccountResponse) -> Unit) {
|
open fun addAccountAsync(bankInfo: BankInfo, customerId: String, pin: String, callback: (AddAccountResponse) -> Unit) {
|
||||||
|
|
||||||
val newClient = bankingClientCreator.createClient(bankInfo, customerId, pin, databaseFolder, threadPool, this.callback)
|
val newClient = bankingClientCreator.createClient(bankInfo, customerId, pin, dataFolder, threadPool, this.callback)
|
||||||
|
|
||||||
val startDate = Date()
|
val startDate = Date()
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ open class fints4kBankingClient(
|
||||||
override fun getTransactionsAsync(bankAccount: BankAccount, parameter: GetTransactionsParameter, callback: (GetTransactionsResponse) -> Unit) {
|
override fun getTransactionsAsync(bankAccount: BankAccount, parameter: GetTransactionsParameter, callback: (GetTransactionsResponse) -> Unit) {
|
||||||
val account = mapper.findAccountForBankAccount(customer, bankAccount)
|
val account = mapper.findAccountForBankAccount(customer, bankAccount)
|
||||||
|
|
||||||
if (account == null) {
|
if (account == null) { // TODO: in this case retrieve data from bank, all data should be re-creatable
|
||||||
callback(GetTransactionsResponse(bankAccount, false, "Cannot find account for ${bankAccount.identifier}")) // TODO: translate
|
callback(GetTransactionsResponse(bankAccount, false, "Cannot find account for ${bankAccount.identifier}")) // TODO: translate
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -159,14 +159,18 @@ open class fints4kBankingClient(
|
||||||
|
|
||||||
protected open fun saveData() {
|
protected open fun saveData() {
|
||||||
try {
|
try {
|
||||||
serializer.serializeObject(customer, getFints4kClientDataFile())
|
val clientDataFile = getFints4kClientDataFile()
|
||||||
|
|
||||||
|
clientDataFile.parentFile.mkdirs()
|
||||||
|
|
||||||
|
serializer.serializeObject(customer, clientDataFile)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
log.error("Could not save customer data for $customer", e)
|
log.error("Could not save customer data for $customer", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun getFints4kClientDataFile(): File {
|
protected open fun getFints4kClientDataFile(): File {
|
||||||
return File(dataFolder, "${bank.bankCode}_${customer.customerId}_$fints4kClientDataFilename")
|
return File(File(dataFolder, "fints4k-client"), "${bank.bankCode}_${customer.customerId}_$fints4kClientDataFilename")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -298,8 +298,10 @@ open class hbci4jBankingClient(
|
||||||
// Die Datei kann problemlos geloescht werden. Sie wird beim naechsten mal automatisch neu erzeugt,
|
// Die Datei kann problemlos geloescht werden. Sie wird beim naechsten mal automatisch neu erzeugt,
|
||||||
// wenn der Parameter "client.passport.PinTan.init" den Wert "1" hat (siehe unten).
|
// wenn der Parameter "client.passport.PinTan.init" den Wert "1" hat (siehe unten).
|
||||||
// Wir speichern die Datei der Einfachheit halber im aktuellen Verzeichnis.
|
// Wir speichern die Datei der Einfachheit halber im aktuellen Verzeichnis.
|
||||||
dataFolder.mkdirs()
|
val hbciClientFolder = File(dataFolder, "hbci4j-client")
|
||||||
val passportFile = File(dataFolder, "passport_${credentials.bankCode}_${credentials.customerId}.dat")
|
hbciClientFolder.mkdirs()
|
||||||
|
|
||||||
|
val passportFile = File(hbciClientFolder, "passport_${credentials.bankCode}_${credentials.customerId}.dat")
|
||||||
|
|
||||||
// Wir setzen die Kernel-Parameter zur Laufzeit. Wir koennten sie alternativ
|
// Wir setzen die Kernel-Parameter zur Laufzeit. Wir koennten sie alternativ
|
||||||
// auch oben in "props" setzen.
|
// auch oben in "props" setzen.
|
||||||
|
|
Loading…
Reference in New Issue