Modified: branches/packs/app/models/blob.rb (3757 => 3758)
--- branches/packs/app/models/blob.rb 2013-10-21 13:33:07 UTC (rev 3757)
+++ branches/packs/app/models/blob.rb 2013-10-21 13:44:59 UTC (rev 3758)
@@ -10,8 +10,12 @@
require 'acts_as_attributable'
require 'sunspot_rails'
+require 'has_research_object'
+
class Blob < ActiveRecord::Base
+ include ResearchObjectsHelper
+
acts_as_site_entity :owner_text => 'Uploader'
acts_as_contributable
@@ -67,6 +71,10 @@
end
end
+ has_research_object
+
+ after_create :create_research_object
+
format_attribute :body
def type
@@ -98,4 +106,23 @@
def statistics_for_rest_api
APIStatistics.statistics(self)
end
+
+ def create_research_object
+
+ user_path = "/users/#{contributor_id}"
+
+ slug = "File#{self.id}"
+ slug = SecureRandom.uuid if ResearchObject.find_by_slug_and_version(slug, nil)
+
+ ro = ResearchObject.create(:slug => slug, :user => self.contributor)
+
+ update_attribute(:research_object, ro)
+
+ file_resource = ro.create_aggregated_resource(
+ :user_uri => user_path,
+ :path => local_name, # FIXME - where should these be URL encoded?
+ :data ="" content_blob.data,
+ :context => self,
+ :content_type => content_type.mime_type)
+ end
end