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/06/08 12:40:45 UTC

[04/15] incubator-taverna-common-activities git commit: add a method that vallidate the cwl tool for Taverna

add a method that vallidate the cwl tool for Taverna


Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/commit/18c5155f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/tree/18c5155f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/diff/18c5155f

Branch: refs/heads/cwl-browse
Commit: 18c5155f380bc1e6e7d92b5b9dcadacff6f9da13
Parents: 6bb504e
Author: ThilinaManamgoda <ma...@gmail.com>
Authored: Sun May 29 03:23:35 2016 +0530
Committer: ThilinaManamgoda <ma...@gmail.com>
Committed: Sun May 29 03:23:35 2016 +0530

----------------------------------------------------------------------
 .../CWLFiles/binding-test.cwl                   |   1 -
 .../java/org/apache/taverna/cwl/ui/App.java     |  29 ------
 .../org/apache/taverna/cwl/ui/CWLParser.java    |  93 -----------------
 .../ui/serviceprovider/CwlServiceProvider.java  | 101 ++++++++++++++++++-
 .../taverna/cwl/ui/serviceprovider/Testing.java |  88 +++++++++++++---
 .../org/apache/taverna/cwl/CwlDumyActivity.java |  15 ++-
 6 files changed, 186 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/18c5155f/taverna-cwl-activity-ui/CWLFiles/binding-test.cwl
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity-ui/CWLFiles/binding-test.cwl b/taverna-cwl-activity-ui/CWLFiles/binding-test.cwl
index 2905c51..6906d71 100644
--- a/taverna-cwl-activity-ui/CWLFiles/binding-test.cwl
+++ b/taverna-cwl-activity-ui/CWLFiles/binding-test.cwl
@@ -5,7 +5,6 @@ cwlVersion: cwl:draft-3
 
 inputs:
   - id: reference
-    type: File
     inputBinding: { position: 2 }
 
   - id: reads

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/18c5155f/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/App.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/App.java b/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/App.java
deleted file mode 100644
index 4abf19f..0000000
--- a/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/App.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
- *  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.cwl.ui;
-
-/**
- * Hello world!
- *
- */
-public class App 
-{
-    public static void main( String[] args )
-    {
-        System.out.println( "Hello World!" );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/18c5155f/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/CWLParser.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/CWLParser.java b/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/CWLParser.java
deleted file mode 100644
index 1badefd..0000000
--- a/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/CWLParser.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*******************************************************************************
- *  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.cwl.ui;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.util.ArrayList;
-import java.util.Map;
-
-import org.yaml.snakeyaml.Yaml;
-
-
-public class CWLParser {
-
-	private File cwlFile;
-
-	private void setUpFile(File cwlFile) {
-
-		this.cwlFile = cwlFile;
-	}
-
-	private void readKeyWords() throws FileNotFoundException {
-
-		Yaml yaml = new Yaml();
-		Map contents = (Map) yaml.load(new FileInputStream(cwlFile));
-
-		for (Object key : contents.keySet()) {
-			if (key.equals("inputs"))
-				for (Object inputPairs : (ArrayList<String>) contents.get(key)) {
-					Map test = (Map) inputPairs;
-					System.out.println(inputPairs);
-
-					for (Object inputKey : test.keySet()) {
-						if (inputKey.equals("id"))
-							System.out.println(test.get(inputKey));
-						else if (inputKey.equals("type")) {
-							try {
-								Map inputType = (Map) test.get(inputKey);
-								for (Object inputTypekey : inputType.keySet()) {
-									if (inputTypekey.equals("inputBinding")) {
-										Map typeInputBinding = (Map) inputType.get(inputTypekey);
-										for (Object inputBindingKey : typeInputBinding.keySet()) {
-
-											System.out.println(
-													inputBindingKey + " " + typeInputBinding.get(inputBindingKey));
-										}
-									} else {
-										System.out.println(inputTypekey + " " + inputType.get(inputTypekey));
-									}
-								}
-							} catch (ClassCastException e) {
-								System.out.println(inputKey + " " + test.get(inputKey));
-							}
-						} else {
-							System.out.println(inputKey + " " + test.get(inputKey));
-						}
-
-					}
-
-				}
-		}
-
-	}
-
-	public static void main(String[] args) {
-		CWLParser cwlParser = new CWLParser();
-
-		cwlParser.setUpFile(new File("CWLFiles/binding-test.cwl"));
-
-		try {
-			cwlParser.readKeyWords();
-		} catch (FileNotFoundException e) {
-			e.printStackTrace();
-		}
-
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/18c5155f/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProvider.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProvider.java b/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProvider.java
index 44cdbdc..ec82630 100644
--- a/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProvider.java
+++ b/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProvider.java
@@ -21,11 +21,13 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FilenameFilter;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import javax.swing.Icon;
 
+import org.apache.taverna.cwl.Type;
 import org.yaml.snakeyaml.Yaml;
 
 import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider;
@@ -33,6 +35,18 @@ import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider;
 public class CwlServiceProvider implements ServiceDescriptionProvider {
 
 	private static final File cwlFilesLocation = new File("CWLFiles");
+	// CWLTYPES
+	private static final String FILE = "File";
+	private static final String INTEGER = "int";
+	private static final String DOUBLE = "double";
+	private static final String FLOAT = "float";
+	private static final String STRING = "string";
+
+	private static final String ITEMS = "items";
+	private static final String TYPE = "type";
+	private static final String ID = "id";
+	private static final String INPUTS = "inputs";
+	private static final String ARRAY = "array";
 
 	@Override
 	public void findServiceDescriptionsAsync(FindServiceDescriptionsCallBack callBack) {
@@ -41,10 +55,10 @@ public class CwlServiceProvider implements ServiceDescriptionProvider {
 		List<CwlServiceDesc> result = new ArrayList<CwlServiceDesc>();
 
 		File[] cwlFiles = getCwlFiles();
-		
+
 		// Load the CWL file using SnakeYaml lib
 		Yaml cwlReader = new Yaml();
-		
+
 		for (File file : cwlFiles) {
 			Map cwlFile = null;
 
@@ -68,6 +82,89 @@ public class CwlServiceProvider implements ServiceDescriptionProvider {
 
 	}
 
+	private HashMap<String, Type> processInputs(ArrayList<Map> inputs) {
+
+		HashMap<String, Type> result = new HashMap<>();
+
+		for (Map input : inputs) {
+
+			String Id = (String) input.get(ID);
+			// This require for nested type definitions
+			Map typeConfigurations;
+			// this object holds the type and if it's an array then type of the
+			// elements in the array
+			Type type = null;
+			try {
+				/*
+				 * This part will go through nested type definitions
+				 * 
+				 * type : type : array items : boolean
+				 * 
+				 */
+
+				typeConfigurations = (Map) input.get(TYPE);
+
+				// Check type is defined or not
+				if (typeConfigurations != null) {
+					type = new Type();
+					type.setType((String) typeConfigurations.get(TYPE));
+					type.setItems((String) typeConfigurations.get(ITEMS));
+
+				}
+
+			} catch (ClassCastException e) {
+				/*
+				 * This exception means type is described as single argument ex:
+				 * type : File
+				 */
+				type = new Type();
+				type.setType((String) input.get(TYPE));
+				type.setItems(null);
+			}
+			//when processing the inputs from the HashMap  type should be checked for is it null or not 
+				result.put(Id, type);
+		}
+		return result;
+	}
+
+	public boolean isTavernaCompatible(Map cwlFile) {
+
+	
+		/*
+		 * in this method cwl tool is verified whether it's compatible with
+		 * Taverna or not
+		 */
+		ArrayList<Map> inputs = (ArrayList<Map>) cwlFile.get(INPUTS);
+
+		if (inputs != null) {
+
+			HashMap<String, Type> processedinputs = processInputs(inputs);
+
+			for (String inputId : processedinputs.keySet()) {
+				Type type = processedinputs.get(inputId);
+				if (type != null)
+					if (type.getItems() == null) {
+						String inputType = type.getType();
+						if (!(inputType.equals(DOUBLE) || inputType.equals(FILE) || inputType.equals(FLOAT)
+								|| inputType.equals(INTEGER) || inputType.equals(STRING)))
+							return false;
+
+					} else {
+						if (type.getType().equals(ARRAY)) {
+							String inputType = type.getItems();
+							if (!(inputType.equals(DOUBLE) || inputType.equals(FILE) || inputType.equals(FLOAT)
+									|| inputType.equals(INTEGER) || inputType.equals(STRING)))
+								return false;
+
+						}
+					}
+				else return false;
+			}
+		}
+		return true;
+		
+	}
+
 	@Override
 	public Icon getIcon() {
 		// TODO Auto-generated method stub

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/18c5155f/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/Testing.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/Testing.java b/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/Testing.java
index 9a7a015..d6baf60 100644
--- a/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/Testing.java
+++ b/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/Testing.java
@@ -18,13 +18,21 @@ public class Testing {
 	private static final String ID = "id";
 	private static final String TYPE = "type";
 	private static final String ARRAY = "array";
-	private static final String FILE = "File";
 	private static final String ITEMS = "items";
-	static int i=0;
+	static int i = 0;
+
+	// CWLTYPES
+	private static final String FILE = "File";
+	private static final String INTEGER = "int";
+	private static final String DOUBLE = "double";
+	private static final String FLOAT = "float";
+	private static final String STRING = "string";
+
 	public static void main(String[] args) {
 		File[] cwlFiles = getCwlFiles();
 
 		for (File file : cwlFiles) {
+
 			Map cwlFile = null;
 			// Load the CWL file using SnakeYaml lib
 			Yaml cwlReader = new Yaml();
@@ -37,14 +45,53 @@ public class Testing {
 				// Creating the CWL configuration bean
 				CwlActivityConfigurationBean configurationBean = new CwlActivityConfigurationBean();
 				configurationBean.setCwlConfigurations(cwlFile);
-				getInputs(configurationBean);
+				// getInputs(configurationBean);
+				if (isTavernaCompatible(cwlFile))
+					System.out.println(file.getName().split("\\.")[0]);
 			}
 
 		}
 	}
 
+	public static boolean isTavernaCompatible(Map cwlFile) {
+
+		/*
+		 * in this method cwl tool is verified whether it's compatible with
+		 * Taverna or not
+		 */
+		ArrayList<Map> inputs = (ArrayList<Map>) cwlFile.get(INPUTS);
+
+		if (inputs != null) {
+
+			HashMap<String, Type> processedinputs = processInputs(inputs);
+
+			for (String inputId : processedinputs.keySet()) {
+				Type type = processedinputs.get(inputId);
+				if (type != null)
+					if (type.getItems() == null) {
+						String inputType = type.getType();
+						if (!(inputType.equals(DOUBLE) || inputType.equals(FILE) || inputType.equals(FLOAT)
+								|| inputType.equals(INTEGER) || inputType.equals(STRING)))
+							return false;
+
+					} else {
+						if (type.getType().equals(ARRAY)) {
+							String inputType = type.getItems();
+							if (!(inputType.equals(DOUBLE) || inputType.equals(FILE) || inputType.equals(FLOAT)
+									|| inputType.equals(INTEGER) || inputType.equals(STRING)))
+								return false;
+
+						}
+					}
+				else return false;
+			}
+		}
+		return true;
+
+	}
+
 	private static void getInputs(CwlActivityConfigurationBean configurationBean) {
-		
+
 		System.out.println(i);
 		i++;
 		Map cwlFile = configurationBean.getCwlConfigurations();
@@ -53,12 +100,14 @@ public class Testing {
 
 			if (mainKey.equals(INPUTS)) {
 				ArrayList<Map> arrayList = (ArrayList<Map>) cwlFile.get(mainKey);
-				
+
 				HashMap<String, Type> map = processInputs(arrayList);
-				for (String s:map.keySet()  ) {
-					if(map.get(s).getType().equals(FILE)) System.out.println("ID: "+s+" type : File");
-					
-					if(map.get(s).getType().equals(ARRAY)) System.out.println("ID :"+s+" type: Array items: "+map.get(s).getItems());
+				for (String s : map.keySet()) {
+					if (map.get(s).getType().equals(FILE))
+						System.out.println("ID: " + s + " type : File");
+
+					if (map.get(s).getType().equals(ARRAY))
+						System.out.println("ID :" + s + " type: Array items: " + map.get(s).getItems());
 				}
 			}
 		}
@@ -71,18 +120,31 @@ public class Testing {
 		for (Map input : inputs) {
 			String currentInputId = (String) input.get(ID);
 			Map typeConfigurations;
-			Type type = new Type();
+			Type type = null;
+
 			try {
+
 				typeConfigurations = (Map) input.get(TYPE);
-				type.setType((String) typeConfigurations.get(TYPE));
-				type.setItems((String) typeConfigurations.get(ITEMS));
+
+				if (typeConfigurations != null) {
+					type = new Type();
+					type.setType((String) typeConfigurations.get(TYPE));
+					type.setItems((String) typeConfigurations.get(ITEMS));
+				}
 			} catch (ClassCastException e) {
 				// This exception means type is described as single argument ex:
 				// type : File
-				type.setType((String)input.get(TYPE));
+
+				type = new Type();
+				type.setType((String) input.get(TYPE));
 				type.setItems(null);
+			} catch (NullPointerException e) {
+
+				System.out.println("No type is defined");
 			}
+
 			result.put(currentInputId, type);
+
 		}
 		return result;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/18c5155f/taverna-cwl-activity/src/main/java/org/apache/taverna/cwl/CwlDumyActivity.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity/src/main/java/org/apache/taverna/cwl/CwlDumyActivity.java b/taverna-cwl-activity/src/main/java/org/apache/taverna/cwl/CwlDumyActivity.java
index d7147cc..03944e0 100644
--- a/taverna-cwl-activity/src/main/java/org/apache/taverna/cwl/CwlDumyActivity.java
+++ b/taverna-cwl-activity/src/main/java/org/apache/taverna/cwl/CwlDumyActivity.java
@@ -33,15 +33,24 @@ public class CwlDumyActivity extends AbstractAsynchronousActivity<CwlActivityCon
 	private static final String ID = "id";
 	private static final String TYPE = "type";
 	private static final String ARRAY = "array";
-	private static final String FILE = "File";
-	private static final String ITEMS = "items";
 
+	private static final String ITEMS = "items";
+	
+	//CWLTYPES
+	private static final String FILE = "File";
+	private static final String INTEGER="int";
+	private static final String DOUBLE="double";
+	private static final String FLOAT="float";
+	private static final String STRING="string";
+	
 	@Override
 	public void configure(CwlActivityConfigurationBean arg0) throws ActivityConfigurationException {
 		removeInputs();
 		removeOutputs();
 
 	}
+	
+	
 
 	private void getInputs(CwlActivityConfigurationBean configurationBean) {
 
@@ -58,6 +67,7 @@ public class CwlDumyActivity extends AbstractAsynchronousActivity<CwlActivityCon
 			for (String inputId : processedInputs.keySet()) {
 				if (processedInputs.get(inputId).getType().equals(FILE))
 					System.out.println("ID: " + inputId + " type : File");
+				
 
 				if (processedInputs.get(inputId).getType().equals(ARRAY))
 					System.out.println(
@@ -106,7 +116,6 @@ public class CwlDumyActivity extends AbstractAsynchronousActivity<CwlActivityCon
 
 	@Override
 	public void executeAsynch(Map<String, T2Reference> arg0, AsynchronousActivityCallback arg1) {
-
 	}
 
 	@Override