Class: GoodData::Project

Inherits:
Rest::Resource show all
Includes:
Mixin::Author, Mixin::Contributor, Mixin::UriGetter
Defined in:
lib/gooddata/models/project.rb

Constant Summary collapse

USER_ACCOUNT_PATH =
'/gdc/account/profile/'
USERSPROJECTS_PATH =
USER_ACCOUNT_PATH + '%s/projects'
PROJECTS_PATH =
'/gdc/projects'
PROJECT_PATH =
'/gdc/projects/%s'
SLIS_PATH =
'/ldm/singleloadinterface'
DEFAULT_INVITE_MESSAGE =
'Join us!'
DEFAULT_ENVIRONMENT =
'PRODUCTION'
EMPTY_OBJECT =
{
  'project' => {
    'meta' => {
      'summary' => 'No summary'
    },
    'content' => {
      'guidedNavigation' => 1,
      'driver' => 'Pg',
      'environment' => GoodData::Helpers::AuthHelper.read_environment
    }
  }
}

Instance Attribute Summary collapse

Attributes inherited from Rest::Object

#client, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::Contributor

#contributor

Methods included from Mixin::Author

#author, #author_uri

Methods inherited from Rest::Object

client, default_client, #saved?

Methods included from Mixin::DataPropertyReader

#data_property_reader

Methods included from Mixin::DataPropertyWriter

#data_property_writer

Methods included from Mixin::MetaPropertyReader

#metadata_property_reader

Methods included from Mixin::MetaPropertyWriter

#metadata_property_writer

Methods included from Mixin::MetaGetter

#meta

Methods included from Mixin::DataGetter

#data

Methods included from Mixin::RootKeyGetter

#root_key

Methods included from Mixin::ContentGetter

#content

Constructor Details

#initialize(json) ⇒ Project

Initializes object instance from raw wire JSON

Parameters:

  • json

    Json used for initialization



1271
1272
1273
1274
1275
# File 'lib/gooddata/models/project.rb', line 1271

def initialize(json)
  super
  @json = json
  @log_formatter = GoodData::ProjectLogFormatter.new(self)
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



63
64
65
# File 'lib/gooddata/models/project.rb', line 63

def connection
  @connection
end

#jsonObject

Returns the value of attribute json.



63
64
65
# File 'lib/gooddata/models/project.rb', line 63

def json
  @json
end

Class Method Details

.[](id, opts = { client: GoodData.connection }) ⇒ Object

Returns a Project object identified by given string The following identifiers are accepted

  • /gdc/md/
  • /gdc/projects/


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/gooddata/models/project.rb', line 83

def [](id, opts = { client: GoodData.connection })
  return id if id.instance_of?(GoodData::Project) || id.respond_to?(:project?) && id.project?

  if id == :all
    Project.all({ client: GoodData.connection }.merge(opts))
  else
    fail(ArgumentError, 'wrong type of argument. Should be either project ID or path') unless project_id_or_path?(id)

    id = id.match(/[a-zA-Z\d]+$/)[0] if id =~ %r{/}

    c = GoodData.get_client(opts)
    response = c.get(PROJECT_PATH % id)
    c.factory.create(Project, response)
  end
end

.add_user_groups_to_dashboard(group_dashboards, dashboard, common_group_names, target_user_groups) ⇒ Object



503
504
505
506
507
508
509
510
511
512
513
# File 'lib/gooddata/models/project.rb', line 503

def add_user_groups_to_dashboard(group_dashboards, dashboard, common_group_names, target_user_groups)
  group_dashboards.each do |group_dashboard|
    group_name = group_dashboard[:name]
    next if common_group_names && common_group_names[group_name]

    target_user_group = target_user_groups.select { |group| group.name == group_name }.first
    next unless target_user_group

    dashboard.grant(:member => target_user_group, :permission => group_dashboard[:permission])
  end
end

.all(opts = { client: GoodData.connection }, limit = nil, offset = nil) ⇒ Object

Returns an array of all projects accessible by current user



72
73
74
75
# File 'lib/gooddata/models/project.rb', line 72

def all(opts = { client: GoodData.connection }, limit = nil, offset = nil)
  c = GoodData.get_client(opts)
  c.user.projects(limit, offset)
end

.clone_with_etl(project, options = {}) ⇒ GoodData::Project

Clones project along with etl and schedules

Parameters:

  • project (Project)

    Project to be cloned from

  • Options (options)

    that are passed into project.clone

Returns:



108
109
110
111
112
# File 'lib/gooddata/models/project.rb', line 108

def clone_with_etl(project, options = {})
  a_clone = project.clone(options)
  GoodData::Project.transfer_etl(project.client, project, a_clone)
  a_clone
end

.collect_process_aliases(process_data, client, aliases) ⇒ Object



366
367
368
369
370
371
372
373
374
375
376
# File 'lib/gooddata/models/project.rb', line 366

def collect_process_aliases(process_data, client, aliases)
  data_sources = process_data.dig('process', 'dataSources')
  unless data_sources.blank?
    data_sources.map do |data_source|
      get_data_source_alias(data_source['id'], client, aliases)
    end
  end
  component = process_data.dig('process', 'component')
  get_data_source_alias(component['configLocation']['dataSourceConfig']['id'], client, aliases) if component&.dig('configLocation', 'dataSourceConfig')
  aliases
end

.create(opts = { client: GoodData.connection }, &block) ⇒ Object

Create a project from a given attributes Expected keys:

  • :title (mandatory)
  • :summary
  • :template (default /projects/blank)


137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/gooddata/models/project.rb', line 137

def create(opts = { client: GoodData.connection }, &block)
  GoodData.logger.info "Creating project #{opts[:title]}"

  auth_token = opts[:auth_token] || opts[:token]
  if auth_token.nil? || auth_token.empty?
    opts = { auth_token: Helpers::AuthHelper.read_token }.merge(opts)
    auth_token = opts[:auth_token]
  end
  fail ArgumentError, 'You have to provide your token for creating projects as :auth_token or :token parameter' if auth_token.nil? || auth_token.empty?

  project = create_object(opts)
  project.save
  # until it is enabled or deleted, recur. This should still end if there
  # is a exception thrown out from RESTClient. This sometimes happens from
  # WebApp when request is too long
  while project.state.to_s != 'enabled'
    if project.deleted?
      # if project is switched to deleted state, fail. This is usually problem of creating a template which is invalid.
      fail 'Project was marked as deleted during creation. This usually means you were trying to create from template and it failed.'
    end
    sleep(3)
    project.reload!
  end

  if block
    GoodData.with_project(project) do |p|
      block.call(p)
    end
  end
  sleep 3
  project
end

.create_from_blueprint(blueprint, options = {}) ⇒ Object



178
179
180
# File 'lib/gooddata/models/project.rb', line 178

def create_from_blueprint(blueprint, options = {})
  GoodData::Model::ProjectCreator.migrate(options.merge(spec: blueprint, client: client))
end

.create_object(data = {}) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/gooddata/models/project.rb', line 114

def create_object(data = {})
  c = GoodData.get_client(data)
  new_data = GoodData::Helpers.deep_dup(EMPTY_OBJECT).tap do |d|
    d['project']['meta']['title'] = data[:title]
    d['project']['meta']['summary'] = data[:summary] if data[:summary]
    d['project']['meta']['projectTemplate'] = data[:template] if data[:template]
    d['project']['content']['guidedNavigation'] = data[:guided_navigation] if data[:guided_navigation]

    token = data[:auth_token] || data[:token]

    d['project']['content']['authorizationToken'] = token if token
    d['project']['content']['driver'] = data[:driver] if data[:driver]
    d['project']['content']['environment'] = data[:environment] if data[:environment]
  end
  c.create(Project, new_data)
end

.dashboard_user_groups(user_groups, dashboard) ⇒ Object



475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
# File 'lib/gooddata/models/project.rb', line 475

def dashboard_user_groups(user_groups, dashboard)
  group_dashboards = []
  dashboard_grantees = dashboard.grantees['granteeURIs']['items'].select { |item| item['aclEntryURI']['grantee'].include?('/usergroups/') }

  dashboard_grantees.each do |dashboard_grantee|
    permission = dashboard_grantee['aclEntryURI']['permission']
    group_id = dashboard_grantee['aclEntryURI']['grantee'].split('/').last
    user_group = user_groups.select { |group| group.links['self'].split('/').last == group_id }.first
    next unless user_group

    group_dashboards << {
      name: user_group.name,
      user_group: user_group,
      permission: permission
    }
  end
  group_dashboards
end

.find(opts = { client: GoodData.connection }) ⇒ Object



170
171
172
173
174
175
176
# File 'lib/gooddata/models/project.rb', line 170

def find(opts = { client: GoodData.connection })
  c = GoodData.get_client(opts)
  user = c.user
  user.projects['projects'].map do |project|
    c.create(GoodData::Project, project)
  end
end

.get_data_source_alias(data_source_id, client, aliases) ⇒ Object



378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/gooddata/models/project.rb', line 378

def get_data_source_alias(data_source_id, client, aliases)
  unless aliases[data_source_id]
    data_source = GoodData::DataSource.from_id(data_source_id, client: client)
    if data_source&.alias
      aliases[data_source_id] = {
        :type => data_source.type,
        :alias => data_source.alias
      }
    end
  end
  aliases[data_source_id]
end

.get_dataset_mapping(from_project) ⇒ Object



260
261
262
# File 'lib/gooddata/models/project.rb', line 260

def get_dataset_mapping(from_project)
  GoodData::DatasetMapping.get(:client => from_project.client, :project => from_project)
end

.get_ldm_layout(from_project) ⇒ Object



276
277
278
279
280
281
# File 'lib/gooddata/models/project.rb', line 276

def get_ldm_layout(from_project)
  GoodData::LdmLayout.get(:client => from_project.client, :project => from_project)
rescue StandardError => e
  GoodData.logger.warn "An unexpected error when get ldm layout. Error: #{e.message}"
  GoodData::LdmLayout::DEFAULT_EMPTY_LDM_LAYOUT
end

.project_id_or_path?(id) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/gooddata/models/project.rb', line 99

def project_id_or_path?(id)
  id.to_s =~ %r{^(\/gdc\/(projects|md)\/)?[a-zA-Z\d]+$}
end

.remove_user_groups_from_dashboard(group_dashboards, dashboard, common_group_names) ⇒ Object



494
495
496
497
498
499
500
501
# File 'lib/gooddata/models/project.rb', line 494

def remove_user_groups_from_dashboard(group_dashboards, dashboard, common_group_names)
  group_dashboards.each do |group_dashboard|
    group_name = group_dashboard[:name]
    next if common_group_names && common_group_names[group_name]

    dashboard.revoke(:member => group_dashboard[:user_group], :permission => group_dashboard[:permission])
  end
end

.replace_data_source_ids(data_sources, client, aliases) ⇒ Object



401
402
403
404
405
406
407
408
409
410
# File 'lib/gooddata/models/project.rb', line 401

def replace_data_source_ids(data_sources, client, aliases)
  array_data_sources = []
  if data_sources && !data_sources.empty?
    data_sources.map do |data_source|
      new_id = verify_data_source_alias(aliases[data_source[:id]], client)
      array_data_sources.push(:id => new_id)
    end
  end
  array_data_sources
end

.replace_process_data_source_ids(process_data, client, aliases) ⇒ Object



391
392
393
394
395
396
397
398
399
# File 'lib/gooddata/models/project.rb', line 391

def replace_process_data_source_ids(process_data, client, aliases)
  component = process_data.dig(:process, :component)
  if component&.dig(:configLocation, :dataSourceConfig)
    the_alias = aliases[component[:configLocation][:dataSourceConfig][:id]]
    process_data[:process][:component][:configLocation][:dataSourceConfig][:id] = verify_data_source_alias(the_alias, client)
  end
  process_data[:process][:dataSources] = replace_data_source_ids(process_data[:process][:dataSources], client, aliases)
  process_data
end

.save_ldm_layout(ldm_layout_json, to_project) ⇒ Object



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/gooddata/models/project.rb', line 283

def save_ldm_layout(ldm_layout_json, to_project)
  ldm_layout = GoodData::LdmLayout.new(ldm_layout_json)
  begin
    ldm_layout.save(:client => to_project.client, :project => to_project)
    status = "OK"
  rescue StandardError => e
    GoodData.logger.warn "An unexpected error when save ldm layout. Error: #{e.message}"
    status = "Failed"
  end

  {
    to: to_project.pid,
    status: status
  }
end

.transfer_color_palette(from_project, to_project) ⇒ Object



726
727
728
729
# File 'lib/gooddata/models/project.rb', line 726

def transfer_color_palette(from_project, to_project)
  colors = from_project.current_color_palette
  to_project.create_custom_color_palette(colors) unless colors.empty?
end

.transfer_dashboard_permission(from_project, to_project, source_dashboards, target_dashboards) ⇒ Object



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/gooddata/models/project.rb', line 453

def transfer_dashboard_permission(from_project, to_project, source_dashboards, target_dashboards)
  source_user_groups = from_project.user_groups
  target_user_groups = to_project.user_groups

  source_dashboards.each do |source_dashboard|
    target_dashboard = target_dashboards.select { |dash| dash.title == source_dashboard.title }.first
    next unless target_dashboard

    begin
      source_group_dashboards = dashboard_user_groups(source_user_groups, source_dashboard)
      target_group_dashboards = dashboard_user_groups(target_user_groups, target_dashboard)

      common_group_names = source_group_dashboards.flat_map { |s| target_group_dashboards.select { |t| t[:name] == s[:name] } }.map { |x| [x[:name], true] }.to_h

      remove_user_groups_from_dashboard(target_group_dashboards, target_dashboard, common_group_names)
      add_user_groups_to_dashboard(source_group_dashboards, target_dashboard, common_group_names, target_user_groups)
    rescue StandardError => e
      GoodData.logger.warn "Failed to synchronize dashboard permission from project: '#{from_project.title}', PID: '#{from_project.pid}' to project: '#{to_project.title}', PID: '#{to_project.pid}', dashboard: '#{target_dashboard.title}', dashboard uri: '#{target_dashboard.uri}' . Error: #{e.message} - #{e}" # rubocop:disable Metrics/LineLength
    end
  end
end

.transfer_etl(client, from_project, to_project) ⇒ Object

Clones project along with etl and schedules.

Object to be cloned from. Can be either segment in which case we take the master, client in which case we take its project, string in which case we treat is as an project object or directly project

Parameters:



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/gooddata/models/project.rb', line 238

def transfer_etl(client, from_project, to_project)
  from_project = case from_project
                 when GoodData::Client
                   from_project.project
                 when GoodData::Segment
                   from_project.master_project
                 else
                   client.projects(from_project)
                 end

  to_project = case to_project
               when GoodData::Client
                 to_project.project
               when GoodData::Segment
                 to_project.master_project
               else
                 client.projects(to_project)
               end
  transfer_processes(from_project, to_project)
  transfer_schedules(from_project, to_project)
end

.transfer_output_stage(from_project, to_project, options) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/gooddata/models/project.rb', line 199

def transfer_output_stage(from_project, to_project, options)
  from_prj_output_stage = from_project.add.output_stage
  output_stage_prefix = options[:ads_output_stage_prefix] || from_prj_output_stage.output_stage_prefix
  output_stage_uri = options[:ads_output_stage_uri] || from_prj_output_stage.schema
  if from_project.processes.any? { |p| p.type == :dataload }
    if to_project.processes.any? { |p| p.type == :dataload }
      to_project.add.output_stage.schema = output_stage_uri
      to_project.add.output_stage.output_stage_prefix = output_stage_prefix
      to_project.add.output_stage.save
    else
      from_server = from_project.client.connection.server.url
      to_server = to_project.client.connection.server.url
      if from_server != to_server && options[:ads_output_stage_uri].nil?
        raise "Cannot transfer output stage from #{from_server} to #{to_server}. " \
              'It is not possible to transfer output stages between ' \
              'different domains. Please specify an address of an output ' \
              'stage that is in the same domain as the target project ' \
              'using the "ads_output_stage_uri" parameter.'
      end

      to_project.add.output_stage = GoodData::AdsOutputStage.create(
        client: to_project.client,
        ads: output_stage_uri,
        client_id: from_prj_output_stage.client_id,
        output_stage_prefix: output_stage_prefix,
        project: to_project
      )
    end
  end
end

.transfer_processes(from_project, to_project, options = {}) ⇒ Object

Parameters:

  • from_project

    The source project

  • to_project

    The target project

  • options (defaults to: {})

    Optional parameters

  • ads_output_stage_uri (Hash)

    a customizable set of options



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/gooddata/models/project.rb', line 303

def transfer_processes(from_project, to_project, options = {})
  options = GoodData::Helpers.symbolize_keys(options)
  aliases = {}
  to_project_processes = to_project.processes
  additional_hidden_params = options[:additional_hidden_params] || {}
  result = from_project.processes.uniq(&:name).map do |process|
    fail "The process name #{process.name} must be unique in transferred project #{to_project}" if to_project_processes.count { |p| p.name == process.name } > 1
    next if process.type == :dataload || process.add_v2_component?
    collect_process_aliases(process.data, from_project.client, aliases)

    to_process = to_project_processes.find { |p| p.name == process.name }

    data_sources = GoodData::Helpers.symbolize_keys_recursively!(process.data_sources)
    data_sources = replace_data_source_ids(data_sources, to_project.client, aliases)
    to_process = if process.path
                   to_process.delete if to_process
                   Process.deploy_from_appstore(process.path, name: process.name, client: to_project.client, project: to_project, data_sources: data_sources)
                 elsif process.component
                   to_process.delete if to_process
                   process_hash = GoodData::Helpers::DeepMergeableHash[GoodData::Helpers.symbolize_keys(process.to_hash)].deep_merge(additional_hidden_params)
                   process_hash = replace_process_data_source_ids(process_hash, to_project.client, aliases)
                   Process.deploy_component(process_hash, project: to_project, client: to_project.client)
                 else
                   Dir.mktmpdir('etl_transfer') do |dir|
                     dir = Pathname(dir)
                     filename = dir + 'process.zip'
                     File.open(filename, 'w') do |f|
                       f << process.download
                     end
                     if to_process
                       to_process.deploy(filename, type: process.type, name: process.name, data_sources: data_sources)
                     else
                       to_project.deploy_process(filename, type: process.type, name: process.name, data_sources: data_sources)
                     end
                   end
                 end

    {
      from: from_project.pid,
      to: to_project.pid,
      name: process.name,
      status: to_process ? 'successful' : 'failed'
    }
  end

  transfer_output_stage(from_project, to_project, options)
  result << {
    from: from_project.pid,
    to: to_project.pid,
    name: 'Automated Data Distribution',
    status: 'successful'
  }

  res = (from_project.processes + to_project.processes).map { |p| [p, p.name, p.type] }
  res.group_by { |x| [x[1], x[2]] }
    .select { |_, procs| procs.length == 1 && procs[2] != :dataload }
    .reject { |_, procs| procs.first.first.add_v2_component? }
    .flat_map { |_, procs| procs.select { |p| p[0].project.pid == to_project.pid }.map { |p| p[0] } }
    .peach(&:delete)

  result.compact
end

.transfer_schedules(from_project, to_project, has_cycle_trigger = false) ⇒ Object

Clones project along with etl and schedules.

Object to be cloned from. Can be either segment in which case we take the master, client in which case we take its project, string in which case we treat is as an project object or directly project.

Parameters:



522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
# File 'lib/gooddata/models/project.rb', line 522

def transfer_schedules(from_project, to_project, has_cycle_trigger = false)
  to_project_processes = to_project.processes.sort_by(&:name)
  from_project_processes = from_project.processes.sort_by(&:name)
  from_project_processes.reject!(&:add_v2_component?)

  GoodData.logger.debug("Processes in from project #{from_project.pid}: #{from_project_processes.map(&:name).join(', ')}")
  GoodData.logger.debug("Processes in to project #{to_project.pid}: #{to_project_processes.map(&:name).join(', ')}")

  cache = to_project_processes
            .zip(from_project_processes)
            .flat_map do |remote, local|
              local.schedules.map do |schedule|
                [remote, local, schedule]
              end
            end

  remote_schedules = to_project.schedules
  remote_stuff = remote_schedules.map do |s|
    v = s.to_hash
    after_schedule = remote_schedules.find { |s2| s.trigger_id == s2.obj_id }
    v[:after] = s.trigger_id && after_schedule && after_schedule.name
    v[:remote_schedule] = s
    v[:params] = v[:params].except("EXECUTABLE", "PROCESS_ID")
    v.compact
  end

  local_schedules = from_project.schedules
  local_stuff = local_schedules.map do |s|
    v = s.to_hash
    after_schedule = local_schedules.find { |s2| s.trigger_id == s2.obj_id }
    after_process_schedule = from_project_processes.find { |p| after_schedule && p.obj_id == after_schedule.process_id }
    v[:after] = s.trigger_id && after_process_schedule && after_schedule && after_schedule.name
    v[:trigger_execution_status] = s.trigger_execution_status
    v[:remote_schedule] = s
    v[:params] = v[:params].except("EXECUTABLE", "PROCESS_ID")
    v.compact
  end

  diff = GoodData::Helpers.diff(remote_stuff, local_stuff, key: :name, fields: [:name, :cron, :after, :params, :hidden_params, :reschedule, :state])
  stack = diff[:added].map do |x|
    [:added, x]
  end

  stack += diff[:changed].map do |x|
    [:changed, x]
  end

  schedule_cache = remote_schedules.reduce({}) do |a, e|
    a[e.name] = e
    a
  end

  results = []
  update_trigger_schedules = []
  loop do # rubocop:disable Metrics/BlockLength
    break if stack.empty?
    state, changed_schedule = stack.shift
    lazy_update_trigger_info = false
    if state == :added
      schedule_spec = changed_schedule
      if schedule_spec[:after] && !schedule_cache[schedule_spec[:after]]
        if has_cycle_trigger
          # The schedule is triggered by another schedule
          lazy_update_trigger_info = true
        else
          stack << [state, schedule_spec]
          next
        end
      end

      remote_process, process_spec = cache.find do |_remote, local, schedule|
        (schedule_spec[:process_id] == local.process_id) && (schedule.name == schedule_spec[:name])
      end

      next unless remote_process || process_spec

      GoodData.logger.info("Creating schedule #{schedule_spec[:name]} for process #{remote_process.name}")

      executable = nil
      if process_spec.type != :dataload
        executable = schedule_spec[:executable] || (process_spec.type == :ruby ? 'main.rb' : 'main.grf')
      end

      params = schedule_parameters(schedule_spec)

      if lazy_update_trigger_info
        # Temporary update nil for trigger info. The trigger info will be update late after transfer all schedules
        created_schedule = remote_process.create_schedule(nil, executable, params)
        update_trigger_schedules << {
          state: :added,
          schedule: created_schedule,
          after: schedule_spec[:after]
        }
      else
        created_schedule = remote_process.create_schedule(schedule_spec[:cron] || schedule_cache[schedule_spec[:after]], executable, params)
      end

      schedule_cache[created_schedule.name] = created_schedule

      results << {
        state: :added,
        process: remote_process,
        schedule: created_schedule
      }
    else
      schedule_spec = changed_schedule[:new_obj]
      if schedule_spec[:after] && !schedule_cache[schedule_spec[:after]]
        if has_cycle_trigger
          # The schedule is triggered by another schedule
          lazy_update_trigger_info = true
        else
          stack << [state, schedule_spec]
          next
        end
      end

      remote_process, process_spec = cache.find do |i|
        i[2].name == schedule_spec[:name]
      end

      schedule = changed_schedule[:old_obj][:remote_schedule]

      GoodData.logger.info("Updating schedule #{schedule_spec[:name]} for process #{remote_process.name}")

      schedule.params = (schedule_spec[:params] || {})
      schedule.cron = schedule_spec[:cron] if schedule_spec[:cron]

      unless lazy_update_trigger_info
        schedule.after = schedule_cache[schedule_spec[:after]] if schedule_spec[:after]
        schedule.trigger_execution_status = schedule_cache[schedule_spec[:trigger_execution_status]] if schedule_spec[:after]
      end

      schedule.hidden_params = schedule_spec[:hidden_params] || {}
      if process_spec.type != :dataload
        schedule.executable = schedule_spec[:executable] || (process_spec.type == :ruby ? 'main.rb' : 'main.grf')
      end

      schedule.reschedule = schedule_spec[:reschedule]
      schedule.name = schedule_spec[:name]
      schedule.state = schedule_spec[:state]
      schedule.save
      schedule_cache[schedule.name] = schedule

      if lazy_update_trigger_info
        update_trigger_schedules << {
          state: :changed,
          schedule: schedule,
          after: schedule_spec[:after],
          trigger_execution_status: schedule_spec[:trigger_execution_status]
        }
      end

      results << {
        state: :changed,
        process: remote_process,
        schedule: schedule
      }
    end
  end

  if has_cycle_trigger
    update_trigger_schedules.each do |update_trigger_schedule|
      working_schedule = update_trigger_schedule[:schedule]
      working_schedule.after = schedule_cache[update_trigger_schedule[:after]]
      working_schedule.trigger_execution_status = schedule_cache[update_trigger_schedule[:trigger_execution_status]] if update_trigger_schedule[:state] == :changed

      # Update trigger info
      working_schedule.save

      # Update transfer result
      results.each do |transfer_result|
        transfer_result[:schedule] = working_schedule if transfer_result[:schedule].obj_id == working_schedule.obj_id
      end
    end
  end

  diff[:removed].each do |removed_schedule|
    GoodData.logger.info("Removing schedule #{removed_schedule[:name]}")

    removed_schedule[:remote_schedule].delete

    results << {
      state: :removed,
      process: removed_schedule.process,
      schedule: removed_schedule
    }
  end

  results
end

.transfer_tagged_stuff(from_project, to_project, tag) ⇒ Object



713
714
715
716
717
718
719
720
721
722
723
724
# File 'lib/gooddata/models/project.rb', line 713

def transfer_tagged_stuff(from_project, to_project, tag)
  GoodData.logger.info("Transferring tagged stuff - #{tag}")

  objects = from_project.find_by_tag(tag)

  if objects.any?
    GoodData.logger.info("\n#{JSON.pretty_generate(objects)}")
    from_project.partial_md_export(objects, project: to_project)
  else
    GoodData.logger.info('No tagged objects to transfer')
  end
end

.transfer_user_groups(from_project, to_project) ⇒ Object



434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/gooddata/models/project.rb', line 434

def transfer_user_groups(from_project, to_project)
  from_project.user_groups.map do |ug|
    # migrate groups
    new_group = to_project.user_groups.select { |group| group.name == ug.name }.first
    new_group_status = new_group ? 'modified' : 'created'
    new_group ||= UserGroup.create(:name => ug.name, :description => ug.description, :project => to_project)
    new_group.project = to_project
    new_group.description = ug.description
    new_group.save

    {
      from: from_project.pid,
      to: to_project.pid,
      user_group: new_group.name,
      status: new_group_status
    }
  end
end

.update_dataset_mapping(model_mapping_json, to_project) ⇒ Object



264
265
266
267
268
269
270
271
272
273
274
# File 'lib/gooddata/models/project.rb', line 264

def update_dataset_mapping(model_mapping_json, to_project)
  dataset_mapping = GoodData::DatasetMapping.new(model_mapping_json)
  res = dataset_mapping.save(:client => to_project.client, :project => to_project)
  status = res&.dig('datasetMappings', 'items').nil? ? "Failed" : "OK"
  count = "OK".eql?(status) ? res['datasetMappings']['items'].length : 0
  {
    to: to_project.pid,
    count: count,
    status: status
  }
end

.user_csv_import(row) ⇒ Object

Takes one CSV line and creates hash from data extracted

Parameters:

  • row

    CSV row



185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/gooddata/models/project.rb', line 185

def user_csv_import(row)
  {
    'user' => {
      'content' => {
        'email' => row[0],
        'login' => row[1],
        'firstname' => row[2],
        'lastname' => row[3]
      },
      'meta' => {}
    }
  }
end

.verify_data_source_alias(ds_alias, client) ⇒ String

Verify whether the data source exists in the domain using its alias

Parameters:

  • ds_alias (String)

    The data source's alias

  • client (Object)

    The Rest Client object

Returns:

  • (String)

    Id of the data source or failed with the reason



417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/gooddata/models/project.rb', line 417

def verify_data_source_alias(ds_alias, client)
  domain = client.connection.server.url
  fail "The data source alias is empty, check your data source configuration." unless ds_alias

  uri = "/gdc/dataload/dataSources/internal/availableAlias?alias=#{ds_alias[:alias]}"
  res = client.get(uri)
  fail "Unable to get information about the Data Source '#{ds_alias[:alias]}' in the domain '#{domain}'" unless res
  fail "Unable to find the #{ds_alias[:type]} Data Source '#{ds_alias[:alias]}' in the domain '#{domain}'" if res['availableAlias']['available']

  ds_type = res['availableAlias']['existingDataSource']['type']
  if ds_type && ds_type != ds_alias[:type]
    fail "Wrong Data Source type - the '#{ds_type}' type is expected but the Data Source '#{ds_alias[:alias]}' in the domain '#{domain}' has the '#{ds_alias[:type]}' type"
  else
    res['availableAlias']['existingDataSource']['id']
  end
end

Instance Method Details

#addObject



2200
2201
2202
2203
# File 'lib/gooddata/models/project.rb', line 2200

def add
  @add ||= GoodData::AutomatedDataDistribution.new(self)
  @add
end

#add_dashboard(dashboard) ⇒ Object Also known as: create_dashboard



745
746
747
# File 'lib/gooddata/models/project.rb', line 745

def add_dashboard(dashboard)
  GoodData::Dashboard.create(dashboard, :client => client, :project => self)
end

#add_data_permissions(filters, options = {}) ⇒ Object



2116
2117
2118
2119
# File 'lib/gooddata/models/project.rb', line 2116

def add_data_permissions(filters, options = {})
  GoodData.logger.info("Synchronizing #{filters.count} filters in project #{pid}")
  GoodData::UserFilterBuilder.execute_mufs(filters, { client: client, project: self }.merge(options))
end

#add_metric(metric, options = {}) ⇒ GoodData::Report Also known as: create_metric, add_measure, create_measure

Creates a metric in a project

Parameters:

  • Optional (options)

    report options

Returns:



767
768
769
770
771
772
773
774
# File 'lib/gooddata/models/project.rb', line 767

def add_metric(metric, options = {})
  default = { client: client, project: self }
  if metric.is_a?(String)
    GoodData::Metric.xcreate(metric, options.merge(default))
  else
    GoodData::Metric.xcreate(options[:expression], metric.merge(options.merge(default)))
  end
end

#add_report(options = {}) ⇒ GoodData::Report Also known as: create_report

Creates new instance of report in context of project

Parameters:

  • Optional (options)

    report options

Returns:



785
786
787
788
# File 'lib/gooddata/models/project.rb', line 785

def add_report(options = {})
  report = GoodData::Report.create(options.merge(client: client, project: self))
  report.save
end

#add_report_definition(json) ⇒ GoodData::ReportDefinition Also known as: create_report_definition

Creates new instance of report definition in context of project This report definition can be used for creating of GoodData::Report

Parameters:

  • Raw (json)

    report definition json

Returns:



797
798
799
800
801
802
# File 'lib/gooddata/models/project.rb', line 797

def add_report_definition(json)
  rd = GoodData::ReportDefinition.new(json)
  rd.client = client
  rd.project = self
  rd.save
end

#add_user_group(data) ⇒ Object Also known as: create_group



751
752
753
754
755
756
757
758
759
# File 'lib/gooddata/models/project.rb', line 751

def add_user_group(data)
  g = GoodData::UserGroup.create(data.merge(project: self))

  begin
    g.save
  rescue RestClient::Conflict
    user_groups(data[:name])
  end
end

#add_variable_permissions(filters, var, options = {}) ⇒ Object



2121
2122
2123
# File 'lib/gooddata/models/project.rb', line 2121

def add_variable_permissions(filters, var, options = {})
  GoodData::UserFilterBuilder.execute_variables(filters, var, { client: client, project: self }.merge(options))
end

#am_i_admin?Boolean

Returns an indication whether current user is admin in this project

Returns:

  • (Boolean)

    True if user has admin role in the project, false otherwise.



809
810
811
# File 'lib/gooddata/models/project.rb', line 809

def am_i_admin?
  user_has_role?(client.user, 'admin')
end

#analytical_dashboards(id = :all) ⇒ GoodData::AnalyticalDashboard | Array<GoodData::AnalyticalDashboard>

Helper for getting analytical dashboards (KD dashboards) of a project

Parameters:

  • id (String | Number | Object) (defaults to: :all)

    Anything that you can pass to GoodData::Dashboard[id]

Returns:



1009
1010
1011
# File 'lib/gooddata/models/project.rb', line 1009

def analytical_dashboards(id = :all)
  GoodData::AnalyticalDashboard[id, project: self, client: client]
end

#attribute_by_identifier(identifier) ⇒ Object



830
831
832
# File 'lib/gooddata/models/project.rb', line 830

def attribute_by_identifier(identifier)
  GoodData::Attribute.find_first_by_identifier(identifier, project: self, client: client)
end

#attribute_by_title(title) ⇒ Object



838
839
840
# File 'lib/gooddata/models/project.rb', line 838

def attribute_by_title(title)
  GoodData::Attribute.find_first_by_title(title, project: self, client: client)
end

#attributes(id = :all) ⇒ GoodData::Attribute | Array<GoodData::Attribute>

Helper for getting attributes of a project

Parameters:

  • Anything (String | Number | Object)

    that you can pass to GoodData::Attribute[id]

Returns:



817
818
819
# File 'lib/gooddata/models/project.rb', line 817

def attributes(id = :all)
  GoodData::Attribute[id, project: self, client: client]
end

#attributes_by_identifier(identifier) ⇒ Object



834
835
836
# File 'lib/gooddata/models/project.rb', line 834

def attributes_by_identifier(identifier)
  GoodData::Attribute.find_by_identifier(identifier, project: self, client: client)
end

#attributes_by_title(title) ⇒ Object



842
843
844
# File 'lib/gooddata/models/project.rb', line 842

def attributes_by_title(title)
  GoodData::Attribute.find_by_title(title, project: self, client: client)
end

#blueprint(options = {}) ⇒ GoodData::ProjectRole

Gets project blueprint from the server

Returns:



849
850
851
852
853
854
855
856
857
858
# File 'lib/gooddata/models/project.rb', line 849

def blueprint(options = {})
  options = { include_ca: true }.merge(options)
  result = client.get("/gdc/projects/#{pid}/model/view", params: { includeDeprecated: true, includeGrain: true, includeCA: options[:include_ca] })

  polling_url = result['asyncTask']['link']['poll']
  model = client.poll_on_code(polling_url, options)
  bp = GoodData::Model::FromWire.from_wire(model, options)
  bp.title = title
  bp
end

#browser_uri(options = {}) ⇒ String

Returns web interface URI of project

Returns:

  • (String)

    Project URL



863
864
865
866
867
868
869
870
871
# File 'lib/gooddata/models/project.rb', line 863

def browser_uri(options = {})
  grey = options[:grey]
  server = client.connection.server_url
  if grey
    "#{server}#{uri}"
  else
    "#{server}/#s=#{uri}"
  end
end

#check_groups(specified_groups, user_groups_cache = nil, options = {}) ⇒ Object



2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
# File 'lib/gooddata/models/project.rb', line 2026

def check_groups(specified_groups, user_groups_cache = nil, options = {})
  current_user_groups = user_groups if user_groups_cache.nil? || user_groups_cache.empty?
  groups = current_user_groups.map(&:name)
  missing_groups = []
  change_groups = {}
  specified_groups.each do |group|
    found_group = groups.find { |name| name.casecmp(group).zero? }
    if found_group.nil?
      missing_groups << group
    else
      # Change groups when they have similar group name with difference of case sensitivity
      if found_group != group
        change_groups[group] = found_group
        GoodData.logger.warn("Group with name #{group} is existed in project with name #{found_group}.")
      end
    end
  end
  if options[:create_non_existing_user_groups]
    missing_groups.each do |g|
      GoodData.logger.info("Creating group #{g}")
      create_group(name: g, description: g)
    end
  else
    unless missing_groups.empty?
      fail 'All groups have to be specified before you try to import ' \
        'users. Groups that are currently in project are ' \
        "#{groups.join(',')} and you asked for #{missing_groups.join(',')}"
    end
  end
  [current_user_groups, change_groups]
end

#clone(options = {}) ⇒ GoodData::Project

Clones project

Parameters:

  • options (Hash) (defaults to: {})

    Export options

Options Hash (options):

  • :data (Boolean)

    Clone project with data

  • :users (Boolean)

    Clone project with users

  • :exclude_schedules (Boolean)

    Specifies whether to include scheduled emails

Returns:



880
881
882
883
884
885
886
887
888
889
890
891
892
893
# File 'lib/gooddata/models/project.rb', line 880

def clone(options = {})
  a_title = options[:title] || "Clone of #{title}"

  begin
    # Create the project first so we know that it is passing.
    # What most likely is wrong is the token and the export actaully takes majority of the time
    new_project = GoodData::Project.create(options.merge(:title => a_title, :client => client, :driver => content[:driver]))
    export_token = export_clone(options)
    new_project.import_clone(export_token)
  rescue
    new_project.delete if new_project
    raise
  end
end

#compute_metric(expression) ⇒ Object Also known as: compute_measure



982
983
984
# File 'lib/gooddata/models/project.rb', line 982

def compute_metric(expression)
  GoodData::Metric.xexecute(expression, client: client, project: self)
end

#compute_report(spec = {}) ⇒ Object



978
979
980
# File 'lib/gooddata/models/project.rb', line 978

def compute_report(spec = {})
  GoodData::ReportDefinition.execute(spec.merge(client: client, project: self))
end

#computed_attributes(id = :all) ⇒ Object



821
822
823
824
825
826
827
828
# File 'lib/gooddata/models/project.rb', line 821

def computed_attributes(id = :all)
  attrs = attributes(id)
  if attrs.is_a?(GoodData::Attribute)
    attrs.computed_attribute? ? attrs : nil
  else
    attrs.select(&:computed_attribute?)
  end
end

#create_custom_color_palette(colors) ⇒ Object



2249
2250
2251
# File 'lib/gooddata/models/project.rb', line 2249

def create_custom_color_palette(colors)
  GoodData::StyleSetting.create(colors, client: client, project: self)
end

#create_output_stage(ads, opts = {}) ⇒ Object



2237
2238
2239
# File 'lib/gooddata/models/project.rb', line 2237

def create_output_stage(ads, opts = {})
  add.create_output_stage(ads, opts)
end

#create_schedule(process, date, executable, options = {}) ⇒ Object



988
989
990
991
# File 'lib/gooddata/models/project.rb', line 988

def create_schedule(process, date, executable, options = {})
  s = GoodData::Schedule.create(process, date, executable, options.merge(client: client, project: self))
  s.save
end

#create_variable(data) ⇒ Object



993
994
995
# File 'lib/gooddata/models/project.rb', line 993

def create_variable(data)
  GoodData::Variable.create(data, client: client, project: self)
end

#current_color_paletteObject



2245
2246
2247
# File 'lib/gooddata/models/project.rb', line 2245

def current_color_palette
  GoodData::StyleSetting.current(client: client, project: self)
end

#dashboards(id = :all) ⇒ GoodData::Dashboard | Array<GoodData::Dashboard>

Helper for getting dashboards of a project

Parameters:

  • id (String | Number | Object) (defaults to: :all)

    Anything that you can pass to GoodData::Dashboard[id]

Returns:



1001
1002
1003
# File 'lib/gooddata/models/project.rb', line 1001

def dashboards(id = :all)
  GoodData::Dashboard[id, project: self, client: client]
end

#data_permissions(id = :all) ⇒ Object Also known as: user_filters



1013
1014
1015
# File 'lib/gooddata/models/project.rb', line 1013

def data_permissions(id = :all)
  GoodData::MandatoryUserFilter[id, client: client, project: self]
end

#dataset_mappingObject



2209
2210
2211
# File 'lib/gooddata/models/project.rb', line 2209

def dataset_mapping
  GoodData::Project.get_dataset_mapping(self)
end

#datasets(id = :all) ⇒ Array<GoodData::Dataset> | GoodData::Dataset

Gives you list of datasets. These are not blueprint datasets but model datasets coming from meta data server.

Parameters:

Returns:



900
901
902
# File 'lib/gooddata/models/project.rb', line 900

def datasets(id = :all)
  GoodData::Dataset[id, project: self, client: client]
end

#deleteObject

Deletes project



1019
1020
1021
1022
# File 'lib/gooddata/models/project.rb', line 1019

def delete
  fail "Project '#{title}' with id #{uri} is already deleted" if deleted?
  client.delete(uri)
end

#delete_all_data(options = {}) ⇒ Array

Helper for getting rid of all data in the project

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :force (Boolean)

    has to be added otherwise the operation is not performed

Returns:

  • (Array)

    Result of executing MAQLs



1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
# File 'lib/gooddata/models/project.rb', line 1035

def delete_all_data(options = {})
  return false unless options[:force]
  begin
    datasets.reject(&:date_dimension?).pmap(&:delete_data)
  rescue MaqlExecutionError => e
    # This is here so that we do not throw out exceptions on synchornizing date dimensions
    # Currently there is no reliable way how to tell it is a date dimension
    fail e unless GoodData::Helpers.interpolate_error_messages(e.data['wTaskStatus']['messages']) == ["Internal error [handle_exception, hide_internal]."]
  end
end

#delete_dashboardsObject

Deletes dashboards for project



1047
1048
1049
# File 'lib/gooddata/models/project.rb', line 1047

def delete_dashboards
  Dashboard.all.map { |data| Dashboard[data['link']] }.each(&:delete)
end

#deleted?Boolean

Returns true if project is in deleted state

Returns:

  • (Boolean)

    Returns true if object deleted. False otherwise.



1027
1028
1029
# File 'lib/gooddata/models/project.rb', line 1027

def deleted?
  state == :deleted
end

#deploy_process(path, options = {}) ⇒ Object



1051
1052
1053
# File 'lib/gooddata/models/project.rb', line 1051

def deploy_process(path, options = {})
  GoodData::Process.deploy(path, options.merge(client: client, project: self))
end

#dimensions(id = :all) ⇒ Object



904
905
906
# File 'lib/gooddata/models/project.rb', line 904

def dimensions(id = :all)
  GoodData::Dimension[id, client: client, project: self]
end

#disable_users(list, options = {}) ⇒ Object



1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
# File 'lib/gooddata/models/project.rb', line 1997

def disable_users(list, options = {})
  list = list.map(&:to_hash)
  url = "#{uri}/users"
  payloads = list.map do |u|
    uri, = resolve_roles(u, [], options)
    generate_user_payload(uri, 'DISABLED')
  end

  payloads.each_slice(100).mapcat do |payload|
    result = client.post(url, 'users' => payload)
    result['projectUsersUpdateResult'].mapcat { |k, v| v.map { |x| { type: k.to_sym, user: x } } }
  end
end

#download_file(file, where) ⇒ Object



1194
1195
1196
# File 'lib/gooddata/models/project.rb', line 1194

def download_file(file, where)
  GoodData.download_from_project_webdav(file, where, project: self)
end

#driverObject



1198
1199
1200
# File 'lib/gooddata/models/project.rb', line 1198

def driver
  content['driver']
end

#environmentObject



1202
1203
1204
# File 'lib/gooddata/models/project.rb', line 1202

def environment
  content['environment']
end

#execute_dml(dml, options = {}) ⇒ Hash

Executes DML expression. See (https://developer.gooddata.com/article/deleting-records-from-datasets) for some examples and explanations

Parameters:

  • dml (String)

    DML expression

Returns:

  • (Hash)

    Result of executing DML



1060
1061
1062
1063
1064
1065
1066
1067
1068
# File 'lib/gooddata/models/project.rb', line 1060

def execute_dml(dml, options = {})
  uri = "/gdc/md/#{pid}/dml/manage"
  result = client.post(uri, manage: { maql: dml })
  polling_uri = result['uri']

  client.poll_on_response(polling_uri, options) do |body|
    body && body['taskState'] && body['taskState']['status'] == 'WAIT'
  end
end

#execute_maql(maql, options = {}) ⇒ Hash

Executes MAQL expression and waits for it to be finished.

Parameters:

  • maql (String)

    MAQL expression

Returns:

  • (Hash)

    Result of executing MAQL



1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
# File 'lib/gooddata/models/project.rb', line 1074

def execute_maql(maql, options = {})
  ldm_links = client.get(md[GoodData::Model::LDM_CTG])
  ldm_uri = Links.new(ldm_links)[GoodData::Model::LDM_MANAGE_CTG]
  response = client.post(ldm_uri, manage: { maql: maql })
  polling_uri = response['entries'].first['link']

  result = client.poll_on_response(polling_uri, options) do |body|
    body && body['wTaskStatus'] && body['wTaskStatus']['status'] == 'RUNNING'
  end
  if result['wTaskStatus']['status'] == 'ERROR'
    fail MaqlExecutionError.new("Executionof MAQL '#{maql}' failed in project '#{pid}'", result)
  end
  result
end

#export_clone(options = {}) ⇒ String

Export a clone from a project to be later imported. If you do not want to do anything special and you do not need fine grained controle use clone method which does all the heavy lifting for you.

Parameters:

  • options (Hash) (defaults to: {})

    Export options

Options Hash (options):

  • :data (Boolean)

    Clone project with data

  • :users (Boolean)

    Clone project with users

  • :authorized_users (String)

    Comma separated logins of authorized users. Users that can use the export

  • :exclude_schedules (Boolean)

    Specifies whether to include scheduled notifications in the export

  • :cross_data_center_export (Boolean)

    Specifies whether export can be used in any data center

Returns:

  • (String)

    token of the export



919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
# File 'lib/gooddata/models/project.rb', line 919

def export_clone(options = {})
  with_data = options[:data].nil? ? true : options[:data]
  with_users = options[:users].nil? ? false : options[:users]

  export = {
    :exportProject => {
      :exportUsers => with_users ? 1 : 0,
      :exportData => with_data ? 1 : 0
    }
  }
  export[:exportProject][:authorizedUsers] = options[:authorized_users] if options[:authorized_users]
  if options[:exclude_schedules]
    exclude_notifications = options[:exclude_schedules] ? 1 : 0
    export[:exportProject][:excludeSchedules] = exclude_notifications
  end
  if options[:cross_data_center_export]
    cross_data_center = options[:cross_data_center_export] ? 1 : 0
    export[:exportProject][:crossDataCenterExport] = cross_data_center
  end

  result = client.post("/gdc/md/#{obj_id}/maintenance/export", export)
  status_url = result['exportArtifact']['status']['uri']
  polling_result = client.poll_on_response(status_url) do |body|
    body['taskState']['status'] == 'RUNNING'
  end

  ensure_clone_task_ok(polling_result, GoodData::ExportCloneError)
  result['exportArtifact']['token']
end

#fact_by_title(title) ⇒ Object



1097
1098
1099
# File 'lib/gooddata/models/project.rb', line 1097

def fact_by_title(title)
  GoodData::Fact.find_first_by_title(title, project: self, client: client)
end

#facts(id = :all) ⇒ GoodData::Fact | Array<GoodData::Fact>

Helper for getting facts of a project

Parameters:

  • Anything (String | Number | Object)

    that you can pass to GoodData::Fact[id]

Returns:



1093
1094
1095
# File 'lib/gooddata/models/project.rb', line 1093

def facts(id = :all)
  GoodData::Fact[id, project: self, client: client]
end

#facts_by_title(title) ⇒ Object



1101
1102
1103
# File 'lib/gooddata/models/project.rb', line 1101

def facts_by_title(title)
  GoodData::Fact.find_by_title(title, project: self, client: client)
end

#find_attribute_element_value(uri) ⇒ Object



1105
1106
1107
# File 'lib/gooddata/models/project.rb', line 1105

def find_attribute_element_value(uri)
  GoodData::Attribute.find_element_value(uri, client: client, project: self)
end

#find_by_tag(tags) ⇒ Object



1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
# File 'lib/gooddata/models/project.rb', line 1217

def find_by_tag(tags)
  tags = tags.split(',').map(&:strip) unless tags.is_a?(Array)

  objects = tags.map do |tag|
    url = "/gdc/md/#{pid}/tags/#{tag}"
    res = client.get(url)

    ((res || {})['entries'] || []).map do |entry|
      entry['link']
    end
  end

  objects.flatten!

  objects.uniq!

  objects
end

#folders(id = :all) ⇒ Object



949
950
951
# File 'lib/gooddata/models/project.rb', line 949

def folders(id = :all)
  GoodData::Folder[id, project: self, client: client]
end

#fuzzy_get_user(name, user_list = users) ⇒ GoodDta::Membership

Gets user by its email, full_name, login or uri.

Parameters:

  • name (String)

    Name to look for

  • user_list (Array<GoodData::User>) (defaults to: users)

    Optional cached list of users used for look-ups

Returns:

  • (GoodDta::Membership)

    User



1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
# File 'lib/gooddata/models/project.rb', line 1241

def fuzzy_get_user(name, user_list = users)
  return name if name.instance_of?(GoodData::Membership)
  return member(name) if name.instance_of?(GoodData::Profile)
  name = name.is_a?(Hash) ? name[:login] || name[:uri] : name
  return nil unless name
  name.downcase!
  user_list.select do |user|
    user.uri.downcase == name ||
      user..downcase == name ||
      user.email.downcase == name
  end
  nil
end

#get_role(role_name, role_list = roles) ⇒ GoodData::ProjectRole

Gets project role

Parameters:

  • role_title (String)

    Title of role to look for

Returns:



1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
# File 'lib/gooddata/models/project.rb', line 1154

def get_role(role_name, role_list = roles)
  return role_name if role_name.is_a? GoodData::ProjectRole

  role_name.downcase!
  role_list.each do |role|
    return role if role.uri == role_name ||
                   role.identifier.downcase == role_name ||
                   role.identifier.downcase.gsub(/role$/, '') == role_name ||
                   role.title.downcase == role_name ||
                   role.summary.downcase == role_name
  end
  nil
end

#get_role_by_identifier(role_name, role_list = roles) ⇒ GoodData::ProjectRole

Gets project role by its identifier

Parameters:

  • role_name (String)

    Title of role to look for

Returns:



1119
1120
1121
1122
1123
1124
1125
1126
# File 'lib/gooddata/models/project.rb', line 1119

def get_role_by_identifier(role_name, role_list = roles)
  role_name = role_name.downcase.gsub(/role$/, '')
  role_list.each do |role|
    tmp_role_name = role.identifier.downcase.gsub(/role$/, '')
    return role if tmp_role_name == role_name
  end
  nil
end

#get_role_by_summary(role_summary, role_list = roles) ⇒ GoodData::ProjectRole

Gets project role byt its summary

Parameters:

  • role_summary (String)

    Summary of role to look for

Returns:



1132
1133
1134
1135
1136
1137
# File 'lib/gooddata/models/project.rb', line 1132

def get_role_by_summary(role_summary, role_list = roles)
  role_list.each do |role|
    return role if role.summary.downcase == role_summary.downcase
  end
  nil
end

#get_role_by_title(role_title, role_list = roles) ⇒ GoodData::ProjectRole

Gets project role by its name

Parameters:

  • role_title (String)

    Title of role to look for

Returns:



1143
1144
1145
1146
1147
1148
# File 'lib/gooddata/models/project.rb', line 1143

def get_role_by_title(role_title, role_list = roles)
  role_list.each do |role|
    return role if role.title.downcase == role_title.downcase
  end
  nil
end

#get_user(slug, user_list = users) ⇒ GoodDta::Membership Also known as: member

Gets user by its login or uri in various shapes It does not find by other information because that is not unique. If you want to search by name or email please use fuzzy_get_user.

Parameters:

  • name (String)

    Name to look for

  • user_list (Array<GoodData::User>) (defaults to: users)

    Optional cached list of users used for look-ups

Returns:

  • (GoodDta::Membership)

    User



1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
# File 'lib/gooddata/models/project.rb', line 1175

def get_user(slug, user_list = users)
  search_crit = if slug.respond_to?(:login)
                  slug. || slug.uri
                elsif slug.is_a?(Hash)
                  slug[:login] || slug[:uri]
                else
                  slug
                end
  return nil unless search_crit
  user_list.find do |user|
    user.uri == search_crit.downcase ||
      user..downcase == search_crit.downcase
  end
end

#import_clone(export_token, options = {}) ⇒ Project

Imports a clone into current project. The project has to be freshly created.

Parameters:

  • export_token (String)

    Export token of the package to be imported

Returns:



962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
# File 'lib/gooddata/models/project.rb', line 962

def import_clone(export_token, options = {})
  import = {
    :importProject => {
      :token => export_token
    }
  }

  result = client.post("/gdc/md/#{obj_id}/maintenance/import", import)
  status_url = result['uri']
  polling_result = client.poll_on_response(status_url, options) do |body|
    body['taskState']['status'] == 'RUNNING'
  end
  ensure_clone_task_ok(polling_result, GoodData::ImportCloneError)
  self
end

#import_users(new_users, options = {}) ⇒ Object

Imports users



1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
# File 'lib/gooddata/models/project.rb', line 1839

def import_users(new_users, options = {})
  role_list = roles
  users_list = users

  GoodData.logger.warn("Importing users to project (#{pid})")
  new_users = new_users.map { |x| ((x.is_a?(Hash) && x[:user] && x[:user].to_hash.merge(role: x[:role])) || x.to_hash).tap { |u| u[:login].downcase! } }
  # First check that if groups are provided we have them set up
  user_groups_cache, change_groups = check_groups(new_users.map(&:to_hash).flat_map { |u| u[:user_group] || [] }.uniq, options[:user_groups_cache], options)

  unless change_groups.empty?
    new_users.each do |user|
      user[:user_group].map! { |e| change_groups[e].nil? ? e : change_groups[e] }
    end
  end

  whitelisted_new_users, whitelisted_users = whitelist_users(new_users.map(&:to_hash), users_list, options[:whitelists])

  # conform the role on list of new users so we can diff them with the users coming from the project
  diffable_new_with_default_role = whitelisted_new_users.map do |u|
    u[:role] = Array(u[:role] || u[:roles] || 'readOnlyUser')
    u
  end

  intermediate_new = diffable_new_with_default_role.map do |u|
    u[:role] = u[:role].map do |r|
      role = get_role(r, role_list)
      role ? role.uri : r
    end

    u[:role_title] = u[:role].map do |r|
      role = get_role(r, role_list)
      role ? role.title : r
    end

    if u[:role].all?(&:nil?)
      u[:type] = :error
      u[:reason] = 'Invalid role(s) specified'
    else
      u[:type] = :ok
    end

    u[:status] = 'ENABLED'
    u
  end

  intermediate_new_by_type = intermediate_new.group_by { |i| i[:type] }
  diffable_new = intermediate_new_by_type[:ok] || []

  # Diff users. Only login and role is important for the diff
  diff = GoodData::Helpers.diff(whitelisted_users, diffable_new, key: :login, fields: [:login, :role, :status])
  diff_results = diff.flat_map do |operation, users|
    if operation == :changed
      users.map { |u| u[:new_obj].merge(operation: operation) }
    else
      users.map { |u| u.merge(operation: operation) }
    end
  end
  diff_results = diff_results.map do |u|
    u[:login_uri] = USER_ACCOUNT_PATH + u[:login]
    u
  end
  return diff_results if options[:dry_run]

  # Create new users
  results = []
  GoodData.logger.warn("Creating #{diff[:added].count} users in project (#{pid})")
  to_create = diff[:added].map { |x| { user: x, role: x[:role] } }
  created_users_result = create_users(to_create, roles: role_list, project_users: whitelisted_users)
  @log_formatter.log_created_users(created_users_result, diff[:added])
  results.concat(created_users_result)
  send_mail_to_new_users(diff[:added], options[:email_options]) if options[:email_options] && !options[:email_options].empty? && !diff[:added].empty?

  # # Update existing users
  GoodData.logger.warn("Updating #{diff[:changed].count} users in project (#{pid})")
  to_update = diff[:changed].map { |x| { user: x[:new_obj], role: x[:new_obj][:role] || x[:new_obj][:roles] } }
  updated_users_result = set_users_roles(to_update, roles: role_list, project_users: whitelisted_users)
  @log_formatter.log_updated_users(updated_users_result, diff[:changed], role_list)
  results.concat(updated_users_result)

  unless options[:do_not_touch_users_that_are_not_mentioned]
    # Remove old users
    to_disable = diff[:removed].reject { |user| user[:status] == 'DISABLED' || user[:status] == :disabled }
    GoodData.logger.warn("Disabling #{to_disable.count} users from project (#{pid})")
    disabled_users_result = disable_users(to_disable, roles: role_list, project_users: whitelisted_users)
    @log_formatter.log_disabled_users(disabled_users_result)
    results.concat(disabled_users_result)

    # Remove old users completely
    if options[:remove_users_from_project]
      to_remove = (to_disable + users(disabled: true).to_a).map(&:to_hash).uniq do |user|
        user[:uri]
      end
      GoodData.logger.warn("Removing #{to_remove.count} users from project (#{pid})")
      removed_users_result = remove_users(to_remove)
      @log_formatter.log_removed_users(removed_users_result)
      results.concat(removed_users_result)
    end
  end

  # reassign to groups
  removal_user_group_members = []
  mappings = new_users.map(&:to_hash).flat_map do |user|
    removal_user_group_members << user[:login] if user[:user_group]&.empty?
    groups = user[:user_group] || []
    groups.map { |g| [user[:login], g] }
  end

  unless mappings.empty?
    users_lookup = 
    mappings.group_by { |_, g| g }.each do |g, mapping|
      remote_users = mapping.map { |user, _| user }.map { || users_lookup[] && users_lookup[].uri }.reject(&:nil?)
      GoodData.logger.info("Assigning users #{remote_users} to group #{g}")
      next if remote_users.empty?
      existing_group = user_groups(g)
      if existing_group.nil?
        GoodData.logger.warn("Group #{g} not found!!!")
      else
        existing_group.set_members(remote_users)
      end
    end
    mentioned_groups = mappings.map(&:last).uniq
    groups_to_cleanup = user_groups_cache.reject { |g| mentioned_groups.include?(g.name) }

    # clean all groups not mentioned with exception of whitelisted users
    groups_to_cleanup.each do |g|
      g.set_members(whitelist_users(g.members.map(&:to_hash), [], options[:whitelists], :include).first.map { |x| x[:uri] })
    end
  end

  remove_member_from_group(users_lookup, removal_user_group_members, user_groups_cache)
  GoodData::Helpers.join(results, diff_results, [:user], [:login_uri])
end

#infoObject



1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
# File 'lib/gooddata/models/project.rb', line 1539

def info
  results = blueprint.datasets.pmap do |ds|
    [ds, ds.count(self)]
  end
  GoodData.logger.info(title)
  GoodData.logger.info(GoodData::Helpers.underline(title))
  GoodData.logger.info("\nDatasets - #{results.count}\n")
  results.each do |x|
    dataset, count = x
    dataset.title.tap do |t|
      GoodData.logger.info(t)
      GoodData.logger.info(GoodData::Helpers.underline(t))
      GoodData.logger.info("Size - #{count} rows")
      GoodData.logger.info("#{dataset.attributes_and_anchors.count} attributes, #{dataset.facts.count} facts, #{dataset.references.count} references\n")
    end
  end
  nil
end

#invitationsArray<GoodData::Invitation>

Returns invitations to project

Returns:



1318
1319
1320
1321
1322
1323
# File 'lib/gooddata/models/project.rb', line 1318

def invitations
  invitations = client.get @json['project']['links']['invitations']
  invitations['invitations'].pmap do |invitation|
    client.create GoodData::Invitation, invitation
  end
end

#invite(email, role, msg = DEFAULT_INVITE_MESSAGE) ⇒ Object

Invites new user to project

TODO: Return invite object

Parameters:

  • email (String)

    User to be invited

  • role (String)

    Role URL or Role ID to be used

  • msg (String) (defaults to: DEFAULT_INVITE_MESSAGE)

    Optional invite message



1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
# File 'lib/gooddata/models/project.rb', line 1284

def invite(email, role, msg = DEFAULT_INVITE_MESSAGE)
  GoodData.logger.info("Inviting #{email}, role: #{role}")

  role_url = nil
  if role.index('/gdc/').nil?
    tmp = get_role(role)
    role_url = tmp.uri if tmp
  else
    role_url = role if role_url.nil?
  end

  data = {
    :invitations => [
      {
        :invitation => {
          :content => {
            :email => email,
            :role => role_url,
            :action => {
              :setMessage => msg
            }
          }
        }
      }
    ]
  }

  url = "/gdc/projects/#{pid}/invitations"
  client.post(url, data)
end

#labels(id = :all, opts = {}) ⇒ GoodData::Fact | Array<GoodData::Fact>

Helper for getting labels of a project

GoodData::Label[id] + it supports :all as welll

Parameters:

  • Anything (String | Number | Object)

    that you can pass to

Returns:



1337
1338
1339
1340
1341
1342
1343
# File 'lib/gooddata/models/project.rb', line 1337

def labels(id = :all, opts = {})
  if id == :all
    attributes.pmapcat(&:labels).uniq
  else
    GoodData::Label[id, opts.merge(project: self, client: client)]
  end
end

#ldm_layoutObject



2217
2218
2219
# File 'lib/gooddata/models/project.rb', line 2217

def ldm_layout
  GoodData::Project.get_ldm_layout(self)
end

Returns project related links

Returns:

  • (Hash)

    Project related links



1328
1329
1330
# File 'lib/gooddata/models/project.rb', line 1328

def links
  data['links']
end

#login_usersObject



1990
1991
1992
1993
1994
1995
# File 'lib/gooddata/models/project.rb', line 1990

def 
  users.reduce({}) do |a, e|
    a[e.] = e
    a
  end
end

#maql_diff(options = {}) ⇒ Hash

get maql diff from another project or blueprint to current project

Parameters:

  • options (Hash) (defaults to: {})

    options

Options Hash (options):

Returns:

  • (Hash)

    project model diff



2264
2265
2266
2267
2268
2269
2270
2271
# File 'lib/gooddata/models/project.rb', line 2264

def maql_diff(options = {})
  fail "No :project or :blueprint specified" unless options[:blueprint] || options[:project]
  bp = options[:blueprint] || options[:project].blueprint
  uri = "/gdc/projects/#{pid}/model/diff"
  params = Hash[(options[:params] || []).map { |i| [i, true] }]
  result = client.post(uri, bp.to_wire, params: params)
  client.poll_on_code(result['asyncTask']['link']['poll'])
end

#mdObject



1345
1346
1347
# File 'lib/gooddata/models/project.rb', line 1345

def md
  @md ||= client.create(Links, client.get(data['links']['metadata']))
end

#member?(profile, list = members) ⇒ Boolean

Checks if the profile is member of project

Parameters:

Returns:

  • (Boolean)

    true if is member else false



1391
1392
1393
# File 'lib/gooddata/models/project.rb', line 1391

def member?(profile, list = members)
  !member(profile, list).nil?
end

#members?(profiles, list = members) ⇒ Boolean

Returns:

  • (Boolean)


1395
1396
1397
# File 'lib/gooddata/models/project.rb', line 1395

def members?(profiles, list = members)
  profiles.map { |p| member?(p, list) }
end

#metadata(key = :all) ⇒ Hash

Get data from project specific metadata storage

Parameters:

  • :all (Symbol | String)

    or nothing for all keys or a string for value of specific key

Returns:

  • (Hash)

    key Hash of stored data



1353
1354
1355
# File 'lib/gooddata/models/project.rb', line 1353

def (key = :all)
  GoodData::ProjectMetadata[key, client: client, project: self]
end

#metric_by_title(title) ⇒ Object Also known as: measure_by_title



1374
1375
1376
# File 'lib/gooddata/models/project.rb', line 1374

def metric_by_title(title)
  GoodData::Metric.find_first_by_title(title, project: self, client: client)
end

#metrics(id = :all, opts = { :full => true }) ⇒ Array<GoodData::Metric> Also known as: measures

Helper for getting metrics of a project

Returns:



1368
1369
1370
# File 'lib/gooddata/models/project.rb', line 1368

def metrics(id = :all, opts = { :full => true })
  GoodData::Metric[id, opts.merge(project: self, client: client)]
end

#metrics_by_title(title) ⇒ Object Also known as: measures_by_title



1380
1381
1382
# File 'lib/gooddata/models/project.rb', line 1380

def metrics_by_title(title)
  GoodData::Metric.find_by_title(title, project: self, client: client)
end

#obj_idString Also known as: pid

Gets raw resource ID

Returns:

  • (String)

    Raw resource ID



1402
1403
1404
# File 'lib/gooddata/models/project.rb', line 1402

def obj_id
  uri.split('/').last
end

#objects(id, opts = {}) ⇒ Array<GoodData::MdObject>

Helper for getting objects of a project

Returns:



1411
1412
1413
# File 'lib/gooddata/models/project.rb', line 1411

def objects(id, opts = {})
  GoodData::MdObject[id, opts.merge(project: self, client: client)]
end

#objects_export(objs, options = {}) ⇒ String

Transfer objects from one project to another

Parameters:

  • objs (Array<GoodData::MdObject | String>, String, GoodData::MdObject)

    Any representation of the object or a list of those

  • options (Hash) (defaults to: {})

    The options to migration.

Options Hash (options):

  • :time_limit (Number)

    Time in seconds before the blocking call will fail. See GoodData::Rest::Client.poll_on_response for additional details

  • :sleep_interval (Number)

    Interval between polls on the status of the migration.

Returns:

  • (String)

    Returns token that you can use as input for object_import



1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
# File 'lib/gooddata/models/project.rb', line 1422

def objects_export(objs, options = {})
  fail 'Nothing to migrate. You have to pass list of objects, ids or uris that you would like to migrate' if objs.nil?
  objs = Array(objs).map { |o| o.respond_to?(:uri) ? o.uri : o }
  if objs.empty?
    GoodData.logger.warn 'Nothing to migrate.'
    return
  end

  export_payload = {
    :partialMDExport => {
      :uris => objs,
      :exportAttributeProperties => '1',
      :crossDataCenterExport => '1'
    }
  }
  result = client.post("#{md['maintenance']}/partialmdexport", export_payload)
  polling_url = result['partialMDArtifact']['status']['uri']
  token = result['partialMDArtifact']['token']

  polling_result = client.poll_on_response(polling_url, options) do |body|
    body['wTaskStatus'] && body['wTaskStatus']['status'] == 'RUNNING'
  end
  if polling_result['wTaskStatus'] && polling_result['wTaskStatus']['status'] == 'ERROR'
    messages = GoodData::Helpers.interpolate_error_messages(polling_result['wTaskStatus']['messages']).join(' ')
    fail ObjectsExportError, "Exporting objects failed with messages. #{messages}"
  end
  token
end

#objects_import(token, options = {}) ⇒ Boolean

Import objects from import token. If you do not need specifically this method what you are probably looking for is transfer_objects. This is a lower level method.

Parameters:

  • token (String)

    Migration token ID

  • options (Hash) (defaults to: {})

    The options to migration.

Options Hash (options):

  • :time_limit (Number)

    Time in seconds before the blocking call will fail. See GoodData::Rest::Client.poll_on_response for additional details

  • :sleep_interval (Number)

    Interval between polls on the status of the migration.

Returns:

  • (Boolean)

    Returns true if it succeeds or throws exceoption



1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
# File 'lib/gooddata/models/project.rb', line 1458

def objects_import(token, options = {})
  fail 'You need to provide a token for object import' if token.blank?

  import_payload = {
    :partialMDImport => {
      :token => token,
      :overwriteNewer => '1',
      :updateLDMObjects => '1',
      :importAttributeProperties => '1'
    }
  }

  result = client.post("#{md['maintenance']}/partialmdimport", import_payload)
  polling_url = result['uri']

  polling_result = client.poll_on_response(polling_url, options) do |body|
    body['wTaskStatus'] && body['wTaskStatus']['status'] == 'RUNNING'
  end

  if polling_result['wTaskStatus']['status'] == 'ERROR'
    messages = GoodData::Helpers.interpolate_error_messages(polling_result['wTaskStatus']['messages']).join(' ')
    fail ObjectsImportError, "Importing objects failed with messages. #{messages}"
  end
  true
end

#partial_md_export(objects, options = {}) ⇒ Boolean | Array<Hash> Also known as: transfer_objects

Transfer objects from one project to another

if you passed only one project. If you provided an array returns list of hashes signifying sucees or failure. Take note that in case of list of projects it does not throw exception.

Parameters:

  • objects (Array<GoodData::MdObject | String>, String, GoodData::MdObject)

    Any representation of the object or a list of those

  • options (Hash) (defaults to: {})

    The options to migration.

Options Hash (options):

  • :project (GoodData::Project | String | Array<String> | Array<GoodData::Project>)

    Project(s) to migrate to

  • :batch_size (Number)

    Number of projects that are migrated at the same time. Default is 10

Returns:

  • (Boolean | Array<Hash>)

    Return either true or throws exception



1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
# File 'lib/gooddata/models/project.rb', line 1495

def partial_md_export(objects, options = {})
  projects = options[:project]
  batch_size = options[:batch_size] || 10
  token = objects_export(objects)
  return if token.nil?

  if projects.is_a?(Array)
    projects.each_slice(batch_size).flat_map do |batch|
      batch.pmap do |proj|
        target_project = client.projects(proj)
        target_project.objects_import(token, options)
        {
          project: target_project,
          result: true
        }
      end
    end
  else
    target_project = client.projects(projects)
    target_project.objects_import(token, options)
    [{
      project: target_project,
      result: true
    }]
  end
end

#processes(id = :all) ⇒ GoodData::Report | Array<GoodData::Report>

Helper for getting processes of a project

Parameters:

  • Anything (String | Number | Object)

    that you can pass to GoodData::Report[id]

Returns:



1528
1529
1530
# File 'lib/gooddata/models/project.rb', line 1528

def processes(id = :all)
  GoodData::Process[id, project: self, client: client]
end

#project?Boolean

Checks if this object instance is project

Returns:

  • (Boolean)

    Return true for all instances



1535
1536
1537
# File 'lib/gooddata/models/project.rb', line 1535

def project?
  true
end

#project_webdav_pathString

Get WebDav directory for project data

Returns:

  • (String)


1111
1112
1113
# File 'lib/gooddata/models/project.rb', line 1111

def project_webdav_path
  client.project_webdav_path(:project => self)
end

#public?Boolean

Returns:

  • (Boolean)


1206
1207
1208
# File 'lib/gooddata/models/project.rb', line 1206

def public?
  content['isPublic']
end

#reload!Object

Forces project to reload



1559
1560
1561
1562
1563
1564
1565
# File 'lib/gooddata/models/project.rb', line 1559

def reload!
  if saved?
    response = client.get(uri)
    @json = response
  end
  self
end

#remove_member_from_group(users_lookup, removal_user_group_members, user_groups_cache) ⇒ Object



1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
# File 'lib/gooddata/models/project.rb', line 1972

def remove_member_from_group(users_lookup, removal_user_group_members, user_groups_cache)
  unless removal_user_group_members.empty?
    users_lookup ||= 
    current_user_groups = user_groups_cache || user_groups
    removal_user_group_members.uniq.each do ||
      user_uri = users_lookup[]&.uri

      # remove user from group if exists as group member
      current_user_groups.each do |user_group|
        if user_group.member?(user_uri)
          GoodData.logger.info("Removing #{user_uri} user from group #{user_group.name}")
          user_group.remove_members(user_uri)
        end
      end
    end
  end
end

#remove_users(list) ⇒ Object



2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
# File 'lib/gooddata/models/project.rb', line 2011

def remove_users(list)
  list = list.map(&:to_hash)

  list.pmapcat do |u|
    u_id = GoodData::Helpers.last_uri_part(u[:uri])
    url = "#{uri}/users/#{u_id}"
    begin
      client.delete(url)
      [{ type: :successful, operation: :user_deleted_from_project, user: u }]
    rescue => e
      [{ type: :failed, message: e.message, user: u }]
    end
  end
end

#replace_from_mapping(mapping, opts = {}) ⇒ Object

Method used for walking through objects in project and trying to replace all occurences of some object for another object. This is typically used as a means for exchanging Date dimensions.

Parameters:

  • mapping (Array<Array>)

    Mapping specifying what should be exchanged for what. As mapping should be used output of GoodData::Helpers.prepare_mapping.



1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
# File 'lib/gooddata/models/project.rb', line 1572

def replace_from_mapping(mapping, opts = {})
  default = {
    :purge => false,
    :dry_run => false
  }
  opts = default.merge(opts)
  dry_run = opts[:dry_run]

  if opts[:purge]
    GoodData.logger.info 'Purging old project definitions'
    reports.peach(&:purge_report_of_unused_definitions!)
  end

  fail ArgumentError, 'No mapping specified' if mapping.blank?
  rds = report_definitions

  {
    # data_permissions: data_permissions,
    variables: variables,
    dashboards: dashboards,
    metrics: metrics,
    report_definitions: rds
  }.each do |key, collection|
    GoodData.logger.info("Replacing #{key}")
    collection.peach do |item|
      new_item = item.replace(mapping)
      if new_item.json != item.json
        if dry_run
          GoodData.logger.info "Would save #{new_item.uri}. Running in dry run mode"
        else
          GoodData.logger.info "Saving #{new_item.uri}"
          new_item.save
        end
      else
        GoodData.logger.info "Ignore #{item.uri}"
      end
    end
  end

  GoodData.logger.info 'Replacing hidden metrics'
  local_metrics = mapping.map { |a, _| a }.pmapcat { |a| a.usedby('metric') }.select { |m| m['deprecated'] == '1' }.map { |m| m['link'] }.uniq
  GoodData.logger.info("Found #{local_metrics.count} metrics")
  local_metrics.pmap { |m| metrics(m) }.peach do |item|
    new_item = item.replace(mapping)
    if new_item.json != item.json
      if dry_run
        GoodData.logger.info "Would save #{new_item.uri}. Running in dry run mode"
      else
        GoodData.logger.info "Saving #{new_item.uri}"
        new_item.save
      end
    else
      GoodData.logger.info "Ignore #{item.uri}"
    end
  end

  GoodData.logger.info 'Replacing dashboard saved views'
  contexts = mapping.map { |a, _| a }.pmapcat { |a| a.usedby('executionContext') }.map { |a| GoodData::MdObject[a['link'], client: client, project: self] }
  GoodData.logger.info("Found #{contexts.count} dashboard saved views")
  contexts.peach do |item|
    new_item = GoodData::MdObject.replace_quoted(item, mapping)
    if new_item.json != item.json
      if dry_run
        GoodData.logger.info "Would save #{new_item.uri}. Running in dry run mode"
      else
        GoodData.logger.info "Saving #{new_item.uri}"
        new_item.save
      end
    else
      GoodData.logger.info "Ignore #{item.uri}"
    end
  end

  GoodData.logger.info 'Replacing variable values'
  variables.each do |var|
    var.values.peach do |val|
      val.replace(mapping).save unless dry_run
    end
  end

  {
    visualizations: MdObject.query('visualizationObject', MdObject, client: client, project: self),
    visualization_widgets: MdObject.query('visualizationWidget', MdObject, client: client, project: self),
    kpis: MdObject.query('kpi', MdObject, client: client, project: self)
  }.each do |key, collection|
    GoodData.logger.info "Replacing #{key}"
    collection.each do |item|
      new_item = MdObject.replace_quoted(item, mapping)
      if new_item.json != item.json
        if dry_run
          GoodData.logger.info "Would save #{new_item.uri}. Running in dry run mode"
        else
          GoodData.logger.info "Saving #{new_item.uri}"
          new_item.save
        end
      else
        GoodData.logger.info "Ignore #{item.uri}"
      end
    end
  end
  nil
end

#report_definitions(id = :all, options = {}) ⇒ GoodData::ReportDefinition | Array<GoodData::ReportDefinition>

Helper for getting report definitions of a project

Parameters:

  • Anything (String | Number | Object)

    that you can pass to GoodData::ReportDefinition[id]

Returns:



1687
1688
1689
# File 'lib/gooddata/models/project.rb', line 1687

def report_definitions(id = :all, options = {})
  GoodData::ReportDefinition[id, options.merge(project: self, client: client)]
end

#reports(id = :all) ⇒ GoodData::Report | Array<GoodData::Report>

Helper for getting reports of a project

Parameters:

  • Anything (String | Number | Object)

    that you can pass to GoodData::Report[id]

Returns:



1679
1680
1681
# File 'lib/gooddata/models/project.rb', line 1679

def reports(id = :all)
  GoodData::Report[id, project: self, client: client]
end

#reset_color_paletteObject



2253
2254
2255
# File 'lib/gooddata/models/project.rb', line 2253

def reset_color_palette
  GoodData::StyleSetting.reset(client: client, project: self)
end

#resolve_roles(login, desired_roles, options = {}) ⇒ Object



2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
# File 'lib/gooddata/models/project.rb', line 2159

def resolve_roles(, desired_roles, options = {})
  user = if .is_a?(String) && .include?('@')
           USER_ACCOUNT_PATH + 
         elsif .is_a?(String)
           
         elsif .is_a?(Hash) && [:login]
           USER_ACCOUNT_PATH + [:login]
         elsif .is_a?(Hash) && [:uri]
           [:uri]
         elsif .respond_to?(:uri) && .uri
           .uri
         elsif .respond_to?(:login) && .
           USER_ACCOUNT_PATH + .
         else
           fail "Unsupported user specification #{}"
         end

  role_list = options[:roles] || roles
  desired_roles = Array(desired_roles)
  roles = desired_roles.map do |role_name|
    role = get_role(role_name, role_list)
    fail ArgumentError, "Invalid role '#{role_name}' specified for user '#{GoodData::Helpers.last_uri_part(user)}'" if role.nil?
    role.uri
  end
  [user, roles]
end

#rolesArray<GoodData::ProjectRole>

Gets the list or project roles

Returns:



1694
1695
1696
1697
1698
1699
1700
# File 'lib/gooddata/models/project.rb', line 1694

def roles
  url = "/gdc/internal/projects/#{pid}/roles"
  res = client.get url
  res['internalProjectRoles']['roles'].map do |r|
    client.create(GoodData::ProjectRole, r, project: self)
  end
end

#saveObject

Saves project



1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
# File 'lib/gooddata/models/project.rb', line 1703

def save
  data_to_send = GoodData::Helpers.deep_dup(raw_data)
  data_to_send['project']['content'].delete('cluster')
  data_to_send['project']['content'].delete('isPublic')
  data_to_send['project']['content'].delete('state')
  response = if uri
               client.post(PROJECT_PATH % pid, data_to_send)
               client.get uri
             else
               result = client.post(PROJECTS_PATH, data_to_send)
               client.get result['uri']
             end
  @json = response
  self
end

#save_ldm_layout(ldm_layout_json) ⇒ Object



2221
2222
2223
# File 'lib/gooddata/models/project.rb', line 2221

def save_ldm_layout(ldm_layout_json)
  GoodData::Project.save_ldm_layout(ldm_layout_json, self)
end

#schedule_mail(options = GoodData::ScheduledMail::DEFAULT_OPTS) ⇒ Object

Schedules an email with dashboard or report content



1720
1721
1722
# File 'lib/gooddata/models/project.rb', line 1720

def schedule_mail(options = GoodData::ScheduledMail::DEFAULT_OPTS)
  GoodData::ScheduledMail.create(options.merge(client: client, project: self))
end

#scheduled_mails(options = { :full => false }) ⇒ Object



1724
1725
1726
# File 'lib/gooddata/models/project.rb', line 1724

def scheduled_mails(options = { :full => false })
  GoodData::ScheduledMail[:all, options.merge(project: self, client: client)]
end

#schedules(id = :all) ⇒ GoodData::Schedule | Array<GoodData::Schedule>

Returns schedule instance or list.

Parameters:

  • Anything (String | Number | Object)

    that you can pass to GoodData::Schedule[id]

Returns:



1730
1731
1732
# File 'lib/gooddata/models/project.rb', line 1730

def schedules(id = :all)
  GoodData::Schedule[id, project: self, client: client]
end

#set_metadata(key, val) ⇒ String

Set data for specific key in project specific metadata storage

Parameters:

  • key (String)

    key of the value to be stored

Returns:

  • (String)

    val value to be stored



1361
1362
1363
# File 'lib/gooddata/models/project.rb', line 1361

def (key, val)
  GoodData::ProjectMetadata.[]=(key, { client: client, project: self }, val)
end

#set_user_roles(login, desired_roles, options = {}) ⇒ Object Also known as: add_user

Update user

Parameters:

  • user

    User to be updated

  • desired_roles

    Roles to be assigned to user

  • role_list

    Optional cached list of roles used for lookups



2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
# File 'lib/gooddata/models/project.rb', line 2063

def set_user_roles(, desired_roles, options = {})
  user_uri, roles = resolve_roles(, desired_roles, options)
  url = "#{uri}/users"
  payload = generate_user_payload(user_uri, 'ENABLED', roles)
  res = client.post(url, payload)
  failure = GoodData::Helpers.get_path(res, %w(projectUsersUpdateResult failed))
  fail ArgumentError, "User #{user_uri} could not be added. #{failure.first['message']}" unless failure.blank?

  res
end

#set_users_roles(list, options = {}) ⇒ Object Also known as: add_users, create_users

Update list of users

Parameters:

  • list

    List of users to be updated

  • role_list

    Optional list of cached roles to prevent unnecessary server round-trips



2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
# File 'lib/gooddata/models/project.rb', line 2079

def set_users_roles(list, options = {})
  return [] if list.empty?
  role_list = options[:roles] || roles
  project_users = options[:project_users] || users

  intermediate_users = list.flat_map do |user_hash|
    user = user_hash[:user] || user_hash[:login]
    desired_roles = user_hash[:role] || user_hash[:roles] || 'readOnlyUser'
    begin
      , roles = resolve_roles(user, desired_roles, options.merge(project_users: project_users, roles: role_list))
      [{ :type => :successful, user: , roles: roles }]
    rescue => e
      [{ :type => :failed, :reason => e.message, user: user, roles: desired_roles }]
    end
  end

  # User can fail pre sending to API during resolving roles. We add only users that passed that step.
  users_by_type = intermediate_users.group_by { |u| u[:type] }
  users_to_add = users_by_type[:successful] || []

  payloads = users_to_add.map { |u| generate_user_payload(u[:user], 'ENABLED', u[:roles]) }
  results = payloads.each_slice(100).map do |payload|
    client.post("#{uri}/users", 'users' => payload)
  end
  # this ugly line turns the hash of errors into list of errors with types so we can process them easily
  typed_results = results.flat_map do |x|
    x['projectUsersUpdateResult'].flat_map do |k, v|
      v.map { |v2| v2.is_a?(String) ? { type: k.to_sym, user: v2 } : GoodData::Helpers.symbolize_keys(v2).merge(type: k.to_sym) }
    end
  end
  # we have to concat errors from role resolution and API result
  typed_results + (users_by_type[:failed] || [])
end

#slisGoodData::Metadata

Gets SLIs data

Returns:

  • (GoodData::Metadata)

    SLI Metadata



1737
1738
1739
1740
1741
1742
# File 'lib/gooddata/models/project.rb', line 1737

def slis
  link = "#{data['links']['metadata']}#{SLIS_PATH}"

  # FIXME: Review what to do with passed extra argument
  Metadata.new client.get(link)
end

#stateString

Gets project state

Returns:

  • (String)

    Project state



1747
1748
1749
# File 'lib/gooddata/models/project.rb', line 1747

def state
  data['content']['state'].downcase.to_sym if data['content'] && data['content']['state']
end

#title=(a_title) ⇒ String

Gets project title

Returns:

  • (String)

    Project title



1756
1757
1758
# File 'lib/gooddata/models/project.rb', line 1756

def title=(a_title)
  data['meta']['title'] = a_title if data['meta']
end

#tokenObject



1210
1211
1212
# File 'lib/gooddata/models/project.rb', line 1210

def token
  content['authorizationToken']
end

#transfer_color_palette(target) ⇒ Object



2241
2242
2243
# File 'lib/gooddata/models/project.rb', line 2241

def transfer_color_palette(target)
  GoodData::Project.transfer_color_palette(self, target)
end

#transfer_etl(target) ⇒ Object



2205
2206
2207
# File 'lib/gooddata/models/project.rb', line 2205

def transfer_etl(target)
  GoodData::Project.transfer_etl(client, self, target)
end

#transfer_processes(target) ⇒ Object



2225
2226
2227
# File 'lib/gooddata/models/project.rb', line 2225

def transfer_processes(target)
  GoodData::Project.transfer_processes(self, target)
end

#transfer_schedules(target) ⇒ Object



2229
2230
2231
# File 'lib/gooddata/models/project.rb', line 2229

def transfer_schedules(target)
  GoodData::Project.transfer_schedules(self, target)
end

#transfer_tagged_stuff(target, tag) ⇒ Object



2233
2234
2235
# File 'lib/gooddata/models/project.rb', line 2233

def transfer_tagged_stuff(target, tag)
  GoodData::Project.transfer_tagged_stuff(self, target, tag)
end

#update_dataset_mapping(model_mapping_json) ⇒ Object



2213
2214
2215
# File 'lib/gooddata/models/project.rb', line 2213

def update_dataset_mapping(model_mapping_json)
  GoodData::Project.update_dataset_mapping(model_mapping_json, self)
end

#update_from_blueprint(blueprint, options = {}) ⇒ Object

Applies blueprint to the project.

Examples:

Update with custom update preference.

GoodData.project.update_from_blueprint(
  blueprint,
  update_preference: {
    cascade_drops: false, preserve_data: false
  }
)

Parameters:

  • blueprint (Hash)

    Blueprint to apply to the project.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :update_preference (Hash) — default: cascade_drops: false, preserve_data: true

    Specifies how dropping LDM and data should be treated.



2155
2156
2157
# File 'lib/gooddata/models/project.rb', line 2155

def update_from_blueprint(blueprint, options = {})
  GoodData::Model::ProjectCreator.migrate(options.merge(spec: blueprint, token: options[:auth_token], client: client, project: self))
end

#upgrade_custom_v2(message, options = {}) ⇒ Object



2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
# File 'lib/gooddata/models/project.rb', line 2186

def upgrade_custom_v2(message, options = {})
  uri = "/gdc/md/#{pid}/datedimension/upgrade"
  poll_result = client&.post(uri, message)

  return poll_result['wTaskStatus']['status'] if poll_result['wTaskStatus'] && poll_result['wTaskStatus']['status']

  polling_uri = poll_result['asyncTask']['link']['poll']
  result = client&.poll_on_response(polling_uri, options) do |body|
    body && body['wTaskStatus'] && body['wTaskStatus']['status'] == 'RUNNING'
  end

  result['wTaskStatus']['status'] == 'OK' ? 'OK' : 'FAIL'
end

#upload(data, blueprint, dataset_name, options = {}) ⇒ Object

Uploads file to project

Parameters:

  • file

    File to be uploaded

  • schema

    Schema to be used



1764
1765
1766
# File 'lib/gooddata/models/project.rb', line 1764

def upload(data, blueprint, dataset_name, options = {})
  GoodData::Model.upload_data(data, blueprint, dataset_name, options.merge(client: client, project: self))
end

#upload_file(file, options = {}) ⇒ Object



1190
1191
1192
# File 'lib/gooddata/models/project.rb', line 1190

def upload_file(file, options = {})
  GoodData.upload_to_project_webdav(file, options.merge(project: self))
end

#upload_multiple(data, blueprint, options = {}) ⇒ Object



1768
1769
1770
# File 'lib/gooddata/models/project.rb', line 1768

def upload_multiple(data, blueprint, options = {})
  GoodData::Model.upload_multiple_data(data, blueprint, options.merge(client: client, project: self))
end

#uriObject



1772
1773
1774
# File 'lib/gooddata/models/project.rb', line 1772

def uri
  data['links']['self'] if data && data['links'] && data['links']['self']
end

#user_groups(id = :all, options = {}) ⇒ Object



953
954
955
# File 'lib/gooddata/models/project.rb', line 953

def user_groups(id = :all, options = {})
  GoodData::UserGroup[id, options.merge(project: self)]
end

#user_has_role?(user, role_name) ⇒ Boolean

Checks whether user has particular role in given proejct

Parameters:

Returns:

  • (Boolean)

    Tru if user has role_name



1260
1261
1262
1263
1264
1265
1266
# File 'lib/gooddata/models/project.rb', line 1260

def user_has_role?(user, role_name)
  member = get_user(user)
  role = get_role(role_name)
  member.roles.include?(role)
rescue
  false
end

#users(opts = {}) ⇒ Array<GoodData::User> Also known as: members

List of users in project

Returns:

  • (Array<GoodData::User>)

    List of users



1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
# File 'lib/gooddata/models/project.rb', line 1780

def users(opts = {})
  client = client(opts)
  all_users = []
  offset = opts[:offset] || 0
  limit = opts[:limit] || 1_000
  loop do
    tmp = client.get("/gdc/projects/#{pid}/users", params: { offset: offset, limit: limit })
    tmp['users'].each do |user_data|
      user = client.create(GoodData::Membership, user_data, project: self)

      if opts[:all]
        all_users << user
      elsif opts[:disabled]
        all_users << user if user&.disabled?
      else
        all_users << user if user&.enabled?
      end
    end
    break if tmp['users'].count < limit

    offset += limit
  end

  all_users
end

#validate(filters = %w(ldm pdm metric_filter invalid_objects), options = {}) ⇒ Object

Run validation on project Valid settins for validation are (default all): ldm - Checks the consistency of LDM objects. pdm Checks LDM to PDM mapping consistency, also checks PDM reference integrity. metric_filter - Checks metadata for inconsistent metric filters. invalid_objects - Checks metadata for invalid/corrupted objects. asyncTask response



2132
2133
2134
2135
2136
2137
2138
# File 'lib/gooddata/models/project.rb', line 2132

def validate(filters = %w(ldm pdm metric_filter invalid_objects), options = {})
  response = client.post "#{md['validate-project']}", 'validateProject' => filters
  polling_link = response['asyncTask']['link']['poll']
  client.poll_on_response(polling_link, options) do |body|
    body['wTaskStatus'] && body['wTaskStatus']['status'] == 'RUNNING'
  end
end

#variables(id = :all, options = { client: client, project: self }) ⇒ Object



2140
2141
2142
# File 'lib/gooddata/models/project.rb', line 2140

def variables(id = :all, options = { client: client, project: self })
  GoodData::Variable[id, options]
end

#whitelist_users(new_users, users_list, whitelist, mode = :exclude) ⇒ Object



1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
# File 'lib/gooddata/models/project.rb', line 1808

def whitelist_users(new_users, users_list, whitelist, mode = :exclude)
  return [new_users, users_list] unless whitelist

  new_whitelist_proc = proc do |user|
    whitelist.any? do |wl|
      if wl.is_a?(Regexp)
        user[:login] =~ wl
      else
        user[:login] && user[:login] == wl
      end
    end
  end

  whitelist_proc = proc do |user|
    whitelist.any? do |wl|
      if wl.is_a?(Regexp)
        user. =~ wl
      else
        user. && user. == wl
      end
    end
  end

  if mode == :include
    [new_users.select(&new_whitelist_proc), users_list.select(&whitelist_proc)]
  elsif mode == :exclude
    [new_users.reject(&new_whitelist_proc), users_list.reject(&whitelist_proc)]
  end
end