]> git.ktnx.net Git - mobile-ledger.git/commitdiff
support both 1.14 and 1.15 JSON APIs
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 21 Dec 2019 21:22:14 +0000 (23:22 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 21 Dec 2019 21:23:50 +0000 (23:23 +0200)
this is a major and somewhat messy rework

the idea is that several APIs should be able to co-exist

conversion between MoLe's internal structures and the JSON API is moved
to the version-dependent JSON representations

an 'auto' setting for the version (the default) attempts all available
API versions starting from the latest

HTTP status 400 is interpreted as "version mismatch" (same as 405)

41 files changed:
app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/async/SendTransactionTask.java
app/src/main/java/net/ktnx/mobileledger/json/AccountListParser.java [deleted file]
app/src/main/java/net/ktnx/mobileledger/json/ParsedAmount.java [deleted file]
app/src/main/java/net/ktnx/mobileledger/json/ParsedBalance.java [deleted file]
app/src/main/java/net/ktnx/mobileledger/json/ParsedLedgerAccount.java [deleted file]
app/src/main/java/net/ktnx/mobileledger/json/ParsedLedgerTransaction.java
app/src/main/java/net/ktnx/mobileledger/json/ParsedPosting.java [deleted file]
app/src/main/java/net/ktnx/mobileledger/json/ParsedPrice.java [deleted file]
app/src/main/java/net/ktnx/mobileledger/json/ParsedQuantity.java [deleted file]
app/src/main/java/net/ktnx/mobileledger/json/ParsedSourcePos.java [deleted file]
app/src/main/java/net/ktnx/mobileledger/json/ParsedStyle.java [deleted file]
app/src/main/java/net/ktnx/mobileledger/json/TransactionListParser.java [deleted file]
app/src/main/java/net/ktnx/mobileledger/json/v1_14/AccountListParser.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedAmount.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedBalance.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedLedgerAccount.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedLedgerTransaction.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedPosting.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedPrice.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedQuantity.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedSourcePos.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedStyle.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_14/TransactionListParser.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_15/AccountListParser.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedAmount.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedBalance.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedLedgerAccount.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedLedgerTransaction.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPosting.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPrice.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedQuantity.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedSourcePos.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedStyle.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/json/v1_15/TransactionListParser.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java
app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java
app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java
app/src/main/res/values-bg/strings.xml
app/src/main/res/values/strings.xml
app/src/test/java/net/ktnx/mobileledger/json/ParsedQuantityTest.java

index 0354e5ed98e034ae5baee6bf82d17b374a4f14e3..5aebe219ffa6cb9650ce15afd30719b6ce2ae150 100644 (file)
@@ -26,11 +26,11 @@ import androidx.annotation.NonNull;
 
 import net.ktnx.mobileledger.App;
 import net.ktnx.mobileledger.err.HTTPException;
 
 import net.ktnx.mobileledger.App;
 import net.ktnx.mobileledger.err.HTTPException;
-import net.ktnx.mobileledger.json.AccountListParser;
-import net.ktnx.mobileledger.json.ParsedBalance;
-import net.ktnx.mobileledger.json.ParsedLedgerAccount;
-import net.ktnx.mobileledger.json.ParsedLedgerTransaction;
-import net.ktnx.mobileledger.json.TransactionListParser;
+import net.ktnx.mobileledger.json.v1_15.AccountListParser;
+import net.ktnx.mobileledger.json.v1_15.ParsedBalance;
+import net.ktnx.mobileledger.json.v1_15.ParsedLedgerAccount;
+import net.ktnx.mobileledger.json.v1_15.ParsedLedgerTransaction;
+import net.ktnx.mobileledger.json.v1_15.TransactionListParser;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerAccount;
 import net.ktnx.mobileledger.model.LedgerTransaction;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerAccount;
 import net.ktnx.mobileledger.model.LedgerTransaction;
index 496624bf52475a6c22e6e2a2388d9d48d44aa53b..5170b9337a362dbcafc55cd6e66360056521157a 100644 (file)
 
 package net.ktnx.mobileledger.async;
 
 
 package net.ktnx.mobileledger.async;
 
+import android.content.res.Resources;
 import android.os.AsyncTask;
 import android.util.Log;
 import android.os.AsyncTask;
 import android.util.Log;
+import android.util.SparseArray;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.ObjectWriter;
 
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.ObjectWriter;
 
-import net.ktnx.mobileledger.json.ParsedLedgerTransaction;
+import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.LedgerTransaction;
 import net.ktnx.mobileledger.model.LedgerTransactionAccount;
 import net.ktnx.mobileledger.model.MobileLedgerProfile;
 import net.ktnx.mobileledger.model.LedgerTransaction;
 import net.ktnx.mobileledger.model.LedgerTransactionAccount;
 import net.ktnx.mobileledger.model.MobileLedgerProfile;
@@ -70,18 +72,37 @@ public class SendTransactionTask extends AsyncTask<LedgerTransaction, Void, Void
         mProfile = profile;
         simulate = false;
     }
         mProfile = profile;
         simulate = false;
     }
-    private boolean sendOK() throws IOException {
+    private boolean send_1_15_OK() throws IOException {
         HttpURLConnection http = NetworkUtil.prepareConnection(mProfile, "add");
         http.setRequestMethod("PUT");
         http.setRequestProperty("Content-Type", "application/json");
         http.setRequestProperty("Accept", "*/*");
 
         HttpURLConnection http = NetworkUtil.prepareConnection(mProfile, "add");
         http.setRequestMethod("PUT");
         http.setRequestProperty("Content-Type", "application/json");
         http.setRequestProperty("Accept", "*/*");
 
-        ParsedLedgerTransaction jsonTransaction;
-        jsonTransaction = ltr.toParsedLedgerTransaction();
+        net.ktnx.mobileledger.json.v1_15.ParsedLedgerTransaction jsonTransaction =
+                net.ktnx.mobileledger.json.v1_15.ParsedLedgerTransaction.fromLedgerTransaction(ltr);
         ObjectMapper mapper = new ObjectMapper();
         ObjectMapper mapper = new ObjectMapper();
-        ObjectWriter writer = mapper.writerFor(ParsedLedgerTransaction.class);
+        ObjectWriter writer =
+                mapper.writerFor(net.ktnx.mobileledger.json.v1_15.ParsedLedgerTransaction.class);
         String body = writer.writeValueAsString(jsonTransaction);
 
         String body = writer.writeValueAsString(jsonTransaction);
 
+        return sendRequest(http, body);
+    }
+    private boolean send_1_14_OK() throws IOException {
+        HttpURLConnection http = NetworkUtil.prepareConnection(mProfile, "add");
+        http.setRequestMethod("PUT");
+        http.setRequestProperty("Content-Type", "application/json");
+        http.setRequestProperty("Accept", "*/*");
+
+        net.ktnx.mobileledger.json.v1_14.ParsedLedgerTransaction jsonTransaction =
+                net.ktnx.mobileledger.json.v1_14.ParsedLedgerTransaction.fromLedgerTransaction(ltr);
+        ObjectMapper mapper = new ObjectMapper();
+        ObjectWriter writer =
+                mapper.writerFor(net.ktnx.mobileledger.json.v1_14.ParsedLedgerTransaction.class);
+        String body = writer.writeValueAsString(jsonTransaction);
+
+        return sendRequest(http, body);
+    }
+    private boolean sendRequest(HttpURLConnection http, String body) throws IOException {
         if (simulate) {
             debug("network", "The request would be: " + body);
             try {
         if (simulate) {
             debug("network", "The request would be: " + body);
             try {
@@ -118,6 +139,7 @@ public class SendTransactionTask extends AsyncTask<LedgerTransaction, Void, Void
                     case 200:
                     case 201:
                         break;
                     case 200:
                     case 201:
                         break;
+                    case 400:
                     case 405:
                         return false; // will cause a retry with the legacy method
                     default:
                     case 405:
                         return false; // will cause a retry with the legacy method
                     default:
@@ -227,21 +249,41 @@ public class SendTransactionTask extends AsyncTask<LedgerTransaction, Void, Void
             }
         }
     }
             }
         }
     }
-
     @Override
     protected Void doInBackground(LedgerTransaction... ledgerTransactions) {
         error = null;
         try {
             ltr = ledgerTransactions[0];
 
     @Override
     protected Void doInBackground(LedgerTransaction... ledgerTransactions) {
         error = null;
         try {
             ltr = ledgerTransactions[0];
 
-            if (!sendOK()) {
-                int tried = 0;
-                while (!legacySendOK()) {
-                    tried++;
-                    if (tried >= 2)
-                        throw new IOException(String.format("aborting after %d tries", tried));
-                    sleep(100);
-                }
+            switch (mProfile.getApiVersion()) {
+                case auto:
+                    Logger.debug("network", "Trying version 1.5.");
+                    if (!send_1_15_OK()) {
+                        Logger.debug("network", "Version 1.5 request failed. Trying with 1.14");
+                        if (!send_1_14_OK()) {
+                            Logger.debug("network", "Version 1.14 failed too. Trying HTML form emulation");
+                            legacySendOkWithRetry();
+                        }
+                        else {
+                            Logger.debug("network", "Version 1.14 request succeeded");
+                        }
+                    }
+                    else {
+                        Logger.debug("network", "Version 1.15 request succeeded");
+                    }
+                    break;
+                case html:
+                    legacySendOkWithRetry();
+                    break;
+                case pre_1_15:
+                    send_1_14_OK();
+                    break;
+                case post_1_14:
+                    send_1_15_OK();
+                    break;
+                default:
+                    throw new IllegalStateException(
+                            "Unexpected API version: " + mProfile.getApiVersion());
             }
         }
         catch (Exception e) {
             }
         }
         catch (Exception e) {
@@ -251,10 +293,56 @@ public class SendTransactionTask extends AsyncTask<LedgerTransaction, Void, Void
 
         return null;
     }
 
         return null;
     }
-
+    private void legacySendOkWithRetry() throws IOException {
+        int tried = 0;
+        while (!legacySendOK()) {
+            tried++;
+            if (tried >= 2)
+                throw new IOException(
+                        String.format("aborting after %d tries", tried));
+            sleep(100);
+        }
+    }
     @Override
     protected void onPostExecute(Void aVoid) {
         super.onPostExecute(aVoid);
         taskCallback.done(error);
     }
     @Override
     protected void onPostExecute(Void aVoid) {
         super.onPostExecute(aVoid);
         taskCallback.done(error);
     }
+
+    public enum API {
+        auto(0), html(-1), pre_1_15(-2), post_1_14(-3);
+        private static SparseArray<API> map = new SparseArray<>();
+
+        static {
+            for (API item : API.values()) {
+                map.put(item.value, item);
+            }
+        }
+
+        private int value;
+
+        API(int value) {
+            this.value = value;
+        }
+        public static API valueOf(int i) {
+            return map.get(i, auto);
+        }
+        public int toInt() {
+            return this.value;
+        }
+        public String getDescription(Resources resources) {
+            switch (this) {
+                case auto:
+                    return resources.getString(R.string.api_auto);
+                case html:
+                    return resources.getString(R.string.api_html);
+                case pre_1_15:
+                    return resources.getString(R.string.api_pre_1_15);
+                case post_1_14:
+                    return resources.getString(R.string.api_post_1_14);
+                default:
+                    throw new IllegalStateException("Unexpected value: " + value);
+            }
+        }
+    }
 }
 }
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/AccountListParser.java b/app/src/main/java/net/ktnx/mobileledger/json/AccountListParser.java
deleted file mode 100644 (file)
index a21fc61..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright © 2019 Damyan Ivanov.
- * This file is part of MoLe.
- * MoLe is free software: you can distribute it and/or modify it
- * under the term of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your opinion), any later version.
- *
- * MoLe is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License terms for details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package net.ktnx.mobileledger.json;
-
-import com.fasterxml.jackson.databind.MappingIterator;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.ObjectReader;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import static net.ktnx.mobileledger.utils.Logger.debug;
-
-public class AccountListParser {
-
-    private final MappingIterator<ParsedLedgerAccount> iter;
-
-    public AccountListParser(InputStream input) throws IOException {
-        ObjectMapper mapper = new ObjectMapper();
-        ObjectReader reader = mapper.readerFor(ParsedLedgerAccount.class);
-
-        iter = reader.readValues(input);
-    }
-    public ParsedLedgerAccount nextAccount() throws IOException {
-        if (!iter.hasNext()) return null;
-
-        ParsedLedgerAccount next = iter.next();
-
-        if (next.getAname().equalsIgnoreCase("root")) return nextAccount();
-
-        debug("accounts", String.format("Got account '%s'", next.getAname()));
-        return next;
-    }
-}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/ParsedAmount.java b/app/src/main/java/net/ktnx/mobileledger/json/ParsedAmount.java
deleted file mode 100644 (file)
index e66258b..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright © 2019 Damyan Ivanov.
- * This file is part of MoLe.
- * MoLe is free software: you can distribute it and/or modify it
- * under the term of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your opinion), any later version.
- *
- * MoLe is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License terms for details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package net.ktnx.mobileledger.json;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class ParsedAmount {
-    private String acommodity;
-    private ParsedQuantity aquantity;
-    private boolean aismultiplier;
-    private ParsedStyle astyle;
-    private ParsedPrice aprice;
-    public ParsedAmount() {
-    }
-    public ParsedPrice getAprice() {
-        return aprice;
-    }
-    public void setAprice(ParsedPrice aprice) {
-        this.aprice = aprice;
-    }
-    public String getAcommodity() {
-        return acommodity;
-    }
-    public void setAcommodity(String acommodity) {
-        this.acommodity = acommodity;
-    }
-    public ParsedQuantity getAquantity() {
-        return aquantity;
-    }
-    public void setAquantity(ParsedQuantity aquantity) {
-        this.aquantity = aquantity;
-    }
-    public boolean isAismultiplier() {
-        return aismultiplier;
-    }
-    public void setAismultiplier(boolean aismultiplier) {
-        this.aismultiplier = aismultiplier;
-    }
-    public ParsedStyle getAstyle() {
-        return astyle;
-    }
-    public void setAstyle(ParsedStyle astyle) {
-        this.astyle = astyle;
-    }
-
-}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/ParsedBalance.java b/app/src/main/java/net/ktnx/mobileledger/json/ParsedBalance.java
deleted file mode 100644 (file)
index a355bbd..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright © 2019 Damyan Ivanov.
- * This file is part of MoLe.
- * MoLe is free software: you can distribute it and/or modify it
- * under the term of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your opinion), any later version.
- *
- * MoLe is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License terms for details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package net.ktnx.mobileledger.json;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-import androidx.annotation.NonNull;
-
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class ParsedBalance {
-    private ParsedQuantity aquantity;
-    private String acommodity;
-    private ParsedStyle astyle;
-    public ParsedBalance() {
-    }
-    public ParsedQuantity getAquantity() {
-        return aquantity;
-    }
-    public void setAquantity(ParsedQuantity aquantity) {
-        this.aquantity = aquantity;
-    }
-    @NonNull
-    public String getAcommodity() {
-        return (acommodity == null) ? "" : acommodity;
-    }
-    public void setAcommodity(String acommodity) {
-        this.acommodity = acommodity;
-    }
-    public ParsedStyle getAstyle() {
-        return astyle;
-    }
-    public void setAstyle(ParsedStyle astyle) {
-        this.astyle = astyle;
-    }
-}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/ParsedLedgerAccount.java b/app/src/main/java/net/ktnx/mobileledger/json/ParsedLedgerAccount.java
deleted file mode 100644 (file)
index d155c2b..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright © 2019 Damyan Ivanov.
- * This file is part of MoLe.
- * MoLe is free software: you can distribute it and/or modify it
- * under the term of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your opinion), any later version.
- *
- * MoLe is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License terms for details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package net.ktnx.mobileledger.json;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-import java.util.List;
-
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class ParsedLedgerAccount {
-    private List<ParsedBalance> aebalance;
-    private List<ParsedBalance> aibalance;
-    private String aname;
-    public ParsedLedgerAccount() {
-    }
-    public List<ParsedBalance> getAebalance() {
-        return aebalance;
-    }
-    public List<ParsedBalance> getAibalance() {
-        return aibalance;
-    }
-    public void setAebalance(List<ParsedBalance> aebalance) {
-        this.aebalance = aebalance;
-    }
-    public void setAibalance(List<ParsedBalance> aibalance) {
-        this.aibalance = aibalance;
-    }
-    public String getAname() {
-        return aname;
-    }
-    public void setAname(String aname) {
-        this.aname = aname;
-    }
-
-}
index 7ba1421cb8db54374df420456b168e00b77916f0..e649b39c0195b9432ee45968065434eef62a9b19 100644 (file)
 
 package net.ktnx.mobileledger.json;
 
 
 package net.ktnx.mobileledger.json;
 
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
 import net.ktnx.mobileledger.model.LedgerTransaction;
 import net.ktnx.mobileledger.model.LedgerTransaction;
-import net.ktnx.mobileledger.utils.Globals;
 
 import java.text.ParseException;
 
 import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class ParsedLedgerTransaction {
-    private String tdate;
-    private String tdate2 = null;
-    private String tdescription;
-    private String tcomment;
-    private String tcode = "";
-    private String tstatus = "Unmarked";
-    private String tprecedingcomment = "";
-    private int tindex;
-    private List<ParsedPosting> tpostings;
-    private List<List<String>> ttags = new ArrayList<>();
-    private ParsedSourcePos tsourcepos = new ParsedSourcePos();
-    public ParsedLedgerTransaction() {
-    }
-    public String getTcode() {
-        return tcode;
-    }
-    public void setTcode(String tcode) {
-        this.tcode = tcode;
-    }
-    public String getTstatus() {
-        return tstatus;
-    }
-    public void setTstatus(String tstatus) {
-        this.tstatus = tstatus;
-    }
-    public List<List<String>> getTtags() {
-        return ttags;
-    }
-    public void setTtags(List<List<String>> ttags) {
-        this.ttags = ttags;
-    }
-    public ParsedSourcePos getTsourcepos() {
-        return tsourcepos;
-    }
-    public void setTsourcepos(ParsedSourcePos tsourcepos) {
-        this.tsourcepos = tsourcepos;
-    }
-    public String getTprecedingcomment() {
-        return tprecedingcomment;
-    }
-    public void setTprecedingcomment(String tprecedingcomment) {
-        this.tprecedingcomment = tprecedingcomment;
-    }
-    public String getTdate() {
-        return tdate;
-    }
-    public void setTdate(String tdate) {
-        this.tdate = tdate;
-    }
-    public String getTdate2() {
-        return tdate2;
-    }
-    public void setTdate2(String tdate2) {
-        this.tdate2 = tdate2;
-    }
-    public String getTdescription() {
-        return tdescription;
-    }
-    public void setTdescription(String tdescription) {
-        this.tdescription = tdescription;
-    }
-    public String getTcomment() {
-        return tcomment;
-    }
-    public void setTcomment(String tcomment) {
-        this.tcomment = tcomment;
-    }
-    public int getTindex() {
-        return tindex;
-    }
-    public void setTindex(int tindex) {
-        this.tindex = tindex;
-        if (tpostings != null)
-            for (ParsedPosting p : tpostings) {
-                p.setPtransaction_(tindex);
-            }
-    }
-    public List<ParsedPosting> getTpostings() {
-        return tpostings;
-    }
-    public void setTpostings(List<ParsedPosting> tpostings) {
-        this.tpostings = tpostings;
-    }
-    public void addPosting(ParsedPosting posting) {
-        posting.setPtransaction_(tindex);
-        tpostings.add(posting);
-    }
-    public LedgerTransaction asLedgerTransaction() throws ParseException {
-        Date date = Globals.parseIsoDate(tdate);
-        LedgerTransaction tr = new LedgerTransaction(tindex, date, tdescription);
-
-        List<ParsedPosting> postings = tpostings;
 
 
-        if (postings != null) {
-            for (ParsedPosting p : postings) {
-                tr.addAccount(p.asLedgerAccount());
-            }
-        }
-        return tr;
-    }
+public interface ParsedLedgerTransaction {
+    LedgerTransaction asLedgerTransaction() throws ParseException;
 }
 }
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/ParsedPosting.java b/app/src/main/java/net/ktnx/mobileledger/json/ParsedPosting.java
deleted file mode 100644 (file)
index 308f01f..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright © 2019 Damyan Ivanov.
- * This file is part of MoLe.
- * MoLe is free software: you can distribute it and/or modify it
- * under the term of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your opinion), any later version.
- *
- * MoLe is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License terms for details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package net.ktnx.mobileledger.json;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-import net.ktnx.mobileledger.model.LedgerTransactionAccount;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class ParsedPosting {
-    private Void pbalanceassertion;
-    private String pstatus = "Unmarked";
-    private String paccount;
-    private List<ParsedAmount> pamount;
-    private String pdate = null;
-    public String getPdate2() {
-        return pdate2;
-    }
-    public void setPdate2(String pdate2) {
-        this.pdate2 = pdate2;
-    }
-    private String pdate2 = null;
-    private String ptype = "RegularPosting";
-    private String pcomment = "";
-    private List<List<String>> ptags = new ArrayList<>();
-    private String poriginal = null;
-    private int ptransaction_;
-    public int getPtransaction_() {
-        return ptransaction_;
-    }
-    public void setPtransaction_(int ptransaction_) {
-        this.ptransaction_ = ptransaction_;
-    }
-    public ParsedPosting() {
-    }
-    public String getPdate() {
-        return pdate;
-    }
-    public void setPdate(String pdate) {
-        this.pdate = pdate;
-    }
-    public String getPtype() {
-        return ptype;
-    }
-    public void setPtype(String ptype) {
-        this.ptype = ptype;
-    }
-    public String getPcomment() {
-        return pcomment;
-    }
-    public void setPcomment(String pcomment) {
-        this.pcomment = pcomment;
-    }
-    public List<List<String>> getPtags() {
-        return ptags;
-    }
-    public void setPtags(List<List<String>> ptags) {
-        this.ptags = ptags;
-    }
-    public String getPoriginal() {
-        return poriginal;
-    }
-    public void setPoriginal(String poriginal) {
-        this.poriginal = poriginal;
-    }
-    public String getPstatus() {
-        return pstatus;
-    }
-    public void setPstatus(String pstatus) {
-        this.pstatus = pstatus;
-    }
-    public Void getPbalanceassertion() {
-        return pbalanceassertion;
-    }
-    public void setPbalanceassertion(Void pbalanceassertion) {
-        this.pbalanceassertion = pbalanceassertion;
-    }
-    public String getPaccount() {
-        return paccount;
-    }
-    public void setPaccount(String paccount) {
-        this.paccount = paccount;
-    }
-    public List<ParsedAmount> getPamount() {
-        return pamount;
-    }
-    public void setPamount(List<ParsedAmount> pamount) {
-        this.pamount = pamount;
-    }
-    public LedgerTransactionAccount asLedgerAccount() {
-        ParsedAmount amt = pamount.get(0);
-        return new LedgerTransactionAccount(paccount, amt.getAquantity().asFloat(),
-                amt.getAcommodity());
-    }
-}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/ParsedPrice.java b/app/src/main/java/net/ktnx/mobileledger/json/ParsedPrice.java
deleted file mode 100644 (file)
index fe8154c..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright © 2019 Damyan Ivanov.
- * This file is part of MoLe.
- * MoLe is free software: you can distribute it and/or modify it
- * under the term of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your opinion), any later version.
- *
- * MoLe is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License terms for details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package net.ktnx.mobileledger.json;
-
-class ParsedPrice {
-    private String tag;
-    private Contents contents;
-    public ParsedPrice() {
-        tag = "NoPrice";
-    }
-    public Contents getContents() {
-        return contents;
-    }
-    public void setContents(Contents contents) {
-        this.contents = contents;
-    }
-    public String getTag() {
-        return tag;
-    }
-    public void setTag(String tag) {
-        this.tag = tag;
-    }
-    private class Contents {
-        private ParsedPrice aprice;
-        private ParsedQuantity aquantity;
-        private String acommodity;
-        private boolean aismultiplier;
-        private ParsedStyle astyle;
-        public Contents() {
-            acommodity = "";
-        }
-        public ParsedPrice getAprice() {
-            return aprice;
-        }
-        public void setAprice(ParsedPrice aprice) {
-            this.aprice = aprice;
-        }
-        public ParsedQuantity getAquantity() {
-            return aquantity;
-        }
-        public void setAquantity(ParsedQuantity aquantity) {
-            this.aquantity = aquantity;
-        }
-        public String getAcommodity() {
-            return acommodity;
-        }
-        public void setAcommodity(String acommodity) {
-            this.acommodity = acommodity;
-        }
-        public boolean isAismultiplier() {
-            return aismultiplier;
-        }
-        public void setAismultiplier(boolean aismultiplier) {
-            this.aismultiplier = aismultiplier;
-        }
-        public ParsedStyle getAstyle() {
-            return astyle;
-        }
-        public void setAstyle(ParsedStyle astyle) {
-            this.astyle = astyle;
-        }
-    }
-}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/ParsedQuantity.java b/app/src/main/java/net/ktnx/mobileledger/json/ParsedQuantity.java
deleted file mode 100644 (file)
index 50ce678..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright © 2019 Damyan Ivanov.
- * This file is part of MoLe.
- * MoLe is free software: you can distribute it and/or modify it
- * under the term of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your opinion), any later version.
- *
- * MoLe is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License terms for details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package net.ktnx.mobileledger.json;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class ParsedQuantity {
-    private long decimalMantissa;
-    private int decimalPlaces;
-    public ParsedQuantity() {
-    }
-    public ParsedQuantity(String input) {
-        parseString(input);
-    }
-    public long getDecimalMantissa() {
-        return decimalMantissa;
-    }
-    public void setDecimalMantissa(long decimalMantissa) {
-        this.decimalMantissa = decimalMantissa;
-    }
-    public int getDecimalPlaces() {
-        return decimalPlaces;
-    }
-    public void setDecimalPlaces(int decimalPlaces) {
-        this.decimalPlaces = decimalPlaces;
-    }
-    public float asFloat() {
-        return (float) (decimalMantissa * Math.pow(10, -decimalPlaces));
-    }
-    public void parseString(String input) {
-        int pointPos = input.indexOf('.');
-        if (pointPos >= 0) {
-            String integral = input.replace(".", "");
-            decimalMantissa = Long.valueOf(integral);
-            decimalPlaces = input.length() - pointPos - 1;
-        }
-        else {
-            decimalMantissa = Long.valueOf(input);
-            decimalPlaces = 0;
-        }
-    }
-}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/ParsedSourcePos.java b/app/src/main/java/net/ktnx/mobileledger/json/ParsedSourcePos.java
deleted file mode 100644 (file)
index fa8dfb9..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright © 2019 Damyan Ivanov.
- * This file is part of MoLe.
- * MoLe is free software: you can distribute it and/or modify it
- * under the term of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your opinion), any later version.
- *
- * MoLe is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License terms for details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package net.ktnx.mobileledger.json;
-
-import java.util.ArrayList;
-import java.util.List;
-
-class ParsedSourcePos {
-    private String tag = "JournalSourcePos";
-    private List<Object> contents;
-    public ParsedSourcePos() {
-        contents = new ArrayList<>();
-        contents.add("");
-        contents.add(new Integer[]{1, 1});
-    }
-    public String getTag() {
-        return tag;
-    }
-    public void setTag(String tag) {
-        this.tag = tag;
-    }
-    public List<Object> getContents() {
-        return contents;
-    }
-    public void setContents(List<Object> contents) {
-        this.contents = contents;
-    }
-}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/ParsedStyle.java b/app/src/main/java/net/ktnx/mobileledger/json/ParsedStyle.java
deleted file mode 100644 (file)
index d0aaa45..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright © 2019 Damyan Ivanov.
- * This file is part of MoLe.
- * MoLe is free software: you can distribute it and/or modify it
- * under the term of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your opinion), any later version.
- *
- * MoLe is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License terms for details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package net.ktnx.mobileledger.json;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class ParsedStyle {
-    private int asprecision;
-    private char asdecimalpoint;
-    private char ascommodityside;
-    private int digitgroups;
-    private boolean ascommodityspaced;
-    public ParsedStyle() {
-    }
-    public int getAsprecision() {
-        return asprecision;
-    }
-    public void setAsprecision(int asprecision) {
-        this.asprecision = asprecision;
-    }
-    public char getAsdecimalpoint() {
-        return asdecimalpoint;
-    }
-    public void setAsdecimalpoint(char asdecimalpoint) {
-        this.asdecimalpoint = asdecimalpoint;
-    }
-    public char getAscommodityside() {
-        return ascommodityside;
-    }
-    public void setAscommodityside(char ascommodityside) {
-        this.ascommodityside = ascommodityside;
-    }
-    public int getDigitgroups() {
-        return digitgroups;
-    }
-    public void setDigitgroups(int digitgroups) {
-        this.digitgroups = digitgroups;
-    }
-    public boolean isAscommodityspaced() {
-        return ascommodityspaced;
-    }
-    public void setAscommodityspaced(boolean ascommodityspaced) {
-        this.ascommodityspaced = ascommodityspaced;
-    }
-}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/TransactionListParser.java b/app/src/main/java/net/ktnx/mobileledger/json/TransactionListParser.java
deleted file mode 100644 (file)
index fc17df6..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright © 2019 Damyan Ivanov.
- * This file is part of MoLe.
- * MoLe is free software: you can distribute it and/or modify it
- * under the term of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your opinion), any later version.
- *
- * MoLe is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License terms for details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package net.ktnx.mobileledger.json;
-
-import com.fasterxml.jackson.databind.MappingIterator;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.ObjectReader;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-public class TransactionListParser {
-
-    private final MappingIterator<ParsedLedgerTransaction> iter;
-
-    public TransactionListParser(InputStream input) throws IOException {
-
-        ObjectMapper mapper = new ObjectMapper();
-        ObjectReader reader = mapper.readerFor(ParsedLedgerTransaction.class);
-        iter = reader.readValues(input);
-    }
-    public ParsedLedgerTransaction nextTransaction() {
-        return iter.hasNext() ? iter.next() : null;
-    }
-}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/AccountListParser.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/AccountListParser.java
new file mode 100644 (file)
index 0000000..e3f0e38
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_14;
+
+import com.fasterxml.jackson.databind.MappingIterator;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectReader;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import static net.ktnx.mobileledger.utils.Logger.debug;
+
+public class AccountListParser {
+
+    private final MappingIterator<ParsedLedgerAccount> iter;
+
+    public AccountListParser(InputStream input) throws IOException {
+        ObjectMapper mapper = new ObjectMapper();
+        ObjectReader reader = mapper.readerFor(ParsedLedgerAccount.class);
+
+        iter = reader.readValues(input);
+    }
+    public ParsedLedgerAccount nextAccount() {
+        if (!iter.hasNext()) return null;
+
+        ParsedLedgerAccount next = iter.next();
+
+        if (next.getAname().equalsIgnoreCase("root")) return nextAccount();
+
+        debug("accounts", String.format("Got account '%s'", next.getAname()));
+        return next;
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedAmount.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedAmount.java
new file mode 100644 (file)
index 0000000..a77ea4d
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_14;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedAmount {
+    private String acommodity;
+    private ParsedQuantity aquantity;
+    private boolean aismultiplier;
+    private ParsedStyle astyle;
+    private ParsedPrice aprice = new ParsedPrice();
+    public ParsedAmount() {
+    }
+    public ParsedPrice getAprice() {
+        return aprice;
+    }
+    public void setAprice(ParsedPrice aprice) {
+        this.aprice = aprice;
+    }
+    public String getAcommodity() {
+        return acommodity;
+    }
+    public void setAcommodity(String acommodity) {
+        this.acommodity = acommodity;
+    }
+    public ParsedQuantity getAquantity() {
+        return aquantity;
+    }
+    public void setAquantity(ParsedQuantity aquantity) {
+        this.aquantity = aquantity;
+    }
+    public boolean isAismultiplier() {
+        return aismultiplier;
+    }
+    public void setAismultiplier(boolean aismultiplier) {
+        this.aismultiplier = aismultiplier;
+    }
+    public ParsedStyle getAstyle() {
+        return astyle;
+    }
+    public void setAstyle(ParsedStyle astyle) {
+        this.astyle = astyle;
+    }
+
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedBalance.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedBalance.java
new file mode 100644 (file)
index 0000000..39cd190
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_14;
+
+import androidx.annotation.NonNull;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedBalance {
+    private ParsedQuantity aquantity;
+    private String acommodity;
+    private ParsedStyle astyle;
+    public ParsedBalance() {
+    }
+    public ParsedQuantity getAquantity() {
+        return aquantity;
+    }
+    public void setAquantity(ParsedQuantity aquantity) {
+        this.aquantity = aquantity;
+    }
+    @NonNull
+    public String getAcommodity() {
+        return (acommodity == null) ? "" : acommodity;
+    }
+    public void setAcommodity(String acommodity) {
+        this.acommodity = acommodity;
+    }
+    public ParsedStyle getAstyle() {
+        return astyle;
+    }
+    public void setAstyle(ParsedStyle astyle) {
+        this.astyle = astyle;
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedLedgerAccount.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedLedgerAccount.java
new file mode 100644 (file)
index 0000000..d346cb7
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_14;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import java.util.List;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedLedgerAccount {
+    private List<ParsedBalance> aebalance;
+    private List<ParsedBalance> aibalance;
+    private String aname;
+    public ParsedLedgerAccount() {
+    }
+    public List<ParsedBalance> getAebalance() {
+        return aebalance;
+    }
+    public List<ParsedBalance> getAibalance() {
+        return aibalance;
+    }
+    public void setAebalance(List<ParsedBalance> aebalance) {
+        this.aebalance = aebalance;
+    }
+    public void setAibalance(List<ParsedBalance> aibalance) {
+        this.aibalance = aibalance;
+    }
+    public String getAname() {
+        return aname;
+    }
+    public void setAname(String aname) {
+        this.aname = aname;
+    }
+
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedLedgerTransaction.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedLedgerTransaction.java
new file mode 100644 (file)
index 0000000..e95c27c
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_14;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import net.ktnx.mobileledger.model.LedgerTransaction;
+import net.ktnx.mobileledger.model.LedgerTransactionAccount;
+import net.ktnx.mobileledger.utils.Globals;
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedLedgerTransaction implements net.ktnx.mobileledger.json.ParsedLedgerTransaction {
+    private String tdate;
+    private String tdate2 = null;
+    private String tdescription;
+    private String tcomment;
+    private String tcode = "";
+    private String tstatus = "Unmarked";
+    private String tprecedingcomment = "";
+    private int tindex;
+    private List<ParsedPosting> tpostings;
+    private List<List<String>> ttags = new ArrayList<>();
+    private ParsedSourcePos
+            tsourcepos = new ParsedSourcePos();
+    public ParsedLedgerTransaction() {
+    }
+    public static ParsedLedgerTransaction fromLedgerTransaction(LedgerTransaction tr) {
+        ParsedLedgerTransaction
+                result = new ParsedLedgerTransaction();
+        result.setTcomment("");
+        result.setTprecedingcomment("");
+
+        ArrayList<ParsedPosting> postings = new ArrayList<>();
+        for (LedgerTransactionAccount acc : tr.getAccounts()) {
+            if (!acc.getAccountName()
+                    .isEmpty())
+                postings.add(ParsedPosting.fromLedgerAccount(acc));
+        }
+
+        result.setTpostings(postings);
+        Date transactionDate = tr.getDate();
+        if (transactionDate == null) {
+            transactionDate = new GregorianCalendar().getTime();
+        }
+        result.setTdate(Globals.formatIsoDate(transactionDate));
+        result.setTdate2(null);
+        result.setTindex(1);
+        result.setTdescription(tr.getDescription());
+        return result;
+    }
+    public String getTcode() {
+        return tcode;
+    }
+    public void setTcode(String tcode) {
+        this.tcode = tcode;
+    }
+    public String getTstatus() {
+        return tstatus;
+    }
+    public void setTstatus(String tstatus) {
+        this.tstatus = tstatus;
+    }
+    public List<List<String>> getTtags() {
+        return ttags;
+    }
+    public void setTtags(List<List<String>> ttags) {
+        this.ttags = ttags;
+    }
+    public ParsedSourcePos getTsourcepos() {
+        return tsourcepos;
+    }
+    public void setTsourcepos(ParsedSourcePos tsourcepos) {
+        this.tsourcepos = tsourcepos;
+    }
+    public String getTprecedingcomment() {
+        return tprecedingcomment;
+    }
+    public void setTprecedingcomment(String tprecedingcomment) {
+        this.tprecedingcomment = tprecedingcomment;
+    }
+    public String getTdate() {
+        return tdate;
+    }
+    public void setTdate(String tdate) {
+        this.tdate = tdate;
+    }
+    public String getTdate2() {
+        return tdate2;
+    }
+    public void setTdate2(String tdate2) {
+        this.tdate2 = tdate2;
+    }
+    public String getTdescription() {
+        return tdescription;
+    }
+    public void setTdescription(String tdescription) {
+        this.tdescription = tdescription;
+    }
+    public String getTcomment() {
+        return tcomment;
+    }
+    public void setTcomment(String tcomment) {
+        this.tcomment = tcomment;
+    }
+    public int getTindex() {
+        return tindex;
+    }
+    public void setTindex(int tindex) {
+        this.tindex = tindex;
+        if (tpostings != null)
+            for (ParsedPosting p : tpostings) {
+                p.setPtransaction_(tindex);
+            }
+    }
+    public List<ParsedPosting> getTpostings() {
+        return tpostings;
+    }
+    public void setTpostings(List<ParsedPosting> tpostings) {
+        this.tpostings = tpostings;
+    }
+    public void addPosting(ParsedPosting posting) {
+        posting.setPtransaction_(tindex);
+        tpostings.add(posting);
+    }
+    public LedgerTransaction asLedgerTransaction() throws ParseException {
+        Date date = Globals.parseIsoDate(tdate);
+        LedgerTransaction tr = new LedgerTransaction(tindex, date, tdescription);
+
+        List<ParsedPosting> postings = tpostings;
+
+        if (postings != null) {
+            for (ParsedPosting p : postings) {
+                tr.addAccount(p.asLedgerAccount());
+            }
+        }
+        return tr;
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedPosting.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedPosting.java
new file mode 100644 (file)
index 0000000..21cc6db
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_14;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import net.ktnx.mobileledger.model.LedgerTransactionAccount;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedPosting {
+    private Void pbalanceassertion;
+    private String pstatus = "Unmarked";
+    private String paccount;
+    private List<ParsedAmount> pamount;
+    private String pdate = null;
+    private String pdate2 = null;
+    private String ptype = "RegularPosting";
+    private String pcomment = "";
+    private List<List<String>> ptags = new ArrayList<>();
+    private String poriginal = null;
+    private int ptransaction_;
+    public ParsedPosting() {
+    }
+    public static ParsedPosting fromLedgerAccount(LedgerTransactionAccount acc) {
+        ParsedPosting result = new ParsedPosting();
+        result.setPaccount(acc.getAccountName());
+        ArrayList<ParsedAmount> amounts = new ArrayList<>();
+        ParsedAmount amt = new ParsedAmount();
+        amt.setAcommodity((acc.getCurrency() == null) ? "" : acc.getCurrency());
+        amt.setAismultiplier(false);
+        ParsedQuantity qty = new ParsedQuantity();
+        qty.setDecimalPlaces(2);
+        qty.setDecimalMantissa(Math.round(acc.getAmount() * 100));
+        amt.setAquantity(qty);
+        ParsedStyle style = new ParsedStyle();
+        style.setAscommodityside('L');
+        style.setAscommodityspaced(false);
+        style.setAsprecision(2);
+        style.setAsdecimalpoint('.');
+        amt.setAstyle(style);
+        amounts.add(amt);
+        result.setPamount(amounts);
+        return result;
+    }
+    public String getPdate2() {
+        return pdate2;
+    }
+    public void setPdate2(String pdate2) {
+        this.pdate2 = pdate2;
+    }
+    public int getPtransaction_() {
+        return ptransaction_;
+    }
+    public void setPtransaction_(int ptransaction_) {
+        this.ptransaction_ = ptransaction_;
+    }
+    public String getPdate() {
+        return pdate;
+    }
+    public void setPdate(String pdate) {
+        this.pdate = pdate;
+    }
+    public String getPtype() {
+        return ptype;
+    }
+    public void setPtype(String ptype) {
+        this.ptype = ptype;
+    }
+    public String getPcomment() {
+        return pcomment;
+    }
+    public void setPcomment(String pcomment) {
+        this.pcomment = pcomment;
+    }
+    public List<List<String>> getPtags() {
+        return ptags;
+    }
+    public void setPtags(List<List<String>> ptags) {
+        this.ptags = ptags;
+    }
+    public String getPoriginal() {
+        return poriginal;
+    }
+    public void setPoriginal(String poriginal) {
+        this.poriginal = poriginal;
+    }
+    public String getPstatus() {
+        return pstatus;
+    }
+    public void setPstatus(String pstatus) {
+        this.pstatus = pstatus;
+    }
+    public Void getPbalanceassertion() {
+        return pbalanceassertion;
+    }
+    public void setPbalanceassertion(Void pbalanceassertion) {
+        this.pbalanceassertion = pbalanceassertion;
+    }
+    public String getPaccount() {
+        return paccount;
+    }
+    public void setPaccount(String paccount) {
+        this.paccount = paccount;
+    }
+    public List<ParsedAmount> getPamount() {
+        return pamount;
+    }
+    public void setPamount(List<ParsedAmount> pamount) {
+        this.pamount = pamount;
+    }
+    public LedgerTransactionAccount asLedgerAccount() {
+        ParsedAmount amt = pamount.get(0);
+        return new LedgerTransactionAccount(paccount, amt.getAquantity()
+                                                         .asFloat(), amt.getAcommodity());
+    }
+
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedPrice.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedPrice.java
new file mode 100644 (file)
index 0000000..7f457a7
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_14;
+
+class ParsedPrice {
+    private String tag;
+    private Contents contents;
+    public ParsedPrice() {
+        tag = "NoPrice";
+    }
+    public Contents getContents() {
+        return contents;
+    }
+    public void setContents(Contents contents) {
+        this.contents = contents;
+    }
+    public String getTag() {
+        return tag;
+    }
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
+    private class Contents {
+        private ParsedPrice aprice;
+        private ParsedQuantity aquantity;
+        private String acommodity;
+        private boolean aismultiplier;
+        private ParsedStyle astyle;
+        public Contents() {
+            acommodity = "";
+        }
+        public ParsedPrice getAprice() {
+            return aprice;
+        }
+        public void setAprice(ParsedPrice aprice) {
+            this.aprice = aprice;
+        }
+        public ParsedQuantity getAquantity() {
+            return aquantity;
+        }
+        public void setAquantity(ParsedQuantity aquantity) {
+            this.aquantity = aquantity;
+        }
+        public String getAcommodity() {
+            return acommodity;
+        }
+        public void setAcommodity(String acommodity) {
+            this.acommodity = acommodity;
+        }
+        public boolean isAismultiplier() {
+            return aismultiplier;
+        }
+        public void setAismultiplier(boolean aismultiplier) {
+            this.aismultiplier = aismultiplier;
+        }
+        public ParsedStyle getAstyle() {
+            return astyle;
+        }
+        public void setAstyle(ParsedStyle astyle) {
+            this.astyle = astyle;
+        }
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedQuantity.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedQuantity.java
new file mode 100644 (file)
index 0000000..72b6fc6
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_14;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedQuantity {
+    private long decimalMantissa;
+    private int decimalPlaces;
+    public ParsedQuantity() {
+    }
+    public ParsedQuantity(String input) {
+        parseString(input);
+    }
+    public long getDecimalMantissa() {
+        return decimalMantissa;
+    }
+    public void setDecimalMantissa(long decimalMantissa) {
+        this.decimalMantissa = decimalMantissa;
+    }
+    public int getDecimalPlaces() {
+        return decimalPlaces;
+    }
+    public void setDecimalPlaces(int decimalPlaces) {
+        this.decimalPlaces = decimalPlaces;
+    }
+    public float asFloat() {
+        return (float) (decimalMantissa * Math.pow(10, -decimalPlaces));
+    }
+    public void parseString(String input) {
+        int pointPos = input.indexOf('.');
+        if (pointPos >= 0) {
+            String integral = input.replace(".", "");
+            decimalMantissa = Long.valueOf(integral);
+            decimalPlaces = input.length() - pointPos - 1;
+        }
+        else {
+            decimalMantissa = Long.valueOf(input);
+            decimalPlaces = 0;
+        }
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedSourcePos.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedSourcePos.java
new file mode 100644 (file)
index 0000000..1d55355
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_14;
+
+import java.util.ArrayList;
+import java.util.List;
+
+class ParsedSourcePos {
+    private String tag = "JournalSourcePos";
+    private List<Object> contents;
+    public ParsedSourcePos() {
+        contents = new ArrayList<>();
+        contents.add("");
+        contents.add(new Integer[]{1, 1});
+    }
+    public String getTag() {
+        return tag;
+    }
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
+    public List<Object> getContents() {
+        return contents;
+    }
+    public void setContents(List<Object> contents) {
+        this.contents = contents;
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedStyle.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedStyle.java
new file mode 100644 (file)
index 0000000..798cb81
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_14;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedStyle {
+    private int asprecision;
+    private char asdecimalpoint;
+    private char ascommodityside;
+    private int digitgroups;
+    private boolean ascommodityspaced;
+    public ParsedStyle() {
+    }
+    public int getAsprecision() {
+        return asprecision;
+    }
+    public void setAsprecision(int asprecision) {
+        this.asprecision = asprecision;
+    }
+    public char getAsdecimalpoint() {
+        return asdecimalpoint;
+    }
+    public void setAsdecimalpoint(char asdecimalpoint) {
+        this.asdecimalpoint = asdecimalpoint;
+    }
+    public char getAscommodityside() {
+        return ascommodityside;
+    }
+    public void setAscommodityside(char ascommodityside) {
+        this.ascommodityside = ascommodityside;
+    }
+    public int getDigitgroups() {
+        return digitgroups;
+    }
+    public void setDigitgroups(int digitgroups) {
+        this.digitgroups = digitgroups;
+    }
+    public boolean isAscommodityspaced() {
+        return ascommodityspaced;
+    }
+    public void setAscommodityspaced(boolean ascommodityspaced) {
+        this.ascommodityspaced = ascommodityspaced;
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/TransactionListParser.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/TransactionListParser.java
new file mode 100644 (file)
index 0000000..8056685
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_14;
+
+import com.fasterxml.jackson.databind.MappingIterator;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectReader;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class TransactionListParser {
+
+    private final MappingIterator<ParsedLedgerTransaction> iter;
+
+    public TransactionListParser(InputStream input) throws IOException {
+
+        ObjectMapper mapper = new ObjectMapper();
+        ObjectReader reader = mapper.readerFor(ParsedLedgerTransaction.class);
+        iter = reader.readValues(input);
+    }
+    public ParsedLedgerTransaction nextTransaction() {
+        return iter.hasNext() ? iter.next() : null;
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/AccountListParser.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/AccountListParser.java
new file mode 100644 (file)
index 0000000..4206d0f
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_15;
+
+import com.fasterxml.jackson.databind.MappingIterator;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectReader;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import static net.ktnx.mobileledger.utils.Logger.debug;
+
+public class AccountListParser {
+
+    private final MappingIterator<ParsedLedgerAccount> iter;
+
+    public AccountListParser(InputStream input) throws IOException {
+        ObjectMapper mapper = new ObjectMapper();
+        ObjectReader reader = mapper.readerFor(ParsedLedgerAccount.class);
+
+        iter = reader.readValues(input);
+    }
+    public ParsedLedgerAccount nextAccount() {
+        if (!iter.hasNext()) return null;
+
+        ParsedLedgerAccount next = iter.next();
+
+        if (next.getAname().equalsIgnoreCase("root")) return nextAccount();
+
+        debug("accounts", String.format("Got account '%s'", next.getAname()));
+        return next;
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedAmount.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedAmount.java
new file mode 100644 (file)
index 0000000..3dee4ae
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_15;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedAmount {
+    private String acommodity;
+    private ParsedQuantity aquantity;
+    private boolean aismultiplier;
+    private ParsedStyle astyle;
+    private ParsedPrice aprice;
+    public ParsedAmount() {
+    }
+    public ParsedPrice getAprice() {
+        return aprice;
+    }
+    public void setAprice(ParsedPrice aprice) {
+        this.aprice = aprice;
+    }
+    public String getAcommodity() {
+        return acommodity;
+    }
+    public void setAcommodity(String acommodity) {
+        this.acommodity = acommodity;
+    }
+    public ParsedQuantity getAquantity() {
+        return aquantity;
+    }
+    public void setAquantity(ParsedQuantity aquantity) {
+        this.aquantity = aquantity;
+    }
+    public boolean isAismultiplier() {
+        return aismultiplier;
+    }
+    public void setAismultiplier(boolean aismultiplier) {
+        this.aismultiplier = aismultiplier;
+    }
+    public ParsedStyle getAstyle() {
+        return astyle;
+    }
+    public void setAstyle(ParsedStyle astyle) {
+        this.astyle = astyle;
+    }
+
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedBalance.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedBalance.java
new file mode 100644 (file)
index 0000000..24e9ccb
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_15;
+
+import androidx.annotation.NonNull;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedBalance {
+    private ParsedQuantity aquantity;
+    private String acommodity;
+    private ParsedStyle astyle;
+    public ParsedBalance() {
+    }
+    public ParsedQuantity getAquantity() {
+        return aquantity;
+    }
+    public void setAquantity(ParsedQuantity aquantity) {
+        this.aquantity = aquantity;
+    }
+    @NonNull
+    public String getAcommodity() {
+        return (acommodity == null) ? "" : acommodity;
+    }
+    public void setAcommodity(String acommodity) {
+        this.acommodity = acommodity;
+    }
+    public ParsedStyle getAstyle() {
+        return astyle;
+    }
+    public void setAstyle(ParsedStyle astyle) {
+        this.astyle = astyle;
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedLedgerAccount.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedLedgerAccount.java
new file mode 100644 (file)
index 0000000..89f3ccc
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_15;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import java.util.List;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedLedgerAccount {
+    private List<ParsedBalance> aebalance;
+    private List<ParsedBalance> aibalance;
+    private String aname;
+    public ParsedLedgerAccount() {
+    }
+    public List<ParsedBalance> getAebalance() {
+        return aebalance;
+    }
+    public List<ParsedBalance> getAibalance() {
+        return aibalance;
+    }
+    public void setAebalance(List<ParsedBalance> aebalance) {
+        this.aebalance = aebalance;
+    }
+    public void setAibalance(List<ParsedBalance> aibalance) {
+        this.aibalance = aibalance;
+    }
+    public String getAname() {
+        return aname;
+    }
+    public void setAname(String aname) {
+        this.aname = aname;
+    }
+
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedLedgerTransaction.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedLedgerTransaction.java
new file mode 100644 (file)
index 0000000..2f6867d
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_15;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import net.ktnx.mobileledger.model.LedgerTransaction;
+import net.ktnx.mobileledger.model.LedgerTransactionAccount;
+import net.ktnx.mobileledger.utils.Globals;
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedLedgerTransaction implements net.ktnx.mobileledger.json.ParsedLedgerTransaction {
+    private String tdate;
+    private String tdate2 = null;
+    private String tdescription;
+    private String tcomment;
+    private String tcode = "";
+    private String tstatus = "Unmarked";
+    private String tprecedingcomment = "";
+    private int tindex;
+    private List<ParsedPosting> tpostings;
+    private List<List<String>> ttags = new ArrayList<>();
+    private ParsedSourcePos tsourcepos = new ParsedSourcePos();
+    public ParsedLedgerTransaction() {
+    }
+    public static ParsedLedgerTransaction fromLedgerTransaction(LedgerTransaction tr) {
+        ParsedLedgerTransaction result = new ParsedLedgerTransaction();
+        result.setTcomment("");
+        result.setTprecedingcomment("");
+
+        ArrayList<ParsedPosting> postings = new ArrayList<>();
+        for (LedgerTransactionAccount acc : tr.getAccounts()) {
+            if (!acc.getAccountName()
+                    .isEmpty())
+                postings.add(ParsedPosting.fromLedgerAccount(acc));
+        }
+
+        result.setTpostings(postings);
+        Date transactionDate = tr.getDate();
+        if (transactionDate == null) {
+            transactionDate = new GregorianCalendar().getTime();
+        }
+        result.setTdate(Globals.formatIsoDate(transactionDate));
+        result.setTdate2(null);
+        result.setTindex(1);
+        result.setTdescription(tr.getDescription());
+        return result;
+    }
+    public String getTcode() {
+        return tcode;
+    }
+    public void setTcode(String tcode) {
+        this.tcode = tcode;
+    }
+    public String getTstatus() {
+        return tstatus;
+    }
+    public void setTstatus(String tstatus) {
+        this.tstatus = tstatus;
+    }
+    public List<List<String>> getTtags() {
+        return ttags;
+    }
+    public void setTtags(List<List<String>> ttags) {
+        this.ttags = ttags;
+    }
+    public ParsedSourcePos getTsourcepos() {
+        return tsourcepos;
+    }
+    public void setTsourcepos(ParsedSourcePos tsourcepos) {
+        this.tsourcepos = tsourcepos;
+    }
+    public String getTprecedingcomment() {
+        return tprecedingcomment;
+    }
+    public void setTprecedingcomment(String tprecedingcomment) {
+        this.tprecedingcomment = tprecedingcomment;
+    }
+    public String getTdate() {
+        return tdate;
+    }
+    public void setTdate(String tdate) {
+        this.tdate = tdate;
+    }
+    public String getTdate2() {
+        return tdate2;
+    }
+    public void setTdate2(String tdate2) {
+        this.tdate2 = tdate2;
+    }
+    public String getTdescription() {
+        return tdescription;
+    }
+    public void setTdescription(String tdescription) {
+        this.tdescription = tdescription;
+    }
+    public String getTcomment() {
+        return tcomment;
+    }
+    public void setTcomment(String tcomment) {
+        this.tcomment = tcomment;
+    }
+    public int getTindex() {
+        return tindex;
+    }
+    public void setTindex(int tindex) {
+        this.tindex = tindex;
+        if (tpostings != null)
+            for (ParsedPosting p : tpostings) {
+                p.setPtransaction_(tindex);
+            }
+    }
+    public List<ParsedPosting> getTpostings() {
+        return tpostings;
+    }
+    public void setTpostings(List<ParsedPosting> tpostings) {
+        this.tpostings = tpostings;
+    }
+    public void addPosting(ParsedPosting posting) {
+        posting.setPtransaction_(tindex);
+        tpostings.add(posting);
+    }
+    public LedgerTransaction asLedgerTransaction() throws ParseException {
+        Date date = Globals.parseIsoDate(tdate);
+        LedgerTransaction tr = new LedgerTransaction(tindex, date, tdescription);
+
+        List<ParsedPosting> postings = tpostings;
+
+        if (postings != null) {
+            for (ParsedPosting p : postings) {
+                tr.addAccount(p.asLedgerAccount());
+            }
+        }
+        return tr;
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPosting.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPosting.java
new file mode 100644 (file)
index 0000000..7c20a7b
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_15;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import net.ktnx.mobileledger.model.LedgerTransactionAccount;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedPosting {
+    private Void pbalanceassertion;
+    private String pstatus = "Unmarked";
+    private String paccount;
+    private List<ParsedAmount> pamount;
+    private String pdate = null;
+    public String getPdate2() {
+        return pdate2;
+    }
+    public void setPdate2(String pdate2) {
+        this.pdate2 = pdate2;
+    }
+    private String pdate2 = null;
+    private String ptype = "RegularPosting";
+    private String pcomment = "";
+    private List<List<String>> ptags = new ArrayList<>();
+    private String poriginal = null;
+    private int ptransaction_;
+    public int getPtransaction_() {
+        return ptransaction_;
+    }
+    public void setPtransaction_(int ptransaction_) {
+        this.ptransaction_ = ptransaction_;
+    }
+    public ParsedPosting() {
+    }
+    public String getPdate() {
+        return pdate;
+    }
+    public void setPdate(String pdate) {
+        this.pdate = pdate;
+    }
+    public String getPtype() {
+        return ptype;
+    }
+    public void setPtype(String ptype) {
+        this.ptype = ptype;
+    }
+    public String getPcomment() {
+        return pcomment;
+    }
+    public void setPcomment(String pcomment) {
+        this.pcomment = pcomment;
+    }
+    public List<List<String>> getPtags() {
+        return ptags;
+    }
+    public void setPtags(List<List<String>> ptags) {
+        this.ptags = ptags;
+    }
+    public String getPoriginal() {
+        return poriginal;
+    }
+    public void setPoriginal(String poriginal) {
+        this.poriginal = poriginal;
+    }
+    public String getPstatus() {
+        return pstatus;
+    }
+    public void setPstatus(String pstatus) {
+        this.pstatus = pstatus;
+    }
+    public Void getPbalanceassertion() {
+        return pbalanceassertion;
+    }
+    public void setPbalanceassertion(Void pbalanceassertion) {
+        this.pbalanceassertion = pbalanceassertion;
+    }
+    public String getPaccount() {
+        return paccount;
+    }
+    public void setPaccount(String paccount) {
+        this.paccount = paccount;
+    }
+    public List<ParsedAmount> getPamount() {
+        return pamount;
+    }
+    public void setPamount(List<ParsedAmount> pamount) {
+        this.pamount = pamount;
+    }
+    public LedgerTransactionAccount asLedgerAccount() {
+        ParsedAmount amt = pamount.get(0);
+        return new LedgerTransactionAccount(paccount, amt.getAquantity().asFloat(),
+                amt.getAcommodity());
+    }
+    public static ParsedPosting fromLedgerAccount(LedgerTransactionAccount acc) {
+        ParsedPosting result = new ParsedPosting();
+        result.setPaccount(acc.getAccountName());
+        ArrayList<ParsedAmount> amounts = new ArrayList<>();
+        ParsedAmount amt = new ParsedAmount();
+        amt.setAcommodity((acc.getCurrency() == null) ? "" : acc.getCurrency());
+        amt.setAismultiplier(false);
+        ParsedQuantity qty = new ParsedQuantity();
+        qty.setDecimalPlaces(2);
+        qty.setDecimalMantissa(Math.round(acc.getAmount() * 100));
+        amt.setAquantity(qty);
+        ParsedStyle style = new ParsedStyle();
+        style.setAscommodityside('L');
+        style.setAscommodityspaced(false);
+        style.setAsprecision(2);
+        style.setAsdecimalpoint('.');
+        amt.setAstyle(style);
+        amounts.add(amt);
+        result.setPamount(amounts);
+        return result;
+    }
+
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPrice.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPrice.java
new file mode 100644 (file)
index 0000000..409ed8b
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_15;
+
+class ParsedPrice {
+    private String tag;
+    private Contents contents;
+    public ParsedPrice() {
+        tag = "NoPrice";
+    }
+    public Contents getContents() {
+        return contents;
+    }
+    public void setContents(Contents contents) {
+        this.contents = contents;
+    }
+    public String getTag() {
+        return tag;
+    }
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
+    private class Contents {
+        private ParsedPrice aprice;
+        private ParsedQuantity aquantity;
+        private String acommodity;
+        private boolean aismultiplier;
+        private ParsedStyle astyle;
+        public Contents() {
+            acommodity = "";
+        }
+        public ParsedPrice getAprice() {
+            return aprice;
+        }
+        public void setAprice(ParsedPrice aprice) {
+            this.aprice = aprice;
+        }
+        public ParsedQuantity getAquantity() {
+            return aquantity;
+        }
+        public void setAquantity(ParsedQuantity aquantity) {
+            this.aquantity = aquantity;
+        }
+        public String getAcommodity() {
+            return acommodity;
+        }
+        public void setAcommodity(String acommodity) {
+            this.acommodity = acommodity;
+        }
+        public boolean isAismultiplier() {
+            return aismultiplier;
+        }
+        public void setAismultiplier(boolean aismultiplier) {
+            this.aismultiplier = aismultiplier;
+        }
+        public ParsedStyle getAstyle() {
+            return astyle;
+        }
+        public void setAstyle(ParsedStyle astyle) {
+            this.astyle = astyle;
+        }
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedQuantity.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedQuantity.java
new file mode 100644 (file)
index 0000000..898d597
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_15;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedQuantity {
+    private long decimalMantissa;
+    private int decimalPlaces;
+    public ParsedQuantity() {
+    }
+    public ParsedQuantity(String input) {
+        parseString(input);
+    }
+    public long getDecimalMantissa() {
+        return decimalMantissa;
+    }
+    public void setDecimalMantissa(long decimalMantissa) {
+        this.decimalMantissa = decimalMantissa;
+    }
+    public int getDecimalPlaces() {
+        return decimalPlaces;
+    }
+    public void setDecimalPlaces(int decimalPlaces) {
+        this.decimalPlaces = decimalPlaces;
+    }
+    public float asFloat() {
+        return (float) (decimalMantissa * Math.pow(10, -decimalPlaces));
+    }
+    public void parseString(String input) {
+        int pointPos = input.indexOf('.');
+        if (pointPos >= 0) {
+            String integral = input.replace(".", "");
+            decimalMantissa = Long.valueOf(integral);
+            decimalPlaces = input.length() - pointPos - 1;
+        }
+        else {
+            decimalMantissa = Long.valueOf(input);
+            decimalPlaces = 0;
+        }
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedSourcePos.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedSourcePos.java
new file mode 100644 (file)
index 0000000..9a78330
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_15;
+
+import java.util.ArrayList;
+import java.util.List;
+
+class ParsedSourcePos {
+    private String tag = "JournalSourcePos";
+    private List<Object> contents;
+    public ParsedSourcePos() {
+        contents = new ArrayList<>();
+        contents.add("");
+        contents.add(new Integer[]{1, 1});
+    }
+    public String getTag() {
+        return tag;
+    }
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
+    public List<Object> getContents() {
+        return contents;
+    }
+    public void setContents(List<Object> contents) {
+        this.contents = contents;
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedStyle.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedStyle.java
new file mode 100644 (file)
index 0000000..554133c
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_15;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedStyle {
+    private int asprecision;
+    private char asdecimalpoint;
+    private char ascommodityside;
+    private int digitgroups;
+    private boolean ascommodityspaced;
+    public ParsedStyle() {
+    }
+    public int getAsprecision() {
+        return asprecision;
+    }
+    public void setAsprecision(int asprecision) {
+        this.asprecision = asprecision;
+    }
+    public char getAsdecimalpoint() {
+        return asdecimalpoint;
+    }
+    public void setAsdecimalpoint(char asdecimalpoint) {
+        this.asdecimalpoint = asdecimalpoint;
+    }
+    public char getAscommodityside() {
+        return ascommodityside;
+    }
+    public void setAscommodityside(char ascommodityside) {
+        this.ascommodityside = ascommodityside;
+    }
+    public int getDigitgroups() {
+        return digitgroups;
+    }
+    public void setDigitgroups(int digitgroups) {
+        this.digitgroups = digitgroups;
+    }
+    public boolean isAscommodityspaced() {
+        return ascommodityspaced;
+    }
+    public void setAscommodityspaced(boolean ascommodityspaced) {
+        this.ascommodityspaced = ascommodityspaced;
+    }
+}
diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/TransactionListParser.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/TransactionListParser.java
new file mode 100644 (file)
index 0000000..c621074
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json.v1_15;
+
+import com.fasterxml.jackson.databind.MappingIterator;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectReader;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class TransactionListParser {
+
+    private final MappingIterator<ParsedLedgerTransaction> iter;
+
+    public TransactionListParser(InputStream input) throws IOException {
+
+        ObjectMapper mapper = new ObjectMapper();
+        ObjectReader reader = mapper.readerFor(ParsedLedgerTransaction.class);
+        iter = reader.readValues(input);
+    }
+    public ParsedLedgerTransaction nextTransaction() {
+        return iter.hasNext() ? iter.next() : null;
+    }
+}
index 252b32f41ed7f1fe1ae8fbad7afbefde7c7127e7..696803670c51067b88a3f002d282db95fe19e8c0 100644 (file)
@@ -20,8 +20,6 @@ package net.ktnx.mobileledger.model;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 
-import net.ktnx.mobileledger.json.ParsedLedgerTransaction;
-import net.ktnx.mobileledger.json.ParsedPosting;
 import net.ktnx.mobileledger.utils.Digest;
 import net.ktnx.mobileledger.utils.Globals;
 
 import net.ktnx.mobileledger.utils.Digest;
 import net.ktnx.mobileledger.utils.Globals;
 
@@ -31,7 +29,6 @@ import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.Date;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.Date;
-import java.util.GregorianCalendar;
 
 public class LedgerTransaction {
     private static final String DIGEST_TYPE = "SHA-256";
 
 public class LedgerTransaction {
     private static final String DIGEST_TYPE = "SHA-256";
@@ -191,25 +188,4 @@ public class LedgerTransaction {
     public void finishLoading() {
         dataLoaded = true;
     }
     public void finishLoading() {
         dataLoaded = true;
     }
-    public ParsedLedgerTransaction toParsedLedgerTransaction() {
-        ParsedLedgerTransaction result = new ParsedLedgerTransaction();
-        result.setTcomment("");
-        result.setTprecedingcomment("");
-
-        ArrayList<ParsedPosting> postings = new ArrayList<>();
-        for (LedgerTransactionAccount acc : accounts) {
-            if (!acc.getAccountName().isEmpty()) postings.add(acc.asParsedPosting());
-        }
-
-        result.setTpostings(postings);
-        Date transactionDate = date;
-        if (transactionDate == null) {
-            transactionDate = new GregorianCalendar().getTime();
-        }
-        result.setTdate(Globals.formatIsoDate(transactionDate));
-        result.setTdate2(null);
-        result.setTindex(1);
-        result.setTdescription(description);
-        return result;
-    }
 }
 }
index 801e0169845f8c2ff2daedb06177eec7d62ba3d6..89d6a83a5d3c935ce98b0dcaa65c8d82fa0b6410 100644 (file)
@@ -19,13 +19,6 @@ package net.ktnx.mobileledger.model;
 
 import androidx.annotation.NonNull;
 
 
 import androidx.annotation.NonNull;
 
-import net.ktnx.mobileledger.json.ParsedAmount;
-import net.ktnx.mobileledger.json.ParsedPosting;
-import net.ktnx.mobileledger.json.ParsedQuantity;
-import net.ktnx.mobileledger.json.ParsedStyle;
-
-import java.util.ArrayList;
-
 public class LedgerTransactionAccount {
     private String accountName;
     private String shortAccountName;
 public class LedgerTransactionAccount {
     private String accountName;
     private String shortAccountName;
@@ -100,25 +93,4 @@ public class LedgerTransactionAccount {
 
         return sb.toString();
     }
 
         return sb.toString();
     }
-    public ParsedPosting asParsedPosting() {
-        ParsedPosting result = new ParsedPosting();
-        result.setPaccount(accountName);
-        ArrayList<ParsedAmount> amounts = new ArrayList<>();
-        ParsedAmount amt = new ParsedAmount();
-        amt.setAcommodity((currency == null) ? "" : currency);
-        amt.setAismultiplier(false);
-        ParsedQuantity qty = new ParsedQuantity();
-        qty.setDecimalPlaces(2);
-        qty.setDecimalMantissa(Math.round(amount * 100));
-        amt.setAquantity(qty);
-        ParsedStyle style = new ParsedStyle();
-        style.setAscommodityside('L');
-        style.setAscommodityspaced(false);
-        style.setAsprecision(2);
-        style.setAsdecimalpoint('.');
-        amt.setAstyle(style);
-        amounts.add(amt);
-        result.setPamount(amounts);
-        return result;
-    }
 }
 }
index e17948f36c8a4d286772af71952f846a5084540c..2cd159c5e7079c840e333f56da1e5c0c6eaf99a8 100644 (file)
@@ -28,6 +28,7 @@ import androidx.annotation.Nullable;
 import net.ktnx.mobileledger.App;
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.async.DbOpQueue;
 import net.ktnx.mobileledger.App;
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.async.DbOpQueue;
+import net.ktnx.mobileledger.async.SendTransactionTask;
 import net.ktnx.mobileledger.utils.Globals;
 import net.ktnx.mobileledger.utils.Logger;
 import net.ktnx.mobileledger.utils.MLDB;
 import net.ktnx.mobileledger.utils.Globals;
 import net.ktnx.mobileledger.utils.Logger;
 import net.ktnx.mobileledger.utils.MLDB;
@@ -52,6 +53,7 @@ public final class MobileLedgerProfile {
     private int themeId;
     private int orderNo = -1;
     private FutureDates futureDates = FutureDates.None;
     private int themeId;
     private int orderNo = -1;
     private FutureDates futureDates = FutureDates.None;
+    private SendTransactionTask.API apiVersion = SendTransactionTask.API.auto;
     public MobileLedgerProfile() {
         this.uuid = String.valueOf(UUID.randomUUID());
     }
     public MobileLedgerProfile() {
         this.uuid = String.valueOf(UUID.randomUUID());
     }
@@ -70,6 +72,7 @@ public final class MobileLedgerProfile {
         themeId = origin.themeId;
         orderNo = origin.orderNo;
         futureDates = origin.futureDates;
         themeId = origin.themeId;
         orderNo = origin.orderNo;
         futureDates = origin.futureDates;
+        apiVersion = origin.apiVersion;
     }
     // loads all profiles into Data.profiles
     // returns the profile with the given UUID
     }
     // loads all profiles into Data.profiles
     // returns the profile with the given UUID
@@ -120,6 +123,15 @@ public final class MobileLedgerProfile {
             db.endTransaction();
         }
     }
             db.endTransaction();
         }
     }
+    public SendTransactionTask.API getApiVersion() {
+        return apiVersion;
+    }
+    public void setApiVersion(SendTransactionTask.API apiVersion) {
+        this.apiVersion = apiVersion;
+    }
+    public void setApiVersion(int apiVersion) {
+        this.apiVersion = SendTransactionTask.API.valueOf(apiVersion);
+    }
     public FutureDates getFutureDates() {
         return futureDates;
     }
     public FutureDates getFutureDates() {
         return futureDates;
     }
index 7402ed52e91011e75c313510f7dcacab90e11437..b1f6c4dc5cbf55b208275cfc52f40ff9f1b894c6 100644 (file)
     <string name="future_dates_all">Без ограничения</string>
     <string name="future_dates_none">Без въвеждане на бъдещи дати</string>
     <string name="profile_future_dates_label">Въвеждане на дати в бъдещето</string>
     <string name="future_dates_all">Без ограничения</string>
     <string name="future_dates_none">Без въвеждане на бъдещи дати</string>
     <string name="profile_future_dates_label">Въвеждане на дати в бъдещето</string>
+    <string name="api_auto">Автоматично откриване</string>
+    <string name="api_html">Симулиране на заявка от браузър</string>
+    <string name="api_post_1_14">версия 1.15 и по-нови</string>
+    <string name="api_pre_1_15">версии преди 1.15</string>
 
 </resources>
 
 </resources>
index c18ada94e222da7bea2799737ca01ba3e4a24716..5f98037e2fc6d2ac888c2a4cdd63242dfe6efb7f 100644 (file)
     <string name="future_dates_180">Up to six months</string>
     <string name="future_dates_365">Up to a year</string>
     <string name="future_dates_all">Without restrictions</string>
     <string name="future_dates_180">Up to six months</string>
     <string name="future_dates_365">Up to a year</string>
     <string name="future_dates_all">Without restrictions</string>
+    <string name="api_html">Simulate HTML form</string>
+    <string name="api_pre_1_15">version before 1.15</string>
+    <string name="api_post_1_14">version 1.15 and above</string>
+    <string name="api_auto">Detect automaticaly</string>
 </resources>
 </resources>
index 38e05f87e8bb0196e263ce5ab6e780c3f5397dda..4841528093ab48d2bc72274cbaba0d3df292f724 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.ktnx.mobileledger.json;
 
 
 package net.ktnx.mobileledger.json;
 
+import net.ktnx.mobileledger.json.v1_15.ParsedQuantity;
+
 import org.junit.Test;
 
 import static junit.framework.TestCase.assertEquals;
 import org.junit.Test;
 
 import static junit.framework.TestCase.assertEquals;