Gianpaolo Coro 2014-02-14 15:50:56 +00:00
parent 9874155dcb
commit 6e7147c050
9 changed files with 1065 additions and 0 deletions

View File

@ -0,0 +1,334 @@
package org.gcube.dataanalysis.geo.wps.client;
import java.math.BigInteger;
import java.net.URL;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import net.opengis.wps.x100.CapabilitiesDocument;
import net.opengis.wps.x100.ComplexDataType;
import net.opengis.wps.x100.ExecuteDocument;
import net.opengis.wps.x100.ExecuteResponseDocument;
import net.opengis.wps.x100.ExecuteResponseDocument.ExecuteResponse.ProcessOutputs;
import net.opengis.wps.x100.InputDescriptionType;
import net.opengis.wps.x100.InputType;
import net.opengis.wps.x100.OutputDescriptionType;
import net.opengis.wps.x100.ProcessBriefType;
import net.opengis.wps.x100.ProcessDescriptionType;
import org.apache.xmlbeans.XmlString;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.datatypes.StatisticalType;
import org.gcube.dataanalysis.geo.wps.mappings.WPS2SM;
import org.n52.wps.client.ExecuteRequestBuilder;
import org.n52.wps.client.WPSClientSession;
import org.w3c.dom.NodeList;
public class WPSClient {
private ProcessBriefType[] processesList;
private String wpsServiceURL;
private InputDescriptionType[] currentInputs;
private OutputDescriptionType[] currentOutputs;
public OutputDescriptionType[] getCurrentOutputs() {
return currentOutputs;
}
public void setCurrentOutputs(OutputDescriptionType[] currentOutputs) {
this.currentOutputs = currentOutputs;
}
private List<StatisticalType> currentInputStatisticalTypes;
private Hashtable<String, StatisticalType> currentOutputStatisticalTypes;
private ProcessDescriptionType currentProcessDescription;
public Hashtable<String, StatisticalType> getCurrentOutputStatisticalTypes() {
return currentOutputStatisticalTypes;
}
public void setCurrentOutputStatisticalTypes(Hashtable<String, StatisticalType> currentOutputStatisticalTypes) {
this.currentOutputStatisticalTypes = currentOutputStatisticalTypes;
}
public String getWpsServiceURL() {
return wpsServiceURL;
}
public void setWpsServiceURL(String wpsServiceURL) {
this.wpsServiceURL = wpsServiceURL;
}
public InputDescriptionType[] getCurrentInputs() {
return currentInputs;
}
public void setCurrentInputs(InputDescriptionType[] currentInputs) {
this.currentInputs = currentInputs;
}
public List<StatisticalType> getCurrentInputStatisticalTypes() {
return currentInputStatisticalTypes;
}
public void setCurrentInputStatisticalTypes(List<StatisticalType> currentStatisticalTypes) {
this.currentInputStatisticalTypes = currentStatisticalTypes;
}
public String getCurrentProcessID() {
return currentProcessID;
}
public void setCurrentProcessID(String currentProcessID) {
this.currentProcessID = currentProcessID;
}
public String getCurrentProcessTitle() {
return currentProcessTitle;
}
public void setCurrentProcessTitle(String currentProcessTitle) {
this.currentProcessTitle = currentProcessTitle;
}
public String getCurrentProcessAbstract() {
return currentProcessAbstract;
}
public void setCurrentProcessAbstract(String currentProcessAbstract) {
this.currentProcessAbstract = currentProcessAbstract;
}
private String currentProcessID;
private String currentProcessTitle;
private String currentProcessAbstract;
// example: http://wps01.i-marine.d4science.org/wps/WebProcessingService
public WPSClient(String wpsServiceURL) throws Exception {
this.wpsServiceURL = wpsServiceURL;
}
public void describeProcess(String processID) throws Exception {
describeProcess(processID, null);
}
public void describeProcess(String processID, URL processDescriptionURL) throws Exception {
WPSClientSession wpsClient = WPSClientSession.getInstance();
try {
ProcessDescriptionType processDescription = wpsClient.getProcessDescription(wpsServiceURL, processID);
this.currentProcessDescription = processDescription;
// processDescription.set(XmlString.Factory.parse(new URL("http://schemas.opengis.net/wps/1.0.0/examples/40_wpsDescribeProcess_response.xml")));
if (processDescriptionURL != null)
processDescription.set(XmlString.Factory.parse(processDescriptionURL));
AnalysisLogger.getLogger().debug(processDescription.toString());
currentProcessID = processDescription.getIdentifier().getStringValue();
currentProcessTitle = processDescription.getTitle().getStringValue();
currentProcessAbstract = processDescription.getAbstract() != null ? processDescription.getAbstract().getStringValue() : "";
AnalysisLogger.getLogger().debug("WPSClient->Process ID:" + currentProcessID);
AnalysisLogger.getLogger().debug("WPSClient->Process Title:" + currentProcessTitle);
AnalysisLogger.getLogger().debug("WPSClient->Process Abstract:" + currentProcessAbstract);
InputDescriptionType[] inputList = processDescription.getDataInputs().getInputArray();
AnalysisLogger.getLogger().debug("WPSClient->Fetching Inputs");
currentInputStatisticalTypes = new ArrayList<StatisticalType>();
for (InputDescriptionType input : inputList) {
StatisticalType stype = WPS2SM.convert2SMType(input);
currentInputStatisticalTypes.add(stype);
AnalysisLogger.getLogger().debug("WPSClient->Converted Into a Statistical Type: " + stype);
}
AnalysisLogger.getLogger().debug("WPSClient->Fetching Outputs");
OutputDescriptionType[] outputList = processDescription.getProcessOutputs().getOutputArray();
currentOutputStatisticalTypes = new Hashtable<String, StatisticalType>();
currentOutputs = outputList;
for (OutputDescriptionType output : outputList) {
AnalysisLogger.getLogger().debug("WPSClient->Output id:" + output.getIdentifier().getStringValue());
if (output.getAbstract() != null)
AnalysisLogger.getLogger().debug("WPSClient->Abstract:" + output.getAbstract().getStringValue());
AnalysisLogger.getLogger().debug("WPSClient->Name:" + output.getTitle().getStringValue());
StatisticalType stype = WPS2SM.convert2SMType(output);
currentOutputStatisticalTypes.put(output.getIdentifier().getStringValue(), stype);
AnalysisLogger.getLogger().debug("WPSClient->Converted Into a Statistical Type: " + stype);
}
currentInputs = inputList;
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
wpsClient.disconnect(wpsServiceURL);
}
}
public void requestGetCapabilities() throws Exception {
WPSClientSession wpsClient = WPSClientSession.getInstance();
wpsClient.connect(wpsServiceURL);
try {
CapabilitiesDocument capabilities = wpsClient.getWPSCaps(wpsServiceURL);
ProcessBriefType[] processList = capabilities.getCapabilities().getProcessOfferings().getProcessArray();
for (ProcessBriefType process : processList) {
AnalysisLogger.getLogger().debug("WPSClient->Process id:" + process.getIdentifier().getStringValue());
AnalysisLogger.getLogger().debug("WPSClient->title:" + process.getTitle().getStringValue());
AnalysisLogger.getLogger().debug("WPSClient->abstract:" + process.getAbstract());
}
this.setProcessesList(processList);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
wpsClient.disconnect(wpsServiceURL);
}
}
public ProcessBriefType[] getProcessesList() {
return processesList;
}
public void setProcessesList(ProcessBriefType[] processesList) {
this.processesList = processesList;
}
public ProcessDescriptionType getProcessDescription() {
return currentProcessDescription;
}
public void setProcessDescription(ProcessDescriptionType processDescription) {
this.currentProcessDescription = processDescription;
}
public ProcessOutputs executeProcess(ExecuteRequestBuilder executeBuilder, ProcessDescriptionType processDescription) throws Exception {
try {
OutputDescriptionType[] odts = processDescription.getProcessOutputs().getOutputArray();
for (OutputDescriptionType odt : odts) {
// executeBuilder.setMimeTypeForOutput("text/xml", "result");
if (odt.isSetComplexOutput())
executeBuilder.setMimeTypeForOutput("text/xml", odt.getIdentifier().getStringValue());
}
} catch (Exception e) {
e.printStackTrace();
AnalysisLogger.getLogger().debug("Execute Process-> Warning, no xml structured objects will be provided");
}
// executeBuilder.setSchemaForOutput("http://schemas.opengis.net/gml/3.1.1/base/feature.xsd", "result");
ExecuteDocument execute = executeBuilder.getExecute();
execute.getExecute().setService("WPS");
WPSClientSession wpsClient = WPSClientSession.getInstance();
try {
wpsClient.connect(wpsServiceURL);
AnalysisLogger.getLogger().debug("Sending:\n" + execute);
Object responseObject = wpsClient.execute(wpsServiceURL, execute);
AnalysisLogger.getLogger().debug("Response:\n" + responseObject);
if (responseObject instanceof ExecuteResponseDocument) {
ExecuteResponseDocument response = (ExecuteResponseDocument) responseObject;
return response.getExecuteResponse().getProcessOutputs();
} else
throw new Exception("" + responseObject);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
wpsClient.disconnect(wpsServiceURL);
}
}
public static void main(String[] args) throws Exception {
AnalysisLogger.setLogger("./cfg/ALog.properties");
WPSClient client = new WPSClient("http://wps01.i-marine.d4science.org/wps/WebProcessingService");
// WPSClient client = new WPSClient("http://geoprocessing.demo.52north.org:8080/wps/WebProcessingService");
client.requestGetCapabilities();
// client.describeProcess("com.terradue.wps_hadoop.processes.examples.async.Async", new URL("file:///C:/Users/coro/Desktop/WorkFolder/Workspace/EcologicalEngineWPSExtension/cfg/test.xml"));
// client.describeProcess("org.n52.wps.extension.GetFuelPriceProcess");
// client.describeProcess("org.n52.wps.server.algorithm.test.DummyTestClass");
// client.describeProcess("org.n52.wps.server.algorithm.coordinatetransform.CoordinateTransformAlgorithm");
// client.describeProcess("org.n52.wps.extension.GetFuelPriceProcess");
client.describeProcess("com.terradue.wps_hadoop.processes.examples.async.Async");
}
public static int calculateBBDimensions(String bbstring) {
String[] bbinput = bbstring.split(",");
int dimcounter = 0;
try {
for (int i = 0; i < bbinput.length; i++) {
Double.parseDouble(bbinput[i]);
dimcounter++;
}
} catch (Exception e) {
AnalysisLogger.getLogger().debug("Dimensions Count: " + dimcounter);
}
return dimcounter;
}
public static void addBoundingBoxInput(org.n52.wps.client.ExecuteRequestBuilder executeBuilder, String identifier, String BBstring) {
ExecuteDocument executor = executeBuilder.getExecute();
InputType input1 = executor.getExecute().getDataInputs().addNewInput();
input1.addNewIdentifier().setStringValue(identifier);
net.opengis.ows.x11.BoundingBoxType bbtype = input1.addNewData().addNewBoundingBoxData();
// bboxInput=46,102,47,103,urn:ogc:def:crs:EPSG:6.6:4326,2
String[] bbinput = BBstring.split(",");
int dimensions = calculateBBDimensions(BBstring);
List lc = new ArrayList<String>();
for (int i = 0; i < dimensions / 2; i++) {
lc.add(bbinput[i]);
}
List uc = new ArrayList<String>();
for (int i = dimensions / 2; i < dimensions; i++) {
uc.add(bbinput[i]);
}
bbtype.setLowerCorner(lc);
bbtype.setUpperCorner(uc);
int crsidx = bbinput[dimensions].indexOf("crs:");
String crs = bbinput[dimensions];
/*
* if (crsidx>=0) crs = bbinput[dimensions].substring(crsidx+4);
*/
bbtype.setCrs(crs);
bbtype.setDimensions(new BigInteger("" + dimensions / 2));
}
public static List<String> retrieveURLsFromWPSResponse(ComplexDataType cdt) {
org.w3c.dom.Node node = cdt.getDomNode();
List<String> urls = getURLFromXML(node);
return urls;
}
private static List<String> getURLFromXML(org.w3c.dom.Node node) {
List<String> urls = new ArrayList<String>();
if (node == null)
return urls;
NodeList listnodes = node.getChildNodes();
int nChildren = listnodes.getLength();
if (nChildren == 0) {
String text = node.getNodeValue();
if (text.startsWith("https:")||text.startsWith("http:") || text.startsWith("ftp:") || text.startsWith("smp:")|| text.startsWith("file:"))
urls.add(text.trim());
} else {
for (int i = 0; i < nChildren; i++) {
List<String> childrenurls = getURLFromXML(listnodes.item(i));
urls.addAll(childrenurls);
}
}
return urls;
}
}

View File

@ -0,0 +1,53 @@
package org.gcube.dataanalysis.geo.wps.factory;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.opengis.wps.x100.ProcessBriefType;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.ecoengine.interfaces.DynamicTransducer;
import org.gcube.dataanalysis.ecoengine.interfaces.Transducerer;
import org.gcube.dataanalysis.geo.wps.client.WPSClient;
import org.gcube.dataanalysis.geo.wps.interfaces.WPSProcess;
public class DynamicWPSTransducerer implements DynamicTransducer{
public Map<String, Transducerer> getTransducers(AlgorithmConfiguration config) {
Map<String, Transducerer> transducerers = new LinkedHashMap<String,Transducerer>();
//get the list of endpoints from the IS
List<String> wpsendpoints = getWPSendpoints(config);
try {
for (String wpsendpoint : wpsendpoints) {
WPSClient client = new WPSClient(wpsendpoint);
client.requestGetCapabilities();
//get the list of available processes for this
ProcessBriefType[] wpsProcesses = client.getProcessesList();
for (ProcessBriefType processInfo : wpsProcesses) {
//prepare a generic wps process according to these
WPSProcess process = new WPSProcess(wpsendpoint, processInfo.getIdentifier().getStringValue());
process.setConfiguration(config);
transducerers.put(processInfo.getIdentifier().getStringValue(),process);
}
}
} catch (Exception e) {
e.printStackTrace();
AnalysisLogger.getLogger().debug("Error in retrieving information by WPS Server: "+e.getLocalizedMessage());
}
return transducerers;
}
//gets the list of endpoints from the IS
public static List<String> getWPSendpoints(AlgorithmConfiguration config) {
List<String> wps = new ArrayList<String>();
// wps.add("http://wps01.i-marine.d4science.org/wps/WebProcessingService");
wps = org.gcube.dataanalysis.executor.util.IfraRetrieval.retrieveAddresses("WPS", config.getGcubeScope(),"StatisticalManager");
return wps;
}
}

View File

@ -0,0 +1,196 @@
package org.gcube.dataanalysis.geo.wps.interfaces;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import javax.xml.namespace.QName;
import net.opengis.wps.x100.ComplexDataType;
import net.opengis.wps.x100.ExecuteResponseDocument.ExecuteResponse.ProcessOutputs;
import net.opengis.wps.x100.InputDescriptionType;
import net.opengis.wps.x100.OutputDataType;
import net.opengis.wps.x100.OutputDescriptionType;
import net.opengis.wps.x100.ProcessDescriptionType;
import net.opengis.wps.x100.SupportedComplexDataInputType;
import org.apache.xmlbeans.XmlObject;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.ecoengine.configuration.INFRASTRUCTURE;
import org.gcube.dataanalysis.ecoengine.datatypes.PrimitiveType;
import org.gcube.dataanalysis.ecoengine.datatypes.PrimitiveTypesList;
import org.gcube.dataanalysis.ecoengine.datatypes.StatisticalType;
import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.PrimitiveTypes;
import org.gcube.dataanalysis.ecoengine.interfaces.Transducerer;
import org.gcube.dataanalysis.ecoengine.utils.ResourceFactory;
import org.gcube.dataanalysis.geo.wps.client.WPSClient;
public class WPSProcess implements Transducerer {
public String wpsurl;
public String processid;
public String title;
public String processAbstract;
private List<StatisticalType> inputTypes;
private Hashtable<String, StatisticalType> outputTypes;
private InputDescriptionType[] wpsInputs;
private OutputDescriptionType[] wpsOutputs;
private ProcessDescriptionType processDescription;
protected ResourceFactory resourceManager;
private AlgorithmConfiguration config;
float status = 0;
public WPSProcess(String wpsurl, String processid) {
this.wpsurl = wpsurl;
this.processid = processid;
}
public void compute() throws Exception {
status = 0;
try {
// setup the inputs
org.n52.wps.client.ExecuteRequestBuilder executeBuilder = new org.n52.wps.client.ExecuteRequestBuilder(processDescription);
// for each input
for (InputDescriptionType input : wpsInputs) {
// retrieve the input from the sm config
String value = config.getParam(input.getIdentifier().getStringValue());
if (value != null && value.trim().length()>0) {
String [] values = value.split(AlgorithmConfiguration.getListSeparator());
if (values.length==0){
values = new String[1];
values[0] = value;
}
// fulfill an input obj for the execution
if (input.isSetLiteralData()) {
AnalysisLogger.getLogger().debug("Configuring Literal: " + input.getIdentifier().getStringValue() + " to: " + value);
for (String v:values){
executeBuilder.addLiteralData(input.getIdentifier().getStringValue(), v);
}
} else if (input.isSetBoundingBoxData()) {
AnalysisLogger.getLogger().debug("Configuring Bounding Box: " + input.getIdentifier().getStringValue() + " to: " + value);
AnalysisLogger.getLogger().debug(input);
for (String v:values){
WPSClient.addBoundingBoxInput(executeBuilder, input.getIdentifier().getStringValue(), v);
}
} else {
AnalysisLogger.getLogger().debug("Configuring Complex: " + input.getIdentifier().getStringValue() + " to: " + value);
SupportedComplexDataInputType complex = input.getComplexData();
for (String v:values){
executeBuilder.addComplexDataReference(input.getIdentifier().getStringValue(), v, complex.getDefault().getFormat().getSchema(), complex.getDefault().getFormat().getEncoding(), complex.getDefault().getFormat().getMimeType());
}
}
}
}
// Submit the execution
WPSClient client = new WPSClient(wpsurl);
AnalysisLogger.getLogger().debug("Starting Process");
ProcessOutputs outs = client.executeProcess(executeBuilder, processDescription);
// retrieve the output objs
if (outs == null)
throw new Exception("Error during the execution of the WPS process: returned an empty document");
else {
OutputDataType[] outputData = outs.getOutputArray();
for (OutputDataType out : outputData) {
String outputID = out.getIdentifier().getStringValue();
String value = "";
if (out.getData().isSetLiteralData()) {
value = out.getData().getLiteralData().getStringValue();
StatisticalType stype = outputTypes.get(outputID);
if (stype != null){
((PrimitiveType) stype).setContent(value);
AnalysisLogger.getLogger().debug("Assigning value: " + value + " to output named: " + outputID);
}
} else if (out.getData().isSetComplexData()) {
if (out.getReference() != null) {
value = out.getReference().getHref();
StatisticalType stype = outputTypes.get(outputID);
if (stype != null){
((PrimitiveType) stype).setContent(value);
AnalysisLogger.getLogger().debug("Assigning value: " + value + " to output named: " + outputID);
}
}
ComplexDataType cdt = out.getData().getComplexData();
List<String> urls = WPSClient.retrieveURLsFromWPSResponse(cdt);
int counter = 1;
for (String url : urls) {
AnalysisLogger.getLogger().debug("Adding URL:" + url);
outputTypes.put("URL_" + counter, new PrimitiveType(String.class.getName(), url, PrimitiveTypes.STRING, "URL", "", ""));
counter++;
}
} else {
value = out.getData().getLiteralData().getStringValue();
}
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
status = 100;
}
}
public void init() throws Exception {
// here we build the WPS process by means of the client
WPSClient wpsclient = new WPSClient(wpsurl);
wpsclient.describeProcess(processid);
inputTypes = wpsclient.getCurrentInputStatisticalTypes();
outputTypes = wpsclient.getCurrentOutputStatisticalTypes();
wpsInputs = wpsclient.getCurrentInputs();
wpsOutputs = wpsclient.getCurrentOutputs();
title = wpsclient.getCurrentProcessTitle();
processAbstract = wpsclient.getCurrentProcessAbstract();
processDescription = wpsclient.getProcessDescription();
}
public String getDescription() {
return processAbstract;
}
public List<StatisticalType> getInputParameters() {
return inputTypes;
}
public INFRASTRUCTURE getInfrastructure() {
return INFRASTRUCTURE.LOCAL;
}
public StatisticalType getOutput() {
// start from the declared outputs and fulfill the objects
PrimitiveType output = new PrimitiveType(HashMap.class.getName(), outputTypes, PrimitiveTypes.MAP, "Results", "Results");
return output;
}
public String getResourceLoad() {
if (resourceManager == null)
resourceManager = new ResourceFactory();
return resourceManager.getResourceLoad(1);
}
public String getResources() {
return ResourceFactory.getResources(100f);
}
public float getStatus() {
return status;
}
public void setConfiguration(AlgorithmConfiguration config) {
this.config = config;
}
public void shutdown() {
}
}

View File

@ -0,0 +1,5 @@
package org.gcube.dataanalysis.geo.wps.mappings;
public class SM2WPS {
}

View File

@ -0,0 +1,201 @@
package org.gcube.dataanalysis.geo.wps.mappings;
import net.opengis.ows.x11.DomainMetadataType;
import net.opengis.wps.x100.ComplexDataDescriptionType;
import net.opengis.wps.x100.InputDescriptionType;
import net.opengis.wps.x100.LiteralInputType;
import net.opengis.wps.x100.LiteralOutputType;
import net.opengis.wps.x100.OutputDescriptionType;
import net.opengis.wps.x100.SupportedComplexDataInputType;
import net.opengis.wps.x100.SupportedComplexDataType;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.datatypes.PrimitiveType;
import org.gcube.dataanalysis.ecoengine.datatypes.PrimitiveTypesList;
import org.gcube.dataanalysis.ecoengine.datatypes.StatisticalType;
import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.PrimitiveTypes;
public class WPS2SM {
// name: abstract, max megabytes, uom, min elements, max elements, default value
public static StatisticalType manageBoundingBoxInformation(String Abstract, int minOcc, int maxOcc, int rangeOccs, String title, String crs) {
StatisticalType converted = null;
Abstract = "Bounding Box Input in OGC 06-121r3 spec. E.g. 102,46,103,47,urn:ogc:def:crs:EPSG:4328 "+ Abstract;
if (crs!=null && crs.length()>0)
Abstract+=" Supported CRS "+crs;
Abstract = buildParameterDescription(Abstract, null, null, minOcc, maxOcc, null);
if ((maxOcc == 1)||(maxOcc<0)||(maxOcc == 0))
converted = new PrimitiveType(String.class.getName(), null, PrimitiveTypes.STRING, title, Abstract, "");
else
converted = new PrimitiveTypesList(String.class.getName(), PrimitiveTypes.STRING, title, Abstract, true);
return converted;
}
public static StatisticalType manageLiteral(String Abstract, int minOcc, int maxOcc, int rangeOccs, String defaultValue, String title, String uoms, DomainMetadataType type) {
StatisticalType converted = null;
AnalysisLogger.getLogger().debug("WPS type:" + type.getStringValue());
String guessedType = guessWPSLiteralType(type);
AnalysisLogger.getLogger().debug("Guessed type: " + guessedType);
// rebuild Abstract
Abstract = buildParameterDescription(Abstract, null, uoms, minOcc, maxOcc, defaultValue);
if ((maxOcc == 1)||(maxOcc<0)||(maxOcc == 0))
converted = new PrimitiveType(guessedType, null, PrimitiveTypes.STRING, title, Abstract, defaultValue);
else
converted = new PrimitiveTypesList(guessedType, PrimitiveTypes.STRING, title, Abstract, true);
return converted;
}
public static StatisticalType manageComplexData(String maxMegaBytes, String Abstract, int minOcc, int maxOcc, int rangeOccs, String title, ComplexDataDescriptionType type) {
StatisticalType converted = null;
String mimeType = null;
String schema = null;
String encoding = null;
mimeType = type.getMimeType();
schema = type.getSchema();
encoding = type.getEncoding();
AnalysisLogger.getLogger().debug("MimeType: " + mimeType);
AnalysisLogger.getLogger().debug("Schema: " + schema);
AnalysisLogger.getLogger().debug("Encoding: " + encoding);
// rebuild Abstract
Abstract = buildParameterDescription(Abstract, maxMegaBytes, null, minOcc, maxOcc, null);
if ((maxOcc == 1)||(maxOcc<0)||(maxOcc == 0))
converted = new PrimitiveType(String.class.getName(), null, PrimitiveTypes.STRING, title, Abstract);
else
converted = new PrimitiveTypesList(String.class.getName(), PrimitiveTypes.STRING, title, Abstract, true);
return converted;
}
public static StatisticalType convert2SMType(InputDescriptionType wpsType) {
String id = wpsType.getIdentifier().getStringValue();
String Abstract = wpsType.getAbstract()!=null?wpsType.getAbstract().getStringValue():"";
int minOcc = wpsType.getMinOccurs().intValue();
int maxOcc = wpsType.getMaxOccurs().intValue();
int rangeOccs = maxOcc - minOcc;
if (rangeOccs == 0)
rangeOccs = 1;
// default
StatisticalType converted = new PrimitiveType(String.class.getName(), null, PrimitiveTypes.STRING, id, Abstract);
if (rangeOccs > 1)
converted = new PrimitiveTypesList(String.class.getName(), PrimitiveTypes.STRING, id, Abstract, true);
// Bounding Boxes
if (wpsType.isSetBoundingBoxData()){
AnalysisLogger.getLogger().debug("Conversion to SM Type->" + id+" is a Bounding Box Input");
converted = manageBoundingBoxInformation(Abstract, minOcc, maxOcc, rangeOccs, id, wpsType.getBoundingBoxData().getDefault().getCRS());
}
// Literals
else if (wpsType.isSetLiteralData()) {
AnalysisLogger.getLogger().debug("Conversion to SM Type->" + id+" is a Literal Input");
LiteralInputType literal = wpsType.getLiteralData();
String uoms = literal.getUOMs() == null ? "" : literal.getUOMs().getDefault().getUOM().getStringValue();
String defaultValue = literal.getDefaultValue();
converted = manageLiteral(Abstract, minOcc, maxOcc, rangeOccs, defaultValue, id, uoms, literal.getDataType());
} else if (wpsType.isSetComplexData()) {
AnalysisLogger.getLogger().debug("Conversion to SM Type->" + id+" is a Complex Input");
SupportedComplexDataInputType complex = wpsType.getComplexData();
String maxMegaBytes = complex.getMaximumMegabytes()!=null?complex.getMaximumMegabytes().toString():"1";
AnalysisLogger.getLogger().debug("Max Megabytes: " + maxMegaBytes);
converted = manageComplexData(maxMegaBytes, Abstract, minOcc, maxOcc, rangeOccs, id, complex.getDefault().getFormat());
}
AnalysisLogger.getLogger().debug("Conversion to SM Type->Abstract:" + Abstract);
AnalysisLogger.getLogger().debug("Conversion to SM Type->Name:" + id);
AnalysisLogger.getLogger().debug("Conversion to SM Type->Number of Inputs to Manage:" + rangeOccs);
return converted;
}
public static StatisticalType convert2SMType(OutputDescriptionType wpsType) {
String id = wpsType.getIdentifier().getStringValue();
String Abstract = wpsType.getAbstract()!=null?wpsType.getAbstract().getStringValue():"";
// default
StatisticalType converted = new PrimitiveType(String.class.getName(), null, PrimitiveTypes.STRING, id, Abstract);
AnalysisLogger.getLogger().debug("Conversion to SM Type->Output id:" + id);
AnalysisLogger.getLogger().debug("Conversion to SM Type->Abstract:" + Abstract);
// Bounding Boxes
if (wpsType.isSetBoundingBoxOutput()){
AnalysisLogger.getLogger().debug("Bounding Box Output");
converted = manageBoundingBoxInformation(Abstract, -1, -1, -1, id,"");
}
// Literals
else if (wpsType.isSetLiteralOutput()) {
AnalysisLogger.getLogger().debug("Literal Output");
LiteralOutputType literal = wpsType.getLiteralOutput();
String uoms = literal.getUOMs() == null ? "" : literal.getUOMs().toString();
converted = manageLiteral(Abstract, -1, -1, -1, "", id, uoms, literal.getDataType());
} else if (wpsType.isSetComplexOutput()) {
AnalysisLogger.getLogger().debug("Complex Output");
SupportedComplexDataType complex = wpsType.getComplexOutput();
converted = manageComplexData("", Abstract, -1, -1, -1, id, complex.getDefault().getFormat());
}
return converted;
}
// name: abstract, max megabytes, uom, min elements, max elements, default value
public static String buildParameterDescription(String Abstract, String maxMegabytes, String UoM, int minElements, int maxElements, String defaultValue) {
String description = Abstract;
String innerDescription = "";
if (maxMegabytes != null && maxMegabytes.trim().length() > 0) {
innerDescription += "Max MB Size:" + maxMegabytes.trim() + "; ";
}
if (UoM != null && UoM.trim().length() > 0) {
innerDescription += "Unit of Measure:" + UoM.trim() + "; ";
}
if (minElements>0) {
innerDescription += "Min N. of Entries:" + minElements+ "; ";
}
if (maxElements >0) {
innerDescription += "Max N. of Entries:" + maxElements+ "; ";
}
if (defaultValue != null && defaultValue.trim().length() > 0) {
innerDescription += "default:" + defaultValue.trim() + "; ";
}
if (innerDescription.length()>0)
description += " [" + innerDescription.substring(0,innerDescription.lastIndexOf(";")).trim() + "]";
return description;
}
public static String guessWPSLiteralType(DomainMetadataType type) {
if (type == null || type.getStringValue() == null)
return String.class.getName();
else {
String typeS = type.getReference().trim();
if (typeS.length() == 0)
return String.class.getName();
else if (typeS.contains("float") || typeS.contains("double") || typeS.contains("decimal"))
return Double.class.getName();
else if (typeS.contains("int"))
return Integer.class.getName();
else if (typeS.contains("long"))
return Long.class.getName();
else if (typeS.contains("short"))
return Short.class.getName();
}
return String.class.getName();
}
}

View File

@ -0,0 +1,103 @@
package org.gcube.dataanalysis.geo.wps.test.invoke;
import java.util.List;
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.ecoengine.evaluation.bioclimate.InterpolateTables.INTERPOLATIONFUNCTIONS;
import org.gcube.dataanalysis.ecoengine.interfaces.ComputationalAgent;
import org.gcube.dataanalysis.ecoengine.processing.factories.TransducerersFactory;
import org.gcube.dataanalysis.ecoengine.test.regression.Regressor;
public class TestTransducerer {
public static void main(String[] args) throws Exception {
System.out.println("TEST 1");
List<ComputationalAgent> trans = null;
trans = TransducerersFactory.getTransducerers(testConfigLocal());
trans.get(0).init();
Regressor.process(trans.get(0));
trans = null;
}
private static AlgorithmConfiguration testConfigLocal() {
AlgorithmConfiguration config = Regressor.getConfig();
config.setParam("DatabaseUserName", "utente");
config.setParam("DatabasePassword", "d4science");
config.setParam("DatabaseURL", "jdbc:postgresql://statistical-manager.d.d4science.research-infrastructures.eu/testdb");
config.setAgent("OCCURRENCES_DUPLICATES_DELETER");
config.setParam("longitudeColumn", "decimallongitude");
config.setParam("latitudeColumn", "decimallatitude");
config.setParam("recordedByColumn", "recordedby");
config.setParam("scientificNameColumn", "scientificname");
config.setParam("eventDateColumn", "eventdate");
config.setParam("lastModificationColumn", "modified");
config.setParam("OccurrencePointsTableName", "whitesharkoccurrences2");
config.setParam("finalTableName", "whitesharkoccurrencesnoduplicates");
config.setParam("spatialTolerance", "0.5");
config.setParam("confidence", "80");
return config;
}
private static AlgorithmConfiguration testConfigWPS() {
AlgorithmConfiguration config = Regressor.getConfig();
config.setParam("DatabaseUserName", "utente");
config.setParam("DatabasePassword", "d4science");
config.setParam("DatabaseURL", "jdbc:postgresql://statistical-manager.d.d4science.research-infrastructures.eu/testdb");
config.setGcubeScope("/gcube");
config.setAgent("com.terradue.wps_hadoop.processes.examples.async.Async");
config.setParam("secondsDelay", "1");
return config;
}
private static AlgorithmConfiguration testSpread() {
// dataInputs=geoColumn=field0;quantityColumn=field4;sourceAreaLayerName=FAO_AREAS;targetAreaLayerName=EEZ_HIGHSEAS;dataUrls=https://dl.dropboxusercontent.com/u/24368142/timeseries_100.json;&ResponseDocument=result
AlgorithmConfiguration config = Regressor.getConfig();
config.setGcubeScope("/gcube");
config.setAgent("com.terradue.wps_hadoop.processes.fao.spread.Spread");
config.setParam("geoColumn", "field0");
config.setParam("quantityColumn", "field4");
config.setParam("sourceAreaLayerName", "FAO_AREAS");
config.setParam("targetAreaLayerName", "EEZ_HIGHSEAS");
config.setParam("dataUrls", "https://dl.dropboxusercontent.com/u/24368142/timeseries_100.json");
return config;
}
private static AlgorithmConfiguration testTunaAtlas1() {
/*
"YFT,Thunnus albacares,Albacore,Rabil,Yellowfin tuna",
"SKJ,Katsuwonus pelamis,Listao,Listado,Ocean skipjack",
"BET,Thunnus obesus,Thon obese,Patudo,Bigeye tuna",
"ALB,Thunnus alalunga,Germon,Atun blanco,Albacore",
"BFT,Thunnus thynnus thynnus,Thon rouge,Atun rojo,Bluefin tuna",
"SBF,Thunnus maccoyii,Thon rouge du sud,Atun rojo del sur,Southern bluefin tuna",
"SFA,Istiophorus platypterus,Voilier Indo-Pacifique,Pez vela del Indo-Pacifico,Indo-Pacific sailfish",
"BLM,Makaira indica,Makaire noir,Aguja negra,Black marlin",
"BUM,Makaira nigricans,Makaire bleu Atlantique,Aguja azul,Atlantic blue marlin",
"MLS,Tetrapturus audax,Marlin raye,Marlin rayado,Striped marlin",
"BIL,Istiophoridae spp.,Poissons a rostre non classes,,Unclassified marlin",
"SWO,Xiphias gladius,Espadon,Pez espada,Broadbill swordfish",
"SSP,Tetrapturus angustirostris,Makaire a rostre court,Marlin trompa corta,short-billed spearfish",
*/
AlgorithmConfiguration config = Regressor.getConfig();
config.setGcubeScope("/gcube");
config.setAgent("com.terradue.wps_hadoop.processes.ird.indicator.IndicatorI1");
config.setParam("species", "YFT");
// http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/tuna_atlas?service=wfs&request=getcapabilities
return config;
}
}

View File

@ -0,0 +1,101 @@
package org.gcube.dataanalysis.geo.wps.test.processes;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.ecoengine.datatypes.StatisticalType;
import org.gcube.dataanalysis.ecoengine.interfaces.ComputationalAgent;
import org.gcube.dataanalysis.ecoengine.test.regression.Regressor;
import org.gcube.dataanalysis.geo.wps.interfaces.WPSProcess;
public class TestWPSProcess {
static String[] algorithms = { "com.terradue.wps_hadoop.processes.examples.async.Async", "com.terradue.wps_hadoop.processes.ird.kernel_density.KernelDensity", "com.terradue.wps_hadoop.processes.terradue.envi_enrich.EnviEnrich", "com.terradue.wps_hadoop.processes.fao.intersection.Intersection", "com.terradue.wps_hadoop.processes.fao.spread.Spread" };
static String wps = "http://wps01.i-marine.d4science.org/wps/WebProcessingService";
static AlgorithmConfiguration[] configs = { testAsynch(), testKernelDensity(), testEnvironmentalEnrichment(), testIntersection(), testSpread() };
public static void main(String[] args) throws Exception {
System.out.println("TEST 1");
for (int i = 0; i < algorithms.length; i++) {
AnalysisLogger.getLogger().debug("Executing:" + algorithms[i]);
ComputationalAgent trans = new WPSProcess(wps, algorithms[i]);
trans.setConfiguration(configs[i]);
trans.init();
Regressor.process(trans);
StatisticalType st = trans.getOutput();
AnalysisLogger.getLogger().debug("ST:" + st);
trans = null;
}
}
private static AlgorithmConfiguration testAsynch() {
AlgorithmConfiguration config = Regressor.getConfig();
config.setParam("secondsDelay", "1");
return config;
}
private static AlgorithmConfiguration testKernelDensity() {
// com.terradue.wps_hadoop.processes.ird.kernel_density.KernelDensity
AlgorithmConfiguration config = Regressor.getConfig();
config.setParam("species", "Carcharodon carcharias");
return config;
}
private static AlgorithmConfiguration testEnvironmentalEnrichment() {
// com.terradue.wps_hadoop.processes.terradue.envi_enrich.EnviEnrich
AlgorithmConfiguration config = Regressor.getConfig();
config.setParam("species", "Carcharodon carcharias");
config.setParam("envVars", "salinity" + AlgorithmConfiguration.listSeparator + "sst");
return config;
}
private static AlgorithmConfiguration testIntersection() {
// com.terradue.wps_hadoop.processes.ird.kernel_density.KernelDensity
AlgorithmConfiguration config = Regressor.getConfig();
config.setParam("masterWfsUrl", "http://www.fao.org/figis/geoserver/species/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=species:SPECIES_DIST_OCC");
config.setParam("slaveWfsUrls", "http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/longhurst?service=WFS&version=1.1.0&request=GetFeature&typeName=Longhurst_world_v4_2010:Longhurst_world_v4_2010");
config.setParam("outputFormat", "GML");
return config;
}
private static AlgorithmConfiguration testSpread() {
// dataInputs=geoColumn=field0;quantityColumn=field4;sourceAreaLayerName=FAO_AREAS;targetAreaLayerName=EEZ_HIGHSEAS;dataUrls=https://dl.dropboxusercontent.com/u/24368142/timeseries_100.json;&ResponseDocument=result
AlgorithmConfiguration config = Regressor.getConfig();
config.setParam("geoColumn", "field0");
config.setParam("quantityColumn", "field4");
config.setParam("sourceAreaLayerName", "FAO_AREAS");
config.setParam("targetAreaLayerName", "EEZ_HIGHSEAS");
config.setParam("dataUrls", "https://dl.dropboxusercontent.com/u/24368142/timeseries_100.json");
return config;
}
private static AlgorithmConfiguration testTuna1() {
// dataInputs=geoColumn=field0;quantityColumn=field4;sourceAreaLayerName=FAO_AREAS;targetAreaLayerName=EEZ_HIGHSEAS;dataUrls=https://dl.dropboxusercontent.com/u/24368142/timeseries_100.json;&ResponseDocument=result
AlgorithmConfiguration config = Regressor.getConfig();
config.setParam("species", "Thunnus albacares");
config.setParam("wfsUrl", "http://www.fao.org/figis/geoserver/species/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=species:SPECIES_DIST_OCC");
return config;
}
private static AlgorithmConfiguration testTuna2() {
// dataInputs=geoColumn=field0;quantityColumn=field4;sourceAreaLayerName=FAO_AREAS;targetAreaLayerName=EEZ_HIGHSEAS;dataUrls=https://dl.dropboxusercontent.com/u/24368142/timeseries_100.json;&ResponseDocument=result
AlgorithmConfiguration config = Regressor.getConfig();
config.setParam("species", "Thunnus albacares");
config.setParam("wfsUrl", "http://www.fao.org/figis/geoserver/species/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=species:SPECIES_DIST_OCC");
return config;
}
}

View File

@ -0,0 +1,40 @@
package org.gcube.dataanalysis.geo.wps.test.regression;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.ecoengine.datatypes.StatisticalType;
import org.gcube.dataanalysis.ecoengine.interfaces.ComputationalAgent;
import org.gcube.dataanalysis.ecoengine.test.regression.Regressor;
import org.gcube.dataanalysis.geo.wps.interfaces.WPSProcess;
public class RegressionTerradueWPSProcess {
public static void main(String[] args) throws Exception {
System.out.println("TEST 1");
ComputationalAgent trans = new WPSProcess("http://wps01.i-marine.d4science.org/wps/WebProcessingService","com.terradue.wps_hadoop.processes.examples.async.Async");
trans.setConfiguration(testConfig());
trans.init();
Regressor.process(trans);
StatisticalType st = trans.getOutput();
AnalysisLogger.getLogger().debug("ST:"+st);
trans = null;
}
private static AlgorithmConfiguration testConfig() {
AlgorithmConfiguration config = Regressor.getConfig();
config.setParam("secondsDelay", "1");
return config;
}
}

View File

@ -0,0 +1,32 @@
package org.gcube.dataanalysis.geo.wps.test.regression;
import java.util.List;
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.ecoengine.datatypes.StatisticalType;
import org.gcube.dataanalysis.ecoengine.interfaces.ComputationalAgent;
import org.gcube.dataanalysis.ecoengine.processing.factories.TransducerersFactory;
import org.gcube.dataanalysis.ecoengine.test.regression.Regressor;
import org.gcube.dataanalysis.geo.wps.interfaces.WPSProcess;
public class RegressionTestWPSProcess {
public static void main(String[] args) throws Exception {
System.out.println("TEST 1");
ComputationalAgent trans = new WPSProcess("http://geoprocessing.demo.52north.org:8080/wps/WebProcessingService","org.n52.wps.extension.GetFuelPriceProcess");
trans.setConfiguration(testConfig());
trans.init();
Regressor.process(trans);
StatisticalType st = trans.getOutput();
trans = null;
}
private static AlgorithmConfiguration testConfig() {
AlgorithmConfiguration config = Regressor.getConfig();
config.setParam("fuelType", "gasoline");
return config;
}
}