Implemented persisting tan media
This commit is contained in:
parent
b53eecd78e
commit
13b7697364
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -73,6 +73,11 @@
|
|||
<attribute name="userSetDisplayName" optional="YES" attributeType="String"/>
|
||||
<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="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 name="PersistedTanProcedure" representedClassName="PersistedTanProcedure" syncable="YES" codeGenerationType="class">
|
||||
<attribute name="allowedTanFormat" attributeType="String" defaultValueString=""/>
|
||||
|
@ -84,7 +89,8 @@
|
|||
<elements>
|
||||
<element name="PersistedAccountTransaction" positionX="-36" positionY="45" width="128" height="553"/>
|
||||
<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="PersistedTanMedium" positionX="-45" positionY="144" width="128" height="28"/>
|
||||
</elements>
|
||||
</model>
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue