commit b80ace99cc2c6f00ce6f6c42e0450c5a33de4d3c
parent 98d717ae97326d30516a94b320bf010948a7106b
Author: Antoine A <>
Date: Mon, 11 Nov 2024 14:06:01 +0100
nexus: improve export cmd
Diffstat:
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/common/src/main/kotlin/helpers.kt b/common/src/main/kotlin/helpers.kt
@@ -71,6 +71,12 @@ fun dateToInstant(date: String): Instant =
fun dateTimeToInstant(date: String): Instant =
LocalDateTime.parse(date, DateTimeFormatter.ISO_DATE_TIME).toInstant(ZoneOffset.UTC)
+private val DATE_TIME_PATH = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HHmmss")
+
+/** Converting Instant to YYYY-MM-DDTHHMMSS */
+fun Instant.toDateTimeFilePath(): String =
+ this.atOffset(ZoneOffset.UTC).format(DATE_TIME_PATH)
+
/* ----- BigInteger -----*/
fun BigInteger.encodeHex(): String = this.toByteArray().encodeHex()
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/cli/Testing.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/cli/Testing.kt
@@ -286,11 +286,13 @@ class ExportCmt: CliktCommand("export") {
override fun run() = cliCmd(logger, common.log) {
nexusConfig(common.config).withDb { db, cfg ->
+ var nbTx: Int = 0
ZipOutputStream(BufferedOutputStream(FileOutputStream(out))).use { zip ->
db.initiated.batch(Instant.now(), randEbicsId())
val ebicsCfg = cfg.ebics
db.initiated.submittable(cfg.currency).forEach { batch ->
- val entry = ZipEntry("${batch.creationDate}-${batch.messageId}.xml")
+ nbTx = batch.payments.size
+ val entry = ZipEntry("${batch.creationDate.toDateTimeFilePath()}-${batch.messageId}.xml")
zip.putNextEntry(entry)
val msg = batchToPain001Msg(ebicsCfg.account, batch)
val xml = createPain001(
@@ -300,6 +302,7 @@ class ExportCmt: CliktCommand("export") {
zip.write(xml)
}
}
+ println("Exported $nbTx transactions in $out")
}
}
}