Sha256: bbb53d70709e0305bbc65071858ba5dff04d451069cd8fd3ff32676a53d0fe7e

Contents?: true

Size: 1.76 KB

Versions: 24

Compression:

Stored size: 1.76 KB

Contents

module Katello
  module Glue::Candlepin::CandlepinObject
    extend ActiveSupport::Concern

    module ClassMethods
      def get_for_organization(organization)
        # returns objects from AR database rather than candlepin data
        pool_ids = self.get_for_owner(organization.label).collect { |x| x['id'] }
        self.where(:cp_id => pool_ids)
      end

      def get_candlepin_ids(organization)
        self.get_for_owner(organization.label).map { |subscription| subscription["id"] }
      end

      def import_candlepin_ids(organization)
        candlepin_ids = self.get_candlepin_ids(organization)
        candlepin_ids.each do |cp_id|
          self.where(:cp_id => cp_id, :organization_id => organization.id).first_or_create unless cp_id.nil?
        end
        candlepin_ids
      end

      def with_identifier(ids)
        self.with_identifiers(ids).first
      end

      def with_identifiers(ids)
        ids = [ids] unless ids.is_a?(Array)
        ids.map!(&:to_s)
        id_integers = ids.map { |string| Integer(string) rescue -1 }
        where("#{self.table_name}.id = (?) or #{self.table_name}.cp_id = (?)", id_integers, ids)
      end

      def import_all(organization = nil, import_managed_associations = true)
        organizations = organization ? [organization] : Organization.all

        organizations.each do |org|
          candlepin_ids = import_candlepin_ids(org)

          objects = self.in_organization(org)
          objects.each do |item|
            if candlepin_ids.include?(item.cp_id)
              item.import_data
              item.import_managed_associations if import_managed_associations && item.respond_to?(:import_managed_associations)
            else
              item.destroy
            end
          end
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
katello-3.11.2 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.10.2 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.10.1.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.10.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.11.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.11.0 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.11.0.rc2 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.11.0.rc1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.10.0 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.10.0.rc1.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.9.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.10.0.rc1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.9.0 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.8.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.9.0.rc2 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.9.0.rc1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.7.1.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.7.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.8.0 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.8.0.rc3 app/models/katello/glue/candlepin/candlepin_object.rb