Displaying differences for changeset
 
display as  

src/java/m/wqm/pestmitgntechsfull/V1_0.java

@@ -12,8 +12,12 @@
 import oms3.annotations.Name;
 import org.codehaus.jettison.json.JSONArray;
 import csip.utils.JSONUtils;
-import java.sql.*;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.logging.Level;
+import org.codehaus.jettison.json.JSONException;
 import wqm.utils.DBResources;
 import static wqm.utils.DBResources.WQM_ID;
 
@@ -24,28 +28,24 @@
 
 public class V1_0 extends ModelDataService {
 
-    int ipm_technique_score_id;
-    int ipm_technique_id;
-    int ipm_technique_score;
-    String ipm_technique_name;
-    String wqm_concern;
-
-    ArrayList<Result1> result1 = new ArrayList<>();
+    private ArrayList<m.wqm.pestmitgntechsfull.V1_0.Result1> result1;
 
     @Override
     protected void doProcess() throws Exception {
+        result1 = new ArrayList<>();
         try (Connection conn = getResourceJDBC(WQM_ID);
                 Statement statement = conn.createStatement()) {
-            String query = "SELECT * FROM wqm_ipm_technique_scores"; // We need to return the entire table, so we use the not standard SELECT * 
+            String query = "SELECT * FROM wqm.wqm_ipm_technique_scores";
             try (ResultSet results = statement.executeQuery(query)) {
                 while (results.next()) {
-                    ipm_technique_score_id = results.getInt("ipm_technique_score_id");
-                    ipm_technique_id = results.getInt("ipm_technique_id");
-                    ipm_technique_score = results.getInt("ipm_technique_score");
-                    ipm_technique_name = results.getString("ipm_technique_name");
-                    wqm_concern = results.getString("wqm_concern");
+                    int ipm_technique_score_id = results.getInt("ipm_technique_score_id");
+                    int ipm_technique_id = results.getInt("ipm_technique_id");
+                    int ipm_technique_score = results.getInt("ipm_technique_score");
+                    String ipm_technique_name = results.getString("ipm_technique_name");
+                    String wqm_concern = results.getString("wqm_concern");
 
-                    result1.add(new Result1(ipm_technique_score_id, ipm_technique_id, ipm_technique_score, ipm_technique_name, wqm_concern));
+                    result1.add(new m.wqm.pestmitgntechsfull.V1_0.Result1(ipm_technique_score_id,
+                            ipm_technique_id, ipm_technique_score, ipm_technique_name, wqm_concern));
                 }
             }
         } catch (SQLException se) {
@@ -58,20 +58,25 @@
     @Override
     //writing the results back to JSON
     protected void postProcess() throws Exception {
-        JSONArray result1Arr = new JSONArray();
-        for (V1_0.Result1 rs1 : result1) {
-            JSONArray tmpArr = new JSONArray();
-            tmpArr.put(JSONUtils.dataDesc("ipm_technique_score_id", rs1.ipm_technique_score_id, "ipm_technique_score_id"));
-            tmpArr.put(JSONUtils.dataDesc("ipm_technique_id", rs1.ipm_technique_id, "ipm_technique_id"));
-            tmpArr.put(JSONUtils.dataDesc("ipm_technique_score", rs1.ipm_technique_score, "ipm_technique_score"));
-            tmpArr.put(JSONUtils.dataDesc("ipm_technique_name", rs1.ipm_technique_name, "Name of the integrated pest management technique"));
-            tmpArr.put(JSONUtils.dataDesc("wqm_concern", rs1.wqm_concern, "WQM resource concern:  pesticide leaching, pesticide solution runoff, pesticide adsorbed runoff, pesticide drift"));
-            result1Arr.put(JSONUtils.dataDesc("IPM techn Scores", tmpArr, "IPMTechnScores"));
+        try {
+            JSONArray result1Arr = new JSONArray();
+            for (m.wqm.pestmitgntechsfull.V1_0.Result1 rs1 : result1) {
+                JSONArray tmpArr = new JSONArray();
+                tmpArr.put(JSONUtils.dataDesc("ipm_technique_score_id", rs1.ipm_technique_score_id, "ipm_technique_score_id"));
+                tmpArr.put(JSONUtils.dataDesc("ipm_technique_id", rs1.ipm_technique_id, "ipm_technique_id"));
+                tmpArr.put(JSONUtils.dataDesc("ipm_technique_score", rs1.ipm_technique_score, "ipm_technique_score"));
+                tmpArr.put(JSONUtils.dataDesc("ipm_technique_name", rs1.ipm_technique_name, "Name of the integrated pest management technique"));
+                tmpArr.put(JSONUtils.dataDesc("wqm_concern", rs1.wqm_concern, "WQM resource concern:  pesticide leaching, pesticide solution runoff, pesticide adsorbed runoff, pesticide drift"));
+                result1Arr.put(JSONUtils.dataDesc("IPM techn Scores", tmpArr, "IPMTechnScores"));
+            }
+            putResult("operation", result1Arr);
+        } catch (JSONException ex) {
+            LOG.log(Level.SEVERE, "Error in processing the response JSON for WQM-25!", ex);
+            throw new ServiceException("Error in processing the response JSON.", ex);
         }
-        putResult("operation", result1Arr);
     }
 
-    public class Result1 {
+    static class Result1 {
 
         int ipm_technique_score_id;
         int ipm_technique_id;

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

@@ -1,6 +1,5 @@
 {
-  "metainfo": {},
-  "parameter": [
-
-  ]
+    "metainfo": {},
+    "parameter": [
+    ]
 }
\ No newline at end of file