import net.ktnx.mobileledger.model.LedgerTransactionAccount;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
import net.ktnx.mobileledger.utils.Globals;
+import net.ktnx.mobileledger.utils.Logger;
import net.ktnx.mobileledger.utils.NetworkUtil;
import net.ktnx.mobileledger.utils.UrlEncodedFormData;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
+import java.util.Date;
+import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.Map;
private String session;
private LedgerTransaction ltr;
private MobileLedgerProfile mProfile;
+ private boolean simulate = false;
+ public SendTransactionTask(TaskCallback callback, MobileLedgerProfile profile,
+ boolean simulate) {
+ taskCallback = callback;
+ mProfile = profile;
+ this.simulate = simulate;
+ }
public SendTransactionTask(TaskCallback callback, MobileLedgerProfile profile) {
taskCallback = callback;
mProfile = profile;
+ simulate = false;
}
private boolean sendOK() throws IOException {
-// if (BuildConfig.DEBUG) {
-// TODO: simulate random problems
-//
-// try {
-// Thread.sleep(1500);
-// }
-// catch (InterruptedException ex) {
-// Logger.debug("network", ex.toString());
-// }
-//
-// return true;
-// }
+ if (simulate) {
+ try {
+ Thread.sleep(1500);
+ if (Math.random() > 0.3)
+ throw new RuntimeException("Simulated test exception");
+ }
+ catch (InterruptedException ex) {
+ Logger.debug("network", ex.toString());
+ }
+
+ return true;
+ }
HttpURLConnection http = NetworkUtil.prepareConnection(mProfile, "add");
http.setRequestMethod("PUT");
params.addPair("_formid", "identify-add");
if (token != null)
params.addPair("_token", token);
- params.addPair("date", Globals.formatLedgerDate(ltr.getDate()));
+
+ Date transactionDate = ltr.getDate();
+ if (transactionDate == null) {
+ transactionDate = new GregorianCalendar().getTime();
+ }
+
+ params.addPair("date", Globals.formatLedgerDate(transactionDate));
params.addPair("description", ltr.getDescription());
for (LedgerTransactionAccount acc : ltr.getAccounts()) {
params.addPair("account", acc.getAccountName());