myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [3344] branches/wf4ever/app: Handle RO file uploa


From: noreply
Subject: [myexperiment-hackers] [3344] branches/wf4ever/app: Handle RO file upload and URI
Date: Wed, 23 Jan 2013 16:43:32 +0000 (UTC)

Revision
3344
Author
stain
Date
2013-01-23 16:43:32 +0000 (Wed, 23 Jan 2013)

Log Message

Handle RO file upload and URI

Multiple files supported. No error handling on actual upload yet.
No annotation made yet.

Modified Paths

Diff

Modified: branches/wf4ever/app/controllers/packs_controller.rb (3343 => 3344)


--- branches/wf4ever/app/controllers/packs_controller.rb	2013-01-23 16:43:26 UTC (rev 3343)
+++ branches/wf4ever/app/controllers/packs_controller.rb	2013-01-23 16:43:32 UTC (rev 3344)
@@ -132,39 +132,51 @@
     render :resource_show
   end
 
-  def create_resource
-
-    session = ROSRS::Session.new(@pack.ro_uri, Conf.rodl_bearer_token)
-
-    filename = File.basename(params[:data].original_filename) if params[:data]
-
-    case params[:commit]
-
-    when "Aggregate workflow"
-
-      c, r, puri, ruri = session.aggregate_internal_resource(@pack.ro_uri, filename, { :body => params[:data].read, :ctype=> 'text/plain' })
-
+  def transform_wf(ruri)
       service_uri = "http://sandbox.wf4ever-project.org/wf-ro/jobs"
       format = "application/vnd.taverna.t2flow+xml"
       token = Conf.rodl_bearer_token
-
       uri = Wf4Ever::TransformationClient.create_job(service_uri, ruri, format, @pack.ro_uri, token)
-
-    when "Aggregate internal resource"
-
-      c, r, puri, ruri = session.aggregate_internal_resource(@pack.ro_uri, filename, { :body => params[:data].read, :ctype=> 'text/plain' })
-
-    when "Aggregate external resource"
-
+      puts "################## Transforming at " + uri
+  end
+  
+  def create_resource
+    session = ROSRS::Session.new(@pack.ro_uri, Conf.rodl_bearer_token)
+    
+    no_item = true
+    if params[:file]
+      for file in params[:file]
+         no_item = false
+         filename = File.basename(file.original_filename)
+        ## FIXME: Content type should not always be text/plain!
+         c, r, puri, ruri = session.aggregate_internal_resource(@pack.ro_uri, filename, { :body => file.read, :ctype=> 'text/plain' })
+        ## NOTE: URI must match config/default_settings.yml ro_resource_types
+        if params[:type] == "http://purl.org/wf4ever/wfdesc#WorkflowDefinition"
+          transform_wf(ruri)
+        end
+      end
+    end
+      
+    if params[:uri] and not params[:uri].empty?
+         no_item = false
       c, r, puri, ruri = session.aggregate_external_resource(@pack.ro_uri, params[:uri])
+      if params[:type] == "http://purl.org/wf4ever/wfdesc#WorkflowDefinition"
+        transform_wf(ruri)
+      end
+    end
 
+    if no_item 
+      ## TODO: prettify error message, but don't use the broken error() function
+      # as it is not following HTTP standard error codes
+      return render :text => "Adding an item failed, either a URL or a file must be provided", :status => :bad_request
     end
-
+    
     respond_to do |format|
       format.html {
         redirect_to pack_url(@pack)
-      }
+      }    
     end
+    
   end
 
   def edit_resource_annotations

Modified: branches/wf4ever/app/views/packs/_add_item_ro.rhtml (3343 => 3344)


--- branches/wf4ever/app/views/packs/_add_item_ro.rhtml	2013-01-23 16:43:26 UTC (rev 3343)
+++ branches/wf4ever/app/views/packs/_add_item_ro.rhtml	2013-01-23 16:43:32 UTC (rev 3344)
@@ -29,11 +29,11 @@
     <% form_tag(create_resource_pack_path(@pack), :multipart => true, :method => :post, :class => :add_item_ro) do %>
 
       <div>
-        <label for=""
+        <label for=""
           <%= info_icon_with_tooltip("The type indicates the item's meaning in the pack.")  -%>
           Type:
         </label>
-        <%= select_tag (:ro_resource_type, options_for_select(Conf.ro_resource_types, 
+        <%= select_tag (:type, options_for_select(Conf.ro_resource_types, 
                           "http://purl.org/wf4ever/ro#Resource") )  -%>
       </div>
     
@@ -48,17 +48,16 @@
         </div>
       </div>
 
-      
       <div class="or">
-        -or-
+        -and/or-
       </div>
 
       <div>
-        <label for=""
+        <label for=""
           <%= info_icon_with_tooltip("Select a local file which will be uploaded as part of the pack") -%>
           Add File:
         </label>
-        <%= file_field_tag :file, {:multiple => :multiple} -%>
+        <%= file_field_tag "file[]", {:multiple => :multiple} -%>
       </div>
       <div>
   			<%= submit_tag "Add" -%>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]