Module: Katello::Glue::Candlepin::Product::InstanceMethods
- Defined in:
- app/models/katello/glue/candlepin/product.rb
Instance Method Summary collapse
- #_attr(key) ⇒ Object
- #add_content(content) ⇒ Object
- #arch ⇒ Object
- #convert_from_cp_fields(cp_json) ⇒ Object
- #default_arch ⇒ Object
- #import_custom_subscription ⇒ Object
-
#remove_hibernate_fields(elements) ⇒ Object
Candlepin sends back its internal hibernate fields in the json.
- #support_level ⇒ Object
Instance Method Details
#_attr(key) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'app/models/katello/glue/candlepin/product.rb', line 74 def _attr(key) puts "Looking for: #{key}" attrs.each do |attr| puts "attr: name: #{attr[:name]} value: #{attr[:value]}" if attr[:name] == key.to_s return attr[:value] end end nil end |
#add_content(content) ⇒ Object
103 104 105 106 |
# File 'app/models/katello/glue/candlepin/product.rb', line 103 def add_content(content) Resources::Candlepin::Product.add_content(self.organization.label, self.cp_id, content.content.id, true) self.productContent << content end |
#arch ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'app/models/katello/glue/candlepin/product.rb', line 64 def arch attrs.each do |attr| if attr[:name] == 'arch' return "noarch" if attr[:value] == 'ALL' return attr[:value] end end default_arch end |
#convert_from_cp_fields(cp_json) ⇒ Object
89 90 91 92 93 94 |
# File 'app/models/katello/glue/candlepin/product.rb', line 89 def convert_from_cp_fields(cp_json) ar_safe_json = cp_json.key?(:attributes) ? cp_json.merge(:attrs => cp_json.delete(:attributes)) : cp_json ar_safe_json[:attrs] = remove_hibernate_fields(cp_json[:attrs]) if ar_safe_json.key?(:attrs) ar_safe_json[:attrs] ||= [] ar_safe_json.except('id') end |
#default_arch ⇒ Object
85 86 87 |
# File 'app/models/katello/glue/candlepin/product.rb', line 85 def default_arch "noarch" end |
#import_custom_subscription ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/katello/glue/candlepin/product.rb', line 108 def import_custom_subscription fail _("Cannot import a custom subscription from a redhat product.") if self.redhat? User.as_anonymous_admin do sub = nil ::Katello::Util::Support.active_record_retry do sub = ::Katello::Subscription.where(:cp_id => self.cp_id, :organization_id => self.organization.id).first_or_create end unless sub.persisted? = _("Subscription was not persisted - %{error_message}") % {:error_message => sub.errors..join("; ")} fail HttpErrors::UnprocessableEntity, end sub.import_data pools = ::Katello::Resources::Candlepin::Product.pools(self.organization.label, self.cp_id) pools.each { |pool_json| ::Katello::Pool.import_pool(pool_json['id']) } end end |
#remove_hibernate_fields(elements) ⇒ Object
Candlepin sends back its internal hibernate fields in the json. However it does not accept them in return when updating (PUT) objects.
98 99 100 101 |
# File 'app/models/katello/glue/candlepin/product.rb', line 98 def remove_hibernate_fields(elements) return nil unless elements elements.collect { |e| e.except(:id, :created, :updated) } end |
#support_level ⇒ Object
60 61 62 |
# File 'app/models/katello/glue/candlepin/product.rb', line 60 def support_level return _attr(:support_level) end |