Displaying differences for changeset
 
display as  

src/java/m/wqm/nutappmgtscores/Crop.java

@@ -7,6 +7,8 @@
 import java.util.Date;
 import csip.utils.Dates;
 import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
 
 public class Crop {
 
@@ -36,8 +38,10 @@
     }
 
     public Date getCropPlantDate() throws Exception {
-        Date date = Dates.parse(cropPlantDate);
-        return date;
+        String[] parse = cropPlantDate.split("-");
+        Calendar date = new GregorianCalendar(Integer.parseInt(parse[0]), 
+                Integer.parseInt(parse[1]) - 1, Integer.parseInt(parse[2]));
+        return date.getTime();
     }
 
     public double getCropYield() {

src/java/m/wqm/nutappmgtscores/Nutrient.java

@@ -6,7 +6,9 @@
  */
 import csip.utils.Dates;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
+import java.util.GregorianCalendar;
 
 public class Nutrient {
 
@@ -21,8 +23,10 @@
     }
 
     public Date getApplicationDate() throws Exception {
-        Date date = Dates.parse(applicationDate);
-        return date;
+        String[] parse = applicationDate.split("-");
+        Calendar date = new GregorianCalendar(Integer.parseInt(parse[0]), 
+                Integer.parseInt(parse[1]) - 1, Integer.parseInt(parse[2]));
+        return date.getTime();
     }
 
     public boolean isIncorporated() {

src/java/m/wqm/nutappmgtscores/Result.java

@@ -6,19 +6,19 @@
  */
 public class Result {
 
-    int AoAId;
-    int nleach_app_mgt_score;
-    int nsurf_app_mgt_score;
-    int psurf_app_mgt_score;
-    int n_app_rate_score;
-    int n_app_timing_score;
-    int p_app_rate_score;
-    int p_app_timing_score;
-    int app_meth_score;
+    private int AoAId;
+    private int nleach_app_mgt_score;
+    private int nsurf_app_mgt_score;
+    private int psurf_app_mgt_score;
+    private int n_app_rate_score;
+    private int n_app_timing_score;
+    private int p_app_rate_score;
+    private int p_app_timing_score;
+    private int app_method_score;
 
     public Result(int AoAId, int nleach_app_mgt_score, int nsurf_app_mgt_score,
             int psurf_app_mgt_score, int n_app_rate_score, int n_app_timing_score,
-            int p_app_rate_score, int p_app_timing_score, int app_meth_score) {
+            int p_app_rate_score, int p_app_timing_score, int app_method_score) {
         this.AoAId = AoAId;
         this.nleach_app_mgt_score = nleach_app_mgt_score;
         this.nsurf_app_mgt_score = nsurf_app_mgt_score;
@@ -27,6 +27,42 @@
         this.n_app_timing_score = n_app_timing_score;
         this.p_app_rate_score = p_app_rate_score;
         this.p_app_timing_score = p_app_timing_score;
-        this.app_meth_score = app_meth_score;
+        this.app_method_score = app_method_score;
+    }
+    
+    public int getAoAId() {
+        return AoAId;
+    }
+    
+    public int getNleachAppMgtScore() {
+        return nleach_app_mgt_score;
+    }
+    
+    public int getNsurfAppMgtScore() {
+        return nsurf_app_mgt_score;
+    }
+    
+    public int getPsurfAppMgtScore() {
+        return psurf_app_mgt_score;
+    }
+    
+    public int getnAppRateScore() {
+        return n_app_rate_score;
+    }
+    
+    public int getnAppTimingScore() {
+        return n_app_timing_score;
+    }
+    
+    public int getpAppRateScore() {
+        return p_app_rate_score;
+    }
+    
+    public int getpAppTimingScore() {
+        return p_app_timing_score;
+    }
+    
+    public int getAppMethodScore() {
+        return app_method_score;
     }
 }
\ No newline at end of file

src/java/m/wqm/nutappmgtscores/V1_0.java

@@ -14,6 +14,7 @@
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Map;
 import javax.ws.rs.Path;
 import oms3.annotations.Description;
@@ -43,9 +44,12 @@
     // reading the inputs from the json file into input object and placing it in the arraylist
     protected void preProcess() throws Exception {
 
-        int AoAId = getIntParam("AoAId", 0);
+        int AoAId = getIntParam("aoa_id", 0);
         String p_soil_test_result = getStringParam("p_soil_test_result", "err");
         ArrayList<Crop> cropList = new ArrayList<>();
+        
+        //System.out.println("AoAId = " + AoAId);
+        //System.out.println("p_soil_test_result = " + p_soil_test_result);
 
         JSONArray cropIds = getJSONArrayParam("cropIds");
         for (int i = 0; i < cropIds.length(); i++) {
@@ -58,6 +62,11 @@
             double cropYield = JSONUtils.getDoubleParam(mgtCropId, "crop_yield", 0);
             String cropYieldUnits = JSONUtils.getStringParam(mgtCropId, "crop_yield_units", "err");
 
+            //System.out.println("cropId = " + cropId);
+            //System.out.println("lmod = " + lmod);
+            //System.out.println("cropPlantDate = " + cropPlantDate);
+           // System.out.println("cropYield = " + cropYield);
+            //System.out.println("cropYieldUnits = " + cropYieldUnits);
             ArrayList<Nutrient> nutrientApplicationList = new ArrayList<>();
             JSONArray applicationList = JSONUtils.getJSONArrayParam(mgtCropId, "applicationList");
             for (int j = 0; j < applicationList.length(); j++) {
@@ -65,12 +74,17 @@
                 String nutrient_application_date = JSONUtils.getStringParam(application, "nutrient_application_date", "err");
                 boolean incorporated = JSONUtils.getBooleanParam(application, "incorporated", false);
 
+                //tem.out.println("nutrient_application_date = " + nutrient_application_date);
+               // System.out.println("incorporated = " + incorporated);
                 ArrayList<NutrientApplied> nutrientAppliedList = new ArrayList<>();
                 JSONArray applicate = JSONUtils.getJSONArrayParam(application, "application");
                 for (int k = 0; k < applicate.length(); k++) {
                     Map<String, JSONObject> a = JSONUtils.preprocess(applicate.getJSONArray(k));
                     String nutrient_applied = JSONUtils.getStringParam(a, "nutrient_applied", "err");
                     double application_rate = JSONUtils.getDoubleParam(a, "application_rate", 0);
+                    //System.out.println("nutrient_applied = " + nutrient_applied);
+                    //System.out.println("application_rate = " + application_rate);
+                    
                     nutrientAppliedList.add(new NutrientApplied(nutrient_applied, application_rate));
                 }
                 nutrientApplicationList.add(new Nutrient(nutrient_application_date, incorporated, nutrientAppliedList));
@@ -78,6 +92,8 @@
             cropList.add(new Crop(cropId, lmod, cropPlantDate, cropYield, cropYieldUnits, nutrientApplicationList));
         }
         input.add(new m.wqm.nutappmgtscores.Input(AoAId, cropList, p_soil_test_result));
+        //tem.out.println(input.size());
+       // System.out.println("Input = " + input.get(0));
     }
 
     @Override
@@ -91,11 +107,14 @@
         try {
             Class.forName(CLASS_NAME);
             conn = DriverManager.getConnection(JDBC_TYPE + SERVER, USER, PASS);
+            //System.out.println("Closed = " + conn.isClosed());
             conn.setAutoCommit(false);
 
             statement = conn.createStatement();
 
             for (m.wqm.nutappmgtscores.Input ip : input) {
+                //System.out.println("In for 1");
+                
                 int n_app_timing_score = 100;
                 int p_app_timing_score = 100;
 
@@ -106,6 +125,7 @@
 
                 ArrayList<Crop> cropList = ip.getCropList();
                 for (Crop crop : cropList) {
+                    //System.out.println("Crop loop");
                     ArrayList<Nutrient> nutrientApplicationList = crop.getNutrientApplicationList();
 
                     //#If request payload crop is an LMOD vegetation, then convert it to a wqm_crop using the link table
@@ -120,11 +140,11 @@
                     }
 
                     //#Determine crop type of the crop
-                    query = "SELECT crop_type FROM wqm_crops WHERE wqm_crop_id=" + this_crop_id + ";";
+                    query = "SELECT wqm_crop_type FROM wqm_crops WHERE wqm_crop_id=" + this_crop_id + ";";
                     resultSet = statement.executeQuery(query);
                     String crop_type = "err";
                     while (resultSet.next()) {
-                        crop_type = resultSet.getString("crop_type");
+                        crop_type = resultSet.getString("wqm_crop_type");
                     }
 
                     //#Determine whether split nutrient applications or not
@@ -141,10 +161,15 @@
                         app_type = "split";
                     }
 
+                   // System.out.println("crop id" + this_crop_id);
+                   // System.out.println("crop type" + crop_type);
+                  //  System.out.println("app type" + app_type);
                     //If no nutrient_application_date (no nutrient applications for the crop)
                     int ncrop_app_rate_score = 0;
                     int pcrop_app_rate_score = 0;
                     if (nutrientApplicationList.isEmpty()) {
+                    //    System.out.println("nutrientApplicationList is empty");
+                        
                         //#Compute score for not fertilizing.
                         query = "SELECT app_mgt_score FROM wqm_nutrient_application_mgt_scores WHERE nutrient='" + "Nitrogen" + "' AND app_mgt_kind='" + "Rate" + "' AND app_mgt_factor='" + "None" + "';";
                         resultSet = statement.executeQuery(query);
@@ -178,12 +203,17 @@
                         }
                     } else { //Else #Compute N and P removal ratios
 
+                      //  System.out.println("nutrientApplicationList is not empty!!!");
+                        
                         double nrate = 0.0;
                         double prate = 0.0;
 
                         for (Nutrient nutrient : nutrientApplicationList) {
+                      //      System.out.println("In nutrientApplicationList for loop!!!");
+                            
                             ArrayList<NutrientApplied> nutrientAppliedList = nutrient.getNutrientAppliedList();
                             for (NutrientApplied nApplied : nutrientAppliedList) {
+                          //      System.out.println("nApplied = " + nApplied.getNutrientApplied());
                                 if (nApplied.getNutrientApplied().equals("Nitrogen")) {
                                     nrate = nrate + nApplied.getApplicationRate();
                                 } else {
@@ -285,12 +315,13 @@
                     int ncrop_app_timing_score = 0;
                     int pcrop_app_timing_score = 0;
                     for (Nutrient nutrient : nutrientApplicationList) {
-                        Date application_date = nutrient.getApplicationDate();
-                        long app_day_diff = Dates.diffInMillis(application_date, crop.getCropPlantDate());
+                        long app_day_diff = Dates.diffInMillis(crop.getCropPlantDate(), nutrient.getApplicationDate());
                         app_day_diff = TimeUnit.MICROSECONDS.convert(app_day_diff, TimeUnit.DAYS);
+                      //  System.out.println(app_day_diff);
 
                         ArrayList<NutrientApplied> nutrientAppliedList = nutrient.getNutrientAppliedList();
                         for (NutrientApplied nApplied : nutrientAppliedList) {
+                       //     System.out.println("In for nApplied");
                             switch (nApplied.getNutrientApplied()) {
                                 case "Nitrogen": {
                                     if (app_type.equals("split")) {
@@ -350,25 +381,28 @@
                                 }
                             }
                         }
+                  //      System.out.println("out of nApplied");
                     }
                     for (Nutrient nutrient : nutrientApplicationList) {
+                  //      System.out.println("final for loop");
                         //#If any nutrient application for any crop is not incorporated, the method score for the AoA is zero
                         if (!nutrient.isIncorporated()) {
                             app_method_score = 0;
                             break;
                         } else if (nutrient.isIncorporated()) { //#If all nutrient applications for all crops are incorporated, the method score for incorporation applies to the AoA
-                            query = "SELECT app_mgt_score FROM wqm_nutrient_application_mgt_scores WHERE app_mgt_kind='" + "Method" + "' AND app_mgt_factor='" + "incorporate" + ";";
+                            query = "SELECT app_mgt_score FROM wqm_nutrient_application_mgt_scores WHERE app_mgt_kind='" + "Method" + "' AND app_mgt_factor='" + "incorporate" + "';";
                             resultSet = statement.executeQuery(query);
                             while (resultSet.next()) {
-                                app_method_score = resultSet.getInt("app_method_score");
+                                app_method_score = resultSet.getInt("app_mgt_score");
 
                             }
 
                         }
 
                     }
-
+          //          System.out.println("Out of final loop");
                 }
+           //     System.out.println("Out");
                 //#Compute application management scores for nitrogen in groundwater, nitrogen in surface water, and phosphorus in surface water
                 int nleach_app_mgt_score = n_app_rate_score + n_app_timing_score + app_method_score;
                 int nsurf_app_mgt_score = n_app_rate_score + n_app_timing_score + app_method_score;
@@ -376,8 +410,12 @@
                 m.wqm.nutappmgtscores.Result result1 = new m.wqm.nutappmgtscores.Result(ip.getAoAId(), nleach_app_mgt_score, nsurf_app_mgt_score, psurf_app_mgt_score, n_app_rate_score, n_app_timing_score, p_app_rate_score, p_app_timing_score, app_method_score);
                 result.add(result1);
             }
+         //   System.out.println("out of for");
             conn.close();
+       //     System.out.println("closed = " + conn.isClosed());
         } catch (SQLException se) {
+      //      System.out.println(se.getCause());
+       //     System.out.println(se.getStackTrace());
             LOG.info("Did not open database for WQM-16!");
             LOG.info(se.getMessage());
         } finally {
@@ -397,17 +435,17 @@
         JSONArray resultArr = new JSONArray();
         for (m.wqm.nutappmgtscores.Result rs1 : result) {
             JSONArray tmpArr = new JSONArray();
-            tmpArr.put(JSONUtils.dataDesc("AoAId", rs1.AoAId, "Area of Analysis Identifier"));
-            tmpArr.put(JSONUtils.dataDesc("nleach_app_mgt_score", rs1.nleach_app_mgt_score, "Nitrogen Application Management Score for Mitigating Leaching Loss Potential"));
-            tmpArr.put(JSONUtils.dataDesc("nsurf_app_mgt_score", rs1.nsurf_app_mgt_score, "Nitrogen Application Management Score for Mitigating Surface Runoff Loss Potential"));
-            tmpArr.put(JSONUtils.dataDesc("psurf_app_mgt_score", rs1.psurf_app_mgt_score, "Phosphorus Application Management Score for Mitigating Surface Runoff Loss Potential"));
-            tmpArr.put(JSONUtils.dataDesc("n_app_rate_score", rs1.n_app_rate_score, "Nitrogen Application Rate Mitigation Score"));
-            tmpArr.put(JSONUtils.dataDesc("n_app_timing_score", rs1.n_app_timing_score, "Nitrogen Application Timing Mitigation Score"));
-            tmpArr.put(JSONUtils.dataDesc("p_app_rate_score", rs1.p_app_rate_score, "Phosphorus Application Rate Mitigation Score"));
-            tmpArr.put(JSONUtils.dataDesc("p_app_timing_score", rs1.p_app_timing_score, "Phosphorus Application Timing Mitigation Score"));
-            tmpArr.put(JSONUtils.dataDesc("app_meth_score", rs1.app_meth_score, "Nutrient Application Method Mitigation Score"));
+            tmpArr.put(JSONUtils.dataDesc("AoAId", rs1.getAoAId(), "Area of Analysis Identifier"));
+            tmpArr.put(JSONUtils.dataDesc("nleach_app_mgt_score", rs1.getNleachAppMgtScore(), "Nitrogen Application Management Score for Mitigating Leaching Loss Potential"));
+            tmpArr.put(JSONUtils.dataDesc("nsurf_app_mgt_score", rs1.getNsurfAppMgtScore(), "Nitrogen Application Management Score for Mitigating Surface Runoff Loss Potential"));
+            tmpArr.put(JSONUtils.dataDesc("psurf_app_mgt_score", rs1.getPsurfAppMgtScore(), "Phosphorus Application Management Score for Mitigating Surface Runoff Loss Potential"));
+            tmpArr.put(JSONUtils.dataDesc("n_app_rate_score", rs1.getnAppRateScore(), "Nitrogen Application Rate Mitigation Score"));
+            tmpArr.put(JSONUtils.dataDesc("n_app_timing_score", rs1.getnAppTimingScore(), "Nitrogen Application Timing Mitigation Score"));
+            tmpArr.put(JSONUtils.dataDesc("p_app_rate_score", rs1.getpAppRateScore(), "Phosphorus Application Rate Mitigation Score"));
+            tmpArr.put(JSONUtils.dataDesc("p_app_timing_score", rs1.getpAppTimingScore(), "Phosphorus Application Timing Mitigation Score"));
+            tmpArr.put(JSONUtils.dataDesc("app_method_score", rs1.getAppMethodScore(), "Nutrient Application Method Mitigation Score"));
             resultArr.put(JSONUtils.dataDesc("Nutrition Application Summary", tmpArr, "Nutrition Application Summary"));
         }
-        putResult("operation", resultArr);
+        putResult("Result", resultArr);
     }
 }

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

@@ -20,7 +20,7 @@
                     {
                         "name": "mgt_crop_id",
                         "description": "Crop Identifier, a crop can be a fallow period",
-                        "value": 1
+                        "value": 121
                     },
                     {
                         "name": "from_lmod",