Diff
Modified: branches/ro/Gemfile (3785 => 3786)
--- branches/ro/Gemfile 2013-11-13 13:33:26 UTC (rev 3785)
+++ branches/ro/Gemfile 2013-11-13 16:17:07 UTC (rev 3786)
@@ -31,5 +31,6 @@
gem "simple-rss", "~> 1.2.3"
gem "net-http-persistent", "~> 2.8"
gem "delayed_job", "~>2.0.4"
+gem "wf4ever-transformation-client", "~> 0.3.0"
gem "sanitize", "~> 2.0.6"
Copied: branches/ro/app/controllers/research_objects_controller.rb (from rev 3780, branches/packs/app/controllers/research_objects_controller.rb) (0 => 3786)
--- branches/ro/app/controllers/research_objects_controller.rb (rev 0)
+++ branches/ro/app/controllers/research_objects_controller.rb 2013-11-13 16:17:07 UTC (rev 3786)
@@ -0,0 +1,139 @@
+# myExperiment: app/controllers/research_objects_controller.rb
+#
+# Copyright (c) 2007-2013 The University of Manchester, the University of
+# Oxford, and the University of Southampton. See license.txt for details.
+
+require 'securerandom'
+
+class ResearchObjectsController < ApplicationController
+
+ # GET /rodl
+ def index
+
+ uri_list = ""
+
+ ResearchObject.all.each do |ro|
+ if Authorization.check('view', ro, current_user)
+ uri_list << "#{research_object_url(ro.slug)}/\n"
+ end
+ end
+
+ send_data(uri_list, :type => 'text/uri-list')
+ end
+
+ # GET /rodl/:id
+ def show
+
+ slug = params[:id]
+ slug = slug[0..-2] if slug.ends_with?("/")
+
+ ro = ResearchObject.find_by_slug_and_version(slug, nil)
+
+ unless ro
+ render :text => "Research Object not found", :status => 404
+ return
+ end
+
+ unless Authorization.check('view', ro, current_user)
+ render_401("You are not authorized to view this research object.")
+ return
+ end
+
+ respond_to do |format|
+ format.html {
+ redirect_to polymorphic_path(ro.context)
+ }
+ format.rdf {
+ redirect_to research_object_url(slug) + "/" + ResearchObject::MANIFEST_PATH, :status => 303
+ }
+ format.zip {
+ redirect_to zipped_research_object_url(slug) + "/"
+ }
+ end
+ end
+
+ def download_zip
+
+ slug = params[:id]
+ slug = slug[0..-2] if slug.ends_with?("/")
+
+ ro = ResearchObject.find_by_slug_and_version(slug, nil)
+
+ unless ro
+ render :text => "Research Object not found", :status => 404
+ return
+ end
+
+ respond_to do |format|
+ format.zip {
+ zip_file_name = ro.generate_zip!
+ send_file zip_file_name, :type => "application/zip", :disposition => 'attachment', :filename => "#{ro.slug}.zip"
+ }
+ end
+ end
+
+ # POST /rodl
+ def create
+
+ unless Authorization.check('create', ResearchObject, current_user)
+ render_401("You are not authorized to create a research object.")
+ return
+ end
+
+ slug = request.headers["Slug"]
+
+ # Remove trailing slash if given.
+
+ slug = slug[0..-2] if slug.ends_with?("/")
+
+ # If a research object exists with the slug then respond with 409 Conflict.
+
+ if ResearchObject.find_by_slug_and_version(slug, nil)
+ render :nothing => true, :status => 409
+ return
+ end
+
+ # Create the research object with a blank manifest. The blank manifest is
+ # created so that when the manifest is aggregated it contains the
+ # description of the manifest.
+
+ ro_uri = research_object_url(slug) + "/"
+
+ ro = ResearchObject.create(:slug => slug, :user => current_user)
+
+ response.headers["Location"] = ro_uri
+
+ ro.manifest_resource.generate_graph!
+
+ send_data(ro.manifest_resource.content_blob.data, :type => "application/rdf+xml", :filename => ResearchObject::MANIFEST_PATH, :status => 201)
+ end
+
+ # DELETE /rodl/:id
+ def destroy
+
+ ro = ResearchObject.find_by_slug_and_version(params[:id], nil)
+
+ unless ro
+ render :text => "Research Object not found", :status => 404
+ return
+ end
+
+ unless Authorization.check('destroy', ro, current_user)
+ render_401("You are not authorized to delete this research object.")
+ return
+ end
+
+ if ro
+ ro.destroy
+ render :nothing => true, :status => 204
+ else
+ render :text => "Research Object not found", :status => 404
+ end
+ end
+
+ # PUT /rodl/:id
+ def update
+ end
+
+end
+
Modified: branches/ro/app/models/research_object.rb (3785 => 3786)
--- branches/ro/app/models/research_object.rb 2013-11-13 13:33:26 UTC (rev 3785)
+++ branches/ro/app/models/research_object.rb 2013-11-13 16:17:07 UTC (rev 3786)
@@ -26,8 +26,6 @@
belongs_to :context, :polymorphic => true
- has_many :checklists, :dependent => :destroy
-
validates_presence_of :slug
def uri
Modified: branches/ro/config/routes.rb (3785 => 3786)
--- branches/ro/config/routes.rb 2013-11-13 13:33:26 UTC (rev 3785)
+++ branches/ro/config/routes.rb 2013-11-13 16:17:07 UTC (rev 3786)
@@ -319,6 +319,43 @@
:controller => 'linked_data', :action ="" 'taggings', :conditions => { :method => :get }
end
+ # RODL routes. There are no HTML pages for 'new' and 'edit' so the routes
+ # are generated without the resource helpers.
+
+ map.research_objects "/rodl/ROs", :controller => "research_objects", :action ="" "index", :conditions => { :method => :get }
+ map.connect "/rodl/ROs", :controller => "research_objects", :action ="" "create", :conditions => { :method => :post }
+
+ map.zipped_research_object "/rodl/zippedROs/:id", :controller => "research_objects", :action ="" "download_zip", :conditions => { :method => :get }
+
+ map.research_object "/rodl/ROs/:id", :controller => "research_objects", :action ="" "show", :conditions => { :method => :get }
+ map.connect "/rodl/ROs/:research_object_id", :controller => "resources", :action ="" "post", :conditions => { :method => :post }
+ map.connect "/rodl/ROs/:id", :controller => "research_objects", :action ="" "update", :conditions => { :method => :put }
+ map.connect "/rodl/ROs/:id", :controller => "research_objects", :action ="" "destroy", :conditions => { :method => :delete }
+
+ map.named_route "research_object_resource", "/rodl/ROs/:research_object_id/:id",
+ :controller => "resources",
+ :action ="" "show",
+ :conditions => { :method => :get },
+ :requirements => { :id => /.*/ }
+
+ map.connect "/rodl/ROs/:research_object_id/:id",
+ :controller => "resources",
+ :action ="" "update",
+ :conditions => { :method => :put },
+ :requirements => { :id => /.*/ }
+
+ map.connect "/rodl/ROs/:research_object_id/:id",
+ :controller => "resources",
+ :action ="" "delete",
+ :conditions => { :method => :delete },
+ :requirements => { :id => /.*/ }
+
+ map.connect "/rodl/ROs/:research_object_id/:path",
+ :controller => "resources",
+ :action ="" "post",
+ :conditions => { :method => :post },
+ :requirements => { :path => /.*/ }
+
# Install the default route as the lowest priority.
map.connect ':controller/:action/:id'
end
Modified: branches/ro/db/schema.rb (3785 => 3786)
--- branches/ro/db/schema.rb 2013-11-13 13:33:26 UTC (rev 3785)
+++ branches/ro/db/schema.rb 2013-11-13 16:17:07 UTC (rev 3786)
@@ -42,6 +42,12 @@
t.datetime "promote_after"
end
+ create_table "annotation_resources", :force => true do |t|
+ t.integer "research_object_id"
+ t.integer "annotation_id"
+ t.string "resource_path"
+ end
+
create_table "announcements", :force => true do |t|
t.string "title"
t.integer "user_id"
@@ -155,9 +161,10 @@
end
create_table "content_blobs", :force => true do |t|
- t.binary "data", :limit => 2147483647
- t.string "md5", :limit => 32
- t.string "sha1", :limit => 40
+ t.binary "data", :limit => 2147483647
+ t.string "md5", :limit => 32
+ t.string "sha1", :limit => 40
+ t.integer "size"
end
add_index "content_blobs", ["md5"], :name => "index_content_blobs_on_md5"
@@ -610,6 +617,46 @@
t.string "workflow_uri"
end
+ create_table "research_objects", :force => true do |t|
+ t.string "context_type"
+ t.integer "context_id"
+ t.string "slug"
+ t.integer "version"
+ t.string "version_type"
+ t.integer "user_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "resources", :force => true do |t|
+ t.integer "research_object_id"
+ t.string "context_type"
+ t.integer "context_id"
+ t.integer "content_blob_id"
+ t.string "sha1", :limit => 40
+ t.integer "size"
+ t.string "content_type"
+ t.text "path"
+ t.string "entry_name"
+ t.string "creator_uri"
+ t.string "uuid", :limit => 36
+ t.string "proxy_in_path"
+ t.string "proxy_for_path"
+ t.string "ao_body_path"
+ t.string "resource_map_path"
+ t.string "aggregated_by_path"
+ t.boolean "is_resource", :default => false
+ t.boolean "is_aggregated", :default => false
+ t.boolean "is_proxy", :default => false
+ t.boolean "is_annotation", :default => false
+ t.boolean "is_resource_map", :default => false
+ t.boolean "is_folder", :default => false
+ t.boolean "is_folder_entry", :default => false
+ t.boolean "is_root_folder", :default => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "reviews", :force => true do |t|
t.string "title", :default => ""
t.text "review"
Copied: branches/ro/lib/has_research_object.rb (from rev 3780, branches/packs/lib/has_research_object.rb) (0 => 3786)
--- branches/ro/lib/has_research_object.rb (rev 0)
+++ branches/ro/lib/has_research_object.rb 2013-11-13 16:17:07 UTC (rev 3786)
@@ -0,0 +1,24 @@
+# myExperiment: lib/has_research_object.rb
+#
+# Copyright (c) 2007-2013 The University of Manchester, the University of
+# Oxford, and the University of Southampton. See license.txt for details.
+
+class ActiveRecord::Base
+
+ def self.has_research_object
+ has_one :research_object, :as => 'context', :dependent => :destroy
+ end
+
+ def self.has_resource
+ has_one :resource, :as => :context, :dependent => :destroy
+ end
+
+ def find_resource_by_path(path)
+ research_object.resources.find_by_path(relative_uri(path, research_object.uri))
+ end
+
+ def find_resource_by_ore_path(path)
+ research_object.find_using_path(relative_uri(path, research_object.uri))
+ end
+
+end
Modified: branches/ro/test/functional/api_controller_test.rb (3785 => 3786)
--- branches/ro/test/functional/api_controller_test.rb 2013-11-13 13:33:26 UTC (rev 3785)
+++ branches/ro/test/functional/api_controller_test.rb 2013-11-13 16:17:07 UTC (rev 3786)
@@ -48,9 +48,9 @@
extra_activities = Activity.find(:all). - existing_activities
assert_equal(1, extra_workflows.length)
- assert_equal(1, extra_activities.length)
+ assert_equal(2, extra_activities.length)
- new_activity = (extra_activities - existing_activities).first
+ new_activity = (extra_activities - existing_activities)[1]
assert_equal("John Smith", new_activity.subject_label);
assert_equal("create", new_activity.action);
@@ -245,11 +245,11 @@
new_activities = Activity.all - existing_activities
- assert_equal(1, new_activities.length)
+ assert_equal(2, new_activities.length)
- assert_equal("John Smith", new_activities.first.subject.name)
- assert_equal("create", new_activities.first.action)
- assert_equal(title, new_activities.first.objekt.title)
+ assert_equal("John Smith", new_activities[1].subject.name)
+ assert_equal("create", new_activities[1].action)
+ assert_equal(title, new_activities[1].objekt.title)
extra_files = Blob.find(:all) - existing_files