def call(params)
include_ca = params.include_computed_attributes
include_ca = true if include_ca.nil?
include_ca = include_ca.to_b
results = []
return results unless include_ca
client = params.gdc_gd_client
collect_synced_status = collect_synced_status(params)
failed_projects = ThreadSafe::Array.new
params.synchronize.each do |info|
from = info.from
to_projects = info.to
params.gdc_logger.info "Synchronize Computed Attributes from project pid: #{from}"
to_projects.peach do |entry|
ca_scripts = entry[:ca_scripts]
next unless ca_scripts
pid = entry[:pid]
next if sync_failed_project(pid, params)
ca_chunks = ca_scripts[:maqlDdlChunks]
to_project = client.projects(pid)
unless to_project
process_failed_project(pid, "Invalid 'to' project specified - '#{pid}'", failed_projects, collect_synced_status)
next
end
params.gdc_logger.info "Synchronizing Computed Attributes to project: '#{to_project.title}', PID: #{pid}"
error_message = nil
begin
ca_chunks.each { |chunk| to_project.execute_maql(chunk) }
rescue => e
error_message = "Error occurred when executing MAQL for project: \"#{to_project.title}\" reason: \"#{e.message}\", chunks: #{ca_chunks.inspect}"
process_failed_project(pid, error_message, failed_projects, collect_synced_status)
end
results << {
from: from,
to: pid,
status: error_message.nil? ? 'ok' : 'failed'
}
end
end
process_failed_projects(failed_projects, short_name, params) if collect_synced_status
results
end