create content-addressed collections with uuid=locator
authorTom Clegg <tom@clinicalfuture.com>
Thu, 31 Jan 2013 19:45:22 +0000 (11:45 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Thu, 31 Jan 2013 19:45:22 +0000 (11:45 -0800)
app/models/collection.rb
db/migrate/20130130205749_add_manifest_text_to_collection.rb [new file with mode: 0644]
db/schema.rb

index 1abe20918984df3f026c7b7054031b726f384422..2d9d9f102fd95233a53cf74f57db27f94bf60b14 100644 (file)
@@ -28,4 +28,23 @@ class Collection < OrvosModel
       end
     end
   end
+
+  def assign_uuid
+    if self.manifest_text.nil? and self.uuid.nil?
+      super
+    elsif self.manifest_text and self.uuid
+      if self.uuid == Digest::MD5.hexdigest(self.manifest_text)
+        true
+      else
+        errors.add :uuid, 'uuid does not match checksum of manifest_text'
+        false
+      end
+    elsif self.manifest_text
+      errors.add :uuid, 'checksum for manifest_text not supplied in uuid'
+      false
+    else
+      errors.add :manifest_text, 'manifest_text not supplied'
+      false
+    end
+  end
 end
diff --git a/db/migrate/20130130205749_add_manifest_text_to_collection.rb b/db/migrate/20130130205749_add_manifest_text_to_collection.rb
new file mode 100644 (file)
index 0000000..7bcb47a
--- /dev/null
@@ -0,0 +1,5 @@
+class AddManifestTextToCollection < ActiveRecord::Migration
+  def change
+    add_column :collections, :manifest_text, :text
+  end
+end
index 7b8c9a8b395540ed07e0718dd38947f47f3809ab..f2deccbb2a3c39050047022e7cfdaa371968482f 100644 (file)
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20130128231343) do
+ActiveRecord::Schema.define(:version => 20130130205749) do
 
   create_table "api_client_authorizations", :force => true do |t|
     t.string   "api_token",               :null => false
@@ -59,6 +59,7 @@ ActiveRecord::Schema.define(:version => 20130128231343) do
     t.integer  "redundancy_confirmed_as"
     t.datetime "updated_at"
     t.string   "uuid"
+    t.text     "manifest_text"
   end
 
   add_index "collections", ["uuid"], :name => "index_collections_on_uuid", :unique => true