Class: Superset::Services::DuplicateDashboard

Inherits:
Request
  • Object
show all
Defined in:
lib/superset/services/duplicate_dashboard.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_dashboard_id:, target_schema:, target_database_id:, allowed_domains: [], tags: [], publish: false) ⇒ DuplicateDashboard

Returns a new instance of DuplicateDashboard.



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

def initialize(source_dashboard_id:, target_schema:, target_database_id: , allowed_domains: [], tags: [], publish: false)
  @source_dashboard_id = source_dashboard_id
  @target_schema = target_schema
  @target_database_id = target_database_id
  @allowed_domains = allowed_domains
  @tags = tags
  @publish = publish
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_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_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



61
62
63
# File 'lib/superset/services/duplicate_dashboard.rb', line 61

def 
  @new_dashboard_json_metadata_configuration ||= new_dashboard.
end

#performObject



23
24
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
# File 'lib/superset/services/duplicate_dashboard.rb', line 23

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}")
  raise e
end