Displaying differences for changeset
 
display as  

nbproject/ant-deploy.xml

@@ -1,42 +1,23 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
-Copyright (c) 2006, 2016 Oracle and/or its affiliates. All rights reserved.
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
 
-Oracle and Java are registered trademarks of Oracle and/or its affiliates.
-Other names may be trademarks of their respective owners.
+      http://www.apache.org/licenses/LICENSE-2.0
 
-The contents of this file are subject to the terms of either the GNU
-General Public License Version 2 only ("GPL") or the Common
-Development and Distribution License("CDDL") (collectively, the
-"License"). You may not use this file except in compliance with the
-License. You can obtain a copy of the License at
-http://www.netbeans.org/cddl-gplv2.html
-or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
-specific language governing permissions and limitations under the
-License.  When distributing the software, include this License Header
-Notice in each file and include the License file at
-nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
-particular file as subject to the "Classpath" exception as provided
-by Oracle in the GPL Version 2 section of the License file that
-accompanied this code. If applicable, add the following below the
-License Header, with the fields enclosed by brackets [] replaced by
-your own identifying information:
-"Portions Copyrighted [year] [name of copyright owner]"
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
 
-If you wish your version of this file to be governed by only the CDDL
-or only the GPL Version 2, indicate your decision by adding
-"[Contributor] elects to include this software in this distribution
-under the [CDDL or GPL Version 2] license." If you do not indicate a
-single choice of license, a recipient has the option to distribute
-your version of this file under either the CDDL, the GPL Version 2 or
-to extend the choice of license to its licensees as provided above.
-However, if you add GPL Version 2 code and therefore, elected the GPL
-Version 2 license, then the option applies only if the new code is
-made subject to such option by the copyright holder.
-
-Contributor(s):
 -->
 <project default="-deploy-ant" basedir=".">
     <target name="-init" if="deploy.ant.enabled">

nbproject/project.properties

@@ -1,106 +1,106 @@
-file.reference.calcmanstir.jar=lib/calcmanstir.jar
-file.reference.commons-codec-1.10.jar=lib/commons-codec-1.10.jar
-file.reference.commons-vfs2-2.1.jar=lib/commons-vfs2-2.1.jar
-file.reference.csip-gis-objects-2.0.17.jar=lib/csip-gis-objects-2.0.17.jar
-file.reference.csip-soilsdb-3.0.18.jar=lib/csip-soilsdb-3.0.18.jar
-file.reference.Lmod2Rusle2.jar=lib/Lmod2Rusle2.jar
-file.reference.SDMDriver-1.0.4.jar=lib/SDMDriver-1.0.4.jar
-j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.4.2.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
-#Thu Dec 17 13:44:22 MST 2015
-javadoc.splitindex=true
-lib.dir=${web.docbase.dir}/WEB-INF/lib
-auxiliary.org-netbeans-modules-css-prep.sass_2e_mappings=/scss\:/css
-build.classes.excludes=**/*.java,**/*.form
-javadoc.author=false
-j2ee.platform=1.6-web
-dist.war=${dist.dir}/${war.name}
-javac.target=1.8
-build.generated.dir=${build.dir}/generated
-project.csip-core=../csip-core
-reference.csip-core.jar=${project.csip-core}/dist/csip-core.jar
-resource.dir=setup
-build.web.excludes=${build.classes.excludes}
-war.ear.name=${war.name}
-j2ee.compile.on.save=true
-debug.test.classpath=${run.test.classpath}
-build.dir=build
-javac.deprecation=false
-persistence.xml.dir=${conf.dir}
-j2ee.copy.static.files.on.save=true
-auxiliary.org-netbeans-modules-css-prep.less_2e_mappings=/less\:/css
-test.src.dir=test
-auxiliary.org-netbeans-modules-css-prep.sass_2e_compiler_2e_options=
-junit.selected.version=4
-includes=**
-jar.compress=false
-annotation.processing.processors.list=
-javadoc.version=false
-build.classes.dir=${build.web.dir}/WEB-INF/classes
-dist.dir=dist
-rest.config.type=ide
-javac.source=1.8
-javac.debug=true
-javac.test.processorpath=${javac.test.classpath}
-run.test.classpath=\
-    ${javac.test.classpath}:\
-    ${build.test.classes.dir}
-build.generated.sources.dir=${build.dir}/generated-sources
-auxiliary.org-netbeans-modules-css-prep.less_2e_enabled=false
-javadoc.notree=false
-source.root=src
-runmain.jvmargs=
-platform.active=default_platform
-javadoc.preview=true
-j2ee.deploy.on.save=true
-annotation.processing.enabled=true
-war.content.additional=
-dist.javadoc.dir=${dist.dir}/javadoc
-client.urlPart=
-javadoc.additionalparam=
-javac.classpath=\
-    ${reference.csip-core.jar}:\
-    ${libs.CSIP-Jersey-2.16.classpath}:\
-    ${file.reference.Lmod2Rusle2.jar}:\
-    ${file.reference.commons-vfs2-2.1.jar}:\
-    ${file.reference.commons-codec-1.10.jar}:\
-    ${file.reference.csip-soilsdb-3.0.18.jar}:\
-    ${file.reference.csip-gis-objects-2.0.17.jar}:\
-    ${file.reference.calcmanstir.jar}:\
-    ${file.reference.SDMDriver-1.0.4.jar}
-javadoc.noindex=false
-webinf.dir=web/WEB-INF
-annotation.processing.enabled.in.editor=true
-javadoc.private=false
-javadoc.encoding=${source.encoding}
-build.test.classes.dir=${build.dir}/test/classes
-auxiliary.org-netbeans-modules-css-prep.less_2e_compiler_2e_options=
-web.docbase.dir=web
-javac.compilerargs=
-auxiliary.org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder=js/libs
-auxiliary.org-netbeans-modules-css-prep.sass_2e_enabled=false
-source.encoding=UTF-8
-dist.ear.war=${dist.dir}/${war.ear.name}
-j2ee.server.type=Tomcat
-conf.dir=${source.root}/conf
-annotation.processing.run.all.processors=true
-compile.jsps=false
-excludes=
-javac.processorpath=\
-    ${javac.classpath}
-build.test.results.dir=${build.dir}/test/results
-display.browser=false
-endorsed.classpath=\
-    ${libs.javaee-endorsed-api-6.0.classpath}
-javadoc.use=true
-build.web.dir=${build.dir}/web
-javadoc.nonavbar=false
-war.name=csip-r2.war
-javadoc.windowtitle=
-javac.test.classpath=\
-    ${javac.classpath}:\
-    ${build.classes.dir}:\
-    ${libs.junit_4.classpath}:\
-    ${libs.hamcrest.classpath}
-src.dir=${source.root}/java
-annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
-debug.classpath=${build.classes.dir}\:${javac.classpath}
+file.reference.calcmanstir.jar=lib/calcmanstir.jar
+file.reference.commons-codec-1.10.jar=lib/commons-codec-1.10.jar
+file.reference.commons-vfs2-2.1.jar=lib/commons-vfs2-2.1.jar
+file.reference.csip-gis-objects-2.0.17.jar=lib/csip-gis-objects-2.0.17.jar
+file.reference.csip-soilsdb-3.0.18.jar=lib/csip-soilsdb-3.0.18.jar
+file.reference.Lmod2Rusle2.jar=lib/Lmod2Rusle2.jar
+file.reference.SDMDriver-1.0.4.jar=lib/SDMDriver-1.0.4.jar
+j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.4.1.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-spdy.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
+#Thu Dec 17 13:44:22 MST 2015
+javadoc.splitindex=true
+lib.dir=${web.docbase.dir}/WEB-INF/lib
+auxiliary.org-netbeans-modules-css-prep.sass_2e_mappings=/scss\:/css
+build.classes.excludes=**/*.java,**/*.form
+javadoc.author=false
+j2ee.platform=1.6-web
+dist.war=${dist.dir}/${war.name}
+javac.target=1.8
+build.generated.dir=${build.dir}/generated
+project.csip-core=../csip-core
+reference.csip-core.jar=${project.csip-core}/dist/csip-core.jar
+resource.dir=setup
+build.web.excludes=${build.classes.excludes}
+war.ear.name=${war.name}
+j2ee.compile.on.save=true
+debug.test.classpath=${run.test.classpath}
+build.dir=build
+javac.deprecation=false
+persistence.xml.dir=${conf.dir}
+j2ee.copy.static.files.on.save=true
+auxiliary.org-netbeans-modules-css-prep.less_2e_mappings=/less\:/css
+test.src.dir=test
+auxiliary.org-netbeans-modules-css-prep.sass_2e_compiler_2e_options=
+junit.selected.version=4
+includes=**
+jar.compress=false
+annotation.processing.processors.list=
+javadoc.version=false
+build.classes.dir=${build.web.dir}/WEB-INF/classes
+dist.dir=dist
+rest.config.type=ide
+javac.source=1.8
+javac.debug=true
+javac.test.processorpath=${javac.test.classpath}
+run.test.classpath=\
+    ${javac.test.classpath}:\
+    ${build.test.classes.dir}
+build.generated.sources.dir=${build.dir}/generated-sources
+auxiliary.org-netbeans-modules-css-prep.less_2e_enabled=false
+javadoc.notree=false
+source.root=src
+runmain.jvmargs=
+platform.active=default_platform
+javadoc.preview=true
+j2ee.deploy.on.save=true
+annotation.processing.enabled=true
+war.content.additional=
+dist.javadoc.dir=${dist.dir}/javadoc
+client.urlPart=
+javadoc.additionalparam=
+javac.classpath=\
+    ${reference.csip-core.jar}:\
+    ${libs.CSIP-Jersey-2.16.classpath}:\
+    ${file.reference.Lmod2Rusle2.jar}:\
+    ${file.reference.commons-vfs2-2.1.jar}:\
+    ${file.reference.commons-codec-1.10.jar}:\
+    ${file.reference.csip-soilsdb-3.0.18.jar}:\
+    ${file.reference.csip-gis-objects-2.0.17.jar}:\
+    ${file.reference.calcmanstir.jar}:\
+    ${file.reference.SDMDriver-1.0.4.jar}
+javadoc.noindex=false
+webinf.dir=web/WEB-INF
+annotation.processing.enabled.in.editor=true
+javadoc.private=false
+javadoc.encoding=${source.encoding}
+build.test.classes.dir=${build.dir}/test/classes
+auxiliary.org-netbeans-modules-css-prep.less_2e_compiler_2e_options=
+web.docbase.dir=web
+javac.compilerargs=
+auxiliary.org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder=js/libs
+auxiliary.org-netbeans-modules-css-prep.sass_2e_enabled=false
+source.encoding=UTF-8
+dist.ear.war=${dist.dir}/${war.ear.name}
+j2ee.server.type=Tomcat
+conf.dir=${source.root}/conf
+annotation.processing.run.all.processors=true
+compile.jsps=false
+excludes=
+javac.processorpath=\
+    ${javac.classpath}
+build.test.results.dir=${build.dir}/test/results
+display.browser=false
+endorsed.classpath=\
+    ${libs.javaee-endorsed-api-6.0.classpath}
+javadoc.use=true
+build.web.dir=${build.dir}/web
+javadoc.nonavbar=false
+war.name=csip-r2.war
+javadoc.windowtitle=
+javac.test.classpath=\
+    ${javac.classpath}:\
+    ${build.classes.dir}:\
+    ${libs.junit_4.classpath}:\
+    ${libs.hamcrest.classpath}
+src.dir=${source.root}/java
+annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+debug.classpath=${build.classes.dir}\:${javac.classpath}

src/java/database/GIS_DB.java

@@ -12,7 +12,7 @@
 package database;
 
 
-import csip.ServiceException;
+import csip.api.server.ServiceException;
 import java.sql.SQLException;
 import java.util.Arrays;
 import java.util.Collection;

src/java/database/SqlGIS.java

@@ -11,7 +11,7 @@
  */
 package database;
 
-import csip.ServiceException;
+import csip.api.server.ServiceException;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;

src/java/m/ApplicationConfig.java

@@ -12,7 +12,7 @@
 package m;
 
 import csip.Config;
-import csip.ContextConfig;
+
 import csip.utils.Services;
 import java.util.HashSet;
 import java.util.Set;
@@ -35,8 +35,8 @@
     public Set<Class<?>> getClasses() {
         Set<Class<?>> resources = new HashSet<>();
         addRestResourceClasses(resources);
-        ContextConfig.filterServices(context, resources);
-        Config.register(resources);
+        
+        Config.register(resources, context);
         return resources;
     }
 

src/java/m/rusle2/R2Run.java

@@ -12,8 +12,8 @@
 package m.rusle2;
 
 import csip.Config;
-import csip.Executable;
-import csip.ServiceException;
+import csip.api.server.Executable;
+import csip.api.server.ServiceException;
 import csip.SessionLogger;
 import static csip.Utils.removeFirstLastChar;
 import java.io.BufferedReader;
@@ -27,7 +27,7 @@
 import java.net.URL;
 import java.util.logging.Level;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang3.StringEscapeUtils;
 import util.XMLUtils;
 
 /**
@@ -36,352 +36,360 @@
  */
 class R2Run {
 
-    SessionLogger LOG;
-    String stdout;
+  SessionLogger LOG;
+  String stdout;
 
-    void setLogger ( SessionLogger l ) {
-        LOG = l;
+
+  void setLogger(SessionLogger l) {
+    LOG = l;
+  }
+
+
+  /**
+   * Execute the rusle2 pyrome python script
+   *
+   * We assume that Python3.4 is installed under
+   * /home/ubuntu/.wine/drive_c/Python34 and that wine's working dir is
+   * /home/ubuntu/.wine The ownership of wine's working directory must
+   * correspond with the user running tomcat
+   *
+   * @param r2_rsh
+   * @return
+   * @throws IOException
+   */
+  int executePyrome(File r2_rsh, Executable python) throws IOException, ServiceException {
+    python.setArguments("rusle2csip.py");
+    LOG.info("Executing pyrome rusle2");
+    int ret = python.exec();
+    if (ret != 0) {
+      String stderr = FileUtils.readFileToString(python.stderr(), "UTF-8");
+      throw new ServiceException("RUSLE 2 PYTHON error: error executing pyrome:" + stderr);
     }
 
-    /**
-     * Execute the rusle2 pyrome python script
-     *
-     * We assume that Python3.4 is installed under
-     * /home/ubuntu/.wine/drive_c/Python34 and that wine's working dir is
-     * /home/ubuntu/.wine The ownership of wine's working directory must
-     * correspond with the user running tomcat
-     *
-     * @param r2_rsh
-     * @return
-     * @throws IOException
-     */
-    int executePyrome ( File r2_rsh, Executable python ) throws IOException, ServiceException {
-        python.setArguments( "rusle2csip.py" );
-        LOG.info( "Executing pyrome rusle2" );
-        int ret = python.exec();
-        if ( ret != 0 ) {
-            String stderr = FileUtils.readFileToString( python.stderr() );
-            throw new ServiceException( "RUSLE 2 PYTHON error: error executing pyrome:" + stderr );
+//        String runrusle2 = "winetricks vd=off ; wine /home/ubuntu/.wine/drive_c/Python34/python.exe rusle2csip.py\n";
+    stdout += "\n" + FileUtils.readFileToString(python.stdout(), "UTF-8");
+    if (LOG.isLoggable(Level.INFO)) {
+      LOG.info("stdout: " + stdout);
+      LOG.info("exit val: " + ret);
+    }
+    return ret;
+  }
+
+  // Must find the hydraulic element flow path element of a hydraulic element system
+  // download this file, and modify the header, so it can be fed to python
+
+  void prepareHydraulicElementFlowPathJ(String hydElemPtr, String r2db, File workingDir) throws IOException {
+    final String hydelemFile = "hydelem_file.tmp";
+    String hydelemflowpathFile = "";
+    BufferedReader br = null;
+    try {
+      // first open hydElemPtr file
+      getFile(hydElemPtr, workingDir.getParentFile(), hydelemFile);
+      // look for HYD_SYSTEM_FLOW_PATH_TYPE
+      LOG.info("reading --- " + workingDir.getParent() + "/" + hydelemFile);
+      File hydElemFile = new File(workingDir.getParent(), hydelemFile);
+      br = new BufferedReader(new FileReader(hydElemFile));
+      String inLine;
+      while ((inLine = br.readLine()) != null) {
+        if (inLine.contains("HYD_SYSTEM_FLOW_PATH_TYPE")) {
+          // get the text between the single two quotes- this will be the flowpathfile we need to get
+          // <ObR><Name>HYD_SYSTEM_FLOW_PATH_TYPE</Name><Data>'0.3% grade channel'</Data><Type>HYD_ELEMENT_FLOW_PATH</Type></ObR></Obj>
+          hydelemflowpathFile = inLine.split("'")[1];
+          LOG.info("Read hydelemflowpathFile as =" + hydelemflowpathFile);
         }
+      }
+      String hydElemFlowPathPtr = r2db + "/hydraulic-element-flow-paths/" + hydelemflowpathFile + ".xml";
+      LOG.info("HydelemflowpathPTR is =" + hydElemFlowPathPtr);
+      // call ingprepareFileJ to finish the work...
+      // next open the flowpathfile, and perform the standard formatting
+      // of adding the <Obj> tag and the <Filename> tag...
+      prepareFileJ(hydElemFlowPathPtr, new File(workingDir.getParent(), "hydelemflowpath_file.xml"), "", "hydraulic-element-flow-paths", "hydelemflowpath", false);
+    } catch (Exception ioe) {
+      LOG.info("IO Exception while preparing file=" + ioe.toString());
+    } finally {
+      if (br != null) {
+        br.close();
+      }
+    }
+  }
 
-//        String runrusle2 = "winetricks vd=off ; wine /home/ubuntu/.wine/drive_c/Python34/python.exe rusle2csip.py\n";
-        stdout += "\n" + FileUtils.readFileToString( python.stdout() );
-        if ( LOG.isLoggable( Level.INFO ) ) {
-            LOG.info( "stdout: " + stdout );
-            LOG.info( "exit val: " + ret );
-        }
-        return ret;
+
+  int determineNumberOfFlowPaths(String hydElemPtr) {
+    hydElemPtr = hydElemPtr.substring(hydElemPtr.lastIndexOf("\\") + 1);
+
+    // This rediumentary algorithm for determining the number of flow paths for
+    // a hydaulic element system is based on conversation with Jack Carlson in late 03/2016
+    LOG.info("********\n\n\n\nHYD ELEM PTR=" + hydElemPtr);
+    //if (hydElemPtr.substring(hydElemPtr.lastIndexOf("\")+1).startsWith("1"))
+    if (hydElemPtr.startsWith("1")) {
+      if (hydElemPtr.contains("middle")) {
+        return 2;
+      } else {
+        return 1;
+      }
     }
 
-    // Must find the hydraulic element flow path element of a hydraulic element system
-    // download this file, and modify the header, so it can be fed to python
-    void prepareHydraulicElementFlowPathJ ( String hydElemPtr, String r2db, File workingDir ) throws IOException {
-        final String hydelemFile = "hydelem_file.tmp";
-        String hydelemflowpathFile = "";
-        BufferedReader br = null;
-        try {
-            // first open hydElemPtr file
-            getFile( hydElemPtr, workingDir.getParentFile(), hydelemFile );
-            // look for HYD_SYSTEM_FLOW_PATH_TYPE
-            LOG.info( "reading --- " + workingDir.getParent() + "/" + hydelemFile );
-            File hydElemFile = new File( workingDir.getParent(), hydelemFile );
-            br = new BufferedReader( new FileReader( hydElemFile ) );
-            String inLine;
-            while ( ( inLine = br.readLine() ) != null ) {
-                if ( inLine.contains( "HYD_SYSTEM_FLOW_PATH_TYPE" ) ) {
-                    // get the text between the single two quotes- this will be the flowpathfile we need to get
-                    // <ObR><Name>HYD_SYSTEM_FLOW_PATH_TYPE</Name><Data>'0.3% grade channel'</Data><Type>HYD_ELEMENT_FLOW_PATH</Type></ObR></Obj>
-                    hydelemflowpathFile = inLine.split( "'" )[1];
-                    LOG.info( "Read hydelemflowpathFile as =" + hydelemflowpathFile );
-                }
-            }
-            String hydElemFlowPathPtr = r2db + "/hydraulic-element-flow-paths/" + hydelemflowpathFile + ".xml";
-            LOG.info( "HydelemflowpathPTR is =" + hydElemFlowPathPtr );
-            // call ingprepareFileJ to finish the work...
-            // next open the flowpathfile, and perform the standard formatting
-            // of adding the <Obj> tag and the <Filename> tag...
-            prepareFileJ( hydElemFlowPathPtr, new File( workingDir.getParent(), "hydelemflowpath_file.xml" ), "", "hydraulic-element-flow-paths", "hydelemflowpath", false );
-        }
-        catch ( Exception ioe ) {
-            LOG.info( "IO Exception while preparing file=" + ioe.toString() );
-        }
-        finally {
-            if ( br != null ) {
-                br.close();
-            }
-        }
+    // presently there are only 2 kinds of hydraulic element systems with 2 elements.
+    // ones with only "middle" in the name which should have 3 flow paths (all evenly distributed along the slope),
+    // and ones with "middle" and "bottom" in the name which should have 2 flow paths (one in middle, one at bottom).
+    //
+    // presently there is one hydraulic element with "along" instead of "middle" in the name
+    // "2 Water and Sediment Control Basins along RUSLE slope.xml"  This should be treated the same as middle.
+    //
+    if (hydElemPtr.startsWith("2")) {
+      if (((hydElemPtr.contains("middle")) || (hydElemPtr.contains("along"))) && (!hydElemPtr.contains("bottom"))) {
+        return 3;
+      } else {
+        // These should have middle and bottom
+        return 2;
+      }
     }
 
-    int determineNumberOfFlowPaths ( String hydElemPtr ) {
-        hydElemPtr = hydElemPtr.substring( hydElemPtr.lastIndexOf( "\\" ) + 1 );
+    // presently there are only 2 kinds of hydraulic element systems with 3 elements.
+    // ones with only "middle" in the name which should have 4 flow paths (all evenly distributed along the slope),
+    // and ones with "middle" and "bottom" in the name which should have 3 flow paths (two in middle, one at bottom).
+    if (hydElemPtr.startsWith("3")) {
+      if ((hydElemPtr.contains("middle")) && (!hydElemPtr.contains("bottom"))) {
+        return 4;
+      } else {
+        // These should have middle and bottom
+        return 3;
+      }
+    }
+    // Should not get here.
+    return 0;
+  }
 
-        // This rediumentary algorithm for determining the number of flow paths for
-        // a hydaulic element system is based on conversation with Jack Carlson in late 03/2016
-        LOG.info( "********\n\n\n\nHYD ELEM PTR=" + hydElemPtr );
-        //if (hydElemPtr.substring(hydElemPtr.lastIndexOf("\")+1).startsWith("1"))
-        if ( hydElemPtr.startsWith( "1" ) ) {
-            if ( hydElemPtr.contains( "middle" ) ) {
-                return 2;
-            } else {
-                return 1;
-            }
-        }
 
-        // presently there are only 2 kinds of hydraulic element systems with 2 elements.
-        // ones with only "middle" in the name which should have 3 flow paths (all evenly distributed along the slope),
-        // and ones with "middle" and "bottom" in the name which should have 2 flow paths (one in middle, one at bottom).
-        //
-        // presently there is one hydraulic element with "along" instead of "middle" in the name
-        // "2 Water and Sediment Control Basins along RUSLE slope.xml"  This should be treated the same as middle.
-        //
-        if ( hydElemPtr.startsWith( "2" ) ) {
-            if ( ( ( hydElemPtr.contains( "middle" ) ) || ( hydElemPtr.contains( "along" ) ) ) && ( !hydElemPtr.contains( "bottom" ) ) ) {
-                return 3;
-            } else {
-                // These should have middle and bottom
-                return 2;
-            }
-        }
-
-        // presently there are only 2 kinds of hydraulic element systems with 3 elements.
-        // ones with only "middle" in the name which should have 4 flow paths (all evenly distributed along the slope),
-        // and ones with "middle" and "bottom" in the name which should have 3 flow paths (two in middle, one at bottom).
-        if ( hydElemPtr.startsWith( "3" ) ) {
-            if ( ( hydElemPtr.contains( "middle" ) ) && ( !hydElemPtr.contains( "bottom" ) ) ) {
-                return 4;
-            } else {
-                // These should have middle and bottom
-                return 3;
-            }
-        }
-        // Should not get here.
-        return 0;
+  double[] determineFlowPathDistribution(String hydElemPtr) {
+    hydElemPtr = hydElemPtr.substring(hydElemPtr.lastIndexOf("\\") + 1);
+    // This rediumentary algorithm for determining the hyd elem flow path position relative to slope length for
+    // a hydaulic element system is based on conversation with Jack Carlson in late 03/2016
+    if (hydElemPtr.substring(hydElemPtr.lastIndexOf("\\") + 1).startsWith("1")) {
+      if (hydElemPtr.contains("middle")) {
+        return new double[]{.5, 1};
+      } else {
+        return new double[]{1};
+      }
     }
 
-    double[] determineFlowPathDistribution ( String hydElemPtr ) {
-        hydElemPtr = hydElemPtr.substring( hydElemPtr.lastIndexOf( "\\" ) + 1 );
-        // This rediumentary algorithm for determining the hyd elem flow path position relative to slope length for
-        // a hydaulic element system is based on conversation with Jack Carlson in late 03/2016
-        if ( hydElemPtr.substring( hydElemPtr.lastIndexOf( "\\" ) + 1 ).startsWith( "1" ) ) {
-            if ( hydElemPtr.contains( "middle" ) ) {
-                return new double[] {.5, 1};
-            } else {
-                return new double[] {1};
-            }
-        }
-
-        // presently there are only 2 kinds of hydraulic element systems with 2 elements.
-        // ones with only "middle" in the name which should have 3 flow paths (all evenly distributed along the slope),
-        // and ones with "middle" and "bottom" in the name which should have 2 flow paths (one in middle, one at bottom).
-        //
-        // presently there is one hydraulic element with "along" instead of "middle" in the name
-        // "2 Water and Sediment Control Basins along RUSLE slope.xml"  This should be treated the same as middle.
-        //
-        if ( hydElemPtr.startsWith( "2" ) ) {
-            if ( ( ( hydElemPtr.contains( "middle" ) ) || ( hydElemPtr.contains( "along" ) ) ) && ( !hydElemPtr.contains( "bottom" ) ) ) {
-                return new double[] {.333, .666, 1};
-            } else {
-                // These should have middle and bottom
-                return new double[] {.5, 1};
-            }
-        }
-
-        // presently there are only 2 kinds of hydraulic element systems with 3 elements.
-        // ones with only "middle" in the name which should have 4 flow paths (all evenly distributed along the slope),
-        // and ones with "middle" and "bottom" in the name which should have 3 flow paths (two in middle, one at bottom).
-        if ( hydElemPtr.startsWith( "3" ) ) {
-            if ( ( hydElemPtr.contains( "middle" ) ) && ( !hydElemPtr.contains( "bottom" ) ) ) {
-                return new double[] {.25, .5, .75, 1};
-            } else {
-                // These should have middle and bottom
-                return new double[] {.333, .666, 1};
-            }
-        }
-        // Should not get here...
-        return new double[] {0};
+    // presently there are only 2 kinds of hydraulic element systems with 2 elements.
+    // ones with only "middle" in the name which should have 3 flow paths (all evenly distributed along the slope),
+    // and ones with "middle" and "bottom" in the name which should have 2 flow paths (one in middle, one at bottom).
+    //
+    // presently there is one hydraulic element with "along" instead of "middle" in the name
+    // "2 Water and Sediment Control Basins along RUSLE slope.xml"  This should be treated the same as middle.
+    //
+    if (hydElemPtr.startsWith("2")) {
+      if (((hydElemPtr.contains("middle")) || (hydElemPtr.contains("along"))) && (!hydElemPtr.contains("bottom"))) {
+        return new double[]{.333, .666, 1};
+      } else {
+        // These should have middle and bottom
+        return new double[]{.5, 1};
+      }
     }
 
-    // Generic File Preparation routine
-    // Downloads, and prepares a file for use in Rusle2 Pyrome
-    //
-    // fileType: the type of file to process
-    // Valid fileType(s) include: "contour",
-    //
-    // fileDir: the dir of the filename specified in the <Filename> tag in the R2 XML file
-    // Valid fileDir(s) include: "countour-systems"
-    //
-    // idx: An index value, if there are multiple items of the same type for slope segments
-    void prepareFileJ ( String httpPtr, File outputFile, String fileType, String fileDir, String basefilename, boolean prepareSoilForPyrome ) throws IOException {
-        BufferedReader br = null;
-        Writer bw = null;
+    // presently there are only 2 kinds of hydraulic element systems with 3 elements.
+    // ones with only "middle" in the name which should have 4 flow paths (all evenly distributed along the slope),
+    // and ones with "middle" and "bottom" in the name which should have 3 flow paths (two in middle, one at bottom).
+    if (hydElemPtr.startsWith("3")) {
+      if ((hydElemPtr.contains("middle")) && (!hydElemPtr.contains("bottom"))) {
+        return new double[]{.25, .5, .75, 1};
+      } else {
+        // These should have middle and bottom
+        return new double[]{.333, .666, 1};
+      }
+    }
+    // Should not get here...
+    return new double[]{0};
+  }
 
-        String fn = ( ( ( basefilename != null ) & ( basefilename.length() > 0 ) ) ? "\\" + basefilename + "1" : "\\aaa" );
-        try {
-            // Generate shell script to prepare --fileType-- file for pyrome
-            LOG.info( "******** the " + fileType + " file name=" + outputFile.getName() );
-            String tmpFilename = outputFile.getName().substring( 0, outputFile.getName().length() - 4 ) + ".tmp";
-            LOG.info( "******** the " + fileType + " tmp file name=" + tmpFilename );
+  // Generic File Preparation routine
+  // Downloads, and prepares a file for use in Rusle2 Pyrome
+  //
+  // fileType: the type of file to process
+  // Valid fileType(s) include: "contour",
+  //
+  // fileDir: the dir of the filename specified in the <Filename> tag in the R2 XML file
+  // Valid fileDir(s) include: "countour-systems"
+  //
+  // idx: An index value, if there are multiple items of the same type for slope segments
 
-            getFile( httpPtr, outputFile.getParentFile(), tmpFilename );
-            bw = new PrintWriter( outputFile );
+  void prepareFileJ(String httpPtr, File outputFile, String fileType, String fileDir, String basefilename, boolean prepareSoilForPyrome) throws IOException {
+    BufferedReader br = null;
+    Writer bw = null;
 
-            File origFile = new File( outputFile.getParent(), tmpFilename );
-            br = new BufferedReader( new FileReader( origFile ) );
+    String fn = (((basefilename != null) & (basefilename.length() > 0)) ? "\\" + basefilename + "1" : "\\aaa");
+    try {
+      // Generate shell script to prepare --fileType-- file for pyrome
+      LOG.info("******** the " + fileType + " file name=" + outputFile.getName());
+      String tmpFilename = outputFile.getName().substring(0, outputFile.getName().length() - 4) + ".tmp";
+      LOG.info("******** the " + fileType + " tmp file name=" + tmpFilename);
 
-            if ( ( fileType.contentEquals( "CLIMATE" ) ) || ( fileType.contentEquals( "SOIL" ) ) || ( prepareSoilForPyrome ) ) {
-                bw.write( "<?xml version=\"1.0\"?>\n" );
-            }
-            if ( !fileType.contentEquals( "SOIL" ) ) {
-                bw.write( "<Obj>\n" );
-                if ( fileType.length() > 1 ) {
-                    bw.write( "<Type>" + fileType + "</Type>\n" );
-                }
-                // if an incrementing index is needed, replace "0" with counter variable
-                bw.write( "<Filename>" + fileDir + fn + "</Filename>\n" );
-            }
-            int i = 0;
-            String inputLine;
-            while ( ( inputLine = br.readLine() ) != null ) {
-                // skip the first line of the file, except for soil files which only have 1 line
-                if ( ( i > 0 ) || ( fileType.contentEquals( "SOIL" ) && ( i == 0 ) && ( inputLine.startsWith( "<Obj>" ) ) ) ) {
-                    bw.write( inputLine + "\n" );
-                }
-                i++;
-            }
+      getFile(httpPtr, outputFile.getParentFile(), tmpFilename);
+      bw = new PrintWriter(outputFile);
+
+      File origFile = new File(outputFile.getParent(), tmpFilename);
+      br = new BufferedReader(new FileReader(origFile));
+
+      if ((fileType.contentEquals("CLIMATE")) || (fileType.contentEquals("SOIL")) || (prepareSoilForPyrome)) {
+        bw.write("<?xml version=\"1.0\"?>\n");
+      }
+      if (!fileType.contentEquals("SOIL")) {
+        bw.write("<Obj>\n");
+        if (fileType.length() > 1) {
+          bw.write("<Type>" + fileType + "</Type>\n");
         }
-        catch ( IOException ioe ) {
-            LOG.info( "IO Exception while preparing flie=" + outputFile.getName() + "---" + ioe.toString() );
+        // if an incrementing index is needed, replace "0" with counter variable
+        bw.write("<Filename>" + fileDir + fn + "</Filename>\n");
+      }
+      int i = 0;
+      String inputLine;
+      while ((inputLine = br.readLine()) != null) {
+        // skip the first line of the file, except for soil files which only have 1 line
+        if ((i > 0) || (fileType.contentEquals("SOIL") && (i == 0) && (inputLine.startsWith("<Obj>")))) {
+          bw.write(inputLine + "\n");
         }
-        finally {
-            if ( br != null ) {
-                br.close();
-            }
-            if ( bw != null ) {
-                bw.close();
-            }
-        }
+        i++;
+      }
+    } catch (IOException ioe) {
+      LOG.info("IO Exception while preparing flie=" + outputFile.getName() + "---" + ioe.toString());
+    } finally {
+      if (br != null) {
+        br.close();
+      }
+      if (bw != null) {
+        bw.close();
+      }
+    }
+  }
+
+  // TO DO
+  // Consider moving to a helper class since this is a generally applicable function
+
+  private boolean getFile(String url, File destDir, String filename) throws FileNotFoundException, IOException {
+    String u = XMLUtils.escapeURL(url);
+    if (exists(u)) {
+      File f = new File(destDir, filename);
+      FileUtils.copyURLToFile(new URL(u), f);
+      return f.exists();
+    }
+    return false;
+  }
+
+
+  public static boolean exists(String URLName) throws IOException {
+    HttpURLConnection.setFollowRedirects(false);
+    // note : you may also need
+    //        HttpURLConnection.setInstanceFollowRedirects(false)
+    HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection();
+    con.setRequestMethod("GET");
+    return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
+  }
+
+
+  /**
+   * Gets results returned from RomeShell
+   *
+   * @param key
+   * @return
+   */
+  protected String getResult(String key) {
+    String sPattern = "RomeFileGetAttrValue " + key;
+
+    // Check if attr is available via the GetAttrValue cmd and return if so
+    if (stdout.contains(sPattern)) {
+      int start = stdout.indexOf(sPattern) + sPattern.length() + 2;
+      int end = stdout.indexOf('\r', start);
+      return stdout.substring(start, end).trim();
     }
 
-    // TO DO
-    // Consider moving to a helper class since this is a generally applicable function
-    private boolean getFile ( String url, File destDir, String filename ) throws FileNotFoundException, IOException {
-        String u = XMLUtils.escapeURL( url );
-        if ( exists( u ) ) {
-            File f = new File( destDir, filename );
-            FileUtils.copyURLToFile( new URL( u ), f );
-            return f.exists();
-        }
-        return false;
+    // Check if attr is available via the TestAttrValue cmd and return if so
+    sPattern = "RomeFileTestAttrValue " + key;
+    if (stdout.contains(sPattern)) {
+      int start = stdout.indexOf(sPattern) + sPattern.length() + 2;
+      int end = stdout.indexOf('\r', start);
+      return stdout.substring(start, end).trim();
     }
 
-    public static boolean exists ( String URLName ) throws IOException {
-        HttpURLConnection.setFollowRedirects( false );
-        // note : you may also need
-        //        HttpURLConnection.setInstanceFollowRedirects(false)
-        HttpURLConnection con = ( HttpURLConnection ) new URL( URLName ).openConnection();
-        con.setRequestMethod( "GET" );
-        return ( con.getResponseCode() == HttpURLConnection.HTTP_OK );
+    sPattern = ":" + removeFirstLastChar(key) + "\"";
+    if (stdout.contains(sPattern)) {
+      int start = stdout.indexOf(sPattern) + sPattern.length() + 2;
+      int end = stdout.indexOf('\r', start);
+      String output = stdout.substring(start, end).trim();
+      if ((output == null) || (output.length() <= 0)) {
+        output = "null";
+      }
+      return output;
     }
+    // If attr is not available return null
+    return "null";
+  }
 
-    /**
-     * Gets results returned from RomeShell
-     *
-     * @param key
-     * @return
-     */
-    protected String getResult ( String key ) {
-        String sPattern = "RomeFileGetAttrValue " + key;
 
-        // Check if attr is available via the GetAttrValue cmd and return if so
-        if ( stdout.contains( sPattern ) ) {
-            int start = stdout.indexOf( sPattern ) + sPattern.length() + 2;
-            int end = stdout.indexOf( '\r', start );
-            return stdout.substring( start, end ).trim();
+  /**
+   * Gets results returned from Pyrome
+   *
+   * @param key
+   * @return
+   */
+  protected String getResultPyrome(String key) {
+    if (stdout.contains(key)) {
+      int start = stdout.indexOf(key) + key.length() + 1;
+      int end = stdout.indexOf('\r', start);
+      return stdout.substring(start, end).trim();
+    }
+    return "null";
+  }
+
+
+  /**
+   * Gets results returned from Pyrome
+   *
+   * @param key
+   * @return
+   */
+  protected String getResultPyromeArray(String key, boolean bQuoted, boolean bEscape, boolean bIndexed) {
+    StringBuilder result = new StringBuilder("[");
+    String sPattern = "";
+    String text = "";
+    int idx = 0;
+    do {
+      sPattern = bIndexed ? (key + ":" + idx) : key;
+      LOG.info("Searching for key=" + sPattern);
+      text = getResultPyrome(sPattern);
+      LOG.info("Result of search=" + text);
+      if (!text.contentEquals("null")) {
+        if (idx > 0) {
+          result.append(",");
         }
+        if (bQuoted) {
+          result.append("\"" + (bEscape ? StringEscapeUtils.escapeJava(text) : text) + "\"");
+        } else {
+          result.append(bEscape ? StringEscapeUtils.escapeJava(text) : text);
+        }
+        idx++;
+      }
+    } while (!text.contentEquals("null"));
+    result.append("]");
+    return result.toString();
+  }
 
-        // Check if attr is available via the TestAttrValue cmd and return if so
-        sPattern = "RomeFileTestAttrValue " + key;
-        if ( stdout.contains( sPattern ) ) {
-            int start = stdout.indexOf( sPattern ) + sPattern.length() + 2;
-            int end = stdout.indexOf( '\r', start );
-            return stdout.substring( start, end ).trim();
-        }
 
-        sPattern = ":" + removeFirstLastChar( key ) + "\"";
-        if ( stdout.contains( sPattern ) ) {
-            int start = stdout.indexOf( sPattern ) + sPattern.length() + 2;
-            int end = stdout.indexOf( '\r', start );
-            String output = stdout.substring( start, end ).trim();
-            if ( ( output == null ) || ( output.length() <= 0 ) ) {
-                output = "null";
-            }
-            return output;
-        }
-        // If attr is not available return null
-        return "null";
-    }
+  public boolean isFileUrlReachable(String targetUrl) throws IOException {
+    String fileUrl = XMLUtils.escapeXMLFileURL(targetUrl);
+    return isUrlReachable(fileUrl);
+  }
 
-    /**
-     * Gets results returned from Pyrome
-     *
-     * @param key
-     * @return
-     */
-    protected String getResultPyrome ( String key ) {
-        if ( stdout.contains( key ) ) {
-            int start = stdout.indexOf( key ) + key.length() + 1;
-            int end = stdout.indexOf( '\r', start );
-            return stdout.substring( start, end ).trim();
-        }
-        return "null";
-    }
 
-    /**
-     * Gets results returned from Pyrome
-     *
-     * @param key
-     * @return
-     */
-    protected String getResultPyromeArray ( String key, boolean bQuoted, boolean bEscape, boolean bIndexed ) {
-        StringBuilder result = new StringBuilder( "[" );
-        String sPattern = "";
-        String text = "";
-        int idx = 0;
-        do {
-            sPattern = bIndexed ? ( key + ":" + idx ) : key;
-            LOG.info( "Searching for key=" + sPattern );
-            text = getResultPyrome( sPattern );
-            LOG.info( "Result of search=" + text );
-            if ( !text.contentEquals( "null" ) ) {
-                if ( idx > 0 ) {
-                    result.append( "," );
-                }
-                if ( bQuoted ) {
-                    result.append( "\"" + ( bEscape ? StringEscapeUtils.escapeJava( text ) : text ) + "\"" );
-                } else {
-                    result.append( bEscape ? StringEscapeUtils.escapeJava( text ) : text );
-                }
-                idx++;
-            }
-        }
-        while ( !text.contentEquals( "null" ) );
-        result.append( "]" );
-        return result.toString();
-    }
+  public boolean isUrlReachable(String targetUrl) throws IOException {
+    String r2db = Config.getString("r2.db", "http://oms-db.engr.colostate.edu/r2");
+    String testUrl = r2db + "/" + targetUrl;
+    return exists(testUrl);
+  }
 
-    public boolean isFileUrlReachable ( String targetUrl ) throws IOException {
-        String fileUrl = XMLUtils.escapeXMLFileURL( targetUrl );
-        return isUrlReachable( fileUrl );
-    }
-
-    public boolean isUrlReachable ( String targetUrl ) throws IOException {
-        String r2db = Config.getString( "r2.db", "http://oms-db.engr.colostate.edu/r2" );
-        String testUrl = r2db + "/" + targetUrl;
-        return exists( testUrl );
-    }
-
-    protected static String escapeJavaNoFwdSlash ( String text ) {
-        String javaEsc = StringEscapeUtils.escapeJava( text );
-        return javaEsc.replace( "\\/", "/" );
-    }
+  protected static String escapeJavaNoFwdSlash(String text) {
+    String javaEsc = StringEscapeUtils.escapeJava(text);
+    return javaEsc.replace("\\/", "/");
+  }
 }

src/java/m/rusle2/T_10.java

@@ -6,9 +6,9 @@
 
 package m.rusle2;
 
-import csip.Executable;
+import csip.api.server.Executable;
 import csip.ModelDataService;
-import csip.ServiceException;
+import csip.api.server.ServiceException;
 import csip.annotations.Description;
 import csip.annotations.Name;
 import csip.annotations.Resource;

src/java/m/rusle2/V1_3.java

@@ -12,9 +12,9 @@
 package m.rusle2;
 
 import csip.Config;
-import csip.Executable;
+import csip.api.server.Executable;
 import csip.ModelDataService;
-import csip.ServiceException;
+import csip.api.server.ServiceException;
 import static csip.Utils.removeFirstLastChar;
 import csip.annotations.*;
 import static csip.annotations.ResourceType.EXECUTABLE;
@@ -41,7 +41,7 @@
 import static m.rusle2.V1_3.*;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang3.StringEscapeUtils;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpGet;
@@ -77,7 +77,7 @@
 
 // database
 @Resource( type = JDBC, file = "${conservation_resources.db}", id = DB )
-
+@Deprecated
 public class V1_3 extends ModelDataService {
 
     static final String ROME_EXE = "romeshell";
@@ -125,15 +125,15 @@
 
     File stdout;
 
-    File r2script = new File( getWorkspaceDir(), R2_TMP_FILENAME + R2_TMP_FILEEXT );
+    File r2script = new File( workspace().getDir(), R2_TMP_FILENAME + R2_TMP_FILEEXT );
 
     @Override
     protected void preProcess () throws Exception {
         try {
             LOG.info( "\n\n\n\n\nMETAINFO:" );
-            LOG.info( "\n" + getMetainfo().toString() );
+            LOG.info( "\n" + metainfo().toString() );
             LOG.info( "\n\n\n" );
-            JSONUtils.checkValidResultRequest( getMetainfo(), potResults );
+            V4_0.checkValidResultRequest( metainfo(), potResults );
         }
         catch ( ServiceException se ) {
             LOG.severe( "\n\n\nERROR!!!\n\n\n" + se.toString() );
@@ -153,13 +153,11 @@
             if ( JSONUtils.checkKeyExistsB( getParamMap(), KEY_HYD_ELEM_SYSTEM_PTR ) ) {
                 params.add( "HYD_ELEM_SYSTEM_PTR" );
             }
-            getMetainfo().put( KEY_REQUEST_RESULTS, params );
+//            getMetainfo().put( KEY_REQUEST_RESULTS, params );
         }
 
         // check if sufficient input is there.
-        //JSONUtils.checkKeyExists(getParamMap(), KEY_CLIMATES);
         JSONUtils.checkKeyExists( getParamMap(), KEY_SOILS );
-//        JSONUtils.checkKeyExists(getParamMap(), KEY_MANAGEMENTS);
         JSONUtils.checkKeyExists( getParamMap(), KEY_LENGTH );
         JSONUtils.checkKeyExists( getParamMap(), KEY_STEEPNESS );
         JSONUtils.checkKeyExists( getParamMap(), KEY_MGMTS );
@@ -168,7 +166,8 @@
             throw new ServiceException( "R2 file server unreachable at: " + Config.getString( "r2.db", "http://oms-db.engr.colostate.edu/r2" ) );
         }
 
-        createInputFile( r2script, getMetainfo(), getParamMap() );
+         String[] reqResults =  metainfo().getStringArray(KEY_REQUEST_RESULTS);
+        createInputFile( r2script, reqResults, getParamMap() );
     }
 
     @Override
@@ -209,7 +208,8 @@
 
 //      results.put(JSONUtils.data(KEY_SLOPE_DELIVERY, 3.0));
         String sout = FileUtils.readFileToString( stdout );
-        for ( String r : JSONUtils.getRequestedResults( getMetainfo() ) ) {
+         String[] reqResults =  metainfo().getStringArray(KEY_REQUEST_RESULTS);
+        for ( String r : reqResults) {
             if ( ( errors > 0 ) && ( r.equals( RES_SLOPE_DEGRAD ) ) ) {
                 results().put( r, getResult( sout, r ), R2_MISSING_XML_FILES_WARNING_MSG );
             } else {
@@ -397,7 +397,7 @@
         return "null";
     }
 
-    private void createInputFile ( File file, JSONObject metainfo, Map<String, JSONObject> param )
+    private void createInputFile ( File file, String[] reqResults, Map<String, JSONObject> param )
             throws Exception {
 
         double steepness = JSONUtils.getDoubleParam( param, KEY_STEEPNESS, 0.0 );
@@ -470,7 +470,7 @@
                     managementFormalName[i] = nl.item( ii ).getTextContent();
                 }
             }
-            translator.writeRusle2Xml( getWorkspaceDir().toString(), "lmod_file" + i + ".xml" );
+            translator.writeRusle2Xml( workspace().getDir().toString(), "lmod_file" + i + ".xml" );
             operations = translator.getOperationFiles();
             vegetations = translator.getVegetationFiles();
             residues = translator.getResidueFiles();
@@ -558,7 +558,7 @@
         // OLD VERSION, WHERE WE GOT CLIMATE DIRECTLY FROM NGINX AND DIDN'T MODIFY IT
         // fos.write(("RomeFileSetAttrValue CLIMATE_PTR \"" + climatePtr + "\"\n").getBytes());
         // NEW VERSION, Where the climate file must be modified to work
-        fos.write( ( "FilesOpen \"#XML:" + new File( getWorkspaceDir(), "cli_file" + 0 + ".xml" + "\"\n" ) ).getBytes() );
+        fos.write( ( "FilesOpen \"#XML:" + new File( workspace().getDir(), "cli_file" + 0 + ".xml" + "\"\n" ) ).getBytes() );
         fos.write( ( "RomeFileSetAttrValue CLIMATE_PTR \"climates\\aaa\"\n" ).getBytes() );
 
         // New version, where we have to process the nginx file so R2 reads it
@@ -572,10 +572,10 @@
 // Don't worry about multiple mgmts for now
 //        for (int i = 0; i < managements.length(); i++) {
 //            //reference the lmod file(s)
-//            fos.write(("RomeFileSetAttrValue MAN_PTR \"" + new File(getWorkspace(), "lmod_file" + i + ".xml" + "\"\n")).getBytes());
+//            fos.write(("RomeFileSetAttrValue MAN_PTR \"" + new File(workspace().get(), "lmod_file" + i + ".xml" + "\"\n")).getBytes());
 //        }
         if ( ( managements != null ) && ( managements.length() >= 1 ) ) {
-            fos.write( ( "FilesOpen \"#XML:" + new File( getWorkspaceDir(), "lmod_file" + 0 + ".xml" + "\"\n" ) ).getBytes() );
+            fos.write( ( "FilesOpen \"#XML:" + new File( workspace().getDir(), "lmod_file" + 0 + ".xml" + "\"\n" ) ).getBytes() );
             // fos.write(("Activate \"" + managementFormalName[0] + "\"\n").getBytes());
             fos.write( ( "RomeFileSetAttrValue MAN_BASE_PTR \"" + managementFormalName[0] + "\"\n" ).getBytes() );
             mgmt = managementFormalName[0];
@@ -583,13 +583,13 @@
 
         // to do
         // commented out - using default for now
-        fos.write( ( "FilesOpen \"#XML:" + new File( getWorkspaceDir(), "soils_file0.xml" + "\"\n" ) ).getBytes() );
+        fos.write( ( "FilesOpen \"#XML:" + new File( workspace().getDir(), "soils_file0.xml" + "\"\n" ) ).getBytes() );
         String soilHttpPtr = r2db + "/" + soilPtr.replace( "\\", "/" ) + ".xml";
-        prepareSoilsFile( soilHttpPtr, new File( getWorkspaceDir(), "soils_file0.xml" ), false, "0" );
-        //r2run.prepareFileJ(soilHttpPtr, new File(getWorkspaceDir(), "soils_file0.xml"), "SOILS", "", "", false);
+        prepareSoilsFile( soilHttpPtr, new File( workspace().getDir(), "soils_file0.xml" ), false, "0" );
+        //r2run.prepareFileJ(soilHttpPtr, new File(workspace().getDir(), "soils_file0.xml"), "SOILS", "", "", false);
 
         String cliHttpPtr = r2db + "/" + climatePtr.replace( "\\", "/" ) + ".xml";
-        prepareFileJ( cliHttpPtr, new File( getWorkspaceDir(), "cli_file0.xml" ), "CLIMATE", "climates", "", false );
+        prepareFileJ( cliHttpPtr, new File( workspace().getDir(), "cli_file0.xml" ), "CLIMATE", "climates", "", false );
 
         fos.write( ( "RomeFileSetAttrValue SOIL_PTR \"" + soilPtr + ".xml\"\n" ).getBytes() );
         fos.write( ( "RomeFileSetAttrValue SLOPE_HORIZ \"" + length + "\"\n" ).getBytes() );
@@ -612,13 +612,10 @@
         }
 
         fos.write( "RomeEngineRun\n".getBytes() );
-        for ( String r : JSONUtils.getRequestedResults( metainfo ) ) {
+        for ( String r : reqResults  ) {
             fos.write( ( "RomeFileGetAttrValue " + r + "\n" ).getBytes() );
         }
 
-//        fos.write(("RomeFileGetAttrValue CONTOUR_SYSTEM_PTR\n").getBytes());
-//        fos.write(("RomeFileGetAttrValue STRIP_BARRIER_SYSTEM_PTR\n").getBytes());
-//        fos.write(("RomeFileGetAttrValue HYD_ELEMENT_SYSTEM_PTR\n").getBytes());
         // optionally only include this line when reporting is requested to save service execution time
         fos.write( "READ \"rusle2_report.rsh\"\n".getBytes() );
         fos.write( "RomeExit\n".getBytes() );
@@ -626,11 +623,10 @@
         fos.close();
 
         // Unpack the report rsh file in the work space dir
-        FileUtils.copyFileToDirectory( resources().getFile( REPORT_RSH ), getWorkspaceDir() );
+        FileUtils.copyFileToDirectory( resources().getFile( REPORT_RSH ), workspace().getDir() );
 
         climate = climatePtr;
         soil = soilPtr;
-//        mgmt = mgmtPtr;
 
         LOG.info( "R2 script: " + file.toString() );
     }

src/java/m/rusle2/V2_1.java

@@ -11,10 +11,10 @@
  */
 package m.rusle2;
 
-import csip.Client;
+import csip.utils.Client;
 import csip.Config;
 import csip.ModelDataService;
-import csip.ServiceException;
+import csip.api.server.ServiceException;
 import static csip.Utils.removeFirstLastChar;
 import csip.annotations.*;
 import static csip.annotations.ResourceType.ARCHIVE;
@@ -34,7 +34,7 @@
 import lmod2rusle2.Rusle2Translator;
 import static m.rusle2.V2_1.*;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang3.StringEscapeUtils;
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
@@ -61,6 +61,7 @@
 @Resource( type = REFERENCE, file = "${csip.dir}/bin/win-x86/Python34/python.exe", wine = true, id = PYTHON )
 @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 )
+@Deprecated
 public class V2_1 extends ModelDataService {
 
     static final String R2_TMP_FILENAME = "rusle2csip.py";
@@ -110,10 +111,10 @@
         try {
             if ( LOG.isLoggable( Level.INFO ) ) {
                 LOG.info( "\n\nMETAINFO:" );
-                LOG.info( "\n" + getMetainfo().toString() );
+                LOG.info( "\n" + metainfo().toString() );
                 LOG.info( "\n\n\n" );
             }
-            JSONUtils.checkValidResultRequest( getMetainfo(), POT_RESULTS );
+            V4_0.checkValidResultRequest( metainfo(), POT_RESULTS );
         }
         catch ( ServiceException se ) {
             LOG.severe( "\n\n\nERROR!!!\n\n\n" + se.toString() );
@@ -133,7 +134,7 @@
             if ( parameter().has( KEY_HYD_ELEM_SYSTEM_PTR ) ) {
                 params.add( "HYD_ELEM_SYSTEM_PTR" );
             }
-            getMetainfo().put( KEY_REQUEST_RESULTS, params );
+//            getMetainfo().put( KEY_REQUEST_RESULTS, params );
         }
 
         // check if sufficient input is there.
@@ -143,13 +144,15 @@
             throw new ServiceException( "R2 file server unreachable at: " + r2db );
         }
 
-        File r2script = getWorkspaceFile( R2_TMP_FILENAME );
-        createInputFile( r2script, getMetainfo(), getParamMap() );
+        File r2script = workspace().getFile( R2_TMP_FILENAME );
+        
+        String[] reqResults =  metainfo().getStringArray(KEY_REQUEST_RESULTS);
+        createInputFile( r2script, reqResults, getParamMap() );
     }
 
     @Override
     protected void doProcess () throws Exception {
-        r2run.executePyrome( getWorkspaceFile( R2_TMP_FILENAME ), resources().getExe( PYTHON ) );
+        r2run.executePyrome( workspace().getFile( R2_TMP_FILENAME ), resources().getExe( PYTHON ) );
     }
 
     @Override
@@ -183,7 +186,8 @@
             }
         }
 
-        for ( String r : JSONUtils.getRequestedResults( getMetainfo() ) ) {
+         String[] reqResults =  metainfo().getStringArray(KEY_REQUEST_RESULTS);
+        for ( String r : reqResults ) {
             if ( ( errors > 0 ) && ( r.equals( RES_SLOPE_DEGRAD ) ) ) {
                 results().put( r, r2run.getResultPyrome( r ), R2_MISSING_XML_FILES_WARNING_MSG );
             } else {
@@ -218,7 +222,7 @@
         }
     }
 
-    private void createInputFile ( File file, JSONObject metainfo, Map<String, JSONObject> param )
+    private void createInputFile ( File file, String[] reqResults, Map<String, JSONObject> param )
             throws Exception {
 
         double steepness = parameter().getDouble( KEY_STEEPNESS, 0.0 );
@@ -366,7 +370,7 @@
                 }
             }
 
-            translator.writeRusle2Xml( getWorkspaceDir().toString(), "lmod_file" + i + ".xml" );
+            translator.writeRusle2Xml( workspace().getDir().toString(), "lmod_file" + i + ".xml" );
             operations = translator.getOperationFiles();
             vegetations = translator.getVegetationFiles();
             residues = translator.getResidueFiles();
@@ -486,13 +490,13 @@
             for ( int i = 0; i < aManIdx.length(); i++ ) {
                 pw.append( "    RomeFileSetAttrValue(profile, 'MAN_HORIZ', '" + aManLength.getString( i ) + "', " + i + ")\n" );
                 if ( LOG.isLoggable( Level.INFO ) ) {
-                    LOG.info( "escapeJava test=" + StringEscapeUtils.escapeJava( "simple / test" ) );
-                    LOG.info( "escapeJava test=" + StringEscapeUtils.escapeJavaScript( "simple / test" ) );
-                    LOG.info( "\n\n\n********************--- escapeJava man name=" + StringEscapeUtils.escapeJava( managementFormalName[aManIdx.getInt( i )] ) );
-                    LOG.info( "********************--- escapeJavaScript man name=" + StringEscapeUtils.escapeJavaScript( managementFormalName[aManIdx.getInt( i )] ) );
-                    LOG.info( "********************--- escapeHtml man name=" + StringEscapeUtils.escapeHtml( managementFormalName[aManIdx.getInt( i )] ) );
-                    LOG.info( "********************--- escapeSql man name=" + StringEscapeUtils.escapeSql( managementFormalName[aManIdx.getInt( i )] ) );
-                    LOG.info( "********************--- escapeXml man name=" + StringEscapeUtils.escapeXml( managementFormalName[aManIdx.getInt( i )] ) );
+//                    LOG.info( "escapeJava test=" + StringEscapeUtils.escapeJava( "simple / test" ) );
+//                    LOG.info( "escapeJava test=" + StringEscapeUtils.escapeJavaScript( "simple / test" ) );
+//                    LOG.info( "\n\n\n********************--- escapeJava man name=" + StringEscapeUtils.escapeJava( managementFormalName[aManIdx.getInt( i )] ) );
+//                    LOG.info( "********************--- escapeJavaScript man name=" + StringEscapeUtils.escapeJavaScript( managementFormalName[aManIdx.getInt( i )] ) );
+//                    LOG.info( "********************--- escapeHtml man name=" + StringEscapeUtils.escapeHtml( managementFormalName[aManIdx.getInt( i )] ) );
+//                    LOG.info( "********************--- escapeSql man name=" + StringEscapeUtils.escapeSql( managementFormalName[aManIdx.getInt( i )] ) );
+//                    LOG.info( "********************--- escapeXml man name=" + StringEscapeUtils.escapeXml( managementFormalName[aManIdx.getInt( i )] ) );
                     LOG.info( "********************--- raw Value is=" + managementFormalName[aManIdx.getInt( i )] );
                 }
                 pw.append( "    RomeFileSetAttrValue(profile, 'MAN_PTR', '" + R2Run.escapeJavaNoFwdSlash( managementFormalName[aManIdx.getInt( i )] ) + "', " + i + ")\n" );
@@ -503,13 +507,13 @@
                     + "    RomeFileSetAttrValue(profile, 'MAN_HORIZ', '" + length + "', 0)\n" );
 
             if ( LOG.isLoggable( Level.INFO ) ) {
-                LOG.info( "escapeJava test=" + StringEscapeUtils.escapeJava( "simple / test" ) );
-                LOG.info( "escapeJava test=" + StringEscapeUtils.escapeJavaScript( "simple / test" ) );
-                LOG.info( "\n\n\n********************--- escapeJava man name=" + StringEscapeUtils.escapeJava( managementFormalName[0] ) );
-                LOG.info( "********************--- escapeJavaScript man name=" + StringEscapeUtils.escapeJavaScript( managementFormalName[0] ) );
-                LOG.info( "********************--- escapeHtml man name=" + StringEscapeUtils.escapeHtml( managementFormalName[0] ) );
-                LOG.info( "********************--- escapeSql man name=" + StringEscapeUtils.escapeSql( managementFormalName[0] ) );
-                LOG.info( "********************--- escapeXml man name=" + StringEscapeUtils.escapeXml( managementFormalName[0] ) );
+//                LOG.info( "escapeJava test=" + StringEscapeUtils.escapeJava( "simple / test" ) );
+//                LOG.info( "escapeJava test=" + StringEscapeUtils.escapeJavaScript( "simple / test" ) );
+//                LOG.info( "\n\n\n********************--- escapeJava man name=" + StringEscapeUtils.escapeJava( managementFormalName[0] ) );
+//                LOG.info( "********************--- escapeJavaScript man name=" + StringEscapeUtils.escapeJavaScript( managementFormalName[0] ) );
+//                LOG.info( "********************--- escapeHtml man name=" + StringEscapeUtils.escapeHtml( managementFormalName[0] ) );
+//                LOG.info( "********************--- escapeSql man name=" + StringEscapeUtils.escapeSql( managementFormalName[0] ) );
+//                LOG.info( "********************--- escapeXml man name=" + StringEscapeUtils.escapeXml( managementFormalName[0] ) );
                 LOG.info( "********************--- raw Value is=" + managementFormalName[0] );
             }
             pw.append( "    RomeFileSetAttrValue(profile, 'MAN_PTR', '" + R2Run.escapeJavaNoFwdSlash( managementFormalName[0] ) + "', 0)\n" );
@@ -553,7 +557,7 @@
                 + "    RomeEngineRun(engine)\n" );
 
         // Request specific outputs from Rusle2
-        for ( String r : JSONUtils.getRequestedResults( metainfo ) ) {
+        for ( String r : reqResults ) {
             pw.append( "    paramsize = RomeFileGetAttrSize(profile,'" + r + "')\n"
                     + "    if paramsize > 1:\n"
                     + "        text = '['\n"
@@ -695,22 +699,22 @@
         // prepare individual contour system, strip barrier system, hyd elem sys, if not provided in an array
         if ( parameter().has( KEY_CONTOUR_SYSTEM_PTR ) ) {
             String contourHttpPtr = r2db + "/" + contourSystem.replace( "\\", "/" ) + ".xml";
-            r2run.prepareFileJ( contourHttpPtr, getWorkspaceFile( "contour_file0.xml" ), "", "contour-systems", "", true );
+            r2run.prepareFileJ( contourHttpPtr, workspace().getFile( "contour_file0.xml" ), "", "contour-systems", "", true );
         }
         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 );
+            r2run.prepareFileJ( stripbarrHttpPtr, workspace().getFile( "stripbarr_file0.xml" ), "", "strip-barrier-systems", "", true );
         }
         if ( parameter().has( KEY_HYD_ELEM_SYSTEM_PTR ) ) {
             String hydelemHttpPtr = r2db + "/" + hydElemSystem.replace( "\\", "/" ) + ".xml";
-            r2run.prepareHydraulicElementFlowPathJ( hydelemHttpPtr, r2db, getWorkspaceFile( "hydelemflowpath_file.xml" ) );
+            r2run.prepareHydraulicElementFlowPathJ( hydelemHttpPtr, r2db, workspace().getFile( "hydelemflowpath_file.xml" ) );
         }
 
         // prepare climate file
-        r2run.prepareFileJ( climatePtr, getWorkspaceFile( "cli_file0.xml" ), "CLIMATE", "climates", "", true );
+        r2run.prepareFileJ( climatePtr, workspace().getFile( "cli_file0.xml" ), "CLIMATE", "climates", "", true );
 
         // Unpack the report rsh file in the work space dir
-        FileUtils.copyFileToDirectory( resources().getFile( REPORT_PY_FILENAME ), getWorkspaceDir() );
+        FileUtils.copyFileToDirectory( resources().getFile( REPORT_PY_FILENAME ), workspace().getDir() );
 
         climate = climatePtr;
         soil = soilPtr[0];
@@ -743,9 +747,9 @@
                 JSONObject soilObj = resultArr.getJSONObject( 0 );
                 String soilFilePath = soilObj.getString( KEY_VALUE );
 
-                new Client().doGET( soilFilePath, getWorkspaceFile( "soils_file" + i + ".xml" ) );
+                new Client().doGET( soilFilePath, workspace().getFile( "soils_file" + i + ".xml" ) );
 
-                soilPtr[i] = getSoilFilePath( getWorkspaceFile( "soils_file" + i + ".xml" ) ).replace( "/", "\\" );
+                soilPtr[i] = getSoilFilePath( workspace().getFile( "soils_file" + i + ".xml" ) ).replace( "/", "\\" );
                 if ( LOG.isLoggable( Level.INFO ) ) {
                     LOG.info( "THE SOIL IS =" + soilPtr[i] + "\n\n\n\n" );
                 }

src/java/m/rusle2/V3_0.java

@@ -11,9 +11,9 @@
  */
 package m.rusle2;
 
-import csip.Client;
+import csip.utils.Client;
 import csip.Config;
-import csip.Executable;
+import csip.api.server.Executable;
 import csip.ModelDataService;
 import static csip.ModelDataService.ERROR;
 import static csip.ModelDataService.KEY_METAINFO;
@@ -29,7 +29,7 @@
 import static csip.ModelDataService.REPORT_TYPE;
 import static csip.ModelDataService.REPORT_UNITS;
 import static csip.ModelDataService.VALUE;
-import csip.ServiceException;
+import csip.api.server.ServiceException;
 import static csip.Utils.removeFirstLastChar;
 import csip.annotations.*;
 import static csip.annotations.ResourceType.ARCHIVE;
@@ -48,7 +48,7 @@
 import javax.xml.parsers.ParserConfigurationException;
 import static m.rusle2.V3_0.*;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang3.StringEscapeUtils;
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
@@ -62,1125 +62,885 @@
  *
  * @author wlloyd, od
  */
-@Name( "Rusle2" )
-@Description( "IET / pyrome version of RomeDLL 2.6.8.4; references NRCS Soil Data Mart" )
-@VersionInfo( "3.0" )
-@State( RELEASED )
-@Path( "m/rusle2/3.0" )
-@Polling( first = 1000, next = 1000 )
+@Name("Rusle2")
+@Description("IET / pyrome version of RomeDLL 2.6.8.4; references NRCS Soil Data Mart")
+@VersionInfo("3.0")
+@State(RELEASED)
+@Path("m/rusle2/3.0")
+@Polling(first = 1000, next = 1000)
 
-@Resource( type = FILE, file = "/bin/win-x86/2.6.8.4/RomeDLL.dll", id = ROMEDLL )
-@Resource( type = FILE, file = "/bin/win-x86/2.6.8.4/pyrome.py", id = PYROMESRC )
-@Resource( type = FILE, file = "/bin/win-x86/2.6.8.4/_pyrome.pyd", id = PYROME )
-@Resource( type = ARCHIVE, file = "/bin/win-x86/Python34.zip", id = PYTHONZIP )
-@Resource( type = REFERENCE, file = "${csip.dir}/bin/win-x86/Python34/python.exe", wine = true, id = PYTHON )
+@Resource(type = FILE, file = "/bin/win-x86/2.6.8.4/RomeDLL.dll", id = ROMEDLL)
+@Resource(type = FILE, file = "/bin/win-x86/2.6.8.4/pyrome.py", id = PYROMESRC)
+@Resource(type = FILE, file = "/bin/win-x86/2.6.8.4/_pyrome.pyd", id = PYROME)
+@Resource(type = ARCHIVE, file = "/bin/win-x86/Python34.zip", id = PYTHONZIP)
+@Resource(type = REFERENCE, file = "${csip.dir}/bin/win-x86/Python34/python.exe", wine = true, id = PYTHON)
 
-@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_report.py", id = REPORT_PY_FILENAME)
+@Resource(type = FILE, file = "/bin/win-x86/Rusle2_Report.json", id = REPORT_JSON_TEMPLATE_FILENAME)
 
 public class V3_0 extends ModelDataService {
 
-    static final boolean PRODUCTION_MODE = true;
-    //
-    static final String R2_TMP_FILENAME = "rusle2csip";
-    static final String ROMEDLL = "RomeDLL.dll";
-    static final String PYROMESRC = "pyrome.py";
-    static final String PYROME = "_pyrome.pyd";
-    static final String PYTHONZIP = "Python34.zip";
-    static final String PYTHON = "python.exe";
-    static final String R2_TMP_FILEEXT = ".py";
-    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";
-    static final String REPORT_PY_FILENAME = "rusle2_report.py";
-    static final String KEY_COKEY = "cokey";
+  static final boolean PRODUCTION_MODE = true;
+  //
+  static final String R2_TMP_FILENAME = "rusle2csip";
+  static final String ROMEDLL = "RomeDLL.dll";
+  static final String PYROMESRC = "pyrome.py";
+  static final String PYROME = "_pyrome.pyd";
+  static final String PYTHONZIP = "Python34.zip";
+  static final String PYTHON = "python.exe";
+  static final String R2_TMP_FILEEXT = ".py";
+  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";
+  static final String REPORT_PY_FILENAME = "rusle2_report.py";
+  static final String KEY_COKEY = "cokey";
 
-    /*
+  /*
      * The R2 Run
-     */
-    final R2Run r2run = new R2Run();
-    static final List<String> potResults = Collections.unmodifiableList( Arrays.asList(
-            RES_SLOPE_DELIVERY,
-            RES_SLOPE_T_VALUE,
-            RES_SLOPE_DEGRAD,
-            RES_SLOPE_EQUIV_DIESEL_USE_PER_AREA,
-            RES_SOIL_COND_INDEX_STIR_VAL,
-            RES_SOIL_COND_INDEX_RESULT,
-            RES_SEG_SIM_DAY_LIVE_BIOMASS,
-            RES_SEG_SIM_DAY_COVER_MASS_SUM,
-            RES_SEG_SIM_DAY_STAND_MASS_SUM,
-            RES_SEG_SIM_DAY_CANOPY_COVER,
-            RES_SEG_SIM_DAY_PERENN_VEG_LIVE_HEIGHT,
-            RES_SLOPE_SIM_DAY_DEGRAD,
-            RES_SURF_RES_OUTPUTS_SURF_COV_AT_OP,
-            RES_SOIL_COND_INDEX_OM_SUBFACTOR,
-            RES_SOIL_COND_INDEX_FO_SUBFACTOR,
-            RES_SOIL_COND_INDEX_ER_SUBFACTOR ) );
-    //
-    String climate;
-    String soil;
-    String mgmt;
-    List<String> operations;
-    List<String> vegetations;
-    List<String> residues;
-    // moved these to globals so both R2 and ann can use them.
-    protected double steepness;
-    protected double length;
-    protected String contourSystem;
-    protected JSONArray managements;
-    protected JSONArray aSoils;
-    protected String climatePtr;
+   */
+  final R2Run r2run = new R2Run();
+  static final List<String> potResults = Collections.unmodifiableList(Arrays.asList(
+      RES_SLOPE_DELIVERY,
+      RES_SLOPE_T_VALUE,
+      RES_SLOPE_DEGRAD,
+      RES_SLOPE_EQUIV_DIESEL_USE_PER_AREA,
+      RES_SOIL_COND_INDEX_STIR_VAL,
+      RES_SOIL_COND_INDEX_RESULT,
+      RES_SEG_SIM_DAY_LIVE_BIOMASS,
+      RES_SEG_SIM_DAY_COVER_MASS_SUM,
+      RES_SEG_SIM_DAY_STAND_MASS_SUM,
+      RES_SEG_SIM_DAY_CANOPY_COVER,
+      RES_SEG_SIM_DAY_PERENN_VEG_LIVE_HEIGHT,
+      RES_SLOPE_SIM_DAY_DEGRAD,
+      RES_SURF_RES_OUTPUTS_SURF_COV_AT_OP,
+      RES_SOIL_COND_INDEX_OM_SUBFACTOR,
+      RES_SOIL_COND_INDEX_FO_SUBFACTOR,
+      RES_SOIL_COND_INDEX_ER_SUBFACTOR));
+  //
+  String climate;
+  String soil;
+  String mgmt;
+  List<String> operations;
+  List<String> vegetations;
+  List<String> residues;
+  // moved these to globals so both R2 and ann can use them.
+  protected double steepness;
+  protected double length;
+  protected String contourSystem;
+  protected JSONArray managements;
+  protected JSONArray aSoils;
+  protected String climatePtr;
 
-    //
-    @Override
-    protected void preProcess () throws Exception {
-        // check for requested output.
-        r2run.setLogger( LOG );
-        try {
-            LOG.info( "\n\n\n\n\nMETAINFO:" );
-            LOG.info( "\n" + getMetainfo().toString() );
-            LOG.info( "\n\n\n" );
-            JSONUtils.checkValidResultRequest( getMetainfo(), potResults );
-        }
-        catch ( ServiceException se ) {
-            LOG.severe( "\n\n\nERROR!!!\n\n\n" + se.toString() );
-            LOG.warning( "No Rusle2 return parameters requested! Will use defaults: SLOPE_DELIVERY, SLOPE_T_VALUE, SLOPE_DEGRAD" );
-            List<String> params = new LinkedList<String>();
-            params.add( RES_SLOPE_DELIVERY );
-            params.add( RES_SLOPE_T_VALUE );
-            params.add( RES_SLOPE_DEGRAD );
+  String[] reqResults;
 
-            // check if these are being set
-            if ( JSONUtils.checkKeyExistsB( getParamMap(), KEY_CONTOUR_SYSTEM_PTR ) ) {
-                params.add( "CONTOUR_SYSTEM_PTR" );
-            }
+  //
 
-            if ( JSONUtils.checkKeyExistsB( getParamMap(), KEY_STRIP_BARRIER_SYSTEM_PTR ) ) {
-                params.add( "STRIP_BARRIER_SYSTEM_PTR" );
-            }
+  @Override
+  protected void preProcess() throws Exception {
+    r2run.setLogger(LOG);
+    try {
+      reqResults = metainfo().getStringArray(KEY_REQUEST_RESULTS);
+      LOG.info("\n" + metainfo().toString());
+      V4_0.checkValidResultRequest(metainfo(), potResults);
+    } catch (ServiceException se) {
+      LOG.severe("\n\n\nERROR!!!\n\n\n" + se.toString());
+      LOG.warning("No Rusle2 return parameters requested! Will use defaults: SLOPE_DELIVERY, SLOPE_T_VALUE, SLOPE_DEGRAD");
+      List<String> params = new LinkedList<>();
+      params.add(RES_SLOPE_DELIVERY);
+      params.add(RES_SLOPE_T_VALUE);
+      params.add(RES_SLOPE_DEGRAD);
 
-            if ( JSONUtils.checkKeyExistsB( getParamMap(), KEY_HYD_ELEM_SYSTEM_PTR ) ) {
-                params.add( "HYD_ELEM_SYSTEM_PTR" );
-            }
-            getMetainfo().put( KEY_REQUEST_RESULTS, params );
+      // check if these are being set
+      if (JSONUtils.checkKeyExistsB(getParamMap(), KEY_CONTOUR_SYSTEM_PTR)) {
+        params.add("CONTOUR_SYSTEM_PTR");
+      }
+
+      if (JSONUtils.checkKeyExistsB(getParamMap(), KEY_STRIP_BARRIER_SYSTEM_PTR)) {
+        params.add("STRIP_BARRIER_SYSTEM_PTR");
+      }
+
+      if (JSONUtils.checkKeyExistsB(getParamMap(), KEY_HYD_ELEM_SYSTEM_PTR)) {
+        params.add("HYD_ELEM_SYSTEM_PTR");
+      }
+      reqResults = params.toArray(new String[0]);
+    }
+
+    parameter().require(KEY_SOILS, KEY_LENGTH, KEY_STEEPNESS, KEY_MGMTS);
+
+    if (!r2run.isUrlReachable("climates/default.xml")) {
+      throw new ServiceException("R2 file server unreachable at: " + Config.getString("r2.db", "http://oms-db.engr.colostate.edu/r2"));
+    }
+
+    File r2script = new File(workspace().getDir(), R2_TMP_FILENAME + R2_TMP_FILEEXT);
+    createInputFile(r2script, getParamMap());
+  }
+
+
+  @Override
+  protected void doProcess() throws Exception {
+    try {
+      Executable python = resources().getExe(V3_0.PYTHON);
+      LOG.log(Level.INFO, "EXECUTING PYROME FROM doProcess()...");
+      int result = r2run.executePyrome(new File(workspace().getDir(), R2_TMP_FILENAME + R2_TMP_FILEEXT), python);
+    } catch (Exception e) {
+      LOG.log(Level.SEVERE, "ERROR EXECUTING PYTHON-RUSLE2", e);
+      throw e;
+    }
+  }
+
+
+  @Override
+  protected void postProcess() throws Exception {
+    int errors = 0;
+    for (int i = 0; i < operations.size(); i++) {
+      String op = operations.get(i);
+      if (r2run.isFileUrlReachable(op)) {
+        results().put("OPERATION_" + (i + 1), op, "operation is valid");
+      } else {
+        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)) {
+        results().put("VEGETATION_" + (i + 1), vege, "vegetation is valid");
+      } else {
+        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)) {
+        results().put("RESIDUE_" + (i + 1), res, "residue is valid");
+      } else {
+        results().put("RESIDUE_INVALID_" + (i + 1), res, "RESIDUE IS MISSING");
+        errors++;
+      }
+    }
+
+//      results.put(JSONUtils.data(KEY_SLOPE_DELIVERY, 3.0));
+    for (String r : reqResults) {
+      if ((errors > 0) && (r.equals(RES_SLOPE_DEGRAD))) {
+        results().put(r, r2run.getResultPyrome(r), R2_MISSING_XML_FILES_WARNING_MSG);
+      } else {
+        results().put(r, r2run.getResultPyrome(r));
+      }
+    }
+
+    // Get erosion for segments
+    if (JSONUtils.checkKeyExistsB(getParamMap(), 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));
+        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");
+        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)) {
+          results().put(KEY_DIVERSIONS, r2run.getResultPyromeArray("HYD_ELEM_SYS", true, true, true));
         }
 
-        JSONUtils.checkKeyExists( getParamMap(), KEY_SOILS );
-        JSONUtils.checkKeyExists( getParamMap(), KEY_LENGTH );
-        JSONUtils.checkKeyExists( getParamMap(), KEY_STEEPNESS );
-        JSONUtils.checkKeyExists( getParamMap(), KEY_MGMTS );
+        if (JSONUtils.checkKeyExistsB(getParamMap(), KEY_STRIP_BARRIER_SYSTEMS)) {
+          results().put(KEY_STRIP_BARRIER_SYSTEMS, r2run.getResultPyromeArray("STRIP_BARRIER_SYS", true, true, true));
+        }
+      }
+    } else {
+      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)));
+    }
+  }
 
-        if ( !r2run.isUrlReachable( "climates/default.xml" ) ) {
-            throw new ServiceException( "R2 file server unreachable at: " + Config.getString( "r2.db", "http://oms-db.engr.colostate.edu/r2" ) );
+
+  protected void createInputFile(File file, Map<String, JSONObject> param)
+      throws Exception {
+
+    steepness = JSONUtils.getDoubleParam(param, KEY_STEEPNESS, 0.0);
+    length = JSONUtils.getDoubleParam(param, KEY_LENGTH, 0.0);
+    boolean resolveLoc = JSONUtils.getBooleanParam(param, KEY_RESOLVE_LOCATION, false);
+    double latitude = JSONUtils.getDoubleParam(param, KEY_LATITUDE, 0.0);
+    double longitude = JSONUtils.getDoubleParam(param, KEY_LONGITUDE, 0.0);
+    double simpleRockCoverPercent = JSONUtils.getDoubleParam(param, KEY_SIMPLE_ROCK_COVER, 0.0);
+
+    LOG.info("Rock cover read by service is=" + simpleRockCoverPercent);
+
+    JSONArray aRockCover = JSONUtils.getJSONArrayParam(param, KEY_SIMPLE_ROCK_COVER);
+    for (int i = 0; i < aRockCover.length(); i++) {
+      LOG.info("Rock cover [" + i + "]=" + aRockCover.getDouble(i));
+      // this is temporary, since R2 will be using slope segments soon
+      if (i == 0) {
+        simpleRockCoverPercent = aRockCover.getDouble(i);
+      }
+    }
+
+    climatePtr = JSONUtils.getStringParam(param, KEY_CLIMATES, "");
+
+    aSoils = JSONUtils.getJSONArrayParam(param, KEY_SOILS);
+    String soilPtr[] = new String[(aSoils.length())];
+    for (int i = 0; i < aSoils.length(); i++) {
+      LOG.info("soil [" + i + "]=" + aSoils.getInt(i));
+    }
+
+    contourSystem = "";
+    String stripBarrierSystem = "";
+    String hydElemSystem = "";
+
+    // Get the Contour System if not default
+    if (JSONUtils.checkKeyExistsB(param, KEY_CONTOUR_SYSTEM_PTR)) {
+      contourSystem = JSONUtils.getStringParam(param, KEY_CONTOUR_SYSTEM_PTR, "");
+    }
+
+    // Get the Strip Barrier System
+    if (JSONUtils.checkKeyExistsB(param, KEY_STRIP_BARRIER_SYSTEM_PTR)) {
+      stripBarrierSystem = JSONUtils.getStringParam(param, KEY_STRIP_BARRIER_SYSTEM_PTR, "");
+    }
+
+    // Get the Hydraylic Element System Pointer
+    if (JSONUtils.checkKeyExistsB(param, KEY_HYD_ELEM_SYSTEM_PTR)) {
+      hydElemSystem = JSONUtils.getStringParam(param, KEY_HYD_ELEM_SYSTEM_PTR, "");
+    }
+
+    JSONArray aTopoLength = new JSONArray();
+    JSONArray aTopoSteepness = new JSONArray();
+    JSONArray aSoilIdx = new JSONArray();
+    JSONArray aManIdx = new JSONArray();
+    JSONArray aManLength = new JSONArray();
+    if (JSONUtils.checkKeyExistsB(param, KEY_TOPO_LENGTH)) {
+      aTopoLength = JSONUtils.getJSONArrayParam(param, KEY_TOPO_LENGTH);
+      for (int i = 0; i < aTopoLength.length(); i++) {
+        LOG.info("Topo Length [" + i + "]=" + aTopoLength.getDouble(i));
+      }
+    }
+
+    if (JSONUtils.checkKeyExistsB(param, KEY_TOPO_STEEPNESS)) {
+      aTopoSteepness = JSONUtils.getJSONArrayParam(param, KEY_TOPO_STEEPNESS);
+      for (int i = 0; i < aTopoSteepness.length(); i++) {
+        LOG.info("Topo Steepness [" + i + "]=" + aTopoSteepness.getDouble(i));
+      }
+    }
+
+    if (JSONUtils.checkKeyExistsB(param, KEY_SOIL_INDEX)) {
+      aSoilIdx = JSONUtils.getJSONArrayParam(param, KEY_SOIL_INDEX);
+      for (int i = 0; i < aSoilIdx.length(); i++) {
+        LOG.info("Soil Index [" + i + "]=" + aSoilIdx.getInt(i));
+        //            if (i==0)
+        //                steepness = aSoilIdx.getInt(i);
+      }
+    }
+
+    if (JSONUtils.checkKeyExistsB(param, KEY_MAN_INDEX)) {
+      aManIdx = JSONUtils.getJSONArrayParam(param, KEY_MAN_INDEX);
+      for (int i = 0; i < aManIdx.length(); i++) {
+        LOG.info("Man Index [" + i + "]=" + aManIdx.getInt(i));
+        //            if (i==0)
+        //                steepness = aTopoSteepness.getDouble(i);
+      }
+    }
+
+    if (JSONUtils.checkKeyExistsB(param, 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 (JSONUtils.checkKeyExistsB(param, KEY_TOPO_LENGTH)) {
+      if (!allEqual(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 (JSONUtils.checkKeyExistsB(param, KEY_MAN_INDEX)) {
+      if (!allEqual(aManLength.length(), aManIdx.length())) {
+        throw new ServiceException("RUSLE2 SEGMENT RUN ERROR! SEGMENT ARRAYS FOR MGMT LENGTH AND MGMT INDEX MUST BE OF EQUAL SIZE!");
+      }
+    }
+
+    //soilPtr = JSONUtils.getStringParam(param, KEY_SOILS, "");
+    String managementFormalName[] = new String[]{};
+
+    // management conversion
+    // Make file line separator unix compatible. ???? not sure if needed.
+    System.setProperty("line.separator", "\n");
+    //
+    managements = JSONUtils.getJSONArrayParam(param, KEY_MGMTS);
+
+    LOG.info("managements array=" + managements.toString());
+    managementFormalName = new String[managements.length()];
+
+    for (int i = 0; i < managements.length(); i++) {
+      LOG.info("management #" + i);
+
+      JSONObject lmod = (JSONObject) managements.get(i);
+      LOG.info(lmod.toString());
+
+      LOG.info("creating Jim's translator.");
+      lmod2rusle2.Rusle2Translator translator = new lmod2rusle2.Rusle2Translator();
+      LOG.info("trying to put in the lmod json");
+      translator.readJsonString(lmod.toString());
+      LOG.info("trying to translate=" + translator.Translate());
+
+      Document r2_xml = translator.getDocument();
+
+      LOG.info("R2 XML FILE from trhe translator:\n\n" + translator.getRusle2Xml());
+      LOG.info("R2 XML FILE:\n\n" + translator.getRusle2Xml());
+      //LOG.info("LMOD XML FILE:\n\n" + lmod_xml.getTextContent());
+
+      if ((r2_xml != null) && (r2_xml.getElementsByTagName("Filename") != null)) {
+        NodeList nl = r2_xml.getElementsByTagName("Filename");
+        for (int ii = 0; ii < nl.getLength(); ii++) {
+          LOG.info("filename node=" + nl.item(ii).getTextContent());
+          managementFormalName[i] = nl.item(ii).getTextContent();
+        }
+      }
+      translator.writeRusle2Xml(workspace().getDir().toString(), "lmod_file" + i + ".xml");
+      operations = translator.getOperationFiles();
+      vegetations = translator.getVegetationFiles();
+      residues = translator.getResidueFiles();
+
+      for (String operation : translator.getOperationFiles()) {
+        System.out.println("operation=" + operation);
+      }
+      for (String vege : translator.getVegetationFiles()) {
+        System.out.println("vegetation=" + vege);
+      }
+      for (String residue : translator.getResidueFiles()) {
+        System.out.println("residue=" + residue);
+      }
+    }
+
+    String altR2db = null;
+    if (param.get(KEY_ALT_R2DB) != null) {
+      altR2db = param.get(KEY_ALT_R2DB).getString(VALUE);
+    }
+
+    // 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
+    // may have been passed in
+    LOG.info("Rulse 2 model request resolveLocation=" + resolveLoc);
+    //if (resolveLoc) {
+
+    climatePtr = getClimateFilePath(latitude, longitude);
+    soilPtr = getSoilFiles(aSoils);
+
+    FileOutputStream fos = new FileOutputStream(file);
+    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('" + resources().getFile(PYROMESRC).getParent().replace('\\', '/') + "')\n").getBytes());
+
+    fos.write("from pyrome import *\n".getBytes());
+    fos.write("from time import sleep\n".getBytes());
+
+    fos.write("def linearTest(save = False, openFlags = RX_FILESOPEN_TEMP):\n".getBytes());
+    fos.write("    romeDLL = RomeInit('')\n".getBytes());
+    fos.write("    files = RomeGetFiles(romeDLL)\n".getBytes());
+    fos.write("    engine = RomeGetEngine(romeDLL)\n".getBytes());
+    fos.write("    RomeEngineSetAutorun(engine,RX_FALSE)\n".getBytes());
+    fos.write("    #Inputs\n".getBytes());
+
+    if (aTopoLength.length() > 1) {
+      String text = "    slopes=[";
+      for (int i = 0; i < aTopoSteepness.length(); i++) {
+        text += "'" + aTopoSteepness.getInt(i) + "'";
+        text += (i == aTopoSteepness.length() - 1) ? "]\n" : ",";
+      }
+      fos.write(text.getBytes());
+      text = "    lengths=[";
+      for (int i = 0; i < aTopoLength.length(); i++) {
+        text += "'" + aTopoLength.getInt(i) + "'";
+        text += (i == aTopoLength.length() - 1) ? "]\n" : ",";
+      }
+      fos.write(text.getBytes());
+      if ((aSoilIdx != null) && (aSoilIdx.length() > 0)) {
+        text = "    soilIndex=[";
+        for (int i = 0; i < aSoilIdx.length(); i++) {
+          text += aSoilIdx.getInt(i) + "";
+          text += (i == aSoilIdx.length() - 1) ? "]\n" : ",";
+        }
+        fos.write(text.getBytes());
+      }
+      text = "    manIndex=[";
+      for (int i = 0; i < aManIdx.length(); i++) {
+        text += aManIdx.getInt(i) + "";
+        text += (i == aManIdx.length() - 1) ? "]\n" : ",";
+      }
+      fos.write(text.getBytes());
+
+    } else {
+      String text = "    slopes=['" + steepness + "']\n";
+      fos.write(text.getBytes());
+      text = "    lengths=['" + length + "']\n";
+      fos.write(text.getBytes());
+      fos.write("    soilIndex=[0]\n".getBytes());
+      fos.write("    manIndex=[0]\n".getBytes());
+    }
+
+    fos.write("    results = list()\n".getBytes());
+
+    fos.write("    #Run a simple profile\n".getBytes());
+    fos.write("    profile = RomeFilesOpen(files,'profiles\\\\csippyrome',openFlags)\n".getBytes());
+
+    // Open all of the mgmt files...
+    for (int i = 0; i < managements.length(); i++) {
+      String text = "    mgmt = RomeFilesOpen(files, '#XML:lmod_file" + i + ".xml',0)\n";
+      fos.write(text.getBytes());
+    }
+
+    fos.write("    cli = RomeFilesOpen(files, '#XML:cli_file0.xml',0)\n".getBytes());
+
+    for (int i = 0; i < aSoils.length(); i++) {
+      String text = "    soil" + i + " = RomeFilesOpen(files, '#XML:soils_file" + i + ".xml',0)\n";
+      fos.write(text.getBytes());
+    }
+
+    fos.write("    # SET SLOPE\n".getBytes());
+    String text = "    RomeFileSetAttrValue(profile, 'SLOPE_HORIZ', '" + length + "', 0)\n";
+    fos.write(text.getBytes());
+    text = "    RomeFileSetAttrValue(profile, 'SLOPE_STEEP', '" + steepness + "', 0)\n";
+    fos.write(text.getBytes());
+
+    fos.write("    # SET CLIMATE_PTR\n".getBytes());
+    fos.write("    RomeFileSetAttrValue(profile, 'CLIMATE_PTR','climates\\\\aaa',0)\n".getBytes());
+    fos.write("    print('CLIMATE_PTR=%s' % RomeFileGetAttrValue(profile, 'CLIMATE_PTR', 0))\n".getBytes());
+
+    fos.write("    # SET TOPO LAYER\n".getBytes());
+    if (aTopoLength.length() > 0) {
+      text = "    RomeFileSetAttrSize(profile, 'TOPO_LAYER', " + aTopoLength.length() + ")\n";
+      fos.write(text.getBytes());
+      for (int i = 0; i < aTopoLength.length(); i++) {
+        text = "    RomeFileSetAttrValue(profile, 'TOPO_HORIZ', '" + aTopoLength.getString(i) + "', " + i + ")\n";
+        fos.write(text.getBytes());
+        text = "    RomeFileSetAttrValue(profile, 'TOPO_STEEP', '" + aTopoSteepness.getString(i) + "', " + i + ")\n";
+        fos.write(text.getBytes());
+      }
+    }
+
+    // Presently we do not support multiple soils
+    fos.write("    # SET SOIL LAYER\n".getBytes());
+    if (aSoils.length() > 0) {
+      text = "    RomeFileSetAttrSize(profile, 'SOIL_LAYER', " + aSoils.length() + ")\n";
+      fos.write(text.getBytes());
+      text = "    RomeFileSetAttrValue(profile, 'SOIL_HORIZ', '" + length + "', 0)\n";
+      fos.write(text.getBytes());
+      text = "    RomeFileSetAttrValue(profile, 'SOIL_PTR', '" + StringEscapeUtils.escapeJava(soilPtr[0]) + "', " + 0 + ")\n";
+      fos.write(text.getBytes());
+    }
+
+    // Must be after set soils or the soils code resets it...sometimes
+    if (JSONUtils.checkKeyExistsB(param, KEY_SIMPLE_ROCK_COVER)) {
+      text = "    RomeFileSetAttrValue(profile, 'SIMPLE_ROCK_COVER', '" + simpleRockCoverPercent + "' ,0)\n";
+      fos.write(text.getBytes());
+    }
+
+    fos.write("    # SET MAN LAYER\n".getBytes());
+    if (aManIdx.length() > 0) {
+      text = "    RomeFileSetAttrSize(profile, 'MAN_LAYER', " + aManIdx.length() + ")\n";
+      fos.write(text.getBytes());
+      for (int i = 0; i < aManIdx.length(); i++) {
+        text = "    RomeFileSetAttrValue(profile, 'MAN_HORIZ', '" + aManLength.getString(i) + "', " + i + ")\n";
+        fos.write(text.getBytes());
+        LOG.info("********************--- raw Value is=" + managementFormalName[aManIdx.getInt(i)]);
+        //text = "    RomeFileSetAttrValue(profile, 'MAN_PTR', '" + managementFormalName[aManIdx.getInt(i)] + "', " + i + ")\n";
+        text = "    RomeFileSetAttrValue(profile, 'MAN_PTR', '" + R2Run.escapeJavaNoFwdSlash(managementFormalName[aManIdx.getInt(i)]) + "', " + i + ")\n";
+        fos.write(text.getBytes());
+      }
+    } else {
+      // IF no max_idx array provided, defaulting to single mgmt
+      text = "    RomeFileSetAttrSize(profile, 'MAN_LAYER', 1)\n";
+      fos.write(text.getBytes());
+      text = "    RomeFileSetAttrValue(profile, 'MAN_HORIZ', '" + length + "', 0)\n";
+      fos.write(text.getBytes());
+      LOG.info("********************--- raw Value is=" + managementFormalName[0]);
+      text = "    RomeFileSetAttrValue(profile, 'MAN_PTR', '" + R2Run.escapeJavaNoFwdSlash(managementFormalName[0]) + "', 0)\n";
+      fos.write(text.getBytes());
+    }
+
+    //fos.write("    # Set SOIL_PTR\n".getBytes());
+    //text = "    RomeFileSetAttrValue(profile, 'SOIL_PTR', '" + StringEscapeUtils.escapeJava(soilPtr[0]) + ".xml',0)\n";
+    //fos.write(text.getBytes());
+    fos.write("    print('SOIL_PTR=%s' % RomeFileGetAttrValue(profile, 'SOIL_PTR', 0))\n".getBytes());
+
+    if ((contourSystem != null) && (contourSystem.length() > 1)) {
+      // Contour Systems can simply point to the nginx XML file - no need to prefetch because of no special
+      // characters in the file name
+      text = "    RomeFileSetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', '" + StringEscapeUtils.escapeJava(contourSystem) + "', 0)\n";
+      fos.write(text.getBytes());
+    }
+
+    // To prevent issues with pyrome converting special chars in filenames to invalid chars for web server retrieval,
+    // we prefetch the file, insert a dummy name, and point to it here
+    if ((stripBarrierSystem != null) && (stripBarrierSystem.length() > 1)) {
+
+      fos.write("    stripbarr = RomeFilesOpen(files, '#XML:stripbarr_file0.xml',0)\n".getBytes());
+      text = "    RomeFileSetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', 'strip-barrier-systems\\\\aaa', 0)\n";
+      fos.write(text.getBytes());
+    }
+
+    // Runs with a Hydraulic Element System, use a hydraulic element flow path
+    if ((hydElemSystem != null) && (hydElemSystem.length() > 1)) {
+      // Load the hyd elem flow path into the workspace
+      fos.write("    hydelem = RomeFilesOpen(files, '#XML:hydelemflowpath_file.xml',0)\n".getBytes());
+      int numFlowPaths = r2run.determineNumberOfFlowPaths(hydElemSystem);
+      text = "    RomeFileSetAttrSize(profile, 'NUM_FLOW_PATHS', " + numFlowPaths + ")\n";
+      fos.write(text.getBytes());
+      double offsets[] = r2run.determineFlowPathDistribution(hydElemSystem);
+      for (int i = 0; i < numFlowPaths; i++) {
+        text = "    RomeFileSetAttrValue(profile, 'FLOW_PATH_HORIZ', '" + length * offsets[i] + "', " + i + ")\n";
+        fos.write(text.getBytes());
+        if (i < (numFlowPaths - 1)) {
+          text = "    RomeFileSetAttrValue(profile, 'HYD_ELEM_FLOW_PATH_PTR', 'hydraulic-element-flow-paths\\hydelemflowpath1', " + i + ")\n";
+          fos.write(text.getBytes());
+        } else {
+          // last flow path is always the default
+          text = "    RomeFileSetAttrValue(profile, 'HYD_ELEM_FLOW_PATH_PTR', 'hydraulic-element-flow-paths\\default', " + i + ")\n";
+          fos.write(text.getBytes());
+        }
+      }
+    }
+
+    fos.write("    RomeFileSave(profile)\n".getBytes());
+    fos.write("    RomeEngineRun(engine)\n".getBytes());
+
+    // Request specific outputs from Rusle2
+    for (String r : reqResults) {
+      text = "    paramsize = RomeFileGetAttrSize(profile,'" + r + "')\n";
+      fos.write(text.getBytes());
+      text = "    if paramsize > 1:\n";
+      fos.write(text.getBytes());
+      text = "        text = '['\n";
+      fos.write(text.getBytes());
+      text = "        for x in range (paramsize):\n";
+      fos.write(text.getBytes());
+      text = "            text += RomeFileGetAttrValue(profile,'" + r + "',x)\n";
+      fos.write(text.getBytes());
+      text = "            if x < (paramsize-1):\n";
+      fos.write(text.getBytes());
+      text = "                text += ', '\n";
+      fos.write(text.getBytes());
+      text = "        text += ']'\n";
+      fos.write(text.getBytes());
+      text = "    else:\n";
+      fos.write(text.getBytes());
+      text = "        text = RomeFileGetAttrValue(profile, '" + r + "', 0)\n";
+      fos.write(text.getBytes());
+      text = "    results.append(RomeFileGetAttrValue(profile, '" + r + "', 0))\n";
+      fos.write(text.getBytes());
+      text = "    print('" + r + "=%s' % text)\n";
+      fos.write(text.getBytes());
+    }
+
+    // Request output for segments (seg 0 for non segmented runs)
+    fos.write("    numflowpaths = RomeFileGetAttrSize(profile, 'NUM_FLOW_PATHS')\n".getBytes());
+    fos.write("    print('------------------------------------------------------------------------------')\n".getBytes());
+    fos.write("    print('NUMBER OF FLOWPATHS=%d' % numflowpaths)\n".getBytes());
+    fos.write("    for xx in range (numflowpaths):\n".getBytes());
+    fos.write("        print('FLOW_PATH_HORIZ:%d=%s' % (xx, RomeFileGetAttrValue(profile, 'FLOW_PATH_HORIZ', xx)))\n".getBytes());
+    fos.write("        print('HYD_ELEM_FLOW_PATH_PTR:%d=%s' % (xx, RomeFileGetAttrValue(profile, 'HYD_ELEM_FLOW_PATH_PTR', xx)))\n".getBytes());
+    fos.write("    numsegs = RomeFileGetAttrSize(profile, 'SEGMENT')\n".getBytes());
+    fos.write("    print('NUMBER OF SEGMENTS=%d' % numsegs)\n".getBytes());
+    fos.write("    for x in range (numsegs):\n".getBytes());
+    fos.write("        print('------------------------------------------------------------------------------')\n".getBytes());
+    fos.write("        print('SEGMENT:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SEGMENT', x)))\n".getBytes());
+    fos.write("        print('SEG_HORIZ:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SEG_HORIZ', x)))\n".getBytes());
+    fos.write("        print('SEG_STEEP:%d=%s' % (x,RomeFileGetAttrValue(profile, 'SEG_STEEP', x)))\n".getBytes());
+    fos.write("        print('SEG_MAN:%d=%s' % (x, RomeFileGetAttrValue(profile, 'MAN_PTR', x)))\n".getBytes());
+    fos.write("        print('SEG_SOIL:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SOIL_PTR', x)))\n".getBytes());
+    fos.write("        results.append(RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', x))\n".getBytes());
+    fos.write("        print('SEG_SOIL_LOSS:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', x)))\n".getBytes());
+    fos.write("        print('SEG_SOIL_LAYER %d=%s' % (x, RomeFileGetAttrValue(profile, 'SEG_SOIL_LAYER', x)))\n".getBytes());
+    fos.write("        print('SEG_MAN_LAYER %d=%s' % (x, RomeFileGetAttrValue(profile, 'SEG_MAN_LAYER', x)))\n".getBytes());
+    fos.write("        print('HYD_ELEM_SYS:%d=%s' % (x, RomeFileGetAttrValue(profile, 'HYD_ELEM_SYSTEM_PTR', x)))\n".getBytes());
+    fos.write("        print('STRIP_BARRIER_SYS:%d=%s' % (x, RomeFileGetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', x)))\n".getBytes());
+    fos.write("        print('CONTOUR_SYS:%d=%s' % (x, RomeFileGetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', x)))\n".getBytes());
+    fos.write("    print('------------------------------------------------------------------------------')\n".getBytes());
+
+    fos.write("    numsegs = RomeFileGetAttrSize(profile, 'SOIL_LAYER')\n".getBytes());
+    fos.write("    print('NUMBER OF SOIL SEGMENTS=%d' % numsegs)\n".getBytes());
+    fos.write("    for x in range (numsegs):\n".getBytes());
+    fos.write("        print('------------------------------------------------------------------------------')\n".getBytes());
+    fos.write("        print('SOIL_SEGMENT:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SOIL_LAYER', x)))\n".getBytes());
+    fos.write("        print('SOIL_HORIZ:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SOIL_HORIZ', x)))\n".getBytes());
+    fos.write("        print('SOIL_PTR:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SOIL_PTR', x)))\n".getBytes());
+    fos.write("    print('------------------------------------------------------------------------------')\n".getBytes());
+
+    fos.write("    numsegs = RomeFileGetAttrSize(profile, 'MAN_LAYER')\n".getBytes());
+    fos.write("    print('NUMBER OF MAN SEGMENTS=%d' % numsegs)\n".getBytes());
+    fos.write("    for x in range (numsegs):\n".getBytes());
+    fos.write("        print('------------------------------------------------------------------------------')\n".getBytes());
+    fos.write("        print('MAN_SEGMENT:%d=%s' % (x, RomeFileGetAttrValue(profile, 'MAN_LAYER', x)))\n".getBytes());
+    fos.write("        print('MAN_HORIZ:%d=%s' % (x, RomeFileGetAttrValue(profile, 'MAN_HORIZ', x)))\n".getBytes());
+    fos.write("        print('MAN_PTR:%d=%s' % (x, RomeFileGetAttrValue(profile, 'MAN_PTR', x)))\n".getBytes());
+    fos.write("    print('------------------------------------------------------------------------------')\n".getBytes());
+
+    fos.write("    numsegs = RomeFileGetAttrSize(profile, 'TOPO_LAYER')\n".getBytes());
+    fos.write("    print('NUMBER OF TOPO SEGMENTS=%d' % numsegs)\n".getBytes());
+    fos.write("    for x in range (numsegs):\n".getBytes());
+    fos.write("        print('------------------------------------------------------------------------------')\n".getBytes());
+    fos.write("        print('TOPO_SEGMENT:%d=%s' % (x, RomeFileGetAttrValue(profile, 'TOPO_LAYER', x)))\n".getBytes());
+    fos.write("        print('TOPO_HORIZ:%d=%s' % (x, RomeFileGetAttrValue(profile, 'TOPO_HORIZ', x)))\n".getBytes());
+    fos.write("        print('TOPO_HORIZ_COMPOSITE:%d=%s' % (x, RomeFileGetAttrValue(profile, 'TOPO_HORIZ_COMPOSITE', x)))\n".getBytes());
+    fos.write("        print('TOPO_STEEP:%d=%s' % (x, RomeFileGetAttrValue(profile, 'TOPO_STEEP', x)))\n".getBytes());
+    fos.write("        print('TOPO_STEEP_COMPOSITE:%d=%s' % (x, RomeFileGetAttrValue(profile, 'TOPO_STEEP_COMPOSITE', x)))\n".getBytes());
+    fos.write("    print('------------------------------------------------------------------------------')\n".getBytes());
+
+    text = "    exec(open(\"" + REPORT_PY_FILENAME + "\").read())\n";
+    fos.write(text.getBytes());
+    fos.write("    RomeFileClose(profile)\n".getBytes());
+    fos.write("    return results\n".getBytes());
+
+    fos.write("if __name__ == \"__main__\":\n".getBytes());
+    fos.write("    #inputs\n".getBytes());
+    fos.write("    save = False\n".getBytes());
+    fos.write("    #Run simulation\n".getBytes());
+    fos.write(("    romeDLL = RomeInit('pyrome /DirRoot=" + resources().getFile(ROMEDLL).getParent().replace('\\', '/') + "/')\n").getBytes());
+    fos.write("    database = RomeGetDatabase(romeDLL)\n".getBytes());
+
+    // Specify the nginx server
+    String r2db = Config.getString("r2.db", "http://oms-db.engr.colostate.edu/r2");
+    if (altR2db == null) {
+      text = "    RomeDatabaseOpen(database,'" + r2db + "')\n";
+      fos.write(text.getBytes());
+    } else {
+      String altr2db = r2db.substring(0, r2db.lastIndexOf("/")) + "/model-data/" + altR2db;
+      text = "    RomeDatabaseOpen(database,'" + altr2db + "')\n";
+      fos.write(text.getBytes());
+    }
+    fos.write("    results = linearTest(save)\n".getBytes());
+    fos.write("    RomeDatabaseClose(database)\n".getBytes());
+    fos.write("    RomeExit(romeDLL)\n".getBytes());
+
+    // prepare individual contour system, strip barrier system, hyd elem sys, if not provided in an array
+    if (JSONUtils.checkKeyExistsB(param, KEY_CONTOUR_SYSTEM_PTR)) {
+      String contourHttpPtr = r2db + "/" + contourSystem.replace("\\", "/") + ".xml";
+      r2run.prepareFileJ(contourHttpPtr, new File(workspace().getDir(), "contour_file0.xml"), "", "contour-systems", "", true);
+    }
+    if (JSONUtils.checkKeyExistsB(param, KEY_STRIP_BARRIER_SYSTEM_PTR)) {
+      String stripbarrHttpPtr = r2db + "/" + stripBarrierSystem.replace("\\", "/") + ".xml";
+      r2run.prepareFileJ(stripbarrHttpPtr, new File(workspace().getDir(), "stripbarr_file0.xml"), "", "strip-barrier-systems", "", true);
+    }
+    if (JSONUtils.checkKeyExistsB(param, KEY_HYD_ELEM_SYSTEM_PTR)) {
+      String hydelemHttpPtr = r2db + "/" + hydElemSystem.replace("\\", "/") + ".xml";
+      r2run.prepareHydraulicElementFlowPathJ(hydelemHttpPtr, r2db, new File(workspace().getDir(), "hydelemflowpath_file.xml"));
+    }
+
+    r2run.prepareFileJ(climatePtr, new File(workspace().getDir(), "cli_file0.xml"), "CLIMATE", "climates", "", true);
+
+    // to do
+    // implement rusle 2 report in pyrome
+    // Rusle2 report
+    //fos.write("READ \"rusle2_report.rsh\"\n".getBytes());
+    fos.close();
+
+    // Unpack the report rsh file in the work space dir
+    FileUtils.copyFileToDirectory(resources().getFile(REPORT_PY_FILENAME), workspace().getDir());
+
+    climate = climatePtr;
+    soil = soilPtr[0];
+    mgmt = managementFormalName[0];
+
+    LOG.info("R2 script: " + file.toString());
+  }
+
+
+  private String[] getSoilFiles(JSONArray cokeys) throws JSONException, Exception {
+    String soilPtr[] = new String[(cokeys.length())];
+    JSONObject soilsRequest = new JSONObject();
+    JSONObject meta = new JSONObject();
+    JSONArray paramObj = new JSONArray();
+    JSONObject cokeyObj = new JSONObject();
+    String cokey;
+    JSONObject responseMeta;
+    JSONArray resultArr;
+    JSONObject soilObj;
+    String soilFilePath;
+
+    soilsRequest.put(KEY_METAINFO, meta);
+    soilsRequest.put(KEY_PARAMETER, paramObj);
+    paramObj.put(cokeyObj);
+
+    for (int i = 0; i < cokeys.length(); i++) {
+      cokey = cokeys.getString(i);
+      paramObj.put(0, cokeyObj);
+      cokeyObj.put(KEY_NAME, KEY_COKEY);
+      cokeyObj.put(KEY_VALUE, cokey);
+      LOG.info("SOILS Request: " + soilsRequest.toString());
+      JSONObject soilsResponse = new Client().doPOST(Config.getString("r2.soils", "http://csip.engr.colostate.edu:8092/csip-soils/d/soilsXML/1.0"), soilsRequest);
+      LOG.info("SOILS Response: " + soilsResponse.toString());
+      responseMeta = soilsResponse.getJSONObject(KEY_METAINFO);
+      if (!responseMeta.getString(KEY_STATUS).equalsIgnoreCase("Failed")) {
+        resultArr = soilsResponse.getJSONArray(KEY_RESULT);
+        soilObj = resultArr.getJSONObject(0);
+        soilFilePath = soilObj.getString(KEY_VALUE);
+
+        new Client().doGET(soilFilePath, workspace().getFile("soils_file" + i + ".xml"));
+
+        soilPtr[i] = getSoilFilePath(workspace().getFile("soils_file" + i + ".xml")).replace("/", "\\");
+        LOG.info("THE SOIL IS =" + soilPtr[i] + "\n\n\n\n");
+
+      } else {
+        String error = responseMeta.getString(ERROR);
+        throw new ServiceException("Soil service error: " + error);
+      }
+    }
+    return soilPtr;
+  }
+
+
+  private String getSoilFilePath(File soilFile) throws ParserConfigurationException, SAXException, IOException {
+    String path = "";
+    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+    Document document = documentBuilder.parse(soilFile);
+    path = document.getElementsByTagName("Filename").item(0).getTextContent();
+    return path;
+  }
+
+
+  private String getClimateFilePath(double lat, double lon) throws JSONException, Exception {
+    JSONObject climateReq = new JSONObject();
+    JSONObject meta = new JSONObject();
+    JSONArray param = new JSONArray();
+    JSONObject jlat = new JSONObject();
+    JSONObject jlong = new JSONObject();
+    JSONArray resultArr;
+    JSONObject responseMeta;
+    JSONObject cliObj;
+    String climatePath = "";
+
+    climateReq.put(KEY_METAINFO, meta);
+    climateReq.put(KEY_PARAMETER, param);
+
+    param.put(jlat);
+    param.put(jlong);
+
+    jlat.put(KEY_NAME, KEY_LATITUDE);
+    jlat.put(KEY_VALUE, lat);
+
+    jlong.put(KEY_NAME, KEY_LONGITUDE);
+    jlong.put(KEY_VALUE, lon);
+
+    LOG.info("CLIMATE Request: " + climateReq.toString());
+    JSONObject climateResponse = new Client().doPOST(Config.getString("r2.climate", "http://csip.engr.colostate.edu:8092/csip-misc/d/r2climate/2.0"), climateReq);
+    LOG.info("CLIMATE Response: " + climateResponse.toString());
+    responseMeta = climateResponse.getJSONObject(KEY_METAINFO);
+    if (!responseMeta.getString(KEY_STATUS).equalsIgnoreCase("Failed")) {
+      resultArr = climateResponse.getJSONArray(KEY_RESULT);
+      cliObj = JSONUtils.preprocess(resultArr).get(KEY_CLIMATE_URL);
+      climatePath = cliObj.getString(KEY_VALUE);
+    }
+    return climatePath;
+  }
+
+
+  private String getFilenumber(String filename) {
+    return filename.substring(R2_TMP_FILENAME.length(), filename.length() - R2_TMP_FILEEXT.length());
+  }
+
+
+  @Override
+  protected void doReport() throws Exception {
+//        String sessionWorkDir = workspace().getDir().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 = resources().getFile(REPORT_JSON_TEMPLATE_FILENAME);
+
+    String sReportJSON = FileUtils.readFileToString(reportTemplate);
+    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);
+      System.out.println("------------------------------------------------------------------------PROCESSING ELEMENT:");
+      System.out.println("VAR NAME:" + itemName);
+      System.out.println("-------------------------------------------------------------------------------------------");
+
+      //String value = r2run.getResultPyrome(itemName);
+      String value = r2run.getResult("\"" + itemName + "\"");
+      LOG.info("the value='" + value + "'");
+      if ((value != null) && (value.equals("null"))) {
+        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 {
+            report().put(itemName, new JSONArray(value), desc, units);
+          } catch (JSONException je) {
+            processReportElement(itemName, dimension, units, desc, type, value);
+          }
+        } else {
+          processReportElement(itemName, dimension, units, desc, type, value);
         }
 
-        File r2script = new File( getWorkspaceDir(), R2_TMP_FILENAME + R2_TMP_FILEEXT );
-        createInputFile( r2script, getMetainfo(), getParamMap() );
+      }
+      if (dimension != null) {
+        report().putMetaInfo(itemName, REPORT_DIM, new JSONArray(dimension));
+      }
     }
+  }
 
-    @Override
-    protected void doProcess () throws Exception {
-        try {
-            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 ) {
-            LOG.log( Level.SEVERE, "ERROR EXECUTING PYTHON-RUSLE2", e );
-            throw e;
-        }
+
+  private void prepareHydraulicFlowElementFile() {
+    // Given a Hydraulic Element Pointer, parse the XML and return a Hydraulic Flow Element
+  }
+
+  // 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 {
+    System.out.println("------------------------------------------------------------------------PROCESSING ELEMENT:\n\n");
+    System.out.println("TYPE:" + type);
+    System.out.println("VALUE:" + value);
+    System.out.println("-------------------------------------------------------------------------------------------\n\n");
+
+    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;
+      report().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);
+      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 = removeFirstLastChar(value);
+        System.out.println("VALUE:" + value);
+        report().put(itemName, Double.parseDouble(value), desc, units);
+      }
+      if (value.equals("\"\"")) {
+        report().put(itemName, new Double(0), desc, units);
+      }
+    }
+    if (type.equals("")) {
+      report().put(itemName, value, desc, units);
+    }
+  }
 
-    @Override
-    protected void postProcess () throws Exception {
-        int errors = 0;
-        for ( int i = 0; i < operations.size(); i++ ) {
-            String op = operations.get( i );
-            if ( r2run.isFileUrlReachable( op ) ) {
-                results().put( "OPERATION_" + ( i + 1 ), op, "operation is valid" );
-            } else {
-                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 ) ) {
-                results().put( "VEGETATION_" + ( i + 1 ), vege, "vegetation is valid" );
-            } else {
-                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 ) ) {
-                results().put( "RESIDUE_" + ( i + 1 ), res, "residue is valid" );
-            } else {
-                results().put( "RESIDUE_INVALID_" + ( i + 1 ), res, "RESIDUE IS MISSING" );
-                errors++;
-            }
-        }
 
-//      results.put(JSONUtils.data(KEY_SLOPE_DELIVERY, 3.0));
-        for ( String r : JSONUtils.getRequestedResults( getMetainfo() ) ) {
-            if ( ( errors > 0 ) && ( r.equals( RES_SLOPE_DEGRAD ) ) ) {
-                results().put( r, r2run.getResultPyrome( r ), R2_MISSING_XML_FILES_WARNING_MSG );
-            } else {
-                results().put( r, r2run.getResultPyrome( r ) );
-            }
-        }
-
-        // Get erosion for segments
-        if ( JSONUtils.checkKeyExistsB( getParamMap(), 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 ) );
-                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" );
-                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 ) ) {
-                    results().put( KEY_DIVERSIONS, r2run.getResultPyromeArray( "HYD_ELEM_SYS", true, true, true ) );
-                }
-
-                if ( JSONUtils.checkKeyExistsB( getParamMap(), KEY_STRIP_BARRIER_SYSTEMS ) ) {
-                    results().put( KEY_STRIP_BARRIER_SYSTEMS, r2run.getResultPyromeArray( "STRIP_BARRIER_SYS", true, true, true ) );
-                }
-            }
-        } else {
-            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 ) ) );
-        }
+  private boolean allEqual(int... vals) {
+    if (vals.length < 2) {
+      return true;
     }
-
-    protected void createInputFile ( File file, JSONObject metainfo, Map<String, JSONObject> param )
-            throws Exception {
-
-        steepness = JSONUtils.getDoubleParam( param, KEY_STEEPNESS, 0.0 );
-        length = JSONUtils.getDoubleParam( param, KEY_LENGTH, 0.0 );
-        boolean resolveLoc = JSONUtils.getBooleanParam( param, KEY_RESOLVE_LOCATION, false );
-        double latitude = JSONUtils.getDoubleParam( param, KEY_LATITUDE, 0.0 );
-        double longitude = JSONUtils.getDoubleParam( param, KEY_LONGITUDE, 0.0 );
-        double simpleRockCoverPercent = JSONUtils.getDoubleParam( param, KEY_SIMPLE_ROCK_COVER, 0.0 );
-
-        LOG.info( "Rock cover read by service is=" + simpleRockCoverPercent );
-
-        JSONArray aRockCover = JSONUtils.getJSONArrayParam( param, KEY_SIMPLE_ROCK_COVER );
-        for ( int i = 0; i < aRockCover.length(); i++ ) {
-            LOG.info( "Rock cover [" + i + "]=" + aRockCover.getDouble( i ) );
-            // this is temporary, since R2 will be using slope segments soon
-            if ( i == 0 ) {
-                simpleRockCoverPercent = aRockCover.getDouble( i );
-            }
-        }
-
-        climatePtr = JSONUtils.getStringParam( param, KEY_CLIMATES, "" );
-
-        aSoils = JSONUtils.getJSONArrayParam( param, KEY_SOILS );
-        String soilPtr[] = new String[( aSoils.length() )];
-        for ( int i = 0; i < aSoils.length(); i++ ) {
-            LOG.info( "soil [" + i + "]=" + aSoils.getInt( i ) );
-            // this is temporary, since R2 will be using slope segments soon
-//            if (i==0)
-//                soilPtr = Integer.toString(aSoils.getInt(i));
-        }
-
-        //JSONArray diversions = new JSONArray();
-        //JSONArray contoursytems = new JSONArray();
-        //JSONArray stripBarrrierSystems = new JSONArray();
-        // scalar variables for non-segmented runs
-        contourSystem = "";
-        String stripBarrierSystem = "";
-        String hydElemSystem = "";
-
-        // Get the Contour System if not default
-        if ( JSONUtils.checkKeyExistsB( param, KEY_CONTOUR_SYSTEM_PTR ) ) {
-            contourSystem = JSONUtils.getStringParam( param, KEY_CONTOUR_SYSTEM_PTR, "" );
-        }
-
-        // Get the Strip Barrier System
-        if ( JSONUtils.checkKeyExistsB( param, KEY_STRIP_BARRIER_SYSTEM_PTR ) ) {
-            stripBarrierSystem = JSONUtils.getStringParam( param, KEY_STRIP_BARRIER_SYSTEM_PTR, "" );
-        }
-
-        // Get the Hydraylic Element System Pointer
-        if ( JSONUtils.checkKeyExistsB( param, KEY_HYD_ELEM_SYSTEM_PTR ) ) {
-            hydElemSystem = JSONUtils.getStringParam( param, KEY_HYD_ELEM_SYSTEM_PTR, "" );
-        }
-
-        JSONArray aTopoLength = new JSONArray();
-        JSONArray aTopoSteepness = new JSONArray();
-        JSONArray aSoilIdx = new JSONArray();
-        JSONArray aManIdx = new JSONArray();
-        JSONArray aManLength = new JSONArray();
-//        JSONArray aDiversionIdx = new JSONArray();
-//        JSONArray aContourIdx = new JSONArray();
-//        JSONArray aStripBarrierIdx = new JSONArray();
-        if ( JSONUtils.checkKeyExistsB( param, KEY_TOPO_LENGTH ) ) {
-            aTopoLength = JSONUtils.getJSONArrayParam( param, KEY_TOPO_LENGTH );
-            for ( int i = 0; i < aTopoLength.length(); i++ ) {
-                LOG.info( "Topo Length [" + i + "]=" + aTopoLength.getDouble( i ) );
-//                // this is temporary, since R2 will be using slope segments soon
-//                if (i == 0) {
-//                    length = aTopoLength.getDouble(i);
-//                }
-            }
-        }
-
-        if ( JSONUtils.checkKeyExistsB( param, KEY_TOPO_STEEPNESS ) ) {
-            aTopoSteepness = JSONUtils.getJSONArrayParam( param, KEY_TOPO_STEEPNESS );
-            for ( int i = 0; i < aTopoSteepness.length(); i++ ) {
-                LOG.info( "Topo Steepness [" + i + "]=" + aTopoSteepness.getDouble( i ) );
-//                if (i == 0) {
-//                    steepness = aTopoSteepness.getDouble(i);
-//                }
-            }
-        }
-
-        if ( JSONUtils.checkKeyExistsB( param, KEY_SOIL_INDEX ) ) {
-            aSoilIdx = JSONUtils.getJSONArrayParam( param, KEY_SOIL_INDEX );
-            for ( int i = 0; i < aSoilIdx.length(); i++ ) {
-                LOG.info( "Soil Index [" + i + "]=" + aSoilIdx.getInt( i ) );
-                //            if (i==0)
-                //                steepness = aSoilIdx.getInt(i);
-            }
-        }
-
-        if ( JSONUtils.checkKeyExistsB( param, KEY_MAN_INDEX ) ) {
-            aManIdx = JSONUtils.getJSONArrayParam( param, KEY_MAN_INDEX );
-            for ( int i = 0; i < aManIdx.length(); i++ ) {
-                LOG.info( "Man Index [" + i + "]=" + aManIdx.getInt( i ) );
-                //            if (i==0)
-                //                steepness = aTopoSteepness.getDouble(i);
-            }
-        }
-
-        if ( JSONUtils.checkKeyExistsB( param, 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 (JSONUtils.checkKeyExistsB(param, KEY_DIVERSION_INDEX)) {
-//            aDiversionIdx = JSONUtils.getJSONArrayParam(param, KEY_DIVERSION_INDEX);
-//            for (int i = 0; i < aDiversionIdx.length(); i++) {
-//                LOG.info("Diversion Index [" + i + "]=" + aDiversionIdx.getInt(i));
-//            }
-//        }
-//        if (JSONUtils.checkKeyExistsB(param, KEY_CONTOUR_INDEX)) {
-//            aContourIdx = JSONUtils.getJSONArrayParam(param, KEY_CONTOUR_INDEX);
-//            for (int i = 0; i < aContourIdx.length(); i++) {
-//                LOG.info("Contour Index [" + i + "]=" + aContourIdx.getInt(i));
-//            }
-//        }
-//        if (JSONUtils.checkKeyExistsB(param, KEY_STRIP_BARRIER_INDEX)) {
-//            aStripBarrierIdx = JSONUtils.getJSONArrayParam(param, KEY_STRIP_BARRIER_INDEX);
-//            for (int i = 0; i < aStripBarrierIdx.length(); i++) {
-//                LOG.info("Strip Barrier Index [" + i + "]=" + aStripBarrierIdx.getInt(i));
-//            }
-//        }
-        if ( JSONUtils.checkKeyExistsB( param, KEY_TOPO_LENGTH ) ) {
-            if ( !allEqual( 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 ( JSONUtils.checkKeyExistsB( param, KEY_MAN_INDEX ) ) {
-            if ( !allEqual( aManLength.length(), aManIdx.length() ) ) {
-                throw new ServiceException( "RUSLE2 SEGMENT RUN ERROR! SEGMENT ARRAYS FOR MGMT LENGTH AND MGMT INDEX MUST BE OF EQUAL SIZE!" );
-            }
-        }
-
-        //soilPtr = JSONUtils.getStringParam(param, KEY_SOILS, "");
-        String managementFormalName[] = new String[] {};
-
-//        String mgmtPtr = JSONUtils.getStringParam(param, KEY_MANAGEMENTS, "");
-//        if (!mgmtPtr.startsWith("managements\\")) {
-//            mgmtPtr = "managements\\" + mgmtPtr;
-//        }
-        // management conversion
-        // Make file line separator unix compatible. ???? not sure if needed.
-        System.setProperty( "line.separator", "\n" );
-        //
-        managements = JSONUtils.getJSONArrayParam( param, KEY_MGMTS );
-
-        LOG.info( "managements array=" + managements.toString() );
-        managementFormalName = new String[managements.length()];
-
-        for ( int i = 0; i < managements.length(); i++ ) {
-            LOG.info( "management #" + i );
-
-            JSONObject lmod = ( JSONObject ) managements.get( i );
-            LOG.info( lmod.toString() );
-
-            LOG.info( "creating Jim's translator." );
-            lmod2rusle2.Rusle2Translator translator = new lmod2rusle2.Rusle2Translator();
-            LOG.info( "trying to put in the lmod json" );
-            translator.readJsonString( lmod.toString() );
-            LOG.info( "trying to translate=" + translator.Translate() );
-
-//            // extract the element as JSON
-//            Document lmod_xml = Lmod2Rusle2.readJSON(lmod, false);
-//            // Translate the file into RUSLE2 format
-//            Document r2_xml = Lmod2Rusle2.LmodXmlToRusle2Xml(lmod_xml, "F");
-            Document r2_xml = translator.getDocument();
-
-            LOG.info( "R2 XML FILE from trhe translator:\n\n" + translator.getRusle2Xml() );
-            LOG.info( "R2 XML FILE:\n\n" + translator.getRusle2Xml() );
-            //LOG.info("LMOD XML FILE:\n\n" + lmod_xml.getTextContent());
-
-//            if ((lmod_xml != null) && (lmod_xml.getElementById("Filename") != null))
-//                managementFormalName[i] = lmod_xml.getElementById("Filename").getTextContent();
-            if ( ( r2_xml != null ) && ( r2_xml.getElementsByTagName( "Filename" ) != null ) ) {
-                NodeList nl = r2_xml.getElementsByTagName( "Filename" );
-                for ( int ii = 0; ii < nl.getLength(); ii++ ) {
-                    LOG.info( "filename node=" + nl.item( ii ).getTextContent() );
-                    managementFormalName[i] = nl.item( ii ).getTextContent();
-                }
-            }
-            translator.writeRusle2Xml( getWorkspaceDir().toString(), "lmod_file" + i + ".xml" );
-            operations = translator.getOperationFiles();
-            vegetations = translator.getVegetationFiles();
-            residues = translator.getResidueFiles();
-
-            for ( String operation : translator.getOperationFiles() ) {
-                System.out.println( "operation=" + operation );
-            }
-            for ( String vege : translator.getVegetationFiles() ) {
-                System.out.println( "vegetation=" + vege );
-            }
-            for ( String residue : translator.getResidueFiles() ) {
-                System.out.println( "residue=" + residue );
-            }
-        }
-
-        String altR2db = null;
-        if ( param.get( KEY_ALT_R2DB ) != null ) {
-            altR2db = param.get( KEY_ALT_R2DB ).getString( VALUE );
-        }
-
-        // 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
-        // may have been passed in
-        LOG.info( "Rulse 2 model request resolveLocation=" + resolveLoc );
-        //if (resolveLoc) {
-
-        climatePtr = getClimateFilePath( latitude, longitude );
-//            // to do
-//            // use only the first soil for now - later we need to use all of them
-//            sString cokey = soilPtr.replace(",", " ");
-//            // strip first and last char
-//            String t2 = cokey.substring(1, cokey.length() - 1);
-//            String delims = "\"";
-//            String tokens[] = t2.split(delims);
-//            LinkedList<String> lst = new LinkedList();
-//            for (String token : tokens) {
-//                if (token.trim().length() > 0) {
-//                    lst.add(token);
-//                }
-//            }
-
-        soilPtr = getSoilFiles( aSoils );
-
-        //}
-        FileOutputStream fos = new FileOutputStream( file );
-
-        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('" + resources().getFile( PYROMESRC ).getParent().replace( '\\', '/' ) + "')\n" ).getBytes() );
-
-        fos.write( "from pyrome import *\n".getBytes() );
-        fos.write( "from time import sleep\n".getBytes() );
-
-        fos.write( "def linearTest(save = False, openFlags = RX_FILESOPEN_TEMP):\n".getBytes() );
-        fos.write( "    romeDLL = RomeInit('')\n".getBytes() );
-        fos.write( "    files = RomeGetFiles(romeDLL)\n".getBytes() );
-        fos.write( "    engine = RomeGetEngine(romeDLL)\n".getBytes() );
-        fos.write( "    RomeEngineSetAutorun(engine,RX_FALSE)\n".getBytes() );
-
-        fos.write( "    #Inputs\n".getBytes() );
-
-        if ( aTopoLength.length() > 1 ) {
-            String text = "    slopes=[";
-            for ( int i = 0; i < aTopoSteepness.length(); i++ ) {
-                text += "'" + aTopoSteepness.getInt( i ) + "'";
-                text += ( i == aTopoSteepness.length() - 1 ) ? "]\n" : ",";
-            }
-            fos.write( text.getBytes() );
-            text = "    lengths=[";
-            for ( int i = 0; i < aTopoLength.length(); i++ ) {
-                text += "'" + aTopoLength.getInt( i ) + "'";
-                text += ( i == aTopoLength.length() - 1 ) ? "]\n" : ",";
-            }
-            fos.write( text.getBytes() );
-            if ( ( aSoilIdx != null ) && ( aSoilIdx.length() > 0 ) ) {
-                text = "    soilIndex=[";
-                for ( int i = 0; i < aSoilIdx.length(); i++ ) {
-                    text += aSoilIdx.getInt( i ) + "";
-                    text += ( i == aSoilIdx.length() - 1 ) ? "]\n" : ",";
-                }
-                fos.write( text.getBytes() );
-            }
-            text = "    manIndex=[";
-            for ( int i = 0; i < aManIdx.length(); i++ ) {
-                text += aManIdx.getInt( i ) + "";
-                text += ( i == aManIdx.length() - 1 ) ? "]\n" : ",";
-            }
-            fos.write( text.getBytes() );
-//            if ((aDiversionIdx != null) && (aDiversionIdx.length() > 0)) {
-//                text = "    diversionIndex=[";
-//                for (int i = 0; i < aDiversionIdx.length(); i++) {
-//                    text += aDiversionIdx.getInt(i) + "";
-//                    text += (i == aDiversionIdx.length() - 1) ? "]\n" : ",";
-//                }
-//                fos.write(text.getBytes());
-//            }
-
-        } else {
-            String text = "    slopes=['" + steepness + "']\n";
-            fos.write( text.getBytes() );
-            text = "    lengths=['" + length + "']\n";
-            fos.write( text.getBytes() );
-            fos.write( "    soilIndex=[0]\n".getBytes() );
-            fos.write( "    manIndex=[0]\n".getBytes() );
-        }
-
-        fos.write( "    results = list()\n".getBytes() );
-
-        fos.write( "    #Run a simple profile\n".getBytes() );
-        fos.write( "    profile = RomeFilesOpen(files,'profiles\\\\csippyrome',openFlags)\n".getBytes() );
-
-        // Open all of the mgmt files...
-        for ( int i = 0; i < managements.length(); i++ ) {
-            String text = "    mgmt = RomeFilesOpen(files, '#XML:lmod_file" + i + ".xml',0)\n";
-            fos.write( text.getBytes() );
-        }
-
-        fos.write( "    cli = RomeFilesOpen(files, '#XML:cli_file0.xml',0)\n".getBytes() );
-
-        for ( int i = 0; i < aSoils.length(); i++ ) {
-            String text = "    soil" + i + " = RomeFilesOpen(files, '#XML:soils_file" + i + ".xml',0)\n";
-            fos.write( text.getBytes() );
-        }
-
-//// need to set these elements based on array settings
-//        for (int i = 0; i < aDiversionIdx.length(); i++) {
-//            String text = "    hydelem = RomeFilesOpen(files, '#XML:hydelem_file" + i + ".xml',0)\n";
-//            fos.write(text.getBytes());
-////            text = "    RomeFileSetAttrValue(profile, 'HYD_ELEM_SYSTEM_PTR', 'hydraulic-element-systems\\\\aaa" + i + "', 0)\n";
-////            fos.write(text.getBytes());
-//        }
-//        for (int i = 0; i < aStripBarrierIdx.length(); i++) {
-//            String text = "    stripbarr = RomeFilesOpen(files, '#XML:stripbarr_file" + i + ".xml',0)\n";
-//            fos.write(text.getBytes());
-////            text = "    RomeFileSetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', 'strip-barrier-systems\\\\aaa" + i + "', 0)\n";
-////            fos.write(text.getBytes());
-//        }
-//        for (int i = 0; i < aContourIdx.length(); i++) {
-//            String text = "    contour = RomeFilesOpen(files, '#XML:contour_file" + i + ".xml',0)\n";
-//            fos.write(text.getBytes());
-////            text = "    RomeFileSetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', 'contour-systems\\\\aaa" + i + "', 0)\n";
-////            fos.write(text.getBytes());
-//        }
-        fos.write( "    # SET SLOPE\n".getBytes() );
-        String text = "    RomeFileSetAttrValue(profile, 'SLOPE_HORIZ', '" + length + "', 0)\n";
-        fos.write( text.getBytes() );
-        text = "    RomeFileSetAttrValue(profile, 'SLOPE_STEEP', '" + steepness + "', 0)\n";
-        fos.write( text.getBytes() );
-
-        fos.write( "    # SET CLIMATE_PTR\n".getBytes() );
-        fos.write( "    RomeFileSetAttrValue(profile, 'CLIMATE_PTR','climates\\\\aaa',0)\n".getBytes() );
-        fos.write( "    print('CLIMATE_PTR=%s' % RomeFileGetAttrValue(profile, 'CLIMATE_PTR', 0))\n".getBytes() );
-
-        fos.write( "    # SET TOPO LAYER\n".getBytes() );
-        if ( aTopoLength.length() > 0 ) {
-            text = "    RomeFileSetAttrSize(profile, 'TOPO_LAYER', " + aTopoLength.length() + ")\n";
-            fos.write( text.getBytes() );
-            for ( int i = 0; i < aTopoLength.length(); i++ ) {
-                text = "    RomeFileSetAttrValue(profile, 'TOPO_HORIZ', '" + aTopoLength.getString( i ) + "', " + i + ")\n";
-                fos.write( text.getBytes() );
-                text = "    RomeFileSetAttrValue(profile, 'TOPO_STEEP', '" + aTopoSteepness.getString( i ) + "', " + i + ")\n";
-                fos.write( text.getBytes() );
-            }
-        }
-
-        // Presently we do not support multiple soils
-        fos.write( "    # SET SOIL LAYER\n".getBytes() );
-        if ( aSoils.length() > 0 ) {
-            text = "    RomeFileSetAttrSize(profile, 'SOIL_LAYER', " + aSoils.length() + ")\n";
-            fos.write( text.getBytes() );
-            text = "    RomeFileSetAttrValue(profile, 'SOIL_HORIZ', '" + length + "', 0)\n";
-            fos.write( text.getBytes() );
-            text = "    RomeFileSetAttrValue(profile, 'SOIL_PTR', '" + StringEscapeUtils.escapeJava( soilPtr[0] ) + "', " + 0 + ")\n";
-            fos.write( text.getBytes() );
-        }
-
-        // Must be after set soils or the soils code resets it...sometimes
-        if ( JSONUtils.checkKeyExistsB( param, KEY_SIMPLE_ROCK_COVER ) ) {
-            text = "    RomeFileSetAttrValue(profile, 'SIMPLE_ROCK_COVER', '" + simpleRockCoverPercent + "' ,0)\n";
-            fos.write( text.getBytes() );
-        }
-
-        fos.write( "    # SET MAN LAYER\n".getBytes() );
-        if ( aManIdx.length() > 0 ) {
-            text = "    RomeFileSetAttrSize(profile, 'MAN_LAYER', " + aManIdx.length() + ")\n";
-            fos.write( text.getBytes() );
-            for ( int i = 0; i < aManIdx.length(); i++ ) {
-                text = "    RomeFileSetAttrValue(profile, 'MAN_HORIZ', '" + aManLength.getString( i ) + "', " + i + ")\n";
-                fos.write( text.getBytes() );
-                LOG.info( "escapeJava test=" + StringEscapeUtils.escapeJava( "simple / test" ) );
-                LOG.info( "escapeJava test=" + StringEscapeUtils.escapeJavaScript( "simple / test" ) );
-                LOG.info( "\n\n\n********************--- escapeJava man name=" + StringEscapeUtils.escapeJava( managementFormalName[aManIdx.getInt( i )] ) );
-                LOG.info( "********************--- escapeJavaScript man name=" + StringEscapeUtils.escapeJavaScript( managementFormalName[aManIdx.getInt( i )] ) );
-                LOG.info( "********************--- escapeHtml man name=" + StringEscapeUtils.escapeHtml( managementFormalName[aManIdx.getInt( i )] ) );
-                LOG.info( "********************--- escapeSql man name=" + StringEscapeUtils.escapeSql( managementFormalName[aManIdx.getInt( i )] ) );
-                LOG.info( "********************--- escapeXml man name=" + StringEscapeUtils.escapeXml( managementFormalName[aManIdx.getInt( i )] ) );
-                LOG.info( "********************--- raw Value is=" + managementFormalName[aManIdx.getInt( i )] );
-                //text = "    RomeFileSetAttrValue(profile, 'MAN_PTR', '" + managementFormalName[aManIdx.getInt(i)] + "', " + i + ")\n";
-                text = "    RomeFileSetAttrValue(profile, 'MAN_PTR', '" + R2Run.escapeJavaNoFwdSlash( managementFormalName[aManIdx.getInt( i )] ) + "', " + i + ")\n";
-                fos.write( text.getBytes() );
-            }
-        } else {
-            // IF no max_idx array provided, defaulting to single mgmt
-            text = "    RomeFileSetAttrSize(profile, 'MAN_LAYER', 1)\n";
-            fos.write( text.getBytes() );
-            text = "    RomeFileSetAttrValue(profile, 'MAN_HORIZ', '" + length + "', 0)\n";
-            fos.write( text.getBytes() );
-            LOG.info( "escapeJava test=" + StringEscapeUtils.escapeJava( "simple / test" ) );
-            LOG.info( "escapeJava test=" + StringEscapeUtils.escapeJavaScript( "simple / test" ) );
-            LOG.info( "\n\n\n********************--- escapeJava man name=" + StringEscapeUtils.escapeJava( managementFormalName[0] ) );
-            LOG.info( "********************--- escapeJavaScript man name=" + StringEscapeUtils.escapeJavaScript( managementFormalName[0] ) );
-            LOG.info( "********************--- escapeHtml man name=" + StringEscapeUtils.escapeHtml( managementFormalName[0] ) );
-            LOG.info( "********************--- escapeSql man name=" + StringEscapeUtils.escapeSql( managementFormalName[0] ) );
-            LOG.info( "********************--- escapeXml man name=" + StringEscapeUtils.escapeXml( managementFormalName[0] ) );
-            LOG.info( "********************--- raw Value is=" + managementFormalName[0] );
-            text = "    RomeFileSetAttrValue(profile, 'MAN_PTR', '" + R2Run.escapeJavaNoFwdSlash( managementFormalName[0] ) + "', 0)\n";
-            fos.write( text.getBytes() );
-        }
-
-        // This segment implementation is currently commented out in favor of populating the
-        // individual topo, soil, and man layers above for now...
-//        if (aTopoLength.length() > 1) {
-//
-//            text = "    RomeFileSetAttrSize(profile, 'SEGMENT', " + aTopoLength.length() + ")\n";
-//            fos.write(text.getBytes());
-//            text = "    RomeFileSetAttrValue(profile, 'SOIL_LAYER', '#INSERT', 1)\n";
-//            fos.write(text.getBytes());
-//
-//            for (int i = 0; i < aSoilIdx.length(); i++) {
-//                text = "    print('LOAD SOIL WITH SOIL IDX=%s' % " + aSoilIdx.getInt(i) + ", " + i + ")\n";
-//                fos.write(text.getBytes());
-//                text = "    RomeFileSetAttrValue(profile, 'SOIL_PTR', '" + StringEscapeUtils.escapeJava(soilPtr[aSoilIdx.getInt(i)]) + ".xml', " + i + ")\n";
-//                fos.write(text.getBytes());
-//            }
-//            for (int i = 0; i < aManIdx.length(); i++) {
-//                text = "    RomeFileSetAttrValue(profile, 'MAN_PTR', '" + StringEscapeUtils.escapeJava(managementFormalName[aManIdx.getInt(i)]) + "', " + i + ")\n";
-//                fos.write(text.getBytes());
-//            }
-//            for (int i = 0; i < aTopoLength.length(); i++) {
-//                text = "    RomeFileSetAttrValue(profile, 'SEG_HORIZ', lengths[" + i + "], " + i + ")\n";
-//                fos.write(text.getBytes());
-//                text = "    RomeFileSetAttrValue(profile, 'SEG_STEEP', slopes[" + i + "], " + i + ")\n";
-//                fos.write(text.getBytes());
-//                text = "    RomeFileSetAttrValue(profile, 'SEG_MAN_LAYER', str(manIndex[" + i + "]), " + i + ")\n";
-//                fos.write(text.getBytes());
-//                text = "    print('SEG_MAN_LAYER=%s' % str(manIndex[" + i + "]), " + i + ")\n";
-//                fos.write(text.getBytes());
-//                text = "    RomeFileSetAttrValue(profile, 'SEG_SOIL_LAYER', str(soilIndex[" + i + "]), " + i + ")\n";
-//                fos.write(text.getBytes());
-//                text = "    print('SEG_SOIL_LAYER=%s' % str(soilIndex[" + i + "]), " + i + ")\n";
-//                fos.write(text.getBytes());
-//
-////                if ((diversions != null) && (diversions.length() > 0)) {
-////                    text = "    RomeFileSetAttrValue(profile, 'HYD_ELEM_SYSTEM_PTR', 'hydraulic-element-systems\\\\aaa" + aDiversionIdx.getInt(i) + "', " + i + ")\n";
-////                    fos.write(text.getBytes());
-////                }
-////                if ((stripBarrrierSystems != null) && (stripBarrrierSystems.length() > 0)) {
-////                    text = "    RomeFileSetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', 'strip-barrier-systems\\\\aaa" + aStripBarrierIdx.getInt(i) + "', " + i + ")\n";
-////                    fos.write(text.getBytes());
-////                }
-////                if ((contoursytems != null) && (contoursytems.length() > 0)) {
-////                    text = "    RomeFileSetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', 'contour-systems\\\\aaa" + aContourIdx.getInt(i) + "', " + i + ")\n";
-////                    fos.write(text.getBytes());
-//                }
-//            }
-//
-//        } else {
-//            text = "    RomeFileSetAttrValue(profile, 'SOIL_PTR', '" + StringEscapeUtils.escapeJava(soilPtr[0]) + ".xml', " + 0 + ")\n";
-//            fos.write(text.getBytes());
-//            text = "    RomeFileSetAttrValue(profile, 'MAN_PTR', '" + StringEscapeUtils.escapeJava(managementFormalName[0]) + "', " + 0 + ")\n";
-//            fos.write(text.getBytes());
-//        }
-        //fos.write("    # Set SOIL_PTR\n".getBytes());
-        //text = "    RomeFileSetAttrValue(profile, 'SOIL_PTR', '" + StringEscapeUtils.escapeJava(soilPtr[0]) + ".xml',0)\n";
-        //fos.write(text.getBytes());
-        fos.write( "    print('SOIL_PTR=%s' % RomeFileGetAttrValue(profile, 'SOIL_PTR', 0))\n".getBytes() );
-
-//        fos.write("    # Set MAN_PTR\n".getBytes());
-//        text = "    RomeFileSetAttrValue(profile, 'MAN_PTR', '" + StringEscapeUtils.escapeJava(managementFormalName[0]) + "',0)\n";
-//        fos.write(text.getBytes());
-//        fos.write("    print('MAN_PTR=%s' % RomeFileGetAttrValue(profile, 'MAN_PTR', 0))\n".getBytes());
-        if ( ( contourSystem != null ) && ( contourSystem.length() > 1 ) ) {
-            // Contour Systems can simply point to the nginx XML file - no need to prefetch because of no special
-            // characters in the file name
-            text = "    RomeFileSetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', '" + StringEscapeUtils.escapeJava( contourSystem ) + "', 0)\n";
-            fos.write( text.getBytes() );
-        }
-
-        // To prevent issues with pyrome converting special chars in filenames to invalid chars for web server retrieval,
-        // we prefetch the file, insert a dummy name, and point to it here
-        if ( ( stripBarrierSystem != null ) && ( stripBarrierSystem.length() > 1 ) ) {
-            // for some reason, must reset SLOPE_HORIZ & SLOPE_STEEP immediately before setting a strip and barrier !!! R2 BUG
-            // This is required for the internal Rusle2 wizard to calculate proper slope segment lengths
-//            text = "    RomeFileSetAttrValue(profile, 'SLOPE_HORIZ', '" + length + "', 0)\n";
-//            fos.write(text.getBytes());
-//            text = "    RomeFileSetAttrValue(profile, 'SLOPE_STEEP', '" + steepness + "', 0)\n";
-//            fos.write(text.getBytes());
-
-            fos.write( "    stripbarr = RomeFilesOpen(files, '#XML:stripbarr_file0.xml',0)\n".getBytes() );
-            text = "    RomeFileSetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', 'strip-barrier-systems\\\\aaa', 0)\n";
-            fos.write( text.getBytes() );
-        }
-
-        // Runs with a Hydraulic Element System, use a hydraulic element flow path
-        if ( ( hydElemSystem != null ) && ( hydElemSystem.length() > 1 ) ) {
-            // Load the hyd elem flow path into the workspace
-            fos.write( "    hydelem = RomeFilesOpen(files, '#XML:hydelemflowpath_file.xml',0)\n".getBytes() );
-//            String r2db = Config.getString("r2.db", "http://oms-db.engr.colostate.edu/r2");
-//            String hydelemHttpPtr = r2db + "/" + hydElemSystem.replace("\\", "/") + ".xml";
-            int numFlowPaths = r2run.determineNumberOfFlowPaths( hydElemSystem );
-            text = "    RomeFileSetAttrSize(profile, 'NUM_FLOW_PATHS', " + numFlowPaths + ")\n";
-            fos.write( text.getBytes() );
-            double offsets[] = r2run.determineFlowPathDistribution( hydElemSystem );
-            for ( int i = 0; i < numFlowPaths; i++ ) {
-                text = "    RomeFileSetAttrValue(profile, 'FLOW_PATH_HORIZ', '" + length * offsets[i] + "', " + i + ")\n";
-                fos.write( text.getBytes() );
-                if ( i < ( numFlowPaths - 1 ) ) {
-                    text = "    RomeFileSetAttrValue(profile, 'HYD_ELEM_FLOW_PATH_PTR', 'hydraulic-element-flow-paths\\hydelemflowpath1', " + i + ")\n";
-                    fos.write( text.getBytes() );
-                } else {
-                    // last flow path is always the default
-                    text = "    RomeFileSetAttrValue(profile, 'HYD_ELEM_FLOW_PATH_PTR', 'hydraulic-element-flow-paths\\default', " + i + ")\n";
-                    fos.write( text.getBytes() );
-                }
-            }
-        }
-
-//        if ((contourSystem != null) && (contourSystem.length() > 1)) {
-//            text = "    RomeFileSetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', '" + contourSystem + "',0)\n";
-//            fos.write(text.getBytes());
-//        }
-        fos.write( "    RomeFileSave(profile)\n".getBytes() );
-        fos.write( "    RomeEngineRun(engine)\n".getBytes() );
-//        fos.write("    results.append(RomeFileGetAttrValue(profile, 'SLOPE_SOIL_LOSS', 0))\n".getBytes());
-//        fos.write("    results.append(RomeFileGetAttrValue(profile, 'SLOPE_DELIVERY', 0))\n".getBytes());
-//        fos.write("    results.append(RomeFileGetAttrValue(profile, 'SLOPE_DEGRAD', 0))\n".getBytes());
-
-        // Request specific outputs from Rusle2
-        for ( String r : JSONUtils.getRequestedResults( metainfo ) ) {
-            text = "    paramsize = RomeFileGetAttrSize(profile,'" + r + "')\n";
-            fos.write( text.getBytes() );
-            text = "    if paramsize > 1:\n";
-            fos.write( text.getBytes() );
-            text = "        text = '['\n";
-            fos.write( text.getBytes() );
-            text = "        for x in range (paramsize):\n";
-            fos.write( text.getBytes() );
-            text = "            text += RomeFileGetAttrValue(profile,'" + r + "',x)\n";
-            fos.write( text.getBytes() );
-            text = "            if x < (paramsize-1):\n";
-            fos.write( text.getBytes() );
-            text = "                text += ', '\n";
-            fos.write( text.getBytes() );
-            text = "        text += ']'\n";
-            fos.write( text.getBytes() );
-            text = "    else:\n";
-            fos.write( text.getBytes() );
-            text = "        text = RomeFileGetAttrValue(profile, '" + r + "', 0)\n";
-            fos.write( text.getBytes() );
-            text = "    results.append(RomeFileGetAttrValue(profile, '" + r + "', 0))\n";
-            fos.write( text.getBytes() );
-            text = "    print('" + r + "=%s' % text)\n";
-            fos.write( text.getBytes() );
-        }
-
-        // Request output for segments (seg 0 for non segmented runs)
-        fos.write( "    numflowpaths = RomeFileGetAttrSize(profile, 'NUM_FLOW_PATHS')\n".getBytes() );
-        fos.write( "    print('------------------------------------------------------------------------------')\n".getBytes() );
-        fos.write( "    print('NUMBER OF FLOWPATHS=%d' % numflowpaths)\n".getBytes() );
-        fos.write( "    for xx in range (numflowpaths):\n".getBytes() );
-        fos.write( "        print('FLOW_PATH_HORIZ:%d=%s' % (xx, RomeFileGetAttrValue(profile, 'FLOW_PATH_HORIZ', xx)))\n".getBytes() );
-        fos.write( "        print('HYD_ELEM_FLOW_PATH_PTR:%d=%s' % (xx, RomeFileGetAttrValue(profile, 'HYD_ELEM_FLOW_PATH_PTR', xx)))\n".getBytes() );
-        fos.write( "    numsegs = RomeFileGetAttrSize(profile, 'SEGMENT')\n".getBytes() );
-        fos.write( "    print('NUMBER OF SEGMENTS=%d' % numsegs)\n".getBytes() );
-        fos.write( "    for x in range (numsegs):\n".getBytes() );
-        fos.write( "        print('------------------------------------------------------------------------------')\n".getBytes() );
-        fos.write( "        print('SEGMENT:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SEGMENT', x)))\n".getBytes() );
-        fos.write( "        print('SEG_HORIZ:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SEG_HORIZ', x)))\n".getBytes() );
-        fos.write( "        print('SEG_STEEP:%d=%s' % (x,RomeFileGetAttrValue(profile, 'SEG_STEEP', x)))\n".getBytes() );
-        fos.write( "        print('SEG_MAN:%d=%s' % (x, RomeFileGetAttrValue(profile, 'MAN_PTR', x)))\n".getBytes() );
-        fos.write( "        print('SEG_SOIL:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SOIL_PTR', x)))\n".getBytes() );
-        fos.write( "        results.append(RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', x))\n".getBytes() );
-        fos.write( "        print('SEG_SOIL_LOSS:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', x)))\n".getBytes() );
-        fos.write( "        print('SEG_SOIL_LAYER %d=%s' % (x, RomeFileGetAttrValue(profile, 'SEG_SOIL_LAYER', x)))\n".getBytes() );
-        fos.write( "        print('SEG_MAN_LAYER %d=%s' % (x, RomeFileGetAttrValue(profile, 'SEG_MAN_LAYER', x)))\n".getBytes() );
-        fos.write( "        print('HYD_ELEM_SYS:%d=%s' % (x, RomeFileGetAttrValue(profile, 'HYD_ELEM_SYSTEM_PTR', x)))\n".getBytes() );
-        fos.write( "        print('STRIP_BARRIER_SYS:%d=%s' % (x, RomeFileGetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', x)))\n".getBytes() );
-        fos.write( "        print('CONTOUR_SYS:%d=%s' % (x, RomeFileGetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', x)))\n".getBytes() );
-        fos.write( "    print('------------------------------------------------------------------------------')\n".getBytes() );
-
-        fos.write( "    numsegs = RomeFileGetAttrSize(profile, 'SOIL_LAYER')\n".getBytes() );
-        fos.write( "    print('NUMBER OF SOIL SEGMENTS=%d' % numsegs)\n".getBytes() );
-        fos.write( "    for x in range (numsegs):\n".getBytes() );
-        fos.write( "        print('------------------------------------------------------------------------------')\n".getBytes() );
-        fos.write( "        print('SOIL_SEGMENT:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SOIL_LAYER', x)))\n".getBytes() );
-        fos.write( "        print('SOIL_HORIZ:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SOIL_HORIZ', x)))\n".getBytes() );
-        fos.write( "        print('SOIL_PTR:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SOIL_PTR', x)))\n".getBytes() );
-        fos.write( "    print('------------------------------------------------------------------------------')\n".getBytes() );
-
-        fos.write( "    numsegs = RomeFileGetAttrSize(profile, 'MAN_LAYER')\n".getBytes() );
-        fos.write( "    print('NUMBER OF MAN SEGMENTS=%d' % numsegs)\n".getBytes() );
-        fos.write( "    for x in range (numsegs):\n".getBytes() );
-        fos.write( "        print('------------------------------------------------------------------------------')\n".getBytes() );
-        fos.write( "        print('MAN_SEGMENT:%d=%s' % (x, RomeFileGetAttrValue(profile, 'MAN_LAYER', x)))\n".getBytes() );
-        fos.write( "        print('MAN_HORIZ:%d=%s' % (x, RomeFileGetAttrValue(profile, 'MAN_HORIZ', x)))\n".getBytes() );
-        fos.write( "        print('MAN_PTR:%d=%s' % (x, RomeFileGetAttrValue(profile, 'MAN_PTR', x)))\n".getBytes() );
-        fos.write( "    print('------------------------------------------------------------------------------')\n".getBytes() );
-
-        fos.write( "    numsegs = RomeFileGetAttrSize(profile, 'TOPO_LAYER')\n".getBytes() );
-        fos.write( "    print('NUMBER OF TOPO SEGMENTS=%d' % numsegs)\n".getBytes() );
-        fos.write( "    for x in range (numsegs):\n".getBytes() );
-        fos.write( "        print('------------------------------------------------------------------------------')\n".getBytes() );
-        fos.write( "        print('TOPO_SEGMENT:%d=%s' % (x, RomeFileGetAttrValue(profile, 'TOPO_LAYER', x)))\n".getBytes() );
-        fos.write( "        print('TOPO_HORIZ:%d=%s' % (x, RomeFileGetAttrValue(profile, 'TOPO_HORIZ', x)))\n".getBytes() );
-        fos.write( "        print('TOPO_HORIZ_COMPOSITE:%d=%s' % (x, RomeFileGetAttrValue(profile, 'TOPO_HORIZ_COMPOSITE', x)))\n".getBytes() );
-        fos.write( "        print('TOPO_STEEP:%d=%s' % (x, RomeFileGetAttrValue(profile, 'TOPO_STEEP', x)))\n".getBytes() );
-        fos.write( "        print('TOPO_STEEP_COMPOSITE:%d=%s' % (x, RomeFileGetAttrValue(profile, 'TOPO_STEEP_COMPOSITE', x)))\n".getBytes() );
-        fos.write( "    print('------------------------------------------------------------------------------')\n".getBytes() );
-
-//        // request erosion by segment, if a segmented run
-//        if (aTopoLength.length() > 1) {
-//            for (int i = 0; i < aTopoLength.length(); i++) {
-//                text = "    results.append(RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', " + i + "))\n";
-//                fos.write(text.getBytes());
-//                text = "    print('SEG_SOIL_LOSS:" + i + "=%s' % (RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', " + i + ")))\n";
-//                fos.write(text.getBytes());
-////                text = "    results.append(float(RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', " + i + ")))\n";
-////                fos.write(text.getBytes());
-////                text = "    print('seg man layer %i =%s' % (" +i + " , RomeFileGetAttrValue(profile, 'SEG_MAN_LAYER', " + i + ")))\n";
-////                fos.write(text.getBytes());
-////                text = "    print('seg soil layer %i =%s' % (" + i + " , RomeFileGetAttrValue(profile, 'SEG_SOIL_LAYER', " + i + ")))\n";
-////                fos.write(text.getBytes());
-////                text = "    print('seg soil loss %i =%s' % (" + i + " , RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', " + i + ")))\n";
-////                fos.write(text.getBytes());
-////                text = "    print('slope soil loss %i =%s' % (" + i + " , RomeFileGetAttrValue(profile, 'SLOPE_SOIL_LOSS', " + i + ")))\n";
-////                fos.write(text.getBytes());
-////                text = "    results.append(RomeFileGetAttrValue(profile, 'SLOPE_SOIL_LOSS', " + i + "))\n";
-////                fos.write(text.getBytes());
-//                text = "    print('SEG_SOIL:" + i + "=%s' % RomeFileGetAttrValue(profile, 'SOIL_PTR', " + i + "))\n";
-//                fos.write(text.getBytes());
-//                text = "    print('SEG_MAN:" + i + "=%s' % RomeFileGetAttrValue(profile, 'MAN_PTR', " + i + "))\n";
-//                fos.write(text.getBytes());
-//                text = "    print('SEG_SOIL_LAYER " + i + "=%s' % (RomeFileGetAttrValue(profile, 'SEG_SOIL_LAYER', " + i + ")))\n";
-//                fos.write(text.getBytes());
-//                text = "    print('SEG_MAN_LAYER " + i + "=%s' % (RomeFileGetAttrValue(profile, 'SEG_MAN_LAYER', " + i + ")))\n";
-//                fos.write(text.getBytes());
-//                text = "    print('HYD_ELEM_SYS:" + i + "=%s' % (RomeFileGetAttrValue(profile, 'HYD_ELEM_SYSTEM_PTR', " + i + ")))\n";
-//                fos.write(text.getBytes());
-//                text = "    print('STRIP_BARRIER_SYS:" + i + "=%s' % (RomeFileGetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', " + i + ")))\n";
-//                fos.write(text.getBytes());
-//                text = "    print('CONTOUR_SYS:" + i + "=%s' % (RomeFileGetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', " + i + ")))\n";
-//                fos.write(text.getBytes());
-//            }
-//        } else {
-//            // always return soil and man ptrs at index 0 - requested by Lucas for IET
-//            text = "    print('SEG_SOIL:0" + "=%s' % RomeFileGetAttrValue(profile, 'SOIL_PTR', " + 0 + "))\n";
-//            fos.write(text.getBytes());
-//            text = "    print('SEG_MAN:0" + "=%s' % RomeFileGetAttrValue(profile, 'MAN_PTR', " + 0 + "))\n";
-//            fos.write(text.getBytes());
-//            //
-//        }
-//        fos.write("    print('SLOPE_DELIVERY=%s' % RomeFileGetAttrValue(profile, 'SLOPE_DELIVERY', 0))\n".getBytes());
-//        fos.write("    print('SLOPE_T_VALUE=%s' % RomeFileGetAttrValue(profile, 'SLOPE_T_VALUE', 0))\n".getBytes());
-//        fos.write("    print('SLOPE_DEGRAD=%s' % RomeFileGetAttrValue(profile, 'SLOPE_DEGRAD', 0))\n".getBytes());
-        text = "    exec(open(\"" + REPORT_PY_FILENAME + "\").read())\n";
-        fos.write( text.getBytes() );
-        fos.write( "    RomeFileClose(profile)\n".getBytes() );
-        fos.write( "    return results\n".getBytes() );
-
-        fos.write( "if __name__ == \"__main__\":\n".getBytes() );
-        fos.write( "    #inputs\n".getBytes() );
-        fos.write( "    save = False\n".getBytes() );
-        fos.write( "    #Run simulation\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());
-
-        // Specify the nginx server
-        String r2db = Config.getString( "r2.db", "http://oms-db.engr.colostate.edu/r2" );
-        if ( altR2db == null ) {
-            text = "    RomeDatabaseOpen(database,'" + r2db + "')\n";
-            fos.write( text.getBytes() );
-        } else {
-            String altr2db = r2db.substring( 0, r2db.lastIndexOf( "/" ) ) + "/model-data/" + altR2db;
-            text = "    RomeDatabaseOpen(database,'" + altr2db + "')\n";
-            fos.write( text.getBytes() );
-        }
-        fos.write( "    results = linearTest(save)\n".getBytes() );
-        fos.write( "    RomeDatabaseClose(database)\n".getBytes() );
-        fos.write( "    RomeExit(romeDLL)\n".getBytes() );
-
-//        for (int i = 0; i < contoursytems.length(); i++) {
-//            String contourSys = contoursytems.getString(i);
-//            String contourHttpPtr = r2db + "/" + contourSys.replace("\\", "/") + ".xml";
-//            r2run.prepareFile(contourHttpPtr, new File(getWorkspaceDir(), "contour_file" + i + ".xml"), "contour", "contour-systems", Integer.toString(i));
-//        }
-//        for (int i = 0; i < stripBarrrierSystems.length(); i++) {
-//            String stripBarrierSys = stripBarrrierSystems.getString(i);
-//            String stripbarrHttpPtr = r2db + "/" + stripBarrierSys.replace("\\", "/") + ".xml";
-//            r2run.prepareFile(stripbarrHttpPtr, new File(getWorkspaceDir(), "stripbarr_file" + i + ".xml"), "strip-barrier", "strip-barrier-systems", Integer.toString(i));
-//        }
-//        for (int i = 0; i < diversions.length(); i++) {
-//            String hydElemSys = diversions.getString(i);
-//            String hydelemHttpPtr = r2db + "/" + hydElemSys.replace("\\", "/") + ".xml";
-//            r2run.prepareFile(hydelemHttpPtr, new File(getWorkspaceDir(), "hydelem_file" + i + ".xml"), "hydraulic-element", "hydraulic-element-systems", Integer.toString(i));
-//        }
-        // prepare individual contour system, strip barrier system, hyd elem sys, if not provided in an array
-        if ( JSONUtils.checkKeyExistsB( param, KEY_CONTOUR_SYSTEM_PTR ) ) {
-            String contourHttpPtr = r2db + "/" + contourSystem.replace( "\\", "/" ) + ".xml";
-            r2run.prepareFileJ( contourHttpPtr, new File( getWorkspaceDir(), "contour_file0.xml" ), "", "contour-systems", "", true );
-        }
-        if ( JSONUtils.checkKeyExistsB( param, KEY_STRIP_BARRIER_SYSTEM_PTR ) ) {
-            String stripbarrHttpPtr = r2db + "/" + stripBarrierSystem.replace( "\\", "/" ) + ".xml";
-            r2run.prepareFileJ( stripbarrHttpPtr, new File( getWorkspaceDir(), "stripbarr_file0.xml" ), "", "strip-barrier-systems", "", true );
-        }
-        if ( JSONUtils.checkKeyExistsB( param, KEY_HYD_ELEM_SYSTEM_PTR ) ) {
-            String hydelemHttpPtr = r2db + "/" + hydElemSystem.replace( "\\", "/" ) + ".xml";
-            r2run.prepareHydraulicElementFlowPathJ( hydelemHttpPtr, r2db, new File( getWorkspaceDir(), "hydelemflowpath_file.xml" ) );
-            //r2run.prepareFileJ(hydelemHttpPtr, new File(getWorkspaceDir(), "hydelemflowpath_file.xml"), climate, text, r2db);
-        }
-
-        // prepare climate file
-        //r2run.prepareClimateFileJ(cliHttpPtr, new File(getWorkspaceDir(), "cli_file0.xml"));
-        r2run.prepareFileJ( climatePtr, new File( getWorkspaceDir(), "cli_file0.xml" ), "CLIMATE", "climates", "", true );
-        //r2run.prepareClimateFile(cliHttpPtr, new File(getWorkspaceDir(), "cli_file0.xml"));
-
-        // to do
-        // implement rusle 2 report in pyrome
-        // Rusle2 report
-        //fos.write("READ \"rusle2_report.rsh\"\n".getBytes());
-        fos.close();
-
-        // 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( resources().getFile( REPORT_PY_FILENAME ), getWorkspaceDir() );
-
-        climate = climatePtr;
-        soil = soilPtr[0];
-        mgmt = managementFormalName[0];
-
-        LOG.info( "R2 script: " + file.toString() );
+    int a = vals[0];
+    for (int i = 0; i < vals.length; i++) {
+      if (vals[i] != a) {
+        return false;
+      }
     }
-
-    private String[] getSoilFiles ( JSONArray cokeys ) throws JSONException, Exception {
-        String soilPtr[] = new String[( cokeys.length() )];
-        JSONObject soilsRequest = new JSONObject();
-        JSONObject meta = new JSONObject();
-        JSONArray paramObj = new JSONArray();
-        JSONObject cokeyObj = new JSONObject();
-        String cokey;
-        JSONObject responseMeta;
-        JSONArray resultArr;
-        JSONObject soilObj;
-        String soilFilePath;
-
-        soilsRequest.put( KEY_METAINFO, meta );
-        soilsRequest.put( KEY_PARAMETER, paramObj );
-        paramObj.put( cokeyObj );
-
-        for ( int i = 0; i < cokeys.length(); i++ ) {
-            cokey = cokeys.getString( i );
-            paramObj.put( 0, cokeyObj );
-            cokeyObj.put( KEY_NAME, KEY_COKEY );
-            cokeyObj.put( KEY_VALUE, cokey );
-            LOG.info( "SOILS Request: " + soilsRequest.toString() );
-            JSONObject soilsResponse = new Client().doPOST( Config.getString( "r2.soils", "http://csip.engr.colostate.edu:8092/csip-soils/d/soilsXML/1.0" ), soilsRequest );
-            LOG.info( "SOILS Response: " + soilsResponse.toString() );
-            responseMeta = soilsResponse.getJSONObject( KEY_METAINFO );
-            if ( !responseMeta.getString( KEY_STATUS ).equalsIgnoreCase( "Failed" ) ) {
-                resultArr = soilsResponse.getJSONArray( KEY_RESULT );
-                soilObj = resultArr.getJSONObject( 0 );
-                soilFilePath = soilObj.getString( KEY_VALUE );
-
-                new Client().doGET( soilFilePath, getWorkspaceFile( "soils_file" + i + ".xml" ) );
-
-                soilPtr[i] = getSoilFilePath( getWorkspaceFile( "soils_file" + i + ".xml" ) ).replace( "/", "\\" );
-                LOG.info( "THE SOIL IS =" + soilPtr[i] + "\n\n\n\n" );
-
-            } else {
-                String error = responseMeta.getString( ERROR );
-                throw new ServiceException( "Soil service error: " + error );
-            }
-        }
-        return soilPtr;
-    }
-
-    private String getSoilFilePath ( File soilFile ) throws ParserConfigurationException, SAXException, IOException {
-        String path = "";
-        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
-        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
-
-        Document document = documentBuilder.parse( soilFile );
-
-        path = document.getElementsByTagName( "Filename" ).item( 0 ).getTextContent();
-
-        return path;
-    }
-
-    private String getClimateFilePath ( double lat, double lon ) throws JSONException, Exception {
-        JSONObject climateReq = new JSONObject();
-        JSONObject meta = new JSONObject();
-        JSONArray param = new JSONArray();
-        JSONObject jlat = new JSONObject();
-        JSONObject jlong = new JSONObject();
-        JSONArray resultArr;
-        JSONObject responseMeta;
-        JSONObject cliObj;
-        String climatePath = "";
-
-        climateReq.put( KEY_METAINFO, meta );
-        climateReq.put( KEY_PARAMETER, param );
-
-        param.put( jlat );
-        param.put( jlong );
-
-        jlat.put( KEY_NAME, KEY_LATITUDE );
-        jlat.put( KEY_VALUE, lat );
-
-        jlong.put( KEY_NAME, KEY_LONGITUDE );
-        jlong.put( KEY_VALUE, lon );
-
-        LOG.info( "CLIMATE Request: " + climateReq.toString() );
-        JSONObject climateResponse = new Client().doPOST( Config.getString( "r2.climate", "http://csip.engr.colostate.edu:8092/csip-misc/d/r2climate/2.0" ), climateReq );
-        LOG.info( "CLIMATE Response: " + climateResponse.toString() );
-        responseMeta = climateResponse.getJSONObject( KEY_METAINFO );
-        if ( !responseMeta.getString( KEY_STATUS ).equalsIgnoreCase( "Failed" ) ) {
-            resultArr = climateResponse.getJSONArray( KEY_RESULT );
-            cliObj = JSONUtils.preprocess( resultArr ).get( KEY_CLIMATE_URL );
-            climatePath = cliObj.getString( KEY_VALUE );
-        }
-
-        return climatePath;
-    }
-
-    private String getFilenumber ( String filename ) {
-        return filename.substring( R2_TMP_FILENAME.length(), filename.length() - R2_TMP_FILEEXT.length() );
-    }
-
-    @Override
-    protected void doReport () throws Exception {
-//        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 = resources().getFile( REPORT_JSON_TEMPLATE_FILENAME );
-
-        String sReportJSON = FileUtils.readFileToString( reportTemplate );
-        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);
-            System.out.println( "------------------------------------------------------------------------PROCESSING ELEMENT:" );
-            System.out.println( "VAR NAME:" + itemName );
-            System.out.println( "-------------------------------------------------------------------------------------------" );
-
-            //String value = r2run.getResultPyrome(itemName);
-            String value = r2run.getResult( "\"" + itemName + "\"" );
-            LOG.info( "the value='" + value + "'" );
-            if ( ( value != null ) && ( value.equals( "null" ) ) ) {
-                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 {
-                        report().put( itemName, new JSONArray( value ), desc, units );
-                    }
-                    catch ( JSONException je ) {
-                        processReportElement( itemName, dimension, units, desc, type, value );
-                    }
-                } else {
-                    processReportElement( itemName, dimension, units, desc, type, value );
-                }
-
-            }
-            if ( dimension != null ) {
-                report().putMetaInfo( itemName, REPORT_DIM, new JSONArray( dimension ) );
-            }
-        }
-    }
-
-    private void prepareHydraulicFlowElementFile () {
-        // Given a Hydraulic Element Pointer, parse the XML and return a Hydraulic Flow Element
-    }
-
-    // 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 {
-        System.out.println( "------------------------------------------------------------------------PROCESSING ELEMENT:\n\n" );
-        System.out.println( "TYPE:" + type );
-        System.out.println( "VALUE:" + value );
-        System.out.println( "-------------------------------------------------------------------------------------------\n\n" );
-
-        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;
-            report().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 );
-            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 = removeFirstLastChar( value );
-                System.out.println( "VALUE:" + value );
-                report().put( itemName, Double.parseDouble( value ), desc, units );
-            }
-            if ( value.equals( "\"\"" ) ) {
-                report().put( itemName, new Double( 0 ), desc, units );
-            }
-        }
-        if ( type.equals( "" ) ) {
-            report().put( itemName, value, desc, units );
-        }
-    }
-
-    private boolean allEqual ( int... vals ) {
-        if ( vals.length < 2 ) {
-            return true;
-        }
-        int a = vals[0];
-        for ( int i = 0; i < vals.length; i++ ) {
-            if ( vals[i] != a ) {
-                return false;
-            }
-        }
-        return true;
-    }
+    return true;
+  }
 }

src/java/m/rusle2/V4_0.java

@@ -5,10 +5,10 @@
  */
 package m.rusle2;
 
-import csip.Client;
+import csip.utils.Client;
 import csip.Config;
-import csip.Executable;
-import csip.ServiceException;
+import csip.api.server.Executable;
+import csip.api.server.ServiceException;
 import csip.annotations.Description;
 import csip.annotations.Name;
 import csip.annotations.Resource;
@@ -18,6 +18,7 @@
 import csip.annotations.State;
 import static csip.annotations.State.DEVELOPMENT;
 import csip.annotations.VersionInfo;
+import csip.api.server.PayloadMetaInfo;
 import csip.utils.JSONUtils;
 import database.ServiceResources;
 import static database.ServiceResources.LMOD_ID;
@@ -25,6 +26,7 @@
 import java.io.IOException;
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.logging.Level;
@@ -84,51 +86,55 @@
   private double ann_erosion;
 
 
+  public static void checkValidResultRequest(PayloadMetaInfo metainfo, Collection<String> results) throws ServiceException {
+    String[] j = metainfo.getStringArray(KEY_REQUEST_RESULTS);
+    for (int i = 0; i < j.length; i++) {
+      String name = j[i];
+      if (!results.contains(name)) {
+        throw new ServiceException("unknown result request :" + name);
+      }
+    }
+  }
+
+
   @Override
   protected void preProcess() throws Exception {
-    // check for requested output.
     r2run.setLogger(LOG);
     try {
-      LOG.info("\n\n\n\n\nMETAINFO:");
-      LOG.info("\n" + getMetainfo().toString());
-      LOG.info("\n\n\n");
-      JSONUtils.checkValidResultRequest(getMetainfo(), potResults);
+      reqResults = metainfo().getStringArray(KEY_REQUEST_RESULTS);
+      LOG.info("\n" + metainfo().toString());
+      checkValidResultRequest(metainfo(), potResults);
     } catch (ServiceException se) {
       LOG.severe("\n\n\nERROR!!!\n\n\n" + se.toString());
       LOG.warning("No Rusle2 return parameters requested! Will use defaults: SLOPE_DELIVERY, SLOPE_T_VALUE, SLOPE_DEGRAD");
-      List<String> params = new LinkedList<String>();
+
+      List<String> params = new LinkedList<>();
       params.add(RES_SLOPE_DELIVERY);
       params.add(RES_SLOPE_T_VALUE);
       params.add(RES_SLOPE_DEGRAD);
 
       // check if these are being set
-      if (JSONUtils.checkKeyExistsB(getParamMap(), KEY_CONTOUR_SYSTEM_PTR)) {
+      if (parameter().has(KEY_CONTOUR_SYSTEM_PTR)) {
         params.add("CONTOUR_SYSTEM_PTR");
       }
-
-      if (JSONUtils.checkKeyExistsB(getParamMap(), KEY_STRIP_BARRIER_SYSTEM_PTR)) {
+      if (parameter().has(KEY_STRIP_BARRIER_SYSTEM_PTR)) {
         params.add("STRIP_BARRIER_SYSTEM_PTR");
       }
-
-      if (JSONUtils.checkKeyExistsB(getParamMap(), 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);
+      reqResults = params.toArray(new String[0]);
     }
+    parameter().require(KEY_SOILS, KEY_LENGTH, KEY_STEEPNESS, KEY_MGMTS);
 
-    JSONUtils.checkKeyExists(getParamMap(), KEY_SOILS);
-    JSONUtils.checkKeyExists(getParamMap(), KEY_LENGTH);
-    JSONUtils.checkKeyExists(getParamMap(), KEY_STEEPNESS);
-    JSONUtils.checkKeyExists(getParamMap(), KEY_MGMTS);
+    File r2script = new File(workspace().getDir(), R2_TMP_FILENAME + R2_TMP_FILEEXT);
 
-    File r2script = new File(getWorkspaceDir(), R2_TMP_FILENAME + R2_TMP_FILEEXT);
-    createInputFile(r2script, getMetainfo(), getParamMap());
+    createInputFile(r2script, getParamMap());
     gatherAnnData();
   }
 
 
-  protected void gatherAnnData() throws ServiceException, JSONException, SQLException, org.json.JSONException, Exception {
-    org.json.JSONObject managementCopy;
+  protected void gatherAnnData() throws Exception {
 
     // get management data
     if (managements.length() > 1) {
@@ -136,7 +142,7 @@
     }
 
     try (Connection connection = resources().getJDBC(LMOD_ID)) {
-      managementCopy = new org.json.JSONObject(managements.getJSONObject(0).toString());
+      org.json.JSONObject managementCopy = new org.json.JSONObject(managements.getJSONObject(0).toString());
       man = new Management(connection, managementCopy);
     }
 
@@ -146,7 +152,6 @@
     if (!(contourSystem.equals("") || contourSystem.equals("(none)"))) {
       contour = 1;
     }
-
     getR_factor();
   }
 
@@ -156,21 +161,17 @@
     MapUnit mUnit;
 
     cokey = cokeys.getString(0);
-
     comp = new Component();
     comp.cokey(cokey);
     mUnit = getSoilMapUnit();
-
   }
 
 
   private MapUnit getSoilMapUnit() throws ServiceException, SQLException, Exception {
     MapUnit mapUnit = new MapUnit(comp);
-
     try (SOILS_DATA soilsDb = SOILS_DB_Factory.createEngine(getClass(), LOG, Config.getString("soils.gis.database.source"))) {
       soilsDb.findHorizonsForCokey(mapUnit, comp);
     }
-
     comp.slopelenusle_r(verifyValue(comp.slopelenusle_l(), comp.slopelenusle_r(), comp.slopelenusle_h()));
     comp.slope_r(verifyValue(comp.slope_l(), comp.slope_r(), comp.slope_h()));
     return mapUnit;
@@ -202,7 +203,7 @@
 
     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     DocumentBuilder builder = factory.newDocumentBuilder();
-    Document doc = builder.parse(new File(getWorkspaceDir(), "cli_file0.xml"));
+    Document doc = builder.parse(new File(workspace().getDir(), "cli_file0.xml"));
     NodeList floatNodes = doc.getElementsByTagName("Flt");
 
     // go through all the flt nodes to find the specific r_factor node
@@ -230,7 +231,7 @@
     try {
       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);
+      int result = r2run.executePyrome(new File(workspace().getDir(), R2_TMP_FILENAME + R2_TMP_FILEEXT), python);
       callAnn();
     } catch (Exception e) {
       LOG.log(Level.SEVERE, "ERROR EXECUTING PYTHON-RUSLE2", e);
@@ -334,7 +335,6 @@
     } else {
       String error = responseMeta.getString(ERROR);
       metainfo().appendWarning(error);
-      //throw new ServiceException("Ann service error: " + error);
     }
   }
 
@@ -370,8 +370,7 @@
       }
     }
 
-//      results.put(JSONUtils.data(KEY_SLOPE_DELIVERY, 3.0));
-    for (String r : JSONUtils.getRequestedResults(getMetainfo())) {
+    for (String r : reqResults) {
       if ((errors > 0) && (r.equals(RES_SLOPE_DEGRAD))) {
         results().put(r, r2run.getResultPyrome(r), R2_MISSING_XML_FILES_WARNING_MSG);
       } else {
@@ -403,7 +402,6 @@
       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)));
     }
-
     results().put(KEY_ANN_EROSION, ann_erosion);
   }
 }

src/java/m/rusle2/V5_0.java

@@ -11,43 +11,13 @@
  */
 package m.rusle2;
 
-import csip.Client;
-import csip.Config;
-import csip.Executable;
-import csip.ServiceException;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.util.*;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringEscapeUtils;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONObject;
-import org.codehaus.jettison.json.JSONException;
-import org.w3c.dom.Document;
-import org.w3c.dom.NodeList;
-import csip.ModelDataService;
-import static csip.ModelDataService.KEY_REQUEST_RESULTS;
-import static csip.ModelDataService.REPORT_DIM;
-import static csip.ModelDataService.REPORT_NAME;
-import static csip.ModelDataService.REPORT_TYPE;
-import static csip.ModelDataService.VALUE;
 import csip.annotations.*;
 import static csip.annotations.ResourceType.ARCHIVE;
 import static csip.annotations.ResourceType.FILE;
 import static csip.annotations.ResourceType.REFERENCE;
 import static csip.annotations.State.RELEASED;
-import static util.Constants.*;
-
-import csip.utils.JSONUtils;
-import csip.utils.Services;
-import java.io.IOException;
-import java.util.logging.Level;
 import javax.ws.rs.Path;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import static m.rusle2.V3_0.*;
-import org.xml.sax.SAXException;
 
 @Name("Rusle2")
 @Description("IET / pyrome version of RomeDLL 2.6.11.1; references NRCS Soil Data Mart")
@@ -69,6 +39,6 @@
  *
  * @author <a href="mailto:shaun.case@colostate.edu">Shaun Case</a>
  */
-public class V5_0 extends V3_0{
-    
+public class V5_0 extends V3_0 {
+
 }

web/WEB-INF/csip-defaults.json

@@ -1,5 +1,5 @@
 { 
-    "csip-r2.version": "$version: 2.11.8.11 default 81 24eb0cf5c794 2019-11-12 od, built at 2021-05-10 10:42 by Lucas$",
+    "csip-r2.version": "$version: 2.11.8.12 default 82 994360fe4d17 2021-05-10 lyaege, built at 2022-01-05 17:58 by od$",
     "lmod.db": "jdbc:sqlserver:\/\/129.82.20.242:1433;databaseName=lmod_temp;user=lmod-rw;password=?",
     "sdmONLINE":"true",
     "csip.session.ttl": "PT1M",