Download_V1_0.java [src/java/m/cfa] Revision: 779e6ead6d7fed07f9d7ef7750fc6a597a6846b4  Date: Thu Mar 13 09:55:08 MDT 2014
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package m.cfa;

import cfa.guiDownload_Data;
import csip.AbstractModelService;
import java.util.Map;
import java.util.concurrent.Callable;
import javax.ws.rs.Path;
import oms3.annotations.Description;
import oms3.annotations.Name;
import oms3.annotations.VersionInfo;
import org.codehaus.jettison.json.*;
import csip.utils.JSONUtils;
import java.io.File;

@Name("download")
@Description("download")
@VersionInfo("1.0")
@Path("m/cfa/download/1.0")
public class Download_V1_0 extends AbstractModelService {

    guiDownload_Data model = new guiDownload_Data();

    @Override
    protected Callable<String> createCallable() throws Exception {
        return new Callable<String>() {
            @Override
            public String call() throws Exception {
                Map<String, JSONObject> m = getParamMap();

                model.setMainFolder(getWorkspaceDir().toString());
                model.setOrganizationName(m.get("org").getString(VALUE));
                model.setStationID(m.get("station_id").getString(VALUE));
                model.setWaterQualityTest(m.get("wq_test").getString(VALUE));
                model.setBeginDate(m.get("begin_date").getString(VALUE));
                model.setEndDate(m.get("end_date").getString(VALUE));

                model.run();
                return EXEC_OK;
            }
        };
    }
    
    @Override
    public File[] postprocess() throws Exception {
        return new File[] {model.getOutput()};
    }
    
    @Override
    protected JSONArray createResults() throws Exception {
//        String output = FileUtils.readFileToString(model.getOutput());
        JSONArray result = new JSONArray();
        result.put(JSONUtils.data("output", "Output successfully created"));
        result.put(JSONUtils.data("output_location", model.getOutput().getName()));
        return result;
    }
  
}