|
From: | noreply |
Subject: | [myexperiment-hackers] [2271] trunk: bulk workflow upload via zip files |
Date: | Fri, 11 Sep 2009 11:19:14 -0400 (EDT) |
bulk workflow upload via zip files
--- trunk/app/controllers/workflows_controller.rb 2009-09-11 15:14:13 UTC (rev 2270)
+++ trunk/app/controllers/workflows_controller.rb 2009-09-11 15:19:14 UTC (rev 2271)
@@ -3,15 +3,17 @@
# Copyright (c) 2007 University of Manchester and the University of Southampton.
# See license.txt for details.
+require 'zip/zip'
+
class WorkflowsController < ApplicationController
before_filter :login_required, :except => [:index, :show, :download, :named_download, :statistics, :launch, :search, :all]
before_filter :find_workflows, : [:all]
before_filter :find_workflows_rss, : [:index]
- before_filter :find_workflow_auth, :except => [:search, :index, :new, :create, :all]
+ before_filter :find_workflow_auth, :except => [:search, :index, :new, :create, :all, :bulk_upload, :bulk_create, :bulk_summary]
- before_filter :initiliase_empty_objects_for_new_pages, : [:new, :create, :new_version, :create_version]
- before_filter :set_sharing_mode_variables, : [:show, :new, :create, :edit, :update]
+ before_filter :initiliase_empty_objects_for_new_pages, : [:new, :create, :new_version, :create_version, :bulk_upload]
+ before_filter :set_sharing_mode_variables, : [:show, :new, :create, :edit, :update, :bulk_upload]
before_filter :check_file_size, : [:create, :create_version]
before_filter :check_custom_workflow_type, : [:create, :create_version]
@@ -19,11 +21,11 @@
before_filter :check_is_owner, : [:edit, :update]
# declare sweepers and which actions should invoke them
- cache_sweeper :workflow_sweeper, : [ :create, :create_version, :launch, :update, :update_version, :destroy_version, :destroy ]
+ cache_sweeper :workflow_sweeper, : [ :create, :bulk_create, :create_version, :launch, :update, :update_version, :destroy_version, :destroy ]
cache_sweeper :download_viewing_sweeper, : [ :show, :download, :named_download, :launch ]
- cache_sweeper :permission_sweeper, : [ :create, :update, :destroy ]
+ cache_sweeper :permission_sweeper, : [ :create, :bulk_create, :update, :destroy ]
cache_sweeper :bookmark_sweeper, : [ :destroy, :favourite, :favourite_delete ]
- cache_sweeper :tag_sweeper, : [ :create, :update, :tag, :destroy ]
+ cache_sweeper :tag_sweeper, : [ :create, :bulk_create, :update, :tag, :destroy ]
cache_sweeper :comment_sweeper, : [ :comment, :comment_delete ]
cache_sweeper :rating_sweeper, : [ :rate ]
@@ -244,6 +246,14 @@
def new
end
+ # GET /workflows/bulk_upload
+ def bulk_upload
+ end
+
+ # GET /workflows/bulk_summary
+ def bulk_summary
+ end
+
# GET /workflows/1/new_version
def new_version
end
@@ -428,6 +438,93 @@
end
+ # POST /workflows/bulk_create
+
+ def bulk_create
+
+ def aux(file)
+
+ @workflow = Workflow.new
+ @workflow.contributor = current_user
+ @workflow.last_edited_by = current_user.id
+ @workflow.license_id = params[:workflow][:license_id]
+ @workflow.content_blob = ContentBlob.new(:data ="" file.read)
+ @workflow.file_ext = file.original_filename.split(".").last.downcase
+
+ # Check that the file uploaded is recognised and can be parsed...
+
+ if infer_metadata(@workflow, file) == false
+ flash.now[:error] = "Couldn't recognise a workflow during bulk"
+ " upload. Currently, only workflows that can be automatically"
+ " recognised can be bulk uploaded."
+ return false
+ end
+
+ return false unless @workflow.save
+
+ if params[:workflow][:tag_list]
+ @workflow.refresh_tags(convert_tags_to_gem_format(params[:workflow][:tag_list]), current_user)
+ end
+
+ update_policy(@workflow, params)
+ update_credits(@workflow, params)
+ update_attributions(@workflow, params)
+
+ @titles.push(@workflow.title)
+
+ return true
+ end
+
+ # Unpack multiple workflows from the zip file
+
+ @results = []
+ @titles = []
+ @failures = []
+ @overall_success = true
+
+ file = params[:workflow][:file]
+
+ Tempfile.open("bulk", "tmp") { |zip_file|
+
+ zip_file.write(file.read)
+ zip_file.open
+
+ begin
+ Workflow.transaction do
+
+ Zip::ZipFile.foreach(zip_file.path) { |entry|
+ if entry.file?
+ stream = entry.get_input_stream
+ stream.extend FileUpload
+ stream.original_filename = entry.name
+
+ if aux(stream) == false
+ @overall_success = false
+ @results.push([entry.name, false])
+ else
+ @results.push([entry.name, true])
+ end
+
+ end
+ }
+
+ raise BulkUploadError unless @overall_success
+
+ end
+ rescue BulkUploadError
+ # Here so that the transaction will rollback upon failure
+ end
+ }
+
+ if @overall_success
+ flash[:notice] = "Bulk upload successful."
+ else
+ flash[:error] = "Failed to process all entries."
+ end
+
+ render(:action ="" :bulk_summary)
+ end
+
# PUT /workflows/1
def update
# remove protected columns
@@ -672,7 +769,7 @@
end
def initiliase_empty_objects_for_new_pages
- if ["new", "create"].include?(action_name)
+ if ["new", "create", "bulk_upload"].include?(action_name)
@workflow = Workflow.new
end
@@ -702,7 +799,7 @@
def set_sharing_mode_variables
case action_name
- when "new"
+ when "new", "bulk_upload"
@sharing_mode = 0
@updating_mode = 6
when "create", "update"
--- trunk/app/helpers/application_helper.rb 2009-09-11 15:14:13 UTC (rev 2270)
+++ trunk/app/helpers/application_helper.rb 2009-09-11 15:19:14 UTC (rev 2271)
@@ -768,6 +768,8 @@
return "famfamfam_silk/application_edit.png"
when "license"
return "famfamfam_silk/text_signature.png"
+ when "home"
+ return "famfamfam_silk/application_home.png"
else
return Conf.label_icons[method.to_s] if Conf.label_icons[method.to_s]
end
--- trunk/app/models/vocabulary.rb 2009-09-11 15:14:13 UTC (rev 2270)
+++ trunk/app/models/vocabulary.rb 2009-09-11 15:19:14 UTC (rev 2271)
@@ -7,6 +7,8 @@
belongs_to :user
+ has_many :tags, :dependent => :destroy
+
validates_presence_of :title
format_attribute :description
--- trunk/app/views/workflows/bulk_summary.rhtml (rev 0)
+++ trunk/app/views/workflows/bulk_summary.rhtml 2009-09-11 15:19:14 UTC (rev 2271)
@@ -0,0 +1,57 @@
+<% t "Bulk upload" -%>
+
+<center><%= error_messages_for :workflow -%></center>
+
+<h1>Bulk upload summary</h1>
+
+<div class="clearer"> </div>
+
+<center>
+ <table class="simple">
+ <tr><th>Entry</th><th>Status</th></tr>
+ <% @results.each do |result| %>
+ <tr>
+ <td><%= result[0] %></td>
+ <% if result[1] %>
+ <td><img src="" /></td>
+ <% else %>
+ <td><img src="" /></td>
+ <% end %>
+ </tr>
+ <% end %>
+ </table>
+</center>
+
+<div class="clearer"> </div>
+<div class="clearer"> </div>
+
+<% if @overall_success %>
+ <center>
+ <ul class="sectionIcons">
+ <li style="margin-left: 0;">
+ <%= icon 'new',
+ "/workflows/bulk_upload",
+ "Bulk upload",
+ nil,
+ "Upload more" -%>
+ </li>
+ <li style="margin-left: 0;">
+ <%= icon 'home',
+ "/home",
+ "Return to the home page",
+ nil,
+ "Finished" -%>
+ </li>
+ </ul>
+ </center>
+
+<% else %>
+ <div class="box_infotext">
+ <p>
+ Nothing was uploaded to <%= Conf.sitename %>. To try the bulk upload
+ again, use your browser's back button to return to the bulk upload page
+ and select to new Zip file.
+ </p>
+ </div>
+<% end %>
+
--- trunk/app/views/workflows/bulk_upload.rhtml (rev 0)
+++ trunk/app/views/workflows/bulk_upload.rhtml 2009-09-11 15:19:14 UTC (rev 2271)
@@ -0,0 +1,68 @@
+<% t "Bulk upload" -%>
+
+<%= _javascript__include_tag :fckeditor %>
+<%= _javascript__include_tag "osp.js" %>
+
+<h1>Bulk upload</h1>
+
+<center>
+ <%= error_messages_for :workflow %>
+</center>
+
+<% form_tag({:action ="" :bulk_create}, :multipart => true) do %>
+
+ <!-- Workflow File -->
+
+ <p class="step_text">1. Zip file containing Workflow files/scripts</p>
+
+ <div class="box_infotext">
+ <p>Select a Zip file containing multiple Workflow files. Note that
+ <%= Conf.sitename %> must be able to automatically recognise and extract
+ metadata from your Workflows to use this feature.</p>
+ </div>
+
+ <br />
+ <br />
+
+ <center>
+ <%= render :partial => 'workflow_file_selection_form' %>
+ </center>
+
+ <br />
+
+ <!-- Other metadata and settings -->
+
+ <p class="step_text" style="text-align: center;">2. Other metadata and settings</p>
+
+ <!-- Tags -->
+ <%= render :partial => "tags/tags_form", :locals => { :edit => false, :taggable => @workflow } -%>
+
+ <!-- Credit and Attribution -->
+ <%= render :partial => "contributions/credit_attribution_form", :locals => { :edit => false, :contributable => @workflow } -%>
+
+ <!-- Sharing -->
+ <%= render :partial => "contributions/sharing_form", :locals => { :edit => false, :contributable => @workflow, :update_perms => true } -%>
+
+ <!-- License/Rights -->
+ <%= render :partial => "workflows/license_form", :locals => { :edit => false } -%>
+
+
+ <!-- Terms and conditions -->
+
+ <p class="step_text">3. Terms and conditions</p>
+
+ <%= render :partial => 'contributions/terms_and_conditions' %>
+
+ <br/>
+
+ <!-- Upload and save -->
+
+ <p class="step_text">4. Upload and save</p>
+
+ <p style="text-align: center;">
+ <%= submit_tag "Upload and Save", :disable_with => "Uploading and saving..." %>
+ </p>
+
+<% end %>
+
+
--- trunk/app/views/workflows/index.rhtml 2009-09-11 15:14:13 UTC (rev 2270)
+++ trunk/app/views/workflows/index.rhtml 2009-09-11 15:19:14 UTC (rev 2271)
@@ -7,6 +7,7 @@
<ul class="sectionIcons">
<li><%= icon "workflow", new_workflow_path, nil, nil, "Upload New Workflow" %></li>
+ <li><%= icon "workflow", bulk_upload_workflows_path, nil, nil, "Bulk Upload" %></li>
<li><%= icon "view-all", all_workflows_path, nil, nil, "View All Workflows" %></li>
</ul>
--- trunk/app/views/workflows/new.rhtml 2009-09-11 15:14:13 UTC (rev 2270)
+++ trunk/app/views/workflows/new.rhtml 2009-09-11 15:19:14 UTC (rev 2271)
@@ -3,6 +3,14 @@
<%= _javascript__include_tag :fckeditor %>
<%= _javascript__include_tag "osp.js" %>
+<div class="box_standout" style="margin: 1.5em 3em; padding: 0.7em 1.5em;">
+ <p>
+ Do you have many Workflows to upload? Use the <a
+ href="" upload</a> page to upload multiple
+ Workflows at the same time.
+ </p>
+</div>
+
<h1>Upload Workflow</h1>
<center>
--- trunk/config/routes.rb 2009-09-11 15:14:13 UTC (rev 2270)
+++ trunk/config/routes.rb 2009-09-11 15:19:14 UTC (rev 2271)
@@ -62,7 +62,11 @@
# workflows (downloadable)
map.resources :workflows,
- :collection => { :all => :get, :search => :get },
+ :collection => { :all => :get,
+ :search => :get,
+ :bulk_upload => :get,
+ :bulk_create => :post,
+ :bulk_summary => :get },
:member => { :new_version => :get,
:download => :get,
:launch => :get,
--- trunk/lib/bulk_upload_error.rb (rev 0)
+++ trunk/lib/bulk_upload_error.rb 2009-09-11 15:19:14 UTC (rev 2271)
@@ -0,0 +1,8 @@
+# myExperiment: lib/bulk_upload_error.rb
+#
+# Copyright (c) 2009 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class BulkUploadError < StandardError
+end
+
[Prev in Thread] | Current Thread | [Next in Thread] |