Improve service discovery
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/dafb2793 Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/tree/dafb2793 Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/diff/dafb2793 Branch: refs/heads/taverna2 Commit: dafb279336d3693e3d93eb86171d98d76f5dcf4f Parents: cd049a2 Author: edikaradumi <[email protected]> Authored: Wed Aug 3 05:35:40 2016 +0100 Committer: edikaradumi <[email protected]> Committed: Wed Aug 3 05:35:40 2016 +0100 ---------------------------------------------------------------------- .../ui/serviceprovider/GisServiceProvider.java | 193 ++++++++++--------- .../GisServiceProviderConfig.java | 23 ++- .../gis/client/impl/GisClientNorthImpl.java | 55 +++--- 3 files changed, 154 insertions(+), 117 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/dafb2793/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 e53cfec..e63f069 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 @@ -6,14 +6,15 @@ import java.util.Arrays; import java.util.List; import javax.swing.Icon; +import javax.swing.JOptionPane; +import org.apache.log4j.Logger; import org.apache.taverna.gis.client.*; import org.apache.taverna.gis.client.impl.TypeDescriptor; import net.sf.taverna.t2.servicedescriptions.AbstractConfigurableServiceProvider; import net.sf.taverna.t2.servicedescriptions.ConfigurableServiceProvider; import net.sf.taverna.t2.servicedescriptions.CustomizedConfigurePanelProvider; -import net.sf.taverna.t2.servicedescriptions.ServiceDescription; import net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityInputPortDefinitionBean; import net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityOutputPortDefinitionBean; @@ -22,83 +23,100 @@ public class GisServiceProvider extends AbstractConfigurableServiceProvider<GisS CustomizedConfigurePanelProvider<GisServiceProviderConfig> { public GisServiceProvider() { - super(new GisServiceProviderConfig()); + super(new GisServiceProviderConfig("", new ArrayList<String>())); } private static final URI providerId = URI .create("http://cs.man.ac.uk/2016/service-provider/apache-taverna2-plugin-gis"); - + + private Logger logger = Logger.getLogger(AddGisServiceDialog.class); + + /** * 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"); - - List<ServiceDescription> results = new ArrayList<ServiceDescription>(); - - GisServiceDesc service = new GisServiceDesc(); - // Populate the service description bean - service.setOgcServiceUri(getConfiguration().getOgcServiceUri()); - service.setProcessIdentifier(getConfiguration().getProcessIdentifier()); - // TODO: Optional: set description (Set a better description - service.setDescription(getConfiguration().getProcessIdentifier()); + URI serviceURI = serviceProviderConfig.getOgcServiceUri(); - // Get input ports + callBack.status("Resolving service: " + serviceURI); + List<GisServiceDesc> results = new ArrayList<GisServiceDesc>(); + IGisClient gisServiceClient = GisClientFactory.getInstance().getGisClient(getConfiguration().getOgcServiceUri().toASCIIString()); + List<String> processIdentifiers = serviceProviderConfig.getProcessIdentifiers(); + try { - List<TypeDescriptor> inputList = gisServiceClient.getTaverna2InputPorts(getConfiguration().getProcessIdentifier()); - - List<ActivityInputPortDefinitionBean> inputPortDefinitions = new ArrayList<ActivityInputPortDefinitionBean>(); - - for (TypeDescriptor 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); - - - // Get output ports - - List<TypeDescriptor> outputList = gisServiceClient.getTaverna2OutputPorts(getConfiguration().getProcessIdentifier()); - List<ActivityOutputPortDefinitionBean> outputPortDefinitions = new ArrayList<ActivityOutputPortDefinitionBean>(); - - for( TypeDescriptor output : outputList ) - { - ActivityOutputPortDefinitionBean newOutputPort = new ActivityOutputPortDefinitionBean(); - newOutputPort.setName(output.getName()); - newOutputPort.setDepth(output.getDepth()); - - outputPortDefinitions.add(newOutputPort); - - } + for (String processID : processIdentifiers) + { + GisServiceDesc service = new GisServiceDesc(); + + // Populate the service description bean + service.setOgcServiceUri(getConfiguration().getOgcServiceUri()); + service.setProcessIdentifier(processID); - service.setOutputPortDefinitions(outputPortDefinitions); - - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + // TODO: Optional: set description (Set a better description) + service.setDescription(processID); + + // Get input ports + List<TypeDescriptor> inputList = gisServiceClient.getTaverna2InputPorts(processID); + + List<ActivityInputPortDefinitionBean> inputPortDefinitions = new ArrayList<ActivityInputPortDefinitionBean>(); + + for (TypeDescriptor 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); + + // Get output ports + + List<TypeDescriptor> outputList = gisServiceClient.getTaverna2OutputPorts(processID); + List<ActivityOutputPortDefinitionBean> outputPortDefinitions = new ArrayList<ActivityOutputPortDefinitionBean>(); + + for( TypeDescriptor output : outputList ) + { + ActivityOutputPortDefinitionBean newOutputPort = new ActivityOutputPortDefinitionBean(); + newOutputPort.setName(output.getName()); + newOutputPort.setDepth(output.getDepth()); + + outputPortDefinitions.add(newOutputPort); + + } + + service.setOutputPortDefinitions(outputPortDefinitions); + + results.add(service); + + // partialResults() can also be called several times from inside + // for-loop if the full search takes a long time + callBack.partialResults(results); + + } + + } catch (Exception ex) { + JOptionPane.showMessageDialog(null, + "Could not read the service definition from " + + serviceURI + ":\n" + ex, + "Could not add service service", + JOptionPane.ERROR_MESSAGE); + + logger.error( + "Failed to list GWS processes for service: " + + serviceURI, ex); } - results.add(service); - - // partialResults() can also be called several times from inside - // for-loop if the full search takes a long time - callBack.partialResults(results); - // No more results will be coming callBack.finished(); } @@ -120,7 +138,7 @@ public class GisServiceProvider extends AbstractConfigurableServiceProvider<GisS @Override public String toString() { - return "Geospatial Web Services " + getConfiguration().getProcessIdentifier(); + return "Geospatial Web Services " + getConfiguration().getOgcServiceUri(); } public String getId() { @@ -129,49 +147,52 @@ public class GisServiceProvider extends AbstractConfigurableServiceProvider<GisS @Override protected List<? extends Object> getIdentifyingData() { - return Arrays.asList(getConfiguration().getOgcServiceUri(), getConfiguration().getProcessIdentifier()); + List<String> result = new ArrayList<String>(); + + List<String> processIdentifiers = getConfiguration().getProcessIdentifiers(); + + for (String processID : processIdentifiers) + { + result.add(getConfiguration().getOgcServiceUri() + processID); + + } + + //return Arrays.asList(getConfiguration().getOgcServiceUri(), getConfiguration().getProcessIdentifier()); + //return Arrays.asList(getConfiguration().getOgcServiceUri()); + return result; + } @Override public List<GisServiceProviderConfig> getDefaultConfigurations(){ - GisServiceProviderConfig myConfig = new GisServiceProviderConfig(); + List<GisServiceProviderConfig> myDefaultConfigs = new ArrayList<GisServiceProviderConfig>(); - myConfig.setOgcServiceUri(URI.create("http://localhost:8080/geoserver/ows")); - myConfig.setProcessIdentifier("gs:StringConcatWPS"); - - return Arrays.asList(myConfig); + myDefaultConfigs.add(new GisServiceProviderConfig("http://localhost:8080/geoserver/ows", + Arrays.asList("gs:StringConcatWPS"))); + return myDefaultConfigs; } @Override public void createCustomizedConfigurePanel( - net.sf.taverna.t2.servicedescriptions.CustomizedConfigurePanelProvider.CustomizedConfigureCallBack<GisServiceProviderConfig> callBack) { + final net.sf.taverna.t2.servicedescriptions.CustomizedConfigurePanelProvider.CustomizedConfigureCallBack<GisServiceProviderConfig> callBack) { + @SuppressWarnings("serial") + AddGisServiceDialog addGISServiceDialog = new AddGisServiceDialog(null) { - AddGisServiceDialog addGISServiceDialog = new AddGisServiceDialog(null); + @Override + protected void addRegistry(String serviceURL, List<String> processIdentifiers) { + GisServiceProviderConfig providerConfig = new GisServiceProviderConfig(serviceURL, processIdentifiers); + callBack.newProviderConfiguration(providerConfig); + + } + + }; addGISServiceDialog.setVisible(true); -// -// -// // Possible choices for drop-down box -// URI[] uris = new URI[3]; -// uris[0] = URI.create("http://example.com/serviceA"); -// uris[1] = URI.create("http://example.com/serviceB"); -// uris[2] = URI.create("http://example.com/serviceC"); -// -// // Dialogue with drop-down -// String message = "Choose the example service URI"; -// String title = "Which service?"; -// Object uri = JOptionPane.showInputDialog(null, message, title, -// JOptionPane.PLAIN_MESSAGE, null, uris, uris[0]); -// -// // Return a new provider configuration -// GisServiceProviderConfig config = new GisServiceProviderConfig(); -// config.setOgcServiceUri((URI) uri); -// callBack.newProviderConfiguration(config); } http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/dafb2793/apache-taverna-plugin-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceProviderConfig.java ---------------------------------------------------------------------- diff --git a/apache-taverna-plugin-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceProviderConfig.java b/apache-taverna-plugin-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceProviderConfig.java index 32cbfcb..ca85f87 100644 --- a/apache-taverna-plugin-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceProviderConfig.java +++ b/apache-taverna-plugin-gis-activity-ui/src/main/java/org/apache/taverna/gis/ui/serviceprovider/GisServiceProviderConfig.java @@ -1,13 +1,24 @@ package org.apache.taverna.gis.ui.serviceprovider; import java.net.URI; +import java.util.Arrays; +import java.util.List; import net.sf.taverna.t2.lang.beans.PropertyAnnotated; import net.sf.taverna.t2.lang.beans.PropertyAnnotation; public class GisServiceProviderConfig extends PropertyAnnotated { - private URI ogcServiceUri = URI.create("http://localhost:8080/geoserver/ows"); - private String processIdentifier = "gs:StringConcatWPS"; + private URI ogcServiceUri = URI.create(""); + private List<String> processIdentifiers = Arrays.asList(""); + + public GisServiceProviderConfig() { + + } + + public GisServiceProviderConfig(String serviceURL, List<String> processIdentifiers ) { + this.ogcServiceUri = URI.create(serviceURL); + this.processIdentifiers = processIdentifiers; + } @PropertyAnnotation(displayName="OGC Web Service URI", preferred=true) public URI getOgcServiceUri() { @@ -18,11 +29,11 @@ public class GisServiceProviderConfig extends PropertyAnnotated { } @PropertyAnnotation(displayName="Process Identifier") - public String getProcessIdentifier() { - return processIdentifier; + public List<String> getProcessIdentifiers() { + return processIdentifiers; } - public void setProcessIdentifier(String processIdentifier) { - this.processIdentifier = processIdentifier; + public void setProcessIdentifiers(List<String> processIdentifiers) { + this.processIdentifiers = processIdentifiers; } } http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/dafb2793/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 ed92332..84c85c3 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 @@ -27,25 +27,25 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import org.apache.log4j.Logger; import org.apache.taverna.gis.client.IGisClient; import org.n52.wps.client.WPSClientException; import org.n52.wps.client.WPSClientSession; -import com.google.common.util.concurrent.UncaughtExceptionHandlers; - 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.ProcessBriefType; import net.opengis.wps.x100.ProcessDescriptionType; +import net.opengis.wps.x100.ProcessDescriptionType.DataInputs; import net.opengis.wps.x100.WPSCapabilitiesType; -// TODO: Change name to a more descriptive one like GisServiceParser public class GisClientNorthImpl implements IGisClient { + private Logger logger = Logger.getLogger(GisClientNorthImpl.class); + private URI serviceURI = null; - private WPSClientSession wpsClient; public GisClientNorthImpl(String serviceURL) { @@ -54,9 +54,8 @@ public class GisClientNorthImpl implements IGisClient { try { wpsClient.connect(serviceURI.toString()); - } catch (WPSClientException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (WPSClientException ex) { + logger.error("Failed to connect to service: " + serviceURI, ex); } } @@ -83,15 +82,19 @@ public class GisClientNorthImpl implements IGisClient { try { processDescription = wpsClient.getProcessDescription(serviceURI.toString(), processID); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (IOException ex) { + logger.error("Failed to list input ports for process: " + processID, ex); } if (processDescription==null) - return null; + return inputPorts; + + DataInputs dataInputs = processDescription.getDataInputs(); - InputDescriptionType[] inputList = processDescription.getDataInputs().getInputArray(); + if (dataInputs == null) + return inputPorts; + + InputDescriptionType[] inputList = dataInputs.getInputArray(); for (InputDescriptionType input : inputList) { @@ -113,13 +116,12 @@ public class GisClientNorthImpl implements IGisClient { try { processDescription = wpsClient.getProcessDescription(serviceURI.toString(), processID); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (IOException ex) { + logger.error("Failed to list processe output port for process: " + processID, ex); } if (processDescription==null) - return null; + return outputPorts; OutputDescriptionType[] outputList = processDescription.getProcessOutputs().getOutputArray(); @@ -143,15 +145,19 @@ public class GisClientNorthImpl implements IGisClient { try { processDescription = wpsClient.getProcessDescription(serviceURI.toString(), processID); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (IOException ex) { + logger.error("Failed to get process description for process: " + processID, ex); } if (processDescription==null) - return null; + return inputPorts; - InputDescriptionType[] inputList = processDescription.getDataInputs().getInputArray(); + DataInputs dataInputs = processDescription.getDataInputs(); + + if (dataInputs == null) + return inputPorts; + + InputDescriptionType[] inputList = dataInputs.getInputArray(); for (InputDescriptionType input : inputList) { TypeDescriptor myNewInputPort = new TypeDescriptor(); @@ -191,13 +197,12 @@ public class GisClientNorthImpl implements IGisClient { try { processDescription = wpsClient.getProcessDescription(serviceURI.toString(), processID); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (IOException ex) { + logger.error("Failed to list output ports for process: " + processID, ex); } if (processDescription == null) - return null; + return outputPorts; OutputDescriptionType[] outputList = processDescription.getProcessOutputs().getOutputArray();
