Class: BulkImports::Entity

Inherits:
ApplicationRecord show all
Includes:
AfterCommitQueue
Defined in:
app/models/bulk_imports/entity.rb

Overview

The BulkImport::Entity represents a Group or Project to be imported during the bulk import process. An entity is nested under the parent group when it is not a top level group.

A full bulk import entity structure might look like this, where the links are parents:

      **Before Import**              **After Import**

         GroupEntity                      Group
          |      |                        |   |
 GroupEntity   ProjectEntity          Group   Project
      |                                 |
ProjectEntity                        Project

The tree structure of the entities results in the same structure for imported Groups and Projects.

Constant Summary collapse

FailedError =
Class.new(StandardError)

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, nullable_column?, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.all_human_statusesObject



113
114
115
# File 'app/models/bulk_imports/entity.rb', line 113

def self.all_human_statuses
  state_machine.states.map(&:human_name)
end

Instance Method Details

#base_resource_pathObject



154
155
156
157
158
159
160
# File 'app/models/bulk_imports/entity.rb', line 154

def base_resource_path
  if source_xid.present?
    base_xid_resource_url_path
  else
    base_resource_url_path
  end
end

#base_resource_url_pathObject



146
147
148
# File 'app/models/bulk_imports/entity.rb', line 146

def base_resource_url_path
  "/#{pluralized_name}/#{encoded_source_full_path}"
end

#base_xid_resource_url_pathObject



150
151
152
# File 'app/models/bulk_imports/entity.rb', line 150

def base_xid_resource_url_path
  "/#{pluralized_name}/#{source_xid}"
end

#checksumsObject



225
226
227
228
229
230
231
232
233
# File 'app/models/bulk_imports/entity.rb', line 225

def checksums
  trackers.each_with_object({}) do |tracker, checksums|
    next unless tracker.file_extraction_pipeline?
    next if tracker.skipped?
    next if tracker.checksums_empty?

    checksums.merge!(tracker.checksums)
  end
end

#default_visibility_levelObject



207
208
209
210
211
# File 'app/models/bulk_imports/entity.rb', line 207

def default_visibility_level
  return default_group_visibility if group?

  default_project_visibility
end

#encoded_source_full_pathObject



117
118
119
# File 'app/models/bulk_imports/entity.rb', line 117

def encoded_source_full_path
  ERB::Util.url_encode(source_full_path)
end

#entity_typeObject



134
135
136
# File 'app/models/bulk_imports/entity.rb', line 134

def entity_type
  source_type.gsub('_entity', '')
end

#export_relations_url_pathObject



166
167
168
169
170
171
172
# File 'app/models/bulk_imports/entity.rb', line 166

def export_relations_url_path
  if bulk_import.supports_batched_export?
    Gitlab::Utils.add_url_parameters(export_relations_url_path_base, batched: true)
  else
    export_relations_url_path_base
  end
end

#export_relations_url_path_baseObject



162
163
164
# File 'app/models/bulk_imports/entity.rb', line 162

def export_relations_url_path_base
  File.join(base_resource_path, 'export_relations')
end

#full_pathObject



199
200
201
# File 'app/models/bulk_imports/entity.rb', line 199

def full_path
  project? ? project&.full_path : group&.full_path
end

#full_path_with_fallbackObject



203
204
205
# File 'app/models/bulk_imports/entity.rb', line 203

def full_path_with_fallback
  full_path || Gitlab::Utils.append_path(destination_namespace, destination_slug)
end

#group?Boolean

Returns:

  • (Boolean)


191
192
193
# File 'app/models/bulk_imports/entity.rb', line 191

def group?
  source_type == 'group_entity'
end

#pipeline_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


130
131
132
# File 'app/models/bulk_imports/entity.rb', line 130

def pipeline_exists?(name)
  pipelines.any? { _1[:pipeline].to_s == name.to_s }
end

#pipelinesObject



121
122
123
124
125
126
127
128
# File 'app/models/bulk_imports/entity.rb', line 121

def pipelines
  @pipelines ||= case source_type
                 when 'group_entity'
                   BulkImports::Groups::Stage.new(self).pipelines
                 when 'project_entity'
                   BulkImports::Projects::Stage.new(self).pipelines
                 end
end

#pluralized_nameObject



138
139
140
# File 'app/models/bulk_imports/entity.rb', line 138

def pluralized_name
  entity_type.pluralize
end

#portable_classObject



142
143
144
# File 'app/models/bulk_imports/entity.rb', line 142

def portable_class
  entity_type.classify.constantize
end

#project?Boolean

Returns:

  • (Boolean)


187
188
189
# File 'app/models/bulk_imports/entity.rb', line 187

def project?
  source_type == 'project_entity'
end

#propagate_cancelObject



235
236
237
# File 'app/models/bulk_imports/entity.rb', line 235

def propagate_cancel
  trackers.each(&:cancel)
end

#relation_download_url_path(relation, batch_number = nil) ⇒ Object



174
175
176
177
178
179
180
181
# File 'app/models/bulk_imports/entity.rb', line 174

def relation_download_url_path(relation, batch_number = nil)
  url = File.join(export_relations_url_path_base, 'download')
  params = { relation: relation }

  params.merge!(batched: true, batch_number: batch_number) if batch_number && bulk_import.supports_batched_export?

  Gitlab::Utils.add_url_parameters(url, params)
end

#source_versionObject



221
222
223
# File 'app/models/bulk_imports/entity.rb', line 221

def source_version
  @source_version ||= bulk_import.source_version_info
end

#update_has_failuresObject



213
214
215
216
217
218
219
# File 'app/models/bulk_imports/entity.rb', line 213

def update_has_failures
  return if has_failures
  return unless failures.any?

  update!(has_failures: true)
  bulk_import.update!(has_failures: true)
end

#update_serviceObject



195
196
197
# File 'app/models/bulk_imports/entity.rb', line 195

def update_service
  "::#{pluralized_name.capitalize}::UpdateService".constantize
end

#wikis_url_pathObject



183
184
185
# File 'app/models/bulk_imports/entity.rb', line 183

def wikis_url_path
  "#{base_resource_path}/wikis"
end