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/21 12:59:32 UTC
[15/50] [abbrv] incubator-taverna-common-activities git commit: Java
Doc
Java Doc
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/acf9f485
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/tree/acf9f485
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/diff/acf9f485
Branch: refs/heads/cwl-browse
Commit: acf9f485ceaae75406a9f49e7b2a6a16cff9378b
Parents: 81518de
Author: ThilinaManamgoda <ma...@gmail.com>
Authored: Sat Jul 16 23:59:48 2016 +0530
Committer: ThilinaManamgoda <ma...@gmail.com>
Committed: Sat Jul 16 23:59:48 2016 +0530
----------------------------------------------------------------------
.../ui/serviceprovider/CwlServiceProvider.java | 96 +++++++++++---------
.../src/main/resources/CWLFiles/customtool1.cwl | 72 +++++++++++++++
.../resources/CWLFiles/customtoolrecord.cwl | 41 +++++++++
.../taverna/cwl/CwlActivityFactoryTest.java | 65 +++++++++++++
.../apache/taverna/cwl/utilities/CWLUtil.java | 51 +++++++++--
.../taverna/cwl/utilities/CWLUtilTest.java | 3 +-
6 files changed, 276 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/acf9f485/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 120e6d6..db99665 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
@@ -43,37 +43,35 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
-public class CwlServiceProvider extends AbstractConfigurableServiceProvider
- implements ConfigurableServiceProvider{
+public class CwlServiceProvider extends AbstractConfigurableServiceProvider implements ConfigurableServiceProvider {
+
+ public static final String TOOL_NAME = "toolName";
+ public static final String CWL_CONF = "cwl_conf";
+ public static final String CWL_PATH = "cwl_path";
+
+ public static final String DEFAULT_PATH_1 = "/usr/share/commonwl/";
+ public static final String DEFAULT_PATH_2 = "/usr/local/share/commonwl/";
+ public static final String DEFAULT_PATH_3 = "$HOME/.local/share/commonwl";
- public static final String TOOL_NAME="toolName";
- public static final String CWL_CONF ="cwl_conf";
- public static final String CWL_PATH ="cwl_path";
private static Logger logger = Logger.getLogger(CwlServiceProvider.class);
-
+
CwlServiceProvider() {
- super( defaultConfig());
+ super(getDefaultConfiguration());
}
private static final String providerName = "CWL Services";
- private static final URI providerId = CwlServiceDesc.ACTIVITY_TYPE.resolve("#provider");
-
-
+ private static final URI providerId = CwlServiceDesc.ACTIVITY_TYPE.resolve("#provider");
+
- private static Configuration defaultConfig() {
- Configuration c = new Configuration();
- ObjectNode conf = c.getJsonAsObjectNode();
- conf.put("path", "");
- return c;
- }
+
@Override
public void findServiceDescriptionsAsync(FindServiceDescriptionsCallBack callBack) {
- //TODO default and configurable provider
-
+ // TODO default and configurable provider
+
// get the location of the cwl tool from the workbench
Path path = getPath();
- //figure out the dots in the path ex: /maanadev/../cwltools
+ // figure out the dots in the path ex: /maanadev/../cwltools
Path normalizedPath = path.normalize();
DirectoryStream<Path> stream = null;
@@ -83,33 +81,33 @@ public class CwlServiceProvider extends AbstractConfigurableServiceProvider
logger.warn("Path is not correct !");
return;
}
- //create stream with parallel capabilities
+ // create stream with parallel capabilities
Stream<Path> paralleStream = StreamSupport.stream(stream.spliterator(), true);
-
+
paralleStream.forEach(p -> {
Yaml reader = getYamlReader();
-
- Map cwlFile;
- try (FileInputStream file =new FileInputStream(path.toFile())){
- cwlFile = (Map) reader.load(file);
- JsonNode config = createJsonNode(p,cwlFile);
- // Creating CWl service Description
- CwlServiceDesc cwlServiceDesc = createCWLDesc(config);
- // return the service description
- callBack.partialResults(Arrays.asList(cwlServiceDesc));
-
- } catch (IOException e) {
-
- logger.warn("File not Found !");
-
- }
-
-
+
+ Map cwlFile;
+ try (FileInputStream file = new FileInputStream(path.toFile())) {
+ cwlFile = (Map) reader.load(file);
+ JsonNode config = createJsonNode(p, cwlFile);
+ // Creating CWl service Description
+ CwlServiceDesc cwlServiceDesc = createCWLDesc(config);
+ // return the service description
+ callBack.partialResults(Arrays.asList(cwlServiceDesc));
+
+ } catch (IOException e) {
+
+ logger.warn("File not Found !");
+
+ }
+
});
callBack.finished();
}
+
private Path getPath() {
return Paths.get(getConfiguration().getJsonAsObjectNode().get("path").asText());
}
@@ -117,10 +115,10 @@ public class CwlServiceProvider extends AbstractConfigurableServiceProvider
private JsonNode createJsonNode(Path p, Map cwlFile) {
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.createObjectNode();
- JsonNode cwl_map =mapper.valueToTree(cwlFile);
- ((ObjectNode )root).put(TOOL_NAME,p.getFileName().toString().split("\\.")[0]);
- ((ObjectNode )root).put(CWL_CONF,cwl_map);
- ((ObjectNode )root).put(CWL_PATH,p.toString());
+ JsonNode cwl_map = mapper.valueToTree(cwlFile);
+ ((ObjectNode) root).put(TOOL_NAME, p.getFileName().toString().split("\\.")[0]);
+ ((ObjectNode) root).put(CWL_CONF, cwl_map);
+ ((ObjectNode) root).put(CWL_PATH, p.toString());
return root;
}
@@ -155,20 +153,32 @@ public class CwlServiceProvider extends AbstractConfigurableServiceProvider
Yaml reader = new Yaml();
return reader;
}
+
@Override
public ServiceDescriptionProvider newInstance() {
return new CwlServiceProvider();
}
+
@Override
public URI getType() {
return providerId;
}
+
@Override
public void setType(URI arg0) {
-
+
}
+
@Override
public boolean accept(Visitor arg0) {
return false;
}
+
+
+ private static Configuration getDefaultConfiguration() {
+ Configuration c = new Configuration();
+ ObjectNode conf = c.getJsonAsObjectNode();
+ conf.put("path", "");
+ return c;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/acf9f485/taverna-cwl-activity/src/main/resources/CWLFiles/customtool1.cwl
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity/src/main/resources/CWLFiles/customtool1.cwl b/taverna-cwl-activity/src/main/resources/CWLFiles/customtool1.cwl
new file mode 100644
index 0000000..cc36f02
--- /dev/null
+++ b/taverna-cwl-activity/src/main/resources/CWLFiles/customtool1.cwl
@@ -0,0 +1,72 @@
+################################################################################
+# 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.
+#################################################################################
+
+
+#!/usr/bin/env cwl-runner
+
+class: CommandLineTool
+cwlVersion: cwl:draft-3
+
+$namespaces:
+ edam: http://edamontology.org/
+
+inputs:
+ - id: input_1
+ type: int
+ label: input 1 testing label
+ description: this is a short description of input 1
+ format: edam:format_2323
+
+ - id: input_2
+ type:
+ type: array
+ items: int
+ label: input 2 testing label
+ description: this is a short description of input 2
+ format: $expression
+
+ - id: input_3
+ type: ["null",int]
+ label: input 3 testing label
+ description: this is a short description of input 3
+ format: noNameSpace:testing
+
+outputs:
+ - id: output_1
+ type: int
+ label: output 1 testing label
+ description: this is a short description of output 1
+ format: just a string
+
+ - id: ouput_2
+ type: String
+ label: output 2 testing label
+ description: this is a short description of output 2
+ format: ["edam:format_2323", just a string]
+
+label: This is a short description of the tool
+
+description: |
+ This is a much longer description of the tool. This can be displayed in
+ the service detail panel. A Command Line Tool is a non-interactive executable
+ program that reads some input, performs a computation, and terminates after
+ producing some output. Command line programs are a flexible unit of code sharing
+ and reuse, unfortunately the syntax and input/output semantics among command
+ line programs is extremely heterogeneous. A common layer for describing the
+ syntax and semantics of programs can reduce this incidental complexity by providing a consistent way to connect programs together.
+
+basecommand: echo
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/acf9f485/taverna-cwl-activity/src/main/resources/CWLFiles/customtoolrecord.cwl
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity/src/main/resources/CWLFiles/customtoolrecord.cwl b/taverna-cwl-activity/src/main/resources/CWLFiles/customtoolrecord.cwl
new file mode 100644
index 0000000..f008bdb
--- /dev/null
+++ b/taverna-cwl-activity/src/main/resources/CWLFiles/customtoolrecord.cwl
@@ -0,0 +1,41 @@
+################################################################################
+# 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.
+#################################################################################
+
+#!/usr/bin/env cwl-runner
+
+class: CommandLineTool
+cwlVersion: cwl:draft-3
+
+inputs:
+ - id: input_1
+ type: record
+
+ - id: input_2
+ type:
+ type: array
+ items: int
+ - id: input_3
+ type: String
+
+outputs:
+ - id: output_1
+ type: int
+
+ - id: ouput_2
+ type: String
+
+basecommand: echo
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/acf9f485/taverna-cwl-activity/src/main/test/java/org/apache/taverna/cwl/CwlActivityFactoryTest.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity/src/main/test/java/org/apache/taverna/cwl/CwlActivityFactoryTest.java b/taverna-cwl-activity/src/main/test/java/org/apache/taverna/cwl/CwlActivityFactoryTest.java
new file mode 100644
index 0000000..8c87b2a
--- /dev/null
+++ b/taverna-cwl-activity/src/main/test/java/org/apache/taverna/cwl/CwlActivityFactoryTest.java
@@ -0,0 +1,65 @@
+package org.apache.taverna.cwl;
+
+
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.cwl.utilities.CWLUtilTest;
+import org.apache.taverna.workflowmodel.processor.activity.ActivityConfigurationException;
+import org.junit.Before;
+import org.junit.Test;
+import org.yaml.snakeyaml.Yaml;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class CwlActivityFactoryTest {
+ private static Logger logger = Logger.getLogger(CwlActivityFactoryTest.class);
+ CwlActivityFactory cwlActivityFactory;
+ public static final String CWL_CONF = "cwl_conf";
+ private JsonNode root;
+
+ @Before
+ public void setUp() throws Exception {
+ System.out.println("1");
+ cwlActivityFactory = new CwlActivityFactory();
+ Yaml reader = new Yaml();
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectNode cwlFile = null;
+ try {
+ cwlFile = mapper.valueToTree(reader.load(new FileInputStream(getClass().getResource("/CWLFiles/customtool1.cwl").getPath())));
+ } catch (IllegalArgumentException | FileNotFoundException e) {
+ System.out.println(e);
+ }
+
+ root =mapper.createObjectNode();
+ ((ObjectNode) root).put(CWL_CONF, cwlFile);
+ }
+
+ @Test
+ public void testSchemaJson() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ try {
+ assertEquals(cwlActivityFactory.getActivityConfigurationSchema(), objectMapper.readTree(getClass().getResource("/schema.json")));
+ } catch (IOException e) {
+ logger.error(e);
+ }
+
+ }
+ @Test
+ public void testgetInputPorts() {
+
+// try {
+// cwlActivityFactory.getInputPorts(root);
+// } catch (ActivityConfigurationException e) {
+// logger.error(e);
+//
+// }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/acf9f485/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/CWLUtil.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/CWLUtil.java b/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/CWLUtil.java
index 7764fd5..8042d40 100644
--- a/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/CWLUtil.java
+++ b/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/CWLUtil.java
@@ -42,7 +42,10 @@ public class CWLUtil {
public JsonNode getNameSpace() {
return nameSpace;
}
-
+/**
+ * This method is processing the CWL NameSpace for later use
+ * such as figuring out the Format of a input or output
+ */
public void processNameSpace() {
if (cwlFile.has("$namespaces")) {
@@ -66,7 +69,11 @@ public class CWLUtil {
public Map<String, PortDetail> processOutputDetails() {
return processdetails(cwlFile.get(OUTPUTS));
}
-
+/**
+ * This method will go through CWL tool input or out puts and figure outs their IDs and the respective depths
+ * @param inputs This is JsonNode object which contains the Inputs or outputs of the respective CWL tool
+ * @return This the respective, ID and the depth of the input or output
+ */
public Map<String, Integer> process(JsonNode inputs) {
Map<String, Integer> result = new HashMap<>();
@@ -117,7 +124,12 @@ public class CWLUtil {
}
return result;
}
-
+/**
+ * This method is used for extracting details of the CWL tool inputs or outputs.
+ * ex:Lable, Format, Description
+ * @param inputs This is JsonNode object which contains the Inputs or outputs of the respective CWL tool
+ * @return
+ */
private Map<String, PortDetail> processdetails(JsonNode inputs) {
Map<String, PortDetail> result = new HashMap<>();
@@ -144,7 +156,11 @@ public class CWLUtil {
}
return result;
}
-
+/**
+ * This method is used for extracting the Label of a CWL input or Output
+ * @param input Single CWL input or output as a JsonNode
+ * @param detail respective PortDetail Object to hold the extracted Label
+ */
public void extractLabel(JsonNode input, PortDetail detail) {
if (input != null)
if (input.has(LABEL)) {
@@ -153,7 +169,11 @@ public class CWLUtil {
detail.setLabel(null);
}
}
-
+/**
+ *
+ * @param input Single CWL input or output as a JsonNode
+ * @param detail respective PortDetail Object to hold the extracted Label
+ */
public void extractDescription(JsonNode input, PortDetail detail) {
if (input != null)
if (input.has(DESCRIPTION)) {
@@ -162,7 +182,12 @@ public class CWLUtil {
detail.setDescription(null);
}
}
-
+/**
+ * This method is used for extracting the Formats of a CWL input or Output
+ * Single argument(Input or Output) can have multiple Formats.
+ * @param input Single CWL input or output as a JsonNode
+ * @param detail respective PortDetail Object to hold the extracted Label
+ */
public void extractFormat(JsonNode input, PortDetail detail) {
if (input != null)
if (input.has(FORMAT)) {
@@ -183,7 +208,13 @@ public class CWLUtil {
}
}
-
+/**
+ * Re Format the CWL format using the NameSpace in CWL Tool if possible otherwise it doesn't change the current
+ * nameSpace => edam:http://edam.org
+ * format : edam :1245 => http://edamontology.org/1245
+ * @param formatInfoString Single Format
+ * @param detail respective PortDetail Object to hold the extracted Label
+ */
public void figureOutFormats(String formatInfoString, PortDetail detail) {
if (formatInfoString.startsWith("$")) {
@@ -204,7 +235,11 @@ public class CWLUtil {
detail.addFormat(formatInfoString);
}
}
-
+/**
+ * This method is used to check whether the input/output is valid CWL TYPE when the type is represented as type: ["null","int"]
+ * @param typeConfigurations Type of the CWl input or output
+ * @return
+ */
public boolean isValidDataType(JsonNode typeConfigurations) {
for (JsonNode type : typeConfigurations) {
if (!( type.asText().equals(FLOAT) || type.asText().equals(NULL) || type.asText().equals(BOOLEAN)
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/acf9f485/taverna-cwl-utilities/src/test/java/org/apache/taverna/cwl/utilities/CWLUtilTest.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-utilities/src/test/java/org/apache/taverna/cwl/utilities/CWLUtilTest.java b/taverna-cwl-utilities/src/test/java/org/apache/taverna/cwl/utilities/CWLUtilTest.java
index 832655a..8a94747 100644
--- a/taverna-cwl-utilities/src/test/java/org/apache/taverna/cwl/utilities/CWLUtilTest.java
+++ b/taverna-cwl-utilities/src/test/java/org/apache/taverna/cwl/utilities/CWLUtilTest.java
@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
+
import org.junit.Before;
import org.junit.Test;
import org.yaml.snakeyaml.Yaml;
@@ -41,7 +42,7 @@ public class CWLUtilTest {
Yaml reader = new Yaml();
ObjectMapper mapper = new ObjectMapper();
cwlFile = mapper.valueToTree(reader.load(new FileInputStream(CWLUtilTest.class.getResource("/CWLFiles/customtool1.cwl").getPath())));
-
+
cwlUtil = new CWLUtil(cwlFile);
input = cwlFile.get("inputs").get(0);
}