@@ -27,7 +27,6 @@ |
import java.io.FileOutputStream; |
import java.util.*; |
import javax.ws.rs.*; |
-import oms3.annotations.*; |
import org.apache.commons.io.FileUtils; |
import org.apache.commons.lang.StringEscapeUtils; |
import org.codehaus.jettison.json.JSONArray; |
@@ -40,8 +39,8 @@ |
import static csip.ModelDataService.REPORT_DIM; |
import static csip.ModelDataService.REPORT_NAME; |
import static csip.ModelDataService.REPORT_TYPE; |
-import static csip.ModelDataService.REPORT_VALUE; |
import static csip.ModelDataService.VALUE; |
+import csip.annotations.*; |
import static util.ErosionConst.*; |
|
import csip.utils.JSONUtils; |
@@ -189,33 +188,32 @@ |
|
|
@Override |
- protected JSONArray createResults() throws Exception { |
- JSONArray results = new JSONArray(); |
+ protected void postProcess() throws Exception { |
int errors = 0; |
for (int i = 0; i < operations.size(); i++) { |
String op = operations.get(i); |
if (isUrlReachable(op)) { |
- results.put(JSONUtils.dataDesc("OPERATION_" + (i + 1), op, "operation is valid")); |
+ putResult("OPERATION_" + (i + 1), op, "operation is valid"); |
} else { |
- results.put(JSONUtils.dataDesc("OPERATION_INVALID_" + (i + 1), op, "OPERATION IS MISSING!")); |
+ putResult("OPERATION_INVALID_" + (i + 1), op, "OPERATION IS MISSING!"); |
errors++; |
} |
} |
for (int i = 0; i < vegetations.size(); i++) { |
String vege = vegetations.get(i); |
if (isUrlReachable(vege)) { |
- results.put(JSONUtils.dataDesc("VEGETATION_" + (i + 1), vege, "vegetation is valid")); |
+ putResult("VEGETATION_" + (i + 1),vege,"vegetation is valid"); |
} else { |
- results.put(JSONUtils.dataDesc("VEGETATION_INVALID_" + (i + 1), vege, "VEGETATION IS MISSING")); |
+ putResult("VEGETATION_INVALID_" + (i + 1), vege, "VEGETATION IS MISSING"); |
errors++; |
} |
} |
for (int i = 0; i < residues.size(); i++) { |
String res = residues.get(i); |
if (isUrlReachable(res)) { |
- results.put(JSONUtils.dataDesc("RESIDUE_" + (i + 1), res, "residue is valid")); |
+ putResult("RESIDUE_" + (i + 1), res, "residue is valid"); |
} else { |
- results.put(JSONUtils.dataDesc("RESIDUE_INVALID_" + (i + 1), res, "RESIDUE IS MISSING")); |
+ putResult("RESIDUE_INVALID_" + (i + 1), res, "RESIDUE IS MISSING"); |
errors++; |
} |
} |
@@ -224,20 +222,19 @@ |
String sout = FileUtils.readFileToString(stdout); |
for (String r : JSONUtils.getRequestedResults(getMetainfo())) { |
if ((errors > 0) && (r.equals(RES_SLOPE_DEGRAD))) { |
- results.put(JSONUtils.dataDesc(r, getResult(sout, r), R2_MISSING_XML_FILES_WARNING_MSG)); |
+ putResult(r, getResult(sout, r), R2_MISSING_XML_FILES_WARNING_MSG); |
} else { |
- results.put(JSONUtils.data(r, getResult(sout, r))); |
+ putResult(r, getResult(sout, r)); |
} |
} |
if (errors > 0) { |
appendMetainfoWarning(R2_MISSING_XML_FILES_WARNING_MSG); |
} |
|
- results.put(JSONUtils.data(KEY_CLIMATES, climate)); |
- results.put(JSONUtils.data(KEY_SOILS, soil)); |
- results.put(JSONUtils.data(KEY_MANAGEMENTS, mgmt)); |
+ putResult(KEY_CLIMATES, climate); |
+ putResult(KEY_SOILS, soil); |
+ putResult(KEY_MANAGEMENTS, mgmt); |
// results.put(JSONUtils.data(KEY_ALT_R2DB, in_ALT_R2DB)); |
- return results; |
} |
|
|
@@ -653,62 +650,65 @@ |
|
|
@Override |
- protected JSONArray createReport() throws Exception { |
+ protected void doReport() throws Exception { |
String sReportJSON = FileUtils.readFileToString(getResourceFile(REPORT_JSON)); |
JSONArray reportItemsFromTemplate = new JSONArray(sReportJSON); |
- JSONArray reportItemsOutput = new JSONArray(); |
+ |
String sout = FileUtils.readFileToString(stdout); |
|
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 = getResult(sout, "\"" + itemName + "\""); |
//LOG.info("the value='" + value + "'"); |
if ((value != null) && (value.equals("null"))) { |
- obj.put(REPORT_VALUE, (String) null); |
+ putReport(itemName, value, 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 { |
- obj.put(REPORT_VALUE, new JSONArray(value)); |
- } catch (JSONException je) { |
- obj = processReportElement(obj, type, value); |
+ putReport(itemName, new JSONArray(value), desc, units); |
+ |
+ } catch (JSONException je) { |
+ processReportElement(itemName,dimension,units,desc, type, value); |
} |
} else { |
- obj = processReportElement(obj, type, value); |
+ processReportElement(itemName,dimension,units,desc, type, value); |
} |
- obj.remove(REPORT_TYPE); |
- reportItemsOutput.put(obj); |
} |
+ if(dimension != null) |
+ putReportMetaInfo(itemName,REPORT_DIM,new JSONArray(dimension)); |
} |
- return reportItemsOutput; |
} |
|
|
- private JSONObject processReportElement(JSONObject obj, String type, String value) throws Exception { |
+ // This is a gross signiture but due to csip report changes this is the easiest way to change it without losing Wes's logic. |
+ private void processReportElement(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); |
- obj.put(REPORT_VALUE, Services.removeFirstLastChar(newString)); |
+ putReport(itemName, Services.removeFirstLastChar(newString), desc, units); |
} |
if (type.equals("INTEGER") && (value != null) && (!value.equals("null")) && (!value.equals("\"\""))) { |
- obj.put("value", new Double(value).intValue()); |
+ putReport(itemName, new Double(value).intValue(), desc, units); |
} |
if (type.equals("REAL") && (value != null)) { |
if ((!value.equals("null")) && (!value.equals("\"\""))) { |
- obj.put(REPORT_VALUE, new Double(value).doubleValue()); |
+ putReport(itemName, Double.parseDouble(value), desc, units); |
} |
if (value.equals("\"\"")) { |
- obj.put(REPORT_VALUE, new Double(0).doubleValue()); |
+ putReport(itemName, new Double(0), desc, units); |
} |
} |
if (type.equals("")) { |
- obj.put(REPORT_VALUE, value); |
+ putReport(itemName, value, desc, units); |
} |
- return obj; |
} |
} |
@@ -11,6 +11,7 @@ |
import csip.Executable; |
import csip.ModelDataService; |
import csip.ServiceException; |
+import csip.annotations.*; |
import csip.annotations.Polling; |
import csip.annotations.Resource; |
import static csip.annotations.ResourceType.*; |
@@ -28,9 +29,6 @@ |
import javax.ws.rs.Path; |
import man2weps.WepsTranslator; |
import man2weps.mcrew.ManageData; |
-import oms3.annotations.Description; |
-import oms3.annotations.Name; |
-import oms3.annotations.VersionInfo; |
import org.apache.commons.io.FileUtils; |
import org.apache.commons.io.IOUtils; |
import org.apache.http.HttpResponse; |
@@ -889,9 +887,8 @@ |
|
|
@Override |
- public JSONArray createResults() throws Exception { |
+ public void postProcess() throws Exception { |
LOG.info("Create the WEPS results..."); |
- JSONArray results = new JSONArray(); |
|
FileReader fr = new FileReader(sessionWorkDir + "/sci_energy.out"); |
BufferedReader bfr = new BufferedReader(fr); |
@@ -915,20 +912,19 @@ |
double windEros_tonAcreYear = Double.parseDouble(wo.windEros) * CONV_KGM2_TONACRE; |
double waterEros_tonAcreYear = Double.parseDouble(wo.waterEros) * CONV_KGM2_TONACRE; |
|
- results.put(JSONUtils.dataDesc(WEPS_RES_SOIL_COND_INDEX, wo.soilConditioningIndex, "total SCI (soil conditioning index)")); |
- results.put(JSONUtils.dataDesc(WEPS_RES_SCI_OM_FACTOR, wo.sciOmFactor, "SCI Organic Matter subfactor")); |
- results.put(JSONUtils.dataDesc(WEPS_RES_SCI_ER_FACTOR, wo.sciErFactor, "SCI Erosion Rate subfactor")); |
- results.put(JSONUtils.dataDesc(WEPS_RES_SCI_FO_FACTOR, wo.sciFoFactor, "SCI Field Operations subfactor")); |
- results.put(JSONUtils.dataUnitDesc(WEPS_RES_DIESEL_ENERGY, dieselEnergy_gallonsPerAcre, "gallon(Diesel)/acre", "energy used by management operations, expressed as fuel consumption equivalent")); |
- results.put(JSONUtils.dataUnitDesc(WEPS_RES_AVG_BIOMASS, averageBiomass_tonAcreYear, "ton/acre/year", "Average biomass")); |
- results.put(JSONUtils.dataUnitDesc(WEPS_RES_WIND_EROS, windEros_tonAcreYear, "ton/acre/year", "Wind erosion (computed by WEPS)")); |
- results.put(JSONUtils.dataUnitDesc(WEPS_RES_WATER_EROS, waterEros_tonAcreYear, "ton/acre/year", "Water erosion (external input)")); |
- results.put(JSONUtils.dataDesc(WEPS_RES_AVG_ALL_STIR, wo.avgAllStir, "Average STIR")); |
- results.put(JSONUtils.data(WEPS_SALTATION, wo.saltation)); |
- results.put(JSONUtils.data(WEPS_SUSPENSION, wo.suspension)); |
- results.put(JSONUtils.data(WEPS_PM10, wo.pm10)); |
+ putResult(WEPS_RES_SOIL_COND_INDEX, wo.soilConditioningIndex, "total SCI (soil conditioning index)"); |
+ putResult(WEPS_RES_SCI_OM_FACTOR, wo.sciOmFactor, "SCI Organic Matter subfactor"); |
+ putResult(WEPS_RES_SCI_ER_FACTOR, wo.sciErFactor, "SCI Erosion Rate subfactor"); |
+ putResult(WEPS_RES_SCI_FO_FACTOR, wo.sciFoFactor, "SCI Field Operations subfactor"); |
+ putResult(WEPS_RES_DIESEL_ENERGY, dieselEnergy_gallonsPerAcre, "SCI Field Operations subfactor"); |
+ putResult(WEPS_RES_AVG_BIOMASS, averageBiomass_tonAcreYear, "Average biomass", "ton/acre/year"); |
+ putResult(WEPS_RES_WIND_EROS, windEros_tonAcreYear, "Wind erosion (computed by WEPS)", "ton/acre/year"); |
+ putResult(WEPS_RES_WATER_EROS, waterEros_tonAcreYear, "Water erosion (external input)", "ton/acre/year"); |
+ putResult(WEPS_RES_AVG_ALL_STIR, wo.avgAllStir, "Average STIR"); |
+ putResult(WEPS_SALTATION, wo.saltation); |
+ putResult(WEPS_SUSPENSION, wo.suspension); |
+ putResult(WEPS_PM10, wo.pm10); |
|
- return results; |
} |
|
|