diff --git a/app/models/collection.rb b/app/models/collection.rb index 015116ae819cd999ad898526fd766e2b5fc868ee..f9f412e261e2cf2a8d172a7e42adb4faacafffe6 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -1,5 +1,6 @@ class Collection include ActiveModel::Model + include OrientDbSerializable include RepositoriesProxy attr_accessor :id, :created_at, :last_modified, :name, :description, :privacy, :owner, :learning_objects @@ -42,7 +43,15 @@ class Collection !@name.blank? end - private + #def to_orientdb_hash + # + #end + + protected + + def excluded_orientdb_properties + ['owner'] + end def defaults { diff --git a/app/models/concerns/orient_db_serializable.rb b/app/models/concerns/orient_db_serializable.rb index ae7ff682f9d7f34160ba18a31652b08d4b0fb539..e8e222f583cc5866cd354b59321b1503602c3266 100644 --- a/app/models/concerns/orient_db_serializable.rb +++ b/app/models/concerns/orient_db_serializable.rb @@ -20,6 +20,8 @@ module OrientDbSerializable hash end - def excluded_orientdb_properties; end + def excluded_orientdb_properties + [] + end end \ No newline at end of file diff --git a/app/repositories/orient_db/collection_repository.rb b/app/repositories/orient_db/collection_repository.rb index 67836427b5b9ced2367491455f3287bfdf326605..064b5c0108ba3ab17ea141c6ef801e8283dc6cf5 100644 --- a/app/repositories/orient_db/collection_repository.rb +++ b/app/repositories/orient_db/collection_repository.rb @@ -4,10 +4,6 @@ module OrientDb include OrientDb::Methods::FinderMethods include RepositoriesProxy - def build_object(args={}) - CollectionBuilder.build_from_orientdb args - end - def save_learning_objects(collection = Collection.new) if collection.id.to_s.empty? raise NotPersistedRecordError, 'Before save learning objects to collection, you must persist using CollectionRepository::create method' @@ -116,7 +112,11 @@ module OrientDb update_property(collection, 'privacy', privacy) if privacy_accepted?(privacy) end - private + protected + + def build_object(args={}) + CollectionBuilder.build_from_orientdb args + end def accepted_properties ['privacy'] diff --git a/test/models/collection_test.rb b/test/models/collection_test.rb index d46e27a106dc7ce8c3a98242f124071879cfd911..eac7a38bfd207529fac40053bc58f206de882290 100644 --- a/test/models/collection_test.rb +++ b/test/models/collection_test.rb @@ -31,4 +31,25 @@ class CollectionTest < ActiveSupport::TestCase assert_count 1, collection.learning_objects end + test 'serialize collection for orientdb' do + collection = Collection.new(name: 'Minha coleção de teste') + assert_equal(build_collection_hash(collection), collection.to_orientdb_hash) + #collection.add LearningObject.new(id: '#43:34') + #collection.add LearningObject.new(id: '#43:53') + #assert_equal({"@class" => "Collection", "created_at" => "2015-11-18 16:10:52", "last_modified" => "2015-11-18 16:10:52", "learning_objects" => ['#43:34', '#43:53'], "privacy" => "private", "name" => "Minha coleção de teste"}, collection.to_orientdb_hash) + end + + private + + def build_collection_hash(collection) + { + "@class" => "Collection", + "created_at" => collection.created_at, + "last_modified" => collection.last_modified, + "learning_objects" => [], + "privacy" => collection.privacy, + "name" => collection.name + } + end + end \ No newline at end of file diff --git a/test/models/learning_object_test.rb b/test/models/learning_object_test.rb index 5d5243859e4b27c5a7ebc65dd0bd5c57b6af815c..3a7c972ea22a714e93b038298a11c7c1db55d486 100644 --- a/test/models/learning_object_test.rb +++ b/test/models/learning_object_test.rb @@ -13,7 +13,7 @@ class LearningObjectTest < ActiveSupport::TestCase thumbnail: '/asdasdasd.jpg', id_dspace: '123213', type: 'image', - file: LearningObject::Attachment.new('[{"id":2203,"name":"Pontociencia_Efe_chamas_na_horizontal.flv","type":"bitstream","link":"/rest/bitstreams/2203","bundleName":"ORIGINAL","description":null,"format":"Unknown","mimeType":"application/octet-stream","sizeBytes":4108209,"parentObject":null,"retrieveLink":"/bitstreams/2203/retrieve","checkSum":{"value":"43bd43bea944dcb8708d6ec708fb510d","checkSumAlgorithm":"MD5"},"sequenceId":-1,"policies":null,"expand":["parent","policies","all"]}]'), + attachment: LearningObject::Attachment.new('[{"id":2203,"name":"Pontociencia_Efe_chamas_na_horizontal.flv","type":"bitstream","link":"/rest/bitstreams/2203","bundleName":"ORIGINAL","description":null,"format":"Unknown","mimeType":"application/octet-stream","sizeBytes":4108209,"parentObject":null,"retrieveLink":"/bitstreams/2203/retrieve","checkSum":{"value":"43bd43bea944dcb8708d6ec708fb510d","checkSumAlgorithm":"MD5"},"sequenceId":-1,"policies":null,"expand":["parent","policies","all"]}]'), last_modified: '2015-03-10 15:33:45', metadata: [] )