Displaying differences for changeset
 
display as  

src/java/m/cfa/CDSN_Data.java

@@ -1,6 +1,7 @@
 package m.cfa;
 
 import java.io.BufferedReader;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.URL;
@@ -15,7 +16,7 @@
 import org.codehaus.jettison.json.JSONObject;
 
 /**
-* Last Updated: 28-April-2016
+* Last Updated: 17-May-2016
 * @author Tyler Wible
 * @since 19-April-2016
 */
@@ -158,19 +159,22 @@
         //WaterBodyName (lots)
         //WatershedManagementUnit (lots)
         
-        //Open the provided website
-        URL webpage = new URL(cdsnDataWebsite);
-        URLConnection yc = webpage.openConnection();
-        BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
-        //Read out all of the webpage out into an ArrayList<String>
-        String inputLine;
         ArrayList<String> pageData = new ArrayList<String>( );
-
-        while((inputLine = in.readLine()) != null){
-            pageData.add(inputLine);
+        
+        try{
+            //Open the provided website
+            URL webpage = new URL(cdsnDataWebsite);
+            URLConnection yc = webpage.openConnection();
+            BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
+            //Read out all of the webpage out into an ArrayList<String>
+            String inputLine;
+            while((inputLine = in.readLine()) != null){
+                pageData.add(inputLine);
+            }
+            in.close();
+        }catch (FileNotFoundException e){
+            //Leave array blank for later error messages pasted onto the user
         }
-        in.close();
-
         return pageData;
     }
     /**
@@ -198,8 +202,8 @@
         
         //Parse results
         ArrayList<String> resultFileContents = new ArrayList<String>();
-        resultFileContents.add("OrganizationIdentifier\tMonitoringLocationIdentifier\tMediaSubdivisionName\tActivityIdentifier\tStartDate\tStartTime\tMediaName\tActivityType\tCharacteristicName\tSampleFraction\tValueType\tStatus\tResultValue\tResultUnit\tAnalyticalMethodContext\tAnalyticalMethodIdentifier\tDetectionCondition\tQualifierCode");
         if(dataList.size() > 0){
+            resultFileContents.add("OrganizationIdentifier\tMonitoringLocationIdentifier\tMediaSubdivisionName\tActivityIdentifier\tStartDate\tStartTime\tMediaName\tActivityType\tCharacteristicName\tSampleFraction\tValueType\tStatus\tResultValue\tResultUnit\tAnalyticalMethodContext\tAnalyticalMethodIdentifier\tDetectionCondition\tQualifierCode");
             //parse the json string into a JSONArray and the object(s) within it
             JSONArray cdsnResponse =  new JSONArray(dataList.get(0));
             for(int i=0; i<cdsnResponse.length(); i++){
@@ -235,6 +239,8 @@
                             methodContext+"\t"+methodIdentifier+"\t"+detectionCondition+"\t"+QualifierCode);
                 }
             }
+        }else{
+            resultFileContents.add("No " +  wq_test + " data found for CDSN Station: " + stationID + " by: " + organizationID);
         }
         
         //convert Array list into String[][] array (column1 = date, column2 = value)