Class: T2Flow::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/t2flow/model.rb

Overview

The model for a given Taverna 2 workflow.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeModel

Creates an empty model for a Taverna 2 workflow.



14
15
16
# File 'lib/t2flow/model.rb', line 14

def initialize
  @dataflows = []
end

Instance Attribute Details

#dataflowsObject

The list of all the dataflows that make up the workflow.



8
9
10
# File 'lib/t2flow/model.rb', line 8

def dataflows
  @dataflows
end

#dependenciesObject

The list of any dependencies that have been found inside the workflow.



11
12
13
# File 'lib/t2flow/model.rb', line 11

def dependencies
  @dependencies
end

Instance Method Details

Retrieve ALL the datalinks within a nested workflow



46
47
48
49
50
# File 'lib/t2flow/model.rb', line 46

def all_datalinks
  links = []
  @dataflows.each { |dataflow| links << dataflow.datalinks }
  return links.flatten
end

#all_processorsObject

Retrieve ALL the processors found in a nested workflow



65
66
67
68
69
# File 'lib/t2flow/model.rb', line 65

def all_processors
  procs =[]
  @dataflows.each { |dataflow| procs << dataflow.processors }
  return procs.flatten
end

#all_sinksObject

Retrieve ALL the sinks(outputs) within the workflow



89
90
91
92
93
# File 'lib/t2flow/model.rb', line 89

def all_sinks
  sinks =[]
  @dataflows.each { |dataflow| sinks << dataflow.sinks }
  return sinks.flatten
end

#all_sourcesObject

Retrieve ALL the sources(inputs) within the workflow



77
78
79
80
81
# File 'lib/t2flow/model.rb', line 77

def all_sources
  sources =[]
  @dataflows.each { |dataflow| sources << dataflow.sources }
  return sources.flatten
end

#annotationsObject

Retrieve the annotations specific to the workflow. This does not return any annotations from workflows encapsulated within the main workflow.



54
55
56
# File 'lib/t2flow/model.rb', line 54

def annotations
  self.main.annotations
end

#beanshellsObject

Retrieve ALL the processors containing beanshells within the workflow.



30
31
32
# File 'lib/t2flow/model.rb', line 30

def beanshells
  self.all_processors.select { |x| x.type == "beanshell" }
end

#dataflow(df_id) ⇒ Object

Retrieve the dataflow with the given ID



24
25
26
27
# File 'lib/t2flow/model.rb', line 24

def dataflow(df_id)
  df = @dataflows.select { |x| x.dataflow_id == df_id }
  return df[0]
end

Retrieve the datalinks from the top level of a nested workflow. If the workflow is not nested, retrieve all datalinks.



41
42
43
# File 'lib/t2flow/model.rb', line 41

def datalinks
  self.main.datalinks
end

For the given dataflow, return the beanshells and/or services which have direct links to or from the given processor. If no dataflow is specified, the top-level dataflow is used. This does a recursive search in nested workflows.

Usage

my_processor = model.processor[0]
linked_processors = model.get_processors_linked_to(my_processor)
processors_feeding_into_my_processor = linked_processors.sources
processors_feeding_from_my_processor = linked_processors.sinks


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/t2flow/model.rb', line 109

def get_processor_links(processor)
  return nil unless processor
  proc_links = ProcessorLinks.new
  
  # SOURCES
  sources = self.all_datalinks.select { |x| x.sink =~ /#{processor.name}:.+/ }
  proc_links.sources = []

  # SINKS
  sinks = self.all_datalinks.select { |x| x.source =~ /#{processor.name}:.+/ }
  proc_links.sinks = []
  temp_sinks = []
  sinks.each { |x| temp_sinks << x.sink }
  
  # Match links by port into format
  # my_port:name_of_link_im_linked_to:its_port
  sources.each do |connection|
    link = connection.sink
    connected_proc_name = link.split(":")[0]
    my_connection_port = link.split(":")[1]
    
    if my_connection_port
      source = my_connection_port << ":" << connection.source
      proc_links.sources << source if source.split(":").size == 3
    end
  end
  
  sinks.each do |connection|
    link = connection.source
    connected_proc_name = link.split(":")[0]
    my_connection_port = link.split(":")[1]
    
    if my_connection_port
      sink = my_connection_port << ":" << connection.sink
      proc_links.sinks << sink if sink.split(":").size == 3
    end
  end
  
  return proc_links
end

#mainObject

Retrieve the top level dataflow ie the MAIN (containing) dataflow



19
20
21
# File 'lib/t2flow/model.rb', line 19

def main
  @dataflows[0]
end

#model_idObject

Retrieve the unique dataflow ID for the top level dataflow.



96
97
98
# File 'lib/t2flow/model.rb', line 96

def model_id
  self.main.dataflow_id
end

#processorsObject

Retrieve processors from the top level of a nested workflow. If the workflow is not nested, retrieve all processors.



60
61
62
# File 'lib/t2flow/model.rb', line 60

def processors
  self.main.processors
end

#sinksObject

Retrieve the sinks(outputs) to the workflow



84
85
86
# File 'lib/t2flow/model.rb', line 84

def sinks
  self.main.sinks
end

#sourcesObject

Retrieve the sources(inputs) to the workflow



72
73
74
# File 'lib/t2flow/model.rb', line 72

def sources
  self.main.sources
end

#web_servicesObject

Retrieve ALL processors of that are webservices WITHIN the model.



35
36
37
# File 'lib/t2flow/model.rb', line 35

def web_services
  self.all_processors.select { |x| x.type =~ /wsdl|soaplab|biomoby/i }
end