Class: Katello::ContentViewFilter

Inherits:
Model
  • Object
show all
Defined in:
app/models/katello/content_view_filter.rb

Constant Summary collapse

RPM =
Rpm::CONTENT_TYPE
PACKAGE_GROUP =
PackageGroup::CONTENT_TYPE
ERRATA =
Erratum::CONTENT_TYPE
CONTENT_TYPES =
[RPM, PACKAGE_GROUP, ERRATA]
CONTENT_OPTIONS =
{ _('Packages') => RPM, _('Package Groups') => PACKAGE_GROUP, _('Errata') => ERRATA }

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#destroy!

Class Method Details

.applicable(repo) ⇒ Object



108
109
110
111
112
113
# File 'app/models/katello/content_view_filter.rb', line 108

def self.applicable(repo)
  query = %{ (katello_content_view_filters.id in (select content_view_filter_id from katello_content_view_filters_repositories where repository_id = #{repo.id})) or
             (katello_content_view_filters.id not in (select content_view_filter_id from katello_content_view_filters_repositories))
           }
  where(query).select("DISTINCT katello_content_view_filters.id")
end

.class_for(content_type) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/katello/content_view_filter.rb', line 57

def self.class_for(content_type)
  case content_type
  when RPM
    ContentViewPackageFilter
  when PACKAGE_GROUP
    ContentViewPackageGroupFilter
  when ERRATA
    ContentViewErratumFilter
  else
    fail _("Invalid content type '%{content_type}' provided. Content types can be one of %{content_types}") %
             { :content_type => content_type, :content_types => CONTENT_TYPES.join(", ") }
  end
end

.create_for(content_type, options) ⇒ Object



103
104
105
106
# File 'app/models/katello/content_view_filter.rb', line 103

def self.create_for(content_type, options)
  clazz = class_for(content_type)
  clazz.create!(options)
end

.rule_class_for(filter) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/katello/content_view_filter.rb', line 71

def self.rule_class_for(filter)
  case filter.type
  when ContentViewPackageFilter.name
    ContentViewPackageFilterRule
  when ContentViewPackageGroupFilter.name
    ContentViewPackageGroupFilterRule
  when ContentViewErratumFilter.name
    ContentViewErratumFilterRule
  else
    fail _("Invalid content type '%{content_type}' provided. Content types can be one of %{content_types}") %
             { :content_type => filter.type, :content_types => CONTENT_TYPES.join(", ") }
  end
end

.rule_ids_for(filter) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/katello/content_view_filter.rb', line 85

def self.rule_ids_for(filter)
  case filter.type
  when ContentViewPackageFilter.name
    filter.package_rule_ids
  when ContentViewPackageGroupFilter.name
    filter.package_group_rule_ids
  when ContentViewErratumFilter.name
    filter.erratum_rule_ids
  else
    fail _("Invalid content type '%{content_type}' provided. Content types can be one of %{content_types}") %
             { :content_type => filter.type, :content_types => CONTENT_TYPES.join(", ") }
  end
end

.yumObject



39
40
41
42
43
# File 'app/models/katello/content_view_filter.rb', line 39

def self.yum
  where(:type => [::Katello::ContentViewPackageGroupFilter.name,
                  ::Katello::ContentViewErratumFilter.name,
                  ::Katello::ContentViewPackageFilter.name])
end

Instance Method Details

#applicable_reposObject



139
140
141
142
143
144
145
# File 'app/models/katello/content_view_filter.rb', line 139

def applicable_repos
  if self.repositories.blank?
    self.content_view.repositories
  else
    self.repositories
  end
end

#as_json(options = {}) ⇒ Object



115
116
117
118
119
120
# File 'app/models/katello/content_view_filter.rb', line 115

def as_json(options = {})
  super(options).update("content_view_label" => content_view.label,
                        "organization" => content_view.organization.label,
                        "repos" => repositories.collect(&:name),
                        "content" => content_type)
end

#content_typeObject



49
50
51
52
53
54
55
# File 'app/models/katello/content_view_filter.rb', line 49

def content_type
  {
    ContentViewPackageFilter => RPM,
    ContentViewErratumFilter => ERRATA,
    ContentViewPackageGroupFilter => PACKAGE_GROUP
  }[self.class]
end

#filter_typeObject



99
100
101
# File 'app/models/katello/content_view_filter.rb', line 99

def filter_type
  CONTENT_OPTIONS.key(content_type)
end

#original_packages=(_include_original) ⇒ Object



147
148
149
# File 'app/models/katello/content_view_filter.rb', line 147

def original_packages=(_include_original)
  fail "setting original_packages not supported for #{self.class.name}"
end

#params_formatObject



45
46
47
# File 'app/models/katello/content_view_filter.rb', line 45

def params_format
  {}
end

#resulting_productsObject



135
136
137
# File 'app/models/katello/content_view_filter.rb', line 135

def resulting_products
  repositories.collect { |r| r.product }.uniq
end

#validate_content_viewObject



122
123
124
125
126
# File 'app/models/katello/content_view_filter.rb', line 122

def validate_content_view
  if self.content_view.composite?
    errors.add(:base, _("cannot contain filters if composite view"))
  end
end

#validate_filter_repos(errors, content_view) ⇒ Object



128
129
130
131
132
133
# File 'app/models/katello/content_view_filter.rb', line 128

def validate_filter_repos(errors, content_view)
  repo_diff = repositories - content_view.repositories
  unless repo_diff.empty?
    errors.add(:base, _("cannot contain filters whose repositories do not belong to this content view"))
  end
end