taverna-player 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.rdoc CHANGED
@@ -1,5 +1,16 @@
1
1
  = Changes log for Taverna Player
2
2
 
3
+ == Version 0.4.0
4
+
5
+ * [TAV-466] Add port metadata to JSON output.
6
+ * [TAV-472] Fix port model overriding stubs.
7
+ * Add methods to query a port value's type.
8
+ * Add a method to get a port value's size.
9
+ * Add protection for value size and type methods.
10
+ * Check that index lists are not altered.
11
+ * Use the new port value methods in the port renderer.
12
+ * [TAV-473] Get all values types directly from a port.
13
+
3
14
  == Version 0.3.0
4
15
 
5
16
  * Refactor callback code out into its own module.
data/README.rdoc CHANGED
@@ -372,6 +372,11 @@ clashes.
372
372
  If you wanted to add a before filter to authenticate your users you would add
373
373
  that line before the +include+ statement, for example.
374
374
 
375
+ <b>Important note!</b> If you override the RunPort model then you _must_
376
+ override the RunPort::Input and RunPort::Output models too (even if you just
377
+ leave the generated stubs unedited). This is because they are subclasses of
378
+ RunPort and the inheritances must be re-established with the overridden model.
379
+
375
380
  == Run callbacks
376
381
 
377
382
  Taverna Player provides four points around a workflow run for you to specify
@@ -36,6 +36,37 @@ module TavernaPlayer
36
36
  # Show up to the first 256 characters of the port's value. This returns
37
37
  # nil if the port has a file instead of a value.
38
38
 
39
+ ##
40
+ # :method: value_size
41
+ # :call-seq:
42
+ # value_size -> string
43
+ # value_size(indices) -> string
44
+ #
45
+ # Get the size (in bytes) of the value held in this port. Pass in a list
46
+ # of indices if it is a list port. Returns nil if there is no port
47
+ # metadata.
48
+
49
+ ##
50
+ # :method: value_type
51
+ # :call-seq:
52
+ # value_type -> string
53
+ # value_type(indices) -> string
54
+ #
55
+ # Get the MIME type of the value held in this port. Pass in a list of
56
+ # indices if it is a list port. Returns "text/plain" if there is no port
57
+ # metadata so if you create a port and put any other type of data in then
58
+ # you should adjust the metadata to match.
59
+
60
+ ##
61
+ # :method: value_is_text?
62
+ # :call-seq:
63
+ # value_is_text? -> string
64
+ # value_is_text?(indices) -> string
65
+ #
66
+ # Is the type of the value held in this port some sort of text? This
67
+ # returns true if the media type section of the MIME type is "text". Pass
68
+ # in a list of indices if it is a list port.
69
+
39
70
  ##
40
71
  # :method: value
41
72
  # :call-seq:
@@ -6,6 +6,8 @@ if @run.outputs.size > 0
6
6
  json.outputs @run.outputs do |output|
7
7
  json.name output.name
8
8
  json.depth output.depth
9
+ json.type output.metadata[:type]
10
+ json.size output.metadata[:size]
9
11
  json.uri run_path(@run) + "/output/#{output.name}"
10
12
  end
11
13
 
@@ -19,7 +19,7 @@ module TavernaPlayer
19
19
  "customization."
20
20
 
21
21
  def copy_models
22
- ["run.rb", "run_port.rb", "input.rb", "output.rb"].each do |file|
22
+ ["run.rb", "run_port.rb"].each do |file|
23
23
  copy_file file, "app/models/taverna_player/#{file}"
24
24
  end
25
25
  end
@@ -17,4 +17,18 @@ module TavernaPlayer
17
17
 
18
18
  # Extend the RunPort model here.
19
19
  end
20
+
21
+ class RunPort::Input < RunPort
22
+ # Do not remove the next line.
23
+ include TavernaPlayer::Concerns::Models::Input
24
+
25
+ # Extend the RunPort::Input model here.
26
+ end
27
+
28
+ class RunPort::Output < RunPort
29
+ # Do not remove the next line.
30
+ include TavernaPlayer::Concerns::Models::Output
31
+
32
+ # Extend the RunPort::Output model here.
33
+ end
20
34
  end
@@ -17,6 +17,8 @@ module TavernaPlayer
17
17
 
18
18
  extend ActiveSupport::Concern
19
19
 
20
+ include TavernaPlayer::Concerns::Utils
21
+
20
22
  included do
21
23
 
22
24
  MAXIMUM_DATABASE_VALUE_SIZE = 255
@@ -88,21 +90,42 @@ module TavernaPlayer
88
90
  data
89
91
  end
90
92
 
93
+ def value_metadata(field, *indices)
94
+ return if metadata.nil?
95
+ index = [*indices].flatten
96
+ recurse_into_lists(metadata[field], index)
97
+ end
98
+
91
99
  end # included
92
100
 
93
101
  def display_name
94
102
  name.gsub('_', ' ')
95
103
  end
96
104
 
105
+ def value_type(*indices)
106
+ value_metadata(:type, *indices) || "text/plain"
107
+ end
108
+
109
+ def value_is_text?(*indices)
110
+ type = value_type(*indices)
111
+ type.starts_with?("text")
112
+ end
113
+
114
+ def value_size(*indices)
115
+ value_metadata(:size, *indices)
116
+ end
117
+
97
118
  def value_preview
98
119
  self[:value]
99
120
  end
100
121
 
101
122
  def value(*indices)
102
123
  if depth == 0
103
- v = self[:value]
104
-
105
- (!v.blank? && !file.path.blank?) ? File.read(file.path) : v
124
+ if file.path.blank?
125
+ self[:value]
126
+ else
127
+ value_is_text? ? File.read(file.path) : File.binread(file.path)
128
+ end
106
129
  else
107
130
  deep_value([*indices].flatten)
108
131
  end
@@ -21,7 +21,6 @@ module TavernaPlayer
21
21
  # etc) available to them.
22
22
  class PortRenderer
23
23
  include TavernaPlayer::Concerns::Callback
24
- include TavernaPlayer::Concerns::Utils
25
24
 
26
25
  # The renderers are all called in the scope of this class so we include
27
26
  # ActionView::Helpers here so that they are all available to them.
@@ -96,7 +95,7 @@ module TavernaPlayer
96
95
  if port.depth > 0 && index.empty?
97
96
  renderer = @hash[:list]
98
97
  else
99
- type = MIME::Types[recurse_into_lists(port.metadata[:type], index.dup)].first
98
+ type = MIME::Types[port.value_type(index)].first
100
99
  renderer = @hash[type.media_type][type.sub_type] ||
101
100
  @hash[type.media_type][:default] || @hash[:default]
102
101
  end
@@ -11,5 +11,5 @@
11
11
  #------------------------------------------------------------------------------
12
12
 
13
13
  module TavernaPlayer
14
- VERSION = "0.3.0"
14
+ VERSION = "0.4.0"
15
15
  end
@@ -53,3 +53,10 @@ five:
53
53
  run_id: 4
54
54
  depth: 0
55
55
  metadata: "---\n:size: 33\n:type: text/plain"
56
+
57
+ six:
58
+ name: Output
59
+ port_type: TavernaPlayer::RunPort::Output
60
+ run_id: 2
61
+ depth: 2
62
+ metadata: "---\n:size:\n- - 15\n - 20\n- - 17\n - 22\n- - 19\n - 24\n:type:\n- - text/plain\n - text/plain\n- - text/plain\n - text/plain\n- - text/plain\n - text/plain\n"
@@ -19,6 +19,7 @@ module TavernaPlayer
19
19
  @port2 = taverna_player_run_ports(:two)
20
20
  @port3 = taverna_player_run_ports(:three)
21
21
  @port5 = taverna_player_run_ports(:five)
22
+ @port6 = taverna_player_run_ports(:six)
22
23
  end
23
24
 
24
25
  test "run port inheritance types" do
@@ -175,7 +176,7 @@ module TavernaPlayer
175
176
  port = RunPort::Input.create(:name => "test_port", :value => "test",
176
177
  :file => file)
177
178
 
178
- assert port.value.blank?, "Value should be blank"
179
+ assert port[:value].blank?, "Value should be blank"
179
180
  refute port.file.blank?, "File should be present"
180
181
  end
181
182
 
@@ -184,7 +185,7 @@ module TavernaPlayer
184
185
  port = RunPort::Output.create(:name => "test_port", :value => "test",
185
186
  :file => file)
186
187
 
187
- assert port.value.blank?, "Value should be blank"
188
+ assert port[:value].blank?, "Value should be blank"
188
189
  refute port.file.blank?, "File should be present"
189
190
  end
190
191
 
@@ -196,7 +197,7 @@ module TavernaPlayer
196
197
  port.value = "test"
197
198
  port.save
198
199
 
199
- assert port.value.blank?, "Value should be blank"
200
+ assert port[:value].blank?, "Value should be blank"
200
201
  refute port.file.blank?, "File should be present"
201
202
  end
202
203
 
@@ -208,7 +209,7 @@ module TavernaPlayer
208
209
  port.value = "test"
209
210
  port.save
210
211
 
211
- assert port.value.blank?, "Value should be blank"
212
+ assert port[:value].blank?, "Value should be blank"
212
213
  refute port.file.blank?, "File should be present"
213
214
  end
214
215
 
@@ -283,7 +284,7 @@ module TavernaPlayer
283
284
 
284
285
  port.file = fixture_file_upload "/files/crassostrea_gigas.csv"
285
286
  port.save
286
- assert_nil port.value, "Port value not nil"
287
+ assert_nil port[:value], "Port value not nil"
287
288
  refute port.file.blank?, "File not present"
288
289
  end
289
290
 
@@ -305,5 +306,55 @@ module TavernaPlayer
305
306
  assert_nil port.value, "Port value not nil"
306
307
  assert port.file.blank?, "File not present"
307
308
  end
309
+
310
+ test "get value types" do
311
+ assert_equal "text/plain", @port1.value_type, "Type not text/plain"
312
+ assert_equal "text/plain", @port2.value_type(1), "Type not text/plain"
313
+ assert_equal "application/x-error", @port2.value_type(2),
314
+ "Type not application/x-error"
315
+ assert_equal "text/plain", @port3.value_type, "Type not text/plain"
316
+ assert_equal "text/plain", @port6.value_type(0, 0),
317
+ "Type not text/plain"
318
+ assert_equal "text/plain", @port6.value_type([2, 1]),
319
+ "Type not text/plain"
320
+
321
+ # Test when there is no metadata
322
+ port = RunPort::Input.create(:name => "test_port", :value => "Test")
323
+ assert_equal "text/plain", port.value_type,
324
+ "Unspecified type should return \"text/plain\""
325
+ assert port.value_is_text?, "Unspecified type should be text"
326
+ assert_nil port.value_size, "Unspecified size should return nil"
327
+ end
328
+
329
+ test "detecting text values" do
330
+ assert @port1.value_is_text?, "Value not detected as text"
331
+ assert @port2.value_is_text?(0), "Value not detected as text"
332
+ assert @port3.value_is_text?, "Value not detected as text"
333
+ assert @port6.value_is_text?(0, 0), "Value not detected as text"
334
+ assert @port6.value_is_text?([1, 1]), "Value not detected as text"
335
+ refute @port2.value_is_text?(2), "Value detected as text"
336
+ end
337
+
338
+ test "get value sizes" do
339
+ assert_equal 13, @port1.value_size, "Value size not 13"
340
+ assert_equal 974, @port2.value_size(2), "Value size not 974"
341
+ assert_equal 3, @port3.value_size, "Value size not 3"
342
+ assert_equal 15, @port6.value_size([0, 0]), "Value size not 15"
343
+ assert_equal 24, @port6.value_size([2, 1]), "Value size not 24"
344
+ end
345
+
346
+ test "value methods should not alter input parameters" do
347
+ index = [1, 1]
348
+ index_saved = index.dup
349
+
350
+ @port6.value_type(index)
351
+ assert_equal index_saved, index, "Parameter index was altered"
352
+
353
+ @port6.value_is_text?(index)
354
+ assert_equal index_saved, index, "Parameter index was altered"
355
+
356
+ @port6.value_size(index)
357
+ assert_equal index_saved, index, "Parameter index was altered"
358
+ end
308
359
  end
309
360
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taverna-player
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-10 00:00:00.000000000 Z
12
+ date: 2013-12-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -322,8 +322,6 @@ files:
322
322
  - lib/generators/templates/callbacks/worker_callbacks.rb
323
323
  - lib/generators/templates/controllers/runs_controller.rb
324
324
  - lib/generators/templates/controllers/service_credentials_controller.rb
325
- - lib/generators/templates/models/input.rb
326
- - lib/generators/templates/models/output.rb
327
325
  - lib/generators/templates/models/run.rb
328
326
  - lib/generators/templates/models/run_port.rb
329
327
  - lib/generators/templates/player_initializer.rb
@@ -456,7 +454,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
456
454
  version: '0'
457
455
  segments:
458
456
  - 0
459
- hash: 1554949292676939893
457
+ hash: -1589530692801981432
460
458
  required_rubygems_version: !ruby/object:Gem::Requirement
461
459
  none: false
462
460
  requirements:
@@ -465,7 +463,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
465
463
  version: '0'
466
464
  segments:
467
465
  - 0
468
- hash: 1554949292676939893
466
+ hash: -1589530692801981432
469
467
  requirements: []
470
468
  rubyforge_project:
471
469
  rubygems_version: 1.8.21
@@ -1,20 +0,0 @@
1
- #------------------------------------------------------------------------------
2
- # Copyright (c) 2013 The University of Manchester, UK.
3
- #
4
- # BSD Licenced. See LICENCE.rdoc for details.
5
- #
6
- # Taverna Player was developed in the BioVeL project, funded by the European
7
- # Commission 7th Framework Programme (FP7), through grant agreement
8
- # number 283359.
9
- #
10
- # Author: Robert Haines
11
- #------------------------------------------------------------------------------
12
-
13
- module TavernaPlayer
14
- class RunPort::Input < ActiveRecord::Base
15
- # Do not remove the next line.
16
- include TavernaPlayer::Concerns::Models::Input
17
-
18
- # Extend the RunPort::Input model here.
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- #------------------------------------------------------------------------------
2
- # Copyright (c) 2013 The University of Manchester, UK.
3
- #
4
- # BSD Licenced. See LICENCE.rdoc for details.
5
- #
6
- # Taverna Player was developed in the BioVeL project, funded by the European
7
- # Commission 7th Framework Programme (FP7), through grant agreement
8
- # number 283359.
9
- #
10
- # Author: Robert Haines
11
- #------------------------------------------------------------------------------
12
-
13
- module TavernaPlayer
14
- class RunPort::Output < ActiveRecord::Base
15
- # Do not remove the next line.
16
- include TavernaPlayer::Concerns::Models::Output
17
-
18
- # Extend the RunPort::Output model here.
19
- end
20
- end