Module: RhCloudHost::ClassMethods

Defined in:
app/models/concerns/rh_cloud_host.rb

Instance Method Summary collapse

Instance Method Details

#search_by_insights_uuid(_key, operator, value) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/concerns/rh_cloud_host.rb', line 49

def search_by_insights_uuid(_key, operator, value)
  # Determine which facet table to search based on IoP mode
  facet_table = ForemanRhCloud.with_iop_smart_proxy? ? Katello::Host::SubscriptionFacet.table_name : InsightsFacet.table_name

  # Build SQL condition
  if ['IN', 'NOT IN'].include?(operator)
    # For IN/NOT IN, value may be an array or comma-separated string
    # Convert to array and build placeholders for each value
    values = value.is_a?(Array) ? value : value.to_s.split(',').map(&:strip)
    placeholders = (['?'] * values.size).join(',')
    condition = sanitize_sql_for_conditions(
      ["#{facet_table}.uuid #{operator} (#{placeholders})", *values]
    )
  else
    # For other operators (=, !=, LIKE, etc.), use value_to_sql for proper SQL formatting
    condition = sanitize_sql_for_conditions(
      ["#{facet_table}.uuid #{operator} ?", value_to_sql(operator, value)]
    )
  end

  # Return search parameters with LEFT JOIN to include hosts without facets
  {
    joins: "LEFT JOIN #{facet_table} ON #{facet_table}.host_id = #{Host::Managed.table_name}.id",
    conditions: condition,
  }
end