BigW Consortium Gitlab

Commit 2a7a1bcc by James Lopez

refactored methods in project tree restorer

parent e90b1e14
......@@ -13,19 +13,23 @@ module Projects
def restore
json = IO.read(@path)
tree_hash = ActiveSupport::JSON.decode(json)
project_params = tree_hash.reject { |_key, value| value.is_a?(Array) }
project = Projects::ImportExport::ProjectFactory.create(project_params: project_params, user: @user)
project.save
relation_hash = {}
project = create_project(tree_hash)
ImportExport.project_tree.each do |relation|
next if tree_hash[relation.to_s].empty?
relation_hash[relation.to_s] = create_relation(relation, tree_hash[relation.to_s], project.id)
project.update_attribute(relation, relation_hash[relation.to_s])
relation_hash = create_relation(relation, tree_hash[relation.to_s], project.id)
project.update_attribute(relation, relation_hash)
end
end
private
def create_project(tree_hash)
project_params = tree_hash.reject { |_key, value| value.is_a?(Array) }
project = Projects::ImportExport::ProjectFactory.create(project_params: project_params, user: @user)
project.save
project
end
def create_relation(relation, relation_hash_list, project_id)
relation_hash_list.map do |relation_hash|
Projects::ImportExport::RelationFactory.create(
......
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