Displaying differences for changeset
 
display as  

src/java/m/dssat/substor/V1_2.java

@@ -15,12 +15,14 @@
 import static csip.ModelDataService.KEY_PARAMETER;
 import static csip.ModelDataService.KEY_STATUS;
 import static csip.ModelDataService.KEY_VALUE;
+import csip.ModelDataServiceCall;
 import csip.PayloadParameter;
 import csip.ServiceException;
 import csip.annotations.Resource;
 import javax.ws.rs.Path;
 import csip.annotations.*;
 import csip.utils.JSONUtils;
+import csip.utils.Parallel;
 import csip.utils.ZipFiles;
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
@@ -83,7 +85,11 @@
 
     String flag = getSimulationType(simulation_type);
     parseXfile(ids, paramFile);
-    getClimateData(ids, longitude, latitude, start_date, end_date);
+    Parallel.par(Config.getBoolean("dssat.serial.datafetch", false),
+        () -> {
+          fetchClimate(ids, longitude, latitude, start_date, end_date);
+        }
+    );
     getSoilData(ids, longitude, latitude, cokey);
 
     Executable p = resources().getExe("DSSAT");
@@ -208,43 +214,26 @@
     System.out.println("destroy simple service");
   }
 
-  private void getClimateData(XfileIDs ids, double longitude, double latitude, String start_date, String end_date) throws JSONException, Exception {
-    JSONObject climateRequest = new JSONObject();
-    JSONObject meta = new JSONObject();
-    meta.put("uid", getSUID());
-    JSONArray paramObj = new JSONArray();
-    JSONObject fileName = new JSONObject();
-    JSONObject lonObj = new JSONObject();
-    JSONObject latObj = new JSONObject();
-    JSONObject startdate_json = new JSONObject();
-    JSONObject enddate_json = new JSONObject();
+  private void fetchClimate(XfileIDs ids, double longitude, double latitude, String start_date, String end_date) throws JSONException, Exception {
     String weatherFile_name = ids.getWthID();
 
-    climateRequest.put(KEY_METAINFO, meta);
-    climateRequest.put(KEY_PARAMETER, paramObj);
+    ModelDataServiceCall res = new ModelDataServiceCall()
+        .withMeta(KEY_METAINFO, getSUID())
+        .withParam(FILE_NAME, weatherFile_name)
+        .withParam(LONGITUDE, longitude)
+        .withParam(LATITUDE, latitude)
+        .withParam(START_DATE, start_date)
+        .withParam(END_DATE, end_date)
+        .setUrl(Config.getString("dssat.weather.service", "http://csip.engr.colostate.edu:8088/csip-climate/d/csm_weather/1.0"))
+        .withLogger()
+        .call();
 
-    paramObj.put(fileName);
-    fileName.put(KEY_NAME, FILE_NAME);
-    fileName.put(KEY_VALUE, weatherFile_name);
-
-    paramObj.put(lonObj);
-    lonObj.put(KEY_NAME, LONGITUDE);
-    lonObj.put(KEY_VALUE, longitude);
-
-    paramObj.put(latObj);
-    latObj.put(KEY_NAME, LATITUDE);
-    latObj.put(KEY_VALUE, latitude);
-
-    paramObj.put(startdate_json);
-    startdate_json.put(KEY_NAME, START_DATE);
-    startdate_json.put(KEY_VALUE, start_date);
-
-    paramObj.put(enddate_json);
-    enddate_json.put(KEY_NAME, END_DATE);
-    enddate_json.put(KEY_VALUE, end_date);
-
-    serviceCall(weatherFile_name, climateRequest, WTH_EXT);
-
+    if (res.isFinished()) {
+      String fileName = weatherFile_name + WTH_EXT;
+      res.download(fileName, getWorkspaceFile(fileName));
+    } else {
+      throw new ServiceException(res.getError());
+    }
   }
 
   private void getSoilData(XfileIDs ids, double longitude, double latitude, String cokey) throws JSONException, Exception {