Displaying differences for changeset
 
display as  

nbproject/build-impl.xml

 

nbproject/build-impl.xml~

 

nbproject/genfiles.properties

 

nbproject/project.properties

 

nbproject/project.xml

 

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

@@ -5,6 +5,7 @@
 import csip.utils.JSONUtils;
 import csip.utils.Dates;
 import csip.annotations.Polling;
+import csip.annotations.Resource;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -23,27 +24,29 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.codehaus.jettison.json.JSONException;
+import wqm.utils.DBResources;
+import static wqm.utils.DBResources.WQM_ID;
 
 @Name("WQM-16: Nutrient Application Management Scores (NutAppMgtScores)")
 @Description("This service computes scores for adjusting the rate, timing, and method of applying nutrients to mitigate nitrogen leaching, and nitrogen and phosphorus runoff loss potential.")
 @Path("m/nutappmgtscores/1.0")
 @Polling(first = 10000, next = 2000)
-
+@Resource( from = DBResources.class)
 public class V1_0 extends ModelDataService {
 
     //Response
-    private ArrayList<V1_0.Result> result;
+    private ArrayList<Result> result;
 
     //private class variables for this service
     private int AoAId = 0;
     private String p_soil_test_result = "err";
-    private ArrayList<V1_0.Crop> cropList;
+    private ArrayList<Crop> cropList;
     private String error_msg = "";
 
     @Override
     protected void preProcess() throws Exception {
 
-    if (error_msg.isEmpty()) {
+    
         AoAId = getIntParam("aoa_id", 0);
         p_soil_test_result = getStringParam("p_soil_test_result", "err");
         cropList = new ArrayList<>();
@@ -57,17 +60,17 @@
             applicationList = JSONUtils.getJSONArrayParam(mgtCropId, "applicationList");
         }
 
-        cropList.add(new V1_0.Crop(JSONUtils.getIntParam(mgtCropId, "mgt_crop_id", 0), JSONUtils.getStringParam(mgtCropId, "crop_plant_date", "err"),
+        cropList.add(new Crop(JSONUtils.getIntParam(mgtCropId, "mgt_crop_id", 0), JSONUtils.getStringParam(mgtCropId, "crop_plant_date", "err"),
             JSONUtils.getDoubleParam(mgtCropId, "crop_yield", 0), JSONUtils.getStringParam(mgtCropId, "crop_yield_units", "err"),
             applicationList, p_soil_test_result));
         }
 
         ValidateInput();
-    }
+    
     }
 
     @Override
-    protected String process() throws Exception {
+    protected void doProcess() throws Exception {
     String ret_val = EXEC_OK;
     int n_app_timing_score = 100;
     int p_app_timing_score = 100;
@@ -76,17 +79,15 @@
     int p_app_rate_score = 0;
     int this_crop_id = 0;
     String query;
-    ResultSet resultSet;
-
+    
     if (!error_msg.isEmpty()) {
         ret_val = error_msg;
     } else {
         result = new ArrayList<>();
 
-        try (
-            Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
-            Statement statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);) {
-        for (V1_0.Crop crop : cropList) {
+     try (Connection conn = getResourceJDBC(WQM_ID);
+                Statement statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) {
+        for (Crop crop : cropList) {
 
             String crop_type = crop.getCropType();
 //////TODO:  Remember to check for errors from the classes....   ///////                    
@@ -98,8 +99,8 @@
             }
 
             //Cummulative sum of N and P application management scores over all crops for the AoA
-            n_app_rate_score += app_rate_scores[V1_0.Crop.N_APP_RATE_SCORE];
-            p_app_rate_score += app_rate_scores[V1_0.Crop.P_APP_RATE_SCORE];
+            n_app_rate_score += app_rate_scores[Crop.N_APP_RATE_SCORE];
+            p_app_rate_score += app_rate_scores[Crop.P_APP_RATE_SCORE];
 
             //#Compute N and P application timing scores for the crop and update timing scores for the AoA
             int[] app_time_scores = crop.getNutrientApplicationTimingScores();
@@ -110,12 +111,12 @@
                         //  There is a problem with the logic of the specification here...It does not take into account the actual timing of applications when
             //  there are mulitple crops and multiple years invovled....these final values are probably not correct.  The "-1" below is placed here
             //  in an attempt to fix the missing database values problem that also exists with this logic at the nutrient level.
-            if ((app_time_scores[V1_0.Crop.N_APP_TIMING_SCORE] < n_app_timing_score) || (n_app_timing_score == -1)) {
-                n_app_timing_score = app_time_scores[V1_0.Crop.N_APP_TIMING_SCORE];
+            if ((app_time_scores[Crop.N_APP_TIMING_SCORE] < n_app_timing_score) || (n_app_timing_score == -1)) {
+                n_app_timing_score = app_time_scores[Crop.N_APP_TIMING_SCORE];
             }
 
-            if ((app_time_scores[V1_0.Crop.P_APP_TIMING_SCORE] < p_app_timing_score) || (p_app_timing_score == -1)) {
-                p_app_timing_score = app_time_scores[V1_0.Crop.P_APP_TIMING_SCORE];
+            if ((app_time_scores[Crop.P_APP_TIMING_SCORE] < p_app_timing_score) || (p_app_timing_score == -1)) {
+                p_app_timing_score = app_time_scores[Crop.P_APP_TIMING_SCORE];
             }
 
             //#If any nutrient application for any crop is not incorporated, the method score for the AoA is zero
@@ -133,7 +134,7 @@
         //  If all crops' nutrients were incorporated this value will still be -1
         if (app_method_score == -1) {
             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);
+          try(ResultSet  resultSet = statement.executeQuery(query)){
             if (resultSet.first()) {
             app_method_score = resultSet.getInt("app_mgt_score");
             }
@@ -143,24 +144,21 @@
         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;
         int psurf_app_mgt_score = p_app_rate_score + p_app_timing_score + app_method_score;
-        result.add(new V1_0.Result(AoAId, 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));
-
-        conn.close();
+        result.add(new Result(AoAId, 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));
+                }
         } catch (SQLException se) {
-        LOG.info("Did not open database for WQM-16!");
-        LOG.info(se.getMessage());
-        ret_val += se.getMessage();
+        throw new ServiceException("SQLException",se);
         } catch (Exception ex) {
-        ret_val += ex.getMessage();
+        throw new ServiceException("Exception",ex);
         }
     }
-    return (error_msg.isEmpty() ? EXEC_OK : error_msg);
+    
     }
 
     @Override
     //writing the results back to JSON
     protected void postProcess() throws Exception {
-    for (V1_0.Result rs1 : result) {
+    for (Result rs1 : result) {
         JSONArray tmpArr = new JSONArray();
         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"));
@@ -176,7 +174,7 @@
     }
 
     private boolean ValidateInput() {
-    for (V1_0.Crop tCrop : cropList) {
+    for (Crop tCrop : cropList) {
         if (!tCrop.validate()) {
         error_msg += "; " + tCrop.getErrorMsg();
         }
@@ -198,8 +196,8 @@
     private Date plantDate;
     private double cropYield;
     private String cropYieldUnits;
-    private ArrayList<V1_0.Crop.NutrientApplication> nutrientApplicationList;
-    private V1_0.Result calc_result;
+    private ArrayList<Crop.NutrientApplication> nutrientApplicationList;
+    private Result calc_result;
     private String cropType = "";
     private String error_msg = "";
     private Boolean multipleNutrientApplication = false;
@@ -211,90 +209,87 @@
     private String pSoilTestResult = "None";
 
     public Crop(int mgtCropId, String cropPlantDate, double cropYield,
-        String cropYieldUnits, JSONArray applicationList, String pSoilTestResult) {
+        String cropYieldUnits, JSONArray applicationList, String pSoilTestResult) throws ServiceException {
         this.mgtCropId = mgtCropId;
         this.cropPlantDate = cropPlantDate;
         this.cropYield = cropYield;
         this.cropYieldUnits = cropYieldUnits;
         this.pSoilTestResult = pSoilTestResult;
 
-        nutrientApplicationList = new ArrayList<V1_0.Crop.NutrientApplication>();
+        nutrientApplicationList = new ArrayList<Crop.NutrientApplication>();
 
         try {
         plantDate = getCropPlantDate();
         if (null != applicationList) {
             for (int j = 0; j < applicationList.length(); j++) {
             Map<String, JSONObject> application = JSONUtils.preprocess(applicationList.getJSONArray(j));
-            nutrientApplicationList.add(new V1_0.Crop.NutrientApplication(JSONUtils.getStringParam(application, "nutrient_application_date", "err"), JSONUtils.getStringParam(application, "incorporated", ""), JSONUtils.getJSONArrayParam(application, "application")));
+            nutrientApplicationList.add(new Crop.NutrientApplication(JSONUtils.getStringParam(application, "nutrient_application_date", "err"), JSONUtils.getStringParam(application, "incorporated", ""), JSONUtils.getJSONArrayParam(application, "application")));
             }
         }
         } catch (Exception ex) {
-        error_msg += "Cannot process list of applied nutrients.  " + ex.getMessage();
+            throw new ServiceException("Exception",ex);
         }
 
         multipleNutrientApplication = (nutrientApplicationList.size() > 1);
-        this.appRateScore[N_APP_RATE_SCORE] = this.appRateScore[P_APP_RATE_SCORE] = -1;
-        this.appNutrientTimingScore[N_APP_TIMING_SCORE] = this.appNutrientTimingScore[P_APP_TIMING_SCORE] = -1;
+        appRateScore[N_APP_RATE_SCORE] = appRateScore[P_APP_RATE_SCORE] = -1;
+        appNutrientTimingScore[N_APP_TIMING_SCORE] = appNutrientTimingScore[P_APP_TIMING_SCORE] = -1;
     }
 
     //Get methods
     public int getMgtCropId() {
-        return this.mgtCropId;
+        return mgtCropId;
     }
 
     public String getErrorMsg() {
-        for (V1_0.Crop.NutrientApplication nutrientApplied : this.nutrientApplicationList) {
+        for (Crop.NutrientApplication nutrientApplied : nutrientApplicationList) {
         error_msg += nutrientApplied.getErrorMsg();
         }
         return error_msg;
     }
 
-    public String getCropType() {
+    public String getCropType() throws ServiceException {
         if ((cropType.isEmpty()) && (error_msg.isEmpty())) {
-        ResultSet resultSet;
+        
         String query = "SELECT wqm_crop_type FROM wqm_crops WHERE wqm_crop_id=" + mgtCropId + " AND wqm_crop_units='" + cropYieldUnits + "';";
-        try (
-            Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
-            Statement statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);) {
-            resultSet = statement.executeQuery(query);
+        try (Connection conn = getResourceJDBC(WQM_ID);
+                Statement statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) {
+        try( ResultSet  resultSet = statement.executeQuery(query)){
             if (!resultSet.first()) {
             error_msg += "That crop, " + mgtCropId + ", and crop yield units, " + cropYieldUnits + ", was not found in the database";
             } else {
             cropType = resultSet.getString("wqm_crop_type");
             }
+                }
         } catch (SQLException ex) {
-            error_msg += ex.getMessage();
-        } catch (ServiceException ex) {
-            Logger.getLogger(V1_0.class.getName()).log(Level.SEVERE, null, ex);
+                    throw new ServiceException("SQLException",ex);
         }
         }
         return cropType;
     }
 
     public final Date getCropPlantDate() throws Exception {
-        String[] parse = this.cropPlantDate.split("-");
+        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() {
-        return this.cropYield;
+        return cropYield;
     }
 
     public String getCropYieldUnits() {
-        return this.cropYieldUnits;
+        return cropYieldUnits;
     }
 
     public ArrayList getNutrientApplicationList() {
-        return this.nutrientApplicationList;
+        return nutrientApplicationList;
     }
 
     public int[] getNutrientApplicationRateScores() {
         if ((appRateScore[N_APP_RATE_SCORE] < 0) || (appRateScore[P_APP_RATE_SCORE] < 0)) {
-        try (
-            Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
-            Statement statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);) {
+        try (Connection conn = getResourceJDBC(WQM_ID);
+                Statement statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) {
             if (nutrientApplicationList.isEmpty()) {
             ResultSet resultSet;
 
@@ -326,9 +321,9 @@
             int ncrop_app_rate_score = 0;
             int pcrop_app_rate_score = 0;
 
-            for (V1_0.Crop.NutrientApplication nutrient : nutrientApplicationList) {
-                ArrayList<V1_0.Crop.NutrientApplication.Nutrient> nutrientAppliedList = nutrient.getNutrientList();
-                for (V1_0.Crop.NutrientApplication.Nutrient nApplied : nutrientAppliedList) {
+            for (Crop.NutrientApplication nutrient : nutrientApplicationList) {
+                ArrayList<Crop.NutrientApplication.Nutrient> nutrientAppliedList = nutrient.getNutrientList();
+                for (Crop.NutrientApplication.Nutrient nApplied : nutrientAppliedList) {
                 switch (nApplied.getNutrientApplied()) {  //Note:  This switch requires JDK 1.7 or above
                     case "Nitrogen":
                     nrate += nApplied.getApplicationRate();
@@ -419,19 +414,19 @@
         } catch (ServiceException ex) {
             Logger.getLogger(V1_0.class.getName()).log(Level.SEVERE, null, ex);
         }
-        }
+            }
 
-        return this.appRateScore;
+        return appRateScore;
     }
 
-    public int[] getNutrientApplicationTimingScores() {
+    public int[] getNutrientApplicationTimingScores() throws ServiceException {
         if ((appNutrientTimingScore[N_APP_TIMING_SCORE] < 0) || (appNutrientTimingScore[P_APP_TIMING_SCORE] < 0)) {
         int tempNScore = 100;
         int tempPScore = 100;
 
-        for (V1_0.Crop.NutrientApplication nutrientApplication : this.nutrientApplicationList) {
+        for (Crop.NutrientApplication nutrientApplication : nutrientApplicationList) {
             //  Call each application compare its results to the last and adjust main score if necessary.
-            int[] tempAppTimingScores = nutrientApplication.getNutrientTimingScores(this.multipleNutrientApplication);
+            int[] tempAppTimingScores = nutrientApplication.getNutrientTimingScores(multipleNutrientApplication);
 
             if (tempAppTimingScores[N_APP_TIMING_SCORE] < tempNScore) {
             tempNScore = tempAppTimingScores[N_APP_TIMING_SCORE];
@@ -446,12 +441,12 @@
         appNutrientTimingScore[N_APP_TIMING_SCORE] = tempNScore;
         }
 
-        return this.appNutrientTimingScore;
+        return appNutrientTimingScore;
     }
 
     public Boolean allNutrientsIncorporated() {
         Boolean ret_val = true;
-        for (V1_0.Crop.NutrientApplication nutrientApplication : this.nutrientApplicationList) {
+        for (Crop.NutrientApplication nutrientApplication : nutrientApplicationList) {
         if (!nutrientApplication.allNutrientsIncorporated()) {
             ret_val = false;
             break;
@@ -468,7 +463,7 @@
     }
 
     public Boolean validate() {
-        for (V1_0.Crop.NutrientApplication tNutrientApplication : nutrientApplicationList) {
+        for (Crop.NutrientApplication tNutrientApplication : nutrientApplicationList) {
         if (!tNutrientApplication.validate()) {
             error_msg += "; " + tNutrientApplication.getErrorMsg();
         }
@@ -482,65 +477,64 @@
 
         class Nutrient {
 
-        private String error_msg = "";
         private final String nutrientApplied;
         private final double applicationRate;
 
-        Nutrient(String nutrientApplied, double applicationRate) {
+        Nutrient(String nutrientApplied, double applicationRate) throws ServiceException {
             this.nutrientApplied = nutrientApplied;
             this.applicationRate = applicationRate;
 
             if (!nutrientApplied.equals("Nitrogen") && !nutrientApplied.equals("Phosphorus")) {
-            this.error_msg += "Invalid input data.  Bad nutrient name";
+              throw new ServiceException("Invalid input data.  Bad nutrient name");
             }
         }
 
         //Get Methods
         public String getNutrientApplied() {
-            return this.nutrientApplied;
+            return nutrientApplied;
         }
 
         public double getApplicationRate() {
-            return this.applicationRate;
+            return applicationRate;
         }
 
         public String getErrorMsg() {
-            return this.error_msg;
+            return error_msg;
         }
 
         public Boolean validate() {
-            return (this.error_msg.isEmpty());
+            return (error_msg.isEmpty());
         }
         }
         private String error_msg = "";
         private String applicationDate;
         private boolean incorporated;
-        private ArrayList<V1_0.Crop.NutrientApplication.Nutrient> nutrientList;
+        private ArrayList<Crop.NutrientApplication.Nutrient> nutrientList;
         private int appMethodScore = 0;
         private int[] nutrientTimingScores = new int[2];
 
-        NutrientApplication(String applicationDate, String incorporated, JSONArray applications) {
+        NutrientApplication(String applicationDate, String incorporated, JSONArray applications) throws ServiceException {
         this.applicationDate = applicationDate;
         nutrientTimingScores[N_APP_TIMING_SCORE] = nutrientTimingScores[P_APP_TIMING_SCORE] = -1;
         if ((!"true".equalsIgnoreCase(incorporated)) && (!"false".equalsIgnoreCase(incorporated))) {
-            this.error_msg += "Invalid incorporation value for nutrient application " + applicationDate;
-        } else {
+        throw new ServiceException("Invalid incorporation value for nutrient application " + applicationDate);
+                } else {
             this.incorporated = Boolean.parseBoolean(incorporated);
             nutrientList = new ArrayList<>();
             try {
             for (int k = 0; k < applications.length(); k++) {
                 Map<String, JSONObject> nutrient = JSONUtils.preprocess(applications.getJSONArray(k));
-                nutrientList.add(new V1_0.Crop.NutrientApplication.Nutrient(JSONUtils.getStringParam(nutrient, "nutrient_applied", "err"), JSONUtils.getDoubleParam(nutrient, "application_rate", 0)));
+                nutrientList.add(new Crop.NutrientApplication.Nutrient(JSONUtils.getStringParam(nutrient, "nutrient_applied", "err"), JSONUtils.getDoubleParam(nutrient, "application_rate", 0)));
             }
             } catch (JSONException ex) {
-            this.error_msg += "Cannot process applied nutrient list.  " + ex.getMessage();
+         throw new ServiceException("JSONException",ex);
             }
         }
         }
 
         //Get Methods
         public Date getApplicationDate() throws Exception {
-        String[] parse = this.applicationDate.split("-");
+        String[] parse = applicationDate.split("-");
         //Some say should set to use UTC first...do we wanna do that?
         Calendar date = new GregorianCalendar(Integer.parseInt(parse[0]),
             Integer.parseInt(parse[1]) - 1, Integer.parseInt(parse[2]));
@@ -548,45 +542,44 @@
         }
 
         public boolean isIncorporated() {
-        return this.incorporated;
+        return incorporated;
         }
 
         public ArrayList getNutrientList() {
-        return this.nutrientList;
+        return nutrientList;
         }
 
         public String getErrorMsg() {
-        for (V1_0.Crop.NutrientApplication.Nutrient nutrient : this.nutrientList) {
-            this.error_msg += nutrient.getErrorMsg();
+        for (Crop.NutrientApplication.Nutrient nutrient : nutrientList) {
+            error_msg += nutrient.getErrorMsg();
         }
-        return this.error_msg;
+        return error_msg;
         }
 
         public Boolean validate() {
-        for (V1_0.Crop.NutrientApplication.Nutrient nutrient : nutrientList) {
+        for (Crop.NutrientApplication.Nutrient nutrient : nutrientList) {
             if (!nutrient.validate()) {
-            this.error_msg += "; " + nutrient.getErrorMsg();
+            error_msg += "; " + nutrient.getErrorMsg();
             }
         }
-        return (this.error_msg.isEmpty());
+        return (error_msg.isEmpty());
         }
 
-        public int[] getNutrientTimingScores(Boolean split) {
+        public int[] getNutrientTimingScores(Boolean split) throws ServiceException {
         if ((nutrientTimingScores[N_APP_TIMING_SCORE] < 0) || (nutrientTimingScores[P_APP_TIMING_SCORE] < 0)) {
             int tempNScore = 100;
             int tempPScore = 100;
-            ResultSet resultSet;
-            for (V1_0.Crop.NutrientApplication.Nutrient nutrient : nutrientList) {
+           
+            for (Crop.NutrientApplication.Nutrient nutrient : nutrientList) {
             int app_timing_score;
-            try (
-                Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
-                Statement statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);) {
+            try (Connection conn = getResourceJDBC(WQM_ID);
+                Statement statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) {
                 long app_day_diff = Dates.diffInMillis(getCropPlantDate(), getApplicationDate());
                 app_day_diff = TimeUnit.MILLISECONDS.toDays(app_day_diff);
                 String query = "SELECT app_mgt_score FROM wqm_nutrient_application_mgt_scores WHERE nutrient='";
                 query += nutrient.getNutrientApplied() + "' ";
                 query += "AND app_mgt_kind='Timing' AND app_mgt_factor='" + (split ? "split" : "nosplit") + "'AND days_fr_plant_1 <= " + app_day_diff + "AND days_fr_plant_2 > " + app_day_diff + ";";
-                resultSet = statement.executeQuery(query);
+              try( ResultSet  resultSet = statement.executeQuery(query)){
                 if (!resultSet.first()) {
                 app_timing_score = -1;
                 } else {
@@ -604,12 +597,13 @@
                     }
                     break;
                 default:
-                    this.error_msg += "Invalid nutrient name specified";
+                    error_msg += "Invalid nutrient name specified";
                 }
+                          }
             } catch (Exception ex) {
-                this.error_msg += "Cannot calculate nutrient application timing scores: " + ex.getMessage();
-            }
-            if (this.error_msg.isEmpty()) {
+            throw new ServiceException("Exception",ex);
+                        }
+            if (error_msg.isEmpty()) {
                 nutrientTimingScores[N_APP_TIMING_SCORE] = tempNScore;
                 nutrientTimingScores[P_APP_TIMING_SCORE] = tempPScore;
             }
@@ -619,7 +613,7 @@
         }
 
         public Boolean allNutrientsIncorporated() {
-        return this.incorporated;
+        return incorporated;
         }
     }
     }
@@ -652,39 +646,39 @@
 
     //Getter Methods
     public int getAoAId() {
-        return this.AoAId;
+        return AoAId;
     }
 
     public int getNleachAppMgtScore() {
-        return this.nleach_app_mgt_score;
+        return nleach_app_mgt_score;
     }
 
     public int getNsurfAppMgtScore() {
-        return this.nsurf_app_mgt_score;
+        return nsurf_app_mgt_score;
     }
 
     public int getPsurfAppMgtScore() {
-        return this.psurf_app_mgt_score;
+        return psurf_app_mgt_score;
     }
 
     public int getnAppRateScore() {
-        return this.n_app_rate_score;
+        return n_app_rate_score;
     }
 
     public int getnAppTimingScore() {
-        return this.n_app_timing_score;
+        return n_app_timing_score;
     }
 
     public int getpAppRateScore() {
-        return this.p_app_rate_score;
+        return p_app_rate_score;
     }
 
     public int getpAppTimingScore() {
-        return this.p_app_timing_score;
+        return p_app_timing_score;
     }
 
     public int getAppMethodScore() {
-        return this.app_method_score;
+        return app_method_score;
     }
     }
 

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

@@ -1,8 +1,8 @@
 package m.wqm.nuttechscores;
 
 import csip.ModelDataService;
-import static csip.ModelDataService.EXEC_OK;
 import csip.ServiceException;
+import csip.annotations.Resource;
 import java.util.ArrayList;
 import javax.ws.rs.Path;
 import oms3.annotations.Description;
@@ -14,6 +14,8 @@
 import java.sql.*;
 import java.util.logging.Level;
 import org.codehaus.jettison.json.JSONException;
+import wqm.utils.DBResources;
+import static wqm.utils.DBResources.WQM_ID;
 
 /**
  * @version 1.0
@@ -24,41 +26,39 @@
 @Name("WQM-14: Nutrient Technique Scores (NutTechScores)")
 @Description("This service computes scores for techniques applied to mitigate nitrogen leaching, nitrogen runoff, and phosphorus runoff loss potential")
 @Path("m/nut_tech_scores/1.0")
-
+@Resource(from = DBResources.class)
 public class V1_0 extends ModelDataService {
 
-    private ArrayList<V1_0.Input> components; // store the set of all input soilcomponents as objects
-    private ArrayList<V1_0.Result1> result1;  // 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
     private int aoaId;
-    private String error_msg;
-
+   
     @Override
     protected void preProcess() {
-        this.error_msg = "";
-        this.components = new ArrayList<V1_0.Input>();
+        
+        components = new ArrayList<Input>();
         try {
             JSONArray groups = getJSONArrayParam("pestcomponents");
             for (int i = 0; i < groups.length(); i++) {
                 Map<String, JSONObject> group = JSONUtils.preprocess(groups.getJSONArray(i));
-                this.aoaId = JSONUtils.getIntParam(group, "AoAid", 0);
+                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", null);
                 String plan_techn_discrim = JSONUtils.getStringParam(group, "plan_techn_discrim", null);
-                this.components.add(new V1_0.Input(this.aoaId, plan_techn_id,
+                components.add(new Input(aoaId, plan_techn_id,
                         plan_techn_discrim_type, plan_techn_discrim));
             }
         } catch (ServiceException | JSONException e) {
-            this.error_msg = "Cannot process the request JSON: " + e.getMessage();
-            LOG.log(Level.SEVERE, this.error_msg);
+            LOG.log(Level.SEVERE,"Cannot process the request JSON",e);
         }
     }
 
     @Override
-    protected String process() {
-        result1 = new ArrayList<V1_0.Result1>();
-        try (Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
-                Statement statement = conn.createStatement();) {
-            conn.setAutoCommit(false);
+    protected void doProcess() throws ServiceException {
+        result1 = new ArrayList<Result1>();
+        try (Connection conn = getResourceJDBC(WQM_ID);
+            Statement statement = conn.createStatement()) {
+            
             int nleach_techn_score = 0;
             int nleach_avoid_techn_score = 0;
             int nleach_control_techn_score = 0;
@@ -72,7 +72,7 @@
             int psurf_control_techn_score = 0;
             int psurf_trap_techn_score = 0;
 
-            for (V1_0.Input ip : components) {
+            for (Input ip : components) {
                 String q1;
                 String q2;
                 q1 = "SELECT nut_tech_score FROM wqm_nutrient_technique_scores "
@@ -214,7 +214,7 @@
                     psurf_trap_techn_score += trap_techn_score;
                 }
             }
-            result1.add(new V1_0.Result1(aoaId, nleach_techn_score,
+            result1.add(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,
@@ -222,20 +222,18 @@
                     psurf_control_techn_score, psurf_trap_techn_score));
 
         } catch (ServiceException | SQLException se) {
-            this.error_msg += "Database connection error: " + se.getMessage();
-            LOG.info("Did not open database for WQM-14!");
-            LOG.info(se.getMessage());
+           throw new ServiceException("SQLException",se);
         }
 
-        return (this.error_msg.isEmpty() ? EXEC_OK : this.error_msg);
+        
     }
 
     @Override
     //writing the results back to JSON
-    protected void postProcess() {
+    protected void postProcess() throws ServiceException {
         try {
             JSONArray result1Arr = new JSONArray();
-            for (V1_0.Result1 rs1 : result1) {
+            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"));
@@ -254,8 +252,7 @@
             }
             putResult("operation", result1Arr);
         } catch (JSONException e) {
-            this.error_msg = "Cannot process the response JSON: " + e.getMessage();
-            LOG.info(e.getMessage());
+            throw new ServiceException("JSONException",e);
         }
     }
 

src/java/m/wqm/pesthazrating/V1_0.java

@@ -7,6 +7,7 @@
 import csip.ModelDataService;
 import static csip.ModelDataService.EXEC_OK;
 import csip.ServiceException;
+import csip.annotations.Resource;
 import csip.utils.JSONUtils;
 import java.sql.Connection;
 import java.sql.ResultSet;
@@ -20,6 +21,8 @@
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
+import wqm.utils.DBResources;
+import static wqm.utils.DBResources.WQM_ID;
 
 /**
  *
@@ -29,12 +32,12 @@
 @Name("WQM-11: Pesticide Hazard Ratings (PestHazRating)")
 @Description("This service computes pesticide hazard ratings for leaching, solution runoff, and adsorbed runoff for each pesticide applied in an area of analysis, and then computes hazard ratings for each concern representing the area of analysis (AoA). The service consumes soil/pesticide interaction loss potentials from the WQM-10 service to compute the hazard ratings, which are used later by the WQM-13 service to compute mitigation threshold scores.")
 @Path("m/pest_hazrating/1.0")
-
+@Resource(from = DBResources.class)
 public class V1_0 extends ModelDataService{
     
   
-    private ArrayList<V1_0.Input> components=new ArrayList<>(); // store the set of all input soilcomponents as objects
-    private ArrayList<V1_0.Result1> result1=new ArrayList<>();  // store the result as objects
+    private ArrayList<Input> components=new ArrayList<>(); // store the set of all input soilcomponents as objects
+    private ArrayList<Result1> result1=new ArrayList<>();  // store the result as objects
     private String aoa_phr_leach_human;
     private String aoa_phr_leach_matcfish;
     private String aoa_phr_sorun_human;
@@ -42,22 +45,22 @@
     private String aoa_phr_adrun_human;
     private String aoa_phr_adrun_stvfish;
     
-    private String error_msg;
+   
     
     
     @Override
         // reading the inputs from the json file into input object and placing it in the arraylist
         protected void preProcess() throws Exception {
-            this.aoa_phr_leach_human="";
-            this.aoa_phr_leach_matcfish="";
-            this.aoa_phr_sorun_human="";
-            this.aoa_phr_sorun_matcfish="";
-            this.aoa_phr_adrun_human="";
-            this.aoa_phr_adrun_stvfish="";            
-            this.error_msg = "";
+            aoa_phr_leach_human="";
+            aoa_phr_leach_matcfish="";
+            aoa_phr_sorun_human="";
+            aoa_phr_sorun_matcfish="";
+            aoa_phr_adrun_human="";
+            aoa_phr_adrun_stvfish="";            
+           
             
-            this.components=new ArrayList<>(); 
-            this.result1=new ArrayList<>();  
+            components=new ArrayList<>(); 
+            result1=new ArrayList<>();  
             
             try{
                 JSONArray groups = getJSONArrayParam("pestcomponents");
@@ -72,25 +75,24 @@
                     double ai_eathuman=JSONUtils.getDoubleParam(group,"ai_eathuman",0);
                     double ai_eatmatc=JSONUtils.getDoubleParam(group,"ai_eatmatc",0);
                     double ai_koc=JSONUtils.getDoubleParam(group,"ai_koc",0);
-                    components.add(new V1_0.Input(operation_id,op_pest_id,op_pest_ilp,op_pest_isrp,op_pest_iarp,ai_eathuman,ai_eatmatc,ai_koc));
+                    components.add(new Input(operation_id,op_pest_id,op_pest_ilp,op_pest_isrp,op_pest_iarp,ai_eathuman,ai_eatmatc,ai_koc));
                 }
             }
             catch( ServiceException | JSONException ex ){
-                this.error_msg = "Cannot read input JSON: " + ex.getMessage();
-                LOG.warning( this.error_msg );
-            }            
+                throw new ServiceException("JSONException",ex);
+             }            
         }
         
 
     @Override
-        protected String process() 
+        protected void doProcess() throws ServiceException 
         {
             String eat_rating_human=null;
-            if ( this.error_msg.isEmpty() ){            
-                try(Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
-                    Statement statement = conn.createStatement();){
                     
-                    for(V1_0.Input ip:components){                    
+             try (Connection conn = getResourceJDBC(WQM_ID);
+                Statement statement = conn.createStatement()) {
+                 
+                    for(Input ip:components){                    
                         if(ip.ai_eathuman<1){
                             eat_rating_human="EXTRA HIGH";
                         }
@@ -186,29 +188,23 @@
                         while(results.next()){
                             op_phr_sorun_matcfish=results.getString("wqm_phr");
                         }
-                        result1.add(new V1_0.Result1(ip.operation_id,ip.op_pest_id,op_phr_leach_human,op_phr_leach_matcfish,op_phr_sorun_human,op_phr_sorun_matcfish,op_phr_adrun_human,op_phr_adrun_stvfish));                        
+                        result1.add(new Result1(ip.operation_id,ip.op_pest_id,op_phr_leach_human,op_phr_leach_matcfish,op_phr_sorun_human,op_phr_sorun_matcfish,op_phr_adrun_human,op_phr_adrun_stvfish));                        
                     }   
                     
                     calAoANutSLP(result1); 
                 }
                 catch( ServiceException | SQLException ex ){
-                    this.error_msg = "Cannot process your request: " + ex.getMessage();
-                    LOG.warning( this.error_msg );
-                }
-                
-
-            }
-        
-        return ( this.error_msg.isEmpty()? EXEC_OK : this.error_msg );       
+                    throw new ServiceException("SQLException", ex);
+                }          
     }
     @Override
     //writing the results back to JSON
     protected void postProcess() throws Exception 
     {
-        if ( this.error_msg.isEmpty() ){
+        
             try{
                 JSONArray result1Arr = new JSONArray();
-                for(V1_0.Result1 rs1:result1)
+                for(Result1 rs1:result1)
                 {
                     JSONArray tmpArr = new JSONArray();
                     tmpArr.put(JSONUtils.dataDesc("operation_id", rs1.operation_id, "operation identifier"));
@@ -232,19 +228,18 @@
             }
             catch (JSONException ex )
             {
-                this.error_msg = "Cannot create output JSON: " + ex.getMessage();
-                LOG.warning( this.error_msg );
+               throw new ServiceException("JSONException", ex);
             }
-        }
+        
     }               
     
     // calculate the aoa_nslp 
-    void calAoANutSLP(ArrayList<V1_0.Result1> source){
+    void calAoANutSLP(ArrayList<Result1> source){
         int phr_leach_high = 1;
         int phr_leach_new = 1;
       //  #Compute pesticide hazard rating for Pesticide Leaching – Human concern
         
-        for(V1_0.Result1 rs1:source){
+        for(Result1 rs1:source){
             switch (rs1.op_phr_leach_human) {
                 case "EXTRA HIGH":
                     phr_leach_new=5;
@@ -274,7 +269,7 @@
         phr_leach_high=1;
       //  #Compute pesticide hazard rating for Pesticide Leaching – Fish concern
         
-        for(V1_0.Result1 rs1:source){
+        for(Result1 rs1:source){
             switch (rs1.op_phr_leach_matcfish) {
                 case "EXTRA HIGH":
                     phr_leach_new=5;
@@ -302,7 +297,7 @@
         phr_leach_high=1;
       //  #Compute pesticide hazard rating for Pesticide Solution Runoff – Human concern 
         
-        for(V1_0.Result1 rs1:source){
+        for(Result1 rs1:source){
             switch (rs1.op_phr_sorun_human) {
                 case "EXTRA HIGH":
                     phr_leach_new=4;
@@ -329,7 +324,7 @@
         phr_leach_high=1;
       //  #Compute pesticide hazard rating for Pesticide Solution Runoff – Fish concern 
         
-        for(V1_0.Result1 rs1:source){
+        for(Result1 rs1:source){
             switch (rs1.op_phr_sorun_matcfish) {
                 case "EXTRA HIGH":
                     phr_leach_new=4;
@@ -356,7 +351,7 @@
         phr_leach_high=1;
       // #Compute pesticide hazard rating for Pesticide Adsorbed Runoff – Human Concern 
         
-        for(V1_0.Result1 rs1:source){
+        for(Result1 rs1:source){
             switch (rs1.op_phr_adrun_human) {
                 case "EXTRA HIGH":
                     phr_leach_new=4;
@@ -383,7 +378,7 @@
         phr_leach_high=1;
       //  #Compute pesticide hazard rating for Pesticide Absorbed Runoff – Fish concern 
         
-        for(V1_0.Result1 rs1:source){
+        for(Result1 rs1:source){
             switch (rs1.op_phr_adrun_stvfish) {
                 case "EXTRA HIGH":
                     phr_leach_new=4;

src/java/m/wqm/pesticide/attributes/V1_0.java

@@ -7,6 +7,7 @@
 
 import csip.ServiceException;
 import csip.annotations.Polling;
+import csip.annotations.Resource;
 import csip.utils.JSONUtils;
 import java.sql.Connection;
 import java.sql.ResultSet;
@@ -15,14 +16,15 @@
 import java.util.ArrayList;
 import java.util.Map;
 import java.util.HashMap;
-import java.util.Iterator;
 import javax.ws.rs.Path;
 import oms3.annotations.Description;
 import oms3.annotations.Name;
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
-import wqm.utils.WQMTools;
+import wqm.utils.DBResources;
+import static wqm.utils.DBResources.WQM_ID;
+
 
 /**
  *
@@ -32,32 +34,29 @@
 @Name("WQM-03:  Pesticide Product List (PestProdList)")
 @Description("This service returns a list of pesticide products and their active ingredients from the wqm_pesticide_products table of the WQM Data Mart.  The list is filtered by criteria provided in the request payload.")
 @Path("m/wqm/pestprodlist/1.0")
+@Resource(from = DBResources.class)
 @Polling(first = 1000, next = 2000)
 
 public class V1_0 extends csip.ModelDataService {
 
-    private ArrayList<V1_0.searchFilter> filters;
-    private String error_msg;
-    private ArrayList<V1_0.searchResult> searchResults;
+    private ArrayList<SearchFilter> filters;
+ 
+    private ArrayList<SearchResult> searchResults;
 
     @Override
     protected void preProcess() throws csip.ServiceException {
     JSONArray filterArray;
-    this.filters = new ArrayList<>();
-    this.searchResults = new ArrayList<>();
-    this.error_msg = "";
+    filters = new ArrayList<>();
+    searchResults = new ArrayList<>();
 
     filterArray = getJSONArrayParam("filters");
 
     try {
         for (int i = 0; i < filterArray.length(); i++) {
-        V1_0.searchFilter tFilter = new V1_0.searchFilter(filterArray.getJSONArray(i));
-        if (!tFilter.getError()) {
-            this.filters.add(tFilter);
-        } else {
-            this.error_msg = tFilter.getErrorMsg();
-            break;
-        }
+        SearchFilter tFilter = new SearchFilter(filterArray.getJSONArray(i));
+        
+            filters.add(tFilter);
+        
         }
     } catch (JSONException ex) {
         throw new csip.ServiceException(ex.getMessage());
@@ -65,32 +64,23 @@
     }
 
     @Override
-    protected String process() throws csip.ServiceException {
+    protected void doProcess() throws csip.ServiceException {
     String query = "SELECT  reg_no, prod_name, type_desc, pc_code, ai_name, pc_pct from wqm_pesticide_products WHERE ";
     int counter = 0;
-
-    if (this.error_msg.isEmpty()) {
-        for (V1_0.searchFilter aFilter : this.filters) {
-        if (!aFilter.getError()) {
+        
+        for (SearchFilter aFilter : filters) {
+        
             if (counter > 0) {
             query += " AND ";
             }
-
             query += aFilter.getWhereClause();
             counter++;
-        } else {
-            this.error_msg += aFilter.getErrorMsg();
-            break;
-        }
+        }
+        
+        try (Connection conn = getResourceJDBC(WQM_ID);
+            Statement statement = conn.createStatement()) {
 
-        }
-
-        if (this.error_msg.isEmpty()) {
-        try (
-            Connection conn = WQMTools.getConnection("wqm", LOG);
-            Statement statement = conn.createStatement();) {
-
-            ResultSet results = statement.executeQuery(query);
+           try( ResultSet results = statement.executeQuery(query)) {
             while (results.next()) {
             Map<String, String> resultMap = new HashMap<>();
 
@@ -101,23 +91,21 @@
             resultMap.put("ai_name", results.getString("ai_name"));
             resultMap.put("pc_pct", results.getString("pc_pct"));
 
-            searchResults.add(new V1_0.searchResult(resultMap));
+            searchResults.add(new SearchResult(resultMap));
             }
-
+                   }
         } catch (ServiceException | SQLException ex) {
-            throw new csip.ServiceException(ex.getMessage());
+            throw new csip.ServiceException("SQLException",ex);
         }
-        }
-    }
-
-    return (this.error_msg.isEmpty() ? EXEC_OK : this.error_msg);
+        
+    
     }
 
     @Override
     protected void postProcess() throws JSONException {
     JSONArray resultArr = new JSONArray();
 
-    for (searchResult result : this.searchResults) {
+    for (SearchResult result : searchResults) {
         resultArr.put(result.getResultArray());
     }
 
@@ -125,24 +113,24 @@
 
     }
 
-    protected static class searchResult {
+    protected static class SearchResult {
 
-    private final Map<String, V1_0.searchResult.valueDescription> results = new HashMap<String, V1_0.searchResult.valueDescription>() {
+    private final Map<String, SearchResult.valueDescription> results = new HashMap<String, SearchResult.valueDescription>() {
         {
-        put("reg_no", new V1_0.searchResult.valueDescription("", "EPA product registration number (EPA Reg. No.)"));
-        put("prod_name", new V1_0.searchResult.valueDescription("", "Pesticide product name"));
-        put("type_desc", new V1_0.searchResult.valueDescription("", "Pesticide product type)"));
-        put("pc_code", new V1_0.searchResult.valueDescription("", "Pesticide chemical code"));
-        put("ai_name", new V1_0.searchResult.valueDescription("", "Active ingredient name"));
-        put("pc_pct", new V1_0.searchResult.valueDescription("", "Active ingredient percentage"));
+        put("reg_no", new SearchResult.valueDescription("", "EPA product registration number (EPA Reg. No.)"));
+        put("prod_name", new SearchResult.valueDescription("", "Pesticide product name"));
+        put("type_desc", new SearchResult.valueDescription("", "Pesticide product type)"));
+        put("pc_code", new SearchResult.valueDescription("", "Pesticide chemical code"));
+        put("ai_name", new SearchResult.valueDescription("", "Active ingredient name"));
+        put("pc_pct", new SearchResult.valueDescription("", "Active ingredient percentage"));
         }
     };
 
-    searchResult(Map<String, String> dbResults) {
-        V1_0.searchResult.valueDescription resultValue;
+    SearchResult(Map<String, String> dbResults) {
+        SearchResult.valueDescription resultValue;
 
         for (Map.Entry<String, String> result : dbResults.entrySet()) {
-        resultValue = this.results.get(result.getKey());
+        resultValue = results.get(result.getKey());
         if (null != resultValue) {
             resultValue.value = result.getValue();
         }
@@ -152,7 +140,7 @@
     public JSONArray getResultArray() throws JSONException {
         JSONArray ret_val = new JSONArray();
 
-        for (Map.Entry<String, V1_0.searchResult.valueDescription> result : this.results.entrySet()) {
+        for (Map.Entry<String, SearchResult.valueDescription> result : results.entrySet()) {
         ret_val.put(JSONUtils.dataDesc(result.getKey(), result.getValue().value, result.getValue().description));
         }
 
@@ -172,61 +160,59 @@
 
     }
 
-    protected static class searchFilter {
+    protected static class SearchFilter {
 
-    private V1_0.searchFilter.columnName filterName;
+    private SearchFilter.columnName filterName;
     private String searchValue;
     private boolean beginsWith;
     private boolean contains;
     private boolean endsWith;
-    private String error_msg;
-
-    searchFilter(JSONArray filterArray) {
-        this.filterName = new V1_0.searchFilter.columnName();
+    
+    SearchFilter(JSONArray filterArray) throws ServiceException {
+        this.filterName = new SearchFilter.columnName();
         this.searchValue = "";
         this.beginsWith = false;
         this.contains = false;
         this.endsWith = false;
-        this.error_msg = "";
-
+      
         if (null != filterArray) {
         try {
             Map<String, JSONObject> filterMap = JSONUtils.preprocess(filterArray);
             if (filterMap.containsKey("pp_filter_name")) {
-            this.filterName.setName(filterMap.get("pp_filter_name").getString("value"));
+            filterName.setName(filterMap.get("pp_filter_name").getString("value"));
             if (filterMap.containsKey("pp_filter_value")) {
-                this.searchValue = filterMap.get("pp_filter_value").getString("value");
+                searchValue = filterMap.get("pp_filter_value").getString("value");
                 if (filterMap.containsKey("begins_with")) {
-                this.beginsWith = filterMap.get("begins_with").getBoolean("value");
+                beginsWith = filterMap.get("begins_with").getBoolean("value");
                 if (filterMap.containsKey("contains")) {
-                    this.contains = filterMap.get("contains").getBoolean("value");
+                    contains = filterMap.get("contains").getBoolean("value");
                     if (filterMap.containsKey("ends_with")) {
-                    this.endsWith = filterMap.get("ends_with").getBoolean("value");
+                    endsWith = filterMap.get("ends_with").getBoolean("value");
                     } else {
-                    this.error_msg = "Missing 'ends_with' parameter for this filter request.  Cannot proceed.";
+                    throw new ServiceException("Missing 'ends_with' parameter for this filter request.  Cannot proceed.");
                     }
                 } else {
-                    this.error_msg = "Missing 'contains' parameter for this filter request.  Cannot proceed.";
+                    throw new ServiceException("Missing 'contains' parameter for this filter request.  Cannot proceed.");
                 }
                 } else {
-                this.error_msg = "Missing 'begins_with' parameter for this filter request.  Cannot proceed.";
+                throw new ServiceException("Missing 'begins_with' parameter for this filter request.  Cannot proceed.");
                 }
             } else {
-                this.error_msg = "Missing 'pp_filter_value' parameter for this filter request.  Cannot proceed.";
+                throw new ServiceException("Missing 'pp_filter_value' parameter for this filter request.  Cannot proceed.");
             }
             } else {
-            this.error_msg = "Missing 'pp_filter_name' parameter for this filter request.  Cannot proceed.";
+            throw new ServiceException("Missing 'pp_filter_name' parameter for this filter request.  Cannot proceed.");
             }
 
         } catch (JSONException ex) {
-            this.error_msg = "Cannot process the input request for this filter: " + ex.getMessage();
+            throw new ServiceException("JSONException",ex);
         }
         } else {
-        this.error_msg = "No input values for the filter. Cannot proceed.";
+        throw new ServiceException("No input values for the filter. Cannot proceed.");
         }
 
-        if (!this.filterName.isValid()) {
-        this.error_msg = "Filter name specified is not a valid column name.  Cannot proceed.";
+        if (!filterName.isValid()) {
+        throw new ServiceException("Filter name specified is not a valid column name.  Cannot proceed.");
         }
     }
 
@@ -234,27 +220,27 @@
         String ret_val = "( ";
         int counter = 0;
 
-        if (this.filterName.isValid() && (this.beginsWith || this.contains || this.endsWith)) {
-        ret_val += this.filterName.getName() + " LIKE ";
+        if (filterName.isValid() && (beginsWith || contains || endsWith)) {
+        ret_val += filterName.getName() + " LIKE ";
 
-        if (this.beginsWith) {
-            ret_val += " '" + this.searchValue + "%' ";
+        if (beginsWith) {
+            ret_val += " '" + searchValue + "%' ";
             counter++;
         }
 
-        if (this.contains) {
+        if (contains) {
             if (counter > 0) {
-            ret_val += " OR " + this.filterName.getName() + " LIKE ";
+            ret_val += " OR " + filterName.getName() + " LIKE ";
             }
-            ret_val += " '%" + this.searchValue + "%' ";
+            ret_val += " '%" + searchValue + "%' ";
             counter++;
         }
 
-        if (this.endsWith) {
+        if (endsWith) {
             if (counter > 0) {
-            ret_val += " OR " + this.filterName.getName() + " LIKE ";
+            ret_val += " OR " + filterName.getName() + " LIKE ";
             }
-            ret_val += " '%" + this.searchValue + "' ";
+            ret_val += " '%" + searchValue + "' ";
             counter++;
         }
 
@@ -267,13 +253,7 @@
         return ret_val;
     }
 
-    boolean getError() {
-        return !this.error_msg.isEmpty();
-    }
-
-    String getErrorMsg() {
-        return this.error_msg;
-    }
+    
 
     //  Since the column names used in the filter are constrained, this class will help
     // ensure that the contraints are adhered to.
@@ -283,7 +263,7 @@
         private int nameIdx;
 
         columnName() {
-        this.nameIdx = -1;
+        nameIdx = -1;
         }
 
         public boolean setName(String cName) {
@@ -294,13 +274,13 @@
             break;
             }
         }
-        return this.isValid();
+        return isValid();
         }
 
         public String getName() {
         String ret_val = "";
         if ((nameIdx >= 0) && (nameIdx <= 5)) {
-            ret_val = this.names[this.nameIdx];
+            ret_val = names[nameIdx];
         }
         return ret_val;
         }

src/java/m/wqm/pesticidesarp/V1_0.java

@@ -1,7 +1,6 @@
 package m.wqm.pesticidesarp;
 
 import csip.ModelDataService;
-import static csip.ModelDataService.EXEC_OK;
 import java.util.ArrayList;
 import javax.ws.rs.Path;
 import oms3.annotations.Description;
@@ -27,8 +26,8 @@
     String aoa_sarp;
 
     //JSONArray getArray
-    ArrayList<V1_0.Input> components;// store the set of all input soilcomponents as objects
-    ArrayList<V1_0.Result1> result1;  // store the result as objects
+    ArrayList<Input> components;// store the set of all input soilcomponents as objects
+    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
@@ -45,14 +44,14 @@
             boolean aoa_comp_slopegr15 = JSONUtils.getBooleanParam(group, "aoa_comp_slopegr15", false);
             boolean aoa_comp_drained = JSONUtils.getBooleanParam(group, "aoa_comp_drained", false);
             
-            components.add(new V1_0.Input(AoAId, cokey, aoa_comp_area, aoa_comp_hsg, aoa_comp_kfact, aoa_comp_slopegr15, aoa_comp_drained));
+            components.add(new Input(AoAId, cokey, aoa_comp_area, aoa_comp_hsg, aoa_comp_kfact, aoa_comp_slopegr15, aoa_comp_drained));
         }
     }
 
     @Override
-    protected String process() throws Exception {
+    protected void doProcess() throws Exception {
         result1 = new ArrayList<>();
-        for (V1_0.Input ip : components) {
+        for (Input ip : components) {
             if ((ip.aoa_comp_hsg.equals("C") && ip.aoa_comp_kfact >= 0.21)
                     || (ip.aoa_comp_hsg.equals("D") && ip.aoa_comp_kfact >= 0.10)
                     || (ip.aoa_comp_hsg.equals("C\\/D") && ip.aoa_comp_drained && ip.aoa_comp_kfact >= 0.21)) {
@@ -78,16 +77,16 @@
                 }
             }
             
-            result1.add(new V1_0.Result1(ip.AoAId, ip.cokey, ip.aoa_comp_area, comp_sarp[comp_sarp_number], comp_sarp_number));
+            result1.add(new Result1(ip.AoAId, ip.cokey, ip.aoa_comp_area, comp_sarp[comp_sarp_number], comp_sarp_number));
         }
         calAoANutSLP(result1);
-        return EXEC_OK;
+       
     }
 
     @Override
     //writing the results back to JSON
     protected void postProcess() throws Exception {
-        for (V1_0.Result1 temp : result1) {
+        for (Result1 temp : result1) {
             
             putResult("AoAId", temp.AoAId, "Area of Analysis ID");
             putResult("cokey", temp.cokey, "cokey");
@@ -103,7 +102,7 @@
         double cum_sarp_product = 0;
         double aoa_area = 0;
 
-        for (V1_0.Result1 tmp : source) {
+        for (Result1 tmp : source) {
             cum_sarp_product += (tmp.comp_sarp_number * tmp.aoa_comp_area);
             aoa_area += tmp.aoa_comp_area;
         }

src/java/m/wqm/pesticidessrp/V1_0.java

@@ -6,7 +6,6 @@
  */
 package m.wqm.pesticidessrp;
 import csip.ModelDataService;
-import static csip.ModelDataService.EXEC_OK;
 import java.util.ArrayList;
 import javax.ws.rs.Path;
 import oms3.annotations.Description;
@@ -30,8 +29,8 @@
     int comp_ssrp_number;
     String aoa_ssrp;
     //JSONArray getArray
-    ArrayList<V1_0.Input> components=new ArrayList<>(); // store the set of all input soilcomponents as objects
-    ArrayList<V1_0.Result1> result1=new ArrayList<>();  // store the result as objects
+    ArrayList<Input> components=new ArrayList<>(); // store the set of all input soilcomponents as objects
+    ArrayList<Result1> result1=new ArrayList<>();  // 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 {
@@ -43,13 +42,14 @@
                 double aoa_comp_area=JSONUtils.getDoubleParam(group,"aoa_comp_area",0);
                 String aoa_comp_hsg=JSONUtils.getStringParam(group,"aoa_comp_hsg","err");
                 boolean aoa_comp_drained=JSONUtils.getBooleanParam(group,"aoa_comp_drained" ,false);
-                components.add(new V1_0.Input(AoAId,cokey,aoa_comp_area,aoa_comp_hsg,aoa_comp_drained));
+                components.add(new Input(AoAId,cokey,aoa_comp_area,aoa_comp_hsg,aoa_comp_drained));
             }
         }
 
     @Override
-        protected String process() throws Exception{
-            for (V1_0.Input ip : components){
+        protected void doProcess() throws Exception{
+            
+            for (Input ip : components){
                 if(ip.aoa_comp_hsg.equals("C")||ip.aoa_comp_hsg.equals("D")||ip.aoa_comp_hsg.equals("C/D")){
                     comp_ssrp_number=3;
                 }
@@ -74,15 +74,15 @@
 
                     }
                 }
-                result1.add(new V1_0.Result1(ip.AoAId,ip.cokey,ip.aoa_comp_area,comp_ssrp[comp_ssrp_number],comp_ssrp_number));
+                result1.add(new Result1(ip.AoAId,ip.cokey,ip.aoa_comp_area,comp_ssrp[comp_ssrp_number],comp_ssrp_number));
             }
             calAoANutSLP(result1);
-            return EXEC_OK;       
+                
         }
     @Override
         //writing the results back to JSON
         protected void postProcess() throws Exception {
-            for(V1_0.Result1 temp:result1){
+            for(Result1 temp:result1){
                 
                 putResult("AoAId",temp.AoAId,"Area of Analysis ID");
                 putResult("cokey",temp.cokey,"Cokey of each soil component");
@@ -97,7 +97,7 @@
             double cum_nslp_product=0;
             double aoa_area=0;
         
-            for(V1_0.Result1 tmp:source){
+            for(Result1 tmp:source){
                 cum_nslp_product+=(tmp.comp_ssrp_number*tmp.aoa_comp_area);
                 aoa_area+=tmp.aoa_comp_area;
             }

src/java/m/wqm/pestipmscores/V1_0.java

@@ -7,6 +7,8 @@
 
 import csip.ModelDataService;
 import static csip.ModelDataService.EXEC_OK;
+import csip.ServiceException;
+import csip.annotations.Resource;
 import java.util.ArrayList;
 import javax.ws.rs.Path;
 import oms3.annotations.Description;
@@ -16,6 +18,8 @@
 import csip.utils.JSONUtils;
 import java.util.Map;
 import java.sql.*;
+import wqm.utils.DBResources;
+import static wqm.utils.DBResources.WQM_ID;
 
 /**
  *
@@ -25,7 +29,7 @@
 @Description("This service computes scores for the level of integrated pest management (IPM) to be applied to mitigate pesticide leaching, solution runoff, adsorbed runoff, and drift hazard potential.")
 //change
 @Path("m/pesticide_ipm_score/1.0")
-
+@Resource(from = DBResources.class)
 public class V1_0 extends ModelDataService {
 
     int AoAId = 0;
@@ -35,8 +39,8 @@
     int pdrift_ipm_score = 0;
 
     //JSONArray getArray
-    ArrayList<V1_0.Input> components = new ArrayList<>(); // store the set of all input soilcomponents as objects
-    ArrayList<V1_0.Result1> result1 = new ArrayList<>();  // store the result as objects
+    ArrayList<Input> components = new ArrayList<>(); // store the set of all input soilcomponents as objects
+    ArrayList<Result1> result1 = new ArrayList<>();  // store the result as objects
 
     @Override
     // reading the inputs from the json file into input object and placing it in the arraylist
@@ -46,17 +50,15 @@
             Map<String, JSONObject> group = JSONUtils.preprocess(groups.getJSONArray(i));
             int AoAId = JSONUtils.getIntParam(group, "AoAId", 0);
             String plan_ipm_level = JSONUtils.getStringParam(group, "plan_ipm_level", "err");
-            components.add(new V1_0.Input(AoAId, plan_ipm_level));
+            components.add(new Input(AoAId, plan_ipm_level));
         }
     }
 
     @Override
-    protected String process() throws Exception {
-        try (
-                Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
-                Statement statement = conn.createStatement();) {
-            conn.setAutoCommit(false);
-            for (V1_0.Input ip : components) {
+    protected void doProcess() throws Exception {
+       try (Connection conn = getResourceJDBC(WQM_ID);
+                Statement statement = conn.createStatement()) {
+            for (Input ip : components) {
                 String query = "SELECT ipm_mitigation_score FROM wqm_ipm_scores WHERE ipm_level='" + ip.plan_ipm_level + "' AND wqm_concern='Pesticide Leaching'";
                 ResultSet results = statement.executeQuery(query);
                 while (results.next()) {
@@ -80,18 +82,17 @@
                 result1.add(new Result1(ip.AoAId, pleach_ipm_score, psolsurf_ipm_score, psolsurf_ipm_score, pdrift_ipm_score));
             }
         } catch (SQLException se) {
-            LOG.info("Did not open database for WQM-17!");
-            LOG.info(se.getMessage());
+         throw new ServiceException("SQLException",se);
         } 
         
-        return EXEC_OK;
+        
     }
 
     @Override
     //writing the results back to JSON
     protected void postProcess() throws Exception {
         JSONArray result1Arr = new JSONArray();
-        for (V1_0.Result1 rs1 : result1) {
+        for (Result1 rs1 : result1) {
             JSONArray tmpArr = new JSONArray();
             tmpArr.put(JSONUtils.dataDesc("AoAId", rs1.AoAId, "Area of Analysis Identifier"));
             tmpArr.put(JSONUtils.dataDesc("pleach_ipm_score", rs1.pleach_ipm_score, "pleach_ipm_score"));

src/java/m/wqm/pesttechnscores/V1_0.java

@@ -5,7 +5,8 @@
  * @author SrinivasReddy kontham
  */
 import csip.ModelDataService;
-import static csip.ModelDataService.EXEC_OK;
+import csip.ServiceException;
+import csip.annotations.Resource;
 import java.util.ArrayList;
 import javax.ws.rs.Path;
 import oms3.annotations.Description;
@@ -15,16 +16,17 @@
 import csip.utils.JSONUtils;
 import java.util.Map;
 import java.sql.*;
-import java.util.concurrent.*;
+import wqm.utils.DBResources;
+import static wqm.utils.DBResources.WQM_ID;
 
 @Name("WQM-18: Pesticide Mitigation Technique Scores (PestTechnScores)")
 @Description("This services computes scores for applying pesticide management techniques to mitigate hazard potentials for leaching, solution runoff, adsorbed runoff, and drift.")
 @Path("m/pest_techn_scores/1.0")
-
+@Resource(from = DBResources.class)
 public class V1_0 extends ModelDataService {
 
-    ArrayList<V1_0.Input> components = new ArrayList<>(); // store the set of all input soilcomponents as objects
-    ArrayList<V1_0.Result1> result1 = new ArrayList<>();  // store the result as objects
+    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 pleach_technique_score;
     int psolsurf_technique_score;
     int padsurf_technique_score;
@@ -39,17 +41,15 @@
             Map<String, JSONObject> group = JSONUtils.preprocess(groups.getJSONArray(i));
             AoAid = JSONUtils.getIntParam(group, "AoAId", 0);
             int plan_ipm_technique = JSONUtils.getIntParam(group, "plan_ipm_technique", 0);
-            components.add(new V1_0.Input(AoAid, plan_ipm_technique));
+            components.add(new Input(AoAid, plan_ipm_technique));
         }
     }
 
     @Override
-    protected String process() throws Exception {
-        try (
-                Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
-                Statement statement = conn.createStatement();) {
-            conn.setAutoCommit(false);
-            for (V1_0.Input ip : components) {
+    protected void doProcess() throws Exception {
+         try (Connection conn = getResourceJDBC(WQM_ID);
+                Statement statement = conn.createStatement()) {
+            for (Input ip : components) {
                 String query = "SELECT ipm_technique_score FROM wqm_ipm_technique_scores WHERE ipm_technique_id=" + ip.plan_ipm_technique + "AND wqm_concern=" + "'" + "Pesticide Leaching" + "'";
                 ResultSet results = statement.executeQuery(query);
                 // #Compute IPM technique mitigation score for Pesticide Leaching and increment total score
@@ -79,20 +79,18 @@
                     pdrift_technique_score = pdrift_technique_score + pd_techn_score;
                 }
             }
-            result1.add(new V1_0.Result1(AoAid, pleach_technique_score, psolsurf_technique_score, padsurf_technique_score, pdrift_technique_score));
+            result1.add(new Result1(AoAid, pleach_technique_score, psolsurf_technique_score, padsurf_technique_score, pdrift_technique_score));
         } catch (SQLException se) {
-            LOG.info("Did not open database for WQM-18!");
-            LOG.info(se.getMessage());
+           throw new ServiceException("SQLException",se);
         }
 
-        return EXEC_OK;
     }
 
     @Override
     //writing the results back to JSON
     protected void postProcess() throws Exception {
         JSONArray result1Arr = new JSONArray();
-        for (V1_0.Result1 rs1 : result1) {
+        for (Result1 rs1 : result1) {
             JSONArray tmpArr = new JSONArray();
             tmpArr.put(JSONUtils.dataDesc("AoAId", rs1.AoAId, "Area of Analysis Identifier"));
             tmpArr.put(JSONUtils.dataDesc("pleach_technique_score", rs1.pleach_technique_score, "IPM Mitigation Technique Score for Pesticide Leaching"));

src/java/m/wqm/scpestslp/V1_0.java

@@ -37,16 +37,16 @@
 
     private int comp_pslp_number;
     private String aoa_pslp;
-    private ArrayList<V1_0.AoA> AoAs;
+    private ArrayList<AoA> aoAs;
     private String error_msg;
 
     // request payload
     // Store all of the input data by AoA
-    private V1_0.Input inputData;
+    private Input inputData;
 
     // response payload
     // Storeage the results
-    private V1_0.Result result;
+    private Result result;
 
     @Override
     // reading the inputs from the json file into input object and placing it in the arraylist
@@ -56,29 +56,29 @@
         error_msg = "";
         result = null;
 
-        AoAs = new ArrayList<>();
-        inputData = new V1_0.Input(AoAs);
+        aoAs = new ArrayList<>();
+        inputData = new Input(aoAs);
 
         if (inputData.getError()) {
-            this.error_msg = inputData.getErrorMsg();
+           throw new ServiceException(inputData.getErrorMsg());
         }
     }
 
     @Override
-    protected String process() throws Exception {
-        if (this.error_msg.isEmpty()) {
-            for (V1_0.AoA AoA : this.AoAs) {
-                if (!AoA.process()) {
-                    this.error_msg += AoA.getErrorMsg();
+    protected void doProcess() throws Exception {
+        if (error_msg.isEmpty()) {
+            for (AoA aoA : aoAs) {
+                if (!aoA.process()) {
+                    error_msg += aoA.getErrorMsg();
                     break;
                 }
             }
-            if (this.error_msg.isEmpty()) {
-                result = new V1_0.Result(AoAs);
+            if (error_msg.isEmpty()) {
+                result = new Result(aoAs);
             }
         }
 
-        return (this.error_msg.isEmpty() ? EXEC_OK : this.error_msg);
+       
     }
 
     @Override
@@ -91,7 +91,7 @@
 
     class AoA {
 
-        private ArrayList<V1_0.AoA.SoilComponent> soilComponents;
+        private ArrayList<SoilComponent> soilComponents;
         private final int AoAId;
         private String error_msg;
         private double cum_pslp_product;
@@ -114,30 +114,30 @@
                     if ((null != components) && (components.length() > 0)) {
                         for (int j = 0; j < components.length(); j++) {
                             Map<String, JSONObject> cokey = JSONUtils.preprocess(components.getJSONArray(j));
-                            V1_0.AoA.SoilComponent tSC = new V1_0.AoA.SoilComponent(AoAId, JSONUtils.getStringParam(cokey, "cokey", "err"),
+                            SoilComponent tSC = new SoilComponent(AoAId, JSONUtils.getStringParam(cokey, "cokey", "err"),
                                     JSONUtils.getStringParam(cokey, "compname", " "), JSONUtils.getDoubleParam(cokey, "aoa_comp_area", 0.0),
                                     JSONUtils.getStringParam(cokey, "aoa_comp_hsg", "err"), JSONUtils.getDoubleParam(cokey, "aoa_comp_kfact", 0.0),
                                     JSONUtils.getDoubleParam(cokey, "aoa_comp_om", 0.0), JSONUtils.getIntParam(cokey, "aoa_comp_hzdepth", 0),
                                     JSONUtils.getBooleanParam(cokey, "aoa_comp_cracksgr24", false), JSONUtils.getBooleanParam(cokey, "aoa_comp_hwt_lt_24", false)
                             );
                             if (!tSC.getError()) {
-                                if (!this.soilComponents.add(tSC)) {
+                                if (!soilComponents.add(tSC)) {
                                     //Shouldn't ever happen, but just in case...
-                                    this.error_msg += "Internal error, could not add this component to the list.";
+                                    error_msg += "Internal error, could not add this component to the list.";
                                     break;
                                 }
                             } else {
                                 //Most likely an input validation error here, caught by the subclass
-                                this.error_msg += tSC.getErrorMsg();
+                                error_msg += tSC.getErrorMsg();
                                 break;
                             }
                         }// End for loop of components for this AoA
                     } else {
                         //This component was empty or the JSON failed to create an item.
-                        this.error_msg += " This AoA's component is empty or missing, cannot proceed.";
+                        error_msg += " This AoA's component is empty or missing, cannot proceed.";
                     }
                 } catch (Exception ex) {
-                    this.error_msg += " " + ex.getMessage();
+                    error_msg += " " + ex.getMessage();
                 }
             }
         }
@@ -145,73 +145,74 @@
         public Boolean process() {
             Boolean ret_val = true;
 
-            for (V1_0.AoA.SoilComponent component : this.soilComponents) {
+            for (SoilComponent component : soilComponents) {
                 if (!component.process()) {
-                    this.error_msg += " " + component.getErrorMsg();
+                    error_msg += " " + component.getErrorMsg();
                     break;
                 }
 
-                this.cum_pslp_product += (component.getCompPslpNumber() * component.getAoaCompArea());
-                this.aoa_area += component.getAoaCompArea();
+                cum_pslp_product += (component.getCompPslpNumber() * component.getAoaCompArea());
+                aoa_area += component.getAoaCompArea();
             }
 
-            if (this.error_msg.isEmpty()) {
-                double aoa_pslp_fract = (this.cum_pslp_product / this.aoa_area);
+            if (error_msg.isEmpty()) {
+                double aoa_pslp_fract = (cum_pslp_product / aoa_area);
 
                 if (aoa_pslp_fract <= 1.50) {
-                    this.aoa_pslp = "VERY LOW";
+                    aoa_pslp = "VERY LOW";
                 } else if (aoa_pslp_fract > 1.50 && aoa_pslp_fract <= 2.50) {
-                    this.aoa_pslp = "LOW";
+                    aoa_pslp = "LOW";
                 } else if (aoa_pslp_fract > 2.50 && aoa_pslp_fract <= 3.50) {
-                    this.aoa_pslp = "INTERMEDIATE";
+                    aoa_pslp = "INTERMEDIATE";
                 } else {
-                    this.aoa_pslp = "HIGH";
+                    aoa_pslp = "HIGH";
                 }
             }
 
             return ret_val;
         }
 
-        public JSONArray putResults() {
+        public JSONArray putResults() throws ServiceException {
             JSONArray AoAData;
             JSONArray components;
 
             AoAData = new JSONArray();
             try {
-                AoAData.put(JSONUtils.dataDesc("AoAId", this.AoAId, "Area of Analysis Identifier"));
-                AoAData.put(JSONUtils.dataDesc("aoa_pslp", this.aoa_pslp, "Pesticide soil leaching potential representing the AoA"));
+                AoAData.put(JSONUtils.dataDesc("AoAId", AoAId, "Area of Analysis Identifier"));
+                AoAData.put(JSONUtils.dataDesc("aoa_pslp", aoa_pslp, "Pesticide soil leaching potential representing the AoA"));
 
                 components = new JSONArray();
-                for (V1_0.AoA.SoilComponent component : this.soilComponents) {
+                for (SoilComponent component : soilComponents) {
                     components.put(component.putResults());
                     if (component.getError()) {
-                        this.error_msg += " " + component.getErrorMsg();
+                        error_msg += " " + component.getErrorMsg();
                         break;
                     }
                 }
 
                 AoAData.put(JSONUtils.dataDesc("componentlist", components, "List of soil components"));
             } catch (JSONException ex) {
-                this.error_msg += " " + ex.getMessage();
+                error_msg += " " + ex.getMessage();
+            throw new ServiceException("JSONException",ex);
             }
 
             return AoAData;
         }
 
         public Boolean getError() {
-            return (!this.error_msg.isEmpty());
+            return (!error_msg.isEmpty());
         }
 
         public String getErrorMsg() {
-            return this.error_msg;
+            return error_msg;
         }
 
         public String getAoAPslp() {
-            return this.aoa_pslp;
+            return aoa_pslp;
         }
 
         public int getAoAId() {
-            return this.AoAId;
+            return AoAId;
         }
 
         class SoilComponent {
@@ -247,90 +248,91 @@
                 this.comp_pslp_number = 0;
 
                 if (cokey.equals("err") || aoa_comp_hsg.equals("err") || (AoAId == -1)) {
-                    this.error_msg += " Invalid input data for this soil component.";
+                    error_msg += " Invalid input data for this soil component.";
                 }
             }
 
             public int getAoAId() {
-                return this.AoAId;
+                return AoAId;
             }
 
             public String getCokey() {
-                return this.cokey;
+                return cokey;
             }
 
             public String getCompname() {
-                return this.compname;
+                return compname;
             }
 
             public String getCompPslp() {
-                return this.comp_pslp;
+                return comp_pslp;
             }
 
             ;
             public int getCompPslpNumber() {
-                return this.comp_pslp_number;
+                return comp_pslp_number;
             }
 
             public double getAoaCompArea() {
-                return this.aoa_comp_area;
+                return aoa_comp_area;
             }
 
             public Boolean getError() {
-                return (!this.error_msg.isEmpty());
+                return (!error_msg.isEmpty());
             }
 
             public String getErrorMsg() {
-                return (this.error_msg);
+                return (error_msg);
             }
 
             public boolean process() {
                 boolean ret_val = true;
 
-                if (this.aoa_comp_hwt_lt_24) {
-                    this.comp_pslp_number = V1_0.HIGH;
-                } else if (((this.aoa_comp_hsg.equals("A") || this.aoa_comp_hsg.equals("A/D")) && ((this.aoa_comp_hzdepth * this.aoa_comp_om) <= 30))
-                        || ((this.aoa_comp_hsg.equals("B") || this.aoa_comp_hsg.equals("B/D")) && ((this.aoa_comp_hzdepth * this.aoa_comp_om) <= 9) && (this.aoa_comp_kfact <= 0.48))
-                        || ((this.aoa_comp_hsg.equals("B") || this.aoa_comp_hsg.equals("B/D")) && ((this.aoa_comp_hzdepth * this.aoa_comp_om) <= 15) && (this.aoa_comp_kfact <= 0.26))) {
-                    this.comp_pslp_number = V1_0.HIGH;
-                } else if (((this.aoa_comp_hsg.equals("B") || this.aoa_comp_hsg.equals("B/D")) && ((this.aoa_comp_hzdepth * this.aoa_comp_om) >= 35) && this.aoa_comp_kfact >= 0.40)
-                        || ((this.aoa_comp_hsg.equals("B") || this.aoa_comp_hsg.equals("B/D")) && ((this.aoa_comp_hzdepth * this.aoa_comp_om) >= 45) && this.aoa_comp_kfact >= 0.20)
-                        || ((this.aoa_comp_hsg.equals("C") || this.aoa_comp_hsg.equals("C/D")) && ((this.aoa_comp_hzdepth * this.aoa_comp_om) <= 10) && this.aoa_comp_kfact <= 0.28)
-                        || ((this.aoa_comp_hsg.equals("C") || this.aoa_comp_hsg.equals("C/D")) && ((this.aoa_comp_hzdepth * this.aoa_comp_om) >= 10))) {
-                    if (!this.aoa_comp_cracksgr24) {
-                        this.comp_pslp_number = V1_0.LOW;
+                if (aoa_comp_hwt_lt_24) {
+                    comp_pslp_number = HIGH;
+                } else if (((aoa_comp_hsg.equals("A") || aoa_comp_hsg.equals("A/D")) && ((aoa_comp_hzdepth * aoa_comp_om) <= 30))
+                        || ((aoa_comp_hsg.equals("B") || aoa_comp_hsg.equals("B/D")) && ((aoa_comp_hzdepth * aoa_comp_om) <= 9) && (aoa_comp_kfact <= 0.48))
+                        || ((aoa_comp_hsg.equals("B") || aoa_comp_hsg.equals("B/D")) && ((aoa_comp_hzdepth * aoa_comp_om) <= 15) && (aoa_comp_kfact <= 0.26))) {
+                    comp_pslp_number = HIGH;
+                } else if (((aoa_comp_hsg.equals("B") || aoa_comp_hsg.equals("B/D")) && ((aoa_comp_hzdepth * aoa_comp_om) >= 35) && aoa_comp_kfact >= 0.40)
+                        || ((aoa_comp_hsg.equals("B") || aoa_comp_hsg.equals("B/D")) && ((aoa_comp_hzdepth * aoa_comp_om) >= 45) && aoa_comp_kfact >= 0.20)
+                        || ((aoa_comp_hsg.equals("C") || aoa_comp_hsg.equals("C/D")) && ((aoa_comp_hzdepth * aoa_comp_om) <= 10) && aoa_comp_kfact <= 0.28)
+                        || ((aoa_comp_hsg.equals("C") || aoa_comp_hsg.equals("C/D")) && ((aoa_comp_hzdepth * aoa_comp_om) >= 10))) {
+                    if (!aoa_comp_cracksgr24) {
+                        comp_pslp_number = LOW;
                     } else {
-                        this.comp_pslp_number = V1_0.INTERMEDIATE;
+                        comp_pslp_number = INTERMEDIATE;
                     }
-                } else if (this.aoa_comp_hsg.equals("D")) {
-                    if (!this.aoa_comp_cracksgr24) {
-                        this.comp_pslp_number = V1_0.VERY_LOW;
+                } else if (aoa_comp_hsg.equals("D")) {
+                    if (!aoa_comp_cracksgr24) {
+                        comp_pslp_number = VERY_LOW;
                     } else {
-                        this.comp_pslp_number = V1_0.LOW;
+                        comp_pslp_number = LOW;
                     }
                 } else {
-                    if (!this.aoa_comp_cracksgr24) {
-                        this.comp_pslp_number = V1_0.INTERMEDIATE;
+                    if (!aoa_comp_cracksgr24) {
+                        comp_pslp_number = INTERMEDIATE;
                     } else {
-                        this.comp_pslp_number = V1_0.HIGH;
+                        comp_pslp_number = HIGH;
                     }
                 }
 
-                this.comp_pslp = comp_pslp_string[this.comp_pslp_number];
+                comp_pslp = comp_pslp_string[comp_pslp_number];
 
                 return ret_val;
             }
 
-            public JSONArray putResults() {
+            public JSONArray putResults() throws ServiceException {
                 JSONArray componentData;
                 componentData = new JSONArray();
 
                 try {
-                    componentData.put(JSONUtils.dataDesc("cokey", this.cokey, "Soil component key"));
-                    componentData.put(JSONUtils.dataDesc("compname", this.compname, "Soil component name"));
-                    componentData.put(JSONUtils.dataDesc("comp_pslp", this.comp_pslp, "Pesticide soil leaching potential representing the soil component"));
-                } catch (JSONException ex) {
-                    this.error_msg += " " + ex.getMessage();
+                    componentData.put(JSONUtils.dataDesc("cokey", cokey, "Soil component key"));
+                    componentData.put(JSONUtils.dataDesc("compname", compname, "Soil component name"));
+                    componentData.put(JSONUtils.dataDesc("comp_pslp", comp_pslp, "Pesticide soil leaching potential representing the soil component"));
+                } catch (JSONException ex) {                   
+                    error_msg += " " + ex.getMessage();
+                    throw new ServiceException("JSONException",ex);
                 }
 
                 return componentData;
@@ -343,8 +345,8 @@
         private String error_msg;
         private JSONArray AoAList;
 
-        Input(ArrayList<V1_0.AoA> AoAs) {
-            this.error_msg = "";
+        Input(ArrayList<AoA> aoAs) throws ServiceException {
+            error_msg = "";
 
             try {
                 AoAList = getJSONArrayParam("AoAList");
@@ -356,32 +358,33 @@
 
                         if (AoAId != -1) {
                             JSONArray components = JSONUtils.getJSONArrayParam(componentGroup, "componentlist");
-                            V1_0.AoA AoA = new V1_0.AoA(AoAId, components);
-                            if (AoA.getError()) {
-                                this.error_msg += " " + AoA.getErrorMsg();
+                            AoA aoA = new AoA(AoAId, components);
+                            if (aoA.getError()) {
+                                error_msg += " " + aoA.getErrorMsg();
                                 break;
                             } else {
-                                AoAs.add(AoA);
+                                aoAs.add(aoA);
                             }
                         } else {
-                            this.error_msg += " The AoAId is not valid or is missing, cannot proceed";
+                            error_msg += " The AoAId is not valid or is missing, cannot proceed";
                             break;
                         }
                     }//  End for loop of AoA's
                 } else {
-                    this.error_msg += " There were no AoA's found in the input payload.  Cannot proceed.";
+                    error_msg += " There were no AoA's found in the input payload.  Cannot proceed.";
                 }
             } catch (ServiceException | JSONException ex) {
-                this.error_msg += " " + ex.getMessage();
+                error_msg += " " + ex.getMessage();
+                throw new ServiceException("JSONException",ex);
             }
         }
 
         public String getErrorMsg() {
-            return this.error_msg;
+            return error_msg;
         }
 
         public Boolean getError() {
-            return (!this.error_msg.isEmpty());
+            return (!error_msg.isEmpty());
         }
     }
 
@@ -389,13 +392,13 @@
 
         JSONArray AoAList;
 
-        Result(ArrayList<V1_0.AoA> AoAs) throws Exception {
-            if (!AoAs.isEmpty()) {
+        Result(ArrayList<AoA> aoAs) throws Exception {
+            if (!aoAs.isEmpty()) {
                 AoAList = new JSONArray();
-                for (V1_0.AoA AoA : AoAs) {
-                    AoAList.put(AoA.putResults());
-                    if (AoA.getError()) {
-                        AoAList.put(JSONUtils.dataDesc("Error:", AoA.getErrorMsg(), "Error message returned while trying to build result output"));
+                for (AoA aoA : aoAs) {
+                    AoAList.put(aoA.putResults());
+                    if (aoA.getError()) {
+                        AoAList.put(JSONUtils.dataDesc("Error:", aoA.getErrorMsg(), "Error message returned while trying to build result output"));
                         break;
                     }
                 }

src/java/m/wqm/sednutpractscores/V1_0.java

@@ -1,8 +1,8 @@
 package m.wqm.sednutpractscores;
 
 import csip.ModelDataService;
-import static csip.ModelDataService.EXEC_OK;
 import csip.ServiceException;
+import csip.annotations.Resource;
 import java.util.ArrayList;
 import javax.ws.rs.Path;
 import oms3.annotations.Description;
@@ -13,13 +13,14 @@
 import java.util.Map;
 import java.sql.*;
 import java.util.logging.Level;
-import java.util.logging.Logger;
 import org.codehaus.jettison.json.JSONException;
+import wqm.utils.DBResources;
+import static wqm.utils.DBResources.WQM_ID;
 
 @Name("WQM-15: Sediment and Nutrient Practice Scores (SedNutPractScores)")
 @Description("This service computes scores for conservation practices applied to mitigate nitrogen leaching, sediment runoff, nitrogen runoff, and phosphorus runoff loss potential.")
 @Path("m/nut_pract_scores/1.0")
-
+@Resource( from = DBResources.class)
 /**
  *
  * @author SrinivasReddy kontham
@@ -27,8 +28,8 @@
  */
 public class V1_0 extends ModelDataService {
 
-    private ArrayList<V1_0.Input> components = new ArrayList<>(); // store the set of all input soilcomponents as objects
-    private ArrayList<V1_0.Result1> result1 = new ArrayList<>();  // store the result as objects
+    private ArrayList<Input> components = new ArrayList<>(); // store the set of all input soilcomponents as objects
+    private ArrayList<Result1> result1 = new ArrayList<>();  // store the result as objects
     private int nleach_pract_score = 0;
     private int nleach_avoid_pract_score = 0;
     private int nleach_control_pract_score = 0;
@@ -47,30 +48,29 @@
     private int ssurf_trap_pract_score = 0;
     private int AoAid;
 
-    private String error_msg;
+ 
 
     @Override
-    protected void preProcess() {
-        this.nleach_pract_score = 0;
-        this.nleach_avoid_pract_score = 0;
-        this.nleach_control_pract_score = 0;
-        this.nleach_trap_pract_score = 0;
-        this.nsurf_pract_score = 0;
-        this.nsurf_avoid_pract_score = 0;
-        this.nsurf_control_pract_score = 0;
-        this.nsurf_trap_pract_score = 0;
-        this.psurf_pract_score = 0;
-        this.psurf_avoid_pract_score = 0;
-        this.psurf_control_pract_score = 0;
-        this.psurf_trap_pract_score = 0;
-        this.ssurf_pract_score = 0;
-        this.ssurf_avoid_pract_score = 0;
-        this.ssurf_control_pract_score = 0;
-        this.ssurf_trap_pract_score = 0;
-        this.error_msg = "";
-
-        this.components = new ArrayList<>();
-        this.result1 = new ArrayList<>();
+    protected void preProcess() throws ServiceException {
+        nleach_pract_score = 0;
+        nleach_avoid_pract_score = 0;
+        nleach_control_pract_score = 0;
+        nleach_trap_pract_score = 0;
+        nsurf_pract_score = 0;
+        nsurf_avoid_pract_score = 0;
+        nsurf_control_pract_score = 0;
+        nsurf_trap_pract_score = 0;
+        psurf_pract_score = 0;
+        psurf_avoid_pract_score = 0;
+        psurf_control_pract_score = 0;
+        psurf_trap_pract_score = 0;
+        ssurf_pract_score = 0;
+        ssurf_avoid_pract_score = 0;
+        ssurf_control_pract_score = 0;
+        ssurf_trap_pract_score = 0;
+      
+        components = new ArrayList<>();
+        result1 = new ArrayList<>();
 
         try {
 
@@ -82,24 +82,20 @@
                 int plan_pract_id = JSONUtils.getIntParam(group, "plan_practice_id", 0);
                 String plan_pract_discrim_type = JSONUtils.getStringParam(group, "plan_practice_discrim_type", "err");
                 String plan_pract_discrim_value = JSONUtils.getStringParam(group, "plan_practice_discrim_value", "err");
-                components.add(new V1_0.Input(AoAid, plan_pract_id, plan_pract_discrim_type, plan_pract_discrim_value));
+                components.add(new Input(AoAid, plan_pract_id, plan_pract_discrim_type, plan_pract_discrim_value));
             }
-        } catch (JSONException ex) {
-            this.error_msg = "Cannot process the input JSON: " + ex.getMessage();
-            LOG.log(Level.SEVERE, this.error_msg);
-        } catch (ServiceException ex) {
-            this.error_msg = "Cannot process the input JSON: " + ex.getMessage();
-            LOG.log(Level.SEVERE, this.error_msg);
-        }
+        } catch (ServiceException | JSONException ex) {
+            LOG.log(Level.SEVERE, "Cannot process the input JSON",ex);
+            throw new ServiceException("JSONException",ex);
+        } 
     }
 
     @Override
-    protected String process() throws Exception {
-        if (this.error_msg.isEmpty()) {
-            try (
-                    Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
-                    Statement statement = conn.createStatement();) {
-                for (V1_0.Input ip : components) {
+    protected void doProcess() throws Exception {
+       
+             try (Connection conn = getResourceJDBC(WQM_ID);
+                Statement statement = conn.createStatement()) {
+                for (Input ip : components) {
                     String query;
                     //  #Compute practice mitigation scores for Nitrogen in Ground Water and increment total scores
                     if (ip.plan_practice_discrim_type.isEmpty()) {
@@ -255,21 +251,21 @@
                     }
                     psurf_pract_score = psurf_trap_pract_score + psurf_control_pract_score + psurf_avoid_pract_score;
                 }
-                result1.add(new V1_0.Result1(AoAid, nleach_pract_score, ssurf_pract_score, nsurf_pract_score, psurf_pract_score, nleach_avoid_pract_score, nleach_control_pract_score, nleach_trap_pract_score, ssurf_avoid_pract_score, ssurf_control_pract_score, ssurf_trap_pract_score, nsurf_avoid_pract_score, nsurf_control_pract_score, nsurf_trap_pract_score, psurf_avoid_pract_score, psurf_control_pract_score, psurf_trap_pract_score));
+                result1.add(new Result1(AoAid, nleach_pract_score, ssurf_pract_score, nsurf_pract_score, psurf_pract_score, nleach_avoid_pract_score, nleach_control_pract_score, nleach_trap_pract_score, ssurf_avoid_pract_score, ssurf_control_pract_score, ssurf_trap_pract_score, nsurf_avoid_pract_score, nsurf_control_pract_score, nsurf_trap_pract_score, psurf_avoid_pract_score, psurf_control_pract_score, psurf_trap_pract_score));
             } catch (NumberFormatException | SQLException ex) {
-                this.error_msg = "Cannot process that request: " + ex.getMessage();
-                LOG.log(Level.SEVERE, this.error_msg);
+                LOG.log(Level.SEVERE, "Cannot process that request",ex);
+                throw new ServiceException("SQLException",ex);
             }
-        }
-        return (this.error_msg.isEmpty() ? EXEC_OK : this.error_msg);
+        
+      
     }
 
     @Override
     protected void postProcess() throws Exception {
-        if (this.error_msg.isEmpty()) {
+       
             try {
                 JSONArray result1Arr = new JSONArray();
-                for (V1_0.Result1 rs1 : result1) {
+                for (Result1 rs1 : result1) {
                     JSONArray tmpArr = new JSONArray();
                     tmpArr.put(JSONUtils.dataDesc("AoAId", AoAid, "Area of Analysis Identifier"));
                     tmpArr.put(JSONUtils.dataDesc("nleach_pract_score", rs1.nleach_pract_score, " Nitrogen Leaching Practice Mitigation Score"));
@@ -293,11 +289,10 @@
 
                 putResult("operation", result1Arr);
             } catch (JSONException ex) {
-                this.error_msg = "Could not create result JSON: " + ex.getMessage();
-                LOG.log(Level.SEVERE, this.error_msg);
-                throw new Exception(this.error_msg);
+                LOG.log(Level.SEVERE, "Could not create result JSON",ex);
+                throw new ServiceException("JSONException",ex);
             }
-        }
+       
     }
 
     public class Input {

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

@@ -3,6 +3,7 @@
 import csip.ModelDataService;
 import csip.ServiceException;
 import csip.annotations.Polling;
+import csip.annotations.Resource;
 import csip.utils.JSONUtils;
 import java.sql.Connection;
 import java.sql.ResultSet;
@@ -19,6 +20,8 @@
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
+import wqm.utils.DBResources;
+import static wqm.utils.DBResources.WQM_ID;
 
 /**
  *
@@ -29,45 +32,45 @@
 @Description("This service computes soil pesticide interaction loss potentials for leaching, solution runoff, and adsorbed runoff.")
 @Path("m/soilpestlosspot/1.0")
 @Polling(first = 10000, next = 2000)
-
+@Resource(from = DBResources.class)
 public class V1_0 extends ModelDataService {
 
-    private V1_0.AoA aoa;
+    private AoA aoa;
     private String error_msg;
 
     //Response
-    private ArrayList<V1_0.Result> result;
+    private ArrayList<Result> result;
 
     @Override
     protected void preProcess() throws Exception {
-        this.error_msg = "";
+        error_msg = "";
         try {
-            aoa = new V1_0.AoA(getStringParam("AoAId"), getStringParam("aoa_pslp"), getStringParam("aoa_ssrp"),
+            aoa = new AoA(getStringParam("AoAId"), getStringParam("aoa_pslp"), getStringParam("aoa_ssrp"),
                     getStringParam("aoa_sarp"), getStringParam("aoa_rain_prob"), getJSONArrayParam("operationlist"));
             error_msg = aoa.getErrorMsg();
         } catch (Exception ex) {
-            error_msg += "  " + ex.getMessage() + ". ";
+            throw new ServiceException("PreProcess Exception",ex);
+            
         }
     }
 
     @Override
-    protected String process() throws Exception {
-        ResultSet resultSet;
-
+    protected void doProcess() throws Exception {
+   
         if (error_msg.isEmpty()) {
             if (aoa.calculate()) {
                 result = aoa.getResults();
             } else {
-                error_msg = aoa.getErrorMsg();
-            }
+                throw new ServiceException(aoa.getErrorMsg());
+           }
 
         }
 
         if (result == null) {
-            error_msg += "  No return data found, cannot validate input or results.  Please check your input parameters.";
+            throw new ServiceException("  No return data found, cannot validate input or results.  Please check your input parameters.");
         }
 
-        return (error_msg.isEmpty() ? EXEC_OK : error_msg);
+     
     }
 
     @Override
@@ -83,7 +86,7 @@
             putResult("AoAId", result.get(0).getAoaId(), "Area of Analysis Identifier");
             JSONArray tmpArr = new JSONArray();
             JSONArray tmpArr2 = new JSONArray();
-            for (V1_0.Result rs1 : result) {
+            for (Result rs1 : result) {
                 if (!rs1.getOperationId().equals(currentOperationId)) {
                     if (!currentOperationId.isEmpty()) {
                         currentOperationId = rs1.getOperationId();
@@ -123,9 +126,9 @@
         private final String aoa_rain_prob;
         private ArrayList<pesticideOperation> pesticideOperationList;
         private String error_msg;
-        ArrayList<V1_0.Result> results;
+        ArrayList<Result> results;
 
-        AoA(String AoAId, String aoa_pslp, String aoa_ssrp, String aoa_sarp, String aoa_rain_prob, JSONArray operationList) {
+        AoA(String AoAId, String aoa_pslp, String aoa_ssrp, String aoa_sarp, String aoa_rain_prob, JSONArray operationList) throws ServiceException {
             error_msg = "";
             this.AoAId = AoAId;
             this.aoa_pslp = aoa_pslp;
@@ -142,33 +145,33 @@
                     pesticideOperationList.add(new pesticideOperation(JSONUtils.getStringParam(operation, "operation_id", "err"), this, JSONUtils.getJSONArrayParam(operation, "pesticidelist")));
                 }
             } catch (JSONException ex) {
-                this.error_msg += ex.getMessage();
+                throw new ServiceException("JSONException",ex);
             }
         }
 
         //Get Methods
         public String getAoaId() {
-            return this.AoAId;
+            return AoAId;
         }
 
         public String getAoa_pslp() {
-            return this.aoa_pslp;
+            return aoa_pslp;
         }
 
         public String getAoa_ssrp() {
-            return this.aoa_ssrp;
+            return aoa_ssrp;
         }
 
         public String getAoa_sarp() {
-            return this.aoa_sarp;
+            return aoa_sarp;
         }
 
         public String getAoa_rain_prob() {
-            return this.aoa_rain_prob;
+            return aoa_rain_prob;
         }
 
         public String getErrorMsg() {
-            return this.error_msg;
+            return error_msg;
         }
 
         public Boolean calculate() throws ServiceException {
@@ -177,7 +180,7 @@
             for (pesticideOperation pesticides : pesticideOperationList) {
                 if (!pesticides.calculate()) {
                     ret_val = false;
-                    this.error_msg = pesticides.getError();
+                    error_msg = pesticides.getError();
                     break;
                 }
             }
@@ -185,14 +188,14 @@
             return ret_val;
         }
 
-        public ArrayList<V1_0.Result> getResults() {
-            this.results = new ArrayList<>();
+        public ArrayList<Result> getResults() {
+            results = new ArrayList<>();
 
             for (pesticideOperation pOperation : pesticideOperationList) {
-                this.results = pOperation.getResult(this.results);
+                results = pOperation.getResult(results);
             }
 
-            return this.results;
+            return results;
         }
     }
 
@@ -203,7 +206,7 @@
         private ArrayList<pesticide> pesticideList;
         private String error_msg = "";
 
-        pesticideOperation(String operation_id, AoA aoa, JSONArray pesticides) {
+        pesticideOperation(String operation_id, AoA aoa, JSONArray pesticides) throws ServiceException {
             this.operation_id = operation_id;
             this.aoa = aoa;
             pesticideList = new ArrayList<>();
@@ -218,12 +221,12 @@
                             JSONUtils.getStringParam(pesticidesData, "ai_parp", "err")));
                 }
             } catch (JSONException ex) {
-                this.error_msg = ex.getMessage();
+                throw new ServiceException("JSONException",ex);
             }
         }
 
         String getError() {
-            return this.error_msg;
+            return error_msg;
         }
 
         Boolean calculate() throws ServiceException {
@@ -233,7 +236,7 @@
                 String tResult = pst.getILP() + " " + pst.getISRP() + " " + pst.getIARP();
                 if ((tResult.contains("ERROR")) || (tResult.contains("err"))) {
                     ret_val = false;
-                    this.error_msg += "  For operation: " + this.operation_id + ", " + pst.getErrorMsg();
+                    error_msg += "  For operation: " + operation_id + ", " + pst.getErrorMsg();
                     break;
                 }
             }
@@ -241,9 +244,9 @@
             return ret_val;
         }
 
-        ArrayList<V1_0.Result> getResult(ArrayList<V1_0.Result> results) {
+        ArrayList<Result> getResult(ArrayList<Result> results) {
 
-            for (pesticideOperation.pesticide pesticide : this.pesticideList) {
+            for (pesticideOperation.pesticide pesticide : pesticideList) {
                 results.add(pesticide.getResult());
             }
 
@@ -262,25 +265,23 @@
             private String op_pest_iarp = "ERROR";
 
             pesticide(String op_pesticide_id, String ai_plp, String ai_psrp, String ai_parp) {
-                this.op_pesticide_id = ("err".equals(op_pesticide_id) ? (this.error_msg = "Pesticide Id invalid or missing") : op_pesticide_id);
-                this.ai_plp = ("err".equals(ai_plp) ? (this.error_msg = "Active Ingredient Pesticide Leaching Potential invalid or missing") : ai_plp);
-                this.ai_psrp = ("err".equals(ai_psrp) ? (this.error_msg = "Active Ingredient Pesticide Solution Runoff Potential invalid or missing") : ai_psrp);
-                this.ai_parp = ("err".equals(ai_parp) ? (this.error_msg = "Active Ingredient Pesticide Adsorbed Runoff Potential invalid or missing") : ai_parp);
+                this.op_pesticide_id = ("err".equals(op_pesticide_id) ? (error_msg = "Pesticide Id invalid or missing") : op_pesticide_id);
+                this.ai_plp = ("err".equals(ai_plp) ? (error_msg = "Active Ingredient Pesticide Leaching Potential invalid or missing") : ai_plp);
+                this.ai_psrp = ("err".equals(ai_psrp) ? (error_msg = "Active Ingredient Pesticide Solution Runoff Potential invalid or missing") : ai_psrp);
+                this.ai_parp = ("err".equals(ai_parp) ? (error_msg = "Active Ingredient Pesticide Adsorbed Runoff Potential invalid or missing") : ai_parp);
             }
 
             String getILP() throws ServiceException {
                 if ("ERROR".equals(op_pest_ilp)) {
                     //Calculate it
-                    ResultSet resultSet;
                     String query = "SELECT wqm_ilp FROM wqm_soil_pest_interaction_leaching WHERE wqm_plp='" + ai_plp + "' AND wqm_slp='" + aoa.getAoa_pslp() + "';";
-                    try (
-                            Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
-                            Statement statement = conn.createStatement(TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY);) {
-                        resultSet = statement.executeQuery(query);
+                      try (Connection conn = getResourceJDBC(WQM_ID);
+                            Statement statement = conn.createStatement(TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY)) {
+                       try(ResultSet resultSet = statement.executeQuery(query)){
                         if (resultSet.first()) {
                             op_pest_ilp = resultSet.getString("wqm_ilp");
                         } else {
-                            this.error_msg += "For pesticide: " + this.op_pesticide_id + ", Cannot find that ai_plp and aoa_pslp combination in the database.";
+                            error_msg += "For pesticide: " + op_pesticide_id + ", Cannot find that ai_plp and aoa_pslp combination in the database.";
                         }
 
                         if ("LOW".equals(aoa.getAoa_rain_prob())) {
@@ -296,8 +297,9 @@
                                     break;
                             }
                         }
+                       }
                     } catch (SQLException se) {
-                        this.error_msg += se.getMessage();
+                        throw new ServiceException("SQLException",se);
                     }
                 }
 
@@ -307,17 +309,17 @@
             String getISRP() throws ServiceException {
                 if ("ERROR".equals(op_pest_isrp)) {
                     //Calculate it
-                    ResultSet resultSet;
+                
                     String query = "SELECT wqm_isrp FROM wqm_soil_pest_interaction_solution_runoff WHERE wqm_psrp='" + ai_psrp + "' AND wqm_ssrp ='" + aoa.getAoa_ssrp() + "';";
-                    try (
-                            Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
-                            Statement statement = conn.createStatement(TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY);) {
-                        resultSet = statement.executeQuery(query);
+                   
+                            try (Connection conn = getResourceJDBC(WQM_ID);
+                            Statement statement = conn.createStatement(TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY)) {
+                            try( ResultSet resultSet = statement.executeQuery(query)){
                         op_pest_isrp = "err";
                         if (resultSet.first()) {
                             op_pest_isrp = resultSet.getString("wqm_isrp");
                         } else {
-                            this.error_msg += "For pesticide: " + this.op_pesticide_id + ", Cannot find that ai_psrp and aoa_ssrp combination in the database.";
+                            throw new ServiceException( "For pesticide: " + op_pesticide_id + ", Cannot find that ai_psrp and aoa_ssrp combination in the database.");                      
                         }
 
                         if ("LOW".equals(aoa.getAoa_rain_prob())) {
@@ -335,8 +337,9 @@
                                  */
                             }
                         }
+                            }
                     } catch (SQLException se) {
-                        this.error_msg += se.getMessage();
+                        throw new ServiceException("SQLException",se);
                     }
 
                 }
@@ -347,17 +350,17 @@
             String getIARP() throws ServiceException {
                 if ("ERROR".equals(op_pest_iarp)) {
                     //Calculate it
-                    ResultSet resultSet;
+                    
                     String query = "SELECT wqm_iarp FROM wqm_soil_pest_interaction_adsorbed_runoff WHERE wqm_parp='" + ai_parp + "' AND wqm_sarp='" + aoa.getAoa_sarp() + "';";
-                    try (
-                            Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
-                            Statement statement = conn.createStatement(TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY);) {
-                        resultSet = statement.executeQuery(query);
+                     try (Connection conn = getResourceJDBC(WQM_ID);
+                Statement statement = conn.createStatement(TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY)) {
+                         
+                       try(ResultSet resultSet = statement.executeQuery(query)){
                         op_pest_iarp = "err";
                         if (resultSet.first()) {
                             op_pest_iarp = resultSet.getString("wqm_iarp");
                         } else {
-                            this.error_msg += "For pesticide: " + this.op_pesticide_id + ", Cannot find that ai_parp and aoa_sarp combination in the database.";
+                            error_msg += "For pesticide: " + op_pesticide_id + ", Cannot find that ai_parp and aoa_sarp combination in the database.";
                         }
 
                         if ("LOW".equals(aoa.getAoa_rain_prob())) {
@@ -375,8 +378,9 @@
                                  */
                             }
                         }
-                    } catch (SQLException Se) {
-                        this.error_msg += Se.getMessage();
+                       }
+                    } catch (SQLException se) {
+                       throw new ServiceException("SQLException",se);
                     }
                 }
 
@@ -384,11 +388,11 @@
             }
 
             String getErrorMsg() {
-                return this.error_msg;
+                return error_msg;
             }
 
-            V1_0.Result getResult() {
-                V1_0.Result result = new V1_0.Result(aoa.getAoaId(), operation_id, op_pesticide_id, op_pest_ilp, op_pest_isrp, op_pest_iarp);
+            Result getResult() {
+                Result result = new Result(aoa.getAoaId(), operation_id, op_pesticide_id, op_pest_ilp, op_pest_isrp, op_pest_iarp);
                 return result;
             }
         }
@@ -413,32 +417,32 @@
         }
 
         public String getAoaId() {
-            return this.AoAId;
+            return AoAId;
         }
 
         public String getOperationId() {
-            return this.operation_id;
+            return operation_id;
         }
 
         public String getOpPesticideId() {
-            return this.op_pesticide_id;
+            return op_pesticide_id;
         }
 
         public String getOpPestIlp() {
-            return this.op_pest_ilp;
+            return op_pest_ilp;
         }
 
         public String getOpPestIsrp() {
-            return this.op_pest_isrp;
+            return op_pest_isrp;
         }
 
         public String getOpPestIarp() {
-            return this.op_pest_iarp;
+            return op_pest_iarp;
         }
 
         @Override
         public int compareTo(Result rs) {
-            return this.getOperationId().compareTo(rs.getOperationId());
+            return getOperationId().compareTo(rs.getOperationId());
         }
     }
 }

src/java/m/wqm/thresholdscores/V1_0.java

@@ -2,6 +2,7 @@
 
 import csip.ModelDataService;
 import csip.ServiceException;
+import csip.annotations.Resource;
 import csip.utils.JSONUtils;
 import java.sql.Connection;
 import java.sql.ResultSet;
@@ -16,6 +17,8 @@
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
+import wqm.utils.DBResources;
+import static wqm.utils.DBResources.WQM_ID;
 
 /**
  *
@@ -25,20 +28,20 @@
 @Name("WQM-13: WQM Concern Treatment Level Threshold Scores (WQMThresholdScores)")
 @Description("This service computes treatment level threshold scores for each of the WQM concerns for an area of analysis. The service uses nutrient soil leaching potentials from WQM-5, sediment and nutrient soil runoff potentials from WQM-6, hazard ratings from pesticide-related WQM concerns from WQM-11, required treatment level from WQM-1, and the AoA climate R factor from WQM-12 to calculate the threshold scores.")
 @Path("m/thresholdscores/1.0")
-
+@Resource(from = DBResources.class)
 public class V1_0 extends ModelDataService {
 
-    private String error_msg;
+   
 
-    ArrayList<V1_0.Input> components; // store the set of all input soilcomponents as objects
-    ArrayList<V1_0.Result1> result1;  // store the result as objects
+    ArrayList<Input> components; // store the set of all input soilcomponents as objects
+    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 {
-        this.components = new ArrayList<>();
-        this.result1 = new ArrayList<>();
-        this.error_msg = "";
+        components = new ArrayList<>();
+        result1 = new ArrayList<>();
+     
 
         try {
             JSONArray groups = getJSONArrayParam("components");
@@ -55,22 +58,23 @@
                 String aoa_phr_adrun_stvfish = JSONUtils.getStringParam(group, "aoa_phr_adrun_stvfish", "err");
                 String aoa_treatment_level = JSONUtils.getStringParam(group, "aoa_treatment_level", "err");
                 int aoa_rfactor = JSONUtils.getIntParam(group, "aoa_rfactor", 0);
-                components.add(new V1_0.Input(AoAId, aoa_nslp, aoa_srp, aoa_phr_leach_human, aoa_phr_leach_matcfish, aoa_phr_sorun_human, aoa_phr_sorun_matcfish, aoa_phr_adrun_human, aoa_phr_adrun_stvfish, aoa_treatment_level, aoa_rfactor));
+                components.add(new Input(AoAId, aoa_nslp, aoa_srp, aoa_phr_leach_human, aoa_phr_leach_matcfish, aoa_phr_sorun_human, aoa_phr_sorun_matcfish, aoa_phr_adrun_human, aoa_phr_adrun_stvfish, aoa_treatment_level, aoa_rfactor));
             }
         } catch (ServiceException | JSONException ex) {
-            this.error_msg = "Cannot process the input JSON: " + ex.getMessage();
-            LOG.log(Level.SEVERE, this.error_msg);
+           
+            LOG.log(Level.SEVERE, "Cannot process the input JSON",ex);
+           throw new ServiceException("JSON Exception",ex); 
+            
         }
     }
 
     @Override
-    protected String process() throws Exception {
-        if (this.error_msg.isEmpty()) {
-            try (
-                    Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
-                    Statement statement = conn.createStatement();) {
+    protected void doProcess() throws Exception {
+        
+             try (Connection conn = getResourceJDBC(WQM_ID);
+                Statement statement = conn.createStatement()) {
 
-                for (V1_0.Input ip : components) {
+                for (Input ip : components) {
                     String query = "SELECT threshold_treatment_score FROM wqm_threshold_scores WHERE wqm_concern=" + "'" + "Nitrogen in Ground Water" + "'" + "AND hazard_loss_rating ='" + ip.aoa_nslp + "' AND treatment_level='" + ip.aoa_treatment_level + "';";
                     ResultSet results = statement.executeQuery(query);
                     int aoa_nleach_threshold = 0;
@@ -144,24 +148,24 @@
                     while (results.next()) {
                         aoa_pdrift_fish_threshold = results.getInt("threshold_treatment_score");
                     }
-                    result1.add(new V1_0.Result1(ip.AoAId, aoa_nleach_threshold, aoa_nrun_threshold, aoa_sedrun_threshold, aoa_prun_threshold, aoa_pleach_human_threshold, aoa_pleach_matcfish_threshold, aoa_psorun_human_threshold, aoa_psorun_matcfish_threshold, aoa_padrun_human_threshold, aoa_padrun_stvfish_threshold, aoa_pdrift_human_threshold, aoa_pdrift_fish_threshold));
+                    result1.add(new Result1(ip.AoAId, aoa_nleach_threshold, aoa_nrun_threshold, aoa_sedrun_threshold, aoa_prun_threshold, aoa_pleach_human_threshold, aoa_pleach_matcfish_threshold, aoa_psorun_human_threshold, aoa_psorun_matcfish_threshold, aoa_padrun_human_threshold, aoa_padrun_stvfish_threshold, aoa_pdrift_human_threshold, aoa_pdrift_fish_threshold));
                 }
             } catch (ServiceException | SQLException ex) {
-                this.error_msg = "Cannot process that request: " + ex.getMessage();
-                LOG.log(Level.SEVERE, this.error_msg);
+                LOG.log(Level.SEVERE,"Cannot process that request",ex);
+            throw new ServiceException("SQL Exception",ex);
             }
-        }
+        
 
-        return (this.error_msg.isEmpty() ? EXEC_OK : this.error_msg);
+       
     }
 
     @Override
     //writing the results back to JSON
     protected void postProcess() throws Exception {
-        if (this.error_msg.isEmpty()) {
+      
             try {
                 JSONArray result1Arr = new JSONArray();
-                for (V1_0.Result1 rs1 : result1) {
+                for (Result1 rs1 : result1) {
                     JSONArray tmpArr = new JSONArray();
                     tmpArr.put(JSONUtils.dataDesc("AoAId", rs1.AoAId, "Area of Analysis Identifier"));
                     tmpArr.put(JSONUtils.dataDesc("aoa_nleach_threshold", rs1.aoa_nleach_threshold, "Nitrogen Leaching Threshold Score"));
@@ -181,11 +185,10 @@
 
                 putResult("operation", result1Arr);
             } catch (JSONException ex) {
-                this.error_msg = "Could not create result JSON: " + ex.getMessage();
-                LOG.log(Level.SEVERE, this.error_msg);
-                throw new Exception(this.error_msg);
+                LOG.log(Level.SEVERE,"Could not create result JSON",ex);
+                throw new ServiceException("JSONException",ex);
             }
-        }
+        
     }
 
     public class Input {

src/java/m/wqm/wqsr/V1_0.java

@@ -7,9 +7,11 @@
 
 import csip.ModelDataService;
 import csip.ServiceException;
+import csip.annotations.Resource;
 import csip.utils.JSONUtils;
 import java.sql.Connection;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.List;
@@ -20,7 +22,8 @@
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
-import wqm.utils.WQMTools;
+import wqm.utils.DBResources;
+import static wqm.utils.DBResources.SSURGO_ID;
 
 /**
  * WQM-01: Water Quality Sensitivity Rating (WQSR)
@@ -32,9 +35,10 @@
         + "Sensitivity Rating (WQSR) spatial layer and computes a sensitivity rating and treatment "
         + "level required for mitigating nutrient and pesticide loss potentials and hazards.")
 @Path("m/wqm/wqsr/1.0")
+@Resource(from = DBResources.class)
 public class V1_0 extends ModelDataService {
 
-    List<V1_0.AoA> list = new ArrayList<>();
+    List<AoA> list = new ArrayList<>();
 
     @Override
     public void preProcess() throws ServiceException, JSONException {
@@ -65,11 +69,11 @@
     }
 
     @Override
-    public String process() throws ServiceException {
-        try (Connection tempCon = WQMTools.getConnection("ssurgo", LOG)) {
-            tempCon.setAutoCommit(false);
-            try (Statement stmt = tempCon.createStatement()) {
-                for (V1_0.AoA aoa : list) {
+    public void doProcess() throws ServiceException, SQLException {
+        try (Connection tempCon = getResourceJDBC(SSURGO_ID);
+             Statement stmt = tempCon.createStatement()) {
+          
+                for (AoA aoa : list) {
                     double aoaBaseArea = 0.0;
                     double aoaSensitiveArea = 0.0;
                     double aoaCriticalArea = 0.0;
@@ -102,17 +106,17 @@
                     }
                 }
             }
-        } catch (Exception e) {
+         catch (Exception e) {
             LOG.info(e.toString());
             throw new ServiceException(e);
         }
-        return EXEC_OK;
+       
     }
 
     @Override
     public void postProcess() throws JSONException {
         JSONArray finalArr = new JSONArray();
-        for (V1_0.AoA aoa : list) {
+        for (AoA aoa : list) {
             JSONArray resultArr = new JSONArray();
             resultArr.put(JSONUtils.dataDesc("AoAId", aoa.getAoAId(), "Area of Analysis Identifier"));
             resultArr.put(JSONUtils.dataDesc("wqs_Rating", aoa.getWQSRating(), "WQS Rating"));

test/service_tests/STest.java

@@ -17,7 +17,8 @@
 
     @Rule
     public TestName name = new TestName();
-
+    
+   
     private void run() throws Exception {
         String testFolder = new File(getClass().getCanonicalName().replace('.', '/')).getParent();
         JSONArray r = ServiceTest2.run(new Properties(), "test/" + testFolder + "/" + name.getMethodName() + ".json");
@@ -52,7 +53,7 @@
 
            This is it! 
     */
-    @Test public void  m_nutrient_slp_1_0__moderate() throws Exception { run(); }
+//    @Test public void  m_nutrient_slp_1_0__moderate() throws Exception { run(); }
     @Test public void  m_ipmscoresfull_1_0_1__getfull() throws Exception { run(); }
     @Test public void  m_pestlosspot_1_0__test_1() throws Exception { run(); }
     @Test public void  m_pestipmscoresfull_1_0__test_1() throws Exception { run(); }
@@ -63,8 +64,6 @@
     
 
     
-
-
     
 
     // .. more here

web/META-INF/csip-conf-CSU.json

 

web/META-INF/csip-conf.json

@@ -9,7 +9,6 @@
   "mssql-ssurgo.db": "jdbc:sqlserver:\/\/129.82.20.241:1433;databaseName=conservation_resources;user=rset-r;password=cs1prs3t",
   "mssql-ssurgo.db.driver":"com.microsoft.sqlserver.jdbc.SQLServerDriver",
   "rse-sql.db.driver":"com.microsoft.sqlserver.jdbc.SQLServerDriver",
-  "wqm.db": "jdbc:postgresql://csip.engr.colostate.edu:5435/wqm?user=postgres&password=admin",
-  "csip-wqm.version" : "$version: 0.0.0 xxxxxxx date, built at 2016-04-20 15:44 by ks_an$"
+  "wqm.db": "jdbc:postgresql://csip.engr.colostate.edu:5435/wqm?user=postgres&password=admin"
 }
 

web/WEB-INF/csip-defaults.json

@@ -1,4 +1,4 @@
 { 
-    "csip-wqm.version": "$version: 0.0.0 xxxxxxx date, built at 2016-04-20 15:44 by ks_an$"
+    "csip-wqm.version": "$version: 0.2.44 23641a4e49d7 2016-04-20 Sandeep Kasavaraju, built at 2016-04-21 08:30 by od$"
 }