Sha256: 9bff82bc8cf68a243abd48742a2a6dab3c75837e47f97ad69c3c9452d2bd2bf6

Contents?: true

Size: 1.67 KB

Versions: 42

Compression:

Stored size: 1.67 KB

Contents

module Katello
  module Glue::Candlepin::Subscription
    def self.included(base)
      base.send :include, LazyAccessor
      base.send :include, InstanceMethods
      base.send :extend, ClassMethods

      base.class_eval do
        lazy_accessor :backend_data, :initializer => lambda { |_s| self.class.candlepin_data(self.organization.label, self.cp_id) }
      end
    end

    module ClassMethods
      def candlepin_data(org, cp_id)
        Katello::Resources::Candlepin::Product.get(org, cp_id)[0]
      end

      def get_for_owner(organization)
        Katello::Resources::Candlepin::Product.all(organization).select do |product|
          #this product's id is non-numeric (marketing product), or its a custom product
          !Glue::Candlepin::Product.engineering_product_id?(product['id']) || Katello::Product.find_by(:cp_id => product['id']).try(:custom?)
        end
      end

      def import_candlepin_records(cp_subs, org)
        cp_subs = cp_subs.reject { |cp_subscription| ::Katello::Glue::Provider.orphaned_custom_product?(cp_subscription['productId'], org) }
        super(cp_subs, org)
      end
    end

    module InstanceMethods
      def import_data
        subscription_attributes = {}
        product_json = self.backend_data

        product_json["attributes"].each { |attr| subscription_attributes[attr["name"].to_sym] = attr["value"] }

        subscription_attributes[:name] = product_json["name"]
        subscription_attributes[:instance_multiplier] = product_json["multiplier"]

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

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
katello-4.16.0 app/models/katello/glue/candlepin/subscription.rb
katello-4.15.1 app/models/katello/glue/candlepin/subscription.rb
katello-4.16.0.rc2 app/models/katello/glue/candlepin/subscription.rb
katello-4.16.0.rc1 app/models/katello/glue/candlepin/subscription.rb
katello-4.14.3 app/models/katello/glue/candlepin/subscription.rb
katello-4.14.2 app/models/katello/glue/candlepin/subscription.rb
katello-4.15.0 app/models/katello/glue/candlepin/subscription.rb
katello-4.15.0.rc2 app/models/katello/glue/candlepin/subscription.rb
katello-4.15.0.rc1 app/models/katello/glue/candlepin/subscription.rb
katello-4.14.1 app/models/katello/glue/candlepin/subscription.rb
katello-4.14.0 app/models/katello/glue/candlepin/subscription.rb
katello-4.14.0.rc3 app/models/katello/glue/candlepin/subscription.rb
katello-4.14.0.rc2 app/models/katello/glue/candlepin/subscription.rb
katello-4.14.0.rc1.1 app/models/katello/glue/candlepin/subscription.rb
katello-4.14.0.rc1 app/models/katello/glue/candlepin/subscription.rb
katello-4.13.1 app/models/katello/glue/candlepin/subscription.rb
katello-4.13.0 app/models/katello/glue/candlepin/subscription.rb
katello-4.12.1 app/models/katello/glue/candlepin/subscription.rb
katello-4.13.0.rc1 app/models/katello/glue/candlepin/subscription.rb
katello-4.12.0 app/models/katello/glue/candlepin/subscription.rb