Displaying differences for changeset
 
display as  

src/java/m/rusle2/V3_0.java

@@ -77,6 +77,7 @@
 
 @Resource(type = FILE, file = "/bin/win-x86/rusle2_report.py", id = REPORT_PY_FILENAME)
 @Resource(type = FILE, file = "/bin/win-x86/Rusle2_Report.json", id = REPORT_JSON_TEMPLATE_FILENAME)
+@Resource(type = FILE, file = "/bin/win-x86/Rusle2_out.json", id = OUT_JSON_TEMPLATE_FILENAME)
 
 public class V3_0 extends ModelDataService {
 
@@ -92,6 +93,9 @@
   static final String IO_TIMING_FILENAME = "/tmp/io-timing";
   static final String IO_TIMING_FILEEXT = ".txt";
   static final String REPORT_JSON_TEMPLATE_FILENAME = "Rusle2_Report.json";
+
+  // additional outputs
+  static final String OUT_JSON_TEMPLATE_FILENAME = "Rusle2_out.json";
   static final String REPORT_PY_FILENAME = "rusle2_report.py";
   static final String KEY_COKEY = "cokey";
 
@@ -265,6 +269,8 @@
       results().put(KEY_SOILS, new JSONArray(r2run.getResultPyromeArray("SEG_SOIL", true, true, true)));
       results().put(KEY_MANAGEMENTS, new JSONArray(r2run.getResultPyromeArray("SEG_MAN", true, true, true)));
     }
+
+    additionalOutputs();
   }
 
 
@@ -859,6 +865,78 @@
   }
 
 
+  protected void additionalOutputs() throws Exception {
+    File reportTemplate = resources().getFile(OUT_JSON_TEMPLATE_FILENAME);
+    String sReportJSON = FileUtils.readFileToString(reportTemplate, "UTF-8");
+
+    JSONArray reportItemsFromTemplate = new JSONArray(sReportJSON);
+
+    for (int i = 0; i < reportItemsFromTemplate.length(); i++) {
+      JSONObject obj = (JSONObject) reportItemsFromTemplate.get(i);
+      String itemName = obj.getString(REPORT_NAME);
+      String dimension = JSONUtils.getJSONString(obj, REPORT_DIM, null);
+      String type = JSONUtils.getJSONString(obj, REPORT_TYPE, "");
+      String units = JSONUtils.getJSONString(obj, REPORT_UNITS, null);
+      String desc = JSONUtils.getJSONString(obj, REPORT_DESC, null);
+      //LOG.info("Attempting to fetch results for:" + itemName);
+
+      String value = r2run.getResult("\"" + itemName + "\"");
+      LOG.info("the value='" + value + "'");
+      if ((value != null) && (value.equals("null"))) {
+        results().put(itemName, (String) null, desc, units);
+        // if there is no value, then item should be removed from the array
+      } else {
+        if ((dimension != null) && (dimension.length() > 0) && (value != null) && (!value.equals("null"))) {
+          try {
+            results().put(itemName, new JSONArray(value), desc, units);
+          } catch (JSONException je) {
+            processReportElement0(itemName, dimension, units, desc, type, value);
+          }
+        } else {
+          processReportElement0(itemName, dimension, units, desc, type, value);
+        }
+
+      }
+      if (dimension != null) {
+        results().putMetaInfo(itemName, REPORT_DIM, new JSONArray(dimension));
+      }
+    }
+  }
+
+
+  private void processReportElement0(String itemName, String dim, String units, String desc, String type, String value) throws Exception {
+
+    if ((type.equals("TEXT")) || (type.equals("FILENAME")) || (type.equals("DATE"))) {
+      // because the RomeShell returns escaped strings, and the JSONObject in Java re-escapes them
+      // we have to remove one level of "escaping" !!!
+
+      String newString = StringEscapeUtils.unescapeJava(value);
+      //String newString=value;
+      results().put(itemName, removeFirstLastChar(newString), desc, units);
+    }
+    if (type.equals("INTEGER") && (value != null) && (!value.equals("null")) && (!value.equals("\"\""))) {
+      // trim off quotes
+      value = removeFirstLastChar(value);
+      System.out.println("VALUE:" + value);
+      results().put(itemName, new Double(value).intValue(), desc, units);
+    }
+    if (type.equals("REAL") && (value != null)) {
+      if ((!value.equals("null")) && (!value.equals("\"\""))) {
+        // trim off quotes
+        value = removeFirstLastChar(value);
+        System.out.println("VALUE:" + value);
+        results().put(itemName, Double.parseDouble(value), desc, units);
+      }
+      if (value.equals("\"\"")) {
+        results().put(itemName, new Double(0), desc, units);
+      }
+    }
+    if (type.equals("")) {
+      results().put(itemName, value, desc, units);
+    }
+  }
+
+
   @Override
   protected void doReport() throws Exception {
 //        String sessionWorkDir = workspace().getDir().toString();

web/WEB-INF/csip-defaults.json

@@ -1,5 +1,5 @@
 { 
-    "csip-r2.version": "$version: 2.11.8.17 default 87 9bcde88e6206 2022-02-10 od, built at 2022-02-10 14:41 by od$",
+    "csip-r2.version": "$version: 2.11.8.18 default 88 49b5c32f9833 2022-02-10 od, built at 2022-02-18 11:04 by od$",
     "lmod.db": "jdbc:sqlserver:\/\/129.82.20.242:1433;databaseName=lmod_temp;user=lmod-rw;password=?",
     "sdmONLINE":"true",
     "csip.session.ttl": "PT1M",