Class: GoodData::LCM2::AssociateClients
- Inherits:
-
BaseAction
- Object
- BaseAction
- GoodData::LCM2::AssociateClients
- Defined in:
- lib/gooddata/lcm/actions/associate_clients.rb
Constant Summary collapse
- DESCRIPTION =
'Associate LCM Clients'
- PARAMS =
define_params(self) do description 'Client Used for Connecting to GD' param :gdc_gd_client, instance_of(Type::GdClientType), required: true description 'Organization Name' param :organization, instance_of(Type::StringType), required: false description 'Domain' param :domain, instance_of(Type::StringType), required: false description 'Delete Extra Clients' param :delete_extra, instance_of(Type::BooleanType), required: false, default: false, deprecated: true, replacement: :delete_mode description 'Physically Delete Client Projects' param :delete_projects, instance_of(Type::BooleanType), required: false, default: false, deprecated: true, replacement: :delete_mode description 'Physically Delete Client Projects' param :delete_mode, instance_of(Type::StringType), required: false, default: 'none' description 'Clients' param :clients, array_of(instance_of(Type::HashType)), required: true, generated: true description 'Segments to provision' param :segments_filter, array_of(instance_of(Type::StringType)), required: false description 'DataProduct' param :data_product, instance_of(Type::GDDataProductType), required: false end
- RESULT_HEADER =
[ :id, :status, :project, :client, :type ]
- DELETE_MODES =
%w( none delete_projects delete_extra )
Constants inherited from BaseAction
BaseAction::FAILED_CLIENTS, BaseAction::FAILED_PROJECTS, BaseAction::FAILED_SEGMENTS, BaseAction::SYNC_FAILED_LIST
Constants included from Dsl::Dsl
Dsl::Dsl::DEFAULT_OPTS, Dsl::Dsl::TYPES
Class Method Summary collapse
Methods inherited from BaseAction
add_failed_client, add_failed_project, add_failed_segment, add_new_clients_to_project_client_mapping, check_params, collect_synced_status, continue_on_error, print_result, process_failed_project, process_failed_projects, sync_failed_client, sync_failed_project, sync_failed_segment, without_check
Methods included from Dsl::Dsl
#define_params, #define_type, #process
Class Method Details
.call(params) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/gooddata/lcm/actions/associate_clients.rb', line 57 def call(params) unless DELETE_MODES.include?(params.delete_mode) || params.delete_mode.nil? fail "The parameter \"delete_mode\" has to have one of the values #{DELETE_MODES.map(&:to_s).join(', ')} or has to be empty." end case params.delete_mode when 'delete_projects' delete_projects = true delete_extra = true when 'delete_extra' delete_projects = false delete_extra = true else # Usage of the depracated params delete_projects = GoodData::Helpers.to_boolean(params.delete_projects) delete_extra = GoodData::Helpers.to_boolean(params.delete_extra) end if delete_projects && !delete_extra GoodData.logger.warn("Parameter `delete_projects` is set to true and parameter `delete_extra` is set to false (which is default) this action will not delete anything!") end client = params.gdc_gd_client domain_name = params.organization || params.domain fail "Either organisation or domain has to be specified in params" unless domain_name domain = client.domain(domain_name) || fail("Invalid domain name specified - #{domain_name}") data_product = params.data_product segments = {} params.clients.group_by { |data| data[:segment] }.each do |segment_name, clients| segment = domain.segments(segment_name, data_product) segments[segment_name] = segment (clients.map(&:id) - segment.clients.map(&:id)).each do |c| segment.create_client(id: c) end end params.clients.map! do |data| data[:data_product_id] = segments[data[:segment]].data_product.data_product_id data end domain.update_clients_settings(params.clients) = { delete_projects: delete_projects } .merge!(delete_extra_option(params, delete_extra)) if delete_extra results = domain.update_clients(params.clients, ) # Update status to CREATED if the client has no project results&.each do |r| r[:status] = 'CREATED' if r[:originalProject].nil? r[:project] = r[:originalProject] end results end |