Module: Glue::Candlepin::Subscription::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#backend_dataObject



19
20
21
# File 'app/models/katello/glue/candlepin/subscription.rb', line 19

def backend_data
  self.class.candlepin_data(self.cp_id)
end

#create_product_associationsObject



45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/katello/glue/candlepin/subscription.rb', line 45

def create_product_associations
  products = self.query_products
  cp_product_ids = products.map { |product| product["id"] }
  cp_product_ids << self.product_id if self.product_id
  cp_product_ids.each do |cp_id|
    product = ::Katello::Product.where(:cp_id => cp_id, :organization_id => self.organization_id)
    if product.any?
      ::Katello::SubscriptionProduct.where(:subscription_id => self.id, :product_id => product.first.id).first_or_create
    end
  end
end

#import_dataObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/katello/glue/candlepin/subscription.rb', line 27

def import_data
  subscription_attributes = {}
  subscription_json = self.backend_data

  subscription_json["product"]["attributes"].map { |attr| subscription_attributes[attr["name"].to_sym] = attr["value"] }

  subscription_attributes[:name] = subscription_json["product"]["name"]
  subscription_attributes[:product_id] = subscription_json["product"]["id"]
  subscription_attributes[:instance_multiplier] = subscription_json["product"]["multiplier"]
  subscription_attributes[:stacking_id] = subscription_json["stackId"]
  organization = Organization.find_by(:label => subscription_json["owner"]["key"]) if subscription_json["owner"]
  subscription_attributes[:organization_id] = organization.id if organization

  exceptions = subscription_attributes.keys.map(&:to_sym) - self.attribute_names.map(&:to_sym)
  self.update_attributes!(subscription_attributes.except!(*exceptions))
  self.create_product_associations
end

#query_productsObject



23
24
25
# File 'app/models/katello/glue/candlepin/subscription.rb', line 23

def query_products
  self.backend_data["providedProducts"]
end