Add GisClient implementation

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/acda22af
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/tree/acda22af
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/diff/acda22af

Branch: refs/heads/taverna2
Commit: acda22afcb128a69297ab4be58ffb9067a31abab
Parents: 5ff7921
Author: edikaradumi <[email protected]>
Authored: Wed Jul 20 23:45:56 2016 +0100
Committer: edikaradumi <[email protected]>
Committed: Wed Jul 20 23:45:56 2016 +0100

----------------------------------------------------------------------
 .../taverna/gis/client/GisClientFactory.java    |  28 +++
 .../apache/taverna/gis/client/IGisClient.java   |  49 +++++
 .../gis/client/impl/GisClientNorthImpl.java     | 220 +++++++++++++++++++
 .../taverna/gis/client/impl/TypeDescriptor.java |  40 ++++
 4 files changed, 337 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/acda22af/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/GisClientFactory.java
----------------------------------------------------------------------
diff --git 
a/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/GisClientFactory.java
 
b/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/GisClientFactory.java
new file mode 100644
index 0000000..1e62c5a
--- /dev/null
+++ 
b/apache-taverna-plugin-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.GisClientNorthImpl;
+
+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 GisClientNorthImpl(serviceURL);
+       }
+       
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/acda22af/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
new file mode 100644
index 0000000..f0356de
--- /dev/null
+++ 
b/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/IGisClient.java
@@ -0,0 +1,49 @@
+/*
+ *
+ * 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;
+import java.util.List;
+
+import org.apache.taverna.gis.client.impl.TypeDescriptor;
+
+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<String, Integer> GetProcessInputPorts(String processID);
+       
+       public HashMap<String, Integer> GetProcessOutputPorts(String processID);
+       
+       public List<TypeDescriptor> getTaverna2InputPorts(String processID);
+       
+       public List<TypeDescriptor> getTaverna2OutputPorts(String processID);
+       
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/acda22af/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
new file mode 100644
index 0000000..485a119
--- /dev/null
+++ 
b/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/GisClientNorthImpl.java
@@ -0,0 +1,220 @@
+/*
+ *
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+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.ProcessDescriptionType;
+
+// TODO: Change name to a more descriptive one like GisServiceParser
+public class GisClientNorthImpl implements IGisClient {
+
+       private URI serviceURI = null;
+
+       private WPSClientSession wpsClient;
+       
+       public GisClientNorthImpl(String serviceURL) {
+               this.serviceURI = URI.create(serviceURL);
+               wpsClient = WPSClientSession.getInstance();
+       }
+       
+       @Override
+       public String GetServiceCapabilities(URI serviceURI) {
+               
+               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<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 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<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 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;
+       }
+       
+       public List<TypeDescriptor> getTaverna2InputPorts(String processID)
+       {
+        
+               List<TypeDescriptor> inputPorts = new 
ArrayList<TypeDescriptor>();
+               
+               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) {
+                       TypeDescriptor myNewInputPort = new TypeDescriptor();
+                       
+                       
myNewInputPort.setName(input.getIdentifier().getStringValue());
+                       myNewInputPort.setDepth(getInputPortDepth(input));
+                       myNewInputPort.setAllowLiteralValues(true);
+                       myNewInputPort.setHandledReferenceSchemes(null); // is 
not used in Taverna
+                       myNewInputPort.setTranslatedElementType(String.class);
+                       
+                       inputPorts.add(myNewInputPort);
+               }
+       
+               return inputPorts;
+       }
+
+       /**
+        * @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;
+       }
+
+       @Override
+       public List<TypeDescriptor> getTaverna2OutputPorts(String processID) {
+               List<TypeDescriptor> outputPorts = new 
ArrayList<TypeDescriptor>();
+
+               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) {
+                       TypeDescriptor myNewOutputPort = new TypeDescriptor();
+
+                       
myNewOutputPort.setName(output.getIdentifier().getStringValue());
+                       myNewOutputPort.setDepth(0); // output port depth is 
always 1
+                       
+                       outputPorts.add(myNewOutputPort);
+               }
+
+               return outputPorts;
+       }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/acda22af/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/TypeDescriptor.java
----------------------------------------------------------------------
diff --git 
a/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/TypeDescriptor.java
 
b/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/TypeDescriptor.java
new file mode 100644
index 0000000..d9fb8f6
--- /dev/null
+++ 
b/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/TypeDescriptor.java
@@ -0,0 +1,40 @@
+package org.apache.taverna.gis.client.impl;
+
+public class TypeDescriptor {
+       private String name;
+       private Integer depth;
+       private boolean allowLiteralValues;
+       private String handledReferenceSchemes;
+       private Class<?> translatedElementType;
+       public String getName() {
+               return name;
+       }
+       public void setName(String name) {
+               this.name = name;
+       }
+       public Integer getDepth() {
+               return depth;
+       }
+       public void setDepth(Integer depth) {
+               this.depth = depth;
+       }
+       public boolean isAllowLiteralValues() {
+               return allowLiteralValues;
+       }
+       public void setAllowLiteralValues(boolean allowLiteralValues) {
+               this.allowLiteralValues = allowLiteralValues;
+       }
+       public String getHandledReferenceSchemes() {
+               return handledReferenceSchemes;
+       }
+       public void setHandledReferenceSchemes(String handledReferenceSchemes) {
+               this.handledReferenceSchemes = handledReferenceSchemes;
+       }
+       public Class<?> getTranslatedElementType() {
+               return translatedElementType;
+       }
+       public void setTranslatedElementType(Class<?> translatedElementType) {
+               this.translatedElementType = translatedElementType;
+       }
+       
+}

Reply via email to