You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by al...@apache.org on 2015/08/24 13:42:08 UTC
[42/50] [abbrv] incubator-taverna-databundle-viewer git commit:
Update data_bundle decorator,
write tests. Prepared for use in show data_bundle content
Update data_bundle decorator, write tests. Prepared for use in show data_bundle content
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/commit/86fee27e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/tree/86fee27e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/diff/86fee27e
Branch: refs/heads/master
Commit: 86fee27ef42052a3a8eb02a8842778b13c775756
Parents: d48c7aa
Author: Denis Karyakin <sa...@gmail.com>
Authored: Wed Aug 19 23:18:22 2015 +0300
Committer: Denis Karyakin <sa...@gmail.com>
Committed: Wed Aug 19 23:18:22 2015 +0300
----------------------------------------------------------------------
app/decorators/data_bundle_decorator.rb | 36 +++++++++++++++++++++-
spec/decorators/data_bundle_decorator_spec.rb | 21 +++++++++++++
2 files changed, 56 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/blob/86fee27e/app/decorators/data_bundle_decorator.rb
----------------------------------------------------------------------
diff --git a/app/decorators/data_bundle_decorator.rb b/app/decorators/data_bundle_decorator.rb
index c9eb6a8..6eda270 100644
--- a/app/decorators/data_bundle_decorator.rb
+++ b/app/decorators/data_bundle_decorator.rb
@@ -28,10 +28,20 @@ class DataBundleDecorator < Draper::Decorator
FILE_TYPES.each do |type_key, type_name|
define_method :"#{type_key}" do
- manifest['aggregates'].select { |files| files['folder'].start_with?(type_name) }
+ files = manifest['aggregates'].select { |files| files['folder'].start_with?(type_name) }
+ result = {}
+ files.each do |file|
+ key = file['file'].split('/').last.split('.').first
+ result[key] = file_content(file['file'])
+ end
+ return result
end
end
+ def file_content(file)
+ File.new("#{object.file_path}#{file}", 'r').read
+ end
+
def manifest
if @manifest.nil?
file = File.new("#{object.file_path}.ro/manifest.json", 'r')
@@ -51,4 +61,28 @@ class DataBundleDecorator < Draper::Decorator
@workflow
end
+
+ def to_json
+ stream = []
+ workflow.datalinks.each { |link| stream << write_link(link, workflow) }
+ stream
+ end
+
+ def write_link(link, dataflow)
+ stream = {}
+ if dataflow.sources.select { |s| s.name == link.source } != []
+ stream[:source] = link.source
+ stream[:file_content] = inputs[link.source] unless inputs[link.source].nil?
+ else
+ processor = dataflow.processors.select { |p| p.name == link.source.split(':')[0] }[0]
+ stream[:source] = processor.name
+ end
+ if dataflow.sinks.select { |s| s.name == link.sink } != []
+ stream[:target] = link.sink
+ else
+ processor = dataflow.processors.select { |p| p.name == link.sink.split(':')[0] }[0]
+ stream[:target] = processor.name
+ end
+ stream
+ end
end
http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/blob/86fee27e/spec/decorators/data_bundle_decorator_spec.rb
----------------------------------------------------------------------
diff --git a/spec/decorators/data_bundle_decorator_spec.rb b/spec/decorators/data_bundle_decorator_spec.rb
index 3bd1e88..4ae890d 100644
--- a/spec/decorators/data_bundle_decorator_spec.rb
+++ b/spec/decorators/data_bundle_decorator_spec.rb
@@ -20,4 +20,25 @@
require 'spec_helper'
describe DataBundleDecorator do
+ let(:data_bundle) { create(:data_bundle).decorate }
+
+ it '#inputs' do
+ expected_result = Hash.new
+ expected_result['name'] = 'Denis'
+ expect(data_bundle.inputs).to include expected_result
+ end
+
+ it '#intermediates' do
+ expected_result = Hash.new
+ expected_result['2d812fc1-dfec-42cb-bef9-87b3ce9c9e2d'] = 'Hello, '
+
+ expect(data_bundle.intermediates).to include expected_result
+ end
+
+ it '#outputs' do
+ expected_result = Hash.new
+ expected_result['greeting'] = 'Hello, Denis'
+
+ expect(data_bundle.outputs).to include expected_result
+ end
end