Class: Queries::DataAttribute::Filter
- Inherits:
-
Query::Filter
- Object
- Query
- Query::Filter
- Queries::DataAttribute::Filter
- Includes:
- Concerns::Polymorphic
- Defined in:
- lib/queries/data_attribute/filter.rb
Constant Summary collapse
- PARAMS =
[ *::DataAttribute..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
-
#attribute_subject_id ⇒ Object
Returns the value of attribute attribute_subject_id.
-
#attribute_subject_type ⇒ Object
Returns the value of attribute attribute_subject_type.
- #controlled_vocabulary_term_id ⇒ Array
-
#data_attribute_id ⇒ Object
Returns the value of attribute data_attribute_id.
-
#import_predicate ⇒ Object
Returns the value of attribute import_predicate.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Params specific to DataAttribute.
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, #document_query, #dwc_occurrence_query, #extract_query, #field_occurrence_query, #image_query, #loan_query, #object_global_id, #observation_query, #order_by, #otu_query, #page, #paginate, #params, #per, #person_query, #project_id, #recent, #recent_target, #taxon_name_query, #venn, #venn_mode
Attributes inherited from Query
Instance Method Summary collapse
- #and_clauses ⇒ Object
-
#from_filter_facet(query, project_ids = []) ⇒ Object
Replaces things like ‘otu_query_facet).
-
#initialize(query_params) ⇒ Filter
constructor
A new instance of Filter.
- #matching_attribute_subject_id ⇒ Arel::Node?
- #matching_attribute_subject_type ⇒ Arel::Node?
- #matching_controlled_vocabulary_term_id ⇒ Arel::Node?
- #matching_import_predicate ⇒ Arel::Node?
- #matching_type ⇒ Arel::Node?
- #matching_value ⇒ Arel::Node?
- #merge_clauses ⇒ Object
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, base_query_name, base_query_to_h, #deep_permit, included_annotator_facets, instantiated_base_filter, inverted_subqueries, #model_id_facet, #object_global_id_facet, #only_project?, params, #permitted_params, #process_url_into_params, #project_id_facet, query_name, #query_name, #set_nested_queries, #shared_and_clauses, #subquery_vector, #target_and_clauses, #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_id ⇒ Object
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_type ⇒ Object
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_id ⇒ 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_id ⇒ Object
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_predicate ⇒ Object
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 |
#type ⇒ Object
Returns the value of attribute type.
29 30 31 |
# File 'lib/queries/data_attribute/filter.rb', line 29 def type @type end |
#value ⇒ Object
Params specific to DataAttribute
22 23 24 |
# File 'lib/queries/data_attribute/filter.rb', line 22 def value @value end |
Instance Method Details
#and_clauses ⇒ Object
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/queries/data_attribute/filter.rb', line 124 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, project_ids = []) ⇒ Object
Replaces things like ‘otu_query_facet)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/queries/data_attribute/filter.rb', line 93 def from_filter_facet(query, project_ids = []) return nil if query.nil? t = "query_#{query.table.name}_da" k = query.referenced_klass.name q = query if !project_ids.empty? q = q.all.where(project_id: project_ids) else q = q.all end s = "WITH #{t} AS (" + q.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_id ⇒ Arel::Node?
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_type ⇒ Arel::Node?
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_id ⇒ Arel::Node?
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_predicate ⇒ Arel::Node?
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_type ⇒ Arel::Node?
83 84 85 |
# File 'lib/queries/data_attribute/filter.rb', line 83 def matching_type type.blank? ? nil : table[:type].eq(type) end |
#matching_value ⇒ Arel::Node?
73 74 75 |
# File 'lib/queries/data_attribute/filter.rb', line 73 def matching_value value.blank? ? nil : table[:value].eq(value) end |
#merge_clauses ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'lib/queries/data_attribute/filter.rb', line 115 def merge_clauses [ from_filter_facet(otu_query, project_id), from_filter_facet(taxon_name_query, project_id), from_filter_facet(collecting_event_query, project_id), from_filter_facet(collection_object_query, project_id), ] end |