Sha256: c972881e695451a2b8b7d6c5ad3a80a7ab6c9ce6a36b9bc687eb8d67433fa033

Contents?: true

Size: 1.46 KB

Versions: 9

Compression:

Stored size: 1.46 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.find_or_create_by_cp_id(cp_id) 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

9 entries across 9 versions & 1 rubygems

Version Path
katello-2.4.5 app/models/katello/glue/candlepin/candlepin_object.rb
katello-2.4.4 app/models/katello/glue/candlepin/candlepin_object.rb
katello-2.4.3 app/models/katello/glue/candlepin/candlepin_object.rb
katello-2.4.2 app/models/katello/glue/candlepin/candlepin_object.rb
katello-2.4.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-2.4.0 app/models/katello/glue/candlepin/candlepin_object.rb
katello-2.4.0.rc3 app/models/katello/glue/candlepin/candlepin_object.rb
katello-2.4.0.rc2 app/models/katello/glue/candlepin/candlepin_object.rb
katello-2.4.0.rc1 app/models/katello/glue/candlepin/candlepin_object.rb