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:05 UTC

[39/50] [abbrv] incubator-taverna-databundle-viewer git commit: Move extract data_bundle from controller to model. Add validation on field file

Move extract data_bundle from controller to model. Add validation on field file


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/dc1a9681
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/tree/dc1a9681
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/diff/dc1a9681

Branch: refs/heads/master
Commit: dc1a9681b0c2620d2b144a8af9675f5ccd1ea46c
Parents: a13a6c8
Author: Denis Karyakin <sa...@gmail.com>
Authored: Wed Aug 19 02:46:39 2015 +0300
Committer: Denis Karyakin <sa...@gmail.com>
Committed: Wed Aug 19 02:46:39 2015 +0300

----------------------------------------------------------------------
 app/controllers/data_bundles_controller.rb | 2 --
 app/models/data_bundle.rb                  | 9 ++++++++-
 2 files changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/blob/dc1a9681/app/controllers/data_bundles_controller.rb
----------------------------------------------------------------------
diff --git a/app/controllers/data_bundles_controller.rb b/app/controllers/data_bundles_controller.rb
index 0510b43..42800f1 100644
--- a/app/controllers/data_bundles_controller.rb
+++ b/app/controllers/data_bundles_controller.rb
@@ -43,8 +43,6 @@ class DataBundlesController < ApplicationController
     @data_bundle = current_user.databundles.new(data_bundle_params)
 
     if @data_bundle.save
-      Archive::Zip.extract(@data_bundle.file.path, "#{@data_bundle.file_path}")
-      Archive::Zip.extract("#{@data_bundle.file_path}workflow.wfbundle", "#{@data_bundle.file_path}#{DataBundle::EXTRACTED_WORKFLOW_PATH}")
       redirect_to @data_bundle, notice: 'Data bundle was successfully created.'
     else
       render :edit

http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/blob/dc1a9681/app/models/data_bundle.rb
----------------------------------------------------------------------
diff --git a/app/models/data_bundle.rb b/app/models/data_bundle.rb
index 13455a6..3fbd5c8 100644
--- a/app/models/data_bundle.rb
+++ b/app/models/data_bundle.rb
@@ -23,7 +23,9 @@ class DataBundle < ActiveRecord::Base
 
   belongs_to :user
 
-  validates :user_id, presence: true
+  validates :user_id, :file, presence: true
+
+  after_create :extract_file
 
   EXTRACTED_DIRECTORY = 'extracted_source'
   EXTRACTED_WORKFLOW_PATH = 'workflow_source'
@@ -31,4 +33,9 @@ class DataBundle < ActiveRecord::Base
   def file_path
     "#{file.root}/#{file.store_dir}/#{EXTRACTED_DIRECTORY}/"
   end
+
+  def extract_file
+    Archive::Zip.extract(file.path, "#{file_path}")
+    Archive::Zip.extract("#{file_path}workflow.wfbundle", "#{file_path}#{DataBundle::EXTRACTED_WORKFLOW_PATH}")
+  end
 end