This commit is contained in:
Gianpaolo Coro 2015-10-30 17:25:40 +00:00
parent 81dcaa34cb
commit a123015d16
5 changed files with 81 additions and 64 deletions

View File

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

View File

@ -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");
}

View File

@ -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");
}
}

View File

@ -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());
}

View File

@ -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");