Skip to content
Snippets Groups Projects
Commit f86b9b3d authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

adding OrientDbSerializable module in collection model

parent feaa4cec
No related branches found
No related tags found
No related merge requests found
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
{
......
......@@ -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
......@@ -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']
......
......@@ -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
......@@ -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: []
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment