@@ -192,27 +192,27 @@ |
for (int i = 0; i < operations.size(); i++) { |
String op = operations.get(i); |
if (isFileUrlReachable(op)) { |
- putResult("OPERATION_" + (i + 1), op, "operation is valid"); |
+ results().put("OPERATION_" + (i + 1), op, "operation is valid"); |
} else { |
- putResult("OPERATION_INVALID_" + (i + 1), op, "OPERATION IS MISSING!"); |
+ results().put("OPERATION_INVALID_" + (i + 1), op, "OPERATION IS MISSING!"); |
errors++; |
} |
} |
for (int i = 0; i < vegetations.size(); i++) { |
String vege = vegetations.get(i); |
if (isFileUrlReachable(vege)) { |
- putResult("VEGETATION_" + (i + 1),vege,"vegetation is valid"); |
+ results().put("VEGETATION_" + (i + 1),vege,"vegetation is valid"); |
} else { |
- putResult("VEGETATION_INVALID_" + (i + 1), vege, "VEGETATION IS MISSING"); |
+ results().put("VEGETATION_INVALID_" + (i + 1), vege, "VEGETATION IS MISSING"); |
errors++; |
} |
} |
for (int i = 0; i < residues.size(); i++) { |
String res = residues.get(i); |
if (isFileUrlReachable(res)) { |
- putResult("RESIDUE_" + (i + 1), res, "residue is valid"); |
+ results().put("RESIDUE_" + (i + 1), res, "residue is valid"); |
} else { |
- putResult("RESIDUE_INVALID_" + (i + 1), res, "RESIDUE IS MISSING"); |
+ results().put("RESIDUE_INVALID_" + (i + 1), res, "RESIDUE IS MISSING"); |
errors++; |
} |
} |
@@ -221,19 +221,19 @@ |
String sout = FileUtils.readFileToString(stdout); |
for (String r : JSONUtils.getRequestedResults(getMetainfo())) { |
if ((errors > 0) && (r.equals(RES_SLOPE_DEGRAD))) { |
- putResult(r, getResult(sout, r), R2_MISSING_XML_FILES_WARNING_MSG); |
+ results().put(r, getResult(sout, r), R2_MISSING_XML_FILES_WARNING_MSG); |
} else { |
- putResult(r, getResult(sout, r)); |
+ results().put(r, getResult(sout, r)); |
} |
} |
if (errors > 0) { |
- appendMetainfoWarning(R2_MISSING_XML_FILES_WARNING_MSG); |
+ metainfo().appendWarning(R2_MISSING_XML_FILES_WARNING_MSG); |
} |
|
|
- putResult(KEY_CLIMATES, climate); |
- putResult(KEY_SOILS, soil); |
- putResult(KEY_MANAGEMENTS, mgmt); |
+ results().put(KEY_CLIMATES, climate); |
+ results().put(KEY_SOILS, soil); |
+ results().put(KEY_MANAGEMENTS, mgmt); |
// results.put(JSONUtils.data(KEY_ALT_R2DB, in_ALT_R2DB)); |
} |
|
@@ -245,7 +245,7 @@ |
* @throws IOException |
*/ |
private File execute(File r2_rsh) throws ServiceException, IOException { |
- Executable exe = getResourceExe(ROME_EXE); |
+ Executable exe = resources().getExe(ROME_EXE); |
exe.setArguments(r2_rsh.toString()); |
int result = exe.exec(); |
if (result != 0) { |
@@ -277,7 +277,7 @@ |
|
|
int prepareSoilsFile(String soilsHttpPtr, File workingDir, boolean bPyrome, String idx) throws IOException, ServiceException { |
- Executable exe = getResourceExe(PREP_SOILS); |
+ Executable exe = resources().getExe(PREP_SOILS); |
exe.setArguments(soilsHttpPtr); |
int result = exe.exec(); |
if (result != 0) { |
@@ -501,7 +501,7 @@ |
altR2db = param.get(KEY_ALT_R2DB).getString(VALUE); |
} |
|
- GIS_DB db = new SqlGIS(getResourceJDBC(DB)); |
+ GIS_DB db = new SqlGIS(resources().getJDBC(DB)); |
|
// If this is a Lat/Lng request, then we need to make a DB lookup |
// to obtain the Climate and Soil information and ignore whatever |
@@ -533,7 +533,7 @@ |
GIS_DB.FileQryResult so = db.findSoilsByCokey(cokey, longitude); |
if (so == null) { |
LOG.warning("No soil for lat=" + latitude + "\nfor long=" + longitude + "\n"); |
- appendMetainfoWarning(R2_NO_SOIL_FOR_PROVIDED_COKEY); |
+ metainfo().appendWarning(R2_NO_SOIL_FOR_PROVIDED_COKEY); |
soilPtr = ""; |
} else { |
soilPtr = so.file_path + "\\" + so.file_name; |
@@ -636,7 +636,7 @@ |
fos.close(); |
|
// Unpack the report rsh file in the work space dir |
- FileUtils.copyFileToDirectory(getResourceFile(REPORT_RSH), getWorkspaceDir()); |
+ FileUtils.copyFileToDirectory(resources().getFile(REPORT_RSH), getWorkspaceDir()); |
|
climate = climatePtr; |
soil = soilPtr; |
@@ -653,7 +653,7 @@ |
|
@Override |
protected void doReport() throws Exception { |
- String sReportJSON = FileUtils.readFileToString(getResourceFile(REPORT_JSON)); |
+ String sReportJSON = FileUtils.readFileToString(resources().getFile(REPORT_JSON)); |
JSONArray reportItemsFromTemplate = new JSONArray(sReportJSON); |
|
String sout = FileUtils.readFileToString(stdout); |
@@ -670,12 +670,12 @@ |
String value = getResult(sout, "\"" + itemName + "\""); |
//LOG.info("the value='" + value + "'"); |
if ((value != null) && (value.equals("null"))) { |
- putReport(itemName, value, desc, units); |
+ report().put(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 { |
- putReport(itemName, new JSONArray(value), desc, units); |
+ report().put(itemName, new JSONArray(value), desc, units); |
|
} catch (JSONException je) { |
processReportElement(itemName,dimension,units,desc, type, value); |
@@ -685,7 +685,7 @@ |
} |
} |
if(dimension != null) |
- putReportMetaInfo(itemName,REPORT_DIM,new JSONArray(dimension)); |
+ report().putMetaInfo(itemName,REPORT_DIM,new JSONArray(dimension)); |
} |
} |
|
@@ -695,21 +695,21 @@ |
// 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); |
- putReport(itemName, Services.removeFirstLastChar(newString), desc, units); |
+ report().put(itemName, Services.removeFirstLastChar(newString), desc, units); |
} |
if (type.equals("INTEGER") && (value != null) && (!value.equals("null")) && (!value.equals("\"\""))) { |
- putReport(itemName, new Double(value).intValue(), desc, units); |
+ report().put(itemName, new Double(value).intValue(), desc, units); |
} |
if (type.equals("REAL") && (value != null)) { |
if ((!value.equals("null")) && (!value.equals("\"\""))) { |
- putReport(itemName, Double.parseDouble(value), desc, units); |
+ report().put(itemName, Double.parseDouble(value), desc, units); |
} |
if (value.equals("\"\"")) { |
- putReport(itemName, new Double(0), desc, units); |
+ report().put(itemName, new Double(0), desc, units); |
} |
} |
if (type.equals("")) { |
- putReport(itemName, value, desc, units); |
+ report().put(itemName, value, desc, units); |
} |
} |
} |
@@ -129,23 +129,20 @@ |
params.add(RES_SLOPE_DEGRAD); |
|
// check if these are being set |
- if (hasParam(KEY_CONTOUR_SYSTEM_PTR)) { |
+ if (parameter().has(KEY_CONTOUR_SYSTEM_PTR)) { |
params.add("CONTOUR_SYSTEM_PTR"); |
} |
- if (hasParam(KEY_STRIP_BARRIER_SYSTEM_PTR)) { |
+ if (parameter().has(KEY_STRIP_BARRIER_SYSTEM_PTR)) { |
params.add("STRIP_BARRIER_SYSTEM_PTR"); |
} |
- if (hasParam(KEY_HYD_ELEM_SYSTEM_PTR)) { |
+ if (parameter().has(KEY_HYD_ELEM_SYSTEM_PTR)) { |
params.add("HYD_ELEM_SYSTEM_PTR"); |
} |
getMetainfo().put(KEY_REQUEST_RESULTS, params); |
} |
|
// check if sufficient input is there. |
- requiredParam(KEY_SOILS); |
- requiredParam(KEY_LENGTH); |
- requiredParam(KEY_STEEPNESS); |
- requiredParam(KEY_MGMTS); |
+ parameter().require(KEY_SOILS, KEY_LENGTH, KEY_STEEPNESS, KEY_MGMTS); |
|
if (!r2run.isUrlReachable("")) { |
throw new ServiceException("R2 file server unreachable at: " + r2db); |
@@ -158,7 +155,7 @@ |
|
@Override |
protected void doProcess() throws Exception { |
- r2run.executePyrome(getWorkspaceFile(R2_TMP_FILENAME), getResourceExe(PYTHON)); |
+ r2run.executePyrome(getWorkspaceFile(R2_TMP_FILENAME), resources().getExe(PYTHON)); |
} |
|
|
@@ -168,63 +165,63 @@ |
for (int i = 0; i < operations.size(); i++) { |
String op = operations.get(i); |
if (r2run.isFileUrlReachable(op)) { |
- putResult("OPERATION_" + (i + 1), op, "operation is valid"); |
+ results().put("OPERATION_" + (i + 1), op, "operation is valid"); |
} else { |
- putResult("OPERATION_INVALID_" + (i + 1), op, "OPERATION IS MISSING!"); |
+ results().put("OPERATION_INVALID_" + (i + 1), op, "OPERATION IS MISSING!"); |
errors++; |
} |
} |
for (int i = 0; i < vegetations.size(); i++) { |
String vege = vegetations.get(i); |
if (r2run.isFileUrlReachable(vege)) { |
- putResult("VEGETATION_" + (i + 1), vege, "vegetation is valid"); |
+ results().put("VEGETATION_" + (i + 1), vege, "vegetation is valid"); |
} else { |
- putResult("VEGETATION_INVALID_" + (i + 1), vege, "VEGETATION IS MISSING"); |
+ results().put("VEGETATION_INVALID_" + (i + 1), vege, "VEGETATION IS MISSING"); |
errors++; |
} |
} |
for (int i = 0; i < residues.size(); i++) { |
String res = residues.get(i); |
if (r2run.isFileUrlReachable(res)) { |
- putResult("RESIDUE_" + (i + 1), res, "residue is valid"); |
+ results().put("RESIDUE_" + (i + 1), res, "residue is valid"); |
} else { |
- putResult("RESIDUE_INVALID_" + (i + 1), res, "RESIDUE IS MISSING"); |
+ results().put("RESIDUE_INVALID_" + (i + 1), res, "RESIDUE IS MISSING"); |
errors++; |
} |
} |
|
for (String r : JSONUtils.getRequestedResults(getMetainfo())) { |
if ((errors > 0) && (r.equals(RES_SLOPE_DEGRAD))) { |
- putResult(r, r2run.getResultPyrome(r), R2_MISSING_XML_FILES_WARNING_MSG); |
+ results().put(r, r2run.getResultPyrome(r), R2_MISSING_XML_FILES_WARNING_MSG); |
} else { |
- putResult(r, r2run.getResultPyrome(r)); |
+ results().put(r, r2run.getResultPyrome(r)); |
} |
} |
|
// Get erosion for segments |
- if (hasParam(KEY_TOPO_LENGTH)) { |
+ if (parameter().has(KEY_TOPO_LENGTH)) { |
JSONArray aTopoLength = JSONUtils.getJSONArrayParam(getParamMap(), KEY_TOPO_LENGTH); |
if (aTopoLength.length() > 0) { |
JSONArray aSoilLoss = new JSONArray(r2run.getResultPyromeArray("SEG_SOIL_LOSS", false, false, true)); |
- putResult("SEG_SOIL_LOSS", aSoilLoss); |
- putResult(KEY_CLIMATES, climate); |
+ results().put("SEG_SOIL_LOSS", aSoilLoss); |
+ results().put(KEY_CLIMATES, climate); |
if (LOG.isLoggable(Level.INFO)) { |
LOG.info("\n\n\n\n\n\nSEG SOIL OUTPUT=" + r2run.getResultPyromeArray("SEG_SOIL", true, true, true) + "\n\n\n\n"); |
LOG.info("\n\n\n\n\n\nSEG SOIL OUTPUT=" + r2run.getResultPyromeArray("SEG_MAN", true, true, true) + "\n\n\n\n"); |
} |
- putResult(KEY_SOILS, new JSONArray(r2run.getResultPyromeArray("SEG_SOIL", true, true, true))); |
- putResult(KEY_MANAGEMENTS, new JSONArray(r2run.getResultPyromeArray("SEG_MAN", true, true, true))); |
- if (hasParam(KEY_DIVERSIONS)) { |
- putResult(KEY_DIVERSIONS, r2run.getResultPyromeArray("HYD_ELEM_SYS", true, true, true)); |
+ 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))); |
+ if (parameter().has(KEY_DIVERSIONS)) { |
+ results().put(KEY_DIVERSIONS, r2run.getResultPyromeArray("HYD_ELEM_SYS", true, true, true)); |
} |
- if (hasParam(KEY_STRIP_BARRIER_SYSTEMS)) { |
- putResult(KEY_STRIP_BARRIER_SYSTEMS, r2run.getResultPyromeArray("STRIP_BARRIER_SYS", true, true, true)); |
+ if (parameter().has(KEY_STRIP_BARRIER_SYSTEMS)) { |
+ results().put(KEY_STRIP_BARRIER_SYSTEMS, r2run.getResultPyromeArray("STRIP_BARRIER_SYS", true, true, true)); |
} |
} |
} else { |
- putResult(KEY_CLIMATES, climate); |
- putResult(KEY_SOILS, new JSONArray(r2run.getResultPyromeArray("SEG_SOIL", true, true, true))); |
- putResult(KEY_MANAGEMENTS, new JSONArray(r2run.getResultPyromeArray("SEG_MAN", true, true, true))); |
+ results().put(KEY_CLIMATES, climate); |
+ 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))); |
} |
} |
|
@@ -232,11 +229,11 @@ |
private void createInputFile(File file, JSONObject metainfo, Map<String, JSONObject> param) |
throws Exception { |
|
- double steepness = getDoubleParam(KEY_STEEPNESS, 0.0); |
- double length = getDoubleParam(KEY_LENGTH, 0.0); |
- boolean resolveLoc = getBooleanParam(KEY_RESOLVE_LOCATION, false); |
- double latitude = getDoubleParam(KEY_LATITUDE, 0.0); |
- double longitude = getDoubleParam(KEY_LONGITUDE, 0.0); |
+ double steepness = parameter().getDouble(KEY_STEEPNESS, 0.0); |
+ double length = parameter().getDouble(KEY_LENGTH, 0.0); |
+ boolean resolveLoc = parameter().getBoolean(KEY_RESOLVE_LOCATION, false); |
+ double latitude = parameter().getDouble(KEY_LATITUDE, 0.0); |
+ double longitude = parameter().getDouble(KEY_LONGITUDE, 0.0); |
double simpleRockCoverPercent = 0.0; |
|
LOG.info("Rock cover read by service is=" + simpleRockCoverPercent); |
@@ -263,18 +260,18 @@ |
String hydElemSystem = ""; |
|
// Get the Contour System if not default |
- if (hasParam(KEY_CONTOUR_SYSTEM_PTR)) { |
- contourSystem = getStringParam(KEY_CONTOUR_SYSTEM_PTR, ""); |
+ if (parameter().has(KEY_CONTOUR_SYSTEM_PTR)) { |
+ contourSystem = parameter().getString(KEY_CONTOUR_SYSTEM_PTR, ""); |
} |
|
// Get the Strip Barrier System |
- if (hasParam(KEY_STRIP_BARRIER_SYSTEM_PTR)) { |
- stripBarrierSystem = getStringParam(KEY_STRIP_BARRIER_SYSTEM_PTR, ""); |
+ if (parameter().has(KEY_STRIP_BARRIER_SYSTEM_PTR)) { |
+ stripBarrierSystem = parameter().getString(KEY_STRIP_BARRIER_SYSTEM_PTR, ""); |
} |
|
// Get the Hydraylic Element System Pointer |
- if (hasParam(KEY_HYD_ELEM_SYSTEM_PTR)) { |
- hydElemSystem = getStringParam(KEY_HYD_ELEM_SYSTEM_PTR, ""); |
+ if (parameter().has(KEY_HYD_ELEM_SYSTEM_PTR)) { |
+ hydElemSystem = parameter().getString(KEY_HYD_ELEM_SYSTEM_PTR, ""); |
} |
|
JSONArray aTopoLength = new JSONArray(); |
@@ -283,7 +280,7 @@ |
JSONArray aManIdx = new JSONArray(); |
JSONArray aManLength = new JSONArray(); |
|
- if (hasParam(KEY_TOPO_LENGTH)) { |
+ if (parameter().has(KEY_TOPO_LENGTH)) { |
aTopoLength = JSONUtils.getJSONArrayParam(param, KEY_TOPO_LENGTH); |
if (LOG.isLoggable(Level.INFO)) { |
for (int i = 0; i < aTopoLength.length(); i++) { |
@@ -292,7 +289,7 @@ |
} |
} |
|
- if (hasParam(KEY_TOPO_STEEPNESS)) { |
+ if (parameter().has(KEY_TOPO_STEEPNESS)) { |
aTopoSteepness = JSONUtils.getJSONArrayParam(param, KEY_TOPO_STEEPNESS); |
if (LOG.isLoggable(Level.INFO)) { |
for (int i = 0; i < aTopoSteepness.length(); i++) { |
@@ -301,7 +298,7 @@ |
} |
} |
|
- if (hasParam(KEY_SOIL_INDEX)) { |
+ if (parameter().has(KEY_SOIL_INDEX)) { |
aSoilIdx = JSONUtils.getJSONArrayParam(param, KEY_SOIL_INDEX); |
if (LOG.isLoggable(Level.INFO)) { |
for (int i = 0; i < aSoilIdx.length(); i++) { |
@@ -310,7 +307,7 @@ |
} |
} |
|
- if (hasParam(KEY_MAN_INDEX)) { |
+ if (parameter().has(KEY_MAN_INDEX)) { |
aManIdx = JSONUtils.getJSONArrayParam(param, KEY_MAN_INDEX); |
if (LOG.isLoggable(Level.INFO)) { |
for (int i = 0; i < aManIdx.length(); i++) { |
@@ -319,20 +316,20 @@ |
} |
} |
|
- if (hasParam(KEY_MAN_LENGTH)) { |
+ if (parameter().has(KEY_MAN_LENGTH)) { |
aManLength = JSONUtils.getJSONArrayParam(param, KEY_MAN_LENGTH); |
for (int i = 0; i < aManLength.length(); i++) { |
LOG.info("Man Length [" + i + "]=" + aManLength.getInt(i)); |
} |
} |
|
- if (hasParam(KEY_TOPO_LENGTH)) { |
+ if (parameter().has(KEY_TOPO_LENGTH)) { |
if (aTopoLength.length() != aTopoSteepness.length()) { |
throw new ServiceException("RUSLE2 SEGMENT RUN ERROR! SEGMENT ARRAYS FOR TOPO LENGTH AND TOPO STEEPNESS MUST BE OF EQUAL SIZE!"); |
} |
} |
|
- if (hasParam(KEY_MAN_INDEX)) { |
+ if (parameter().has(KEY_MAN_INDEX)) { |
if (aManLength.length() != aManIdx.length()) { |
throw new ServiceException("RUSLE2 SEGMENT RUN ERROR! SEGMENT ARRAYS FOR MGMT LENGTH AND MGMT INDEX MUST BE OF EQUAL SIZE!"); |
} |
@@ -407,7 +404,7 @@ |
PrintWriter pw = new PrintWriter(file); |
pw.append("import sys\n" |
// could rewrite this line based on the OS, but python is interpretting it ok on windows |
- + "sys.path.append('" + getResourceFile(PYROMESRC).getParent().replace('\\', '/') + "')\n" |
+ + "sys.path.append('" + resources().getFile(PYROMESRC).getParent().replace('\\', '/') + "')\n" |
+ "from pyrome import *\n" |
+ "\n" |
+ "def linearTest(save = False, openFlags = RX_FILESOPEN_TEMP):\n" |
@@ -488,7 +485,7 @@ |
} |
|
// Must be after set soils or the soils code resets it...sometimes |
- if (hasParam(KEY_SIMPLE_ROCK_COVER)) { |
+ if (parameter().has(KEY_SIMPLE_ROCK_COVER)) { |
pw.append(" RomeFileSetAttrValue(profile, 'SIMPLE_ROCK_COVER', '" + simpleRockCoverPercent + "' ,0)\n"); |
} |
pw.append(" # SET MAN LAYER\n"); |
@@ -684,15 +681,15 @@ |
+ " #inputs\n" |
+ " save = False\n" |
+ " #Run simulation\n" |
- + " romeDLL = RomeInit('pyrome /DirRoot=" + getResourceFile(ROMEDLL).getParent().replace('\\', '/') + "/')\n" |
+ + " romeDLL = RomeInit('pyrome /DirRoot=" + resources().getFile(ROMEDLL).getParent().replace('\\', '/') + "/')\n" |
+ " database = RomeGetDatabase(romeDLL)\n"); |
|
// prints all outputs in single array |
// Specify the nginx server |
- if (!hasParam(KEY_ALT_R2DB)) { |
+ if (!parameter().has(KEY_ALT_R2DB)) { |
pw.append(" RomeDatabaseOpen(database,'" + r2db + "')\n"); |
} else { |
- String altr2db = r2db.substring(0, r2db.lastIndexOf("/")) + "/model-data/" + getStringParam(KEY_ALT_R2DB); |
+ String altr2db = r2db.substring(0, r2db.lastIndexOf("/")) + "/model-data/" + parameter().getString(KEY_ALT_R2DB); |
pw.append(" RomeDatabaseOpen(database,'" + altr2db + "')\n"); |
} |
|
@@ -704,15 +701,15 @@ |
pw.close(); |
|
// prepare individual contour system, strip barrier system, hyd elem sys, if not provided in an array |
- if (hasParam(KEY_CONTOUR_SYSTEM_PTR)) { |
+ if (parameter().has(KEY_CONTOUR_SYSTEM_PTR)) { |
String contourHttpPtr = r2db + "/" + contourSystem.replace("\\", "/") + ".xml"; |
r2run.prepareFileJ(contourHttpPtr, getWorkspaceFile("contour_file0.xml"), "", "contour-systems", "", true); |
} |
- if (hasParam(KEY_STRIP_BARRIER_SYSTEM_PTR)) { |
+ if (parameter().has(KEY_STRIP_BARRIER_SYSTEM_PTR)) { |
String stripbarrHttpPtr = r2db + "/" + stripBarrierSystem.replace("\\", "/") + ".xml"; |
r2run.prepareFileJ(stripbarrHttpPtr, getWorkspaceFile("stripbarr_file0.xml"), "", "strip-barrier-systems", "", true); |
} |
- if (hasParam(KEY_HYD_ELEM_SYSTEM_PTR)) { |
+ if (parameter().has(KEY_HYD_ELEM_SYSTEM_PTR)) { |
String hydelemHttpPtr = r2db + "/" + hydElemSystem.replace("\\", "/") + ".xml"; |
r2run.prepareHydraulicElementFlowPathJ(hydelemHttpPtr, r2db, getWorkspaceFile("hydelemflowpath_file.xml")); |
} |
@@ -721,7 +718,7 @@ |
r2run.prepareFileJ(climatePtr, getWorkspaceFile("cli_file0.xml"), "CLIMATE", "climates", "", true); |
|
// Unpack the report rsh file in the work space dir |
- FileUtils.copyFileToDirectory(getResourceFile(REPORT_PY_FILENAME), getWorkspaceDir()); |
+ FileUtils.copyFileToDirectory(resources().getFile(REPORT_PY_FILENAME), getWorkspaceDir()); |
|
climate = climatePtr; |
soil = soilPtr[0]; |
@@ -815,7 +812,7 @@ |
|
@Override |
protected void doReport() throws Exception { |
- String sReportJSON = FileUtils.readFileToString(getResourceFile(REPORT_JSON_TEMPLATE_FILENAME)); |
+ String sReportJSON = FileUtils.readFileToString(resources().getFile(REPORT_JSON_TEMPLATE_FILENAME)); |
JSONArray reportItemsFromTemplate = new JSONArray(sReportJSON); |
for (int i = 0; i < reportItemsFromTemplate.length(); i++) { |
JSONObject obj = (JSONObject) reportItemsFromTemplate.get(i); |
@@ -834,12 +831,12 @@ |
String value = r2run.getResult("\"" + itemName + "\""); |
LOG.info("the value='" + value + "'"); |
if ((value != null) && (value.equals("null"))) { |
- putReport(itemName, (String) null, desc, units); |
+ report().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 { |
- putReport(itemName, new JSONArray(value), desc, units); |
+ report().put(itemName, new JSONArray(value), desc, units); |
} catch (JSONException je) { |
processReportElement(itemName, dimension, units, desc, type, value); |
} |
@@ -848,7 +845,7 @@ |
} |
} |
if (dimension != null) { |
- putReportMetaInfo(itemName, REPORT_DIM, new JSONArray(dimension)); |
+ report().putMetaInfo(itemName, REPORT_DIM, new JSONArray(dimension)); |
} |
} |
} |
@@ -867,25 +864,25 @@ |
// we have to remove one level of "escaping" !!! |
String newString = StringEscapeUtils.unescapeJava(value); |
//String newString=value; |
- putReport(itemName, Services.removeFirstLastChar(newString), desc, units); |
+ report().put(itemName, Services.removeFirstLastChar(newString), desc, units); |
} |
if (type.equals("INTEGER") && (value != null) && (!value.equals("null")) && (!value.equals("\"\""))) { |
// trim off quotes |
value = Services.removeFirstLastChar(value); |
- putReport(itemName, new Double(value).intValue(), desc, units); |
+ report().put(itemName, new Double(value).intValue(), desc, units); |
} |
if (type.equals("REAL") && (value != null)) { |
if ((!value.equals("null")) && (!value.equals("\"\""))) { |
// trim off quotes |
value = Services.removeFirstLastChar(value); |
- putReport(itemName, Double.parseDouble(value), desc, units); |
+ report().put(itemName, Double.parseDouble(value), desc, units); |
} |
if (value.equals("\"\"")) { |
- putReport(itemName, new Double(0), desc, units); |
+ report().put(itemName, new Double(0), desc, units); |
} |
} |
if (type.equals("")) { |
- putReport(itemName, value, desc, units); |
+ report().put(itemName, value, desc, units); |
} |
} |
} |
@@ -173,7 +173,7 @@ |
@Override |
protected void doProcess() throws Exception { |
try { |
- Executable python = getResourceExe(V3_0.PYTHON); |
+ Executable python = resources().getExe(V3_0.PYTHON); |
LOG.log(Level.INFO, "EXECUTING PYROME FROM doProcess()..."); |
int result = r2run.executePyrome(new File(getWorkspaceDir(), R2_TMP_FILENAME + R2_TMP_FILEEXT), python); |
} catch (Exception e) { |
@@ -189,27 +189,27 @@ |
for (int i = 0; i < operations.size(); i++) { |
String op = operations.get(i); |
if (r2run.isFileUrlReachable(op)) { |
- putResult("OPERATION_" + (i + 1), op, "operation is valid"); |
+ results().put("OPERATION_" + (i + 1), op, "operation is valid"); |
} else { |
- putResult("OPERATION_INVALID_" + (i + 1), op, "OPERATION IS MISSING!"); |
+ results().put("OPERATION_INVALID_" + (i + 1), op, "OPERATION IS MISSING!"); |
errors++; |
} |
} |
for (int i = 0; i < vegetations.size(); i++) { |
String vege = vegetations.get(i); |
if (r2run.isFileUrlReachable(vege)) { |
- putResult("VEGETATION_" + (i + 1),vege,"vegetation is valid"); |
+ results().put("VEGETATION_" + (i + 1),vege,"vegetation is valid"); |
} else { |
- putResult("VEGETATION_INVALID_" + (i + 1), vege, "VEGETATION IS MISSING"); |
+ results().put("VEGETATION_INVALID_" + (i + 1), vege, "VEGETATION IS MISSING"); |
errors++; |
} |
} |
for (int i = 0; i < residues.size(); i++) { |
String res = residues.get(i); |
if (r2run.isFileUrlReachable(res)) { |
- putResult("RESIDUE_" + (i + 1), res, "residue is valid"); |
+ results().put("RESIDUE_" + (i + 1), res, "residue is valid"); |
} else { |
- putResult("RESIDUE_INVALID_" + (i + 1), res, "RESIDUE IS MISSING"); |
+ results().put("RESIDUE_INVALID_" + (i + 1), res, "RESIDUE IS MISSING"); |
errors++; |
} |
} |
@@ -217,9 +217,9 @@ |
// results.put(JSONUtils.data(KEY_SLOPE_DELIVERY, 3.0)); |
for (String r : JSONUtils.getRequestedResults(getMetainfo())) { |
if ((errors > 0) && (r.equals(RES_SLOPE_DEGRAD))) { |
- putResult(r, r2run.getResultPyrome(r), R2_MISSING_XML_FILES_WARNING_MSG); |
+ results().put(r, r2run.getResultPyrome(r), R2_MISSING_XML_FILES_WARNING_MSG); |
} else { |
- putResult(r, r2run.getResultPyrome(r)); |
+ results().put(r, r2run.getResultPyrome(r)); |
} |
} |
|
@@ -228,23 +228,23 @@ |
JSONArray aTopoLength = JSONUtils.getJSONArrayParam(getParamMap(), KEY_TOPO_LENGTH); |
if (aTopoLength.length() > 0) { |
JSONArray aSoilLoss = new JSONArray(r2run.getResultPyromeArray("SEG_SOIL_LOSS", false, false, true)); |
- putResult("SEG_SOIL_LOSS", aSoilLoss); |
- putResult(KEY_CLIMATES, climate); |
+ results().put("SEG_SOIL_LOSS", aSoilLoss); |
+ results().put(KEY_CLIMATES, climate); |
LOG.info("\n\n\n\n\n\nSEG SOIL OUTPUT=" + r2run.getResultPyromeArray("SEG_SOIL", true, true, true) + "\n\n\n\n"); |
LOG.info("\n\n\n\n\n\nSEG SOIL OUTPUT=" + r2run.getResultPyromeArray("SEG_MAN", true, true, true) + "\n\n\n\n"); |
- putResult(KEY_SOILS, new JSONArray(r2run.getResultPyromeArray("SEG_SOIL", true, true, true))); |
- putResult(KEY_MANAGEMENTS, new JSONArray(r2run.getResultPyromeArray("SEG_MAN", true, true, true))); |
+ 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))); |
if (JSONUtils.checkKeyExistsB(getParamMap(), KEY_DIVERSIONS)) |
- putResult(KEY_DIVERSIONS, r2run.getResultPyromeArray("HYD_ELEM_SYS", true, true, true)); |
+ results().put(KEY_DIVERSIONS, r2run.getResultPyromeArray("HYD_ELEM_SYS", true, true, true)); |
|
if (JSONUtils.checkKeyExistsB(getParamMap(), KEY_STRIP_BARRIER_SYSTEMS)) { |
- putResult(KEY_STRIP_BARRIER_SYSTEMS, r2run.getResultPyromeArray("STRIP_BARRIER_SYS", true, true, true)); |
+ results().put(KEY_STRIP_BARRIER_SYSTEMS, r2run.getResultPyromeArray("STRIP_BARRIER_SYS", true, true, true)); |
} |
} |
} else { |
- putResult(KEY_CLIMATES, climate); |
- putResult(KEY_SOILS, new JSONArray(r2run.getResultPyromeArray("SEG_SOIL", true, true, true))); |
- putResult(KEY_MANAGEMENTS, new JSONArray(r2run.getResultPyromeArray("SEG_MAN", true, true, true))); |
+ results().put(KEY_CLIMATES, climate); |
+ 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))); |
} |
} |
|
@@ -484,7 +484,7 @@ |
|
fos.write("import sys\n".getBytes()); |
// could rewrite this line based on the OS, but python is interpretting it ok on windows |
- fos.write(("sys.path.append('"+this.getResourceFile(PYROMESRC).getParent().replace('\\','/')+"')\n").getBytes()); |
+ fos.write(("sys.path.append('"+ resources().getFile(PYROMESRC).getParent().replace('\\','/')+"')\n").getBytes()); |
|
fos.write("from pyrome import *\n".getBytes()); |
fos.write("from time import sleep\n".getBytes()); |
@@ -909,7 +909,7 @@ |
fos.write(" #inputs\n".getBytes()); |
fos.write(" save = False\n".getBytes()); |
fos.write(" #Run simulation\n".getBytes()); |
- fos.write((" romeDLL = RomeInit('pyrome /DirRoot="+getResourceFile(ROMEDLL).getParent().replace('\\','/')+"/')\n").getBytes()); |
+ fos.write((" romeDLL = RomeInit('pyrome /DirRoot="+ resources().getFile(ROMEDLL).getParent().replace('\\','/')+"/')\n").getBytes()); |
fos.write(" database = RomeGetDatabase(romeDLL)\n".getBytes()); |
// prints all outputs in single array |
//fos.write(" print(results[:])\n".getBytes()); |
@@ -971,7 +971,7 @@ |
|
// Unpack the report rsh file in the work space dir |
// Binaries.unpackResourceAbsolute("/bin/win-x86/" + REPORT_PY_FILENAME, getWorkspaceDir().toString() + "/" + REPORT_PY_FILENAME); |
- FileUtils.copyFileToDirectory(getResourceFile(REPORT_PY_FILENAME), getWorkspaceDir()); |
+ FileUtils.copyFileToDirectory(resources().getFile(REPORT_PY_FILENAME), getWorkspaceDir()); |
|
climate = climatePtr; |
soil = soilPtr[0]; |
@@ -1085,7 +1085,7 @@ |
// String sessionWorkDir = getWorkspaceDir().toString(); |
// String reportJSON = Binaries.unpackResourceAbsolute("/bin/win-x86/" + REPORT_JSON_TEMPLATE_FILENAME, sessionWorkDir + "/" + REPORT_JSON_TEMPLATE_FILENAME).toString(); |
// File reportTemplate = new File(sessionWorkDir + "/" + REPORT_JSON_TEMPLATE_FILENAME); |
- File reportTemplate = getResourceFile(REPORT_JSON_TEMPLATE_FILENAME); |
+ File reportTemplate = resources().getFile(REPORT_JSON_TEMPLATE_FILENAME); |
|
String sReportJSON = FileUtils.readFileToString(reportTemplate); |
JSONArray reportItemsFromTemplate = new JSONArray(sReportJSON); |
@@ -1106,12 +1106,12 @@ |
String value = r2run.getResult("\"" + itemName + "\""); |
LOG.info("the value='" + value + "'"); |
if ((value != null) && (value.equals("null"))) { |
- putReport(itemName, (String) null, desc, units); |
+ report().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 { |
- putReport(itemName, new JSONArray(value), desc, units); |
+ report().put(itemName, new JSONArray(value), desc, units); |
} catch (JSONException je) { |
processReportElement(itemName,dimension,units,desc, type, value); |
} |
@@ -1121,7 +1121,7 @@ |
|
} |
if(dimension != null) |
- putReportMetaInfo(itemName,REPORT_DIM,new JSONArray(dimension)); |
+ report().putMetaInfo(itemName,REPORT_DIM,new JSONArray(dimension)); |
} |
} |
|
@@ -1144,27 +1144,27 @@ |
|
String newString = StringEscapeUtils.unescapeJava(value); |
//String newString=value; |
- putReport(itemName, Services.removeFirstLastChar(newString), desc, units); |
+ report().put(itemName, Services.removeFirstLastChar(newString), desc, units); |
} |
if (type.equals("INTEGER") && (value != null) && (!value.equals("null")) && (!value.equals("\"\""))) { |
// trim off quotes |
value = Services.removeFirstLastChar(value); |
System.out.println("VALUE:" + value); |
- putReport(itemName, new Double(value).intValue(), desc, units); |
+ report().put(itemName, new Double(value).intValue(), desc, units); |
} |
if (type.equals("REAL") && (value != null)) { |
if ((!value.equals("null")) && (!value.equals("\"\""))) { |
// trim off quotes |
value = Services.removeFirstLastChar(value); |
System.out.println("VALUE:" + value); |
- putReport(itemName, Double.parseDouble(value), desc, units); |
+ report().put(itemName, Double.parseDouble(value), desc, units); |
} |
if (value.equals("\"\"")) { |
- putReport(itemName, new Double(0), desc, units); |
+ report().put(itemName, new Double(0), desc, units); |
} |
} |
if (type.equals("")) { |
- putReport(itemName, value, desc, units); |
+ report().put(itemName, value, desc, units); |
} |
} |
|
@@ -17,7 +17,6 @@ |
import static csip.annotations.ResourceType.REFERENCE; |
import csip.annotations.State; |
import static csip.annotations.State.DEVELOPMENT; |
-import static csip.annotations.State.RELEASED; |
import csip.annotations.VersionInfo; |
import csip.utils.JSONUtils; |
import database.ServiceResources; |
@@ -136,7 +135,7 @@ |
throw new ServiceException("R2 Ann does not handle multiple managements yet."); |
} |
|
- try (Connection connection = getResourceJDBC(LMOD_ID)) { |
+ try (Connection connection = resources().getJDBC(LMOD_ID)) { |
managementCopy = new org.json.JSONObject(managements.getJSONObject(0).toString()); |
man = new Management(connection, managementCopy); |
} |
@@ -229,7 +228,7 @@ |
@Override |
protected void doProcess() throws Exception { |
try { |
- Executable python = getResourceExe(V3_0.PYTHON); |
+ Executable python = resources().getExe(V3_0.PYTHON); |
LOG.log(Level.INFO, "EXECUTING PYROME FROM doProcess()..."); |
int result = r2run.executePyrome(new File(getWorkspaceDir(), R2_TMP_FILENAME + R2_TMP_FILEEXT), python); |
callAnn(); |
@@ -334,7 +333,7 @@ |
ann_erosion = jresult.getDouble(VALUE); |
} else { |
String error = responseMeta.getString(ERROR); |
- this.appendMetainfoWarning(error); |
+ metainfo().appendWarning(error); |
//throw new ServiceException("Ann service error: " + error); |
} |
} |
@@ -346,27 +345,27 @@ |
for (int i = 0; i < operations.size(); i++) { |
String op = operations.get(i); |
if (r2run.isUrlReachable(op)) { |
- putResult("OPERATION_" + (i + 1), op, "operation is valid"); |
+ results().put("OPERATION_" + (i + 1), op, "operation is valid"); |
} else { |
- putResult("OPERATION_INVALID_" + (i + 1), op, "OPERATION IS MISSING!"); |
+ results().put("OPERATION_INVALID_" + (i + 1), op, "OPERATION IS MISSING!"); |
errors++; |
} |
} |
for (int i = 0; i < vegetations.size(); i++) { |
String vege = vegetations.get(i); |
if (r2run.isUrlReachable(vege)) { |
- putResult("VEGETATION_" + (i + 1), vege, "vegetation is valid"); |
+ results().put("VEGETATION_" + (i + 1), vege, "vegetation is valid"); |
} else { |
- putResult("VEGETATION_INVALID_" + (i + 1), vege, "VEGETATION IS MISSING"); |
+ results().put("VEGETATION_INVALID_" + (i + 1), vege, "VEGETATION IS MISSING"); |
errors++; |
} |
} |
for (int i = 0; i < residues.size(); i++) { |
String res = residues.get(i); |
if (r2run.isUrlReachable(res)) { |
- putResult("RESIDUE_" + (i + 1), res, "residue is valid"); |
+ results().put("RESIDUE_" + (i + 1), res, "residue is valid"); |
} else { |
- putResult("RESIDUE_INVALID_" + (i + 1), res, "RESIDUE IS MISSING"); |
+ results().put("RESIDUE_INVALID_" + (i + 1), res, "RESIDUE IS MISSING"); |
errors++; |
} |
} |
@@ -374,9 +373,9 @@ |
// results.put(JSONUtils.data(KEY_SLOPE_DELIVERY, 3.0)); |
for (String r : JSONUtils.getRequestedResults(getMetainfo())) { |
if ((errors > 0) && (r.equals(RES_SLOPE_DEGRAD))) { |
- putResult(r, r2run.getResultPyrome(r), R2_MISSING_XML_FILES_WARNING_MSG); |
+ results().put(r, r2run.getResultPyrome(r), R2_MISSING_XML_FILES_WARNING_MSG); |
} else { |
- putResult(r, r2run.getResultPyrome(r)); |
+ results().put(r, r2run.getResultPyrome(r)); |
} |
} |
|
@@ -385,26 +384,26 @@ |
JSONArray aTopoLength = JSONUtils.getJSONArrayParam(getParamMap(), KEY_TOPO_LENGTH); |
if (aTopoLength.length() > 0) { |
JSONArray aSoilLoss = new JSONArray(r2run.getResultPyromeArray("SEG_SOIL_LOSS", false, false, true)); |
- putResult("SEG_SOIL_LOSS", aSoilLoss); |
- putResult(KEY_CLIMATES, climate); |
+ results().put("SEG_SOIL_LOSS", aSoilLoss); |
+ results().put(KEY_CLIMATES, climate); |
LOG.info("\n\n\n\n\n\nSEG SOIL OUTPUT=" + r2run.getResultPyromeArray("SEG_SOIL", true, true, true) + "\n\n\n\n"); |
LOG.info("\n\n\n\n\n\nSEG SOIL OUTPUT=" + r2run.getResultPyromeArray("SEG_MAN", true, true, true) + "\n\n\n\n"); |
- putResult(KEY_SOILS, new JSONArray(r2run.getResultPyromeArray("SEG_SOIL", true, true, true))); |
- putResult(KEY_MANAGEMENTS, new JSONArray(r2run.getResultPyromeArray("SEG_MAN", true, true, true))); |
+ 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))); |
if (JSONUtils.checkKeyExistsB(getParamMap(), KEY_DIVERSIONS)) { |
- putResult(KEY_DIVERSIONS, r2run.getResultPyromeArray("HYD_ELEM_SYS", true, true, true)); |
+ results().put(KEY_DIVERSIONS, r2run.getResultPyromeArray("HYD_ELEM_SYS", true, true, true)); |
} |
|
if (JSONUtils.checkKeyExistsB(getParamMap(), KEY_STRIP_BARRIER_SYSTEMS)) { |
- putResult(KEY_STRIP_BARRIER_SYSTEMS, r2run.getResultPyromeArray("STRIP_BARRIER_SYS", true, true, true)); |
+ results().put(KEY_STRIP_BARRIER_SYSTEMS, r2run.getResultPyromeArray("STRIP_BARRIER_SYS", true, true, true)); |
} |
} |
} else { |
- putResult(KEY_CLIMATES, climate); |
- putResult(KEY_SOILS, new JSONArray(r2run.getResultPyromeArray("SEG_SOIL", true, true, true))); |
- putResult(KEY_MANAGEMENTS, new JSONArray(r2run.getResultPyromeArray("SEG_MAN", true, true, true))); |
+ results().put(KEY_CLIMATES, climate); |
+ 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))); |
} |
|
- putResult(KEY_ANN_EROSION, ann_erosion); |
+ results().put(KEY_ANN_EROSION, ann_erosion); |
} |
} |