package Taverna.Visitor;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import CLInterface.Printer;
import Core.Pair;
import LONI.tree.GraphObject.DataModule;
import LONI.tree.Author;
import LONI.tree.Authors;
import LONI.tree.GraphObject.GraphObject;
import LONI.tree.GraphObject.Module;
import LONI.tree.GraphObject.ModuleGroup;
import LONI.tree.workflow.Connections;
import LONI.tree.workflow.Pipeline;
import Specification.LoniSpecification;
import Specification.TavernaSpecification;
import Taverna.Tree.Workflow;
import Taverna.Tree.Annotation.*;
import Taverna.Tree.DataFlowImpl.Dataflow;
import Taverna.Tree.Processor.Processor;
import Taverna.Tree.Processor.Processors;
/**
* @author johnny5550822, Nick
* Methods for Taverna to Loni Conversion
*
*/
public class TavernaToLoniConverter extends DFSVisitor {
public TavernaToLoniConverter(){
annotationVisitor = new AnnotationConverter();
dataFlowImplVisitor = new DataFlowImplConverter();
}
public Connections getConnections(Dataflow dflow){
Connections conn = (Connections) dataFlowImplVisitor.visit(dflow.getDatalinks());
return conn;
}
/* (non-Javadoc)
* @see Taverna.Visitor.DFSVisitor#visit(Taverna.Tree.Workflow)
*/
public Object visit(Workflow workflow){
Pipeline pipeline;
String version = workflow.getVersion();
ModuleGroup moduleGroup;
Connections connections = getConnections(workflow.getDataflow());
moduleGroup = (ModuleGroup) visit(workflow.getDataflow());
pipeline = new Pipeline(version, moduleGroup, connections);
return pipeline;
}
/* (non-Javadoc)
* @see Taverna.Visitor.DFSVisitor#visit(Taverna.Tree.DataFlowImpl.Dataflow)
*/
public Object visit(Dataflow dataflow){
ModuleGroup myModuleGroup = null;
String id = "workflow_1";
String name = "workflow";
final String myPackage = "";
final String version = "0.1";
String description = "";
Authors authors = null;
final String icon = "";
final int rotation = 0;
final int posX = 0;
final int posY = 0;
final boolean needsProvenance = false;
//Annotation assignment
try{
AnnotationContent annotationContent=new AnnotationContent();
annotationContent=(AnnotationContent) annotationVisitor.visit(dataflow.getAnnotations());
if (annotationContent.name!=null){
name=annotationContent.name;
}
if (annotationContent.iD!=null){
id=annotationContent.iD;
}
if (annotationContent.description!=null){
description=annotationContent.description;
}
}catch (Exception e) {
Printer.log("No Annotation");
}
myModuleGroup = new ModuleGroup( id, name, myPackage,
version, description, icon, rotation,
posX, posY, needsProvenance, authors);
//This is used to create the input and output modules if there are---important
try{
List<DataModule> inputDataModules = (List<DataModule>)dataFlowImplVisitor.visit(dataflow.getInputPorts());
if(inputDataModules.size() > 0){
for(DataModule d : inputDataModules){
myModuleGroup.getModules().add(d);
}
}
} catch (Exception e){
Printer.log("No InputPorts");
}
try{
List<DataModule> outputDataModules = (List<DataModule>)dataFlowImplVisitor.visit(dataflow.getOutputPorts());
if(outputDataModules.size() > 0){
for(DataModule d : outputDataModules){
myModuleGroup.getModules().add(d);
}
}
} catch (Exception e){
Printer.log("No OutputPorts");
}
List<GraphObject> procs = (List<GraphObject>) dataFlowImplVisitor.visit(dataflow.getProcessors());
if(procs != null)
myModuleGroup.getModules().addAll(procs);
return myModuleGroup;
}
}