Method: GoodData::LCM2::SynchronizeDataSetMapping.call

Defined in:
lib/gooddata/lcm/actions/synchronize_dataset_mappings.rb

.call(params) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/gooddata/lcm/actions/synchronize_dataset_mappings.rb', line 44

def call(params)
  results = []
  collect_synced_status = collect_synced_status(params)
  failed_projects = ThreadSafe::Array.new

  client = params.gdc_gd_client
  development_client = params.development_client
  number_of_threads = Integer(params.number_of_threads || '8')

  params.synchronize.peach(number_of_threads) do |info|
    from_project = info.from
    to_projects = info.to

    from = development_client.projects(from_project)
    unless from
      process_failed_project(from_project, "Invalid 'from' project specified - '#{from_project}'", failed_projects, collect_synced_status)
      next
    end

    dataset_mapping = from.dataset_mapping
    if dataset_mapping&.dig('datasetMappings', 'items').nil? || dataset_mapping['datasetMappings']['items'].empty?
      params.gdc_logger.info "Project: '#{from.title}', PID: '#{from.pid}' has no model mapping, skip synchronizing model mapping."
    else
      to_projects.peach(number_of_threads) do |to|
        pid = to[:pid]
        next if sync_failed_project(pid, params)

        to_project = client.projects(pid)
        process_failed_project(pid, "Invalid 'to' project specified - '#{pid}'", failed_projects, collect_synced_status) unless to_project

        message_to_project = "to project: '#{to_project.title}', PID: '#{to_project.pid}'"
        params.gdc_logger.info "Transferring model mapping, from project: '#{from.title}', PID: '#{from.pid}', #{message_to_project}"
        res = to_project.update_dataset_mapping(dataset_mapping)
        res[:from] = from.pid
        results << res

        failed_message = "Failed to transfer model mapping from project '#{from.pid}' to project '#{to_project.pid}'"
        process_failed_project(pid, failed_message, failed_projects, collect_synced_status) if collect_synced_status && res[:status] != 'OK'
      end
    end
  end

  process_failed_projects(failed_projects, short_name, params) if collect_synced_status
  # Return results
  results.flatten
end