Class: Queries::BiologicalAssociationsGraph::Filter

Inherits:
Query::Filter show all
Includes:
Concerns::Citations, Concerns::DataAttributes, Concerns::Notes, Concerns::Tags
Defined in:
lib/queries/biological_associations_graph/filter.rb

Constant Summary collapse

PARAMS =
[
  :biological_association_id,
  :biological_associations_graph_id,
  :biological_relationship_id,

  biological_association_id: [],
  biological_associations_graph_id: [],
  biological_relationship_id: [],
].freeze
API_PARAM_EXCLUSIONS =
[ ]

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, #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

#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, 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.



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

def initialize(query_params)
  super

  @biological_association_id = params[:biological_association_id]
  @biological_associations_graph_id = params[:biological_associations_graph_id]
  @biological_relationship_id = params[:biological_relationship_id]

  set_data_attributes_params(params)
  set_citations_params(params)
  set_notes_params(params)
  set_tags_params(params)
end

Instance Attribute Details

#biological_association_idArray

Returns one or more BiologicalAssociation#id.

Parameters:

  • biological_association_id (Array, Integer)

Returns:

  • (Array)

    one or more BiologicalAssociation#id



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

def biological_association_id
  @biological_association_id
end

#biological_associations_graph_idObject

Parameters:

  • biological_associations_graph_id

    These biological association graphs



24
25
26
# File 'lib/queries/biological_associations_graph/filter.rb', line 24

def biological_associations_graph_id
  @biological_associations_graph_id
end

#biological_relationship_idArray

See also exclude_taxon_name_relationship

Parameters:

  • biological_relationship_id (Array, Integer)

Returns:

  • (Array)

    one or more biological relationship ID



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

def biological_relationship_id
  @biological_relationship_id
end

Instance Method Details

#and_clausesObject



89
90
91
# File 'lib/queries/biological_associations_graph/filter.rb', line 89

def and_clauses
  [ biological_associations_graph_id_facet ]
end

#biological_association_id_facetObject



73
74
75
76
77
# File 'lib/queries/biological_associations_graph/filter.rb', line 73

def biological_association_id_facet
  return nil if biological_association_id.empty?
  ::BiologicalAssociationsGraph.joins(biological_associations_biological_associations_graphs: [:biological_association])
  .where(biological_associations_biological_associations_graphs: { biological_association_id: }).distinct
end

#biological_association_query_facetObject



79
80
81
82
83
84
85
86
87
# File 'lib/queries/biological_associations_graph/filter.rb', line 79

def biological_association_query_facet
  return nil if biological_association_query.nil?
  s = 'WITH query_ba_bag AS (' + biological_association_query.all.to_sql + ') '

  s << ::BiologicalAssociationGraph.joins(:biological_associations_biological_associations_graphs)
    .joins('JOIN query_ba_bag as query_ba_bag1 on biological_associations_biological_associations_graphs.biological_association_id = query_ba_bag1.id').to_sql

  ::BiologicalAssociation.from('(' + s + ') as biological_associations')
end

#biological_associations_graph_id_facetObject



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

def biological_associations_graph_id_facet
  return nil if biological_associations_graph_id.empty?
  table[:id].in(biological_associations_graph_id)
end

#biological_relationship_id_facetObject



67
68
69
70
71
# File 'lib/queries/biological_associations_graph/filter.rb', line 67

def biological_relationship_id_facet
  return nil if biological_relationship_id.empty?
  ::BiologicalAssociationsGraph.joins(biological_associations_biological_associations_graphs: [:biological_association])
  .where(biological_associations: { biological_association_relationship_id: biological_relationship_id }).distinct
end

#merge_clausesObject



93
94
95
96
97
98
# File 'lib/queries/biological_associations_graph/filter.rb', line 93

def merge_clauses
  [
    biological_association_id_facet,
    biological_relationship_id_facet,
  ]
end