Implemented persisting tan media

This commit is contained in:
dankito 2020-09-01 16:26:33 +02:00
parent b53eecd78e
commit 13b7697364
4 changed files with 61 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package net.dankito.banking.ui.model.tan package net.dankito.banking.ui.model.tan
import net.dankito.banking.ui.model.Displayable import net.dankito.banking.ui.model.Displayable
import net.dankito.utils.multiplatform.UUID
open class TanMedium( open class TanMedium(
@ -12,6 +13,9 @@ open class TanMedium(
internal constructor() : this("", TanMediumStatus.Available) // for object deserializers internal constructor() : this("", TanMediumStatus.Available) // for object deserializers
open var technicalId: String = UUID.random()
override fun toString(): String { override fun toString(): String {
return "$displayName $status" return "$displayName $status"
} }

View File

@ -73,6 +73,11 @@
<attribute name="userSetDisplayName" optional="YES" attributeType="String"/> <attribute name="userSetDisplayName" optional="YES" attributeType="String"/>
<relationship name="accounts" toMany="YES" deletionRule="Cascade" ordered="YES" destinationEntity="PersistedBankAccount" inverseName="customer" inverseEntity="PersistedBankAccount"/> <relationship name="accounts" toMany="YES" deletionRule="Cascade" ordered="YES" destinationEntity="PersistedBankAccount" inverseName="customer" inverseEntity="PersistedBankAccount"/>
<relationship name="supportedTanProcedures" toMany="YES" deletionRule="Cascade" ordered="YES" destinationEntity="PersistedTanProcedure"/> <relationship name="supportedTanProcedures" toMany="YES" deletionRule="Cascade" ordered="YES" destinationEntity="PersistedTanProcedure"/>
<relationship name="tanMedia" optional="YES" toMany="YES" deletionRule="Cascade" ordered="YES" destinationEntity="PersistedTanMedium"/>
</entity>
<entity name="PersistedTanMedium" representedClassName="PersistedTanMedium" syncable="YES" codeGenerationType="class">
<attribute name="displayName" attributeType="String"/>
<attribute name="status" attributeType="String"/>
</entity> </entity>
<entity name="PersistedTanProcedure" representedClassName="PersistedTanProcedure" syncable="YES" codeGenerationType="class"> <entity name="PersistedTanProcedure" representedClassName="PersistedTanProcedure" syncable="YES" codeGenerationType="class">
<attribute name="allowedTanFormat" attributeType="String" defaultValueString=""/> <attribute name="allowedTanFormat" attributeType="String" defaultValueString=""/>
@ -84,7 +89,8 @@
<elements> <elements>
<element name="PersistedAccountTransaction" positionX="-36" positionY="45" width="128" height="553"/> <element name="PersistedAccountTransaction" positionX="-36" positionY="45" width="128" height="553"/>
<element name="PersistedBankAccount" positionX="-54" positionY="63" width="128" height="343"/> <element name="PersistedBankAccount" positionX="-54" positionY="63" width="128" height="343"/>
<element name="PersistedCustomer" positionX="-63" positionY="-18" width="128" height="253"/> <element name="PersistedCustomer" positionX="-63" positionY="-18" width="128" height="28"/>
<element name="PersistedTanProcedure" positionX="-54" positionY="135" width="128" height="118"/> <element name="PersistedTanProcedure" positionX="-54" positionY="135" width="128" height="118"/>
<element name="PersistedTanMedium" positionX="-45" positionY="144" width="128" height="28"/>
</elements> </elements>
</model> </model>

View File

@ -49,6 +49,12 @@ class CoreDataBankingPersistence: IBankingPersistence, IRemitteeSearcher {
tanProcedure.technicalId = mappedTanProcedure.objectIDAsString 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
}
}
} }

View File

@ -16,6 +16,8 @@ class Mapper {
mapped.supportedTanProcedures = map(customer.supportedTanProcedures?.array as? [PersistedTanProcedure]) mapped.supportedTanProcedures = map(customer.supportedTanProcedures?.array as? [PersistedTanProcedure])
mapped.selectedTanProcedure = mapped.supportedTanProcedures.first(where: { $0.bankInternalProcedureCode == customer.selectedTanProcedureCode }) mapped.selectedTanProcedure = mapped.supportedTanProcedures.first(where: { $0.bankInternalProcedureCode == customer.selectedTanProcedureCode })
mapped.tanMedia = map(customer.tanMedia?.array as? [PersistedTanMedium])
mapped.technicalId = customer.objectIDAsString mapped.technicalId = customer.objectIDAsString
return mapped return mapped
@ -42,6 +44,8 @@ class Mapper {
mapped.supportedTanProcedures = NSOrderedSet(array: map(customer.supportedTanProcedures, context)) mapped.supportedTanProcedures = NSOrderedSet(array: map(customer.supportedTanProcedures, context))
mapped.selectedTanProcedureCode = customer.selectedTanProcedure?.bankInternalProcedureCode mapped.selectedTanProcedureCode = customer.selectedTanProcedure?.bankInternalProcedureCode
mapped.tanMedia = NSOrderedSet(array: map(customer.tanMedia, context))
return mapped 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 { func map(_ date: Date?) -> CommonDate {
if let date = date { if let date = date {
return CommonDate(date: date) return CommonDate(date: date)