Sha256: 743b71ad91ab6e0946c5b1747b3a5c46b6644b079944855348e4b7ce6be1d098

Contents?: true

Size: 1.47 KB

Versions: 35

Compression:

Stored size: 1.47 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).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).first_or_create unless cp_id.nil?
        end
      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
        candlepin_ids = []

        Organization.all.each do |org|
          import_candlepin_ids(org.label)
          candlepin_ids.concat(get_candlepin_ids(org.label))
        end

        self.all.each do |item|
          if candlepin_ids.include?(item.cp_id)
            item.import_data
          else
            item.destroy
          end
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
katello-3.4.2 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.4.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.4.0.2 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.4.0.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.3.2 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.4.0 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.4.0.rc2 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.4.0.rc1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.3.1.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.3.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.3.0.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.3.0 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.3.0.rc2 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.3.0.rc1.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.3.0.rc1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.2.1.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.2.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.2.0 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.2.0.rc3 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.2.0.rc2 app/models/katello/glue/candlepin/candlepin_object.rb