Displaying differences for changeset
 
display as  

src/java/m/wqm/nuttechscores/Input.java

@@ -1,9 +1,9 @@
-
 package m.wqm.nuttechscores;
 
 /**
  *
  * @author Kontham Srinivas Reddy
+ * @update Rumpal Sidhu
  */
 public class Input {
 
@@ -11,13 +11,14 @@
     int plan_techn_id;
     String plan_techn_discrim_type;
     String plan_techn_discrim;
-    public Input(int AoAid,int plan_techn_id,String plan_techn_discrim_type,String plan_techn_discrim)
-    {
-        this.AoAid=AoAid;
-        this.plan_techn_id=plan_techn_id;
-        this.plan_techn_discrim_type=plan_techn_discrim_type;
-        this.plan_techn_discrim=plan_techn_discrim;
-        
+
+    public Input(int AoAid, int plan_techn_id, String plan_techn_discrim_type,
+            String plan_techn_discrim) {
+        this.AoAid = AoAid;
+        this.plan_techn_id = plan_techn_id;
+        this.plan_techn_discrim_type = plan_techn_discrim_type;
+        this.plan_techn_discrim = plan_techn_discrim;
+
     }
-    
+
 }

src/java/m/wqm/nuttechscores/Result1.java

@@ -3,37 +3,42 @@
 /**
  *
  * @author Srinivas Reddy Kontham
+ * @ Update Rumpal Sidhu
  */
+public class Result1 {
 
-public class Result1 
-{
-            int nleach_techn_score=0;
-            int nleach_avoid_techn_score=0;
-            int nleach_control_techn_score=0;
-            int nleach_trap_techn_score=0;
-            int nsurf_techn_score=0;
-            int nsurf_avoid_techn_score=0;
-            int nsurf_control_techn_score=0;
-            int nsurf_trap_techn_score=0;
-            int psurf_techn_score=0;
-            int psurf_avoid_techn_score=0;
-            int psurf_control_techn_score=0;
-            int psurf_trap_techn_score=0;
-            int AoAid;
-    public Result1(int AoAid,int nleach_techn_score,int nsurf_techn_score,int psurf_techn_score,int nleach_avoid_techn_score,int nleach_control_techn_score,int nleach_trap_techn_score,int nsurf_avoid_techn_score,int nsurf_control_techn_score,int nsurf_trap_techn_score,int psurf_avoid_techn_score,int psurf_control_techn_score,int psurf_trap_techn_score)
-    {
-         this.nleach_techn_score=nleach_techn_score;
-         this.nleach_avoid_techn_score=nleach_avoid_techn_score;
-         this.nleach_control_techn_score=nleach_control_techn_score;
-         this.nleach_trap_techn_score=nleach_trap_techn_score;
-         this.nsurf_techn_score=nsurf_techn_score;
-         this.nsurf_avoid_techn_score=nsurf_avoid_techn_score;
-         this.nsurf_control_techn_score=nsurf_control_techn_score;
-         this.nsurf_trap_techn_score=nsurf_trap_techn_score;
-         this.psurf_techn_score=psurf_techn_score;
-         this.psurf_avoid_techn_score=psurf_avoid_techn_score;
-         this.psurf_control_techn_score=psurf_control_techn_score;
-         this.psurf_trap_techn_score=psurf_trap_techn_score;
-         this.AoAid=AoAid;
+    int nleach_techn_score = 0;
+    int nleach_avoid_techn_score = 0;
+    int nleach_control_techn_score = 0;
+    int nleach_trap_techn_score = 0;
+    int nsurf_techn_score = 0;
+    int nsurf_avoid_techn_score = 0;
+    int nsurf_control_techn_score = 0;
+    int nsurf_trap_techn_score = 0;
+    int psurf_techn_score = 0;
+    int psurf_avoid_techn_score = 0;
+    int psurf_control_techn_score = 0;
+    int psurf_trap_techn_score = 0;
+    int AoAid;
+
+    public Result1(int AoAid, int nleach_techn_score, int nsurf_techn_score, 
+            int psurf_techn_score, int nleach_avoid_techn_score, 
+            int nleach_control_techn_score, int nleach_trap_techn_score, 
+            int nsurf_avoid_techn_score, int nsurf_control_techn_score, 
+            int nsurf_trap_techn_score, int psurf_avoid_techn_score, 
+            int psurf_control_techn_score, int psurf_trap_techn_score) {
+        this.nleach_techn_score = nleach_techn_score;
+        this.nleach_avoid_techn_score = nleach_avoid_techn_score;
+        this.nleach_control_techn_score = nleach_control_techn_score;
+        this.nleach_trap_techn_score = nleach_trap_techn_score;
+        this.nsurf_techn_score = nsurf_techn_score;
+        this.nsurf_avoid_techn_score = nsurf_avoid_techn_score;
+        this.nsurf_control_techn_score = nsurf_control_techn_score;
+        this.nsurf_trap_techn_score = nsurf_trap_techn_score;
+        this.psurf_techn_score = psurf_techn_score;
+        this.psurf_avoid_techn_score = psurf_avoid_techn_score;
+        this.psurf_control_techn_score = psurf_control_techn_score;
+        this.psurf_trap_techn_score = psurf_trap_techn_score;
+        this.AoAid = AoAid;
     }
 }

src/java/m/wqm/nuttechscores/V1_0.java

@@ -1,9 +1,9 @@
-
 package m.wqm.nuttechscores;
 
 /**
  *
  * @author SrinivasReddy kontham
+ * @ update Rumpal Sidhu
  */
 import csip.ModelDataService;
 import static csip.ModelDataService.EXEC_OK;
@@ -18,185 +18,218 @@
 import java.sql.*;
 import java.util.concurrent.*;
 
-@Name("(NutTechScores)")
+@Name("WQM-14:(NutTechScores)")
 @Description("Nutrient Technique Scores")
 @Path("m/nut_tech_scores/1.0")
 
-public class V1_0 extends ModelDataService
-{
-    ArrayList<Input> components=new ArrayList<>(); // store the set of all input soilcomponents as objects
-    ArrayList<Result1> result1=new ArrayList<>();  // store the result as objects
-            int nleach_techn_score=0;
-            int nleach_avoid_techn_score=0;
-            int nleach_control_techn_score=0;
-            int nleach_trap_techn_score=0;
-            int nsurf_techn_score=0;
-            int nsurf_avoid_techn_score=0;
-            int nsurf_control_techn_score=0;
-            int nsurf_trap_techn_score=0;
-            int psurf_techn_score=0;
-            int psurf_avoid_techn_score=0;
-            int psurf_control_techn_score=0;
-            int psurf_trap_techn_score=0;
-            int AoAid;
+public class V1_0 extends ModelDataService {
+
+    //SQL params names here for quick modification
+    private final String USER = "postgres";
+    private final String PASS = "admin";
+    private final String HOST = "localhost";
+    private final String PORT = "5432";
+    private final String DBNAME = "postgres";
+    private final String JDBC_TYPE = "jdbc:postgresql://";
+    private final String CONNECTION = JDBC_TYPE + HOST + ":" + PORT + "/" + DBNAME;
+    private final String CLASS_NAME = "org.postgresql.Driver";
+
+    private ArrayList<Input> components; // store the set of all input soilcomponents as objects
+    private ArrayList<Result1> result1;  // store the result as objects
+    private int aoaId;
+
     @Override
-        // reading the inputs from the json file into input object and placing it in the arraylist
-        protected void preProcess() throws Exception {
+    // reading the inputs from the json file into input object and placing it in the arraylist
+    protected void preProcess() throws Exception {
+        components = new ArrayList<>();
         JSONArray groups = getJSONArrayParam("pestcomponents");
-            for(int i=0;i<groups.length();i++)
-            {
-                Map<String, JSONObject> group = JSONUtils.preprocess(groups.getJSONArray(i));
+        for (int i = 0; i < groups.length(); i++) {
+            Map<String, JSONObject> group = JSONUtils.preprocess(groups.getJSONArray(i));
+            aoaId = JSONUtils.getIntParam(group, "AoAid", 0);
+            int plan_techn_id = JSONUtils.getIntParam(group, "plan_techn_id", 0);
+            String plan_techn_discrim_type = JSONUtils.getStringParam(group, "plan_techn_discrim_type", "err");
+            String plan_techn_discrim = JSONUtils.getStringParam(group, "plan_techn_discrim", "err");
+            Input input = new Input(aoaId, plan_techn_id, plan_techn_discrim_type, plan_techn_discrim);
+            components.add(input);
+        }
+    }
 
-                
-                AoAid = JSONUtils.getIntParam(group, "AoAid", 0);
-                int  plan_techn_id=JSONUtils.getIntParam(group,"plan_techn_id",0);
-                String plan_techn_discrim_type=JSONUtils.getStringParam(group,"plan_techn_discrim_type","err");
-                String plan_techn_discrim=JSONUtils.getStringParam(group,"plan_techn_discrim","err");
-                Input input=new Input(AoAid,plan_techn_id,plan_techn_discrim_type,plan_techn_discrim);
-                components.add(input);
+    @Override
+    protected String process() throws Exception {
+        result1 = new ArrayList<>();
+        Connection conn = null;
+        Statement statement = null;
+        try {
+            Class.forName(CLASS_NAME);
+            conn = DriverManager.getConnection(CONNECTION, USER, PASS);
+            conn.setAutoCommit(false);
+            statement = conn.createStatement();
+
+            int nleach_techn_score = 0;
+            int nleach_avoid_techn_score = 0;
+            int nleach_control_techn_score = 0;
+            int nleach_trap_techn_score = 0;
+            int nsurf_techn_score = 0;
+            int nsurf_avoid_techn_score = 0;
+            int nsurf_control_techn_score = 0;
+            int nsurf_trap_techn_score = 0;
+            int psurf_techn_score = 0;
+            int psurf_avoid_techn_score = 0;
+            int psurf_control_techn_score = 0;
+            int psurf_trap_techn_score = 0;
+
+            for (Input ip : components) {
+                String query = "SELECT nut_tech_score FROM wqm_nutrient_technique_scores "
+                        + "WHERE nutrient_technique_id = " + ip.plan_techn_id
+                        + " AND wqm_concern ='Nitrogen in Ground Water';";
+                ResultSet resultset = statement.executeQuery(query);
+                while (resultset.next()) {
+                    int techn_score = resultset.getInt("nut_tech_score");
+                    nleach_techn_score += techn_score;
+                }
+
+                query = "SELECT nut_tech_score FROM wqm_nutrient_technique_scores "
+                        + "WHERE nutrient_technique_id= " + ip.plan_techn_id
+                        + " AND wqm_concern = 'Nitrogen in Ground Water' AND mode_of_action = 'Avoid';";
+                resultset = statement.executeQuery(query);
+                while (resultset.next()) {
+                    int avoid_techn_score = resultset.getInt("nut_tech_score");
+                    nleach_avoid_techn_score += avoid_techn_score;
+                }
+
+                query = "SELECT nut_tech_score FROM wqm_nutrient_technique_scores "
+                        + "WHERE nutrient_technique_id = " + ip.plan_techn_id
+                        + " AND wqm_concern = 'Nitrogen in Ground Water' AND mode_of_action = 'Control';";
+                resultset = statement.executeQuery(query);
+                while (resultset.next()) {
+                    int control_techn_score = resultset.getInt("nut_tech_score");
+                    nleach_control_techn_score += control_techn_score;
+                }
+
+                query = "SELECT nut_tech_score FROM wqm_nutrient_technique_scores "
+                        + "WHERE nutrient_technique_id = " + ip.plan_techn_id
+                        + " AND wqm_concern = 'Nitrogen in Ground Water' AND mode_of_action = 'Trap';";
+                resultset = statement.executeQuery(query);
+                while (resultset.next()) {
+                    int trap_techn_score = resultset.getInt("nut_tech_score");
+                    nleach_trap_techn_score += trap_techn_score;
+                }
+
+                //  #Compute nutrient technique mitigation scores for Nitrogen in Surface Water concern and increment total scores           
+                query = "SELECT nut_tech_score FROM wqm_nutrient_technique_scores "
+                        + "WHERE nutrient_technique_id = " + ip.plan_techn_id
+                        + " AND wqm_concern = 'Nitrogen in Surface Water';";
+                resultset = statement.executeQuery(query);
+                while (resultset.next()) {
+                    int techn_score = resultset.getInt("nut_tech_score");
+                    nsurf_techn_score += techn_score;
+                }
+
+                query = "SELECT nut_tech_score FROM wqm_nutrient_technique_scores "
+                        + "WHERE nutrient_technique_id = " + ip.plan_techn_id
+                        + " AND wqm_concern = 'Nitrogen in Surface Water' AND mode_of_action = 'Avoid';";
+                resultset = statement.executeQuery(query);
+                while (resultset.next()) {
+                    int avoid_techn_score = resultset.getInt("nut_tech_score");
+                    nsurf_avoid_techn_score += avoid_techn_score;
+                }
+
+                query = "SELECT nut_tech_score FROM wqm_nutrient_technique_scores "
+                        + "WHERE nutrient_technique_id = " + ip.plan_techn_id
+                        + " AND wqm_concern = 'Nitrogen in Surface Water' AND mode_of_action = 'Control';";
+                resultset = statement.executeQuery(query);
+                while (resultset.next()) {
+                    int control_techn_score = resultset.getInt("nut_tech_score");
+                    nsurf_control_techn_score += control_techn_score;
+                }
+
+                query = "SELECT nut_tech_score FROM wqm_nutrient_technique_scores "
+                        + "WHERE nutrient_technique_id = " + ip.plan_techn_id
+                        + " AND wqm_concern = 'Nitrogen in Surface Water' AND mode_of_action = 'Trap';";
+                resultset = statement.executeQuery(query);
+                while (resultset.next()) {
+                    int trap_techn_score = resultset.getInt("nut_tech_score");
+                    nsurf_trap_techn_score += trap_techn_score;
+                }
+
+                //#Compute nutrient technique mitigation scores for Phosphorus in Surface Water concern and increment total scores            
+                query = "SELECT nut_tech_score FROM wqm_nutrient_technique_scores "
+                        + "WHERE nutrient_technique_id = " + ip.plan_techn_id
+                        + " AND wqm_concern = 'Phosphorous in Surface Water'"
+                        + " AND tech_discrim_type ='" + ip.plan_techn_discrim_type
+                        + "' AND tech_discrim = '" + ip.plan_techn_discrim + "';";
+                resultset = statement.executeQuery(query);
+                while (resultset.next()) {
+                    int techn_score = resultset.getInt("nut_tech_score");
+                    psurf_techn_score += techn_score;
+                }
+
+                query = "SELECT nut_tech_score FROM wqm_nutrient_technique_scores "
+                        + "WHERE nutrient_technique_id = " + ip.plan_techn_id
+                        + " AND wqm_concern = 'Phosphorus in Surface Water' AND mode_of_action = 'Avoid';";
+                resultset = statement.executeQuery(query);
+                while (resultset.next()) {
+                    int avoid_techn_score = resultset.getInt("nut_tech_score");
+                    psurf_avoid_techn_score += avoid_techn_score;
+                }
+
+                query = "SELECT nut_tech_score FROM wqm_nutrient_technique_scores "
+                        + "WHERE nutrient_technique_id = " + ip.plan_techn_id
+                        + "AND wqm_concern = 'Phosphorus in Surface Water' AND mode_of_action = 'Control';";
+                resultset = statement.executeQuery(query);
+                while (resultset.next()) {
+                    int control_techn_score = resultset.getInt("nut_tech_score");
+                    psurf_control_techn_score += control_techn_score;
+                }
+
+                query = "SELECT nut_tech_score FROM wqm_nutrient_technique_scores "
+                        + "WHERE nutrient_technique_id = " + ip.plan_techn_id
+                        + " AND wqm_concern = 'Phosphorus in Surface Water' AND mode_of_action = 'Trap';";
+                resultset = statement.executeQuery(query);
+                while (resultset.next()) {
+                    int trap_techn_score = resultset.getInt("nut_tech_score");
+                    psurf_trap_techn_score += trap_techn_score;
+                }
+            }
+            Result1 result = new Result1(aoaId, nleach_techn_score, nsurf_techn_score, psurf_techn_score, nleach_avoid_techn_score, nleach_control_techn_score, nleach_trap_techn_score, nsurf_avoid_techn_score, nsurf_control_techn_score, nsurf_trap_techn_score, psurf_avoid_techn_score, psurf_control_techn_score, psurf_trap_techn_score);
+            result1.add(result);
+
+        } catch (SQLException se) {
+            LOG.info("Did not open database for WQM-4!");
+            LOG.info(se.getMessage());
+        } finally {
+            if (statement != null) {
+                statement.close();
+            }
+            if (conn != null) {
+                conn.close();
             }
         }
-        @Override
-        protected String process() throws Exception
-        {
-            Connection conn = null;
-            Statement statement = null;
-            Class.forName("org.postgresql.Driver");
-            conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", "postgres", "admin");
-            conn.setAutoCommit(false);
-            statement = conn.createStatement();
-            
-            for(Input ip:components)
-            {
-                String query="SELECT nut_tech_score FROM wqm_nutrient_technique_scores WHERE nutrient_technique_id="+ip.plan_techn_id+"AND wqm_concern="+"'"+"Nitrogen in Ground Water"+"'";
-                ResultSet results = statement.executeQuery(query);
-        //        #Compute nutrient technique mitigation scores for Nitrogen in Ground Water concern and increment total scores
-                while (results.next())
-                {
-                   int techn_score=results.getInt("nut_tech_score");
-                   nleach_techn_score=nleach_techn_score+techn_score;
-                }
-                query="SELECT nut_tech_score FROM wqm_nutrient_technique_scores WHERE nutrient_technique_id="+ip.plan_techn_id+"AND wqm_concern="+"'"+"Nitrogen in Ground Water"+"' AND mode_of_action='"+"Avoid"+"'";
-                results = statement.executeQuery(query);
-                
-                while (results.next())
-                {
-                   int avoid_techn_score=results.getInt("nut_tech_score");
-                   nleach_avoid_techn_score=nleach_avoid_techn_score+avoid_techn_score;
-                }
-                query="SELECT nut_tech_score FROM wqm_nutrient_technique_scores WHERE nutrient_technique_id="+ip.plan_techn_id+"AND wqm_concern="+"'"+"Nitrogen in Ground Water"+"' AND mode_of_action='"+"Control"+"'";
-                results = statement.executeQuery(query);
-                
-                while (results.next())
-                {
-                   int control_techn_score=results.getInt("nut_tech_score");
-                   nleach_control_techn_score=nleach_avoid_techn_score+control_techn_score;
-                }
-                query="SELECT nut_tech_score FROM wqm_nutrient_technique_scores WHERE nutrient_technique_id="+ip.plan_techn_id+"AND wqm_concern="+"'"+"Nitrogen in Ground Water"+"' AND mode_of_action='"+"Trap"+"'";
-                results = statement.executeQuery(query);
-                
-                while (results.next())
-                {
-                   int trap_techn_score=results.getInt("nut_tech_score");
-                   nleach_trap_techn_score=nleach_avoid_techn_score+trap_techn_score;
-                }
-                
-    //  #Compute nutrient technique mitigation scores for Nitrogen in Surface Water concern and increment total scores           
-                query="SELECT nut_tech_score FROM wqm_nutrient_technique_scores WHERE nutrient_technique_id="+ip.plan_techn_id+"AND wqm_concern="+"'"+"Nitrogen in Surface Water"+"'";
-                results = statement.executeQuery(query);
-                while (results.next())
-                {
-                   int techn_score=results.getInt("nut_tech_score");
-                   nsurf_techn_score=nsurf_techn_score+techn_score;
-                }
-                query="SELECT nut_tech_score FROM wqm_nutrient_technique_scores WHERE nutrient_technique_id="+ip.plan_techn_id+"AND wqm_concern="+"'"+"Nitrogen in Surface Water"+"' AND mode_of_action='"+"Avoid"+"'";
-                results = statement.executeQuery(query);
-                
-                while (results.next())
-                {
-                   int avoid_techn_score=results.getInt("nut_tech_score");
-                   nsurf_avoid_techn_score=nsurf_avoid_techn_score+avoid_techn_score;
-                }
-                query="SELECT nut_tech_score FROM wqm_nutrient_technique_scores WHERE nutrient_technique_id="+ip.plan_techn_id+"AND wqm_concern="+"'"+"Nitrogen in Surface Water"+"' AND mode_of_action='"+"Control"+"'";
-                results = statement.executeQuery(query);
-                
-                while (results.next())
-                {
-                   int control_techn_score=results.getInt("nut_tech_score");
-                   nsurf_control_techn_score=nsurf_avoid_techn_score+control_techn_score;
-                }
-                query="SELECT nut_tech_score FROM wqm_nutrient_technique_scores WHERE nutrient_technique_id="+ip.plan_techn_id+"AND wqm_concern="+"'"+"Nitrogen in Surface Water"+"' AND mode_of_action='"+"Trap"+"'";
-                results = statement.executeQuery(query);
-                
-                while (results.next())
-                {
-                   int trap_techn_score=results.getInt("nut_tech_score");
-                   nsurf_trap_techn_score=nsurf_avoid_techn_score+trap_techn_score;
-                }
-    //#Compute nutrient technique mitigation scores for Phosphorus in Surface Water concern and increment total scores            
-                 query="SELECT nut_tech_score FROM wqm_nutrient_technique_scores WHERE nutrient_technique_id="+ip.plan_techn_id+"AND wqm_concern="+"'"+"Phosphorous in Surface Water"+"' AND tech_discrim_type='"+ip.plan_techn_discrim_type+"' AND tech_discrim='"+ip.plan_techn_discrim+"'";
-                results = statement.executeQuery(query);
-                while (results.next())
-                {
-                   int techn_score=results.getInt("nut_tech_score");
-                   psurf_techn_score=psurf_techn_score+techn_score;
-                }
-                query="SELECT nut_tech_score FROM wqm_nutrient_technique_scores WHERE nutrient_technique_id="+ip.plan_techn_id+"AND wqm_concern="+"'"+"Phosphorus in Surface Water"+"' AND mode_of_action='"+"Avoid"+"'";
-                results = statement.executeQuery(query);
-                
-                while (results.next())
-                {
-                   int avoid_techn_score=results.getInt("nut_tech_score");
-                   psurf_avoid_techn_score=psurf_avoid_techn_score+avoid_techn_score;
-                }
-                query="SELECT nut_tech_score FROM wqm_nutrient_technique_scores WHERE nutrient_technique_id="+ip.plan_techn_id+"AND wqm_concern="+"'"+"Phosphorus in Surface Water"+"' AND mode_of_action='"+"Control"+"'";
-                results = statement.executeQuery(query);
-                
-                while (results.next())
-                {
-                   int control_techn_score=results.getInt("nut_tech_score");
-                   psurf_control_techn_score=psurf_avoid_techn_score+control_techn_score;
-                }
-                query="SELECT nut_tech_score FROM wqm_nutrient_technique_scores WHERE nutrient_technique_id="+ip.plan_techn_id+"AND wqm_concern="+"'"+"Phosphorus in Surface Water"+"' AND mode_of_action='"+"Trap"+"'";
-                results = statement.executeQuery(query);
-                
-                while (results.next())
-                {
-                   int trap_techn_score=results.getInt("nut_tech_score");
-                   psurf_trap_techn_score=psurf_avoid_techn_score+trap_techn_score;
-                }
-                        
-            }
-            Result1 result=new Result1(AoAid,nleach_techn_score,nsurf_techn_score,psurf_techn_score,nleach_avoid_techn_score,nleach_control_techn_score,nleach_trap_techn_score,nsurf_avoid_techn_score,nsurf_control_techn_score,nsurf_trap_techn_score,psurf_avoid_techn_score,psurf_control_techn_score,psurf_trap_techn_score);
-            result1.add(result);
-            return EXEC_OK;
+        return EXEC_OK;
+    }
+
+    @Override
+    //writing the results back to JSON
+    protected void postProcess() throws Exception {
+        JSONArray result1Arr = new JSONArray();
+        for (Result1 rs1 : result1) {
+            JSONArray tmpArr = new JSONArray();
+            tmpArr.put(JSONUtils.dataDesc("AoAId", rs1.AoAid, "Area of Analysis Identifier"));
+            tmpArr.put(JSONUtils.dataDesc("nleach_techn_score", rs1.nleach_techn_score, "nutrient management technique mitigation score for nitrogen in ground water concern"));
+            tmpArr.put(JSONUtils.dataDesc("nsurf_techn_score", rs1.nsurf_techn_score, "nutrient management technique mitigation score for nitrogen in surface water concern"));
+            tmpArr.put(JSONUtils.dataDesc("psurf_techn_score", rs1.psurf_techn_score, "nutrient management technique mitigation score for phosphorus in surface water concern"));
+            tmpArr.put(JSONUtils.dataDesc("nleach_avoid_techn_score", rs1.nleach_avoid_techn_score, "integer, nutrient management technique mitigation score for avoiding excess nitrogen use or application and loss to groundwater"));
+            tmpArr.put(JSONUtils.dataDesc("nleach_control_techn_score", rs1.nleach_control_techn_score, "nutrient management technique mitigation score for controlling in-field nitrogen losses to groundwater"));
+            tmpArr.put(JSONUtils.dataDesc("nleach_trap_techn_score", rs1.nleach_trap_techn_score, "nutrient management technique mitigation score for trapping excess nitrogen and keeping it from groundwater"));
+            tmpArr.put(JSONUtils.dataDesc("nsurf_avoid_techn_score", rs1.nsurf_avoid_techn_score, "nutrient management technique mitigation score for avoiding excess nitrogen use or application and loss to surface water"));
+            tmpArr.put(JSONUtils.dataDesc("nsurf_control_techn_score", rs1.nsurf_control_techn_score, "nutrient management technique mitigation score for controlling in-field nitrogen losses to surface water runoff"));
+            tmpArr.put(JSONUtils.dataDesc("nsurf_trap_techn_score", rs1.nsurf_trap_techn_score, "nutrient management technique mitigation score for trapping excess nitrogen and keeping it from surface water"));
+            tmpArr.put(JSONUtils.dataDesc("psurf_avoid_techn_score", rs1.psurf_avoid_techn_score, "nutrient management technique mitigation score for avoiding excess phosphorus use or application and loss to surface water"));
+            tmpArr.put(JSONUtils.dataDesc("psurf_control_techn_score", rs1.psurf_control_techn_score, "nutrient management technique mitigation score for controlling in-field phosphorus losses to surface water runoff"));
+            tmpArr.put(JSONUtils.dataDesc("psurf_trap_techn_score", rs1.psurf_trap_techn_score, "nutrient management technique mitigation score for trapping excess phophorus and keeping it from surface water"));
+            result1Arr.put(JSONUtils.dataDesc("Nutrient Technique Scores", tmpArr, "AoANutScores"));
         }
-         @Override
-        //writing the results back to JSON
-    protected void postProcess() throws Exception 
-    {
-                JSONArray result1Arr = new JSONArray();
-                 for(Result1 rs1:result1)
-                {
-                    JSONArray tmpArr = new JSONArray();
-                    tmpArr.put(JSONUtils.dataDesc("AoAId", AoAid, "Area of Analysis Identifier"));
-                    tmpArr.put(JSONUtils.dataDesc("nleach_techn_score", rs1.nleach_techn_score, "nutrient management technique mitigation score for nitrogen in ground water concern"));
-                    tmpArr.put(JSONUtils.dataDesc("nsurf_techn_score", rs1.nsurf_techn_score, "nutrient management technique mitigation score for nitrogen in surface water concern"));
-                    tmpArr.put(JSONUtils.dataDesc("psurf_techn_score", rs1.psurf_techn_score, "nutrient management technique mitigation score for phosphorus in surface water concern"));
-                    tmpArr.put(JSONUtils.dataDesc("nleach_avoid_techn_score", rs1.nleach_avoid_techn_score, "integer, nutrient management technique mitigation score for avoiding excess nitrogen use or application and loss to groundwater"));
-                    tmpArr.put(JSONUtils.dataDesc("nleach_control_techn_score", rs1.nleach_control_techn_score, "nutrient management technique mitigation score for controlling in-field nitrogen losses to groundwater"));
-                    tmpArr.put(JSONUtils.dataDesc("nleach_trap_techn_score", rs1.nleach_trap_techn_score, "nutrient management technique mitigation score for trapping excess nitrogen and keeping it from groundwater"));
-                    tmpArr.put(JSONUtils.dataDesc("nsurf_avoid_techn_score", rs1.nsurf_avoid_techn_score, "nutrient management technique mitigation score for avoiding excess nitrogen use or application and loss to surface water"));
-                    tmpArr.put(JSONUtils.dataDesc("nsurf_control_techn_score", rs1.nsurf_control_techn_score, "nutrient management technique mitigation score for controlling in-field nitrogen losses to surface water runoff"));
-                    tmpArr.put(JSONUtils.dataDesc("nsurf_trap_techn_score", rs1.nsurf_trap_techn_score, "nutrient management technique mitigation score for trapping excess nitrogen and keeping it from surface water"));
-                    tmpArr.put(JSONUtils.dataDesc("psurf_avoid_techn_score", rs1.psurf_avoid_techn_score, "nutrient management technique mitigation score for avoiding excess phosphorus use or application and loss to surface water"));
-                    tmpArr.put(JSONUtils.dataDesc("psurf_control_techn_score", rs1.psurf_control_techn_score, "nutrient management technique mitigation score for controlling in-field phosphorus losses to surface water runoff"));
-                    tmpArr.put(JSONUtils.dataDesc("psurf_trap_techn_score", rs1.psurf_trap_techn_score, "nutrient management technique mitigation score for trapping excess phophorus and keeping it from surface water"));
-                    result1Arr.put(JSONUtils.dataDesc("Nutrient Technique Scores", tmpArr, "AoANutScores"));
-                }
-                
-                putResult("operation", result1Arr);    
+        putResult("operation", result1Arr);
     }
-    
 
 }

src/java/m/wqm/nuttechscores/V1_0.json

@@ -1,151 +1,143 @@
 {
- "metainfo": {
- },
- "parameter": [
-  {
-   "name": "pestcomponents",
-   "value": [
-    [
-     {
-      "name": "AoAid",
-      "value": 1,
-      "Description":"Area of Analysis Identifier"
-      
-     },
-     {
-      "name": "plan_techn_id",
-      "value": 1,
-      "Description":"nutrient management technique identifier corresponding to nutrient_technique_score_id value in WQM data mart"
-     },
-     {
-      "name": "plan_techn_discrim_type",
-      "value": "",
-      "Description":"type of discriminator for varying nutrient management technique scores; value is “soil test result” otherwise NULL"
-     },
-     {
-      "name": "plan_techn_discrim",
-      "value": "",
-      "Description":"value of the discriminator:  HIGH,MEDIUM, LOW, NO SOIL TEST"
-     }
-     
-    ],
-    
-    [
-    {
-      "name": "AoAid",
-      "value": 1,
-      "Description":"Area of Analysis Identifier"
-      
-     },
-     {
-      "name": "plan_techn_id",
-      "value": 5,
-      "Description":"nutrient management technique identifier corresponding to nutrient_technique_score_id value in WQM data mart"
-     },
-     {
-      "name": "plan_techn_discrim_type",
-      "value": "",
-      "Description":"type of discriminator for varying nutrient management technique scores; value is “soil test result” otherwise NULL"
-     },
-     {
-      "name": "plan_techn_discrim",
-      "value": "",
-      "Description":"value of the discriminator:  HIGH,MEDIUM, LOW, NO SOIL TEST"
-     }
-    ],
-    [
+    "metainfo": {
+    },
+    "parameter": [
         {
-      "name": "AoAid",
-      "value": 1,
-      "Description":"Area of Analysis Identifier"
-      
-     },
-     {
-      "name": "plan_techn_id",
-      "value": 8,
-      "Description":"nutrient management technique identifier corresponding to nutrient_technique_score_id value in WQM data mart"
-     },
-     {
-      "name": "plan_techn_discrim_type",
-      "value": "Soil test result",
-      "Description":"type of discriminator for varying nutrient management technique scores; value is “soil test result” otherwise NULL"
-     },
-     {
-      "name": "plan_techn_discrim",
-      "value": "Medium",
-      "Description":"value of the discriminator:  HIGH,MEDIUM, LOW, NO SOIL TEST"
-     }
-    ],
-    [
-        {
-      "name": "AoAid",
-      "value": 1,
-      "Description":"Area of Analysis Identifier"
-      
-     },
-     {
-      "name": "plan_techn_id",
-      "value": 14,
-      "Description":"nutrient management technique identifier corresponding to nutrient_technique_score_id value in WQM data mart"
-     },
-     {
-      "name": "plan_techn_discrim_type",
-      "value": "",
-      "Description":"type of discriminator for varying nutrient management technique scores; value is “soil test result” otherwise NULL"
-     },
-     {
-      "name": "plan_techn_discrim",
-      "value": "",
-      "Description":"value of the discriminator:  HIGH,MEDIUM, LOW, NO SOIL TEST"
-     }
-    ],
-    [
-        {
-      "name": "AoAid",
-      "value": 1,
-      "Description":"Area of Analysis Identifier"
-      
-     },
-     {
-      "name": "plan_techn_id",
-      "value": 2,
-      "Description":"nutrient management technique identifier corresponding to nutrient_technique_score_id value in WQM data mart"
-     },
-     {
-      "name": "plan_techn_discrim_type",
-      "value": "",
-      "Description":"type of discriminator for varying nutrient management technique scores; value is “soil test result” otherwise NULL"
-     },
-     {
-      "name": "plan_techn_discrim",
-      "value": "",
-      "Description":"value of the discriminator:  HIGH,MEDIUM, LOW, NO SOIL TEST"
-     }
-    ],
-    [
-        {
-      "name": "AoAid",
-      "value": 1,
-      "Description":"Area of Analysis Identifier"
-      
-     },
-     {
-      "name": "plan_techn_id",
-      "value": 9,
-      "Description":"nutrient management technique identifier corresponding to nutrient_technique_score_id value in WQM data mart"
-     },
-     {
-      "name": "plan_techn_discrim_type",
-      "value": "",
-      "Description":"type of discriminator for varying nutrient management technique scores; value is “soil test result” otherwise NULL"
-     },
-     {
-      "name": "plan_techn_discrim",
-      "value": "",
-      "Description":"value of the discriminator:  HIGH,MEDIUM, LOW, NO SOIL TEST"
-     }
+            "name": "pestcomponents",
+            "value": [
+                [
+                    {
+                        "name": "AoAid",
+                        "value": 1,
+                        "Description": "Area of Analysis Identifier"
+                    },
+                    {
+                        "name": "plan_techn_id",
+                        "value": 1,
+                        "Description": "nutrient management technique identifier corresponding to nutrient_technique_score_id value in WQM data mart"
+                    },
+                    {
+                        "name": "plan_techn_discrim_type",
+                        "value": "",
+                        "Description": "type of discriminator for varying nutrient management technique scores; value is “soil test result” otherwise NULL"
+                    },
+                    {
+                        "name": "plan_techn_discrim",
+                        "value": "",
+                        "Description": "value of the discriminator:  HIGH,MEDIUM, LOW, NO SOIL TEST"
+                    }
+                ],
+                [
+                    {
+                        "name": "AoAid",
+                        "value": 1,
+                        "Description": "Area of Analysis Identifier"
+                    },
+                    {
+                        "name": "plan_techn_id",
+                        "value": 5,
+                        "Description": "nutrient management technique identifier corresponding to nutrient_technique_score_id value in WQM data mart"
+                    },
+                    {
+                        "name": "plan_techn_discrim_type",
+                        "value": "",
+                        "Description": "type of discriminator for varying nutrient management technique scores; value is “soil test result” otherwise NULL"
+                    },
+                    {
+                        "name": "plan_techn_discrim",
+                        "value": "",
+                        "Description": "value of the discriminator:  HIGH,MEDIUM, LOW, NO SOIL TEST"
+                    }
+                ],
+                [
+                    {
+                        "name": "AoAid",
+                        "value": 1,
+                        "Description": "Area of Analysis Identifier"
+                    },
+                    {
+                        "name": "plan_techn_id",
+                        "value": 8,
+                        "Description": "nutrient management technique identifier corresponding to nutrient_technique_score_id value in WQM data mart"
+                    },
+                    {
+                        "name": "plan_techn_discrim_type",
+                        "value": "Soil test result",
+                        "Description": "type of discriminator for varying nutrient management technique scores; value is “soil test result” otherwise NULL"
+                    },
+                    {
+                        "name": "plan_techn_discrim",
+                        "value": "Medium",
+                        "Description": "value of the discriminator:  HIGH,MEDIUM, LOW, NO SOIL TEST"
+                    }
+                ],
+                [
+                    {
+                        "name": "AoAid",
+                        "value": 1,
+                        "Description": "Area of Analysis Identifier"
+                    },
+                    {
+                        "name": "plan_techn_id",
+                        "value": 14,
+                        "Description": "nutrient management technique identifier corresponding to nutrient_technique_score_id value in WQM data mart"
+                    },
+                    {
+                        "name": "plan_techn_discrim_type",
+                        "value": "",
+                        "Description": "type of discriminator for varying nutrient management technique scores; value is “soil test result” otherwise NULL"
+                    },
+                    {
+                        "name": "plan_techn_discrim",
+                        "value": "",
+                        "Description": "value of the discriminator:  HIGH,MEDIUM, LOW, NO SOIL TEST"
+                    }
+                ],
+                [
+                    {
+                        "name": "AoAid",
+                        "value": 1,
+                        "Description": "Area of Analysis Identifier"
+                    },
+                    {
+                        "name": "plan_techn_id",
+                        "value": 2,
+                        "Description": "nutrient management technique identifier corresponding to nutrient_technique_score_id value in WQM data mart"
+                    },
+                    {
+                        "name": "plan_techn_discrim_type",
+                        "value": "",
+                        "Description": "type of discriminator for varying nutrient management technique scores; value is “soil test result” otherwise NULL"
+                    },
+                    {
+                        "name": "plan_techn_discrim",
+                        "value": "",
+                        "Description": "value of the discriminator:  HIGH,MEDIUM, LOW, NO SOIL TEST"
+                    }
+                ],
+                [
+                    {
+                        "name": "AoAid",
+                        "value": 1,
+                        "Description": "Area of Analysis Identifier"
+                    },
+                    {
+                        "name": "plan_techn_id",
+                        "value": 9,
+                        "Description": "nutrient management technique identifier corresponding to nutrient_technique_score_id value in WQM data mart"
+                    },
+                    {
+                        "name": "plan_techn_discrim_type",
+                        "value": "",
+                        "Description": "type of discriminator for varying nutrient management technique scores; value is “soil test result” otherwise NULL"
+                    },
+                    {
+                        "name": "plan_techn_discrim",
+                        "value": "",
+                        "Description": "value of the discriminator:  HIGH,MEDIUM, LOW, NO SOIL TEST"
+                    }
+                ]
+            ]
+        }
     ]
-   ]
-  }
- ]
 }

src/java/m/wqm/pestlosspot/Input.java

@@ -1,27 +1,26 @@
-
 package m.wqm.pestlosspot;
 
 /**
  *
  * @author Srinivas Reddy Kontham
+ * @update Rumpal Sidhu
  */
-public class Input
-{
+public class Input {
+
     int operation_id;
     int AoAId;
     String op_pest_id;
     String app_rate;
     String app_area;
     String app_method;
-    
-    public Input(int AoAId,int operation_id,String op_pest_id,String app_rate,String app_area,String app_method)
-    {
-        this.AoAId=AoAId;
-        this.operation_id=operation_id;
-        this.op_pest_id=op_pest_id;
-        this.app_rate=app_rate;
-        this.app_area=app_area;
-        this.app_method=app_method;
-       
+
+    public Input(int AoAId, int operation_id, String op_pest_id, String app_rate, String app_area, String app_method) {
+        this.AoAId = AoAId;
+        this.operation_id = operation_id;
+        this.op_pest_id = op_pest_id;
+        this.app_rate = app_rate;
+        this.app_area = app_area;
+        this.app_method = app_method;
+
     }
 }

src/java/m/wqm/pestlosspot/Result1.java

@@ -3,46 +3,52 @@
 /**
  *
  * @author Kontham Srinivas Reddy
+ * @ Update Rumpal Sidhu
  */
-public class Result1 
-{
-                    int operation_id;
-                    int AoAId;
-                    String op_pest_id;
-                    String app_rate;
-                    String app_area;
-                    String app_method; 
-                    String ai_name="";
-                    Double ai_ph=0.0;
-                    Double ai_sol=0.0;
-                    Double ai_koc=0.0;
-                    Double ai_hl=0.0;
-                    Double ai_fishtox=0.0;
-                    String ai_fishtoxtype="";
-                    Double ai_humtox=0.0;
-                    String ai_humtoxtype="";
-                    String ai_plp;
-                    String ai_psrp;
-                    String ai_parp;
-                public Result1(int AoAId,int operation_id,String op_pest_id,String app_rate,String ai_name,Double ai_ph, Double ai_hl, Double ai_koc,Double ai_sol,Double humtox,String humtoxtype,Double fishtox,String fishtoxtype,String ai_plp,String ai_psrp,String ai_parp,String op_app_area,String op_app_method)
-                {
-                    this.AoAId=AoAId;
-                    this.operation_id=operation_id;
-                    this.op_pest_id=op_pest_id;
-                    this.app_rate=app_rate;
-                    this.ai_name=ai_name;
-                    this.ai_ph=ai_ph;
-                    this.ai_hl=ai_hl;
-                    this.ai_koc=ai_koc;
-                    this.ai_sol=ai_sol;
-                    this.ai_humtox=humtox;
-                    this.ai_humtoxtype=humtoxtype;
-                    this.ai_fishtox=fishtox;
-                    this.ai_fishtoxtype=fishtoxtype;
-                    this.ai_plp=ai_plp;
-                    this.ai_psrp=ai_psrp;
-                    this.ai_parp=ai_parp;
-                    this.app_area=op_app_area;
-                    this.app_method=op_app_method;
-                }
+public class Result1 {
+
+    int operation_id;
+    int AoAId;
+    String op_pest_id;
+    String app_rate;
+    String app_area;
+    String app_method;
+    String ai_name = "";
+    Double ai_ph = 0.0;
+    Double ai_sol = 0.0;
+    Double ai_koc = 0.0;
+    Double ai_hl = 0.0;
+    Double ai_fishtox = 0.0;
+    String ai_fishtoxtype = "";
+    Double ai_humtox = 0.0;
+    String ai_humtoxtype = "";
+    String ai_plp;
+    String ai_psrp;
+    String ai_parp;
+
+    public Result1(int AoAId, int operation_id, String op_pest_id, 
+            String app_rate, String ai_name, Double ai_ph, 
+            Double ai_hl, Double ai_koc, Double ai_sol, Double humtox, 
+            String humtoxtype, Double fishtox, String fishtoxtype, 
+            String ai_plp, String ai_psrp, String ai_parp, 
+            String op_app_area, String op_app_method) {
+        this.AoAId = AoAId;
+        this.operation_id = operation_id;
+        this.op_pest_id = op_pest_id;
+        this.app_rate = app_rate;
+        this.ai_name = ai_name;
+        this.ai_ph = ai_ph;
+        this.ai_hl = ai_hl;
+        this.ai_koc = ai_koc;
+        this.ai_sol = ai_sol;
+        this.ai_humtox = humtox;
+        this.ai_humtoxtype = humtoxtype;
+        this.ai_fishtox = fishtox;
+        this.ai_fishtoxtype = fishtoxtype;
+        this.ai_plp = ai_plp;
+        this.ai_psrp = ai_psrp;
+        this.ai_parp = ai_parp;
+        this.app_area = op_app_area;
+        this.app_method = op_app_method;
+    }
 }

src/java/m/wqm/pestlosspot/V1_0.java

@@ -1,5 +1,5 @@
+package m.wqm.pestlosspot;
 
-package m.wqm.pestlosspot;
 import csip.ModelDataService;
 import java.util.ArrayList;
 import javax.ws.rs.Path;
@@ -11,235 +11,256 @@
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Map;
+
 /**
  *
  * @ Srinivas
+ * @ Update Rumpal Sidhu
  */
 @Name("WQM-4")
 @Description("Pesticide Attributes (WQMPestAttr)")
 @Path("m/pestlosspot/1.0")
 
-public class V1_0 extends ModelDataService{
-    
-  
+public class V1_0 extends ModelDataService {
+
+    //SQL params names here for quick modification
+    private final String USER = "postgres";
+    private final String PASS = "admin";
+    private final String HOST = "localhost";
+    private final String PORT = "5432";
+    private final String DBNAME = "postgres";
+    private final String JDBC_TYPE = "jdbc:postgresql://";
+    private final String CONNECTION = JDBC_TYPE + HOST + ":" + PORT + "/" + DBNAME;
+    private final String CLASS_NAME = "org.postgresql.Driver";
+
     //JSONArray getArray
-    ArrayList<Input> components=new ArrayList<>(); // store the set of all input soilcomponents as objects
-    ArrayList<Result1> result1=new ArrayList<>();  // store the result as objects
+    private ArrayList<Input> components; // store the set of all input soilcomponents as objects
+    private ArrayList<Result1> result1;  // store the result as objects
+
     @Override
-        // reading the inputs from the json file into input object and placing it in the arraylist
-        protected void preProcess() throws Exception {
+    // reading the inputs from the json file into input object and placing it in the arraylist
+    protected void preProcess() throws Exception {
+        components = new ArrayList<>();
         JSONArray groups = getJSONArrayParam("pestcomponents");
-            for(int i=0;i<groups.length();i++)
-            {
-                Map<String, JSONObject> group = JSONUtils.preprocess(groups.getJSONArray(i));
-                int AoAId = JSONUtils.getIntParam(group, "AoAId", 0);
-                int operation_id=JSONUtils.getIntParam(group,"operation_id",0);
-                String op_pest_id=JSONUtils.getStringParam(group,"op_pest_id","err");
-                String app_rate=JSONUtils.getStringParam(group,"app_rate","err");
-                String app_area=JSONUtils.getStringParam(group,"app_area","err");
-                String app_method=JSONUtils.getStringParam(group,"app_method","err");
-                Input input=new Input(AoAId,operation_id,op_pest_id,app_rate,app_area,app_method);
-                components.add(input);
+        for (int i = 0; i < groups.length(); i++) {
+            Map<String, JSONObject> group = JSONUtils.preprocess(groups.getJSONArray(i));
+            int AoAId = JSONUtils.getIntParam(group, "AoAId", 0);
+            int operation_id = JSONUtils.getIntParam(group, "operation_id", 0);
+            String op_pest_id = JSONUtils.getStringParam(group, "op_pest_id", "err");
+            String app_rate = JSONUtils.getStringParam(group, "app_rate", "err");
+            String app_area = JSONUtils.getStringParam(group, "app_area", "err");
+            String app_method = JSONUtils.getStringParam(group, "app_method", "err");
+            Input input = new Input(AoAId, operation_id, op_pest_id, app_rate, app_area, app_method);
+            components.add(input);
+        }
+    }
+
+    @Override
+    protected String process() throws Exception {
+        result1 = new ArrayList<>();
+        Connection conn = null;
+        Statement statement = null;
+        try {
+            Class.forName(CLASS_NAME);
+            conn = DriverManager.getConnection(CONNECTION, USER, PASS);
+            conn.setAutoCommit(false);
+            statement = conn.createStatement();
+
+            for (Input ip : components) {
+                String ai_name = "";
+                double ai_ph = 0.0;
+                double ai_sol = 0.0;
+                double ai_koc = 0.0;
+                double ai_hl = 0.0;
+                double ai_fishtox = 0.0;
+                String ai_fishtoxtype = "";
+                double ai_humtox = 0.0;
+                String ai_humtoxtype = "";
+
+                String query = "SELECT * FROM wqm_pesticides WHERE \"PC_CODE\"='" + ip.op_pest_id + "';";
+                ResultSet results = statement.executeQuery(query);
+                while (results.next()) {
+                    ai_name = results.getString("AI_NAME");
+                    ai_ph = results.getDouble("PH");
+                    ai_hl = results.getDouble("SOIL_HL_RV");
+                    ai_koc = results.getDouble("KOC_RV");
+                    ai_sol = results.getDouble("SOL_RV");
+                    ai_humtox = results.getDouble("HUMAN_TOX_PPB");
+                    ai_humtoxtype = results.getString("HUMAN_TOX_TYPE");
+                    ai_fishtox = results.getDouble("FISH_TOX_PPB");
+                    ai_fishtoxtype = results.getString("FISH_TOX_TYPE");
+                }
+
+                //     #Compute pesticide leaching potential fore each operation pesticide
+                double log_val = Math.log10(ai_hl) * (4 - Math.log10(ai_koc));
+                String ai_plp;
+                if (log_val >= 2.8) {
+                    if (ip.app_area.equals("Banded")
+                            || ip.app_method.equals("Foliar Application")
+                            || ip.app_rate.equals("LOW")) {
+                        ai_plp = "INTERMEDIATE";
+                    } else if (ip.app_area.equals("Spot Treatment")
+                            || ip.app_rate.equals("ULTRA LOW")) {
+                        ai_plp = "LOW";
+                    } else {
+                        ai_plp = "HIGH";
+                    }
+                } else if (log_val < 0.0 || (ai_sol < 1 && ai_hl <= 1)) {
+                    ai_plp = "VERY LOW";
+                } else if (log_val <= 1.8) {
+                    if (ip.app_area.equals("Banded")
+                            || ip.app_area.equals("Spot Treatment")
+                            || ip.app_method.equals("Foliar Application")
+                            || ip.app_rate.equals("LOW")
+                            || ip.app_rate.equals("ULTRA LOW")) {
+                        ai_plp = "VERY LOW";
+                    } else {
+                        ai_plp = "LOW";
+                    }
+                } else {
+                    if (ip.app_area.equals("Banded")
+                            || ip.app_method.equals("Foliar Application")
+                            || ip.app_rate.equals("LOW")) {
+                        ai_plp = "LOW";
+                    } else if (ip.app_area.equals("Spot Treatment")
+                            || ip.app_rate.equals("ULTRA LOW")) {
+                        ai_plp = "VERY LOW";
+                    } else {
+                        ai_plp = "INTERMEDIATE";
+                    }
+                }
+
+                String ai_psrp;
+                //   #Compute pesticide solution runoff potential for each operation pesticide
+                if ((ai_sol >= 1 && ai_hl > 35 && ai_koc < 100000)
+                        || (ai_sol >= 10 && ai_sol < 100 && ai_koc <= 700)) {
+                    if (ip.app_area.equals("Banded")
+                            || ip.app_method.equals("Foliar Application")
+                            || ip.app_method.equals("Soil Incorporated")
+                            || ip.app_rate.equals("LOW")) {
+                        ai_psrp = "INTERMEDIATE";
+                    } else if (ip.app_area.equals("Spot Treatment")
+                            || ip.app_rate.equals("ULTRA LOW")) {
+                        ai_psrp = "LOW";
+                    } else {
+                        ai_psrp = "HIGH";
+                    }
+                } else if ((ai_koc >= 100000)
+                        || (ai_koc >= 1000 && ai_hl <= 1)
+                        || (ai_sol < 0.5 && ai_hl < 35)) {
+                    if (ip.app_area.equals("Banded")
+                            || ip.app_area.equals("Spot Treatment")
+                            || ip.app_method.equals("Foliar Application")
+                            || ip.app_method.equals("Soil Incorporated")
+                            || ip.app_rate.equals("LOW")
+                            || ip.app_rate.equals("ULTRA LOW")) {
+                        ai_psrp = "VERY LOW";
+                    } else {
+                        ai_psrp = "LOW";
+                    }
+                } else {
+                    if (ip.app_area.equals("Banded")
+                            || ip.app_method.equals("Foliar Application")
+                            || ip.app_method.equals("Soil Incorporated")
+                            || ip.app_rate.equals("LOW")) {
+                        ai_psrp = "LOW";
+                    } else if (ip.app_area.equals("Spot Treatment")
+                            || ip.app_rate.equals("ULTRA LOW")) {
+                        ai_psrp = "VERY LOW";
+                    } else {
+                        ai_psrp = "INTERMEDIATE";
+                    }
+                }
+
+                //    #Compute pesticide adsorbed runoff potential for each operation pesticide
+                String ai_parp;
+                if ((ai_hl >= 40 && ai_koc >= 1000)
+                        || (ai_hl >= 40 && ai_koc >= 500 && ai_sol <= 0.5)) {
+                    if (ip.app_area.equals("Banded")
+                            || ip.app_method.equals("Foliar Application")
+                            || ip.app_method.equals("Soil Incorporate")
+                            || ip.app_rate.equals("LOW")) {
+                        ai_parp = "INTERMEDIATE";
+                    } else if (ip.app_area.equals("Spot Treatment")
+                            || ip.app_rate.equals("ULTRA LOW")) {
+                        ai_parp = "LOW";
+                    } else {
+                        ai_parp = "HIGH";
+                    }
+                } else if ((ai_hl <= 1) || (ai_hl <= 2 && ai_koc <= 500)
+                        || (ai_hl <= 4 && ai_koc <= 900 && ai_sol >= 0.5)
+                        || (ai_hl <= 40 && ai_koc <= 500 && ai_sol >= 0.5)
+                        || (ai_hl <= 50 && ai_koc <= 900 && ai_sol >= 2)) {
+                    if (ip.app_area.equals("Banded")
+                            || ip.app_area.equals("Spot Treatment")
+                            || ip.app_method.equals("Foliar Application")
+                            || ip.app_method.equals("Soil Incorporated")
+                            || ip.app_rate.equals("LOW")
+                            || ip.app_rate.equals("ULTRA LOW")) {
+                        ai_parp = "VERY LOW";
+                    } else {
+                        ai_parp = "LOW";
+                    }
+                } else {
+                    if (ip.app_area.equals("Banded")
+                            || ip.app_method.equals("Foliar Application")
+                            || ip.app_method.equals("Soil Incorporated")
+                            || ip.app_rate.equals("LOW")) {
+                        ai_parp = "VERY LOW";
+                    } else {
+                        ai_parp = "INTERMEDIATE";
+                    }
+                }
+                Result1 result = new Result1(ip.AoAId, ip.operation_id,
+                        ip.op_pest_id, ip.app_rate, ai_name, ai_ph, ai_hl,
+                        ai_koc, ai_sol, ai_humtox, ai_humtoxtype, ai_fishtox,
+                        ai_fishtoxtype, ai_plp, ai_psrp, ai_parp,
+                        ip.app_area, ip.app_method);
+                result1.add(result);
+            }
+        } catch (SQLException se) {
+            LOG.info("Did not open database for WQM-4!");
+            LOG.info(se.getMessage());
+        } finally {
+            if (statement != null) {
+                statement.close();
+            }
+            if (conn != null) {
+                conn.close();
             }
         }
-        @Override
-        protected String process() throws Exception
-        {
-            Connection conn = null;
-                Statement statement = null;
-                Class.forName("org.postgresql.Driver");
-                conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/wqm", "postgres", "admin");
-                conn.setAutoCommit(false);
-                statement = conn.createStatement();
-                    
-                for(Input ip:components)
-                {
-                    String pc_code="";
-                    String ai_name="";
-                    Double ai_ph=0.0;
-                    Double ai_sol=0.0;
-                    Double ai_koc=0.0;
-                    Double ai_hl=0.0;
-                    Double ai_fishtox=0.0;
-                    String ai_fishtoxtype="";
-                    Double ai_humtox=0.0;
-                    String ai_humtoxtype="";
-                
-                    String query="SELECT * FROM wqm_pesticides WHERE \"PC_CODE\"='"+ip.op_pest_id+"';";
-                    ResultSet results = statement.executeQuery(query);
-                    while (results.next())
-                    {
-                        pc_code=results.getString("PC_CODE");
-                        ai_name=results.getString("AI_NAME");
-                        ai_ph=results.getDouble("PH");
-                        ai_sol=results.getDouble("SOL_RV");
-                        ai_koc=results.getDouble("KOC_RV");
-                        ai_hl=results.getDouble("SOIL_HL_RV");
-                        ai_fishtox=results.getDouble("FISH_TOX_PPB");
-                        ai_fishtoxtype=results.getString("FISH_TOX_TYPE");
-                        ai_humtox=results.getDouble("HUMAN_TOX_PPB");
-                        ai_humtoxtype=results.getString("HUMAN_TOX_TYPE");
-                    }
-               //     #Compute pesticide leaching potential fore each operation pesticide
-                    double log_val=Math.log(ai_hl)*(4-Math.log(ai_koc));
-                    String ai_plp="";
-                    if(log_val>=2.8)
-                    {
-                        if(ip.app_area.equals("Banded")||ip.app_method.equals("Foliar Application")||ip.app_rate.equals("LOW"))
-                        {
-                            ai_plp="INTERMEDIATE";
-                        }
-                        else if(ip.app_area.equals("Spot Treatment")||ip.app_rate.equals("ULTRA LOW"))
-                        {
-                            ai_plp="LOW";
-                        }
-                        else
-                        {
-                            ai_plp="HIGH";
-                        }
-                        
-                    }
-                    else if(log_val<0.0 || (ai_sol<1 && ai_hl<=1))
-                    {
-                        ai_plp="VERY LOW";
-                    }
-                    else if(log_val<=1.8)
-                    {
-                        if(ip.app_area.equals("Banded")||ip.app_area.equals("Spot Treatment")||ip.app_method.equals("Foliar Application")||ip.app_rate.equals("LOW")||ip.app_rate.equals("ULTRA LOW"))
-                        {
-                            ai_plp="VERY LOW";
-                            
-                        }
-                        else
-                        {
-                            ai_plp="LOW";
-                        }
-                    }
-                    else
-                    {
-                        if(ip.app_area.equals("Banded")||ip.app_method.equals("Foliar Application")||ip.app_rate.equals("LOW"))
-                        {
-                            ai_plp="LOW";
-                        }
-                        else if(ip.app_area.equals("Spot Treatment")||ip.app_rate.equals("ULTRA LOW"))
-                        {
-                            ai_plp="VERY LOW";
-                        }
-                        else
-                        {
-                            ai_plp="INTERMEDIATE";
-                        }
-                            
-                    }String ai_psrp="";
-                 //   #Compute pesticide solution runoff potential for each operation pesticide
-                    if((ai_sol>=1 && ai_hl>35 && ai_koc <100000) ||(ai_sol >=10 && ai_hl <100 &&ai_koc <=700 ))
-                    {
-                        if(ip.app_area.equals("Banded")||ip.app_method.equals("Foliar Application")||ip.app_method.equals("Soil Incorporated") || ip.app_rate.equals("LOW"))
-                        {
-                            ai_psrp="INTERMEDIATE";
-                        }
-                        else if(ip.app_area.equals("Spot Treatment")||ip.app_rate.equals("ULTRA LOW"))
-                        {
-                            ai_plp="LOW";
-                        }
-                        else
-                        {
-                            ai_psrp="HIGH";
-                        }
-                    }
-                    else if((ai_koc>=100000)||(ai_koc>=1000 && ai_hl<=1)|| (ai_sol<0.5 && ai_hl<35))
-                    {
-                        if(ip.app_area.equals("Banded")||ip.app_area.equals("Spot Treatment")||ip.app_method.equals("Foliar Application")||ip.app_method.equals("Soil Incorporated")||ip.app_rate.equals("LOW")||ip.app_rate.equals("ULTRA LOW"))
-                        {
-                            ai_psrp="VERY LOW";
-                        }
-                        else
-                        {
-                            ai_psrp="LOW";
-                        }
-                    }
-                    else
-                    {
-                        if(ip.app_area.equals("Banded")||ip.app_method.equals("Foliar Application")||ip.app_method.equals("Soil Incorporated")||ip.app_rate.equals("LOW"))
-                        {
-                            ai_psrp="LOW";
-                        }
-                        else if(ip.app_area.equals("Spot Treatment")||ip.app_rate.equals("ULTRA LOW"))
-                        {
-                            ai_psrp="VERY LOW";
-                        }
-                        else
-                        {
-                            ai_psrp="INTERMEDIATE";
-                        }
-                    }
-                //    #Compute pesticide adsorbed runoff potential for each operation pesticide
-                    String ai_parp="";
-                    if((ai_hl>=40&&ai_koc>=1000)||(ai_hl>=40 &&ai_koc>=500 &&ai_sol<=0.5))
-                    {
-                        if(ip.app_area.equals("Banded")||ip.app_method.equals("Foliar Application")||ip.app_method.equals("Soil Incorporate")||ip.app_rate.equals("LOW"))
-                        {
-                            ai_parp="INTERMEDIATE";
-                        }
-                        else if(ip.app_area.equals("Spot Treatment")||ip.app_rate.equals("ULTRA LOW"))
-                        {
-                            ai_parp="LOW";
-                        }
-                        else
-                        {
-                            ai_parp="HIGH";
-                        }
-                        
-                    }
-                    else if((ai_hl<=1)||(ai_hl<=2 &&ai_koc<=500)||(ai_koc<=900 && ai_sol>=0.5)||(ai_hl<=40&&ai_koc<=500 && ai_sol>=0.5)||(ai_hl<=50 && ai_koc<=900 && ai_sol>=2))
-                    {
-                        if(ip.app_area.equals("Banded")||ip.app_area.equals("Spot Treatment")||ip.app_method.equals("Foliar Application")||ip.app_method.equals("Soil Incorporated")||ip.app_rate.equals("LOW")||ip.app_rate.equals("ULTRA LOW"))
-                        {
-                            ai_parp="VERY LOW";
-                        }
-                        else
-                        {
-                            ai_parp="LOW";
-                        }
-                    }
-                    Result1 result=new Result1(ip.AoAId,ip.operation_id,ip.op_pest_id,ip.app_rate,ai_name,ai_ph,ai_hl,ai_koc,ai_sol,ai_humtox,ai_humtoxtype,ai_fishtox,ai_fishtoxtype,ai_plp,ai_psrp,ai_parp,ip.app_area,ip.app_method); 
-                    result1.add(result);    
-               }
-                return EXEC_OK; 
-            }
-        @Override
-        //writing the results back to JSON
+        return EXEC_OK;
+    }
+
+    @Override
+    //writing the results back to JSON
     protected void postProcess() throws Exception {
-    JSONArray result1Arr = new JSONArray();
-                for(Result1 rs1:result1)
-                {
-                    JSONArray tmpArr = new JSONArray();
-                    tmpArr.put(JSONUtils.dataDesc("AoAId", rs1.AoAId, "Area of Analysis Identifier"));
-                    tmpArr.put(JSONUtils.dataDesc("operation_id", rs1.operation_id, "Operation ID"));
-                  
-                    tmpArr.put(JSONUtils.dataDesc("op_pest_id", rs1.op_pest_id, "Pesticide Identifier (PC_CODE)"));
-                    tmpArr.put(JSONUtils.dataDesc("app_rate", rs1.app_rate, "Pesticide Application Rating"));
-                    tmpArr.put(JSONUtils.dataDesc("ai_name", rs1.ai_name, "Active Ingredient Name (AI_NAME)"));
-                    tmpArr.put(JSONUtils.dataDesc("ai_ph", rs1.ai_ph, "Active ingredient pH of associate properties (PH)"));
-                    tmpArr.put(JSONUtils.dataDesc("ai_hl", rs1.ai_hl, "Active ingredient field half life (HL)"));
-                    tmpArr.put(JSONUtils.dataDesc("ai_koc", rs1.ai_koc, "Active ingredient soil organic carbon sorption coefficient (KOC)"));
-                    tmpArr.put(JSONUtils.dataDesc("ai_sol", rs1.ai_sol, "Active ingredient solubility in water (SOL)"));
-                    tmpArr.put(JSONUtils.dataDesc("ai_humtox", rs1.ai_humtox, "Active ingredient human toxicity value – long term"));
-                   tmpArr.put(JSONUtils.dataDesc("ai_humtoxtype", rs1.ai_humtoxtype, "Active ingredient human toxicity type"));
-                   tmpArr.put(JSONUtils.dataDesc("ai_fistox", rs1.ai_fishtox, "Active ingredient maximum acceptable toxicant concentration-fish"));
-                   tmpArr.put(JSONUtils.dataDesc("ai_fishtoxtype", rs1.ai_fishtoxtype, "Active ingredient fish toxicity type"));
-                   tmpArr.put(JSONUtils.dataDesc("ai_plp", rs1.ai_plp, "Active ingredient pesticide leaching potential"));
-                   tmpArr.put(JSONUtils.dataDesc("ai_psrp", rs1.ai_psrp, "Active ingredient pesticide soil leaching potential"));
-                   tmpArr.put(JSONUtils.dataDesc("ai_parp", rs1.ai_parp, "Active ingredient pesticide adsorbed runoff potential"));
-                   tmpArr.put(JSONUtils.dataDesc("op_app_area", rs1.app_area, "Pesticide application operation area"));
-                   tmpArr.put(JSONUtils.dataDesc("op_app_method", rs1.app_method, "Pesticide application operation method"));
-                   result1Arr.put(JSONUtils.dataDesc("pesticide summary", tmpArr, "Pest"));
-                }
-                
-                putResult("operation", result1Arr);    
+        JSONArray result1Arr = new JSONArray();
+        for (Result1 rs1 : result1) {
+            JSONArray tmpArr = new JSONArray();
+            tmpArr.put(JSONUtils.dataDesc("AoAId", rs1.AoAId, "Area of Analysis Identifier"));
+            tmpArr.put(JSONUtils.dataDesc("operation_id", rs1.operation_id, "Operation ID"));
+            tmpArr.put(JSONUtils.dataDesc("op_pest_id", rs1.op_pest_id, "Pesticide Identifier (PC_CODE)"));
+            tmpArr.put(JSONUtils.dataDesc("app_rate", rs1.app_rate, "Pesticide Application Rating"));
+            tmpArr.put(JSONUtils.dataDesc("ai_name", rs1.ai_name, "Active Ingredient Name (AI_NAME)"));
+            tmpArr.put(JSONUtils.dataDesc("ai_ph", rs1.ai_ph, "Active ingredient pH of associate properties (PH)"));
+            tmpArr.put(JSONUtils.dataDesc("ai_hl", rs1.ai_hl, "Active ingredient field half life (HL)"));
+            tmpArr.put(JSONUtils.dataDesc("ai_koc", rs1.ai_koc, "Active ingredient soil organic carbon sorption coefficient (KOC)"));
+            tmpArr.put(JSONUtils.dataDesc("ai_sol", rs1.ai_sol, "Active ingredient solubility in water (SOL)"));
+            tmpArr.put(JSONUtils.dataDesc("ai_humtox", rs1.ai_humtox, "Active ingredient human toxicity value – long term"));
+            tmpArr.put(JSONUtils.dataDesc("ai_humtoxtype", rs1.ai_humtoxtype, "Active ingredient human toxicity type"));
+            tmpArr.put(JSONUtils.dataDesc("ai_fistox", rs1.ai_fishtox, "Active ingredient maximum acceptable toxicant concentration-fish"));
+            tmpArr.put(JSONUtils.dataDesc("ai_fishtoxtype", rs1.ai_fishtoxtype, "Active ingredient fish toxicity type"));
+            tmpArr.put(JSONUtils.dataDesc("ai_plp", rs1.ai_plp, "Active ingredient pesticide leaching potential"));
+            tmpArr.put(JSONUtils.dataDesc("ai_psrp", rs1.ai_psrp, "Active ingredient pesticide soil leaching potential"));
+            tmpArr.put(JSONUtils.dataDesc("ai_parp", rs1.ai_parp, "Active ingredient pesticide adsorbed runoff potential"));
+            tmpArr.put(JSONUtils.dataDesc("op_app_area", rs1.app_area, "Pesticide application operation area"));
+            tmpArr.put(JSONUtils.dataDesc("op_app_method", rs1.app_method, "Pesticide application operation method"));
+            result1Arr.put(JSONUtils.dataDesc("pesticide summary", tmpArr, "Pest"));
+        }
+        putResult("operation", result1Arr);
     }
-    }   
-    
-
+}

src/java/m/wqm/pestlosspot/V1_0.json

@@ -1,80 +1,215 @@
 {
- "metainfo": {
- },
- "parameter": [
-  {
-   "name": "pestcomponents",
-   "value": [
-    [
-     {
-      "name": "AoAId",
-      "value": 1,
-      "Description":"Area of Analysis Identifier"
-      
-     },
-     {
-      "name": "operation_id",
-      "value": 1,
-      "Description":"Pesticide application operation identifier"
-      
-     },
-     {
-      "name": "op_pest_id",
-      "value": "101101",
-      "Description":"Pesticide identifier, EPA Pesticide Chemical Code (PC_CODE)"
-     },
-     {
-      "name": "app_rate",
-      "value": "STANDARD",
-      "Description":"Pesticide application rate"
-     },
-     {
-      "name": "app_area",
-      "value": "Broadcast",
-      "Description":"Pesticide application operation area"
-     },
-     {
-      "name": "app_method",
-      "value": "Surface Applied",
-      "Description":"Pesticide application operation method"
-     }
-    ],
-    [
-     {
-      "name": "AoAId",
-      "value": 1,
-      "Description":"AoA Identifier"
-      
-     },
-     {
-      "name": "operation_id",
-      "value": 1,
-      "Description":"Pesticide application operation identifier"
-      
-     },
-     {
-      "name": "op_pest_id",
-      "value": "101702",
-      "Description":"Pesticide identifier, EPA Pesticide Chemical Code (PC_CODE)"
-     },
-     {
-      "name": "app_rate",
-      "value": "LOW",
-      "Description":"Pesticide application rate"
-     },
-     {
-      "name": "app_area",
-      "value": "Broadcast",
-      "Description":"Pesticide application operation area"
-     },
-     {
-      "name": "app_method",
-      "value": "Surface Applied",
-      "Description":"Pesticide application operation method"
-     }
+    "metainfo": {
+    },
+    "parameter": [
+        {
+            "name": "pestcomponents",
+            "value": [
+                [
+                    {
+                        "name": "AoAId",
+                        "value": 1,
+                        "Description": "Area of Analysis Identifier"
+
+                    },
+                    {
+                        "name": "operation_id",
+                        "value": 1,
+                        "Description": "Pesticide application operation identifier"
+
+                    },
+                    {
+                        "name": "op_pest_id",
+                        "value": "53501",
+                        "Description": "Pesticide identifier, EPA Pesticide Chemical Code (PC_CODE)"
+                    },
+                    {
+                        "name": "app_rate",
+                        "value": "Starndard Rate",
+                        "Description": "Pesticide application rate"
+                    },
+                    {
+                        "name": "app_area",
+                        "value": "Broadcast",
+                        "Description": "Pesticide application operation area"
+                    },
+                    {
+                        "name": "app_method",
+                        "value": "Surface Applied",
+                        "Description": "Pesticide application operation method"
+                    }
+                ],
+                [
+                    {
+                        "name": "AoAId",
+                        "value": 1,
+                        "Description": "Area of Analysis Identifier"
+
+                    },
+                    {
+                        "name": "operation_id",
+                        "value": 2,
+                        "Description": "Pesticide application operation identifier"
+
+                    },
+                    {
+                        "name": "op_pest_id",
+                        "value": "108801",
+                        "Description": "Pesticide identifier, EPA Pesticide Chemical Code (PC_CODE)"
+                    },
+                    {
+                        "name": "app_rate",
+                        "value": "Starndard Rate",
+                        "Description": "Pesticide application rate"
+                    },
+                    {
+                        "name": "app_area",
+                        "value": "Broadcast",
+                        "Description": "Pesticide application operation area"
+                    },
+                    {
+                        "name": "app_method",
+                        "value": "Surface Applied",
+                        "Description": "Pesticide application operation method"
+                    }
+                ],
+                [
+                    {
+                        "name": "AoAId",
+                        "value": 1,
+                        "Description": "Area of Analysis Identifier"
+
+                    },
+                    {
+                        "name": "operation_id",
+                        "value": 3,
+                        "Description": "Pesticide application operation identifier"
+
+                    },
+                    {
+                        "name": "op_pest_id",
+                        "value": "98301",
+                        "Description": "Pesticide identifier, EPA Pesticide Chemical Code (PC_CODE)"
+                    },
+                    {
+                        "name": "app_rate",
+                        "value": "Starndard Rate",
+                        "Description": "Pesticide application rate"
+                    },
+                    {
+                        "name": "app_area",
+                        "value": "Broadcast",
+                        "Description": "Pesticide application operation area"
+                    },
+                    {
+                        "name": "app_method",
+                        "value": "Surface Applied",
+                        "Description": "Pesticide application operation method"
+                    }
+                ], [
+                    {
+                        "name": "AoAId",
+                        "value": 1,
+                        "Description": "Area of Analysis Identifier"
+
+                    },
+                    {
+                        "name": "operation_id",
+                        "value": 4,
+                        "Description": "Pesticide application operation identifier"
+
+                    },
+                    {
+                        "name": "op_pest_id",
+                        "value": "105001",
+                        "Description": "Pesticide identifier, EPA Pesticide Chemical Code (PC_CODE)"
+                    },
+                    {
+                        "name": "app_rate",
+                        "value": "Starndard Rate",
+                        "Description": "Pesticide application rate"
+                    },
+                    {
+                        "name": "app_area",
+                        "value": "Broadcast",
+                        "Description": "Pesticide application operation area"
+                    },
+                    {
+                        "name": "app_method",
+                        "value": "Surface Applied",
+                        "Description": "Pesticide application operation method"
+                    }
+                ],
+                [
+                    {
+                        "name": "AoAId",
+                        "value": 1,
+                        "Description": "Area of Analysis Identifier"
+
+                    },
+                    {
+                        "name": "operation_id",
+                        "value": 5,
+                        "Description": "Pesticide application operation identifier"
+
+                    },
+                    {
+                        "name": "op_pest_id",
+                        "value": "128008",
+                        "Description": "Pesticide identifier, EPA Pesticide Chemical Code (PC_CODE)"
+                    },
+                    {
+                        "name": "app_rate",
+                        "value": "Starndard Rate",
+                        "Description": "Pesticide application rate"
+                    },
+                    {
+                        "name": "app_area",
+                        "value": "Broadcast",
+                        "Description": "Pesticide application operation area"
+                    },
+                    {
+                        "name": "app_method",
+                        "value": "Surface Applied",
+                        "Description": "Pesticide application operation method"
+                    }
+                ],
+                [
+                    {
+                        "name": "AoAId",
+                        "value": 1,
+                        "Description": "Area of Analysis Identifier"
+
+                    },
+                    {
+                        "name": "operation_id",
+                        "value": 6,
+                        "Description": "Pesticide application operation identifier"
+
+                    },
+                    {
+                        "name": "op_pest_id",
+                        "value": "81901",
+                        "Description": "Pesticide identifier, EPA Pesticide Chemical Code (PC_CODE)"
+                    },
+                    {
+                        "name": "app_rate",
+                        "value": "Starndard Rate",
+                        "Description": "Pesticide application rate"
+                    },
+                    {
+                        "name": "app_area",
+                        "value": "Broadcast",
+                        "Description": "Pesticide application operation area"
+                    },
+                    {
+                        "name": "app_method",
+                        "value": "Surface Applied",
+                        "Description": "Pesticide application operation method"
+                    }
+                ]
+            ]
+        }
     ]
-   ]
-  }
- ]
 }
 

src/java/m/wqm/rfactor/V1_0.java

@@ -17,6 +17,7 @@
 import java.sql.ResultSet;
 import java.sql.Statement;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Map;
 import javax.ws.rs.Path;
 import javax.xml.parsers.DocumentBuilder;
@@ -65,6 +66,7 @@
    JSONArray aoaArr;
    ArrayList<AoA> list;
    ArrayList<String> rfactorList;
+   ArrayList<Double> temp;
     @Override
     public void preProcess() throws ServiceException, JSONException
     {
@@ -111,7 +113,7 @@
           for(int i=0;i<list.size();i++)
           {
               String points= list.get(i).getCoordinates();
-          String gisQuery="SELECT m.co_fips, r2_path, r2_name, m.ei_rang, st_area(st_intersection(ST_PolygonFromText('POLYGON(("+points+"))'), geometry)) / st_area(ST_PolygonFromText('POLYGON(("+points+"))'))*100 as percentAoi,st_area(st_intersection(ST_PolygonFromText('POLYGON(("+points+"))'), geometry))/43560 as sizeAoi FROM cli_geom AS g, map_climates AS m WHERE ST_Intersects(ST_PolygonFromText('POLYGON(("+points+"))'), g.geometry) AND g.co_fips = m.co_fips and g.ei_rang = m.ei_rang and st_isvalid(geometry)='t' and st_isvalid(ST_PolygonFromText('POLYGON(("+points+"))'))='t';";
+          String gisQuery="SELECT m.co_fips, r2_path, r2_name, m.ei_rang, st_area(st_intersection(ST_PolygonFromText('POLYGON(("+points+"))'), geometry)) / st_area(ST_PolygonFromText('POLYGON(("+points+"))'))*100 as percentAoi,st_area(st_intersection(ST_PolygonFromText('POLYGON(("+points+"))'), geometry))/43560 as sizeAoi FROM cli_geom AS g, map_climates AS m WHERE ST_Intersects(ST_PolygonFromText('POLYGON(("+points+"))'), g.geometry) AND g.co_fips = m.co_fips and st_isvalid(geometry)='t' and st_isvalid(ST_PolygonFromText('POLYGON(("+points+"))'))='t';";
            //stmt.execute(gisQuery);
          //statement.execute(query1);
          
@@ -151,8 +153,13 @@
     JSONArray finalArr= new JSONArray();
     for(int i=0;i<list.size();i++){
     JSONArray resultArr = new JSONArray();
+    temp=new ArrayList<Double>();
+    for(int j=0;j<list.get(i).getRFactor().size();j++)
+      temp.add(Double.parseDouble(list.get(i).getRFactor().get(j)));
+    
+    Collections.sort(temp);
     resultArr.put(JSONUtils.dataDesc("AoAId",list.get(i).getAoAId(),"Area of Analysis Identifier"));
-    resultArr.put(JSONUtils.dataDesc("RFactor",list.get(i).getRFactor(),"R Factor"));
+    resultArr.put(JSONUtils.dataDesc("RFactor",temp.get(temp.size()-1),"R Factor"));
     
     finalArr.put(resultArr);
     }

src/java/m/wqm/soilpestlosspot/Input.java

@@ -4,19 +4,18 @@
  *
  * @author RUMPAL SIDHU
  */
-
 public class Input {
 
-    int AoAId;
-    int operation_id;
-    String op_pesticide_id;
-    String ai_plp;
-    String ai_psrp;
-    String ai_parp;
-    String aoa_pslp;
-    String aoa_ssrp;
-    String aoa_sarp;
-    String aoa_rain_prob;
+    private int AoAId;
+    private int operation_id;
+    private String op_pesticide_id;
+    private String ai_plp;
+    private String ai_psrp;
+    private String ai_parp;
+    private String aoa_pslp;
+    private String aoa_ssrp;
+    private String aoa_sarp;
+    private String aoa_rain_prob;
 
     public Input(int AoAId, int operation_id, String op_pesticide_id, String ai_plp, String ai_psrp, String ai_parp, String aoa_pslp, String aoa_ssrp, String aoa_sarp, String aoa_rain_prob) {
         this.AoAId = AoAId;
@@ -30,4 +29,45 @@
         this.aoa_sarp = aoa_sarp;
         this.aoa_rain_prob = aoa_rain_prob;
     }
+
+    //Getter Methods
+    public int getAoaId() {
+        return this.AoAId;
+    }
+
+    public int getOperationId() {
+        return this.operation_id;
+    }
+
+    public String getPesticideId() {
+        return this.op_pesticide_id;
+    }
+
+    public String getAi_plp() {
+        return this.ai_plp;
+    }
+
+    public String getAi_psrp() {
+        return this.ai_psrp;
+    }
+
+    public String getAi_parp() {
+        return this.ai_parp;
+    }
+
+    public String getAoa_pslp() {
+        return this.aoa_pslp;
+    }
+
+    public String getAoa_ssrp() {
+        return this.aoa_ssrp;
+    }
+
+    public String getAoa_sarp() {
+        return this.aoa_sarp;
+    }
+
+    public String getAoa_rain_prob() {
+        return this.aoa_rain_prob;
+    }
 }

src/java/m/wqm/soilpestlosspot/Result.java

@@ -4,15 +4,14 @@
  *
  * @author RUMPAL SIDHU
  */
-
 public class Result {
 
-    int AoAId;
-    int operation_id;
-    String op_pesticide_id;
-    String op_pest_ilp;
-    String op_pest_isrp;
-    String op_pest_iarp;
+    private int AoAId;
+    private int operation_id;
+    private String op_pesticide_id;
+    private String op_pest_ilp;
+    private String op_pest_isrp;
+    private String op_pest_iarp;
 
     public Result(int AoAId, int operation_id, String op_pesticide_id, String op_pest_ilp, String op_pest_isrp, String op_pest_iarp) {
         this.AoAId = AoAId;
@@ -22,4 +21,28 @@
         this.op_pest_isrp = op_pest_isrp;
         this.op_pest_iarp = op_pest_iarp;
     }
-}
\ No newline at end of file
+
+    public int getAoaId() {
+        return this.AoAId;
+    }
+
+    public int getOperationId() {
+        return this.operation_id;
+    }
+
+    public String getOpPesticideId() {
+        return this.op_pesticide_id;
+    }
+
+    public String getOpPestIlp() {
+        return this.op_pest_ilp;
+    }
+
+    public String getOpPestIsrp() {
+        return this.op_pest_isrp;
+    }
+
+    public String getOpPestIarp() {
+        return this.op_pest_iarp;
+    }
+}

src/java/m/wqm/soilpestlosspot/V1_0.java

@@ -78,13 +78,13 @@
 
             for (Input ip : components) {
 
-                query = "SELECT wqm_ilp FROM wqm_soil_pest_interaction_leaching WHERE wqm_plp='" + ip.ai_plp + "'AND wqm_slp='" + ip.aoa_pslp + "';";
+                query = "SELECT wqm_ilp FROM wqm_soil_pest_interaction_leaching WHERE wqm_plp='" + ip.getAi_plp() + "' AND wqm_slp='" + ip.getAoa_pslp() + "';";
                 resultSet = statement.executeQuery(query);
                 String op_pest_ilp = "err";
                 while (resultSet.next()) {
                     op_pest_ilp = resultSet.getString("wqm_ilp");
                 }
-                if (ip.aoa_rain_prob.equals("LOW")) {
+                if (ip.getAoa_rain_prob().equals("LOW")) {
                     switch (op_pest_ilp) {
                         case "HIGH":
                             op_pest_ilp = "INTERMEDIATE";
@@ -98,13 +98,13 @@
                     }
                 }
 
-                query = "SELECT wqm_isrp FROM wqm_soil_pest_interaction_solution_runoff WHERE wqm_psrp='" + ip.ai_psrp + "'AND wqm_ssrp ='" + ip.aoa_ssrp + "';";
+                query = "SELECT wqm_isrp FROM wqm_soil_pest_interaction_solution_runoff WHERE wqm_psrp='" + ip.getAi_psrp() + "' AND wqm_ssrp ='" + ip.getAoa_ssrp() + "';";
                 resultSet = statement.executeQuery(query);
                 String op_pest_isrp = "err";
                 while (resultSet.next()) {
                     op_pest_isrp = resultSet.getString("wqm_isrp");
                 }
-                if (ip.aoa_rain_prob.equals("LOW")) {
+                if (ip.getAoa_rain_prob().equals("LOW")) {
                     switch (op_pest_isrp) {
                         case "HIGH":
                             op_pest_isrp = "INTERMEDIATE";
@@ -112,19 +112,16 @@
                         case "INTERMEDIATE":
                             op_pest_isrp = "LOW";
                             break;
-                        case "LOW":
-                            op_pest_isrp = "VERY LOW";
-                            break;
                     }
                 }
 
-                query = "SELECT wqm_iarp FROM wqm_soil_pest_interaction_adsorbed_runoff WHERE wqm_parp='" + ip.ai_parp + "'AND wqm_sarp='" + ip.aoa_sarp + "';";
+                query = "SELECT wqm_iarp FROM wqm_soil_pest_interaction_adsorbed_runoff WHERE wqm_parp='" + ip.getAi_parp() + "' AND wqm_sarp='" + ip.getAoa_sarp() + "';";
                 resultSet = statement.executeQuery(query);
                 String op_pest_iarp = "err";
                 while (resultSet.next()) {
                     op_pest_iarp = resultSet.getString("wqm_iarp");
                 }
-                if (ip.aoa_rain_prob.equals("LOW")) {
+                if (ip.getAoa_rain_prob().equals("LOW")) {
                     switch (op_pest_iarp) {
                         case "HIGH":
                             op_pest_iarp = "INTERMEDIATE";
@@ -132,13 +129,10 @@
                         case "INTERMEDIATE":
                             op_pest_iarp = "LOW";
                             break;
-                        case "LOW":
-                            op_pest_iarp = "VERY LOW";
-                            break;
                     }
                 }
 
-                Result result1 = new Result(ip.AoAId, ip.operation_id, ip.op_pesticide_id, op_pest_ilp, op_pest_isrp, op_pest_iarp);
+                Result result1 = new Result(ip.getAoaId(), ip.getOperationId(), ip.getPesticideId(), op_pest_ilp, op_pest_isrp, op_pest_iarp);
                 result.add(result1);
             }
         } catch (SQLException se) {
@@ -161,12 +155,12 @@
         JSONArray resultArr = new JSONArray();
         for (Result rs1 : result) {
             JSONArray tmpArr = new JSONArray();
-            tmpArr.put(JSONUtils.dataDesc("AoAId", rs1.AoAId, "Area of Analysis Identifier"));
-            tmpArr.put(JSONUtils.dataDesc("operation_id", rs1.operation_id, "Pesticide Application Operation Identifier"));
-            tmpArr.put(JSONUtils.dataDesc("op_pesticide_id", rs1.op_pesticide_id, "Pesticide identifier, EPA Pesticide Chemical Code (PC_CODE)"));
-            tmpArr.put(JSONUtils.dataDesc("op_pest_ilp", rs1.op_pest_ilp, "Operation Soil Pesticide Interaction Leaching Potential"));
-            tmpArr.put(JSONUtils.dataDesc("op_pest_isrp", rs1.op_pest_isrp, "Operation Soil Pesticide Interaction Solution Runoff Potential"));
-            tmpArr.put(JSONUtils.dataDesc("op_pest_iarp", rs1.op_pest_iarp, "Operation Soil Pesticide Interaction Adsorbed Runoff Potential"));
+            tmpArr.put(JSONUtils.dataDesc("AoAId", rs1.getAoaId(), "Area of Analysis Identifier"));
+            tmpArr.put(JSONUtils.dataDesc("operation_id", rs1.getOperationId(), "Pesticide Application Operation Identifier"));
+            tmpArr.put(JSONUtils.dataDesc("op_pesticide_id", rs1.getOpPesticideId(), "Pesticide identifier, EPA Pesticide Chemical Code (PC_CODE)"));
+            tmpArr.put(JSONUtils.dataDesc("op_pest_ilp", rs1.getOpPestIlp(), "Operation Soil Pesticide Interaction Leaching Potential"));
+            tmpArr.put(JSONUtils.dataDesc("op_pest_isrp", rs1.getOpPestIsrp(), "Operation Soil Pesticide Interaction Solution Runoff Potential"));
+            tmpArr.put(JSONUtils.dataDesc("op_pest_iarp", rs1.getOpPestIarp(), "Operation Soil Pesticide Interaction Adsorbed Runoff Potential"));
             resultArr.put(JSONUtils.dataDesc("pesticide summary", tmpArr, "Pest"));
         }
         putResult("operation", resultArr);

src/java/m/wqm/soilpestlosspot/V1_0.json

@@ -48,7 +48,7 @@
                     },
                     {
                         "name": "aoa_sarp",
-                        "value": "VERY LOW",
+                        "value": "LOW",
                         "Description": "Soil Pesticide Adsorbed Runoff Potential for the Area of Analysis"
                     },
                     {
@@ -100,7 +100,7 @@
                     },
                     {
                         "name": "aoa_sarp",
-                        "value": "VERY LOW",
+                        "value": "LOW",
                         "Description": "Soil Pesticide Adsorbed Runoff Potential for the Area of Analysis"
                     },
                     {
@@ -152,7 +152,7 @@
                     },
                     {
                         "name": "aoa_sarp",
-                        "value": "VERY LOW",
+                        "value": "LOW",
                         "Description": "Soil Pesticide Adsorbed Runoff Potential for the Area of Analysis"
                     },
                     {
@@ -204,7 +204,7 @@
                     },
                     {
                         "name": "aoa_sarp",
-                        "value": "VERY LOW",
+                        "value": "LOW",
                         "Description": "Soil Pesticide Adsorbed Runoff Potential for the Area of Analysis"
                     },
                     {
@@ -256,7 +256,7 @@
                     },
                     {
                         "name": "aoa_sarp",
-                        "value": "VERY LOW",
+                        "value": "LOW",
                         "Description": "Soil Pesticide Adsorbed Runoff Potential for the Area of Analysis"
                     },
                     {
@@ -308,7 +308,7 @@
                     },
                     {
                         "name": "aoa_sarp",
-                        "value": "VERY LOW",
+                        "value": "LOW",
                         "Description": "Soil Pesticide Adsorbed Runoff Potential for the Area of Analysis"
                     },
                     {