@@ -59,13 +59,20 @@ |
public static final String RIVERTRAK = "rivertrak"; |
public static final String RIVERTRAK_MAR19 = "rivertrak_Mar19"; |
|
- public static final String RIVERTRAK_CFG = "rivertrak.cfg"; |
- public static final String CONFIG_DIM = "dim"; |
- public static final String CONFIG_UNITS = "units"; |
- public static final String CONFIG_DATATYPES = "datatypes"; |
- public static final String CONFIG_PROPERTIES = "properties"; |
+ static final String RIVERTRAK_CFG = "rivertrak.cfg"; |
+ static final String CONFIG_DIM = "dim"; |
+ static final String CONFIG_UNITS = "units"; |
+ static final String CONFIG_DATATYPES = "datatypes"; |
+ static final String CONFIG_PROPERTIES = "properties"; |
|
- public static final String RIVERTRAK_CONF_VM = "org/rti/rivertrak/config.vm"; |
+ static final String RIVERTRAK_CONF_VM = "org/rti/rivertrak/config.vm"; |
+ |
+ static final String FORMKEY_TSINPUT = "ts_input"; |
+ static final String METAKEY_MODELNAME = "model_name"; |
+ static final String PARAMKEY_OPTABLE = "OpTable"; |
+ static final String PARAMKEY_RUNSTARTDATE = "RunStartDate"; |
+ static final String PARAMKEY_RUNENDDATE = "RunEndDate"; |
+ static final String PARAMKEY_STATESWRITEMODE = "StatesWriteMode"; |
|
// config properties |
static final String DRIVE = Config.getString("win.drive", "Z:"); |
@@ -78,12 +85,12 @@ |
int refreshCount; |
String opTable = "Models.optable"; |
|
- private static class KeyIterable implements Iterable<String> { |
+ private static class JSONKeys implements Iterable<String> { |
|
JSONObject json; |
|
|
- KeyIterable(JSONObject json) { |
+ JSONKeys(JSONObject json) { |
this.json = json; |
} |
|
@@ -99,6 +106,12 @@ |
@Override |
protected void doProcess() throws Exception { |
|
+ parameter().require(PARAMKEY_OPTABLE) |
+ .require(PARAMKEY_RUNSTARTDATE) |
+ .require(PARAMKEY_RUNENDDATE) |
+ .require(PARAMKEY_STATESWRITEMODE); |
+ formdata().requireKey(FORMKEY_TSINPUT); |
+ |
// config settings with defaults |
enableDebug = parameter().getInt("EnableDebug", 0); |
debugLevel = parameter().getInt("DebugLevel", 1); |
@@ -108,10 +121,6 @@ |
|
getWorkspaceFile("States").mkdirs(); |
|
- if (!formdata().hasKey("ts_input")) { |
- throw new ServiceException("missing attachement ts_input"); |
- } |
- |
if (!getWorkspaceFile("TimeSeries").exists()) { |
throw new ServiceException("No Time series data."); |
} |
@@ -121,22 +130,18 @@ |
modelFolder.mkdirs(); |
} |
|
- parameter().require("OpTable"); |
- |
try { |
// assume an embedded JSONObject for optable |
- JSONObject j = parameter().getJSON("OpTable"); |
- for (String modelName : new KeyIterable(j)) { |
- |
+ JSONObject j = parameter().getJSON(PARAMKEY_OPTABLE); |
+ for (String modelName : new JSONKeys(j)) { |
// append to opTable |
FileUtils.write(new File(modelFolder, opTable), modelName + "\n", true); |
- |
try (PrintWriter w = new PrintWriter(new File(modelFolder, modelName))) { |
JSONObject modelDefs = j.getJSONObject(modelName); |
- for (String section : new KeyIterable(modelDefs)) { |
+ for (String section : new JSONKeys(modelDefs)) { |
w.println("#" + section); |
JSONObject kv = modelDefs.getJSONObject(section); |
- for (String key : new KeyIterable(kv)) { |
+ for (String key : new JSONKeys(kv)) { |
w.println(key + "=" + kv.get(key).toString()); |
} |
} |
@@ -144,24 +149,24 @@ |
} |
} catch (ServiceException E) { |
// carry on |
- opTable = parameter().getString("OpTable"); |
+ opTable = parameter().getString(PARAMKEY_OPTABLE); |
} |
|
File opTableFile = new File(modelFolder, opTable); |
if (!opTableFile.exists()) { |
- throw new ServiceException("Optable file not found: " + opTable.toString()); |
+ throw new ServiceException("OpTable file not found: " + opTable); |
} |
|
String modelName = RIVERTRAK; |
- if (metainfo().hasName("model_name")) { |
- modelName = metainfo().getString("model_name"); |
+ if (metainfo().hasName(METAKEY_MODELNAME)) { |
+ modelName = metainfo().getString(METAKEY_MODELNAME); |
} |
|
Executable rt = resources().getExe(modelName); |
rt.addArguments("-Config", createConfig(), |
- "-RunStartDate", parameter().getString("RunStartDate"), |
- "-RunEndDate", parameter().getString("RunEndDate"), |
- "-StatesWriteMode", parameter().getString("StatesWriteMode", "WRITE") |
+ "-RunStartDate", parameter().getString(PARAMKEY_RUNSTARTDATE), |
+ "-RunEndDate", parameter().getString(PARAMKEY_RUNENDDATE), |
+ "-StatesWriteMode", parameter().getString(PARAMKEY_STATESWRITEMODE, "WRITE") |
); |
|
int ret = rt.exec(); |