Class: Queries::DataAttribute::Filter

Inherits:
Query::Filter show all
Includes:
Concerns::Polymorphic
Defined in:
lib/queries/data_attribute/filter.rb

Constant Summary collapse

PARAMS =
[
  *::DataAttribute.related_foreign_keys.map(&:to_sym),
  :value,
  :controlled_vocabulary_term_id,
  :import_predicate,
  :type,
  :attribute_subject_type,
  :attribute_subject_id,
  :data_attribute_id,
  controlled_vocabulary_term_id: [],
  data_attribute_id: []
].freeze

Constants inherited from Query::Filter

Query::Filter::FILTER_QUERIES, Query::Filter::SUBQUERIES

Instance Attribute Summary collapse

Attributes inherited from Query::Filter

#api, #asserted_distribution_query, #biological_association_query, #biological_associations_graph_query, #collecting_event_query, #collection_object_query, #content_query, #controlled_vocabulary_term_query, #data_attribute_query, #descriptor_query, #extract_query, #field_occurrence_query, #image_query, #loan_query, #object_global_id, #observation_query, #otu_query, #page, #paginate, #params, #per, #person_query, #project_id, #recent, #taxon_name_query, #venn, #venn_mode

Attributes inherited from Query

#query_string, #terms

Instance Method Summary collapse

Methods inherited from Query::Filter

#all, #all_and_clauses, #all_merge_clauses, #annotator_and_clauses, #annotator_merge_clauses, annotator_params, api_except_params, api_excluded_params, #apply_venn, #attribute_exact_facet, base_filter, #deep_permit, included_annotator_facets, inverted_subqueries, #model_id_facet, #object_global_id_facet, params, #permitted_params, #process_url_into_params, #project_id_facet, query_name, #query_name, #set_nested_queries, #shared_and_clauses, #subquery_vector, #venn_query

Methods inherited from Query

#alphabetic_strings, #alphanumeric_strings, base_name, #base_name, #base_query, #build_terms, #cached_facet, #end_wildcard, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #no_terms?, referenced_klass, #referenced_klass, #referenced_klass_except, #referenced_klass_intersection, #referenced_klass_union, #start_and_end_wildcard, #start_wildcard, #table, #wildcard_pieces

Constructor Details

#initialize(query_params) ⇒ Filter

Returns a new instance of Filter.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/queries/data_attribute/filter.rb', line 38

def initialize(query_params)
  super

  @attribute_subject_id = params[:attribute_subject_id]
  @attribute_subject_type = params[:attribute_subject_type]
  @controlled_vocabulary_term_id = params[:controlled_vocabulary_term_id]
  @data_attribute_id = params[:data_attribute_id]
  @import_predicate = params[:import_predicate]
  @type = params[:type]
  @value = params[:value]

  set_polymorphic_params(params)
end

Instance Attribute Details

#attribute_subject_idObject

Returns the value of attribute attribute_subject_id.



33
34
35
# File 'lib/queries/data_attribute/filter.rb', line 33

def attribute_subject_id
  @attribute_subject_id
end

#attribute_subject_typeObject

Returns the value of attribute attribute_subject_type.



31
32
33
# File 'lib/queries/data_attribute/filter.rb', line 31

def attribute_subject_type
  @attribute_subject_type
end

#controlled_vocabulary_term_idArray

Returns:

  • (Array)


25
26
27
# File 'lib/queries/data_attribute/filter.rb', line 25

def controlled_vocabulary_term_id
  @controlled_vocabulary_term_id
end

#data_attribute_idObject

Returns the value of attribute data_attribute_id.



35
36
37
# File 'lib/queries/data_attribute/filter.rb', line 35

def data_attribute_id
  @data_attribute_id
end

#import_predicateObject

Returns the value of attribute import_predicate.



27
28
29
# File 'lib/queries/data_attribute/filter.rb', line 27

def import_predicate
  @import_predicate
end

#typeObject

Returns the value of attribute type.



29
30
31
# File 'lib/queries/data_attribute/filter.rb', line 29

def type
  @type
end

#valueObject

Params specific to DataAttribute



22
23
24
# File 'lib/queries/data_attribute/filter.rb', line 22

def value
  @value
end

Instance Method Details

#and_clausesObject



115
116
117
118
119
120
121
122
123
124
# File 'lib/queries/data_attribute/filter.rb', line 115

def and_clauses
  [
    matching_type,
    matching_value,
    matching_import_predicate,
    matching_attribute_subject_id,
    matching_attribute_subject_type,
    matching_controlled_vocabulary_term_id,
  ]
end

#from_filter_facet(query) ⇒ Object

Replaces things like ‘otu_query_facet)



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/queries/data_attribute/filter.rb', line 93

def from_filter_facet(query)
  return nil if query.nil?
  t = "query_#{query.table.name}_da"
  k = query.referenced_klass.name

  s = "WITH #{t} AS (" + query.all.to_sql + ') ' +
    ::DataAttribute
    .joins("JOIN #{t} as #{t}1 on data_attributes.attribute_subject_id = #{t}1.id AND data_attributes.attribute_subject_type = '" + k + "'")
    .to_sql

  ::DataAttribute.from('(' + s + ') as data_attributes').distinct
end

#matching_attribute_subject_idArel::Node?

Returns:

  • (Arel::Node, nil)


68
69
70
# File 'lib/queries/data_attribute/filter.rb', line 68

def matching_attribute_subject_id
  attribute_subject_id.present? ? table[:attribute_subject_id].eq(attribute_subject_id)  : nil
end

#matching_attribute_subject_typeArel::Node?

Returns:

  • (Arel::Node, nil)


63
64
65
# File 'lib/queries/data_attribute/filter.rb', line 63

def matching_attribute_subject_type
  attribute_subject_type.present? ? table[:attribute_subject_type].eq(attribute_subject_type)  : nil
end

#matching_controlled_vocabulary_term_idArel::Node?

Returns:

  • (Arel::Node, nil)


88
89
90
# File 'lib/queries/data_attribute/filter.rb', line 88

def matching_controlled_vocabulary_term_id
  controlled_vocabulary_term_id.empty? ? nil : table[:controlled_vocabulary_term_id].in(controlled_vocabulary_term_id)
end

#matching_import_predicateArel::Node?

Returns:

  • (Arel::Node, nil)


78
79
80
# File 'lib/queries/data_attribute/filter.rb', line 78

def matching_import_predicate
  import_predicate.blank? ? nil : table[:import_predicate].eq(import_predicate)
end

#matching_typeArel::Node?

Returns:

  • (Arel::Node, nil)


83
84
85
# File 'lib/queries/data_attribute/filter.rb', line 83

def matching_type
  type.blank? ? nil : table[:type].eq(type)
end

#matching_valueArel::Node?

Returns:

  • (Arel::Node, nil)


73
74
75
# File 'lib/queries/data_attribute/filter.rb', line 73

def matching_value
  value.blank? ? nil : table[:value].eq(value)
end

#merge_clausesObject



106
107
108
109
110
111
112
113
# File 'lib/queries/data_attribute/filter.rb', line 106

def merge_clauses
  [
    from_filter_facet(otu_query),
    from_filter_facet(taxon_name_query),
    from_filter_facet(collecting_event_query),
    from_filter_facet(collection_object_query),
  ]
end