Module: Glue::Candlepin::Product::InstanceMethods

Defined in:
app/models/katello/glue/candlepin/product.rb

Instance Method Summary collapse

Instance Method Details

#_attr(key) ⇒ Object



94
95
96
97
98
99
100
101
102
103
# File 'app/models/katello/glue/candlepin/product.rb', line 94

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



124
125
126
127
# File 'app/models/katello/glue/candlepin/product.rb', line 124

def add_content(content)
  Resources::Candlepin::Product.add_content self.cp_id, content.content.id, true
  self.productContent << content
end

#archObject



84
85
86
87
88
89
90
91
92
# File 'app/models/katello/glue/candlepin/product.rb', line 84

def arch
  attrs.each do |attr|
    if attr[:name] == 'arch'
      return "noarch" if attr[:value] == 'ALL'
      return attr[:value]
    end
  end
  default_arch
end

#build_product_content(attrs) ⇒ Object



76
77
78
# File 'app/models/katello/glue/candlepin/product.rb', line 76

def build_product_content(attrs)
  @productContent = attrs.collect { |pc| Katello::Candlepin::ProductContent.new pc }
end

#convert_from_cp_fields(cp_json) ⇒ Object



109
110
111
112
113
114
115
# File 'app/models/katello/glue/candlepin/product.rb', line 109

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[:productContent] = ar_safe_json[:productContent].collect { |pc| ::Katello::Candlepin::ProductContent.new(pc, self.id) }
  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_archObject



105
106
107
# File 'app/models/katello/glue/candlepin/product.rb', line 105

def default_arch
  "noarch"
end

#displayable_product_contentsObject



68
69
70
# File 'app/models/katello/glue/candlepin/product.rb', line 68

def displayable_product_contents
  self.productContent.select(&:displayable?)
end

#import_subscription(subscription_id) ⇒ Object



141
142
143
144
145
146
147
148
149
# File 'app/models/katello/glue/candlepin/product.rb', line 141

def import_subscription(subscription_id)
  sub = ::Katello::Subscription.where(:cp_id => subscription_id).first_or_create
  sub.import_data
  pools = ::Katello::Resources::Candlepin::Product.pools(self.organization.label, self.cp_id)
  pools.each do |pool_json|
    pool = ::Katello::Pool.where(:cp_id => pool_json['id']).first_or_create
    pool.import_data
  end
end

#initialize(attribs = nil, options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/katello/glue/candlepin/product.rb', line 49

def initialize(attribs = nil, options = {})
  unless attribs.nil?
    attributes_key = attribs.key?(:attributes) ? :attributes : 'attributes'
    if attribs.key?(attributes_key)
      attribs[:attrs] = attribs[attributes_key]
      attribs.delete(attributes_key)
    end

    @productContent = [] unless attribs.key?(:productContent)

    # ugh. hack-ish. otherwise we have to modify code every time things change on cp side
    attribs = attribs.reject do |k, _v|
      !self.class.column_defaults.keys.member?(k.to_s) && (!respond_to?(:"#{k.to_s}=") rescue true)
    end
  end

  super
end

#orphaned?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/models/katello/glue/candlepin/product.rb', line 72

def orphaned?
  self.provider.redhat_provider? && self.certificate.nil?
end

#product_content_by_id(content_id) ⇒ Object



133
134
135
# File 'app/models/katello/glue/candlepin/product.rb', line 133

def product_content_by_id(content_id)
  self.productContent.find { |pc| pc.content.id == content_id }
end

#product_content_by_name(content_name) ⇒ Object



137
138
139
# File 'app/models/katello/glue/candlepin/product.rb', line 137

def product_content_by_name(content_name)
  self.productContent.find { |pc| pc.content.name == content_name }
end

#remove_content_by_id(content_id) ⇒ Object



129
130
131
# File 'app/models/katello/glue/candlepin/product.rb', line 129

def remove_content_by_id(content_id)
  Resources::Candlepin::Product.remove_content cp_id, content_id
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.



119
120
121
122
# File 'app/models/katello/glue/candlepin/product.rb', line 119

def remove_hibernate_fields(elements)
  return nil unless elements
  elements.collect { |e| e.except(:id, :created, :updated) }
end

#support_levelObject



80
81
82
# File 'app/models/katello/glue/candlepin/product.rb', line 80

def support_level
  return _attr(:support_level)
end