package com.spoon.backgroundFileUpload;

import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;


public class FileTransferSettings {

  String filePath = "";
  String serverUrl = "";
  String id = "";
  String fileKey = "file";
  boolean showNotification = true;
  String notificationTitle;

  HashMap<String, String> headers = new HashMap<String, String>();
  HashMap<String, String> parameters = new HashMap<String, String>();


  public FileTransferSettings(String jsonSettings) throws Exception {
    try {
      JSONObject settings = new JSONObject(jsonSettings);

      filePath = settings.getString("filePath");
      serverUrl = settings.getString("serverUrl");
      id = settings.getString("id");
      fileKey = settings.getString("fileKey");
      showNotification = settings.getBoolean("showNotification");
      notificationTitle = settings.getString("notificationTitle");

      if (settings.has("headers")) {
        JSONObject headersObject = settings.getJSONObject("headers");
        if (headersObject != null) {

          Iterator<?> keys = headersObject.keys();
          while (keys.hasNext()) {
            String key = (String) keys.next();
            String value = headersObject.getString(key);
            headers.put(key, value);
          }

        }
      }

      if (settings.has("parameters")) {
        JSONObject parametersObject = settings.getJSONObject("parameters");
        if (parametersObject != null) {

          Iterator<?> keys = parametersObject.keys();
          while (keys.hasNext()) {
            String key = (String) keys.next();
            String value = parametersObject.getString(key);
            parameters.put(key, value);
          }

        }
      }

      if (!new File(filePath).exists())
        throw new IOException("File not found: " + filePath);

    } catch (Exception e) {
      throw e;
    }
  }
}

@@ -820,24 +820,70 @@
 %22fileKey%22);%0A
+      if (settings.has(%22showNotification%22))%0A  
       showNo
@@ -932,24 +932,71 @@
 fication%22);%0A
+      if (settings.has(%22notificationTitle%22))%0A  
       notifi

check for optional values