V1_0.java [src/java/m/ewsf/prms] Revision: default  Date:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package m.ewsf.prms;

import csip.Config;
import csip.ModelDataService;
import csip.annotations.Polling;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.Path;
import csip.annotations.Description;
import csip.annotations.Name;
import csip.annotations.VersionInfo;

/**
 * PRMS service.
 *
 * @author od
 */
@Name("PRMS")
@Description("PRMS model")
@VersionInfo("1.0")
@Polling(first = 4000, next = 1000)
@Path("m/prms/1.0")
public class V1_0 extends ModelDataService {

  // parameter keys
  static final String KEY_START = "startTime";
  static final String KEY_END = "endTime";


  @Override
  protected void doProcess() throws Exception {
    String startTime = parameter().getString(KEY_START);
    String endTime = parameter().getString(KEY_END);
    runPRMS(workspace().getDir(), startTime, endTime);
  }


  @Override
  protected void postProcess() throws Exception {
    results().put(new File("prms/out/out.csv"));
    results().put(new File("prms/out/out1.csv"));
  }

  ///////////

  private void runPRMS(File ws, String startTime, String endTime) throws Exception {
    String binDir = Config.getString("m.bin.dir", "/tmp/csip/bin");

    // unpacking a jar file does not work (security?). Unpacking any other
    // file and then renaming it works fine.
//        File prms = Binaries.unpackResource("/prms.jar_", new File(binDir, "prms.jar"));
    File prms = resources().getFile("prms.jar_");

//        File sim = Binaries.unpackResource("/prms.sim", ws);
    File sim = resources().getFile("prms.sim");

    // add prms to the path.
    System.setProperty("oms.sim.resources", prms.toString());

    // Binding variables
    Map m = new HashMap();
    m.put("oms_prj", ws.toString());
    m.put("startTime", startTime);
    m.put("endTime", endTime);

//        oms3.CLI.dsl(sim.toString(), "OFF", "run", m);
  }


  // local testing
  public static void main(String[] args) throws Exception {
//        runPRMS(new File("/tmp/csip/work"), "1980-10-01", "1986-09-30");
  }
}