myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [3313] branches/wf4ever/app: added ability to spe


From: noreply
Subject: [myexperiment-hackers] [3313] branches/wf4ever/app: added ability to specify RO URI during workflow / pack creation
Date: Sat, 19 Jan 2013 16:58:03 +0000 (UTC)

Revision
3313
Author
dgc
Date
2013-01-19 16:58:02 +0000 (Sat, 19 Jan 2013)

Log Message

added ability to specify RO URI during workflow / pack creation

Modified Paths

Added Paths

Diff

Modified: branches/wf4ever/app/controllers/application_controller.rb (3312 => 3313)


--- branches/wf4ever/app/controllers/application_controller.rb	2013-01-18 13:53:42 UTC (rev 3312)
+++ branches/wf4ever/app/controllers/application_controller.rb	2013-01-19 16:58:02 UTC (rev 3313)
@@ -1130,4 +1130,27 @@
     end
 
   end
+
+  def check_and_create_research_object(contributable, new_uri)
+
+    rodl_uri = URI.parse(contributable.ro_uri)
+    
+    path_bits = rodl_uri.path.sub(/\/$/, "").split("/")
+
+    slug = path_bits.pop
+
+    rodl_uri.path = "#{path_bits.join("/")}/"
+
+    session = ROSRS::Session.new(rodl_uri.to_s, Conf.rodl_bearer_token)
+
+    if session.check_research_object(slug) == false
+      c, r, u, m = session.create_research_object(slug)
+
+      if c != 201
+        return "Unable to create research object: #{r}"
+      end
+    end
+  end
+          
+
 end

Modified: branches/wf4ever/app/controllers/packs_controller.rb (3312 => 3313)


--- branches/wf4ever/app/controllers/packs_controller.rb	2013-01-18 13:53:42 UTC (rev 3312)
+++ branches/wf4ever/app/controllers/packs_controller.rb	2013-01-19 16:58:02 UTC (rev 3313)
@@ -61,6 +61,11 @@
   
   # GET /packs/1
   def show
+
+    session = ROSRS::Session.new(@pack.ro_uri, Conf.rodl_bearer_token)
+
+    @annotations = session.get_annotation_graph(@pack.ro_uri, @pack.ro_uri)
+
     if allow_statistics_logging(@pack)
       @viewing = Viewing.create(:contribution => @pack.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'], :accessed_from_site => accessed_from_website?())
     end
@@ -228,6 +233,11 @@
           @pack.tag_list = convert_tags_to_gem_format params[:pack][:tag_list]
           @pack.update_tags
         end
+
+        # Check that the RO exists and if not, create it.
+        if err = check_and_create_research_object(@pack, params[:pack][:ro_uri])
+          flash.now[:error] = err
+        end
         
         # update policy
         policy_err_msg = update_policy(@pack, params)
@@ -260,29 +270,10 @@
       if @pack.update_attributes(params[:pack])
 
         # Check that the RO exists and if not, create it.
-        
-        unless params[:pack][:ro_uri].empty?
-
-          rodl_uri = URI.parse(@pack.ro_uri)
-          
-          path_bits = rodl_uri.path.sub(/\/$/, "").split("/")
-
-          slug = path_bits.pop
-
-          rodl_uri.path = "#{path_bits.join("/")}/"
-
-          session = ROSRS::Session.new(rodl_uri.to_s, Conf.rodl_bearer_token)
-
-          if session.check_research_object(slug) == false
-            c, r, u, m = session.create_research_object(slug)
-
-            if c != 201
-              flash.now[:error] = "Unable to create research object: #{r}"
-            end
-          end
-          
+        if err = check_and_create_research_object(@pack, params[:pack][:ro_uri])
+          flash.now[:error] = err
         end
-
+        
         @pack.refresh_tags(convert_tags_to_gem_format(params[:pack][:tag_list]), current_user) if params[:pack][:tag_list]
         policy_err_msg = update_policy(@pack, params)
         update_layout(@pack, params[:layout])
@@ -655,6 +646,5 @@
       end
 
     end
-
   end
 end

Modified: branches/wf4ever/app/controllers/workflows_controller.rb (3312 => 3313)


--- branches/wf4ever/app/controllers/workflows_controller.rb	2013-01-18 13:53:42 UTC (rev 3312)
+++ branches/wf4ever/app/controllers/workflows_controller.rb	2013-01-19 16:58:02 UTC (rev 3313)
@@ -308,6 +308,7 @@
     @workflow.license_id = params[:workflow][:license_id] == "0" ? nil : params[:workflow][:license_id]
     @workflow.content_blob = ContentBlob.new(:data ="" file.read)
     @workflow.file_ext = file.original_filename.split(".").last.downcase
+    @workflow.ro_uri = params[:workflow][:ro_uri]
     
     file.rewind
     
@@ -529,29 +530,10 @@
       if @workflow.update_attributes(params[:workflow])
 
         # Check that the RO exists and if not, create it.
-        
-        unless params[:workflow][:ro_uri].empty?
-
-          rodl_uri = URI.parse(@workflow.ro_uri)
-          
-          path_bits = rodl_uri.path.sub(/\/$/, "").split("/")
-
-          slug = path_bits.pop
-
-          rodl_uri.path = "#{path_bits.join("/")}/"
-
-          session = ROSRS::Session.new(rodl_uri.to_s, Conf.rodl_bearer_token)
-
-          if session.check_research_object(slug) == false
-            c, r, u, m = session.create_research_object(slug)
-
-            if c != 201
-              flash.now[:error] = "Unable to create research object: #{r}"
-            end
-          end
-          
+        if err = check_and_create_research_object(@workflow, params[:workflow][:ro_uri])
+          flash.now[:error] = err
         end
-
+        
         if params[:workflow][:tag_list]
           @workflow.refresh_tags(convert_tags_to_gem_format(params[:workflow][:tag_list]), current_user)
           @workflow.reload

Added: branches/wf4ever/app/views/contributions/_ro_uri_box.rhtml (0 => 3313)


--- branches/wf4ever/app/views/contributions/_ro_uri_box.rhtml	                        (rev 0)
+++ branches/wf4ever/app/views/contributions/_ro_uri_box.rhtml	2013-01-19 16:58:02 UTC (rev 3313)
@@ -0,0 +1,16 @@
+<div class="ro_uri_edit_box">
+  <p><b>Research Object URI</b></p>
+
+  <p>You may associate a <em>research object</em> by specifying the RO URI.
+  Once set, metadata will be synchronised with the research object.</p>
+
+  <p>
+    <% if f %>
+      <%= f.text_field :ro_uri, :size => 60, :placeholder => 'http://www.example.org/rodl/ROs/research_object/' %>
+    <% else %>
+      <%= text_field_tag input_name, '', :size => 60, :placeholder => 'http://www.example.org/rodl/ROs/research_object/' %>
+    <% end %>
+  </p>
+</div>
+
+

Modified: branches/wf4ever/app/views/packs/edit.rhtml (3312 => 3313)


--- branches/wf4ever/app/views/packs/edit.rhtml	2013-01-18 13:53:42 UTC (rev 3312)
+++ branches/wf4ever/app/views/packs/edit.rhtml	2013-01-19 16:58:02 UTC (rev 3313)
@@ -15,16 +15,8 @@
 
 <% form_for(:pack, :url ="" pack_path(@pack), :html => { :method => :put }) do |f| %>
 
-  <div class="ro_uri_edit_box">
-    <p><b>Research Object URI</b></p>
+  <%= render :partial => "contributions/ro_uri_box", :locals => { :f => f } %>
 
-    <p>You may associate this workflow with a <em>research object</em> by
-    specifying the URI to it.  Once set, metadata will be synchronised
-    with the research object.</p>
-
-    <p><%= f.text_field :ro_uri, :size => 60, :placeholder => 'http://www.example.org/rodl/ROs/research_object/' %></p>
-  </div>
-
 	<center>
 		<div class="box_form" style="width: 550px; margin: 1em 0; text-align: left;">
 			<p><b>Title: </b></p>

Modified: branches/wf4ever/app/views/packs/new.rhtml (3312 => 3313)


--- branches/wf4ever/app/views/packs/new.rhtml	2013-01-18 13:53:42 UTC (rev 3312)
+++ branches/wf4ever/app/views/packs/new.rhtml	2013-01-19 16:58:02 UTC (rev 3313)
@@ -10,6 +10,9 @@
 </center>
 
 <% form_tag :action ="" :create do %>
+
+  <%= render :partial => "contributions/ro_uri_box", :locals => { :f => nil, :input_name => 'pack[ro_uri]' } -%>
+
   <center>
 		<div class="box_form" style="width: 550px; margin: 1em 0; text-align: left;">
 			<p><b>Title: </b></p>

Modified: branches/wf4ever/app/views/workflows/edit.rhtml (3312 => 3313)


--- branches/wf4ever/app/views/workflows/edit.rhtml	2013-01-18 13:53:42 UTC (rev 3312)
+++ branches/wf4ever/app/views/workflows/edit.rhtml	2013-01-19 16:58:02 UTC (rev 3313)
@@ -17,16 +17,7 @@
 
 <% form_for(:workflow, :url ="" workflow_path(@workflow), :html => { :method => :put }) do |f| %>
 
-  <div class="ro_uri_edit_box">
-    <p><b>Research Object URI</b></p>
-
-    <p>You may associate this workflow with a <em>research object</em> by
-    specifying the URI to it.  Once set, metadata will be synchronised
-    with the research object.</p>
-
-    <p><%= f.text_field :ro_uri, :size => 60, :placeholder => 'http://www.example.org/rodl/ROs/research_object/' %></p>
-  </div>
-
+  <%= render :partial => "contributions/ro_uri_box", :locals => { :f => f } %>
   <%= render :partial => "tags/tags_form", :locals => { :edit => true, :taggable => @workflow } %>
   <%= render :partial => "contributions/credit_attribution_form", :locals => { :edit => true, :contributable => @workflow } %>
 

Modified: branches/wf4ever/app/views/workflows/new.rhtml (3312 => 3313)


--- branches/wf4ever/app/views/workflows/new.rhtml	2013-01-18 13:53:42 UTC (rev 3312)
+++ branches/wf4ever/app/views/workflows/new.rhtml	2013-01-19 16:58:02 UTC (rev 3313)
@@ -11,6 +11,8 @@
 
 <% form_tag({:action ="" :create}, :multipart => true) do %>
 
+  <%= render :partial => "contributions/ro_uri_box", :locals => { :f => nil, :input_name => 'workflow[ro_uri]' } -%>
+
   <!-- Workflow File -->
 	
 	<p class="step_text">1. Workflow file/script</p>

reply via email to

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