Class: Superset::Services::DuplicateDashboard

Inherits:
Request
  • Object
show all
Defined in:
lib/superset/services/duplicate_dashboard.rb

Constant Summary

Constants inherited from Request

Request::DEFAULT_PAGE_SIZE

Instance Attribute Summary collapse

Attributes inherited from Request

#page_num, #page_size

Instance Method Summary collapse

Methods inherited from Request

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

Methods included from Display

#ids, #list, #list_attributes, #result, #rows, #table, #title, #to_h

Constructor Details

#initialize(source_dashboard_id:, target_schema:, target_database_id:, target_dataset_suffix_override: nil, allowed_domains: [], tags: [], publish: false, target_catalog_name: nil) ⇒ DuplicateDashboard

Returns a new instance of DuplicateDashboard.



14
15
16
17
18
19
20
21
22
23
# File 'lib/superset/services/duplicate_dashboard.rb', line 14

def initialize(source_dashboard_id:, target_schema:, target_database_id: , target_dataset_suffix_override: nil, allowed_domains: [], tags: [], publish: false, target_catalog_name: nil)
  @source_dashboard_id = source_dashboard_id
  @target_schema = target_schema
  @target_database_id = target_database_id
  @target_dataset_suffix_override = target_dataset_suffix_override
  @allowed_domains = allowed_domains
  @tags = tags
  @publish = publish
  @target_catalog_name = target_catalog_name
end

Instance Attribute Details

#allowed_domainsObject (readonly)

Returns the value of attribute allowed_domains.



12
13
14
# File 'lib/superset/services/duplicate_dashboard.rb', line 12

def allowed_domains
  @allowed_domains
end

#publishObject (readonly)

Returns the value of attribute publish.



12
13
14
# File 'lib/superset/services/duplicate_dashboard.rb', line 12

def publish
  @publish
end

#source_dashboard_idObject (readonly)

Returns the value of attribute source_dashboard_id.



12
13
14
# File 'lib/superset/services/duplicate_dashboard.rb', line 12

def source_dashboard_id
  @source_dashboard_id
end

#tagsObject (readonly)

Returns the value of attribute tags.



12
13
14
# File 'lib/superset/services/duplicate_dashboard.rb', line 12

def tags
  @tags
end

#target_catalog_nameObject (readonly)

Returns the value of attribute target_catalog_name.



12
13
14
# File 'lib/superset/services/duplicate_dashboard.rb', line 12

def target_catalog_name
  @target_catalog_name
end

#target_database_idObject (readonly)

Returns the value of attribute target_database_id.



12
13
14
# File 'lib/superset/services/duplicate_dashboard.rb', line 12

def target_database_id
  @target_database_id
end

#target_dataset_suffix_overrideObject (readonly)

Returns the value of attribute target_dataset_suffix_override.



12
13
14
# File 'lib/superset/services/duplicate_dashboard.rb', line 12

def target_dataset_suffix_override
  @target_dataset_suffix_override
end

#target_schemaObject (readonly)

Returns the value of attribute target_schema.



12
13
14
# File 'lib/superset/services/duplicate_dashboard.rb', line 12

def target_schema
  @target_schema
end

Instance Method Details

#new_dashboard_json_metadata_configurationObject



68
69
70
# File 'lib/superset/services/duplicate_dashboard.rb', line 68

def 
  @new_dashboard_json_metadata_configuration ||= new_dashboard.
end

#performObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/superset/services/duplicate_dashboard.rb', line 25

def perform
  # validate all params before starting the process
  validate_params

  # Pull the Datasets for all charts on the source dashboard
  source_dashboard_datasets

  # create a new_dashboard by copying the source_dashboard using with 'duplicate_slices: true' to get a new set of charts.
  # The new_dashboard will have a copy of charts from the source_dashboard, but with the same datasets as the source_dashboard
  new_dashboard

  # Duplicate these Datasets to the new target schema and target database
  duplicate_source_dashboard_datasets

  # Update the Charts on the New Dashboard with the New Datasets and update the Dashboard json_metadata for the charts
  update_charts_with_new_datasets

  # Duplicate filters to the new target schema and target database
  duplicate_source_dashboard_filters

  

  created_embedded_config

  add_tags_to_new_dashboard

  publish_dashboard if publish

  end_log_message

  # return the new dashboard id and url
  { new_dashboard_id: new_dashboard.id, new_dashboard_url: new_dashboard.url, published: publish }

rescue => e
  logger.error("#{e.message}")
  remove_duplicated_objects
  puts "------------------------------------------------------------------------------\n"
  puts "DUPLICATE DASHBOARD FAILED - ERROR: #{e.message}\n"
  puts "REMOVED DUPLICATED OBJECTS - Check log/superset-client.log for more details\n"
  puts "------------------------------------------------------------------------------\n"
  raise e
end