Commit 5e3d4be6 authored by hh1966's avatar hh1966
Browse files

Add support for nested collections to Export/Import

parent cbc33c56
......@@ -62,13 +62,21 @@ module Export
# get the collections from the database
collections = Collection.find(@collection_ids)
# fetch collections for export
fetch_many(collections, {
:user_id => 'User'
})
# add decendants for nested collections
if @nested
descendants = []
Collection.find(@collection_ids).each do |collection|
descendants += collection.descendants
end
collections += descendants
end
# loop over all collections
collections.each do |collection|
# fetch collection
fetch_one(collection, {
:user_id => 'User'
})
# fetch samples
fetch_many(collection.samples, {
......@@ -272,6 +280,15 @@ module Export
@data[type] = {}
end
# replace ids in the ancestry field
if instance.send('ancestry')
ancestor_uuids = []
instance.ancestor_ids.each do |ancestor_id|
ancestor_uuids << uuid(type, ancestor_id)
end
update['ancestry'] = ancestor_uuids.join('/')
end
# check if deleted_at is nil
if instance.respond_to?('deleted_at') and not instance.deleted_at.nil?
raise 'Instance with non nil deleted_at in export'
......
......@@ -71,6 +71,16 @@ module Import
def import_collections
@data.fetch('Collection', []).each do |uuid, fields|
# check the ancestry for parents
ancestry = fields.fetch('ancestry')
if ancestry
parents = ancestry.split('/')
parent_uuid = parents[-1]
parent = @instances.fetch('Collection').fetch(parent_uuid)
else
parent = nil
end
# create the collection
collection = Collection.create!(fields.slice(
'label',
......@@ -82,7 +92,8 @@ module Import
'created_at',
'updated_at'
).merge({
:user_id => @current_user_id
:user_id => @current_user_id,
:parent => parent
}))
# add collection to @instances map
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment