You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2016/08/12 13:13:28 UTC
[40/46] incubator-taverna-plugin-gis git commit: Implement gis client
Execute method
Implement gis client Execute method
Improve client get Input/Output ports
Moved the code to create ports to PortDataDescriptorFactory
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/commit/24e3b9d0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/tree/24e3b9d0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/diff/24e3b9d0
Branch: refs/heads/taverna2
Commit: 24e3b9d066f636b4bae5e5e7a61aea7f88802797
Parents: 00f882b
Author: edikaradumi <ed...@gmail.com>
Authored: Sat Aug 6 00:12:35 2016 +0100
Committer: edikaradumi <ed...@gmail.com>
Committed: Sat Aug 6 00:12:35 2016 +0100
----------------------------------------------------------------------
.../ui/serviceprovider/GisServiceProvider.java | 35 +-
.../org/apache/taverna/gis/GisActivity.java | 203 ++++----
.../apache/taverna/gis/client/IGisClient.java | 8 +-
.../gis/client/impl/GisClientNorthImpl.java | 466 ++++++++-----------
4 files changed, 308 insertions(+), 404 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/24e3b9d0/apache-taverna-plugin-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceProvider.java
----------------------------------------------------------------------
diff --git a/apache-taverna-plugin-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceProvider.java b/apache-taverna-plugin-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceProvider.java
index 61e466e..0fff6d9 100644
--- a/apache-taverna-plugin-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceProvider.java
+++ b/apache-taverna-plugin-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceProvider.java
@@ -61,40 +61,15 @@ public class GisServiceProvider extends AbstractConfigurableServiceProvider<GisS
service.setDescription(processID);
// Get input ports
- List<PortTypeDescriptor> inputList = gisServiceClient.getTaverna2InputPorts(processID);
-
- List<ActivityInputPortDefinitionBean> inputPortDefinitions = new ArrayList<ActivityInputPortDefinitionBean>();
-
- for (PortTypeDescriptor input : inputList) {
- ActivityInputPortDefinitionBean newInputPort = new ActivityInputPortDefinitionBean();
- newInputPort.setName(input.getName());
- newInputPort.setDepth(input.getDepth());
- newInputPort.setAllowsLiteralValues(input.isAllowLiteralValues());
- newInputPort.setHandledReferenceSchemes(null);
- newInputPort.setTranslatedElementType(input.getTranslatedElementType());
-
- inputPortDefinitions.add(newInputPort);
-
- }
-
- service.setInputPortDefinitions(inputPortDefinitions);
+ List<IPortDataDescriptor> inputList = gisServiceClient.getTaverna2InputPorts(processID);
+
+ service.setInputPortDefinitions(inputList);
// Get output ports
- List<PortTypeDescriptor> outputList = gisServiceClient.getTaverna2OutputPorts(processID);
- List<ActivityOutputPortDefinitionBean> outputPortDefinitions = new ArrayList<ActivityOutputPortDefinitionBean>();
+ List<IPortDataDescriptor> outputList = gisServiceClient.getTaverna2OutputPorts(processID);
- for( PortTypeDescriptor output : outputList )
- {
- ActivityOutputPortDefinitionBean newOutputPort = new ActivityOutputPortDefinitionBean();
- newOutputPort.setName(output.getName());
- newOutputPort.setDepth(output.getDepth());
-
- outputPortDefinitions.add(newOutputPort);
-
- }
-
- service.setOutputPortDefinitions(outputPortDefinitions);
+ service.setOutputPortDefinitions(outputList);
results.add(service);
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/24e3b9d0/apache-taverna-plugin-gis-activity/src/main/java/org/apache/taverna/gis/GisActivity.java
----------------------------------------------------------------------
diff --git a/apache-taverna-plugin-gis-activity/src/main/java/org/apache/taverna/gis/GisActivity.java b/apache-taverna-plugin-gis-activity/src/main/java/org/apache/taverna/gis/GisActivity.java
index 1c468ce..6f58548 100644
--- a/apache-taverna-plugin-gis-activity/src/main/java/org/apache/taverna/gis/GisActivity.java
+++ b/apache-taverna-plugin-gis-activity/src/main/java/org/apache/taverna/gis/GisActivity.java
@@ -1,19 +1,15 @@
package org.apache.taverna.gis;
-import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-import org.n52.wps.client.ExecuteRequestBuilder;
-import org.n52.wps.client.ExecuteResponseAnalyser;
-import org.n52.wps.client.WPSClientException;
-import org.n52.wps.client.WPSClientSession;
+import org.apache.log4j.Logger;
+import org.apache.taverna.gis.client.ComplexDataFormat;
+import org.apache.taverna.gis.client.ComplexPortDataDescriptor;
+import org.apache.taverna.gis.client.GisClientFactory;
+import org.apache.taverna.gis.client.IGisClient;
+import org.apache.taverna.gis.client.IPortDataDescriptor;
-import net.opengis.wps.x100.DataType;
-import net.opengis.wps.x100.ExecuteDocument;
-import net.opengis.wps.x100.ExecuteResponseDocument;
-import net.opengis.wps.x100.OutputDataType;
-import net.opengis.wps.x100.ProcessDescriptionType;
import net.sf.taverna.t2.invocation.InvocationContext;
import net.sf.taverna.t2.reference.ReferenceService;
import net.sf.taverna.t2.reference.T2Reference;
@@ -21,14 +17,14 @@ import net.sf.taverna.t2.workflowmodel.processor.activity.AbstractAsynchronousAc
import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
import net.sf.taverna.t2.workflowmodel.processor.activity.AsynchronousActivity;
import net.sf.taverna.t2.workflowmodel.processor.activity.AsynchronousActivityCallback;
-import net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityInputPortDefinitionBean;
-import net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityOutputPortDefinitionBean;
public class GisActivity extends AbstractAsynchronousActivity<GisActivityConfigurationBean>
implements AsynchronousActivity<GisActivityConfigurationBean> {
private GisActivityConfigurationBean configBean;
+ private static Logger logger = Logger.getLogger(GisActivity.class);
+
@Override
public void configure(GisActivityConfigurationBean configBean) throws ActivityConfigurationException {
@@ -50,36 +46,28 @@ public class GisActivity extends AbstractAsynchronousActivity<GisActivityConfigu
removeOutputs();
// Add input ports
- for(ActivityInputPortDefinitionBean inputPort : configBean.getInputPortDefinitions())
+ for(IPortDataDescriptor inputPort : configBean.getInputPortDefinitions())
{
- if (inputPort.getName()=="polygon")
- {
- addInput("polygon_schema",0,true, null, null);
- addInput("polygon_encoding",0,true, null, null);
- addInput("polygon_mimetype",0,true, null, null);
-
- }
-
- if (inputPort.getName()=="line")
+ if (inputPort instanceof ComplexPortDataDescriptor)
{
- addInput("line_schema",0,true, null, null);
- addInput("line_encoding",0,true, null, null);
- addInput("line_mimetype",0,true, null, null);
+ addInput( inputPort.getName() + "_schema",0,true, null, null);
+ addInput(inputPort.getName() + "_encoding",0,true, null, null);
+ addInput(inputPort.getName() + "_mimetype",0,true, null, null);
}
- addInput(inputPort.getName(),inputPort.getDepth(),inputPort.getAllowsLiteralValues(),inputPort.getHandledReferenceSchemes(), inputPort.getTranslatedElementType());
+ addInput(inputPort.getName(),inputPort.getDepth(),inputPort.isAllowLiteralValues(),null, inputPort.getTranslatedElementType());
}
// Add output ports
- for(ActivityOutputPortDefinitionBean outputPort : configBean.getOutputPortDefinitions())
+ for(IPortDataDescriptor outputPort : configBean.getOutputPortDefinitions())
{
addOutput(outputPort.getName(),outputPort.getDepth());
- if (outputPort.getName()=="result")
+ if (outputPort instanceof ComplexPortDataDescriptor)
{
- addOutput("result_schema",0);
- addOutput("result_encoding",0);
- addOutput("result_mimetype",0);
+ addOutput(outputPort.getName() + "_schema",0);
+ addOutput(outputPort.getName() + "_encoding",0);
+ addOutput(outputPort.getName() + "_mimetype",0);
}
}
@@ -101,86 +89,111 @@ public class GisActivity extends AbstractAsynchronousActivity<GisActivityConfigu
try {
// prepare the execute object
- WPSClientSession wpsClient = WPSClientSession.getInstance();
+ IGisClient gisClient = GisClientFactory.getInstance().getGisClient(
+ configBean.getOgcServiceUri().toString());
- ProcessDescriptionType processDescription = wpsClient.getProcessDescription(configBean.getOgcServiceUri().toString(), configBean.getProcessIdentifier());
+ HashMap<String, IPortDataDescriptor> serviceInputs = new HashMap<String, IPortDataDescriptor>();
- ExecuteRequestBuilder executeBuilder = new ExecuteRequestBuilder(processDescription);
-
- for (ActivityInputPortDefinitionBean activityInputPort : configBean.getInputPortDefinitions()) {
- String portValue = (String) referenceService.renderIdentifier(inputs.get(activityInputPort.getName()), String.class, context);
-
- if (activityInputPort.getName().equals("polygon") || activityInputPort.getName().equals("line"))
+ for (IPortDataDescriptor activityInputPort : configBean.getInputPortDefinitions())
+ {
+ // Optional inputs are not stored in the map if no value is provided, hence they are skipped
+ if (inputs.containsKey(activityInputPort.getName()))
{
- String schema = "application/wkt";
- String encoding = null;
- String mimeType = "application/wkt";
+ Object inputValue = referenceService.renderIdentifier(inputs.get(activityInputPort.getName()), String.class, context);
+
+ activityInputPort.setValue(inputValue);
- executeBuilder.addComplexData(activityInputPort.getName(),
- portValue, schema, encoding, mimeType);
+ if (activityInputPort instanceof ComplexPortDataDescriptor)
+ {
+ //TODO: set format
+ ComplexDataFormat complexFormat = new ComplexDataFormat();
+
+ complexFormat.setEncoding(null);
+ complexFormat.setMimeType("application/wkt");
+ complexFormat.setSchema(null);
+
+ ((ComplexPortDataDescriptor) activityInputPort).setComplexFormat(complexFormat);
+ }
- }else
- {
- executeBuilder.addLiteralData(activityInputPort.getName(), portValue);
+ serviceInputs.put(activityInputPort.getName(), activityInputPort);
}
}
-
- ExecuteDocument execute = executeBuilder.getExecute();
-
- execute.getExecute().setService("WPS");
- Object responseObject = null;
+ // Execute process
+ HashMap<String, String> serviceOutput = gisClient.executeProcess(configBean.getProcessIdentifier().toString(), serviceInputs);
- try {
- // execute service
- responseObject = wpsClient.execute(configBean.getOgcServiceUri().toString(), execute);
- } catch (WPSClientException e) {
- // if the an error return from service
- callback.fail(e.getServerException().xmlText());
- }
-
- // Register outputs
outputs = new HashMap<String, T2Reference>();
T2Reference simpleRef = null;
- if (responseObject instanceof ExecuteResponseDocument) {
- ExecuteResponseDocument response = (ExecuteResponseDocument) responseObject;
-
- // analyser is used to get complex data
- ExecuteResponseAnalyser analyser = new ExecuteResponseAnalyser(
- execute, response, processDescription);
-
- for(OutputDataType output : response.getExecuteResponse().getProcessOutputs().getOutputArray())
- {
- DataType data = output.getData();
-
- if (data.isSetLiteralData())
- {
- simpleRef = referenceService.register(data.getLiteralData().getStringValue(), 0, true, context);
-
- outputs.put(output.getIdentifier().getStringValue(), simpleRef);
- }
- else
- {
-
- simpleRef = referenceService.register(data.getComplexData().toString(), 0, true, context);
-
- outputs.put(output.getIdentifier().getStringValue(), simpleRef);
-
- }
-
- }
-
- }
+ for (Map.Entry<String, String> entry : serviceOutput.entrySet()) {
+ String key = entry.getKey();
+ String value = entry.getValue();
+
+ simpleRef = referenceService.register(value, 0, true, context);
+ outputs.put(key, simpleRef);
+
+ }
+//
+//
+// Object responseObject = null;
+//
+// try {
+// // execute service
+// responseObject = wpsClient.execute(configBean.getOgcServiceUri().toString(), execute);
+// } catch (WPSClientException e) {
+// // if the an error return from service
+// callback.fail(e.getServerException().xmlText());
+// }
+//
+// // Register outputs
+// outputs = new HashMap<String, T2Reference>();
+// T2Reference simpleRef = null;
+//
+// if (responseObject instanceof ExecuteResponseDocument) {
+// ExecuteResponseDocument response = (ExecuteResponseDocument) responseObject;
+//
+// // analyser is used to get complex data
+// ExecuteResponseAnalyser analyser = new ExecuteResponseAnalyser(
+// execute, response, processDescription);
+//
+// for(OutputDataType output : response.getExecuteResponse().getProcessOutputs().getOutputArray())
+// {
+// DataType data = output.getData();
+//
+// if (data.isSetLiteralData())
+// {
+// simpleRef = referenceService.register(data.getLiteralData().getStringValue(), 0, true, context);
+//
+// outputs.put(output.getIdentifier().getStringValue(), simpleRef);
+// }
+// else
+// {
+//
+// simpleRef = referenceService.register(data.getComplexData().toString(), 0, true, context);
+//
+// outputs.put(output.getIdentifier().getStringValue(), simpleRef);
+//
+// }
+//
+// }
+//
+// }
+//
+//
+// } catch (WPSClientException e) {
+// callback.fail(e.getMessage());
+// } catch (IOException e) {
+// callback.fail(e.getMessage());
+// }
- } catch (WPSClientException e) {
- callback.fail(e.getMessage());
- } catch (IOException e) {
- callback.fail(e.getMessage());
+ } catch (Exception e) {
+ logger.error("Error executing service/process: "
+ + configBean.getOgcServiceUri().toString() + "/" + configBean.getProcessIdentifier().toString(), e);
+ callback.fail("Unable to execute service", e);
}
-
+
callback.receiveResult(outputs, new int[0]);
}
});
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/24e3b9d0/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/IGisClient.java
----------------------------------------------------------------------
diff --git a/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/IGisClient.java b/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/IGisClient.java
index 316961e..0fdbafc 100644
--- a/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/IGisClient.java
+++ b/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/IGisClient.java
@@ -20,6 +20,7 @@
*/
package org.apache.taverna.gis.client;
+import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
@@ -42,8 +43,11 @@ public interface IGisClient {
public HashMap<String, Integer> getProcessOutputPorts(String processID);
- public List<PortTypeDescriptor> getTaverna2InputPorts(String processID);
+ public List<IPortDataDescriptor> getTaverna2InputPorts(String processID);
- public List<PortTypeDescriptor> getTaverna2OutputPorts(String processID);
+ public List<IPortDataDescriptor> getTaverna2OutputPorts(String processID);
+
+ public HashMap<String, String> executeProcess(String processID, HashMap<String, IPortDataDescriptor> inputs)
+ throws Exception;
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/24e3b9d0/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/GisClientNorthImpl.java
----------------------------------------------------------------------
diff --git a/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/GisClientNorthImpl.java b/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/GisClientNorthImpl.java
index 514a54b..8d168c3 100644
--- a/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/GisClientNorthImpl.java
+++ b/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/GisClientNorthImpl.java
@@ -28,45 +28,48 @@ import java.util.HashMap;
import java.util.List;
import org.apache.log4j.Logger;
-import org.apache.taverna.gis.client.ComplexDataTypeDescriptor;
+import org.apache.taverna.gis.client.ComplexDataFormat;
+import org.apache.taverna.gis.client.ComplexPortDataDescriptor;
import org.apache.taverna.gis.client.IGisClient;
-import org.apache.taverna.gis.client.PortDataType;
-import org.apache.taverna.gis.client.PortTypeDescriptor;
+import org.apache.taverna.gis.client.IPortDataDescriptor;
+import org.apache.taverna.gis.client.PortDataDescriptorFactory;
+import org.n52.wps.client.ExecuteRequestBuilder;
+import org.n52.wps.client.ExecuteResponseAnalyser;
import org.n52.wps.client.WPSClientException;
import org.n52.wps.client.WPSClientSession;
import net.opengis.ows.x11.LanguageStringType;
-import net.opengis.wps.x100.CRSsType;
import net.opengis.wps.x100.CapabilitiesDocument;
-import net.opengis.wps.x100.ComplexDataCombinationType;
-import net.opengis.wps.x100.ComplexDataCombinationsType;
-import net.opengis.wps.x100.ComplexDataDescriptionType;
+import net.opengis.wps.x100.DataType;
import net.opengis.wps.x100.InputDescriptionType;
+import net.opengis.wps.x100.OutputDataType;
import net.opengis.wps.x100.OutputDescriptionType;
import net.opengis.wps.x100.ProcessBriefType;
import net.opengis.wps.x100.ProcessDescriptionType;
import net.opengis.wps.x100.ProcessDescriptionType.DataInputs;
import net.opengis.wps.x100.WPSCapabilitiesType;
+import net.opengis.wps.x100.ExecuteDocument;
+import net.opengis.wps.x100.ExecuteResponseDocument;
public class GisClientNorthImpl implements IGisClient {
private Logger logger = Logger.getLogger(GisClientNorthImpl.class);
-
+
private URI serviceURI = null;
private WPSClientSession wpsClient;
-
+
public GisClientNorthImpl(String serviceURL) {
this.serviceURI = URI.create(serviceURL);
wpsClient = WPSClientSession.getInstance();
-
+
try {
wpsClient.connect(serviceURI.toString());
} catch (WPSClientException ex) {
logger.error("Failed to connect to service: " + serviceURI, ex);
}
-
+
}
-
+
@Override
public String getServiceCapabilities(URI serviceURI) {
@@ -74,7 +77,7 @@ public class GisClientNorthImpl implements IGisClient {
LanguageStringType[] serviceAbstract = capabilities.getCapabilities().getServiceIdentification()
.getTitleArray();
-
+
if (serviceAbstract != null && serviceAbstract.length > 0)
return serviceAbstract[0].getStringValue();
else
@@ -84,112 +87,101 @@ public class GisClientNorthImpl implements IGisClient {
@Override
public HashMap<String, Integer> getProcessInputPorts(String processID) {
HashMap<String, Integer> inputPorts = new HashMap<String, Integer>();
-
+
ProcessDescriptionType processDescription = null;
-
+
try {
processDescription = wpsClient.getProcessDescription(serviceURI.toString(), processID);
} catch (IOException ex) {
logger.error("Failed to list input ports for process: " + processID, ex);
}
- if (processDescription==null)
+ if (processDescription == null)
return inputPorts;
-
+
DataInputs dataInputs = processDescription.getDataInputs();
-
+
if (dataInputs == null)
return inputPorts;
-
+
InputDescriptionType[] inputList = dataInputs.getInputArray();
for (InputDescriptionType input : inputList) {
- // if compareTo returns 1 then first value is greater than 1. it means that there is more than one occurrence therefore the depth is more than 0
- int depth = ((input.getMaxOccurs().compareTo(BigInteger.valueOf(1))==1) ? 1 : 0);
-
+ // if compareTo returns 1 then first value is greater than 1. it
+ // means that there is more than one occurrence therefore the depth
+ // is more than 0
+ int depth = ((input.getMaxOccurs().compareTo(BigInteger.valueOf(1)) == 1) ? 1 : 0);
+
inputPorts.put(input.getIdentifier().getStringValue(), depth);
}
-
+
return inputPorts;
-
+
}
@Override
public HashMap<String, Integer> getProcessOutputPorts(String processID) {
HashMap<String, Integer> outputPorts = new HashMap<String, Integer>();
-
+
ProcessDescriptionType processDescription = null;
-
+
try {
processDescription = wpsClient.getProcessDescription(serviceURI.toString(), processID);
} catch (IOException ex) {
logger.error("Failed to list processe output port for process: " + processID, ex);
}
- if (processDescription==null)
+ if (processDescription == null)
return outputPorts;
-
+
OutputDescriptionType[] outputList = processDescription.getProcessOutputs().getOutputArray();
for (OutputDescriptionType output : outputList) {
// TODO: Calculate output depth
int depth = 0;
-
+
outputPorts.put(output.getIdentifier().getStringValue(), depth);
}
-
+
return outputPorts;
}
-
- public List<PortTypeDescriptor> getTaverna2InputPorts(String processID)
- {
-
- List<PortTypeDescriptor> inputPorts = new ArrayList<PortTypeDescriptor>();
-
+
+ public List<IPortDataDescriptor> getTaverna2InputPorts(String processID) {
+
+ List<IPortDataDescriptor> inputPorts = new ArrayList<IPortDataDescriptor>();
+
ProcessDescriptionType processDescription = null;
-
+
try {
processDescription = wpsClient.getProcessDescription(serviceURI.toString(), processID);
} catch (IOException ex) {
logger.error("Failed to get process description for process: " + processID, ex);
}
- if (processDescription==null)
+ if (processDescription == null)
return inputPorts;
-
+
DataInputs dataInputs = processDescription.getDataInputs();
-
+
if (dataInputs == null)
return inputPorts;
-
+
InputDescriptionType[] inputList = dataInputs.getInputArray();
for (InputDescriptionType input : inputList) {
- PortTypeDescriptor myNewInputPort = new PortTypeDescriptor();
-
- myNewInputPort.setName(input.getIdentifier().getStringValue());
- myNewInputPort.setDepth(getInputPortDepth(input));
- myNewInputPort.setAllowLiteralValues(true);
- myNewInputPort.setHandledReferenceSchemes(null); // is not used in Taverna
- myNewInputPort.setTranslatedElementType(String.class);
- myNewInputPort.setPortDataType(getPortDataType(input));
- myNewInputPort.setRequired(input.getMinOccurs().compareTo(BigInteger.valueOf(1))>0?true:false);
- myNewInputPort.setSupportedComplexFormats(getInputPortSupportedComplexFormats(input));
- myNewInputPort.setDefaultComplexFormat(getInputPortDefaultComplexFormat(input));
- myNewInputPort.setSupportedBoundingBoxFormats(getInputPortSupportedBoundingBoxFormats(input));
- myNewInputPort.setDefaultBoundingBoxFormat(getInputPortDefaultBoundingBoxFormats(input));
-
+ IPortDataDescriptor myNewInputPort = PortDataDescriptorFactory.getInstance().getPortDataDescriptor(input);
+
inputPorts.add(myNewInputPort);
}
-
+
return inputPorts;
}
@Override
- public List<PortTypeDescriptor> getTaverna2OutputPorts(String processID) {
- List<PortTypeDescriptor> outputPorts = new ArrayList<PortTypeDescriptor>();
+ public List<IPortDataDescriptor> getTaverna2OutputPorts(String processID) {
+ List<IPortDataDescriptor> outputPorts = new ArrayList<IPortDataDescriptor>();
ProcessDescriptionType processDescription = null;
@@ -205,18 +197,7 @@ public class GisClientNorthImpl implements IGisClient {
OutputDescriptionType[] outputList = processDescription.getProcessOutputs().getOutputArray();
for (OutputDescriptionType output : outputList) {
- PortTypeDescriptor myNewOutputPort = new PortTypeDescriptor();
-
- myNewOutputPort.setName(output.getIdentifier().getStringValue());
- myNewOutputPort.setDepth(0); // output port depth is always 1
-
- myNewOutputPort.setPortDataType(getPortDataType(output));
- myNewOutputPort.setRequired(false);
- myNewOutputPort.setSupportedComplexFormats(getOutputPortSupportedComplexFormats(output));
- myNewOutputPort.setDefaultComplexFormat(getOutputPortDefaultComplexFormat(output));
- myNewOutputPort.setSupportedBoundingBoxFormats(getOutputPortSupportedBoundingBoxFormats(output));
- myNewOutputPort.setDefaultBoundingBoxFormat(getOutputPortDefaultBoundingBoxFormats(output));
-
+ IPortDataDescriptor myNewOutputPort = PortDataDescriptorFactory.getInstance().getPortDataDescriptor(output);
outputPorts.add(myNewOutputPort);
}
@@ -228,229 +209,160 @@ public class GisClientNorthImpl implements IGisClient {
List<String> results = new ArrayList<String>();
WPSCapabilitiesType wpsCapabilities = wpsClient.getWPSCaps(serviceURI.toString()).getCapabilities();
-
+
ProcessBriefType[] processList = wpsCapabilities.getProcessOfferings().getProcessArray();
-
- for( ProcessBriefType process: processList)
- {
+
+ for (ProcessBriefType process : processList) {
results.add(process.getIdentifier().getStringValue());
}
-
+
return results;
-
- }
- private PortDataType getPortDataType(InputDescriptionType inputPort)
- {
- // set default dataType to literal data
- PortDataType portDataType = PortDataType.LITERAL_DATA;
-
- if (inputPort.getLiteralData()!=null)
- return portDataType;
-
- if(inputPort.getComplexData()!=null)
- return PortDataType.COMPLEX_DATA;
-
- if(inputPort.getBoundingBoxData()!=null)
- return PortDataType.BOUNDING_BOX_DATA;
-
- return portDataType;
-
}
+
+ @Override
+ public HashMap<String, String> executeProcess(String processID, HashMap<String, IPortDataDescriptor> inputs)
+ throws Exception {
+
+ HashMap<String, String> executeOutput = new HashMap<String, String>();
+
+ ProcessDescriptionType processDescription = null;
+
+ // Get process description
+ try {
+ processDescription = wpsClient.getProcessDescription(serviceURI.toString(), processID);
+ } catch (IOException ex) {
+ throw new Exception("Failed to get process description for process: " + processID, ex);
+ }
+
+ // Initialise execute builder
+ ExecuteRequestBuilder executeBuilder = new ExecuteRequestBuilder(processDescription);
+
+ boolean hasInput = true;
+
+ DataInputs dataInputs = processDescription.getDataInputs();
+
+ if (dataInputs == null)
+ hasInput = false;
+
+ if (hasInput) {
+
+ InputDescriptionType[] inputList = dataInputs.getInputArray();
+
+ // TODO: Handle input when depth > 0
+ // Provide user values for each service input
+ for (InputDescriptionType input : inputList) {
+ String inputName = input.getIdentifier().getStringValue();
+ Object inputValue = inputs.containsKey(inputName)?inputs.get(inputName).getValue():null;
+
+ // Check if input is required but not provided
+ if (inputValue == null && input.getMinOccurs().intValue() > 0) {
+ throw new IOException("Required Input not set: " + inputName);
+ }
+
+ // Skip not user supplied optional inputs
+ if (inputValue!=null)
+ {
+ if (input.getLiteralData() != null) {
+ if (inputValue instanceof String) {
+ executeBuilder.addLiteralData(inputName, (String) inputValue);
+ }
- private PortDataType getPortDataType(OutputDescriptionType outputPort)
- {
- // set default dataType to literal data
- PortDataType portDataType = PortDataType.LITERAL_DATA;
-
- if (outputPort.getLiteralOutput()!=null)
- return portDataType;
-
- if(outputPort.getComplexOutput()!=null)
- return PortDataType.COMPLEX_DATA;
-
- if(outputPort.getBoundingBoxOutput()!=null)
- return PortDataType.BOUNDING_BOX_DATA;
-
- return portDataType;
-
- }
+ } else if (input.getComplexData() != null) {
- /**
- * @param input port
- * @return List of supported formats
- */
- private List<ComplexDataTypeDescriptor> getInputPortSupportedComplexFormats(InputDescriptionType inputPort)
- {
- List<ComplexDataTypeDescriptor> supportedComplexFormats = new ArrayList<ComplexDataTypeDescriptor>();
-
- if (inputPort.getComplexData()==null)
- return supportedComplexFormats;
- else
- {
- ComplexDataCombinationsType complexDataSupportedTypes = inputPort.getComplexData().getSupported();
-
- if (complexDataSupportedTypes.sizeOfFormatArray()==0)
- return supportedComplexFormats;
-
- for(ComplexDataDescriptionType format : complexDataSupportedTypes.getFormatArray())
- {
- supportedComplexFormats.add(new ComplexDataTypeDescriptor(format.getMimeType(),format.getEncoding(), format.getSchema()));
- }
- }
-
- return supportedComplexFormats;
- }
+ // Check if the selected format (mimeType, encoding, schema)
+ // is supported by the service
+ ComplexPortDataDescriptor complexData = (ComplexPortDataDescriptor) inputs.get(inputName);
+ ComplexDataFormat selectedFormat = complexData.getComplexFormat();
- private ComplexDataTypeDescriptor getInputPortDefaultComplexFormat(InputDescriptionType inputPort)
- {
- ComplexDataTypeDescriptor defaultFormat = null;
-
- if (inputPort.getComplexData()==null)
- if (inputPort.getComplexData().getDefault()!=null)
- if(inputPort.getComplexData().getDefault().getFormat()!=null)
- {
- ComplexDataDescriptionType outputDefaultFormat = inputPort.getComplexData().getDefault().getFormat();
- defaultFormat = new ComplexDataTypeDescriptor(outputDefaultFormat.getMimeType(),outputDefaultFormat.getEncoding(),outputDefaultFormat.getSchema());
- }
-
- return defaultFormat;
-
- }
+ if (!complexData.getSupportedComplexFormats().contains(selectedFormat)) {
+ throw new IllegalArgumentException(
+ "Unsupported format: " + complexData.getComplexFormat().toString());
+ }
- private List<String> getInputPortSupportedBoundingBoxFormats(InputDescriptionType inputPort)
- {
- List<String> supportedBoundingBoxFormats = new ArrayList<String>();
-
- if (inputPort.getBoundingBoxData()==null)
- return supportedBoundingBoxFormats;
- else
- {
- CRSsType boundingBoxDataSupportedTypes = inputPort.getBoundingBoxData().getSupported();
-
- if (boundingBoxDataSupportedTypes.sizeOfCRSArray()==0)
- return supportedBoundingBoxFormats;
-
- for(String format : boundingBoxDataSupportedTypes.getCRSArray())
- {
- supportedBoundingBoxFormats.add(format);
- }
-
- }
-
- return supportedBoundingBoxFormats;
-
- }
+ if (inputValue instanceof String) {
+ // Check if complex data is provided by reference or by
+ // value
+ boolean isReference = true;
- private String getInputPortDefaultBoundingBoxFormats(InputDescriptionType inputPort)
- {
- String defaultFormat = null;
-
- if (inputPort.getBoundingBoxData()==null)
- if (inputPort.getBoundingBoxData().getDefault()!=null)
- if(inputPort.getBoundingBoxData().getDefault().getCRS()!=null)
- {
- defaultFormat = inputPort.getBoundingBoxData().getDefault().getCRS();
- }
-
- return defaultFormat;
-
- }
+ try {
+ URI.create((String) inputValue);
+ } catch (IllegalArgumentException ex) {
+ isReference = false;
+ }
- /**
- * @param input port
- * @return List of supported formats
- */
- private List<ComplexDataTypeDescriptor> getOutputPortSupportedComplexFormats(OutputDescriptionType outputPort)
- {
- List<ComplexDataTypeDescriptor> supportedComplexFormats = new ArrayList<ComplexDataTypeDescriptor>();
-
- if (outputPort.getComplexOutput()==null)
- return supportedComplexFormats;
- else
- {
- ComplexDataCombinationsType complexDataSupportedTypes = outputPort.getComplexOutput().getSupported();
-
- if (complexDataSupportedTypes.sizeOfFormatArray()==0)
- return supportedComplexFormats;
-
- for(ComplexDataDescriptionType format : complexDataSupportedTypes.getFormatArray())
- {
- supportedComplexFormats.add(new ComplexDataTypeDescriptor(format.getMimeType(),format.getEncoding(), format.getSchema()));
- }
- }
-
- return supportedComplexFormats;
- }
+ if (isReference) {
+ // complex data by reference
+ executeBuilder.addComplexDataReference(inputName, (String) inputValue,
+ selectedFormat.getSchema(), selectedFormat.getEncoding(),
+ selectedFormat.getMimeType());
+ } else {
- private ComplexDataTypeDescriptor getOutputPortDefaultComplexFormat(OutputDescriptionType outputPort)
- {
- ComplexDataTypeDescriptor defaultFormat = null;
-
- if (outputPort.getComplexOutput()==null)
- if (outputPort.getComplexOutput().getDefault()!=null)
- if(outputPort.getComplexOutput().getDefault().getFormat()!=null)
- {
- ComplexDataDescriptionType outputDefaultFormat = outputPort.getComplexOutput().getDefault().getFormat();
- defaultFormat = new ComplexDataTypeDescriptor(outputDefaultFormat.getMimeType(),outputDefaultFormat.getEncoding(),outputDefaultFormat.getSchema());
- }
-
- return defaultFormat;
-
- }
+ // complex data by value
+ try {
- private List<String> getOutputPortSupportedBoundingBoxFormats(OutputDescriptionType outputPort)
- {
- List<String> supportedBoundingBoxFormats = new ArrayList<String>();
-
- if (outputPort.getBoundingBoxOutput()==null)
- return supportedBoundingBoxFormats;
- else
- {
- CRSsType boundingBoxDataSupportedTypes = outputPort.getBoundingBoxOutput().getSupported();
-
- if (boundingBoxDataSupportedTypes.sizeOfCRSArray()==0)
- return supportedBoundingBoxFormats;
-
- for(String format : boundingBoxDataSupportedTypes.getCRSArray())
- {
- supportedBoundingBoxFormats.add(format);
- }
-
+ executeBuilder.addComplexData(inputName, (String) inputValue,
+ selectedFormat.getSchema(), selectedFormat.getEncoding(),
+ selectedFormat.getMimeType());
+
+ } catch (WPSClientException e) {
+ throw new Exception("Failed to set complex data: " + processID, e);
+ }
+ }
+ }
+ } else if (input.getBoundingBoxData() != null) {
+ // TODO: Handle BBox data
+ }
+ }
+
+
+ } // End input loop
+
}
-
- return supportedBoundingBoxFormats;
+ ExecuteDocument execute = executeBuilder.getExecute();
+
+ execute.getExecute().setService("WPS");
+
+ Object responseObject = null;
+
+ try {
+ // Execute service
+ responseObject = wpsClient.execute(serviceURI.toString(), execute);
+ } catch (WPSClientException e) {
+ throw new Exception(e.getServerException().xmlText());
+ }
+
+ // Register outputs
+ if (responseObject instanceof ExecuteResponseDocument) {
+ ExecuteResponseDocument response = (ExecuteResponseDocument) responseObject;
+
+ // analyser is used to get complex data
+ ExecuteResponseAnalyser analyser = new ExecuteResponseAnalyser(execute, response, processDescription);
+
+ for (OutputDataType output : response.getExecuteResponse().getProcessOutputs().getOutputArray()) {
+ DataType data = output.getData();
+
+ if (data.isSetLiteralData()) {
+
+ // simpleRef =
+ // referenceService.register(data.getLiteralData().getStringValue(),
+ // 0, true, context);
+
+ executeOutput.put(output.getIdentifier().getStringValue(), data.getLiteralData().getStringValue());
+ } else {
+
+ // simpleRef =
+ // referenceService.register(data.getComplexData().toString(),
+ // 0, true, context);
+
+ executeOutput.put(output.getIdentifier().getStringValue(), data.getComplexData().toString());
- }
-
- private String getOutputPortDefaultBoundingBoxFormats(OutputDescriptionType outputPort)
- {
- String defaultFormat = null;
-
- if (outputPort.getBoundingBoxOutput()==null)
- if (outputPort.getBoundingBoxOutput().getDefault()!=null)
- if(outputPort.getBoundingBoxOutput().getDefault().getCRS()!=null)
- {
- defaultFormat = outputPort.getBoundingBoxOutput().getDefault().getCRS();
}
-
- return defaultFormat;
-
- }
-
- /**
- * @param inputPort
- * @return
- */
- private int getInputPortDepth(InputDescriptionType inputPort)
- {
- // The input has cardinality (Min/Max Occurs) of 1 when it returns 1 value and greater than 1 when it
- // returns multiple values
- // if compareTo returns 1 then first value (MaxOccurs) is greater than 1. it means that there is more than one occurrence
- // therefore the depth is greater than 0
- int depth = ((inputPort.getMaxOccurs().compareTo(BigInteger.valueOf(1))==1) ? 1 : 0);
-
- return depth;
+
+ }
+
+ }
+
+ return executeOutput;
}
-
}