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 2015/06/11 18:35:43 UTC
[24/31] incubator-taverna-language git commit: Package updated
Package updated
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/commit/7fea7108
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/tree/7fea7108
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/diff/7fea7108
Branch: refs/heads/master
Commit: 7fea710801088662588afbb3630c43c5fb3e6b8e
Parents: 3d6285d
Author: Menaka Madushanka <me...@gmail.com>
Authored: Thu Jun 11 21:11:11 2015 +0530
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Jun 11 17:33:29 2015 +0100
----------------------------------------------------------------------
.../apache/taverna/tavlang/CommandLineTool.java | 276 +++++++++++++++++
.../taverna/tavlang/TavernaCommandline.java | 29 ++
.../org/apache/taverna/tavlang/tools/Tools.java | 89 ++++++
.../tavlang/tools/convert/Scufl2Convert.java | 190 ++++++++++++
.../taverna/tavlang/tools/convert/ToJson.java | 310 +++++++++++++++++++
.../tavlang/tools/convert/ToRobundle.java | 68 ++++
.../tavlang/tools/inspect/ProcessorNames.java | 169 ++++++++++
.../tavlang/tools/inspect/ServiceTypes.java | 111 +++++++
.../tavlang/tools/validate/Validate.java | 38 +++
.../tavlang/commandline/CommandLineTool.java | 276 -----------------
.../tavlang/commandline/TavernaCommandline.java | 29 --
.../apache/tavlang/commandline/tools/Tools.java | 89 ------
.../tools/convert/Scufl2Convert.java | 190 ------------
.../commandline/tools/convert/ToJson.java | 310 -------------------
.../commandline/tools/convert/ToRobundle.java | 68 ----
.../tools/inspect/ProcessorNames.java | 169 ----------
.../commandline/tools/inspect/ServiceTypes.java | 111 -------
.../commandline/tools/validate/Validate.java | 38 ---
.../taverna/tavlang/test/CommandLineTest.java | 57 ++++
.../taverna/tavlang/test/Scufl2ConvertTest.java | 14 +
.../commandline/test/CommandLineTest.java | 57 ----
.../commandline/test/Scufl2ConvertTest.java | 14 -
22 files changed, 1351 insertions(+), 1351 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/CommandLineTool.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/CommandLineTool.java b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/CommandLineTool.java
new file mode 100644
index 0000000..57ee3cb
--- /dev/null
+++ b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/CommandLineTool.java
@@ -0,0 +1,276 @@
+package org.apache.taverna.tavlang;
+
+
+/*
+ * 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.
+ */
+
+
+import io.airlift.airline.Arguments;
+import io.airlift.airline.Cli;
+import io.airlift.airline.Cli.CliBuilder;
+import io.airlift.airline.Command;
+import io.airlift.airline.Help;
+import io.airlift.airline.Option;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.xml.bind.JAXBException;
+
+import org.apache.taverna.scufl2.api.io.ReaderException;
+import org.apache.taverna.tavlang.tools.Tools;
+import org.apache.taverna.tavlang.tools.Tools.ConvertionTools;
+import org.apache.taverna.tavlang.tools.convert.Scufl2Convert;
+import org.apache.taverna.tavlang.tools.convert.ToRobundle;
+import org.apache.taverna.tavlang.tools.inspect.ProcessorNames;
+import org.apache.taverna.tavlang.tools.inspect.ServiceTypes;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Lists;
+
+
+/*
+ * The command line options for convert, validate and inspect workflows.
+ * Use the airlift/airline library
+ * */
+
+public class CommandLineTool {
+
+ private Cli<TvnLangTool> parser(){
+ CliBuilder<TvnLangTool> build = Cli.<TvnLangTool>builder("tavlang")
+ .withDescription("Convert, manage workflows")
+ .withDefaultCommand(HelpCommand.class)
+ .withCommand(CommandConvert.class)
+ .withCommand(HelpCommand.class)
+ .withCommand(CommandInspect.class)
+ .withCommand(CommandValidate.class)
+ .withCommand(CommandVersion.class);
+
+ return build.build();
+ }
+
+ public CommandLineTool(){};
+ public void parse(String... args)
+ {
+ System.out.println("$ tavlang " + Joiner.on(" ").join(args));
+ TvnLangTool command = parser().parse(args);
+ command.execute();
+ System.out.println();
+ }
+
+ public static abstract class TvnLangTool{
+
+ public abstract void execute();
+ }
+
+ //placeholder for output file types
+ public static class Filetypes{
+ @Option(name= "-wfdesc", description="Convert the workflow file to wfdesc-turtle")
+ public static boolean isWfdesc = false;
+
+ @Option(name="-wfbundle", description="Convert the workflow file to wfbundel")
+ public static boolean isWfbundel = false;
+
+ @Option(name = "-robundle", description = "Convert given bundel in to Research Object bundel")
+ public static boolean isRo = false;
+
+ @Option(name= "-structure", description = "Convert the workflow into *.structure")
+ public static boolean isStructure = false;
+
+ @Option(name = "-json", description = "Convert the workflow into json")
+ public static boolean isJson = false;
+
+ //The tool can only handle one output format at a time.
+ //Return the file type which is selected
+ public static String isTrue(){
+ if(isWfdesc) return "wfdesc";
+ else if(isWfbundel) return "wfbundle";
+ else if(isRo) return "robundle";
+ else if(isStructure) return "structure";
+ else if(isJson) return "json";
+ else return null;
+ }
+
+ }
+
+ public static class Inspect{
+ @Option(name = "-servicetypes", description = "List the service types used in workflow")
+ public static boolean servicetypes = false;
+
+ @Option(name = "-processornames", description = "List a tree of processor names used in workflow")
+ public static boolean processor = false;
+
+ public String getWay(){
+ if(servicetypes) return "servicetypes";
+ else if (processor) return "processornames";
+ else return null;
+ }
+
+ }
+
+
+ //Placeholder for optional parameters: Ex: -i, -o
+ public static class Optional{
+
+ //The input file or directory
+ @Option(name = {"-i", "--input"}, description="Input file/ file dir for conversion")
+ public static String in_file_dir;
+
+ //The out put file or directory. When this is set, all the converted files will be saved into the directory that specified.
+ @Option(name = {"-o", "--output"}, description="Output file/ directory")
+ public static String out_file_dir;
+
+ public static String getInFile(){
+ return in_file_dir;
+ }
+
+ public static String getOutFile(){
+ return out_file_dir;
+ }
+
+ }
+
+ @Command(name = "help", description = "Display help information about Tvarna")
+ public static class HelpCommand extends TvnLangTool{
+ @Inject
+ public Help help;
+
+ @Override
+ public void execute(){
+ help.call();
+ }
+ }
+
+ //Command for convert workflows
+ @Command(name="convert", description="Convert the given workflow")
+ public static class CommandConvert extends TvnLangTool{
+ @Inject
+ Optional optional = new Optional();
+
+ @Inject
+ Filetypes filetypes = new Filetypes();
+
+ @Arguments(usage = "<output format> <input files> ", description = "List of files to be converted.\n "
+ + "Give the list of files to be converted without -i/-o and the converted files will be saved in to /converted folder in the same dir")
+ public final List<String> files = Lists.newArrayList();
+
+ //When this is true, the command will run recursively in a directory.
+ @Option(name={"-r", "--recursive"}, description="Execute the command recursively")
+ public boolean recurse = false;
+
+ //Option for validate the given workflow when converting
+ @Option(name = {"-V", "--validate"}, description="Validate the workflow before convert")
+ public boolean validate = false;
+
+ @Override
+ public void execute(){
+ Scufl2Convert bn;
+ if(filetypes.isJson ){
+
+ }else if(filetypes.isRo){
+ try {
+ ToRobundle ro = new ToRobundle(files, optional.getOutFile());
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }else{
+ if(recurse){
+ bn = new Scufl2Convert(filetypes.isTrue(), optional.getInFile(), optional.getOutFile());
+ }else{
+ bn = new Scufl2Convert(filetypes.isTrue(), files, optional.getOutFile());
+ }
+ }
+
+ }
+
+ }
+
+ //Version command
+ @Command(name="version", description = "Show version informantion")
+ public static class CommandVersion extends TvnLangTool{
+
+ @Override
+ public void execute() {
+ // TODO Auto-generated method stub
+ System.out.println("Apache Taverna Language Command line tool. \nVersion 1.0 ");
+ }
+
+ }
+
+ //Command for inspection of workflows....!!
+ @Command(name="inspect", description="Inspect the given workflow and show the results on the terminal")
+ public static class CommandInspect extends TvnLangTool{
+
+ @Inject
+ Inspect inspect = new Inspect();
+
+ @Option(name={"-l", "--log"}, description="Specify the file name where results should be stored ([some dir]/log.txt)")
+ public String file;
+
+ @Arguments(usage="<option> <input files>", description="Inspect the given workflow")
+ public List<String> toInspect = Lists.newArrayList();
+
+ @Override
+ public void execute() {
+ // TODO Auto-generated method stub
+ if(inspect.processor){
+ try {
+ ProcessorNames pn = new ProcessorNames(toInspect, file);
+
+ } catch (ReaderException | IOException | JAXBException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }else if(inspect.servicetypes){
+ try {
+ ServiceTypes st = new ServiceTypes(toInspect, file);
+ } catch (IOException | ReaderException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ }
+
+ }
+
+ //Command for validation
+ @Command(name = "validate", description = "validate the given workflow")
+ public static class CommandValidate extends TvnLangTool{
+
+ @Inject
+ Optional optional = new Optional();
+
+ @Arguments(usage="<option> <input files> <output dir>", description="Validate the given workflow file/s")
+ public List<String> toValidate = Lists.newArrayList();
+
+ @Override
+ public void execute() {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/TavernaCommandline.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/TavernaCommandline.java b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/TavernaCommandline.java
new file mode 100644
index 0000000..016488c
--- /dev/null
+++ b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/TavernaCommandline.java
@@ -0,0 +1,29 @@
+package org.apache.taverna.tavlang;
+
+/*
+ * 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.
+ */
+
+public class TavernaCommandline {
+
+ public static void main(String args[]){
+ CommandLineTool tool = new CommandLineTool();
+ tool.parse(args);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/Tools.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/Tools.java b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/Tools.java
new file mode 100644
index 0000000..a8ee5f4
--- /dev/null
+++ b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/Tools.java
@@ -0,0 +1,89 @@
+package org.apache.taverna.tavlang.tools;
+
+/*
+ * 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.
+ */
+
+
+import javax.print.attribute.standard.Media;
+
+public class Tools {
+
+ public static enum ConvertionTools {
+ wfbundle{
+ public String mediaType = "application/vnd.taverna.scufl2.workflow-bundle";
+
+
+ @Override
+ public String getMediaType(ConvertionTools t) {
+ // TODO Auto-generated method stub
+ System.out.println(mediaType);
+ return this.mediaType;
+ }
+ },
+ json{
+ public String mediaType = "application/json";
+
+
+ @Override
+ public String getMediaType(ConvertionTools t) {
+ // TODO Auto-generated method stub
+ System.out.println(mediaType);
+ return mediaType;
+ }
+ },
+ wfdesc{
+ public String mediaType = "text/vnd.wf4ever.wfdesc+turtle";
+
+
+ @Override
+ public String getMediaType(ConvertionTools t) {
+ // TODO Auto-generated method stub
+ System.out.println(mediaType);
+ return mediaType;
+ }
+ },
+ robundle{
+
+ @Override
+ public String getMediaType(ConvertionTools t) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ },
+ structure{
+ public String mediaType = "text/vnd.taverna.scufl2.structure";
+
+ @Override
+ public String getMediaType(ConvertionTools t) {
+ // TODO Auto-generated method stub
+ System.out.println(mediaType);
+ return mediaType;
+ }
+
+
+ };
+
+ ConvertionTools(){}
+
+ public abstract String getMediaType(ConvertionTools t);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/convert/Scufl2Convert.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/convert/Scufl2Convert.java b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/convert/Scufl2Convert.java
new file mode 100644
index 0000000..02135dc
--- /dev/null
+++ b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/convert/Scufl2Convert.java
@@ -0,0 +1,190 @@
+package org.apache.taverna.tavlang.tools.convert;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.taverna.scufl2.api.container.WorkflowBundle;
+import org.apache.taverna.scufl2.api.io.ReaderException;
+import org.apache.taverna.scufl2.api.io.WorkflowBundleIO;
+import org.apache.taverna.scufl2.api.io.WriterException;
+import org.apache.taverna.tavlang.tools.Tools.ConvertionTools;
+import org.apache.taverna.tavlang.tools.validate.Validate;
+
+
+/*
+ * Converts
+ * .t2flow --> .wfbundle
+ * .t2flow --> .structure
+ * .wfbundle --> .structure
+ * two constructors.
+ * Scufl2Convert(List<String> list, String out) --> will save the converted files in 'out folder or a directory named /converted in the same folder.
+ * Scufl2Convert(String in, String out) --> Will convert all the files in the 'in' folder and save them in 'out' folder --> -r must be true.
+ *
+ * */
+public class Scufl2Convert{
+
+ private ConvertionTools t;
+ private String MEDIA_TYPE;
+ private String input;
+ private String output;
+ private String type;
+ private List<String> filesList;
+
+ public Scufl2Convert(String type, List<String> files, String out){
+ this.filesList = files;
+ this.output = out;
+ this.type = type.equals("wfdesc")?".wfdesc.ttl":"."+type;
+ this.MEDIA_TYPE = ConvertionTools.valueOf(type).getMediaType(t);
+ this.convert();
+ }
+
+ //When recursive case is on....
+ public Scufl2Convert(String type, String in, String out){
+ this.input = in;
+ this.output = out;
+ this.type = type.equals("wfdesc")?".wfdesc.ttl":"."+type;
+ this.MEDIA_TYPE = ConvertionTools.valueOf(type).getMediaType(t); //Determine the writer media type
+
+ this.createdir();
+ }
+
+ //Create the dir if not exists
+ public void createdir(){
+ if(output == null){
+ File outFile = new File(this.input, "converted");
+ try {
+ FileUtils.forceMkdir(outFile);
+ this.output = outFile.getAbsolutePath();
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ System.err.println("Error creating the directory...!!!!");
+ e1.printStackTrace();
+ }
+ }else{
+ File outFile = new File(this.output);
+ try {
+ FileUtils.forceMkdir(outFile);
+
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ System.err.println("Error creating the directory...!!!!");
+ e1.printStackTrace();
+ }
+ }
+ this.rec_convert(this.input);
+ }
+
+ //Convert the given file. Return in case of an exception.
+ public boolean convert(){
+
+ boolean check = false;
+ // If the output folder is given, save the converted files in to that folder.
+
+ if(this.filesList.size()>0 && this.output != null){
+ File outFile = new File(this.output);
+ try {
+ FileUtils.forceMkdir(outFile);
+ } catch (IOException e1) {
+ System.err.println("Error creating the directory...!!!");
+ }
+ for(String file : this.filesList){
+ File t2File = new File(file);
+
+ convertFile(t2File, outFile);
+
+ }
+
+ }
+
+ /* If the output file is not given, save the converted files in
+ * '/converted' folder.
+ */
+
+ else if(this.filesList.size()>0 && this.output == null){
+ for(String file : this.filesList){
+ File t2File = new File(file);
+
+ File outFile = new File(t2File.getParentFile(), "converted");
+ try {
+ FileUtils.forceMkdir(outFile);
+ } catch (IOException e1) {
+ System.err.println("Error creating the directory...!!!");
+ }
+
+ convertFile(t2File, outFile);
+
+ }
+ }else{
+ System.err.println("Argument mismatch");
+ check = false;
+ }
+
+ return check;
+ }
+
+ //Convert the files in a given directory and save the converted files in to specified dir or /converted folder.
+ //Recursive conversion
+ public void rec_convert(String dir){
+
+ File parent = new File(this.input);
+ if(!parent.exists()){
+ System.err.println("Input directory not found");
+ }else{
+ for(File file : parent.listFiles()){
+ if(!file.isDirectory())
+ {
+ File outFile = new File(this.output);
+ convertFile(file, outFile);
+ }
+ }
+ }
+ }
+
+ //Convert the file
+ public void convertFile(File t2File, File outFile){
+ WorkflowBundleIO wfbio = new WorkflowBundleIO();
+ String filename = t2File.getName();
+ filename = filename.replaceFirst("\\..*", this.type);
+// System.out.println(filename);
+ File scufl2File = new File(outFile.getAbsolutePath(), filename);
+
+ WorkflowBundle wfBundle;
+ try {
+ wfBundle = wfbio.readBundle(t2File, null);// null --> will guess the media type for reading.
+ wfbio.writeBundle(wfBundle, scufl2File, this.MEDIA_TYPE);
+ System.out.println(scufl2File.getPath() + " is created.");
+ }catch (ReaderException e){
+ System.err.println(e.getLocalizedMessage());
+// e.printStackTrace();
+ }catch(IOException e){
+ System.err.println(e.getLocalizedMessage());
+// e.printStackTrace();
+ }catch(WriterException e) {
+ System.err.println(e.getLocalizedMessage());
+// e.printStackTrace();
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/convert/ToJson.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/convert/ToJson.java b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/convert/ToJson.java
new file mode 100644
index 0000000..f2ab156
--- /dev/null
+++ b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/convert/ToJson.java
@@ -0,0 +1,310 @@
+package org.apache.taverna.tavlang.tools.convert;
+
+/*
+ * 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.
+ */
+
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.taverna.scufl2.api.annotation.Annotation;
+import org.apache.taverna.scufl2.api.annotation.Revision;
+import org.apache.taverna.scufl2.api.common.Child;
+import org.apache.taverna.scufl2.api.common.Ported;
+import org.apache.taverna.scufl2.api.common.Scufl2Tools;
+import org.apache.taverna.scufl2.api.common.URITools;
+import org.apache.taverna.scufl2.api.container.WorkflowBundle;
+import org.apache.taverna.scufl2.api.core.BlockingControlLink;
+import org.apache.taverna.scufl2.api.core.ControlLink;
+import org.apache.taverna.scufl2.api.core.DataLink;
+import org.apache.taverna.scufl2.api.core.Processor;
+import org.apache.taverna.scufl2.api.core.Workflow;
+import org.apache.taverna.scufl2.api.io.ReaderException;
+import org.apache.taverna.scufl2.api.io.WorkflowBundleIO;
+import org.apache.taverna.scufl2.api.io.WorkflowBundleWriter;
+import org.apache.taverna.scufl2.api.io.WriterException;
+import org.apache.taverna.scufl2.api.port.DepthPort;
+import org.apache.taverna.scufl2.api.port.GranularDepthPort;
+import org.apache.taverna.scufl2.api.port.Port;
+import org.apache.taverna.scufl2.api.profiles.Profile;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
+
+public class ToJson {
+ public class JsonWriter implements WorkflowBundleWriter {
+
+ @Override
+ public Set<String> getMediaTypes() {
+ return new HashSet<String>(Arrays.asList("application/ld+json",
+ "application/json"));
+ }
+ @Override
+ public void writeBundle(WorkflowBundle wfBundle, File destination,
+ String mediaType) throws WriterException, IOException {
+ ObjectNode json = toJson(wfBundle);
+ mapper.writeValue(destination, json);
+ }
+
+ @Override
+ public void writeBundle(WorkflowBundle wfBundle,
+ OutputStream output, String mediaType)
+ throws WriterException, IOException {
+ ObjectNode json = toJson(wfBundle);
+ mapper.writeValue(output, json);
+ }
+
+ }
+
+ public static void main(String[] args) throws ReaderException, IOException,
+ WriterException {
+ String[] args2 = {"/home/menaka/conv/aaa/as.wfbundle"};
+ new ToJson().convert(args2);
+ }
+
+
+ private WorkflowBundleIO io = new WorkflowBundleIO();;
+
+ private WorkflowBundleWriter jsonWriter = new JsonWriter();
+
+ private ObjectMapper mapper = new ObjectMapper();
+
+ private Scufl2Tools scufl2Tools = new Scufl2Tools();
+
+ private URITools uriTools = new URITools();
+
+ public ToJson() {
+ mapper.enable(SerializationFeature.INDENT_OUTPUT);
+ mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
+ mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+
+ mapper.setDateFormat(new ISO8601DateFormat());
+
+ // Adding custom writer dynamically
+ List<WorkflowBundleWriter> writers = io.getWriters();
+ writers.add(jsonWriter);
+ io.setWriters(writers);
+ }
+
+ protected void addPorts(Ported ported, ObjectNode p) {
+ ArrayNode inputs = mapper.createArrayNode();
+ for (Port port : ported.getInputPorts()) {
+ inputs.add(toJson(port));
+ }
+ p.put("inputs", inputs);
+
+ ArrayNode outputs = mapper.createArrayNode();
+ for (Port port : ported.getOutputPorts()) {
+ outputs.add(toJson(port));
+ // FIXME: Do we need the id for ports? Needed if we add datalinks
+ }
+ p.put("outputs", outputs);
+ }
+
+ protected ObjectNode annotations(Child<?> bean) {
+ ObjectNode node = mapper.createObjectNode();
+ for (Annotation ann : scufl2Tools.annotationsFor(bean)) {
+ URI annUri = uriTools.uriForBean(ann);
+
+ // TODO: include annotation body?
+ }
+ return node;
+ }
+
+ public void convert(String[] filepaths) throws ReaderException,
+ IOException, WriterException {
+ if (filepaths[0].equals("-")) {
+ // Do piped Stdin/Stdout instead
+ WorkflowBundle wfBundle = io.readBundle(System.in, null);
+ io.writeBundle(wfBundle, System.err, "application/ld+json");
+ return;
+ }
+
+ for (String filepath : filepaths) {
+ File workflow = new File(filepath);
+
+ String filename = workflow.getName();
+ filename = filename.replaceFirst("\\..*", ".json");
+ File workflowFile = new File(workflow.getParentFile(), filename);
+
+ WorkflowBundle wfBundle = io.readBundle(workflow, null);
+ io.writeBundle(wfBundle, workflowFile, "application/ld+json");
+ System.out.println(workflowFile);
+ }
+ }
+
+ protected ObjectNode toJson(Port port) {
+ ObjectNode p = mapper.createObjectNode();
+ p.put("name", port.getName());
+ p.putPOJO("id", uriTools.relativeUriForBean(port,
+ scufl2Tools.findParent(WorkflowBundle.class, ((Child<?>)port))));
+
+ if (port instanceof DepthPort) {
+ DepthPort depthPort = (DepthPort) port;
+ if (depthPort.getDepth() != null) {
+ p.put("depth", depthPort.getDepth());
+ }
+ }
+ if (port instanceof GranularDepthPort) {
+ GranularDepthPort granularDepthPort = (GranularDepthPort) port;
+ if (granularDepthPort.getGranularDepth() != null &&
+ ! granularDepthPort.getGranularDepth().equals(granularDepthPort.getDepth())) {
+ p.put("granularDepth", granularDepthPort.getGranularDepth());
+ }
+ }
+ p.putAll(annotations((Child<?>)port));
+ return p;
+ }
+
+ protected JsonNode toJson(Processor proc) {
+ ObjectNode p = mapper.createObjectNode();
+ p.putPOJO("id", uriTools.relativeUriForBean(proc, proc.getParent().getParent()));
+ p.put("name", proc.getName());
+ addPorts(proc, p);
+ p.putAll(annotations(proc));
+
+ List<Workflow> nested = scufl2Tools.nestedWorkflowsForProcessor(proc,
+ proc.getParent().getParent().getMainProfile());
+ if (! nested.isEmpty()) {
+ if (nested.size() == 1) {
+ p.put("nestedWorkflow", toJson(nested.iterator().next()));
+ } else {
+ ArrayNode list = mapper.createArrayNode();
+ for (Workflow w : nested) {
+ list.add(toJson(w));
+ }
+ p.put("nestedWorkflow", list);
+ }
+ }
+ return p;
+ }
+
+ protected JsonNode toJson(Revision currentRevision) {
+ ArrayNode revisions = mapper.createArrayNode();
+ while (currentRevision != null) {
+ ObjectNode rev = mapper.createObjectNode();
+ rev.putPOJO("id", currentRevision.getIdentifier());
+ if (currentRevision.getGeneratedAtTime() != null) {
+ rev.putPOJO("generatedAtTime", currentRevision.getGeneratedAtTime());
+ }
+ currentRevision = currentRevision.getPreviousRevision();
+ if (currentRevision != null) {
+ rev.putPOJO("wasRevisionOf", currentRevision.getIdentifier());
+ }
+ revisions.add(rev);
+ }
+ return revisions;
+ }
+
+ protected ObjectNode toJson(Workflow workflow) {
+ ObjectNode wf = mapper.createObjectNode();
+
+ wf.putPOJO("id", uriTools.relativeUriForBean(workflow, workflow.getParent()));
+
+ wf.put("name", workflow.getName());
+ wf.put("revisions", toJson(workflow.getCurrentRevision()));
+
+ ArrayNode processors = mapper.createArrayNode();
+ for (Processor p : workflow.getProcessors()) {
+ processors.add(toJson(p));
+ }
+ addPorts(workflow, wf);
+ wf.put("processors", processors);
+
+ ArrayNode datalinks = mapper.createArrayNode();
+ for (DataLink link : workflow.getDataLinks()) {
+ datalinks.add(toJson(link));
+ }
+ wf.put("datalinks", datalinks);
+
+ ArrayNode controlLinks = mapper.createArrayNode();
+ for (ControlLink link : workflow.getControlLinks()) {
+ controlLinks.add(toJson(link));
+ }
+ wf.put("controllinks", controlLinks);
+
+
+ wf.putAll(annotations(workflow));
+
+ return wf;
+ }
+
+ protected JsonNode toJson(ControlLink link) {
+ ObjectNode l = mapper.createObjectNode();
+ if (link instanceof BlockingControlLink) {
+ BlockingControlLink controlLink = (BlockingControlLink) link;
+ l.putPOJO("block", uriTools.relativeUriForBean(controlLink.getBlock(),
+ link.getParent().getParent()));
+ l.putPOJO("untilFinished", uriTools.relativeUriForBean(controlLink.getUntilFinished(),
+ link.getParent().getParent()));
+ }
+ return l;
+ }
+
+ protected JsonNode toJson(DataLink link) {
+ ObjectNode l = mapper.createObjectNode();
+ l.putPOJO("receivesFrom", uriTools.relativeUriForBean(link.getReceivesFrom(),
+ link.getParent().getParent()));
+ l.putPOJO("sendsTo", uriTools.relativeUriForBean(link.getSendsTo(),
+ link.getParent().getParent()));
+ if (link.getMergePosition() != null) {
+ l.put("mergePosition", link.getMergePosition());
+ }
+ return l;
+ }
+
+ public ObjectNode toJson(WorkflowBundle wfBundle) {
+
+ ObjectNode root = mapper.createObjectNode();
+ ArrayNode contextList = root.arrayNode();
+ root.put("@context", contextList);
+ ObjectNode context = root.objectNode();
+ contextList.add("https://w3id.org/scufl2/context");
+ contextList.add(context);
+ URI base = wfBundle.getGlobalBaseURI();
+ context.put("@base", base.toASCIIString());
+ root.put("id", base.toASCIIString());
+
+// root.put("name", wfBundle.getName());
+// root.put("revisions", toJson(wfBundle.getCurrentRevision()));
+
+ root.put("workflow", toJson(wfBundle.getMainWorkflow()));
+ root.put("profile", toJson(wfBundle.getMainProfile()));
+
+ return root;
+ }
+
+ private JsonNode toJson(Profile profile) {
+ ObjectNode pf = mapper.createObjectNode();
+
+ pf.putPOJO("id", uriTools.relativeUriForBean(profile, profile.getParent()));
+ // TODO: Activities and configurations
+ return pf;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/convert/ToRobundle.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/convert/ToRobundle.java b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/convert/ToRobundle.java
new file mode 100644
index 0000000..8781ca6
--- /dev/null
+++ b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/convert/ToRobundle.java
@@ -0,0 +1,68 @@
+package org.apache.taverna.tavlang.tools.convert;
+
+/*
+ * 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.
+ */
+
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.taverna.robundle.Bundle;
+import org.apache.taverna.robundle.Bundles;
+
+public class ToRobundle{
+
+ public ToRobundle(List<String> files, String out) throws Exception{
+
+ Logger logger = Logger.getLogger("");
+ //logger.setLevel(Level.FINER);
+ ConsoleHandler console = new ConsoleHandler();
+ console.setLevel(Level.FINEST);
+ logger.addHandler(console);
+ Logger.getLogger("org.researchobject").setLevel(Level.FINEST);
+
+ for(String f : files){
+ Path file = Paths.get(f);
+ convert(file);
+ }
+ }
+
+ //Recursive conversion
+ public ToRobundle(String type, String in, String out) {
+ // TODO Auto-generated constructor stub
+
+ }
+
+ public void convert(Path file) throws IOException{
+ try (Bundle bundle = Bundles.openBundle(file)) {
+
+ System.out.println(bundle.getManifest().toString());
+// bundle.getManifest().writeAsJsonLD();
+// bundle.getManifest().writeAsCombineManifest();
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/inspect/ProcessorNames.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/inspect/ProcessorNames.java b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/inspect/ProcessorNames.java
new file mode 100644
index 0000000..8cbf989
--- /dev/null
+++ b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/inspect/ProcessorNames.java
@@ -0,0 +1,169 @@
+package org.apache.taverna.tavlang.tools.inspect;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeModel;
+import javax.xml.bind.JAXBException;
+
+import org.apache.taverna.scufl2.api.common.Scufl2Tools;
+import org.apache.taverna.scufl2.api.common.URITools;
+import org.apache.taverna.scufl2.api.container.WorkflowBundle;
+import org.apache.taverna.scufl2.api.core.Processor;
+import org.apache.taverna.scufl2.api.core.Workflow;
+import org.apache.taverna.scufl2.api.io.ReaderException;
+import org.apache.taverna.scufl2.api.io.WorkflowBundleIO;
+import org.apache.taverna.scufl2.api.profiles.Profile;
+
+/*
+ * 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.
+ */
+
+
+/*
+ * list the processor names used in the workflow.
+ * Supported formats: .t2flow, .wfbundle
+ * */
+
+public class ProcessorNames {
+
+ private List<String> fileList;
+
+ private String file2;
+
+ private Scufl2Tools scufl2Tools = new Scufl2Tools();
+
+ private URITools uriTools = new URITools();
+
+ public ProcessorNames(List<String> fileList, String file) throws ReaderException, IOException, JAXBException{
+ this.fileList = fileList;
+ this.file2 = file;
+ this.show();
+ }
+
+ public void show() throws ReaderException, IOException, JAXBException{
+ WorkflowBundleIO io = new WorkflowBundleIO();
+ StringBuilder sb = new StringBuilder();
+
+ for(String file : this.fileList){
+ File file2 = new File(file);
+ if(file2.isDirectory()){
+ for(File f : file2.listFiles()){
+ WorkflowBundle wfb = io.readBundle(f, null);
+ System.out.println("Processor tree of "+ f.getName() +" \n" +this.showProcessorTree(wfb));
+ sb.append("Processor tree of "+ f.getName() +" \n" +this.showProcessorTree(wfb) + "\n");
+ }
+ }else{
+ WorkflowBundle wfb = io.readBundle(new File(file), null);
+ System.out.println("Processor tree of "+ file +" \n" +this.showProcessorTree(wfb));
+ sb.append("Processor tree of "+ file +" \n" +this.showProcessorTree(wfb) + "\n");
+ }
+
+
+ }
+
+ if(this.file2!=null){
+ File log = new File(file2);
+ FileWriter fw = new FileWriter(log);
+ BufferedWriter bw = new BufferedWriter(fw);
+ bw.write(sb.toString());
+ bw.close();
+ fw.close();
+ }
+ }
+
+ private Workflow findNestedWorkflow(Processor processor) {
+ Profile profile = processor.getParent().getParent().getMainProfile();
+ return scufl2Tools.nestedWorkflowForProcessor(processor, profile);
+ }
+
+ private void findProcessors(WorkflowBundle ro, Workflow workflow,
+ DefaultMutableTreeNode parent) {
+ for (Processor processor : workflow.getProcessors()) {
+ DefaultMutableTreeNode processorNode = new DefaultMutableTreeNode(
+ processor.getName());
+ parent.add(processorNode);
+ Workflow wf = findNestedWorkflow(processor);
+ if (wf != null) {
+ findProcessors(ro, wf, processorNode);
+ }
+ }
+
+ }
+
+ public TreeModel makeProcessorTree(WorkflowBundle workflowBundle)
+ throws JAXBException, IOException {
+ Workflow workflow = workflowBundle.getMainWorkflow();
+ TreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode(
+ workflow.getName()));
+ DefaultMutableTreeNode parent = (DefaultMutableTreeNode) treeModel
+ .getRoot();
+
+ findProcessors(workflowBundle, workflow, parent);
+ return treeModel;
+ }
+
+ public List<String> showProcessorNames(WorkflowBundle ro)
+ throws JAXBException, IOException {
+ ArrayList<String> names = new ArrayList<String>();
+ for (Processor processor : ro.getMainWorkflow().getProcessors()) {
+ names.add(processor.getName());
+ }
+ Collections.sort(names);
+ return names;
+ }
+
+ public String showProcessorTree(WorkflowBundle ro) throws JAXBException,
+ IOException {
+ TreeModel treeModel = makeProcessorTree(ro);
+ return treeModelAsString(treeModel);
+ }
+
+ public String treeModelAsString(TreeModel treeModel) {
+ StringBuffer sb = new StringBuffer();
+ Object root = treeModel.getRoot();
+ treeModelAsString(treeModel, root, sb, "");
+ return sb.toString();
+ }
+
+ protected void treeModelAsString(TreeModel treeModel, Object parent,
+ StringBuffer sb, String indentation) {
+ sb.append(indentation);
+ int childCount = treeModel.getChildCount(parent);
+ if (childCount == 0) {
+ sb.append("- ");
+ } else {
+ sb.append("+ ");
+ indentation = indentation + " ";
+ }
+ sb.append(parent);
+ sb.append("\n");
+ for (int i = 0; i < childCount; i++) {
+ Object child = treeModel.getChild(parent, i);
+ treeModelAsString(treeModel, child, sb, indentation);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/inspect/ServiceTypes.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/inspect/ServiceTypes.java b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/inspect/ServiceTypes.java
new file mode 100644
index 0000000..d27e024
--- /dev/null
+++ b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/inspect/ServiceTypes.java
@@ -0,0 +1,111 @@
+package org.apache.taverna.tavlang.tools.inspect;
+
+
+/*
+ * 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.
+ */
+
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.taverna.scufl2.api.io.WorkflowBundleIO;
+import org.apache.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.scufl2.api.container.WorkflowBundle;
+import org.apache.taverna.scufl2.api.io.ReaderException;
+import org.apache.taverna.scufl2.api.profiles.Profile;
+
+/*
+ * List the service types used in workflow.
+ * Supported file formats : .wfbundle, .t2flow
+ * */
+
+public class ServiceTypes {
+
+ private List<String> filesList;
+ private Set<String> types = new LinkedHashSet<String>();
+ private String save;
+
+ public ServiceTypes(List<String> filesList, String file) throws IOException, ReaderException{
+ this.filesList = filesList;
+ this.save = file;
+ this.service();
+
+ }
+
+ public void service() throws ReaderException, IOException{
+ WorkflowBundleIO io = new WorkflowBundleIO();
+ StringBuilder sb = new StringBuilder();
+
+ for (String filepath : filesList) {
+ File file = new File(filepath);
+
+ if(file.isDirectory()){
+ for(File f : file.listFiles()){
+ WorkflowBundle wfBundle = io.readBundle(f, null);
+ System.out.println("Service types used in " + f.getCanonicalPath() + " :" +"\n");
+ sb.append("Service types used in " + f.getCanonicalPath() + " :");
+ for (Profile profile : wfBundle.getProfiles()) {
+ for (Activity activity : profile.getActivities()) {
+ this.types.add(activity.getType().toASCIIString());
+ }
+ }
+ for(String t : types){
+ System.out.println(t);
+ sb.append(t + "\n");
+ }
+ System.out.println("\n**************************************************\n");
+ sb.append("\n**************************************************\n");
+ }
+ }else{
+ // mediaType = null --> guess
+ WorkflowBundle wfBundle = io.readBundle(file, null);
+ System.out.println("Service types used in " + file.getCanonicalPath() + " :" + "\n");
+ sb.append("Service types used in " + file.getCanonicalPath() + " :");
+ for (Profile profile : wfBundle.getProfiles()) {
+ for (Activity activity : profile.getActivities()) {
+ this.types.add(activity.getType().toASCIIString());
+ }
+ }
+ for(String t : types){
+ System.out.println(t);
+ sb.append(t + "\n");
+ }
+
+ System.out.println("\n**************************************************\n");
+ sb.append("\n**************************************************\n");
+ }
+ }
+
+ if(save!=null){
+ File log = new File(save);
+ FileWriter fw = new FileWriter(log);
+ BufferedWriter bw = new BufferedWriter(fw);
+ bw.write(sb.toString());
+ bw.close();
+ fw.close();
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/validate/Validate.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/validate/Validate.java b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/validate/Validate.java
new file mode 100644
index 0000000..572679f
--- /dev/null
+++ b/taverna-language-commandline/src/main/java/org/apache/taverna/tavlang/tools/validate/Validate.java
@@ -0,0 +1,38 @@
+package org.apache.taverna.tavlang.tools.validate;
+
+/*
+ * 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.
+ */
+
+import org.apache.taverna.scufl2.api.container.WorkflowBundle;
+import org.apache.taverna.scufl2.validation.ValidationReport;
+import org.apache.taverna.scufl2.validation.Validator;
+import org.apache.taverna.scufl2.validation.structural.StructuralValidationListener;
+import org.apache.taverna.scufl2.validation.structural.StructuralValidator;
+
+
+public class Validate {
+
+ public Validate(WorkflowBundle wfb){
+ System.out.println("Validation started...");
+ StructuralValidator v = new StructuralValidator();
+ StructuralValidationListener l = v.validate(wfb);
+ ValidationReport r;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/CommandLineTool.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/CommandLineTool.java b/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/CommandLineTool.java
deleted file mode 100644
index bff8576..0000000
--- a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/CommandLineTool.java
+++ /dev/null
@@ -1,276 +0,0 @@
-package org.apache.tavlang.commandline;
-
-
-/*
- * 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.
- */
-
-
-import io.airlift.airline.Arguments;
-import io.airlift.airline.Cli;
-import io.airlift.airline.Cli.CliBuilder;
-import io.airlift.airline.Command;
-import io.airlift.airline.Help;
-import io.airlift.airline.Option;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.xml.bind.JAXBException;
-
-import org.apache.taverna.scufl2.api.io.ReaderException;
-import org.apache.tavlang.commandline.tools.Tools;
-import org.apache.tavlang.commandline.tools.Tools.ConvertionTools;
-import org.apache.tavlang.commandline.tools.convert.Scufl2Convert;
-import org.apache.tavlang.commandline.tools.convert.ToRobundle;
-import org.apache.tavlang.commandline.tools.inspect.ProcessorNames;
-import org.apache.tavlang.commandline.tools.inspect.ServiceTypes;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.Lists;
-
-
-/*
- * The command line options for convert, validate and inspect workflows.
- * Use the airlift/airline library
- * */
-
-public class CommandLineTool {
-
- private Cli<TvnLangTool> parser(){
- CliBuilder<TvnLangTool> build = Cli.<TvnLangTool>builder("tavlang")
- .withDescription("Convert, manage workflows")
- .withDefaultCommand(HelpCommand.class)
- .withCommand(CommandConvert.class)
- .withCommand(HelpCommand.class)
- .withCommand(CommandInspect.class)
- .withCommand(CommandValidate.class)
- .withCommand(CommandVersion.class);
-
- return build.build();
- }
-
- public CommandLineTool(){};
- public void parse(String... args)
- {
- System.out.println("$ tavlang " + Joiner.on(" ").join(args));
- TvnLangTool command = parser().parse(args);
- command.execute();
- System.out.println();
- }
-
- public static abstract class TvnLangTool{
-
- public abstract void execute();
- }
-
- //placeholder for output file types
- public static class Filetypes{
- @Option(name= "-wfdesc", description="Convert the workflow file to wfdesc-turtle")
- public static boolean isWfdesc = false;
-
- @Option(name="-wfbundle", description="Convert the workflow file to wfbundel")
- public static boolean isWfbundel = false;
-
- @Option(name = "-robundle", description = "Convert given bundel in to Research Object bundel")
- public static boolean isRo = false;
-
- @Option(name= "-structure", description = "Convert the workflow into *.structure")
- public static boolean isStructure = false;
-
- @Option(name = "-json", description = "Convert the workflow into json")
- public static boolean isJson = false;
-
- //The tool can only handle one output format at a time.
- //Return the file type which is selected
- public static String isTrue(){
- if(isWfdesc) return "wfdesc";
- else if(isWfbundel) return "wfbundle";
- else if(isRo) return "robundle";
- else if(isStructure) return "structure";
- else if(isJson) return "json";
- else return null;
- }
-
- }
-
- public static class Inspect{
- @Option(name = "-servicetypes", description = "List the service types used in workflow")
- public static boolean servicetypes = false;
-
- @Option(name = "-processornames", description = "List a tree of processor names used in workflow")
- public static boolean processor = false;
-
- public String getWay(){
- if(servicetypes) return "servicetypes";
- else if (processor) return "processornames";
- else return null;
- }
-
- }
-
-
- //Placeholder for optional parameters: Ex: -i, -o
- public static class Optional{
-
- //The input file or directory
- @Option(name = {"-i", "--input"}, description="Input file/ file dir for conversion")
- public static String in_file_dir;
-
- //The out put file or directory. When this is set, all the converted files will be saved into the directory that specified.
- @Option(name = {"-o", "--output"}, description="Output file/ directory")
- public static String out_file_dir;
-
- public static String getInFile(){
- return in_file_dir;
- }
-
- public static String getOutFile(){
- return out_file_dir;
- }
-
- }
-
- @Command(name = "help", description = "Display help information about Tvarna")
- public static class HelpCommand extends TvnLangTool{
- @Inject
- public Help help;
-
- @Override
- public void execute(){
- help.call();
- }
- }
-
- //Command for convert workflows
- @Command(name="convert", description="Convert the given workflow")
- public static class CommandConvert extends TvnLangTool{
- @Inject
- Optional optional = new Optional();
-
- @Inject
- Filetypes filetypes = new Filetypes();
-
- @Arguments(usage = "<output format> <input files> ", description = "List of files to be converted.\n "
- + "Give the list of files to be converted without -i/-o and the converted files will be saved in to /converted folder in the same dir")
- public final List<String> files = Lists.newArrayList();
-
- //When this is true, the command will run recursively in a directory.
- @Option(name={"-r", "--recursive"}, description="Execute the command recursively")
- public boolean recurse = false;
-
- //Option for validate the given workflow when converting
- @Option(name = {"-V", "--validate"}, description="Validate the workflow before convert")
- public boolean validate = false;
-
- @Override
- public void execute(){
- Scufl2Convert bn;
- if(filetypes.isJson ){
-
- }else if(filetypes.isRo){
- try {
- ToRobundle ro = new ToRobundle(files, optional.getOutFile());
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }else{
- if(recurse){
- bn = new Scufl2Convert(filetypes.isTrue(), optional.getInFile(), optional.getOutFile());
- }else{
- bn = new Scufl2Convert(filetypes.isTrue(), files, optional.getOutFile());
- }
- }
-
- }
-
- }
-
- //Version command
- @Command(name="version", description = "Show version informantion")
- public static class CommandVersion extends TvnLangTool{
-
- @Override
- public void execute() {
- // TODO Auto-generated method stub
- System.out.println("Apache Taverna Language Command line tool. \nVersion 1.0 ");
- }
-
- }
-
- //Command for inspection of workflows....!!
- @Command(name="inspect", description="Inspect the given workflow and show the results on the terminal")
- public static class CommandInspect extends TvnLangTool{
-
- @Inject
- Inspect inspect = new Inspect();
-
- @Option(name={"-l", "--log"}, description="Specify the file name where results should be stored ([some dir]/log.txt)")
- public String file;
-
- @Arguments(usage="<option> <input files>", description="Inspect the given workflow")
- public List<String> toInspect = Lists.newArrayList();
-
- @Override
- public void execute() {
- // TODO Auto-generated method stub
- if(inspect.processor){
- try {
- ProcessorNames pn = new ProcessorNames(toInspect, file);
-
- } catch (ReaderException | IOException | JAXBException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }else if(inspect.servicetypes){
- try {
- ServiceTypes st = new ServiceTypes(toInspect, file);
- } catch (IOException | ReaderException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- }
-
- }
-
- //Command for validation
- @Command(name = "validate", description = "validate the given workflow")
- public static class CommandValidate extends TvnLangTool{
-
- @Inject
- Optional optional = new Optional();
-
- @Arguments(usage="<option> <input files> <output dir>", description="Validate the given workflow file/s")
- public List<String> toValidate = Lists.newArrayList();
-
- @Override
- public void execute() {
- // TODO Auto-generated method stub
-
- }
-
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/TavernaCommandline.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/TavernaCommandline.java b/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/TavernaCommandline.java
deleted file mode 100644
index 0bd0226..0000000
--- a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/TavernaCommandline.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.tavlang.commandline;
-
-/*
- * 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.
- */
-
-public class TavernaCommandline {
-
- public static void main(String args[]){
- CommandLineTool tool = new CommandLineTool();
- tool.parse(args);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/Tools.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/Tools.java b/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/Tools.java
deleted file mode 100644
index c5ba1b3..0000000
--- a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/Tools.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package org.apache.tavlang.commandline.tools;
-
-/*
- * 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.
- */
-
-
-import javax.print.attribute.standard.Media;
-
-public class Tools {
-
- public static enum ConvertionTools {
- wfbundle{
- public String mediaType = "application/vnd.taverna.scufl2.workflow-bundle";
-
-
- @Override
- public String getMediaType(ConvertionTools t) {
- // TODO Auto-generated method stub
- System.out.println(mediaType);
- return this.mediaType;
- }
- },
- json{
- public String mediaType = "application/json";
-
-
- @Override
- public String getMediaType(ConvertionTools t) {
- // TODO Auto-generated method stub
- System.out.println(mediaType);
- return mediaType;
- }
- },
- wfdesc{
- public String mediaType = "text/vnd.wf4ever.wfdesc+turtle";
-
-
- @Override
- public String getMediaType(ConvertionTools t) {
- // TODO Auto-generated method stub
- System.out.println(mediaType);
- return mediaType;
- }
- },
- robundle{
-
- @Override
- public String getMediaType(ConvertionTools t) {
- // TODO Auto-generated method stub
- return null;
- }
-
- },
- structure{
- public String mediaType = "text/vnd.taverna.scufl2.structure";
-
- @Override
- public String getMediaType(ConvertionTools t) {
- // TODO Auto-generated method stub
- System.out.println(mediaType);
- return mediaType;
- }
-
-
- };
-
- ConvertionTools(){}
-
- public abstract String getMediaType(ConvertionTools t);
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/Scufl2Convert.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/Scufl2Convert.java b/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/Scufl2Convert.java
deleted file mode 100644
index 9d0a145..0000000
--- a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/Scufl2Convert.java
+++ /dev/null
@@ -1,190 +0,0 @@
-package org.apache.tavlang.commandline.tools.convert;
-
-/*
- * 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.
- */
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.taverna.scufl2.api.container.WorkflowBundle;
-import org.apache.taverna.scufl2.api.io.ReaderException;
-import org.apache.taverna.scufl2.api.io.WorkflowBundleIO;
-import org.apache.taverna.scufl2.api.io.WriterException;
-import org.apache.tavlang.commandline.tools.Tools.ConvertionTools;
-import org.apache.tavlang.commandline.tools.validate.Validate;
-
-
-/*
- * Converts
- * .t2flow --> .wfbundle
- * .t2flow --> .structure
- * .wfbundle --> .structure
- * two constructors.
- * Scufl2Convert(List<String> list, String out) --> will save the converted files in 'out folder or a directory named /converted in the same folder.
- * Scufl2Convert(String in, String out) --> Will convert all the files in the 'in' folder and save them in 'out' folder --> -r must be true.
- *
- * */
-public class Scufl2Convert{
-
- private ConvertionTools t;
- private String MEDIA_TYPE;
- private String input;
- private String output;
- private String type;
- private List<String> filesList;
-
- public Scufl2Convert(String type, List<String> files, String out){
- this.filesList = files;
- this.output = out;
- this.type = type.equals("wfdesc")?".wfdesc.ttl":"."+type;
- this.MEDIA_TYPE = ConvertionTools.valueOf(type).getMediaType(t);
- this.convert();
- }
-
- //When recursive case is on....
- public Scufl2Convert(String type, String in, String out){
- this.input = in;
- this.output = out;
- this.type = type.equals("wfdesc")?".wfdesc.ttl":"."+type;
- this.MEDIA_TYPE = ConvertionTools.valueOf(type).getMediaType(t); //Determine the writer media type
-
- this.createdir();
- }
-
- //Create the dir if not exists
- public void createdir(){
- if(output == null){
- File outFile = new File(this.input, "converted");
- try {
- FileUtils.forceMkdir(outFile);
- this.output = outFile.getAbsolutePath();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- System.err.println("Error creating the directory...!!!!");
- e1.printStackTrace();
- }
- }else{
- File outFile = new File(this.output);
- try {
- FileUtils.forceMkdir(outFile);
-
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- System.err.println("Error creating the directory...!!!!");
- e1.printStackTrace();
- }
- }
- this.rec_convert(this.input);
- }
-
- //Convert the given file. Return in case of an exception.
- public boolean convert(){
-
- boolean check = false;
- // If the output folder is given, save the converted files in to that folder.
-
- if(this.filesList.size()>0 && this.output != null){
- File outFile = new File(this.output);
- try {
- FileUtils.forceMkdir(outFile);
- } catch (IOException e1) {
- System.err.println("Error creating the directory...!!!");
- }
- for(String file : this.filesList){
- File t2File = new File(file);
-
- convertFile(t2File, outFile);
-
- }
-
- }
-
- /* If the output file is not given, save the converted files in
- * '/converted' folder.
- */
-
- else if(this.filesList.size()>0 && this.output == null){
- for(String file : this.filesList){
- File t2File = new File(file);
-
- File outFile = new File(t2File.getParentFile(), "converted");
- try {
- FileUtils.forceMkdir(outFile);
- } catch (IOException e1) {
- System.err.println("Error creating the directory...!!!");
- }
-
- convertFile(t2File, outFile);
-
- }
- }else{
- System.err.println("Argument mismatch");
- check = false;
- }
-
- return check;
- }
-
- //Convert the files in a given directory and save the converted files in to specified dir or /converted folder.
- //Recursive conversion
- public void rec_convert(String dir){
-
- File parent = new File(this.input);
- if(!parent.exists()){
- System.err.println("Input directory not found");
- }else{
- for(File file : parent.listFiles()){
- if(!file.isDirectory())
- {
- File outFile = new File(this.output);
- convertFile(file, outFile);
- }
- }
- }
- }
-
- //Convert the file
- public void convertFile(File t2File, File outFile){
- WorkflowBundleIO wfbio = new WorkflowBundleIO();
- String filename = t2File.getName();
- filename = filename.replaceFirst("\\..*", this.type);
-// System.out.println(filename);
- File scufl2File = new File(outFile.getAbsolutePath(), filename);
-
- WorkflowBundle wfBundle;
- try {
- wfBundle = wfbio.readBundle(t2File, null);// null --> will guess the media type for reading.
- wfbio.writeBundle(wfBundle, scufl2File, this.MEDIA_TYPE);
- System.out.println(scufl2File.getPath() + " is created.");
- }catch (ReaderException e){
- System.err.println(e.getLocalizedMessage());
-// e.printStackTrace();
- }catch(IOException e){
- System.err.println(e.getLocalizedMessage());
-// e.printStackTrace();
- }catch(WriterException e) {
- System.err.println(e.getLocalizedMessage());
-// e.printStackTrace();
- }
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/ToJson.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/ToJson.java b/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/ToJson.java
deleted file mode 100644
index 4193c30..0000000
--- a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/ToJson.java
+++ /dev/null
@@ -1,310 +0,0 @@
-package org.apache.tavlang.commandline.tools.convert;
-
-/*
- * 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.
- */
-
-
-import java.io.File;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URI;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.taverna.scufl2.api.annotation.Annotation;
-import org.apache.taverna.scufl2.api.annotation.Revision;
-import org.apache.taverna.scufl2.api.common.Child;
-import org.apache.taverna.scufl2.api.common.Ported;
-import org.apache.taverna.scufl2.api.common.Scufl2Tools;
-import org.apache.taverna.scufl2.api.common.URITools;
-import org.apache.taverna.scufl2.api.container.WorkflowBundle;
-import org.apache.taverna.scufl2.api.core.BlockingControlLink;
-import org.apache.taverna.scufl2.api.core.ControlLink;
-import org.apache.taverna.scufl2.api.core.DataLink;
-import org.apache.taverna.scufl2.api.core.Processor;
-import org.apache.taverna.scufl2.api.core.Workflow;
-import org.apache.taverna.scufl2.api.io.ReaderException;
-import org.apache.taverna.scufl2.api.io.WorkflowBundleIO;
-import org.apache.taverna.scufl2.api.io.WorkflowBundleWriter;
-import org.apache.taverna.scufl2.api.io.WriterException;
-import org.apache.taverna.scufl2.api.port.DepthPort;
-import org.apache.taverna.scufl2.api.port.GranularDepthPort;
-import org.apache.taverna.scufl2.api.port.Port;
-import org.apache.taverna.scufl2.api.profiles.Profile;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
-
-public class ToJson {
- public class JsonWriter implements WorkflowBundleWriter {
-
- @Override
- public Set<String> getMediaTypes() {
- return new HashSet<String>(Arrays.asList("application/ld+json",
- "application/json"));
- }
- @Override
- public void writeBundle(WorkflowBundle wfBundle, File destination,
- String mediaType) throws WriterException, IOException {
- ObjectNode json = toJson(wfBundle);
- mapper.writeValue(destination, json);
- }
-
- @Override
- public void writeBundle(WorkflowBundle wfBundle,
- OutputStream output, String mediaType)
- throws WriterException, IOException {
- ObjectNode json = toJson(wfBundle);
- mapper.writeValue(output, json);
- }
-
- }
-
- public static void main(String[] args) throws ReaderException, IOException,
- WriterException {
- String[] args2 = {"/home/menaka/conv/aaa/as.wfbundle"};
- new ToJson().convert(args2);
- }
-
-
- private WorkflowBundleIO io = new WorkflowBundleIO();;
-
- private WorkflowBundleWriter jsonWriter = new JsonWriter();
-
- private ObjectMapper mapper = new ObjectMapper();
-
- private Scufl2Tools scufl2Tools = new Scufl2Tools();
-
- private URITools uriTools = new URITools();
-
- public ToJson() {
- mapper.enable(SerializationFeature.INDENT_OUTPUT);
- mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
- mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
-
- mapper.setDateFormat(new ISO8601DateFormat());
-
- // Adding custom writer dynamically
- List<WorkflowBundleWriter> writers = io.getWriters();
- writers.add(jsonWriter);
- io.setWriters(writers);
- }
-
- protected void addPorts(Ported ported, ObjectNode p) {
- ArrayNode inputs = mapper.createArrayNode();
- for (Port port : ported.getInputPorts()) {
- inputs.add(toJson(port));
- }
- p.put("inputs", inputs);
-
- ArrayNode outputs = mapper.createArrayNode();
- for (Port port : ported.getOutputPorts()) {
- outputs.add(toJson(port));
- // FIXME: Do we need the id for ports? Needed if we add datalinks
- }
- p.put("outputs", outputs);
- }
-
- protected ObjectNode annotations(Child<?> bean) {
- ObjectNode node = mapper.createObjectNode();
- for (Annotation ann : scufl2Tools.annotationsFor(bean)) {
- URI annUri = uriTools.uriForBean(ann);
-
- // TODO: include annotation body?
- }
- return node;
- }
-
- public void convert(String[] filepaths) throws ReaderException,
- IOException, WriterException {
- if (filepaths[0].equals("-")) {
- // Do piped Stdin/Stdout instead
- WorkflowBundle wfBundle = io.readBundle(System.in, null);
- io.writeBundle(wfBundle, System.err, "application/ld+json");
- return;
- }
-
- for (String filepath : filepaths) {
- File workflow = new File(filepath);
-
- String filename = workflow.getName();
- filename = filename.replaceFirst("\\..*", ".json");
- File workflowFile = new File(workflow.getParentFile(), filename);
-
- WorkflowBundle wfBundle = io.readBundle(workflow, null);
- io.writeBundle(wfBundle, workflowFile, "application/ld+json");
- System.out.println(workflowFile);
- }
- }
-
- protected ObjectNode toJson(Port port) {
- ObjectNode p = mapper.createObjectNode();
- p.put("name", port.getName());
- p.putPOJO("id", uriTools.relativeUriForBean(port,
- scufl2Tools.findParent(WorkflowBundle.class, ((Child<?>)port))));
-
- if (port instanceof DepthPort) {
- DepthPort depthPort = (DepthPort) port;
- if (depthPort.getDepth() != null) {
- p.put("depth", depthPort.getDepth());
- }
- }
- if (port instanceof GranularDepthPort) {
- GranularDepthPort granularDepthPort = (GranularDepthPort) port;
- if (granularDepthPort.getGranularDepth() != null &&
- ! granularDepthPort.getGranularDepth().equals(granularDepthPort.getDepth())) {
- p.put("granularDepth", granularDepthPort.getGranularDepth());
- }
- }
- p.putAll(annotations((Child<?>)port));
- return p;
- }
-
- protected JsonNode toJson(Processor proc) {
- ObjectNode p = mapper.createObjectNode();
- p.putPOJO("id", uriTools.relativeUriForBean(proc, proc.getParent().getParent()));
- p.put("name", proc.getName());
- addPorts(proc, p);
- p.putAll(annotations(proc));
-
- List<Workflow> nested = scufl2Tools.nestedWorkflowsForProcessor(proc,
- proc.getParent().getParent().getMainProfile());
- if (! nested.isEmpty()) {
- if (nested.size() == 1) {
- p.put("nestedWorkflow", toJson(nested.iterator().next()));
- } else {
- ArrayNode list = mapper.createArrayNode();
- for (Workflow w : nested) {
- list.add(toJson(w));
- }
- p.put("nestedWorkflow", list);
- }
- }
- return p;
- }
-
- protected JsonNode toJson(Revision currentRevision) {
- ArrayNode revisions = mapper.createArrayNode();
- while (currentRevision != null) {
- ObjectNode rev = mapper.createObjectNode();
- rev.putPOJO("id", currentRevision.getIdentifier());
- if (currentRevision.getGeneratedAtTime() != null) {
- rev.putPOJO("generatedAtTime", currentRevision.getGeneratedAtTime());
- }
- currentRevision = currentRevision.getPreviousRevision();
- if (currentRevision != null) {
- rev.putPOJO("wasRevisionOf", currentRevision.getIdentifier());
- }
- revisions.add(rev);
- }
- return revisions;
- }
-
- protected ObjectNode toJson(Workflow workflow) {
- ObjectNode wf = mapper.createObjectNode();
-
- wf.putPOJO("id", uriTools.relativeUriForBean(workflow, workflow.getParent()));
-
- wf.put("name", workflow.getName());
- wf.put("revisions", toJson(workflow.getCurrentRevision()));
-
- ArrayNode processors = mapper.createArrayNode();
- for (Processor p : workflow.getProcessors()) {
- processors.add(toJson(p));
- }
- addPorts(workflow, wf);
- wf.put("processors", processors);
-
- ArrayNode datalinks = mapper.createArrayNode();
- for (DataLink link : workflow.getDataLinks()) {
- datalinks.add(toJson(link));
- }
- wf.put("datalinks", datalinks);
-
- ArrayNode controlLinks = mapper.createArrayNode();
- for (ControlLink link : workflow.getControlLinks()) {
- controlLinks.add(toJson(link));
- }
- wf.put("controllinks", controlLinks);
-
-
- wf.putAll(annotations(workflow));
-
- return wf;
- }
-
- protected JsonNode toJson(ControlLink link) {
- ObjectNode l = mapper.createObjectNode();
- if (link instanceof BlockingControlLink) {
- BlockingControlLink controlLink = (BlockingControlLink) link;
- l.putPOJO("block", uriTools.relativeUriForBean(controlLink.getBlock(),
- link.getParent().getParent()));
- l.putPOJO("untilFinished", uriTools.relativeUriForBean(controlLink.getUntilFinished(),
- link.getParent().getParent()));
- }
- return l;
- }
-
- protected JsonNode toJson(DataLink link) {
- ObjectNode l = mapper.createObjectNode();
- l.putPOJO("receivesFrom", uriTools.relativeUriForBean(link.getReceivesFrom(),
- link.getParent().getParent()));
- l.putPOJO("sendsTo", uriTools.relativeUriForBean(link.getSendsTo(),
- link.getParent().getParent()));
- if (link.getMergePosition() != null) {
- l.put("mergePosition", link.getMergePosition());
- }
- return l;
- }
-
- public ObjectNode toJson(WorkflowBundle wfBundle) {
-
- ObjectNode root = mapper.createObjectNode();
- ArrayNode contextList = root.arrayNode();
- root.put("@context", contextList);
- ObjectNode context = root.objectNode();
- contextList.add("https://w3id.org/scufl2/context");
- contextList.add(context);
- URI base = wfBundle.getGlobalBaseURI();
- context.put("@base", base.toASCIIString());
- root.put("id", base.toASCIIString());
-
-// root.put("name", wfBundle.getName());
-// root.put("revisions", toJson(wfBundle.getCurrentRevision()));
-
- root.put("workflow", toJson(wfBundle.getMainWorkflow()));
- root.put("profile", toJson(wfBundle.getMainProfile()));
-
- return root;
- }
-
- private JsonNode toJson(Profile profile) {
- ObjectNode pf = mapper.createObjectNode();
-
- pf.putPOJO("id", uriTools.relativeUriForBean(profile, profile.getParent()));
- // TODO: Activities and configurations
- return pf;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7fea7108/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/ToRobundle.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/ToRobundle.java b/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/ToRobundle.java
deleted file mode 100644
index 9c788ff..0000000
--- a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/ToRobundle.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package org.apache.tavlang.commandline.tools.convert;
-
-/*
- * 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.
- */
-
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.taverna.robundle.Bundle;
-import org.apache.taverna.robundle.Bundles;
-
-public class ToRobundle{
-
- public ToRobundle(List<String> files, String out) throws Exception{
-
- Logger logger = Logger.getLogger("");
- //logger.setLevel(Level.FINER);
- ConsoleHandler console = new ConsoleHandler();
- console.setLevel(Level.FINEST);
- logger.addHandler(console);
- Logger.getLogger("org.researchobject").setLevel(Level.FINEST);
-
- for(String f : files){
- Path file = Paths.get(f);
- convert(file);
- }
- }
-
- //Recursive conversion
- public ToRobundle(String type, String in, String out) {
- // TODO Auto-generated constructor stub
-
- }
-
- public void convert(Path file) throws IOException{
- try (Bundle bundle = Bundles.openBundle(file)) {
-
- System.out.println(bundle.getManifest().toString());
-// bundle.getManifest().writeAsJsonLD();
-// bundle.getManifest().writeAsCombineManifest();
- }
- }
-
-
-}