Displaying differences for changeset
 
display as  

tools/GetClimateWindSoil/src/getclimatewindsoil/CliWindSoil.java

@@ -21,22 +21,31 @@
  *
  * @author <a href="mailto:shaun.case@colostate.edu">Shaun Case</a>
  */
-public class CliWindSoil extends ServiceCall{
-    double latitude, longitude;
+public class CliWindSoil extends ServiceCall {
+
+    double latitude = Double.NaN, longitude = Double.NaN;
+    String polyCoordinates = null;
     File data = null;
 
-    public CliWindSoil( double lat, double lon, String URI) {
+    public CliWindSoil(double lat, double lon, String URI) {
         super(URI);
         latitude = lat;
         longitude = lon;
-        
+
         errorPrefix = "CliWindSoilBundle";
     }
 
-    public File data(){
+    public CliWindSoil(String _coordinates, String URI) {
+        super(URI);
+        polyCoordinates = _coordinates;
+
+        errorPrefix = "CliWindSoilBundle";
+    }
+
+    public File data() {
         return data;
     }
-    
+
     @Override
     protected void parseResults() throws ServiceException {
         //   Error checking has already been done on these results.
@@ -51,8 +60,8 @@
             Map<String, JSONObject> resultMap = JSONUtils.getResults(results);
             String fileName = getReturnMetainfo().getString("suid") + ".zip";
             String tURI = JSONUtils.getStringParam(resultMap, fileName, "");
-            URI windURI = new URI( tURI );
-            
+            URI windURI = new URI(tURI);
+
             Client fileGet = new Client();
 
             data = fileGet.doGET(windURI.toString(), new File(fileName));
@@ -74,22 +83,36 @@
             requestMetainfoObject.put("MultipartRequest", "Bundled Service Request From csip-crp MetaModeling CliWindSoil Service");
             request.put(KEY_METAINFO, requestMetainfoObject);
 
-            JSONObject location = new JSONObject();       
+            JSONObject location = new JSONObject();
             JSONArray coordinates = new JSONArray();
-            
+
             location.put("name", "aoa_geometry");
-            location.put("type", "Point");
-            coordinates.put(longitude);
-            coordinates.put(latitude);
-            location.put("coordinates", coordinates);
+            if ((null != polyCoordinates) && !polyCoordinates.isEmpty()) {
+                String tType = polyCoordinates.substring(0, polyCoordinates.indexOf("[") - 1).trim();
+                String tCoordinates = polyCoordinates.substring(polyCoordinates.indexOf("[") - 1).trim();
+                
+                location.put("type", tType);
+                coordinates = new JSONArray( tCoordinates);
+                location.put("coordinates", coordinates);
+
+            } else {
+                if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
+                    location.put("type", "Point");
+                    coordinates.put(longitude);
+                    coordinates.put(latitude);
+                    location.put("coordinates", coordinates);
+                } else {
+                    throw new ServiceException("No coordinates were specified.");
+                }
+            }
 
             dataArray.put(location);
-            
+
             request.put(KEY_PARAMETER, dataArray);
 
         } catch (JSONException ex) {
             throwServiceCallException("Cannot create the JSON request.", ex);
         }
-    }              
-    
+    }
+
 }

tools/GetClimateWindSoil/src/getclimatewindsoil/GetClimateWindSoil.java

@@ -34,7 +34,9 @@
 
             File inputFile = new File(args[0]);
             BufferedReader inputStream = Files.newBufferedReader(inputFile.toPath());
-            double[][] coordinates = new double[10][2];
+            double[][] coordinates = new double[maxThreads][2];
+            String[] sCoordinates = new String[maxThreads];
+            boolean gotString = false;
 
             while (!fileDone) {
                 int count = 0;
@@ -45,11 +47,21 @@
                         lineNumber++;
                         String[] latLon = inLine.split(",");
                         if (latLon.length == 2) {
+                            gotString = false;
                             coordinates[count][0] = Double.parseDouble(latLon[0]);
                             coordinates[count][1] = Double.parseDouble(latLon[1]);
+                            sCoordinates[count] = "";
                             count++;
                         } else {
-                            throw new ServiceException("Malformed input file, invalid number of coordinates on line: " + lineNumber);
+                            if (latLon.length > 2) {
+                                gotString = true;
+                                sCoordinates[count] = inLine;
+                                coordinates[count][0] = Double.NaN;
+                                coordinates[count][1] = Double.NaN;
+                                count++;
+                            } else {
+                                throw new ServiceException("Malformed input file, invalid number of coordinates on line: " + lineNumber);
+                            }
                         }
                     } else {
                         fileDone = true;
@@ -57,7 +69,9 @@
                 }
                 CountDownLatch latch = new CountDownLatch(count);
                 for (int i = 0; i < count; i++) {
-                    ServiceCallThread tServiceCall = new ServiceCallThread(coordinates[i][0], coordinates[i][1], latch);
+                    ServiceCallThread tServiceCall = ((!gotString && (!Double.isNaN(coordinates[i][0])) && (!Double.isNaN(coordinates[i][1]))) 
+                            ? new ServiceCallThread(coordinates[i][0], coordinates[i][1], latch)
+                            : new ServiceCallThread(sCoordinates[i], latch));
                     tServiceCall.start();
                 }
 

tools/GetClimateWindSoil/src/getclimatewindsoil/ServiceCallThread.java

@@ -14,25 +14,34 @@
  *
  * @author <a href="mailto:shaun.case@colostate.edu">Shaun Case</a>
  */
-public class ServiceCallThread extends Thread{
-    protected double latitude, longitude;
+public class ServiceCallThread extends Thread {
+
+    protected double latitude = Double.NaN, longitude = Double.NaN;
+    protected String coordinates = null;
     protected CountDownLatch latch;
-    
+
     public ServiceCallThread(double latitude, double longitude, CountDownLatch latch) {
         this.latitude = latitude;
-        this.longitude = longitude;     
+        this.longitude = longitude;
+        this.latch = latch;
+    }
+
+    public ServiceCallThread(String _coordinates, CountDownLatch latch) {
+        coordinates = _coordinates;
         this.latch = latch;
     }
 
     @Override
     public void run() {
-        CliWindSoil serviceCall = new CliWindSoil(latitude, longitude, "http://csip.engr.colostate.edu:8092/csip-crp/m/cliwindsoil/1.0");
+        CliWindSoil serviceCall = ((!Double.isNaN(latitude) && !Double.isNaN(longitude))
+                ? new CliWindSoil(latitude, longitude, "http://csip.engr.colostate.edu:8092/csip-crp/m/cliwindsoil/1.0")
+                : new CliWindSoil(coordinates, "http://csip.engr.colostate.edu:8092/csip-crp/m/cliwindsoil/1.0"));
         try {
             serviceCall.call();
         } catch (ServiceException ex) {
             Logger.getLogger(ServiceCallThread.class.getName()).log(Level.SEVERE, null, ex);
         }
-        
-        latch.countDown();        
+
+        latch.countDown();
     }
 }