From a123015d16b5a6e1c57f9329aaffb1da7ef12d01 Mon Sep 17 00:00:00 2001 From: Gianpaolo Coro Date: Fri, 30 Oct 2015 17:25:40 +0000 Subject: [PATCH] git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/SeaDataNetConnector@120146 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../seadatanet/DivaAnalysisGetResponse.java | 7 +++ .../seadatanet/DivaHTTPClient.java | 31 +++++++++++-- .../dataanalysis/seadatanet/Downloader.java | 43 ----------------- .../seadatanet/SeaDataNetConnector.java | 46 +++++++++++++++---- .../test/TestSeaDataNetConnector.java | 18 ++++---- 5 files changed, 81 insertions(+), 64 deletions(-) delete mode 100644 src/org/gcube/dataanalysis/seadatanet/Downloader.java diff --git a/src/org/gcube/dataanalysis/seadatanet/DivaAnalysisGetResponse.java b/src/org/gcube/dataanalysis/seadatanet/DivaAnalysisGetResponse.java index 57f935a..edfc496 100644 --- a/src/org/gcube/dataanalysis/seadatanet/DivaAnalysisGetResponse.java +++ b/src/org/gcube/dataanalysis/seadatanet/DivaAnalysisGetResponse.java @@ -32,6 +32,13 @@ public class DivaAnalysisGetResponse { this.identifier = id; } + public Double getVmin() { + return vmin; + } + + public void setVmin(Double vmin) { + this.vmin = vmin; + } public Double getVmax() { return vmax; diff --git a/src/org/gcube/dataanalysis/seadatanet/DivaHTTPClient.java b/src/org/gcube/dataanalysis/seadatanet/DivaHTTPClient.java index cb43e04..a0199d4 100644 --- a/src/org/gcube/dataanalysis/seadatanet/DivaHTTPClient.java +++ b/src/org/gcube/dataanalysis/seadatanet/DivaHTTPClient.java @@ -4,6 +4,8 @@ import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; @@ -11,6 +13,7 @@ import java.io.InputStreamReader; import java.io.StringReader; import java.net.HttpURLConnection; import java.net.URL; +import java.net.URLConnection; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -26,6 +29,7 @@ import org.xml.sax.SAXException; public class DivaHTTPClient { public static String WEB_HTTP="http://gher-diva.phys.ulg.ac.be/web-vis/Python/web"; + public static String DOWN_FILE_NC="/download?fieldname="; public static String postFile(File file) throws Exception { String crlf = "\r\n"; @@ -221,6 +225,27 @@ public class DivaHTTPClient { } + public static void downloadFileDiva(String fileurl, String destinationFile) throws Exception{ + try { + URL smpFile = new URL(fileurl); + URLConnection uc = (URLConnection) smpFile.openConnection(); + InputStream is = uc.getInputStream(); + AnalysisLogger.getLogger().debug("Retrieving file from " + fileurl + " to :" + destinationFile); + inputStreamToFile(is, destinationFile); + is.close(); + } catch (Exception e) { + throw e; + } + } + + public static void inputStreamToFile(InputStream is, String path) throws FileNotFoundException, IOException { + FileOutputStream out = new FileOutputStream(new File(path)); + byte buf[] = new byte[1024]; + int len = 0; + while ((len = is.read(buf)) > 0) + out.write(buf, 0, len); + out.close(); + } public static void main(String[] args) throws Exception { @@ -229,15 +254,15 @@ public class DivaHTTPClient { //System.out.println(getAnalysis(response.getSessionid(),5,4,76,78,1,35,78,1,2)); System.out.println(""+response); - DivaAnalysisGetResponse respAnalysis = getAnalysis(response.getSessionid(),10, 0.8, -180, 180, 3, -70, 70, 3, 1); + DivaAnalysisGetResponse respAnalysis = getAnalysis(response.getSessionid(),10, 0.8, -180, 180, 3, -80, 80, 3, 1); System.out.println("Response: "+respAnalysis.toString()); - Downloader downFileNC = new Downloader(); + //Downloader downFileNC = new Downloader(); //System.out.println(System.getProperty("user.dir")+File.separator+"temp.nc"); File f=new File(System.getProperty("user.dir")+File.separator+"temp.nc"); if(!f.exists()) f.createNewFile(); - downFileNC.downloadFile(WEB_HTTP+"/download?fieldname="+ + downloadFileDiva(WEB_HTTP+DOWN_FILE_NC+ respAnalysis.getIdentifier(),System.getProperty("user.dir")+File.separator+"temp.nc"); } diff --git a/src/org/gcube/dataanalysis/seadatanet/Downloader.java b/src/org/gcube/dataanalysis/seadatanet/Downloader.java deleted file mode 100644 index 3df97dc..0000000 --- a/src/org/gcube/dataanalysis/seadatanet/Downloader.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.gcube.dataanalysis.seadatanet; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; - -import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger; - -public class Downloader { - - public static void downloadFile(String fileurl, String destinationFile) throws Exception{ - try { - URL smpFile = new URL(fileurl); - URLConnection uc = (URLConnection) smpFile.openConnection(); - InputStream is = uc.getInputStream(); - AnalysisLogger.getLogger().debug("Retrieving file from " + fileurl + " to :" + destinationFile); - inputStreamToFile(is, destinationFile); - is.close(); - } catch (Exception e) { - throw e; - } - } - - public static void inputStreamToFile(InputStream is, String path) throws FileNotFoundException, IOException { - FileOutputStream out = new FileOutputStream(new File(path)); - byte buf[] = new byte[1024]; - int len = 0; - while ((len = is.read(buf)) > 0) - out.write(buf, 0, len); - out.close(); - } - - /** - * - */ - public static void main(String args[]) throws Exception{ - downloadFile("https://dl.dropboxusercontent.com/u/12809149/2_Reviewed.jpg","test.jpg"); - } -} diff --git a/src/org/gcube/dataanalysis/seadatanet/SeaDataNetConnector.java b/src/org/gcube/dataanalysis/seadatanet/SeaDataNetConnector.java index 3bf4759..5f2c16e 100644 --- a/src/org/gcube/dataanalysis/seadatanet/SeaDataNetConnector.java +++ b/src/org/gcube/dataanalysis/seadatanet/SeaDataNetConnector.java @@ -49,18 +49,19 @@ public class SeaDataNetConnector extends StandardLocalExternalAlgorithm { @Override protected void process() throws Exception { + + + String outpath = config.getPersistencePath(); File neofile = new File(outpath,"seadn_diva_"+UUID.randomUUID()+".nc"); + + /* BufferedWriter fileWriter = new BufferedWriter(new FileWriter(neofile)); fileWriter.write("test test"); fileWriter.close(); + */ - statResultMap.put("Minimum value of the analysis", "1"); - statResultMap.put("Maximum value of the analysis", "1"); - statResultMap.put("Number of observations used", "1"); - statResultMap.put("Posterior probability of the model", "1"); - - outputfile=neofile; + //outputfile=neofile; AnalysisLogger.getLogger().debug("Input Table: "+config.getParam("InputTable")); AnalysisLogger.getLogger().debug("Input Long: "+config.getParam("Longitude")); @@ -71,8 +72,8 @@ public class SeaDataNetConnector extends StandardLocalExternalAlgorithm { AnalysisLogger.getLogger().debug("Longitude max X: "+config.getParam("LongitudeMaxValue")); AnalysisLogger.getLogger().debug("Longitude resolution: "+config.getParam("LongitudeResolution")); - AnalysisLogger.getLogger().debug("Latitude min X: "+config.getParam("LatitudeMinValue")); - AnalysisLogger.getLogger().debug("Latitude max X: "+config.getParam("LatitudeMaxValue")); + AnalysisLogger.getLogger().debug("Latitude min Y: "+config.getParam("LatitudeMinValue")); + AnalysisLogger.getLogger().debug("Latitude max Y: "+config.getParam("LatitudeMaxValue")); AnalysisLogger.getLogger().debug("Latitude resolution: "+config.getParam("LatitudeResolution")); AnalysisLogger.getLogger().debug("Correlation length: "+config.getParam("CorrelationLength")); @@ -105,11 +106,38 @@ public class SeaDataNetConnector extends StandardLocalExternalAlgorithm { } fileWriterDiva.close(); + //integration DivaHttpClient + //UPLOADFILE for DIVA DivaHTTPClient neo= new DivaHTTPClient(); - DivaFilePostResponse response=neo.uploadFile(new File("C:"+File.separator+"Users"+File.separator+"marbas"+File.separator+"Desktop"+File.separator+"temperature_argo.txt")); + DivaFilePostResponse response=neo.uploadFile(fileForDiva); AnalysisLogger.getLogger().debug("Server Response: "+response.getSessionid()); + //ANALYSIS + Double correlationVal = Double.parseDouble(config.getParam("CorrelationLength")); + Double signalNoiseVal = Double.parseDouble(config.getParam("SignalNoise")); + Double longMinVal = Double.parseDouble(config.getParam("LongitudeMinValue")); + Double longMaxVal = Double.parseDouble(config.getParam("LongitudeMaxValue")); + Double longResolutionVal = Double.parseDouble(config.getParam("LongitudeResolution")); + Double latMinVal = Double.parseDouble(config.getParam("LatitudeMinValue")); + Double latMaxVal = Double.parseDouble(config.getParam("LatitudeMaxValue")); + Double latResolutionVal = Double.parseDouble(config.getParam("LatitudeResolution")); + Double depthLevelVal = Double.parseDouble(config.getParam("DepthLevel")); + + DivaAnalysisGetResponse respAnalysis = neo.getAnalysis(response.getSessionid(), + correlationVal, signalNoiseVal, longMinVal, longMaxVal, longResolutionVal, + latMinVal, latMaxVal, latResolutionVal, depthLevelVal); + + statResultMap.put("Minimum value of the analysis",""+respAnalysis.getVmin()); + statResultMap.put("Maximum value of the analysis", ""+respAnalysis.getVmax()); + statResultMap.put("Number of observations used", ""+respAnalysis.getStat_obs_count_used()); + statResultMap.put("Posterior probability of the model", ""+respAnalysis.getStat_posteriori_stn()); + + //DOWNLOAD FILE + neo.downloadFileDiva(neo.WEB_HTTP+neo.DOWN_FILE_NC+respAnalysis.getIdentifier(), + neofile.getAbsolutePath()); + + } diff --git a/src/org/gcube/dataanalysis/seadatanet/test/TestSeaDataNetConnector.java b/src/org/gcube/dataanalysis/seadatanet/test/TestSeaDataNetConnector.java index 6c33a28..8978c0c 100644 --- a/src/org/gcube/dataanalysis/seadatanet/test/TestSeaDataNetConnector.java +++ b/src/org/gcube/dataanalysis/seadatanet/test/TestSeaDataNetConnector.java @@ -48,17 +48,17 @@ public class TestSeaDataNetConnector { config.setParam("Latitude", "centerlat"); config.setParam("Quantity", "landdist"); - config.setParam("LongitudeMinValue", "76"); - config.setParam("LongitudeMaxValue", "78"); - config.setParam("LongitudeResolution", "1"); + config.setParam("LongitudeMinValue", "-180"); + config.setParam("LongitudeMaxValue", "180"); + config.setParam("LongitudeResolution", "3"); - config.setParam("LatitudeMinValue", "35"); - config.setParam("LatitudeMaxValue", "78"); - config.setParam("LatitudeResolution", "1"); + config.setParam("LatitudeMinValue", "-70"); + config.setParam("LatitudeMaxValue", "70"); + config.setParam("LatitudeResolution", "3"); - config.setParam("CorrelationLength", "5"); - config.setParam("SignalNoise", "4"); - config.setParam("DepthLevel", "2"); + config.setParam("CorrelationLength", "10"); + config.setParam("SignalNoise", "0.8"); + config.setParam("DepthLevel", "1"); config.setParam("DatabaseUserName","utente"); config.setParam("DatabasePassword","d4science");