commit ce9962fb1743c1570568f806fa94af0f9613e1f4
parent 291fffb89df9e291cde8d4d68ca1640b70c5b342
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Wed, 25 Mar 2020 20:00:55 +0100
Helper function.
Unzip data and loop over it calling a lambda function
for each entry.
Diffstat:
3 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -16,18 +16,12 @@ const val ID_MAX_LENGTH = 50
object EbicsRawBankTransactionsTable : IdTable<Long>() {
override val id = EbicsSubscribersTable.long("id").entityId().primaryKey()
val nexusSubscriber = reference("subscriber", EbicsSubscribersTable)
- /**
- * How did we learn about this transaction? C52 / C53 / C54
- */
+ // How did we learn about this transaction? C52 / C53 / C54
val sourceType = text("sourceType")
val sourceFileName = text("sourceFileName")
- /**
- * "Subject" of the SEPA transaction
- */
+ // "Subject" of the SEPA transaction
val unstructuredRemittanceInformation = text("unstructuredRemittanceInformation")
- /**
- * Is it a credit or debit transaction?
- */
+ // Debit or credit
val transactionType = text("transactionType")
val currency = text("currency")
val amount = text("amount")
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -624,6 +624,7 @@ fun main() {
post("/ebics/subscribers/{id}/collect-transactions-c52") {
// FIXME(florian): Download C52 and store the result in the right database table
+
}
post("/ebics/subscribers/{id}/collect-transactions-c53") {
@@ -647,7 +648,7 @@ fun main() {
when (response) {
is EbicsDownloadSuccessResult -> {
call.respondText(
- response.orderData.unzipWithLoop(),
+ response.orderData.prettyPrintUnzip(),
ContentType.Text.Plain,
HttpStatusCode.OK
)
@@ -670,7 +671,7 @@ fun main() {
when (response) {
is EbicsDownloadSuccessResult -> {
call.respondText(
- unzipOrderData(response.orderData),
+ response.orderData.prettyPrintUnzip(),
ContentType.Text.Plain,
HttpStatusCode.OK
)
diff --git a/util/src/main/kotlin/zip.kt b/util/src/main/kotlin/zip.kt
@@ -25,7 +25,7 @@ fun ByteArray.zip(): ByteArray {
return baos.toByteArray()
}
-fun ByteArray.unzipWithLoop(): String {
+fun ByteArray.prettyPrintUnzip(): String {
val mem = SeekableInMemoryByteChannel(this)
val zipFile = ZipFile(mem)
val s = java.lang.StringBuilder()
@@ -35,4 +35,12 @@ fun ByteArray.unzipWithLoop(): String {
s.append("\n")
}
return s.toString()
+}
+
+fun ByteArray.unzipWithLoop(process: (String) -> Unit) {
+ val mem = SeekableInMemoryByteChannel(this)
+ val zipFile = ZipFile(mem)
+ zipFile.getEntriesInPhysicalOrder().iterator().forEach {
+ process(zipFile.getInputStream(it).readAllBytes().toString(Charsets.UTF_8))
+ }
}
\ No newline at end of file