myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [3581] branches/packs: default folders, merged an


From: noreply
Subject: [myexperiment-hackers] [3581] branches/packs: default folders, merged annotation graphs and automatic RO creation
Date: Tue, 4 Jun 2013 14:36:01 +0000 (UTC)

Revision
3581
Author
dgc
Date
2013-06-04 14:36:01 +0000 (Tue, 04 Jun 2013)

Log Message

default folders, merged annotation graphs and automatic RO creation

Modified Paths

Diff

Modified: branches/packs/app/helpers/research_objects_helper.rb (3580 => 3581)


--- branches/packs/app/helpers/research_objects_helper.rb	2013-06-03 08:27:38 UTC (rev 3580)
+++ branches/packs/app/helpers/research_objects_helper.rb	2013-06-04 14:36:01 UTC (rev 3581)
@@ -1,3 +1,7 @@
+# myExperiment: app/helpers/research_objects_helper.rb
+#
+# Copyright (c) 2007-2013 The University of Manchester, the University of
+# Oxford, and the University of Southampton.  See license.txt for details.
 
 require 'xml/libxml'
 
@@ -158,9 +162,17 @@
     end
   end
 
-  def load_graph(content)
-    graph = RDF::Graph.new # FIXME - this should support more than just rdf+xml
-    graph << RDF::Reader.for(:rdfxml).new(content) if content
+  def load_graph(content, content_type = "application/rdf+xml")
+
+    case content_type
+    when "application/rdf+xml"
+      format = :rdfxml
+    when "text/turtle", "application/x-turtle"
+      format = :turtle
+    end
+
+    graph = RDF::Graph.new
+    graph << RDF::Reader.for(format).new(content) if content
     graph
   end
 

Modified: branches/packs/app/models/pack.rb (3580 => 3581)


--- branches/packs/app/models/pack.rb	2013-06-03 08:27:38 UTC (rev 3580)
+++ branches/packs/app/models/pack.rb	2013-06-04 14:36:01 UTC (rev 3581)
@@ -13,6 +13,10 @@
 
 class Pack < ActiveRecord::Base
 
+  include ResearchObjectsHelper
+
+  after_create :create_research_object
+
   acts_as_site_entity :owner_text => 'Creator'
 
   acts_as_contributable
@@ -28,6 +32,8 @@
 
   belongs_to :license
 
+  belongs_to :research_object
+
   def find_version(version)
     match = versions.find(:first, :conditions => ["version = ?", version])
     return match if match
@@ -1008,4 +1014,35 @@
     
     boost
   end
+
+  def create_research_object
+
+    slug = "Pack#{self.id}"
+    slug = SecureRandom.uuid if ResearchObject.find_by_slug_and_version(slug, nil)
+
+    ro = ResearchObject.create(:slug => slug, :user => self.contributor)
+
+    update_attributes( {
+      :ro_uri          => relative_uri(ro.uri, Conf.base_uri),
+      :research_object => ro
+    })
+
+    # Create the folder structure
+
+    user_path = "/users/#{contributor.id}"
+
+    Conf.research_object_default_folders.each do |folder_path|
+    
+      bits = folder_path.split("/")
+
+      folder_path = bits.join("/") + "/"
+      parent_path = bits[0..-2].join("/") + "/"
+
+      ro.create_folder(folder_path, user_path)
+
+      if parent_path != "/"
+        ro.create_folder_entry(folder_path, parent_path, user_path)
+      end
+    end
+  end
 end

Modified: branches/packs/app/models/pack_contributable_entry.rb (3580 => 3581)


--- branches/packs/app/models/pack_contributable_entry.rb	2013-06-03 08:27:38 UTC (rev 3580)
+++ branches/packs/app/models/pack_contributable_entry.rb	2013-06-04 14:36:01 UTC (rev 3581)
@@ -20,6 +20,8 @@
   after_save :touch_pack
   after_destroy :touch_pack
 
+  after_save :synchronize_research_object
+
   def check_unique
 
     conditions = ["pack_id = ?", "version = ?", "contributable_type = ?", "contributable_id = ?"]
@@ -91,4 +93,12 @@
   def touch_pack
     pack.touch unless (pack.destroyed? || pack.contribution.nil?)
   end
+
+  def synchronize_research_object
+
+    ro = pack.research_object
+
+    if ro
+    end
+  end
 end

Modified: branches/packs/app/models/research_object.rb (3580 => 3581)


--- branches/packs/app/models/research_object.rb	2013-06-03 08:27:38 UTC (rev 3580)
+++ branches/packs/app/models/research_object.rb	2013-06-04 14:36:01 UTC (rev 3581)
@@ -174,21 +174,14 @@
 
     elsif content_type == "application/vnd.wf4ever.folder"
 
-      folder = create_folder(
-        :path     => slug,
-        :user_uri => user_uri)
+      folder = create_folder(slug, opts[:user_uri])
 
-      proxy = create_proxy(
-        :proxy_for_path => folder.path,
-        :proxy_in_path  => ".",
-        :user_uri       => user_uri)
+      location = folder.proxy.uri
 
-      location = proxy.uri
-
       links << { :link => folder.resource_map.uri, :rel => ORE.isDescribedBy }
       links << { :link => folder.uri,              :rel => ORE.proxyFor      }
 
-      changed << proxy
+      changed << folder.proxy
       changed << folder.resource_map
       changed << folder
 
@@ -208,19 +201,8 @@
 
       # Create the folder entry
 
-      folder_entry = create_resource(
-        :path            => calculate_path(nil, 'application/vnd.wf4ever.folderentry'),
-        :is_folder_entry => true,
-        :proxy_in_path   => proxy_in_path,
-        :proxy_for_path  => proxy_for_path,
-        :content_type    => content_type,
-        :creator_uri     => user_uri)
+      folder_entry = create_folder_entry(proxy_for_path, proxy_in_path, user_uri)
 
-      folder_entry.proxy_for.update_attribute(:aggregated_by_path, proxy_in_path)
-
-      folder_entry.update_graph!
-      folder_entry.proxy_for.update_graph!
-
       location = folder_entry.uri
 
       links << { :link => proxy_for_uri, :rel => ORE.proxyFor }
@@ -244,9 +226,8 @@
       stub = create_annotation_stub(
         :user_uri       => user_uri,
         :ao_body_path   => ao_body.path,
-        :resource_paths => request_links[AO.annotatesResource.to_s].each { |resource| relative_uri(resource, uri) } )
+        :resource_paths => request_links[AO.annotatesResource.to_s].map { |resource| relative_uri(resource, uri) } )
 
-      ao_body.update_graph!
       stub.update_graph!
 
       request_links[AO.annotatesResource.to_s].each do |annotated_resource_uri|
@@ -342,12 +323,18 @@
     stub
   end
 
-  def create_aggregated_resource(opts)
+  def create_aggregated_resource(opts = {})
 
+    throw "user_uri required"     unless opts[:user_uri]
+    throw "data required"         unless opts[:data]
+    throw "content_type required" unless opts[:content_type]
+
+    path = calculate_path(opts[:path], opts[:content_type])
+
     # Create a proxy for this resource.
 
     proxy = create_proxy(
-      :proxy_for_path => opts[:path],
+      :proxy_for_path => path,
       :proxy_in_path  => ".",
       :user_uri       => opts[:user_uri])
 
@@ -356,7 +343,7 @@
     # Create the resource.
 
     create_resource(
-      :path          => opts[:path],
+      :path          => path,
       :content_blob  => ContentBlob.new(:data ="" opts[:data]),
       :creator_uri   => opts[:user_uri],
       :content_type  => opts[:content_type],
@@ -367,14 +354,14 @@
   def create_resource_map(opts)
 
     create_resource(
-      :path            => opts[:path] || calculate_path(nil, "application/vnd.wf4ever.folder"),
+      :path            => calculate_path(opts[:path], "application/vnd.wf4ever.folder"),
       :creator_uri     => opts[:user_uri],
       :content_type    => 'application/rdf+xml',
       :is_resource_map => true)
 
   end
 
-  def create_folder(opts)
+  def create_folder_resource(opts)
 
     # Create a resource map for this folder
 
@@ -409,9 +396,56 @@
     resource
   end
 
+  def create_folder(path, user_uri)
+
+    folder = create_folder_resource(
+      :path     => path,
+      :user_uri => user_uri)
+
+    proxy = create_proxy(
+      :proxy_for_path => folder.path,
+      :proxy_in_path  => ".",
+      :user_uri       => user_uri)
+
+    folder
+  end
+
+  def create_folder_entry(path, parent_path, user_uri)
+
+    folder_entry = create_resource(
+      :path            => calculate_path(nil, 'application/vnd.wf4ever.folderentry'),
+      :entry_name      => URI(path).path.split("/").last,
+      :is_folder_entry => true,
+      :proxy_in_path   => parent_path,
+      :proxy_for_path  => path,
+      :content_type    => 'application/vnd.wf4ever.folderentry',
+      :creator_uri     => user_uri)
+
+    folder_entry.proxy_for.update_attribute(:aggregated_by_path, parent_path)
+
+    folder_entry.update_graph!
+    folder_entry.proxy_for.update_graph!
+
+    folder_entry
+  end
+
+  def find_using_path(path)
+    bits = path.split("/")
+
+    object = root_folder
+
+    while (bit = bits.shift)
+      folder_entry = object.proxies.find(:first, :conditions => { :entry_name => bit })
+      return nil if folder_entry.nil?
+      object = folder_entry.proxy_for
+    end
+
+    object
+  end
+
 private
 
-  def create_manifest
+  def create_manifest #:nodoc:
 
     resources.create(:path => ResearchObject::MANIFEST_PATH,
                      :content_type => 'application/rdf+xml')

Modified: branches/packs/app/models/resource.rb (3580 => 3581)


--- branches/packs/app/models/resource.rb	2013-06-03 08:27:38 UTC (rev 3580)
+++ branches/packs/app/models/resource.rb	2013-06-04 14:36:01 UTC (rev 3581)
@@ -137,6 +137,10 @@
     RDF::URI(research_object.uri) + path
   end
 
+  def name
+    URI(path).path.split("/").last
+  end
+
   def update_graph!
 
     new_description = create_rdf_xml { |graph| graph << description }
@@ -145,6 +149,21 @@
     update_attribute(:content_blob, ContentBlob.new(:data ="" new_description))
   end
 
+  def merged_annotation_graphs
+
+    result = RDF::Graph.new
+
+    annotation_resources = research_object.annotation_resources.find(:all,
+        :conditions => { :resource_path => path })
+    
+    annotation_resources.each do |ar|
+      ao_body = ar.annotation.ao_body
+      result << load_graph(ao_body.content_blob.data, ao_body.content_type)
+    end
+
+    result
+  end
+
   def copy_metadata
     if content_blob
       self.sha1 = content_blob.calc_sha1

Modified: branches/packs/config/default_settings.yml (3580 => 3581)


--- branches/packs/config/default_settings.yml	2013-06-03 08:27:38 UTC (rev 3580)
+++ branches/packs/config/default_settings.yml	2013-06-04 14:36:01 UTC (rev 3581)
@@ -680,4 +680,23 @@
 #
 # shortcut_keywords:
 #   biovel: /groups/643
-#
\ No newline at end of file
+
+research_object_default_folders:
+
+- root
+- root/biblio
+- root/biblio/produced
+- root/biblio/used
+- root/config
+- root/config/scripts
+- root/config/setup
+- root/config/software
+- root/config/web%20services
+- root/datasets
+- root/datasets/inputs
+- root/datasets/results
+- root/workflows
+- root/workflows/components
+- root/workflows/main
+- root/workflows/nested
+

Modified: branches/packs/db/migrate/20130520145900_create_research_objects.rb (3580 => 3581)


--- branches/packs/db/migrate/20130520145900_create_research_objects.rb	2013-06-03 08:27:38 UTC (rev 3580)
+++ branches/packs/db/migrate/20130520145900_create_research_objects.rb	2013-06-04 14:36:01 UTC (rev 3581)
@@ -22,6 +22,7 @@
       t.integer "size"
       t.string  "content_type"
       t.text    "path"
+      t.string  "entry_name"
       t.string  "creator_uri"
       t.string  "proxy_in_path"
       t.string  "proxy_for_path"
@@ -47,12 +48,21 @@
       t.string  "resource_path"
     end
 
+    add_column :packs, :ro_uri, :text
+    add_column :packs, :research_object_id, :text
+    add_column :pack_contributable_entries, :resource_path, :text
+    add_column :pack_remote_entries, :resource_path, :text
   end
 
   def self.down
     drop_table :research_objects
     drop_table :resources
     drop_table :annotation_resources
+
+    remove_column :packs, :ro_uri
+    remove_column :packs, :research_object_id
+    remove_column :pack_contributable_entries, :resource_path
+    remove_column :pack_remote_entries, :resource_path
   end
 
 end

Modified: branches/packs/db/schema.rb (3580 => 3581)


--- branches/packs/db/schema.rb	2013-06-03 08:27:38 UTC (rev 3580)
+++ branches/packs/db/schema.rb	2013-06-04 14:36:01 UTC (rev 3581)
@@ -457,6 +457,7 @@
     t.datetime "created_at"
     t.datetime "updated_at"
     t.integer  "version"
+    t.text     "resource_path"
   end
 
   create_table "pack_remote_entries", :force => true do |t|
@@ -469,6 +470,7 @@
     t.datetime "created_at"
     t.datetime "updated_at"
     t.integer  "version"
+    t.text     "resource_path"
   end
 
   create_table "pack_versions", :force => true do |t|
@@ -492,6 +494,8 @@
     t.datetime "updated_at"
     t.integer  "current_version"
     t.integer  "license_id"
+    t.text     "ro_uri"
+    t.text     "research_object_id"
   end
 
   create_table "pending_invitations", :force => true do |t|
@@ -628,6 +632,7 @@
     t.integer  "size"
     t.string   "content_type"
     t.text     "path"
+    t.string   "entry_name"
     t.string   "creator_uri"
     t.string   "proxy_in_path"
     t.string   "proxy_for_path"

Modified: branches/packs/lib/conf.rb (3580 => 3581)


--- branches/packs/lib/conf.rb	2013-06-03 08:27:38 UTC (rev 3580)
+++ branches/packs/lib/conf.rb	2013-06-04 14:36:01 UTC (rev 3581)
@@ -210,6 +210,10 @@
     self.fetch_entry('sesame_repository')
   end
 
+  def self.research_object_default_folders
+    self.fetch_entry('research_object_default_folders')
+  end
+
   # This method is required to create an administrator in the test fixtures
 
   def self.admins=(value)

reply via email to

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