Module: Katello::Glue::Candlepin::Product
- Included in:
- Product
- Defined in:
- app/models/katello/glue/candlepin/product.rb
Defined Under Namespace
Modules: InstanceMethods
Constant Summary collapse
- PRODUCT_ATTRS =
%w(name attributes.name attributes.value).freeze
Class Method Summary collapse
- .custom_product_id?(id) ⇒ Boolean
- .engineering_product_id?(id) ⇒ Boolean
- .import_redhat_product_from_cp(attrs, organization) ⇒ Object
- .included(base) ⇒ Object
Class Method Details
.custom_product_id?(id) ⇒ Boolean
53 54 55 56 57 |
# File 'app/models/katello/glue/candlepin/product.rb', line 53 def self.custom_product_id?(id) # Engineering products with 12 digits are custom products (see Katello::Product#unused_product_id) # however, previously generated ids are random and can be shorter than 12 digits id =~ /^\d{8,12}$/ end |
.engineering_product_id?(id) ⇒ Boolean
31 32 33 |
# File 'app/models/katello/glue/candlepin/product.rb', line 31 def self.engineering_product_id?(id) id.match(/^\d+$/) #engineering products are numeric end |
.import_redhat_product_from_cp(attrs, organization) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/katello/glue/candlepin/product.rb', line 35 def self.import_redhat_product_from_cp(attrs, organization) import_logger = attrs[:import_logger] product_attrs = {'name' => attrs['name'], 'cp_id' => attrs['id'], 'label' => Util::Model.labelize(attrs['name']), 'multiplier' => attrs['multiplier'], 'organization_id' => organization.id, 'provider_id' => organization.redhat_provider.id} Product.create!(product_attrs) rescue => e [Rails.logger, import_logger].each do |logger| logger&.error "Failed to create product #{attrs['name']}: #{e}" end raise e end |
.included(base) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/katello/glue/candlepin/product.rb', line 5 def self.included(base) base.send :include, LazyAccessor base.send :include, InstanceMethods base.class_eval do lazy_accessor :multiplier, :href, :attrs, :initializer => (lambda do |_s| convert_from_cp_fields( Resources::Candlepin::Product.get(self.organization.label, cp_id, PRODUCT_ATTRS)[0] ) end) lazy_accessor :product_certificate, :initializer => lambda { |_s| Resources::Candlepin::Product.product_certificate(cp_id, self.organization.label) }, :unless => lambda { |_s| cp_id.nil? } # Entitlement Certificate for this product lazy_accessor :certificate, :initializer => lambda { |_s| product_certificate['cert'] if product_certificate } # Entitlement Key for this product lazy_accessor :key, :initializer => lambda { |_s| product_certificate['key'] if product_certificate } # we must store custom logger object during product importing so we can log status # from various places like callbacks attr_accessor :import_logger end end |