Class: HammerCLIImport::ImportCommand::RepositoryImportCommand
- Inherits:
-
BaseCommand
- Object
- HammerCLI::Apipie::Command
- BaseCommand
- HammerCLIImport::ImportCommand::RepositoryImportCommand
- Extended by:
- ImportTools::Repository::Extend
- Includes:
- ImportTools::Repository::Include
- Defined in:
- lib/hammer_cli_import/repository.rb
Instance Attribute Summary
Attributes included from PersistentMap::Extend
#map_description, #map_target_entity, #maps
Instance Method Summary collapse
- #delete_single_row(data) ⇒ Object
- #import_single_row(data) ⇒ Object
- #mk_product_hash(data, product_name) ⇒ Object
- #mk_repo_hash(data, product_id) ⇒ Object
Methods included from ImportTools::Repository::Extend
Methods included from ImportTools::Repository::Include
#repo_synced?, #sync_repo, #sync_repo2, #with_synced_repo
Methods inherited from BaseCommand
#_compare_hash, #_create_entity, #api_call, api_call, api_init, #create_entity, csv_columns, #cvs_iterate, #data_dir, #delete, #delete_entity, #delete_entity_by_import_id, #execute, #find_uniq, #found_errors, #get_cache, #get_original_id, #get_translated_id, #import, #initialize, #last_in_cache?, #list_server_entities, #load_cache, #lookup_entity, #lookup_entity_in_array, #lookup_entity_in_cache, #map_entity, #mapped_api_call, #post_delete, #post_import, #print_summary, #process_error, #recognizable_error, #report_summary, #split_multival, #to_singular, #unmap_entity, #update_entity, #wait_for_task, #was_translated
Methods included from PersistentMap::Extend
#persistent_map, #persistent_maps
Methods included from ImportTools::ImportLogging::Extend
Methods included from AsyncTasksReactor::Extend
#add_async_tasks_reactor_options
Methods included from AsyncTasksReactor::Include
#atr_exit, #atr_init, #postpone_till, #wait_for
Methods included from ImportTools::Exceptional::Include
#handle_missing_and_supress, #silently
Methods included from ImportTools::Task::Include
Methods included from ImportTools::ImportLogging::Include
#debug, #error, #fatal, #info, #log, #logtrace, #progress, #setup_logging, #warn
Methods included from PersistentMap::Include
#load_persistent_maps, #map_target_entity, #maps, #prune_persistent_maps, #save_persistent_maps
Constructor Details
This class inherits a constructor from HammerCLIImport::BaseCommand
Instance Method Details
#delete_single_row(data) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/hammer_cli_import/repository.rb', line 72 def delete_single_row(data) # check just becasue we're calling get_translated_id unless @pm[:repositories][data['id'].to_i] info to_singular(:repositories).capitalize + ' with id ' + data['id'] + " wasn't imported. Skipping deletion." return end # find out product id repo_id = get_translated_id(:repositories, data['id'].to_i) product_id = lookup_entity(:repositories, repo_id)['product']['id'] # delete repo delete_entity(:repositories, data['id'].to_i) # delete its product, if it's not associated with any other repositories product = lookup_entity(:products, product_id, true) delete_entity_by_import_id(:products, product_id) if product['repository_count'] == 0 end |
#import_single_row(data) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/hammer_cli_import/repository.rb', line 55 def import_single_row(data) begin product_name = URI.parse(data['source_url']).host.split('.').last(2).join('.').upcase rescue error 'Skipping ' + data['repo_label'] + ' ' + to_singular(:repositories) + ' import, invalid source_url.' report_summary :skipped, :repositories return end product_hash = mk_product_hash(data, product_name) composite_id = [data['org_id'].to_i, product_name] product_id = create_entity(:products, product_hash, composite_id)['id'] repo_hash = mk_repo_hash data, product_id repo = create_entity(:repositories, repo_hash, data['id'].to_i) with_synced_repo(repo) end |
#mk_product_hash(data, product_name) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/hammer_cli_import/repository.rb', line 39 def mk_product_hash(data, product_name) { :name => product_name, :organization_id => get_translated_id(:organizations, data['org_id'].to_i) } end |
#mk_repo_hash(data, product_id) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/hammer_cli_import/repository.rb', line 46 def mk_repo_hash(data, product_id) { :name => data['repo_label'], :product_id => product_id, :url => data['source_url'], :content_type => data['repo_type'] } end |