Sha256: c7d69d9dadd81b13cd249c4c52c82c224f9fcc6f7acb0e26b98f5e3e87d9c45f

Contents?: true

Size: 1.59 KB

Versions: 52

Compression:

Stored size: 1.59 KB

Contents

module Katello
  class ContentViewDebFilter < ContentViewFilter
    CONTENT_TYPE = Deb::CONTENT_TYPE

    has_many :deb_rules, :dependent => :destroy, :foreign_key => :content_view_filter_id,
                                   :class_name => "Katello::ContentViewDebFilterRule"
    validates_lengths_from_database

    def generate_clauses(repo)
      package_filenames = []

      self.deb_rules.each do |rule|
        package_filenames.concat(query_debs(repo, rule))
      end

      ContentViewDebFilter.generate_deb_clauses(package_filenames)
    end

    def content_unit_pulp_ids(repo)
      deb_filenames = []
      self.deb_rules.each do |rule|
        deb_filenames.concat(query_debs(repo, rule))
      end
      debs = Deb.in_repositories(repo)
      debs.where(filename: deb_filenames).pluck(:pulp_id).flatten.uniq
    end

    def self.generate_deb_clauses(package_filenames = [])
      { 'filename' => { "$in" => package_filenames } } unless package_filenames.empty?
    end

    def applicable_debs
      Deb.in_repositories(self.applicable_repos)
    end

    def query_debs(repo, rule)
      debs = Deb.in_repositories(repo)
      query_debs_from_collection(debs, rule).pluck("#{Deb.table_name}.filename")
    end

    def query_debs_from_collection(collection, rule)
      query_name = rule.name.tr("*", "%")
      query = collection.where("#{Deb.table_name}.name ilike ?", query_name)
      if rule.architecture.present?
        query_arch = rule.architecture.tr("*", "%")
        query = query.where("#{Deb.table_name}.architecture ilike ?", query_arch)
      end
      query.default_sort
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
katello-4.14.2 app/models/katello/content_view_deb_filter.rb
katello-4.15.0 app/models/katello/content_view_deb_filter.rb
katello-4.15.0.rc2 app/models/katello/content_view_deb_filter.rb
katello-4.15.0.rc1 app/models/katello/content_view_deb_filter.rb
katello-4.14.1 app/models/katello/content_view_deb_filter.rb
katello-4.14.0 app/models/katello/content_view_deb_filter.rb
katello-4.14.0.rc3 app/models/katello/content_view_deb_filter.rb
katello-4.14.0.rc2 app/models/katello/content_view_deb_filter.rb
katello-4.14.0.rc1.1 app/models/katello/content_view_deb_filter.rb
katello-4.14.0.rc1 app/models/katello/content_view_deb_filter.rb
katello-4.13.1 app/models/katello/content_view_deb_filter.rb
katello-4.13.0 app/models/katello/content_view_deb_filter.rb
katello-4.12.1 app/models/katello/content_view_deb_filter.rb
katello-4.13.0.rc1 app/models/katello/content_view_deb_filter.rb
katello-4.12.0 app/models/katello/content_view_deb_filter.rb
katello-4.12.0.rc3 app/models/katello/content_view_deb_filter.rb
katello-4.12.0.rc2 app/models/katello/content_view_deb_filter.rb
katello-4.12.0.rc1 app/models/katello/content_view_deb_filter.rb
katello-4.11.1 app/models/katello/content_view_deb_filter.rb
katello-4.11.0 app/models/katello/content_view_deb_filter.rb