From 13b7697364064974f14a84f43209da5ecc502c48 Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 1 Sep 2020 16:26:33 +0200 Subject: [PATCH] Implemented persisting tan media --- .../dankito/banking/ui/model/tan/TanMedium.kt | 4 ++ .../BankingiOSApp.xcdatamodel/contents | 8 +++- .../CoreDataBankingPersistence.swift | 6 +++ .../BankingiOSApp/persistence/Mapper.swift | 44 +++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/tan/TanMedium.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/tan/TanMedium.kt index 29feb19a..ee0c8c01 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/tan/TanMedium.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/tan/TanMedium.kt @@ -1,6 +1,7 @@ package net.dankito.banking.ui.model.tan import net.dankito.banking.ui.model.Displayable +import net.dankito.utils.multiplatform.UUID open class TanMedium( @@ -12,6 +13,9 @@ open class TanMedium( internal constructor() : this("", TanMediumStatus.Available) // for object deserializers + open var technicalId: String = UUID.random() + + override fun toString(): String { return "$displayName $status" } diff --git a/ui/BankingiOSApp/BankingiOSApp/BankingiOSApp.xcdatamodeld/BankingiOSApp.xcdatamodel/contents b/ui/BankingiOSApp/BankingiOSApp/BankingiOSApp.xcdatamodeld/BankingiOSApp.xcdatamodel/contents index f1a43629..2aae05c4 100644 --- a/ui/BankingiOSApp/BankingiOSApp/BankingiOSApp.xcdatamodeld/BankingiOSApp.xcdatamodel/contents +++ b/ui/BankingiOSApp/BankingiOSApp/BankingiOSApp.xcdatamodeld/BankingiOSApp.xcdatamodel/contents @@ -73,6 +73,11 @@ + + + + + @@ -84,7 +89,8 @@ - + + \ No newline at end of file diff --git a/ui/BankingiOSApp/BankingiOSApp/persistence/CoreDataBankingPersistence.swift b/ui/BankingiOSApp/BankingiOSApp/persistence/CoreDataBankingPersistence.swift index 7074e85b..5ac85bac 100644 --- a/ui/BankingiOSApp/BankingiOSApp/persistence/CoreDataBankingPersistence.swift +++ b/ui/BankingiOSApp/BankingiOSApp/persistence/CoreDataBankingPersistence.swift @@ -49,6 +49,12 @@ class CoreDataBankingPersistence: IBankingPersistence, IRemitteeSearcher { tanProcedure.technicalId = mappedTanProcedure.objectIDAsString } } + + for tanMedium in customer.tanMedia { + if let mappedTanMedium = mappedCustomer.tanMedia?.first { ($0 as! PersistedTanMedium).displayName == tanMedium.displayName } as? PersistedTanMedium { + tanMedium.technicalId = mappedTanMedium.objectIDAsString + } + } } diff --git a/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift b/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift index 4d5205fc..dc3454ce 100644 --- a/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift +++ b/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift @@ -16,6 +16,8 @@ class Mapper { mapped.supportedTanProcedures = map(customer.supportedTanProcedures?.array as? [PersistedTanProcedure]) mapped.selectedTanProcedure = mapped.supportedTanProcedures.first(where: { $0.bankInternalProcedureCode == customer.selectedTanProcedureCode }) + mapped.tanMedia = map(customer.tanMedia?.array as? [PersistedTanMedium]) + mapped.technicalId = customer.objectIDAsString return mapped @@ -42,6 +44,8 @@ class Mapper { mapped.supportedTanProcedures = NSOrderedSet(array: map(customer.supportedTanProcedures, context)) mapped.selectedTanProcedureCode = customer.selectedTanProcedure?.bankInternalProcedureCode + mapped.tanMedia = NSOrderedSet(array: map(customer.tanMedia, context)) + return mapped } @@ -259,6 +263,46 @@ class Mapper { } + func map(_ tanMedia: [PersistedTanMedium]?) -> [TanMedium] { + return tanMedia?.map { map($0) } ?? [] + } + + func map(_ tanMedium: PersistedTanMedium) -> TanMedium { + let mapped = TanMedium( + displayName: map(tanMedium.displayName), + status: mapTanMediumStatus(tanMedium.status) + ) + + mapped.technicalId = tanMedium.objectIDAsString + + return mapped + } + + func map(_ tanMedia: [TanMedium], _ context: NSManagedObjectContext) -> [PersistedTanMedium] { + return tanMedia.map { map($0, context) } + } + + func map(_ tanMedium: TanMedium, _ context: NSManagedObjectContext) -> PersistedTanMedium { + let mapped = context.objectByID(tanMedium.technicalId) ?? PersistedTanMedium(context: context) + + mapped.displayName = tanMedium.displayName + mapped.status = tanMedium.status.name + + return mapped + } + + func mapTanMediumStatus(_ status: String?) -> TanMediumStatus { + switch status { + case TanMediumStatus.used.name: + return TanMediumStatus.used + case TanMediumStatus.available.name: + return TanMediumStatus.available + default: + return TanMediumStatus.available + } + } + + func map(_ date: Date?) -> CommonDate { if let date = date { return CommonDate(date: date)