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;
package net.ktnx.mobileledger.async;
+import android.content.res.Resources;
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 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;
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", "*/*");
- 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();
- ObjectWriter writer = mapper.writerFor(ParsedLedgerTransaction.class);
+ ObjectWriter writer =
+ mapper.writerFor(net.ktnx.mobileledger.json.v1_15.ParsedLedgerTransaction.class);
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 {
case 200:
case 201:
break;
+ case 400:
case 405:
return false; // will cause a retry with the legacy method
default:
}
}
}
-
@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) {
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);
}
+
+ 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);
+ }
+ }
+ }
}
+++ /dev/null
-/*
- * 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;
- }
-}
+++ /dev/null
-/*
- * 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;
- }
-
-}
+++ /dev/null
-/*
- * 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;
- }
-}
+++ /dev/null
-/*
- * 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;
- }
-
-}
package net.ktnx.mobileledger.json;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
import net.ktnx.mobileledger.model.LedgerTransaction;
-import net.ktnx.mobileledger.utils.Globals;
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;
}
+++ /dev/null
-/*
- * 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());
- }
-}
+++ /dev/null
-/*
- * 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;
- }
- }
-}
+++ /dev/null
-/*
- * 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;
- }
- }
-}
+++ /dev/null
-/*
- * 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;
- }
-}
+++ /dev/null
-/*
- * 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;
- }
-}
+++ /dev/null
-/*
- * 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;
- }
-}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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());
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
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 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 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;
- }
}
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;
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;
- }
}
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;
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());
}
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
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;
}
<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>
<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>
package net.ktnx.mobileledger.json;
+import net.ktnx.mobileledger.json.v1_15.ParsedQuantity;
+
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;