package com.sailthru.client.params.job;

import com.google.gson.reflect.TypeToken;
import com.sailthru.client.SailthruUtil;
import com.sailthru.client.params.ApiFileParams;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.lang.reflect.Type;
import java.util.HashMap;

/**
 *
 * @author Prajwal Tuladhar <praj@sailthru.com>
 */
public class ImportJob extends Job implements ApiFileParams {
    
    private static final String JOB = "import";
    
    protected String emails;
    protected transient File file = null;
    protected String list;

    public ImportJob() {
        this.job = JOB;
    }
    
    public ImportJob setEmails(List<String> emails) {
        this.emails = SailthruUtil.arrayListToCSV(emails);
        return this;
    }
    
    public ImportJob setFile(String filePath) {
        this.file = new File(filePath);
        return this;
    }
    
    public ImportJob setFile(File file) {
        this.file = file;
        return this;
    }
    
    public ImportJob setList(String list) {
        this.list = list;
        return this;
    }
    
    @Override
    public Type getType() {
        return new TypeToken<ImportJob>() {}.getType();
    }
    
    
    public Map<String, File> getFileParams() {
        Map<String, File> files = new HashMap<String, File>();
        if (this.file != null) {
            files.put("file", this.file);
        }
        return files;
    }
}

@@ -177,20 +177,148 @@
 ort 
-java.io.File
+org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.FileNotFoundException
 ;%0Aim
@@ -422,67 +422,8 @@
 p;%0A%0A
-/**%0A *%0A * @author Prajwal Tuladhar %3Cpraj@sailthru.com%3E%0A */%0A
 publ
@@ -480,21 +480,16 @@
 arams %7B%0A
-    %0A
     priv
@@ -528,24 +528,98 @@
 mport%22;%0A    
+protected static Logger logger = LoggerFactory.getLogger(ImportJob.class);
 %0A    protect
@@ -660,24 +660,35 @@
 ansient File
+InputStream
  file = null
@@ -909,36 +909,32 @@
 urn this;%0A    %7D%0A
-    
 %0A    public Impo
@@ -962,24 +962,42 @@
 filePath) %7B%0A
+        try %7B%0A    
         this
@@ -1016,19 +1016,126 @@
 File
-(filePath);
+InputStream(filePath);%0A        %7D catch (FileNotFoundException e) %7B%0A            logger.error(e.getMessage());%0A        %7D
 %0A   
@@ -1150,36 +1150,32 @@
 urn this;%0A    %7D%0A
-    
 %0A    public Impo
@@ -1214,24 +1214,403 @@
    t
-his.file = file;
+ry %7B%0A            this.file = new FileInputStream(file);%0A        %7D catch (FileNotFoundException e) %7B%0A            logger.error(e.getMessage());%0A        %7D%0A        return this;%0A    %7D%0A%0A    public ImportJob setFileInputStream(String data) %7B%0A        try %7B%0A            this.file = new FileInputStream(data);%0A        %7D catch (FileNotFoundException e) %7B%0A            logger.error(e.getMessage());%0A        %7D
 %0A   
@@ -1844,25 +1844,16 @@
 ;%0A    %7D%0A
-    %0A    
 %0A    pub
@@ -1872,16 +1872,27 @@
 ng, File
+InputStream
 %3E getFil
@@ -1927,16 +1927,27 @@
 ng, File
+InputStream
 %3E files 
@@ -1972,16 +1972,27 @@
 ng, File
+InputStream
 %3E();%0A   

Change implementation from File to FileInputStream for ImportJob