Displaying differences for changeset
 
display as  

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;
                     }
                 }