myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [3616] branches/packs: added ability to add pack


From: noreply
Subject: [myexperiment-hackers] [3616] branches/packs: added ability to add pack remote entries to RO enabled packs
Date: Wed, 31 Jul 2013 13:24:35 +0000 (UTC)

Revision
3616
Author
dgc
Date
2013-07-31 13:24:34 +0000 (Wed, 31 Jul 2013)

Log Message

added ability to add pack remote entries to RO enabled packs

Modified Paths

Diff

Modified: branches/packs/app/controllers/packs_controller.rb (3615 => 3616)


--- branches/packs/app/controllers/packs_controller.rb	2013-07-24 10:06:02 UTC (rev 3615)
+++ branches/packs/app/controllers/packs_controller.rb	2013-07-31 13:24:34 UTC (rev 3616)
@@ -5,6 +5,7 @@
 
 class PacksController < ApplicationController
   include ApplicationHelper
+  include ResearchObjectsHelper
   
   ## NOTE: URI must match config/default_settings.yml ro_resource_types
   WORKFLOW_DEFINITION = "http://purl.org/wf4ever/wfdesc#WorkflowDefinition"
@@ -82,6 +83,15 @@
       format.html {
         
         @graph = @pack.research_object.merged_annotation_graphs
+        @ore_directories = @pack.research_object.ore_directories
+        @ore_resources = @pack.research_object.ore_resources
+        @ro_relationships = Conf.ro_relationships
+        @sketch = @graph.query(:predicate => RDF.type,
+            :object => RDF::URI("http://purl.org/wf4ever/roterms#Sketch")).first_subject
+        @hypothesis = @graph.query(:predicate => RDF.type,
+            :object => RDF::URI("http://purl.org/wf4ever/roterms#Hypothesis")).first_subject
+        @conclusions = @graph.query(:predicate => RDF.type,
+            :object => RDF::URI("http://purl.org/wf4ever/roterms#Conclusions")).first_subject
 
         @lod_nir  = pack_url(@pack)
         @lod_html = pack_url(:id => @pack.id, :format => 'html')
@@ -390,7 +400,14 @@
         # By this point, we either have errors, or have an entry that needs saving.
         if errors.empty? && entry.save
 
-          post_process_created_resource(@pack, entry.resource, params)
+          case entry
+          when PackContributableEntry
+            resource_uri = entry.resource.uri
+          when PackRemoteEntry
+            resource_uri = entry.uri
+          end
+          
+          post_process_created_resource(@pack, resource_uri, params)
 
           flash[:notice] = 'Item succesfully added to pack.'
           format.html { redirect_to pack_url(@pack) }
@@ -544,15 +561,15 @@
     end
   end
 
-  def annotate_resource_type(resource, type_uri)
+  def annotate_resource_type(resource_uri, type_uri)
 
     body = RDF::Graph.new
-    body << [RDF::URI(resource.uri), RDF.type, RDF::URI(type_uri)]
+    body << [RDF::URI(resource_uri), RDF.type, RDF::URI(type_uri)]
 
-    @pack.research_object.create_annotation(:body_graph => body, :resources => [resource.uri], :creator_uri => "/users/#{current_user.id}")
+    @pack.research_object.create_annotation(:body_graph => body, :resources => [resource_uri], :creator_uri => "/users/#{current_user.id}")
   end
 
-  def post_process_created_resource(pack, resource, params)
+  def post_process_created_resource(pack, resource_uri, params)
 
     ro = pack.research_object
 
@@ -563,7 +580,7 @@
 #   end
 
     if params[:type] != RO_RESOURCE
-      annotate_resource_type(resource, params[:type])
+      annotate_resource_type(resource_uri, params[:type])
     end
 
     # Folder selection is performed on the following with decreasing order of
@@ -583,7 +600,7 @@
 
     folder = ro.root_folder if folder.nil?
 
-    ro.create_folder_entry(resource.path, folder.path, user_path)
+    ro.create_folder_entry(relative_uri(resource_uri, @pack.research_object.uri), folder.path, user_path)
   end
 
 end

Modified: branches/packs/app/models/research_object.rb (3615 => 3616)


--- branches/packs/app/models/research_object.rb	2013-07-24 10:06:02 UTC (rev 3615)
+++ branches/packs/app/models/research_object.rb	2013-07-31 13:24:34 UTC (rev 3616)
@@ -459,11 +459,16 @@
       :content_type    => 'application/vnd.wf4ever.folderentry',
       :creator_uri     => user_uri)
 
-    folder_entry.proxy_for.update_attribute(:aggregated_by_path, parent_path)
+    if folder_entry.proxy_for
+      folder_entry.proxy_for.update_attribute(:aggregated_by_path, parent_path)
+    end
 
     folder_entry.update_graph!
-    folder_entry.proxy_for.update_graph!
 
+    if folder_entry.proxy_for
+      folder_entry.proxy_for.update_graph!
+    end
+
     folder_entry
   end
 
@@ -513,7 +518,8 @@
     else
       {
         :name => entry.entry_name,
-        :type => :file
+        :type => :file,
+        :path => entry.proxy_for.path
       }
     end
   end
@@ -546,6 +552,26 @@
     ore_directories_aux('', ore_structure).sort
   end
 
+  def ore_resources_aux(structure)
+    results = []
+
+    structure.each do |entry|
+
+      case entry[:type]
+      when :file
+        results << entry
+      when :folder
+        results += ore_resources_aux(entry[:entries])
+      end
+    end
+
+    results
+  end
+
+  def ore_resources
+    ore_resources_aux(ore_structure)
+  end
+
   def find_template_from_graph(graph, templates)
 
     templates.each do |name, template|

Modified: branches/packs/app/models/resource.rb (3615 => 3616)


--- branches/packs/app/models/resource.rb	2013-07-24 10:06:02 UTC (rev 3615)
+++ branches/packs/app/models/resource.rb	2013-07-31 13:24:34 UTC (rev 3616)
@@ -149,8 +149,10 @@
 
     new_description = create_rdf_xml { |graph| graph << description }
 
-    content_blob.destroy if content_blob
-    update_attribute(:content_blob, ContentBlob.new(:data ="" new_description))
+    unless is_resource
+      content_blob.destroy if content_blob
+      update_attribute(:content_blob, ContentBlob.new(:data ="" new_description))
+    end
   end
 
   def annotations

Modified: branches/packs/app/views/packs/_add_item.rhtml (3615 => 3616)


--- branches/packs/app/views/packs/_add_item.rhtml	2013-07-24 10:06:02 UTC (rev 3615)
+++ branches/packs/app/views/packs/_add_item.rhtml	2013-07-31 13:24:34 UTC (rev 3616)
@@ -20,7 +20,7 @@
             :placeholder => 'http://www.example.com/resource' -%>
               <%= select_tag(:type, options_for_select(Conf.ro_resource_types.map { |x| [x["label"], x["uri"]] },
                     "http://purl.org/wf4ever/ro#Resource") )  -%>
-              Folder: <%= select_tag(:folder, options_for_select(['(automatic)'] + @pack.research_object.ore_directories)) -%>
+              Folder: <%= select_tag(:folder, options_for_select(['(automatic)'] + @ore_directories)) -%>
 					</td>
 					<td class="submit" style="padding-bottom: 0;">
 						<%= submit_tag "Add", :disable_with => "..." -%>
@@ -64,7 +64,7 @@
 							</select>
               <%= select_tag(:type, options_for_select(Conf.ro_resource_types.map { |x| [x["label"], x["uri"]] },
                     "http://purl.org/wf4ever/ro#Resource") )  -%>
-              Folder: <%= select_tag(:folder, options_for_select(['(automatic)'] + @pack.research_object.ore_directories)) -%>
+              Folder: <%= select_tag(:folder, options_for_select(['(automatic)'] + @ore_directories)) -%>
 						</td>
 						<td class="submit">
 							<%= submit_tag "Add", :disable_with => "..." -%>
@@ -126,4 +126,13 @@
 		</table>
 	</div>
 
+  <% if @ore_resources.count > 1 %>
+    <% form_tag("#{rest_resource_uri(@pack)}/relationships") do -%>
+        <%= select_tag(:subject,   options_for_select(@ore_resources.map    { |r| [r[:name],   r[:path]] }) )  -%>
+        <%= select_tag(:predicate, options_for_select(@ro_relationships.map { |r| [r["label"], r["uri"]] }) )  -%>
+        <%= select_tag(:object,    options_for_select(@ore_resources.map    { |r| [r[:name],   r[:path]] }) )  -%>
+        <%= submit_tag("Add") -%>
+    <% end %>
+  <% end %>
+
 <% end -%>

Modified: branches/packs/app/views/packs/show.rhtml (3615 => 3616)


--- branches/packs/app/views/packs/show.rhtml	2013-07-24 10:06:02 UTC (rev 3615)
+++ branches/packs/app/views/packs/show.rhtml	2013-07-31 13:24:34 UTC (rev 3616)
@@ -49,6 +49,10 @@
 
 	</div>
 			
+      <h2>Research Object URI</h2>
+
+      <p>This pack is available as a research object at <%= link_to(h(@pack.research_object.uri), @pack.research_object.uri) -%>.</p>
+
 			<h2>Description</h2>
 			
 			<% unless @pack.description.blank? %>
@@ -65,15 +69,6 @@
 				</p>
 			<% end %>
 
-  <% @sketch = @graph.query(:predicate => RDF.type,
-                            :object    => RDF::URI("http://purl.org/wf4ever/roterms#Sketch")).first_subject %>
-
-  <% @hypothesis = @graph.query(:predicate => RDF.type,
-                                :object    => RDF::URI("http://purl.org/wf4ever/roterms#Hypothesis")).first_subject %>
-
-  <% @conclusions = @graph.query(:predicate => RDF.type,
-                                 :object    => RDF::URI("http://purl.org/wf4ever/roterms#Conclusions")).first_subject %>
-
   <% if @sketch %>
     <h2>Research overview</h2>
     <%= image_tag(@sketch.to_s, :width => '100%') -%>

Modified: branches/packs/config/default_settings.yml (3615 => 3616)


--- branches/packs/config/default_settings.yml	2013-07-24 10:06:02 UTC (rev 3615)
+++ branches/packs/config/default_settings.yml	2013-07-31 13:24:34 UTC (rev 3616)
@@ -1453,6 +1453,14 @@
     uri:    "http://purl.org/wf4ever/roterms#WorkflowRunBundle"
     folder: "datasets/results"
 
+ro_relationships:
+
+  - label: "Input selected"
+    uri: "http://purl.org/wf4ever/roterms#inputSelected"
+
+  - label: "Output selected"
+    uri: "http://purl.org/wf4ever/roterms#outputSelected"
+
 ro_templates:
 
   creator:
@@ -1478,8 +1486,11 @@
 
     label: Input selection relationship
 
+    types:
+
+       resource1: user
+       resource2: user
+
     required_statements:
     - [:resource1, "<http://purl.org/wf4ever/roterms#inputSelected>", :resource2]
 
-empty:
-

reply via email to

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