Class: Superset::Chart::Duplicate

Inherits:
Request
  • Object
show all
Defined in:
lib/superset/chart/duplicate.rb

Constant Summary

Constants inherited from Request

Request::PAGE_SIZE

Instance Attribute Summary collapse

Attributes inherited from Request

#page_num

Instance Method Summary collapse

Methods inherited from Request

call, #query_params, #response, #result, #superset_host

Methods included from Display

#display_headers, #headings, #list, #list_attributes, #result, #rows, #table, #title

Constructor Details

#initialize(source_chart_id:, target_dataset_id:, new_chart_name:) ⇒ Duplicate

Returns a new instance of Duplicate.



11
12
13
14
15
# File 'lib/superset/chart/duplicate.rb', line 11

def initialize(source_chart_id: , target_dataset_id: , new_chart_name:  )
  @source_chart_id = source_chart_id
  @target_dataset_id = target_dataset_id
  @new_chart_name = new_chart_name
end

Instance Attribute Details

#new_chart_nameObject (readonly)

Returns the value of attribute new_chart_name.



9
10
11
# File 'lib/superset/chart/duplicate.rb', line 9

def new_chart_name
  @new_chart_name
end

#source_chart_idObject (readonly)

Returns the value of attribute source_chart_id.



9
10
11
# File 'lib/superset/chart/duplicate.rb', line 9

def source_chart_id
  @source_chart_id
end

#target_dataset_idObject (readonly)

Returns the value of attribute target_dataset_id.



9
10
11
# File 'lib/superset/chart/duplicate.rb', line 9

def target_dataset_id
  @target_dataset_id
end

Instance Method Details

#performObject



17
18
19
20
21
22
23
24
# File 'lib/superset/chart/duplicate.rb', line 17

def perform
  raise "Error: source_chart_id integer is required" unless source_chart_id.present? && source_chart_id.is_a?(Integer)
  raise "Error: target_dataset_id integer is required" unless target_dataset_id.present? && target_dataset_id.is_a?(Integer)
  raise "Error: new_chart_name string is required" unless new_chart_name.present? && new_chart_name.is_a?(String)

  logger.info("Duplicating Chart #{source_chart_id}:#{source_chart['slice_name']}. New chart dataset #{target_dataset_id} and new chart name #{new_chart_name}")
  Superset::Chart::Create.new(params: new_chart_params).perform
end