From 525323bfdec379c896486342bb8e746ef44ba2b4 Mon Sep 17 00:00:00 2001 From: Alejandro Revilla Date: Tue, 28 Apr 2020 22:31:06 -0300 Subject: [PATCH] add TxnId.toFile --- .../main/java/org/jpos/transaction/TxnId.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/modules/txn/src/main/java/org/jpos/transaction/TxnId.java b/modules/txn/src/main/java/org/jpos/transaction/TxnId.java index 17086aae54..79f5194ff7 100644 --- a/modules/txn/src/main/java/org/jpos/transaction/TxnId.java +++ b/modules/txn/src/main/java/org/jpos/transaction/TxnId.java @@ -21,6 +21,7 @@ import org.joda.time.DateTime; import org.joda.time.DateTimeZone; +import java.io.File; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -54,6 +55,41 @@ private TxnId init (int year, int dayOfYear, int secondOfDay, int node, long tra + transactionId % 100000; return this; } + /** + * Returns a file suitable to store contents of this transaction. + * File format is yyyy/mm/dd/hh-mm-ss-node-id + * @return file in said format + */ + public File toFile () { + long l = id; + int yy = (int) (id / YMUL); l -= yy*YMUL; + int dd = (int) (l / DMUL); l -= dd*DMUL; + int sod = (int) (l / SMUL); l -= sod*SMUL; + int node = (int) (l / NMUL); l -= node * NMUL; + int hh = sod/3600; + int mm = (sod-3600*hh) / 60; + int ss = sod % 60; + + DateTime dt = new DateTime() + .withYear(2000+yy) + .withDayOfYear(dd) + .withHourOfDay(hh) + .withMinuteOfHour(mm) + .withSecondOfMinute(ss); + + return new File( + String.format("%04d/%02d/%02d/%02d-%02d-%02d-%03d-%05d", + dt.year().get(), + dt.monthOfYear().get(), + dt.dayOfMonth().get(), + dt.hourOfDay().get(), + dt.minuteOfHour().get(), + dt.secondOfMinute().get(), + node, + l + ) + ); + } @Override public String toString() {