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.



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

def initialize
  @dataflows = []
  @dependencies = []
end

Instance Attribute Details

#dataflowsObject

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



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

def dataflows
  @dataflows
end

#dependenciesObject

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



28
29
30
# File 'lib/t2flow/model.rb', line 28

def dependencies
  @dependencies
end

Instance Method Details

#all_coordinationsObject

Retrieve ALL the coordinations found in a nested workflow



106
107
108
109
110
# File 'lib/t2flow/model.rb', line 106

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

Retrieve ALL the datalinks within a nested workflow



74
75
76
77
78
# File 'lib/t2flow/model.rb', line 74

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



93
94
95
96
97
# File 'lib/t2flow/model.rb', line 93

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

#all_sinksObject

Retrieve ALL the sinks(outputs) within the workflow



130
131
132
133
134
# File 'lib/t2flow/model.rb', line 130

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

#all_sourcesObject

Retrieve ALL the sources(inputs) within the workflow



118
119
120
121
122
# File 'lib/t2flow/model.rb', line 118

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.



82
83
84
# File 'lib/t2flow/model.rb', line 82

def annotations
  self.main.annotations
end

#beanshellsObject

Retrieve ALL the processors containing beanshells within the workflow.



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

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

#coordinationsObject

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



101
102
103
# File 'lib/t2flow/model.rb', line 101

def coordinations
  self.main.coordinations
end

#dataflow(df_id) ⇒ Object

Retrieve the dataflow with the given ID



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

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.



69
70
71
# File 'lib/t2flow/model.rb', line 69

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


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/t2flow/model.rb', line 150

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

#local_workersObject

Retrieve ALL local workers WITHIN the workflow



63
64
65
# File 'lib/t2flow/model.rb', line 63

def local_workers
  self.all_processors.select { |x| x.type =~ /local/i }
end

#mainObject

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



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

def main
  @dataflows[0]
end

#model_idObject

Retrieve the unique dataflow ID for the top level dataflow.



137
138
139
# File 'lib/t2flow/model.rb', line 137

def model_id
  self.main.dataflow_id
end

#nameObject

Retrieve the top level dataflow’s name



37
38
39
# File 'lib/t2flow/model.rb', line 37

def name
  main.name
end

#processorsObject

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



88
89
90
# File 'lib/t2flow/model.rb', line 88

def processors
  self.main.processors
end

#sinksObject

Retrieve the sinks(outputs) to the workflow



125
126
127
# File 'lib/t2flow/model.rb', line 125

def sinks
  self.main.sinks
end

#sourcesObject

Retrieve the sources(inputs) to the workflow



113
114
115
# File 'lib/t2flow/model.rb', line 113

def sources
  self.main.sources
end

#web_servicesObject

Retrieve ALL processors of that are webservices WITHIN the model.



58
59
60
# File 'lib/t2flow/model.rb', line 58

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