diff --git a/pom.xml b/pom.xml index 283d755..dbfea83 100644 --- a/pom.xml +++ b/pom.xml @@ -52,37 +52,38 @@ - - org.apache.taverna.osgi - taverna-maven-plugin - ${taverna.osgi.version} - true - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.apache.taverna.orgi - taverna-maven-plugin - [${taverna.osgi.version},) - - plugin-generate - - - - - - - - - - + + org.apache.taverna.osgi + taverna-maven-plugin + ${taverna.osgi.version} + true + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.taverna.orgi + taverna-maven-plugin + [${taverna.osgi.version},) + + plugin-generate + + + + + + + + + + @@ -112,8 +113,8 @@ taverna-gis-plugin taverna-gis-activity - taverna-gis-activity-ui - taverna-gis-plugin + taverna-gis-activity-ui + taverna-gis-client diff --git a/taverna-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceDesc.java b/taverna-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceDesc.java index c9a93f0..7b389ea 100644 --- a/taverna-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceDesc.java +++ b/taverna-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceDesc.java @@ -33,7 +33,7 @@ public class GisServiceDesc extends ServiceDescription { public static final URI ACTIVITY_TYPE = URI - .create("http://ns.taverna.org.uk/2016/activity/gis"); + .create("http://ns.taverna.org.uk/2016/service/gis"); /** diff --git a/taverna-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceProvider.java b/taverna-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceProvider.java index 9811100..a03fe93 100644 --- a/taverna-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceProvider.java +++ b/taverna-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceProvider.java @@ -20,7 +20,6 @@ */ package org.apache.taverna.gis.ui.serviceprovider; -import java.io.IOException; import java.net.URI; import java.util.ArrayList; import java.util.Arrays; @@ -29,23 +28,14 @@ import javax.swing.Icon; import org.apache.taverna.scufl2.api.common.Visitor; -import org.apache.taverna.scufl2.api.common.WorkflowBean; import org.apache.taverna.scufl2.api.configurations.Configuration; import org.apache.taverna.servicedescriptions.AbstractConfigurableServiceProvider; import org.apache.taverna.servicedescriptions.ConfigurableServiceProvider; import org.apache.taverna.servicedescriptions.ServiceDescription; import org.apache.taverna.servicedescriptions.ServiceDescriptionProvider; -import org.apache.taverna.servicedescriptions.ServiceDescriptionProvider.FindServiceDescriptionsCallBack; -import org.apache.taverna.workflowmodel.processor.activity.config.ActivityInputPortDefinitionBean; -import org.apache.taverna.workflowmodel.processor.activity.config.ActivityOutputPortDefinitionBean; -import org.n52.wps.client.WPSClientSession; import com.fasterxml.jackson.databind.node.ObjectNode; -import net.opengis.wps.x100.InputDescriptionType; -import net.opengis.wps.x100.OutputDescriptionType; -import net.opengis.wps.x100.ProcessDescriptionType; - public class GisServiceProvider extends AbstractConfigurableServiceProvider implements ConfigurableServiceProvider { @@ -68,7 +58,6 @@ private static Configuration defaultConfig() { /** * Do the actual search for services. Return using the callBack parameter. */ - @SuppressWarnings("unchecked") public void findServiceDescriptionsAsync(FindServiceDescriptionsCallBack callBack) { // Use callback.status() for long-running searches callBack.status("Resolving GIS services"); @@ -89,58 +78,6 @@ public void findServiceDescriptionsAsync(FindServiceDescriptionsCallBack callBac // TODO: Optional: set description (Set a better description service.setDescription(processIdentifier); - // TODO: Exctract in a separate method - // Get input ports - - WPSClientSession wpsClient = WPSClientSession.getInstance(); - - ProcessDescriptionType processDescription; - try { - processDescription = wpsClient - .getProcessDescription(serviceUri, processIdentifier); - - InputDescriptionType[] inputList = processDescription.getDataInputs() - .getInputArray(); - - List inputPortDefinitions = new ArrayList(); - - for (InputDescriptionType input : inputList) { - ActivityInputPortDefinitionBean newInputPort = new ActivityInputPortDefinitionBean(); - newInputPort.setName(input.getIdentifier().getStringValue()); - newInputPort.setDepth(0); - newInputPort.setAllowsLiteralValues(true); - newInputPort.setHandledReferenceSchemes(null); - newInputPort.setTranslatedElementType(String.class); - - inputPortDefinitions.add(newInputPort); - - } - - // service.setInputPortDefinitions(inputPortDefinitions); - - - // Get output ports - - OutputDescriptionType[] outputList = processDescription.getProcessOutputs().getOutputArray(); - List outputPortDefinitions = new ArrayList(); - - for( OutputDescriptionType output : outputList ) - { - ActivityOutputPortDefinitionBean newOutputPort = new ActivityOutputPortDefinitionBean(); - newOutputPort.setName(output.getIdentifier().getStringValue()); - newOutputPort.setDepth(0); - - outputPortDefinitions.add(newOutputPort); - - } - - //service.setOutputPortDefinitions(outputPortDefinitions); - - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - results.add(service); // partialResults() can also be called several times from inside diff --git a/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivity.java b/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivity.java index 2b8aef0..4849bb6 100644 --- a/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivity.java +++ b/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivity.java @@ -21,25 +21,26 @@ package org.apache.taverna.gis; import java.io.IOException; -import java.util.ArrayList; +import java.net.URI; import java.util.HashMap; -import java.util.Iterator; -import java.util.List; import java.util.Map; -import org.geotools.ows.ServiceException; 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.n52.wps.io.data.IData; -import org.n52.wps.io.data.binding.complex.GTVectorDataBinding; + +import com.fasterxml.jackson.databind.JsonNode; 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 org.apache.log4j.Logger; +import org.apache.taverna.gis.client.GisClientFactory; +import org.apache.taverna.gis.client.IGisClient; import org.apache.taverna.invocation.InvocationContext; import org.apache.taverna.reference.ReferenceService; import org.apache.taverna.reference.T2Reference; @@ -50,45 +51,64 @@ import org.apache.taverna.workflowmodel.processor.activity.config.ActivityInputPortDefinitionBean; import org.apache.taverna.workflowmodel.processor.activity.config.ActivityOutputPortDefinitionBean; -public class GisActivity extends AbstractAsynchronousActivity - implements AsynchronousActivity { - - private GisActivityConfigurationBean configBean; - - @Override - public void configure(GisActivityConfigurationBean configBean) throws ActivityConfigurationException { - - // TODO: Should I call HealthChecker here?? - // Any pre-config sanity checks - if (configBean.getOgcServiceUri().equals("")) { - throw new ActivityConfigurationException("Geospatial web service URI can't be empty"); - } - // Store for getConfiguration() - this.configBean = configBean; +public class GisActivity extends AbstractAsynchronousActivity implements AsynchronousActivity { - // REQUIRED: (Re)create input/output ports depending on configuration - configurePorts(); - } + public static final String ACTIVITY_TYPE = "http://ns.taverna.org.uk/2016/activity/gis"; - protected void configurePorts() { - // In case we are being reconfigured - remove existing ports first - // to avoid duplicates - removeInputs(); - removeOutputs(); + private static Logger logger = Logger.getLogger(GisActivity.class); - // Add input ports - for(ActivityInputPortDefinitionBean inputPort : configBean.getInputPortDefinitions()) - { - addInput(inputPort.getName(),inputPort.getDepth(),inputPort.getAllowsLiteralValues(),inputPort.getHandledReferenceSchemes(), inputPort.getTranslatedElementType()); - } + private JsonNode configurationBean; - // Add output ports - for(ActivityOutputPortDefinitionBean outputPort : configBean.getOutputPortDefinitions()) - { - addOutput(outputPort.getName(),outputPort.getDepth()); + /** + * Configures the activity according to the information passed by the + * configuration bean.
+ * During this process the WPS is parsed to determine the input and output + * ports. + * + * @param bean + * the {@link GisActivityConfigurationBean} configuration bean + */ + @Override + public void configure(JsonNode bean) throws ActivityConfigurationException { + this.configurationBean = bean; + + try { + parseGISService(); + } catch (Exception ex) { + throw new ActivityConfigurationException( + "Unable to parse the WSDL " + bean.get("service").textValue(), ex); } + } + @Override + public JsonNode getConfiguration() { + return this.configurationBean; } + + // FIXME: Is the procedure needed? +// protected void configurePorts() { +// // In case we are being reconfigured - remove existing ports first +// // to avoid duplicates +// removeInputs(); +// removeOutputs(); +// +// IGisClient gisServiceParser = GisClientFactory.getInstance() +// .getGisClient(configurationBean.get("service").textValue()); +// +// gisServiceParser.GetProcessInputPorts(configurationBean.get("process").textValue()); +// +// // Add input ports +// for (ActivityInputPortDefinitionBean inputPort : configurationBean.getInputPortDefinitions()) { +// addInput(inputPort.getName(), inputPort.getDepth(), inputPort.getAllowsLiteralValues(), +// inputPort.getHandledReferenceSchemes(), inputPort.getTranslatedElementType()); +// } +// +// // Add output ports +// for (ActivityOutputPortDefinitionBean outputPort : configurationBean.getOutputPortDefinitions()) { +// addOutput(outputPort.getName(), outputPort.getDepth()); +// } +// +// } @SuppressWarnings("unchecked") @Override @@ -104,18 +124,21 @@ public void run() { Map outputs = null; try { - + // FIXME: Extract service execution to GisClient // prepare the execute object WPSClientSession wpsClient = WPSClientSession.getInstance(); - ProcessDescriptionType processDescription = wpsClient.getProcessDescription(configBean.getOgcServiceUri().toString(), configBean.getProcessIdentifier()); + ProcessDescriptionType processDescription = wpsClient.getProcessDescription( + configurationBean.get("service").textValue(), configurationBean.get("process").textValue()); ExecuteRequestBuilder executeBuilder = new ExecuteRequestBuilder(processDescription); - for (ActivityInputPortDefinitionBean activityInputPort : configBean.getInputPortDefinitions()) { - String portValue = (String) referenceService.renderIdentifier(inputs.get(activityInputPort.getName()), String.class, context); - executeBuilder.addLiteralData(activityInputPort.getName(), portValue); - } + // FIXME: Provide ports +// for (ActivityInputPortDefinitionBean activityInputPort : configurationBean.getInputPortDefinitions()) { +// String portValue = (String) referenceService +// .renderIdentifier(inputs.get(activityInputPort.getName()), String.class, context); +// executeBuilder.addLiteralData(activityInputPort.getName(), portValue); +// } ExecuteDocument execute = executeBuilder.getExecute(); @@ -125,7 +148,7 @@ public void run() { try { // execute service - responseObject = wpsClient.execute(configBean.getOgcServiceUri().toString(), execute); + responseObject = wpsClient.execute(configurationBean.get("service").textValue(), execute); } catch (WPSClientException e) { // if the an error return from service callback.fail(e.getServerException().xmlText()); @@ -136,27 +159,26 @@ public void run() { T2Reference simpleRef = null; if (responseObject instanceof ExecuteResponseDocument) { - ExecuteResponseDocument response = (ExecuteResponseDocument) responseObject; + ExecuteResponseDocument response = (ExecuteResponseDocument) responseObject; - // analyser is used to get complex data - ExecuteResponseAnalyser analyser = new ExecuteResponseAnalyser( - execute, response, processDescription); + // 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(); + for (OutputDataType output : response.getExecuteResponse().getProcessOutputs() + .getOutputArray()) { + DataType data = output.getData(); - if (data.isSetLiteralData()) - { - simpleRef = referenceService.register(data.getLiteralData().getStringValue(), 0, true, context); + if (data.isSetLiteralData()) { + simpleRef = referenceService.register(data.getLiteralData().getStringValue(), 0, true, + context); outputs.put(output.getIdentifier().getStringValue(), simpleRef); } } - } - + } } catch (WPSClientException e) { callback.fail(e.getMessage()); @@ -169,9 +191,19 @@ public void run() { }); } - @Override - public GisActivityConfigurationBean getConfiguration() { - return this.configBean; + /** + * This method should ping the gis web service to check if it is live or + * other check like valid URL etc. + */ + private void parseGISService() { + } +// @Override +// public GisActivityConfigurationBean getConfiguration() { +// return this.configBean; +// } + + + } diff --git a/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityConfigurationBean.java b/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityConfigurationBean.java index babafae..b53efdb 100644 --- a/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityConfigurationBean.java +++ b/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityConfigurationBean.java @@ -27,6 +27,7 @@ import net.opengis.wps.x100.InputDescriptionType; import net.opengis.wps.x100.OutputDescriptionType; import org.apache.taverna.workflowmodel.processor.activity.config.ActivityPortsDefinitionBean; +import org.apache.taverna.workflowmodel.processor.config.ConfigurationProperty; /** * Gis activity configuration bean. @@ -52,19 +53,23 @@ public class GisActivityConfigurationBean extends ActivityPortsDefinitionBean im * be referenced as well, as long as they are part of the same plugin. */ - private URI ogcServiceUri; private String processIdentifier; public URI getOgcServiceUri() { return ogcServiceUri; } + + @ConfigurationProperty(name = "service", label = "OGC Service URI", description = "The location of the GIS Web Service definition") public void setOgcServiceUri(URI ogcServiceUri) { this.ogcServiceUri = ogcServiceUri; } + public String getProcessIdentifier() { return processIdentifier; } + + @ConfigurationProperty(name = "process", label = "Process ID", description = "The identifier of the process provided by the web service") public void setProcessIdentifier(String processIdentifier) { this.processIdentifier = processIdentifier; } diff --git a/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityFactory.java b/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityFactory.java index 0f43ab0..6f64693 100644 --- a/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityFactory.java +++ b/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityFactory.java @@ -20,16 +20,20 @@ */ package org.apache.taverna.gis; -import static org.apache.taverna.gis.GisActivity.*; - import java.io.IOException; import java.net.URI; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.log4j.Logger; +import org.apache.taverna.gis.client.GisClientFactory; +import org.apache.taverna.gis.client.IGisClient; +import org.apache.taverna.gis.client.impl.NorthClientImpl; import org.apache.taverna.workflowmodel.Edits; import org.apache.taverna.workflowmodel.processor.activity.ActivityFactory; import org.apache.taverna.workflowmodel.processor.activity.ActivityInputPort; @@ -40,6 +44,8 @@ */ public class GisActivityFactory implements ActivityFactory { + private static Logger logger = Logger.getLogger(GisActivityFactory.class); + private Edits edits; @Override @@ -64,39 +70,49 @@ public JsonNode getActivityConfigurationSchema() { @Override public Set getInputPorts(JsonNode configuration) { - Set inputPorts = new HashSet<>(); - - // FIXME: Replace with your input port definitions - - // Hard coded input port, expecting a single String - inputPorts.add(edits.createActivityInputPort(IN_FIRST_INPUT, 0, true, null, String.class)); - - // Optional ports depending on configuration - if (configuration.get("exampleString").asText().equals("specialCase")) { - // depth 1, ie. list of binary byte[] arrays - inputPorts.add(edits.createActivityInputPort(IN_EXTRA_DATA, 1, true, null, byte[].class)); + Map inputPorts = new HashMap(); + + IGisClient gisServiceParser = GisClientFactory.getInstance().getGisClient(configuration.get("ogcServiceUri").textValue()); + + try { + // get ports name, depth + Map inputPortDescriptions = gisServiceParser.GetProcessInputPorts(configuration.get("processIdentifier").textValue()); + + for (Map.Entry entry : inputPortDescriptions.entrySet()) { + inputPorts.put(entry.getKey(), edits.createActivityInputPort( + entry.getKey(), entry.getValue(), true, null, String.class)); + } + } catch (Exception e) { + logger.warn( + "Unable to parse the GIS " + configuration.get("service").textValue(), e); } - - return inputPorts; + + return new HashSet(inputPorts.values()); } @Override public Set getOutputPorts(JsonNode configuration) { - Set outputPorts = new HashSet<>(); - - // FIXME: Replace with your output port definitions - - // Optional ports depending on configuration - if (configuration.get("exampleString").asText().equals("specialCase")) { - outputPorts.add(edits.createActivityOutputPort(OUT_REPORT, 0, 0)); + Map outputPorts = new HashMap(); + + IGisClient gisServiceParser = GisClientFactory.getInstance() + .getGisClient(configuration.get("ogcServiceUri").textValue()); + + try { + // get ports (name, depth) pairs + Map outputPortDescriptions = gisServiceParser.GetProcessOutputPorts(configuration.get("processIdentifier").textValue()); + + for (Map.Entry outputPortIterator : outputPortDescriptions.entrySet()) { + outputPorts.put(outputPortIterator.getKey(), + edits.createActivityOutputPort(outputPortIterator.getKey(), + outputPortIterator.getValue(),outputPortIterator.getValue())); + } + } catch (Exception e) { + logger.warn( + "Unable to parse the GIS " + configuration.get("ogcServiceUri").textValue(), e); } - - // Single value output port (depth 0) - outputPorts.add(edits.createActivityOutputPort(OUT_SIMPLE_OUTPUT, 0, 0)); - // Output port with list of values (depth 1) - outputPorts.add(edits.createActivityOutputPort(OUT_MORE_OUTPUTS, 1, 1)); - - return outputPorts; + + return new HashSet(outputPorts.values()); + } /** diff --git a/taverna-gis-activity/src/main/resources/exampleconfig.json b/taverna-gis-activity/src/main/resources/exampleconfig.json new file mode 100644 index 0000000..0c938eb --- /dev/null +++ b/taverna-gis-activity/src/main/resources/exampleconfig.json @@ -0,0 +1,15 @@ +{ "service": { + "ogcServiceUri": "http://example.com/", + "processIdentifier": "process1", + }, + "portConfig": { + "inputs": { + "in54": { + "mediaType": "application/json", + "isReference": true + } + }, + "outputs": { + } + } +} \ No newline at end of file diff --git a/taverna-gis-activity/src/main/resources/wps_config.xml b/taverna-gis-activity/src/main/resources/wps_config.xml deleted file mode 100644 index cd73904..0000000 --- a/taverna-gis-activity/src/main/resources/wps_config.xml +++ /dev/null @@ -1,212 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.n52.wps.server.algorithm.JTSConvexHullAlgorithm - org.n52.wps.server.algorithm.test.DummyTestClass - org.n52.wps.server.algorithm.test.LongRunningDummyTestClass - org.n52.wps.server.algorithm.test.MultipleComplexInAndOutputsDummyTestClass - org.n52.wps.server.algorithm.test.MultiReferenceInputAlgorithm - org.n52.wps.server.algorithm.test.MultiReferenceBinaryInputAlgorithm - org.n52.wps.server.algorithm.test.EchoProcess - - - - - - - - - - - - false - - - - true - - PT1H - - P7D - - - - - - \ No newline at end of file diff --git a/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityFactoryTest.java b/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityFactoryTest.java index 9468849..59e66ad 100644 --- a/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityFactoryTest.java +++ b/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityFactoryTest.java @@ -49,8 +49,8 @@ public class GisActivityFactoryTest { @Before public void setUp() throws Exception { configuration = JsonNodeFactory.instance.objectNode(); - configuration.put("exampleString", "something"); - configuration.put("exampleUri", "http://localhost:8080/myEndPoint"); + configuration.put("ogcServiceUri", "http://localhost:8080/geoserver/ows"); + configuration.put("processIdentifier", "custom:splitPolygon"); activityFactory = new GisActivityFactory(); activityFactory.setEdits(new EditsImpl()); @@ -74,14 +74,15 @@ public void testGetActivityConfigurationSchema() { assertNotNull(configurationSchema); assertTrue(configurationSchema.has("properties")); JsonNode propertiesNode = configurationSchema.get("properties"); - assertTrue(propertiesNode.has("exampleString")); - assertTrue(propertiesNode.has("exampleUri")); + assertTrue(propertiesNode.has("ogcServiceUri")); + assertTrue(propertiesNode.has("processIdentifier")); } @Test public void testGetInputPorts() { Set expectedInputs = new HashSet(); - expectedInputs.add("firstInput"); + expectedInputs.add("line"); + expectedInputs.add("polygon"); Set inputPorts = activityFactory.getInputPorts(configuration); assertEquals("Unexpected inputs", expectedInputs.size(), inputPorts.size()); @@ -91,8 +92,8 @@ public void testGetInputPorts() { } ObjectNode specialConfiguration = JsonNodeFactory.instance.objectNode(); - specialConfiguration.put("exampleString", "specialCase"); - specialConfiguration.put("exampleUri", "http://localhost:8080/myEndPoint"); + specialConfiguration.put("ogcServiceUri", "http://localhost:8080/geoserver/ows"); + specialConfiguration.put("processIdentifier", "custom:splitPolygon"); assertEquals("Unexpected inputs", 2, activityFactory.getInputPorts(specialConfiguration).size()); } @@ -100,8 +101,7 @@ public void testGetInputPorts() { @Test public void testGetOutputPorts() { Set expectedOutputs = new HashSet(); - expectedOutputs.add("simpleOutput"); - expectedOutputs.add("moreOutputs"); + expectedOutputs.add("result"); Set outputPorts = activityFactory.getOutputPorts(configuration); assertEquals("Unexpected outputs", expectedOutputs.size(), outputPorts.size()); @@ -111,10 +111,10 @@ public void testGetOutputPorts() { } ObjectNode specialConfiguration = JsonNodeFactory.instance.objectNode(); - specialConfiguration.put("exampleString", "specialCase"); - specialConfiguration.put("exampleUri", "http://localhost:8080/myEndPoint"); + specialConfiguration.put("ogcServiceUri", "http://localhost:8080/geoserver/ows"); + specialConfiguration.put("processIdentifier", "custom:splitPolygon"); - assertEquals("Unexpected outputs", 3, activityFactory.getOutputPorts(specialConfiguration).size()); + assertEquals("Unexpected outputs", 1, activityFactory.getOutputPorts(specialConfiguration).size()); } } diff --git a/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityTest.java b/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityTest.java index 6faea0d..78e56db 100644 --- a/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityTest.java +++ b/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityTest.java @@ -51,8 +51,8 @@ public class GisActivityTest { @Before public void makeConfiguration() throws Exception { configuration = JsonNodeFactory.instance.objectNode(); - configuration.put("exampleString", "something"); - configuration.put("exampleUri", "http://localhost:8080/myEndPoint"); + configuration.put("serviceUri", "http://localhost:8080/geoserver/ows"); + configuration.put("processID", "gs:StringConcatWPS"); } @Test diff --git a/taverna-gis-client/pom.xml b/taverna-gis-client/pom.xml index 54143cb..6829ef4 100644 --- a/taverna-gis-client/pom.xml +++ b/taverna-gis-client/pom.xml @@ -30,7 +30,7 @@ org.n52.wps 52n-wps-client-lib - 3.3.1 + 3.5.0 diff --git a/taverna-gis-client/src/main/java/org/apache/taverna/gis/client/GisClientFactory.java b/taverna-gis-client/src/main/java/org/apache/taverna/gis/client/GisClientFactory.java new file mode 100644 index 0000000..e9289bc --- /dev/null +++ b/taverna-gis-client/src/main/java/org/apache/taverna/gis/client/GisClientFactory.java @@ -0,0 +1,28 @@ +package org.apache.taverna.gis.client; + +import org.apache.taverna.gis.client.impl.NorthClientImpl; + +public class GisClientFactory { + + private static GisClientFactory instance = null; + + private GisClientFactory() + { + // private constructor + } + + public static GisClientFactory getInstance() + { + if (instance == null) + return new GisClientFactory(); + else + return instance; + + } + + public IGisClient getGisClient(String serviceURL) + { + return new NorthClientImpl(serviceURL); + } + +} diff --git a/taverna-gis-client/src/main/java/org/apache/taverna/gis/client/IGisClient.java b/taverna-gis-client/src/main/java/org/apache/taverna/gis/client/IGisClient.java new file mode 100644 index 0000000..9d044f3 --- /dev/null +++ b/taverna-gis-client/src/main/java/org/apache/taverna/gis/client/IGisClient.java @@ -0,0 +1,44 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.taverna.gis.client; + +import java.net.URI; +import java.util.HashMap; + +public interface IGisClient { + + // TODO: The interface is specific to WPS services. It should be more generic to handle different + // geospatial web services + + + /** + * @param serviceURI - the URI of the GWS that will return the capabilities + * @return + */ + public String GetServiceCapabilities(URI serviceURI); + + public HashMap GetProcessInputPorts(String processID); + + public HashMap GetProcessOutputPorts(String processID); + + + +} diff --git a/taverna-gis-client/src/main/java/org/apache/taverna/gis/client/impl/NorthClientImpl.java b/taverna-gis-client/src/main/java/org/apache/taverna/gis/client/impl/NorthClientImpl.java new file mode 100644 index 0000000..fb8a9b8 --- /dev/null +++ b/taverna-gis-client/src/main/java/org/apache/taverna/gis/client/impl/NorthClientImpl.java @@ -0,0 +1,139 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.taverna.gis.client.impl; + +import java.io.IOException; +import java.math.BigInteger; +import java.net.URI; +import java.util.HashMap; + +import org.apache.taverna.gis.client.IGisClient; +import org.n52.wps.client.WPSClientException; +import org.n52.wps.client.WPSClientSession; + +import net.opengis.ows.x11.LanguageStringType; +import net.opengis.wps.x100.CapabilitiesDocument; +import net.opengis.wps.x100.InputDescriptionType; +import net.opengis.wps.x100.OutputDescriptionType; +import net.opengis.wps.x100.ProcessDescriptionType; + +// TODO: Change name to a more descriptive one like GisServiceParser +public class NorthClientImpl implements IGisClient { + + private URI serviceURI = null; + + public NorthClientImpl(String serviceURL) { + this.serviceURI = URI.create(serviceURL); + } + + @Override + public String GetServiceCapabilities(URI serviceURI) { + WPSClientSession wpsClient = WPSClientSession.getInstance(); + + try { + wpsClient.connect(serviceURI.toString()); + } catch (WPSClientException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + CapabilitiesDocument capabilities = wpsClient.getWPSCaps(serviceURI.toString()); + + LanguageStringType[] serviceAbstract = capabilities.getCapabilities().getServiceIdentification() + .getTitleArray(); + // + // ProcessBriefType[] processList = capabilities.getCapabilities() + // .getProcessOfferings().getProcessArray(); + // + // for (ProcessBriefType process : processList) { + // System.out.println(process.getIdentifier().getStringValue()); + // } + // return capabilities; + if (serviceAbstract != null && serviceAbstract.length > 0) + return serviceAbstract[0].getStringValue(); + else + return null; + } + + @Override + public HashMap GetProcessInputPorts(String processID) { + HashMap inputPorts = new HashMap(); + + WPSClientSession wpsClient = WPSClientSession.getInstance(); + + ProcessDescriptionType processDescription = null; + + try { + processDescription = wpsClient.getProcessDescription(serviceURI.toString(), processID); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + if (processDescription==null) + return null; + + InputDescriptionType[] inputList = processDescription.getDataInputs().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); + + inputPorts.put(input.getIdentifier().getStringValue(), depth); + } + + return inputPorts; + + } + + @Override + public HashMap GetProcessOutputPorts(String processID) { + HashMap outputPorts = new HashMap(); + + WPSClientSession wpsClient = WPSClientSession.getInstance(); + + ProcessDescriptionType processDescription = null; + + try { + processDescription = wpsClient.getProcessDescription(serviceURI.toString(), processID); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + if (processDescription==null) + return null; + + OutputDescriptionType[] outputList = processDescription.getProcessOutputs().getOutputArray(); + + for (OutputDescriptionType output : outputList) { + + // TODO: Calculate output depth + int depth = 0; + + outputPorts.put(output.getIdentifier().getStringValue(), depth); + } + + return outputPorts; + } + +} diff --git a/taverna-gis-client/src/test/java/org/apache/taverna/gis/client/impl/NorthClientImplTest.java b/taverna-gis-client/src/test/java/org/apache/taverna/gis/client/impl/NorthClientImplTest.java new file mode 100644 index 0000000..31cc1d6 --- /dev/null +++ b/taverna-gis-client/src/test/java/org/apache/taverna/gis/client/impl/NorthClientImplTest.java @@ -0,0 +1,65 @@ +package org.apache.taverna.gis.client.impl; + +import static org.junit.Assert.*; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; + +import org.junit.Test; + +public class NorthClientImplTest { + + @Test + public void testGetServiceCapabilities() throws URISyntaxException { + + URI uri = new URI("http://localhost:8080/geoserver/ows"); + + String result = new NorthClientImpl(uri.toASCIIString()).GetServiceCapabilities(uri); + + assertEquals("Incorrect service title",result, "Prototype GeoServer WPS"); + + } + + @Test + public void testGetProcessInputPorts() throws URISyntaxException { + + URI uri = new URI("http://localhost:8080/geoserver/ows"); + + String processID = "gs:StringConcatWPS"; + + HashMap expectedInputResult = new HashMap(); + expectedInputResult.put("name", 0); + expectedInputResult.put("surname", 0); + + HashMap result = new NorthClientImpl(uri.toASCIIString()).GetProcessInputPorts(processID); + + assertEquals("Incorrect input ports result",result, expectedInputResult); + + } + + @Test + public void testGetProcessOutputPorts() throws URISyntaxException { + + URI uri = new URI("http://localhost:8080/geoserver/ows"); + + String processID = "gs:StringConcatWPS"; + + // check if the ports match + HashMap expectedOutputResult = new HashMap(); + expectedOutputResult.put("result", 0); + + HashMap result = new NorthClientImpl(uri.toASCIIString()).GetProcessOutputPorts(processID); + + // check if the ports do not match + assertEquals("Incorrect output ports result",result, expectedOutputResult); + + expectedOutputResult.clear(); + expectedOutputResult.put("result1", 0); + + assertNotEquals("The output ports result should not match", result, expectedOutputResult); + + } + + +}