Extracted Separators

This commit is contained in:
dankl 2019-10-05 18:41:07 +02:00 committed by dankito
parent b44482d246
commit f30fd61d69
5 changed files with 21 additions and 36 deletions

View File

@ -1,7 +1,6 @@
package net.dankito.fints.messages
import net.dankito.fints.messages.datenelemente.implementierte.tan.TanProcess
import net.dankito.fints.messages.nachrichten.Nachricht
import net.dankito.fints.messages.segmente.ISegmentNumberGenerator
import net.dankito.fints.messages.segmente.Segment
import net.dankito.fints.messages.segmente.SegmentId
@ -98,7 +97,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
val closing = Nachrichtenabschluss(generator.getNextSegmentNumber(), dialogData)
return listOf(header.format(), formattedPayload, closing.format())
.joinToString(Nachricht.SegmentSeparator, postfix = Nachricht.SegmentSeparator)
.joinToString(Separators.SegmentSeparator, postfix = Separators.SegmentSeparator)
}
@ -130,14 +129,14 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
val encryptionHeader = PinTanVerschluesselungskopf(bank, customer, date, time)
val encryptedData = VerschluesselteDaten(formatPayload(payload) + Nachricht.SegmentSeparator)
val encryptedData = VerschluesselteDaten(formatPayload(payload) + Separators.SegmentSeparator)
return listOf(encryptionHeader, encryptedData)
}
protected open fun formatPayload(payload: List<Segment>): String {
return payload.joinToString(Nachricht.SegmentSeparator) { it.format() }
return payload.joinToString(Separators.SegmentSeparator) { it.format() }
}
}

View File

@ -0,0 +1,14 @@
package net.dankito.fints.messages
class Separators {
companion object {
const val SegmentSeparator = "'"
const val DataElementGroupsSeparator = "+"
const val DataElementsSeparator = ":"
}
}

View File

@ -1,19 +1,15 @@
package net.dankito.fints.messages.datenelementgruppen
import net.dankito.fints.messages.Existenzstatus
import net.dankito.fints.messages.Separators
import net.dankito.fints.messages.datenelemente.DatenelementBase
abstract class Datenelementgruppe(val dataElements: List<DatenelementBase>, existenzstatus: Existenzstatus)
: DatenelementBase(existenzstatus) {
companion object {
const val DataElementsSeparator = ":"
}
override fun format(): String {
return dataElements.joinToString(DataElementsSeparator) { it.format() }
return dataElements.joinToString(Separators.DataElementsSeparator) { it.format() }
}
}

View File

@ -1,19 +0,0 @@
package net.dankito.fints.messages.nachrichten
import net.dankito.fints.messages.Nachrichtenteil
import net.dankito.fints.messages.segmente.Segment
open class Nachricht(val segments: List<Segment>) : Nachrichtenteil() {
companion object {
const val SegmentSeparator = "'"
}
override fun format(): String {
return segments.joinToString(SegmentSeparator, postfix = SegmentSeparator) { it.format() }
}
}

View File

@ -1,20 +1,15 @@
package net.dankito.fints.messages.segmente
import net.dankito.fints.messages.Existenzstatus
import net.dankito.fints.messages.Separators
import net.dankito.fints.messages.datenelemente.DatenelementBase
abstract class Segment(val dataElementsAndGroups: List<DatenelementBase>, existenzstatus: Existenzstatus)
: DatenelementBase(existenzstatus) {
companion object {
const val DataElementGroupsSeparator = "+"
}
override fun format(): String {
// TODO: really use DatenelementGruppenSeparator for all elements or use for Datenelement Datenelementgruppe.DatenelementSeparator ?
return dataElementsAndGroups.joinToString(DataElementGroupsSeparator) { it.format() }
return dataElementsAndGroups.joinToString(Separators.DataElementGroupsSeparator) { it.format() }
}
}