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:38 UTC

[19/31] incubator-taverna-language git commit: processornames and servicetypes

processornames and servicetypes

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

Branch: refs/heads/master
Commit: 7da9a3befa72c17933e159059b6b222cb0899e39
Parents: dce2802
Author: menaka121 <me...@gmail.com>
Authored: Wed Jun 10 03:46:30 2015 +0530
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Jun 11 17:33:29 2015 +0100

----------------------------------------------------------------------
 .../tavlang/commandline/CommandLineTool.java    |  75 ++++----
 .../tools/inspect/ProcessorNames.java           | 169 +++++++++++++++++++
 .../commandline/tools/inspect/ServiceTypes.java | 111 ++++++++++++
 3 files changed, 319 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7da9a3be/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
index 5201986..3145e4d 100644
--- 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
@@ -29,12 +29,18 @@ 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.ToWfbundle;
+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;
@@ -123,12 +129,8 @@ public class CommandLineTool {
 	//Placeholder for optional parameters: Ex: -i, -o 
 	public static class Optional{
 		
-		
-		@Option(name={"-l", "--log"}, description = "Save a results to a file")
-		public boolean log = false;
-		
 		//The input file or directory
-		@Option(name = {"-i", "--input"}, description="Input file/ file dir for convertion")
+		@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.
@@ -179,31 +181,16 @@ public class CommandLineTool {
 		
 		@Override
 		public void execute(){
-			Tools to = new Tools();
-			
-			System.out.println(filetypes.isTrue());
-			ConvertionTools t = ConvertionTools.valueOf(filetypes.isTrue());
-			t.run();
-//			
-//			if(Filetypes.isWfbundel){
-//				if(!files.isEmpty() && optional.getInFile()!=null){
-//					System.err.println("Unexpected arguments:"+" " + files.toString() + " "+ optional.getInFile());
-//					return;
-//				}
-//				File dir = new File(Optional.getInFile());
-//				File odir = new File(Optional.getOutFile());
-//				if(!odir.exists()){
-//					odir.mkdirs();
-//				}
-//				for(File f : dir.listFiles()){
-////					(new ToWfbundel(f.toString(), odir.toString())).run();
-////					System.out.println(f);
-//					
-//				}
-//					
-//			}
-			
-			
+			ToWfbundle bn; 
+			if(!filetypes.isJson || !filetypes.isRo){
+				if(recurse){
+					bn = new ToWfbundle(filetypes.isTrue(), optional.getInFile(), optional.getOutFile());
+				}else{
+					bn =  new ToWfbundle(filetypes.isTrue(), files, optional.getOutFile());
+				}
+			}else{
+				System.out.println("To be implemented");
+			}
 			
 		}
 		
@@ -222,22 +209,38 @@ public class CommandLineTool {
 	}
 	
 	//Command for inspection of workflows....!!
-	@Command(name="inspect", description="Inspect the given workflow")
+	@Command(name="inspect", description="Inspect the given workflow and show the results on the terminal")
 	public static class CommandInspect extends TvnLangTool{
-
-		@Inject
-		Optional optional = new Optional();
 		
 		@Inject
 		Inspect inspect = new Inspect();
 		
-		@Arguments(usage="<option> <input files> <output dir>", description="Inspect the given workflow")
+		@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();
+				}
+				
+			}
 			
 		}
 		

http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/7da9a3be/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/inspect/ProcessorNames.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/inspect/ProcessorNames.java b/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/inspect/ProcessorNames.java
new file mode 100644
index 0000000..3a0dd31
--- /dev/null
+++ b/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/inspect/ProcessorNames.java
@@ -0,0 +1,169 @@
+package org.apache.tavlang.commandline.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/7da9a3be/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/inspect/ServiceTypes.java
----------------------------------------------------------------------
diff --git a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/inspect/ServiceTypes.java b/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/inspect/ServiceTypes.java
new file mode 100644
index 0000000..f3d7396
--- /dev/null
+++ b/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/inspect/ServiceTypes.java
@@ -0,0 +1,111 @@
+package org.apache.tavlang.commandline.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();
+		}
+		
+	}
+	
+}