Class: Queries::CollectionObject::Filter

Inherits:
Query
  • Object
show all
Includes:
Queries::Concerns::DataAttributes, Queries::Concerns::Identifiers, Queries::Concerns::Notes, Queries::Concerns::Tags, Queries::Concerns::Users, Helpers
Defined in:
lib/queries/collection_object/filter.rb

Overview

TODO

  • use date processing? / DateConcern

  • syncronize with GIS/GEO

Instance Attribute Summary collapse

Attributes inherited from Query

#dynamic_limit, #options, #project_id, #query_string, #terms

Instance Method Summary collapse

Methods included from Helpers

#boolean_param

Methods inherited from Query

#alphabetic_strings, #alphanumeric_strings, #attribute_exact_facet, #autocomplete, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_common_name_exact, #autocomplete_common_name_like, #autocomplete_exact_id, #autocomplete_exactly_named, #autocomplete_named, #autocomplete_ordered_wildcard_pieces_in_cached, #build_terms, #cached, #combine_or_clauses, #common_name_name, #common_name_table, #common_name_wild_pieces, #end_wildcard, #exactly_named, #fragments, #integers, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #no_terms?, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #start_and_end_wildcard, #start_wildcard, #string_fragments, #wildcard_pieces, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #year_letter, #years

Constructor Details

#initialize(params) ⇒ Filter

Returns a new instance of Filter.

Parameters:

  • args (Hash)

    are permitted params



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/queries/collection_object/filter.rb', line 215

def initialize(params)
  params.reject!{ |_k, v| v.blank? } # dump all entries with empty values

  # Only CollectingEvent fields are permitted now.
  # (Perhaps) TODO: allow concern attributes nested inside as well, e.g. show me all COs with this Tag on CE.
  collecting_event_params = ::Queries::CollectingEvent::Filter::ATTRIBUTES + ::Queries::CollectingEvent::Filter::PARAMS

  @collecting_event_query = ::Queries::CollectingEvent::Filter.new(
    params.select{|a,b| collecting_event_params.include?(a.to_s) }
  )

  @ancestor_id = params[:ancestor_id].blank? ? nil : params[:ancestor_id]
  @biocuration_class_ids = params[:biocuration_class_ids] || []
  @biological_relationship_ids = params[:biological_relationship_ids] || []
  @buffered_collecting_event = params[:buffered_collecting_event]
  @buffered_determinations = params[:buffered_determinations]
  @buffered_other_labels = params[:buffered_other_labels]
  @collecting_event = boolean_param(params, :collecting_event)
  @collecting_event_ids = params[:collecting_event_ids] || []
  @collection_object_type = params[:collection_object_type].blank? ? nil : params[:collection_object_type]
  @current_determinations = boolean_param(params, :current_determinations)
  @current_repository = boolean_param(params, :current_repository)
  @current_repository_id = params[:current_repository_id].blank? ? nil : params[:current_repository_id]
  @depictions = boolean_param(params, :depictions)
  @determiner_id = params[:determiner_id]
  @determiner_id_or = boolean_param(params, :determiner_id_or)
  @determiner_name_regex = params[:determiner_name_regex]
  @dwc_indexed = boolean_param(params, :dwc_indexed)
  @exact_buffered_collecting_event = boolean_param(params, :exact_buffered_collecting_event)
  @exact_buffered_determinations = boolean_param(params, :exact_buffered_determinations)
  @exact_buffered_other_labels = boolean_param(params, :exact_buffered_other_labels)
  @geographic_area = boolean_param(params, :geographic_area)
  @georeferences = boolean_param(params, :georeferences)
  @is_type = params[:is_type] || []
  @loaned = boolean_param(params, :loaned)
  @never_loaned = boolean_param(params, :never_loaned)
  @object_global_id = params[:object_global_id]
  @on_loan =  boolean_param(params, :on_loan)
  @loan_id = params[:loan_id]
  @otu_descendants = boolean_param(params, :otu_descendants)
  @otu_ids = params[:otu_ids] || []
  @preparation_type_id = params[:preparation_type_id]
  @recent = boolean_param(params, :recent)
  @repository = boolean_param(params, :repository)
  @preparation_type = boolean_param(params, :preparation_type)
  @repository_id = params[:repository_id].blank? ? nil : params[:repository_id]
  @sled_image_id = params[:sled_image_id].blank? ? nil : params[:sled_image_id]
  @taxon_determinations = boolean_param(params, :taxon_determinations)
  @type_material = boolean_param(params, :type_material)
  @type_specimen_taxon_name_id = params[:type_specimen_taxon_name_id].blank? ? nil : params[:type_specimen_taxon_name_id]
  @validity = boolean_param(params, :validity)
  @with_buffered_collecting_event = boolean_param(params, :with_buffered_collecting_event)
  @with_buffered_determinations =  boolean_param(params, :with_buffered_determinations)
  @with_buffered_other_labels = boolean_param(params, :with_buffered_other_labels)

  set_data_attributes_params(params)
  set_identifier(params)
  set_notes_params(params)
  set_tags_params(params)
  set_user_dates(params)
end

Instance Attribute Details

#ancestor_idProtonym.id?

Return all collection objects determined as an Otu that is self or descendant linked to this TaxonName

Returns:

  • (Protonym.id, nil)

    return all collection objects determined as an Otu that is self or descendant linked to this TaxonName



39
40
41
# File 'lib/queries/collection_object/filter.rb', line 39

def ancestor_id
  @ancestor_id
end

#biocuration_class_idsArray

Returns of biocuration_class ids.

Returns:

  • (Array)

    of biocuration_class ids



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

def biocuration_class_ids
  @biocuration_class_ids
end

#biological_relationship_idsArray

Returns of biological_relationship_ids.

Returns:

  • (Array)

    of biological_relationship_ids



72
73
74
# File 'lib/queries/collection_object/filter.rb', line 72

def biological_relationship_ids
  @biological_relationship_ids
end

#buffered_collecting_eventString?

Returns:

  • (String, nil)


175
176
177
# File 'lib/queries/collection_object/filter.rb', line 175

def buffered_collecting_event
  @buffered_collecting_event
end

#buffered_determinationsString?

Returns:

  • (String, nil)


169
170
171
# File 'lib/queries/collection_object/filter.rb', line 169

def buffered_determinations
  @buffered_determinations
end

#buffered_other_labelsString?

Returns:

  • (String, nil)


184
185
186
# File 'lib/queries/collection_object/filter.rb', line 184

def buffered_other_labels
  @buffered_other_labels
end

#collecting_eventTrue, ...

Parameters:

  • collecting_event ('true', 'false')

    true - has collecting_event_id false - does not have collecting_event_id nil - not applied

Returns:

  • (True, False, nil)


149
150
151
# File 'lib/queries/collection_object/filter.rb', line 149

def collecting_event
  @collecting_event
end

#collecting_event_idsObject

Array

only return objects with this collecting event ID



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

def collecting_event_ids
  @collecting_event_ids
end

#collecting_event_queryObject

All params managed by CollectingEvent filter are available here as well



30
31
32
# File 'lib/queries/collection_object/filter.rb', line 30

def collecting_event_query
  @collecting_event_query
end

#collection_object_typeObject

Parameters:

  • one (String, nil)

    of 'Specimen', 'Lot', or 'RangedLot'



23
24
25
# File 'lib/queries/collection_object/filter.rb', line 23

def collection_object_type
  @collection_object_type
end

#collector_idObject

See Queries::CollectingEvent::Filter



187
188
189
# File 'lib/queries/collection_object/filter.rb', line 187

def collector_id
  @collector_id
end

#collector_ids_orObject

Returns the value of attribute collector_ids_or.



188
189
190
# File 'lib/queries/collection_object/filter.rb', line 188

def collector_ids_or
  @collector_ids_or
end

#current_determinationsBoolean?

Returns nil = TaxonDeterminations match regardless of current or historical true = TaxonDetermination must be .current false = TaxonDetermination must be .historical.

Returns:

  • (Boolean, nil)

    nil = TaxonDeterminations match regardless of current or historical true = TaxonDetermination must be .current false = TaxonDetermination must be .historical



51
52
53
# File 'lib/queries/collection_object/filter.rb', line 51

def current_determinations
  @current_determinations
end

#current_repositoryTrue, ...

Returns true - has current_repository_id false - does not have current_repository_id nil - not applied.

Returns:

  • (True, False, nil)

    true - has current_repository_id false - does not have current_repository_id nil - not applied



133
134
135
# File 'lib/queries/collection_object/filter.rb', line 133

def current_repository
  @current_repository
end

#current_repository_idCurrentRepository#id?

Returns:

  • (CurrentRepository#id, nil)


87
88
89
# File 'lib/queries/collection_object/filter.rb', line 87

def current_repository_id
  @current_repository_id
end

#depictionsTrue, ...

Returns true - index is built false - index is not built nil - not applied.

Returns:

  • (True, False, nil)

    true - index is built false - index is not built nil - not applied



101
102
103
# File 'lib/queries/collection_object/filter.rb', line 101

def depictions
  @depictions
end

#determiner_idArray

Parameters:

  • determiner (Array or Person#id)

    one ore more people id

Returns:

  • (Array)


160
161
162
# File 'lib/queries/collection_object/filter.rb', line 160

def determiner_id
  @determiner_id
end

#determiner_id_orBoolean

Parameters:

  • determiner_id_or (String, nil)

    `false`, nil - treat ids as “or” 'true' - treat ids as “and” (only collection objects with all and only all will match)

Returns:

  • (Boolean)


166
167
168
# File 'lib/queries/collection_object/filter.rb', line 166

def determiner_id_or
  @determiner_id_or
end

#determiner_name_regexObject

A PostgreSQL valid regular expression. Note that simple strings evaluate as wildcard matches. !! Probably shouldn't expose to external API.

Returns:

  • String



212
213
214
# File 'lib/queries/collection_object/filter.rb', line 212

def determiner_name_regex
  @determiner_name_regex
end

#dwc_indexedTrue, ...

Returns true - index is built false - index is not built nil - not applied.

Returns:

  • (True, False, nil)

    true - index is built false - index is not built nil - not applied



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

def dwc_indexed
  @dwc_indexed
end

#exact_buffered_collecting_eventBoolean?

Returns:

  • (Boolean, nil)


178
179
180
# File 'lib/queries/collection_object/filter.rb', line 178

def exact_buffered_collecting_event
  @exact_buffered_collecting_event
end

#exact_buffered_determinationsBoolean?

Returns:

  • (Boolean, nil)


172
173
174
# File 'lib/queries/collection_object/filter.rb', line 172

def exact_buffered_determinations
  @exact_buffered_determinations
end

#exact_buffered_other_labelsBoolean?

Returns:

  • (Boolean, nil)


181
182
183
# File 'lib/queries/collection_object/filter.rb', line 181

def exact_buffered_other_labels
  @exact_buffered_other_labels
end

#geographic_areaTrue, ...

Returns true - has collecting event that has geographic_area false - does not have collecting event that has geographic area nil - not applied.

Returns:

  • (True, False, nil)

    true - has collecting event that has geographic_area false - does not have collecting event that has geographic area nil - not applied



155
156
157
# File 'lib/queries/collection_object/filter.rb', line 155

def geographic_area
  @geographic_area
end

#georeferencesTrue, ...

Returns true - has one ore more georeferences false - does not have any georeferences nil - not applied.

Returns:

  • (True, False, nil)

    true - has one ore more georeferences false - does not have any georeferences nil - not applied



113
114
115
# File 'lib/queries/collection_object/filter.rb', line 113

def georeferences
  @georeferences
end

#is_typeArray?

Returns one of `holotype`, `lectotype` etc.

nil - not applied.

Returns:

  • (Array, nil)

    one of `holotype`, `lectotype` etc.

    nil - not applied
    


92
93
94
# File 'lib/queries/collection_object/filter.rb', line 92

def is_type
  @is_type
end

#loan_idArray

Returns an array of loan_ids, all collection objects inside them will be included.

Returns:

  • (Array)

    an array of loan_ids, all collection objects inside them will be included



64
65
66
# File 'lib/queries/collection_object/filter.rb', line 64

def loan_id
  @loan_id
end

#loanedTrue?

Returns:

  • (True, nil)


57
58
59
# File 'lib/queries/collection_object/filter.rb', line 57

def loaned
  @loaned
end

#never_loanedTrue?

Returns:

  • (True, nil)


60
61
62
# File 'lib/queries/collection_object/filter.rb', line 60

def never_loaned
  @never_loaned
end

#object_global_idObject

Returns the value of attribute object_global_id.



121
122
123
# File 'lib/queries/collection_object/filter.rb', line 121

def object_global_id
  @object_global_id
end

#on_loanTrue?

Returns:

  • (True, nil)


54
55
56
# File 'lib/queries/collection_object/filter.rb', line 54

def on_loan
  @on_loan
end

#otu_idsArray?

Returns a list of Otu ids, matches one ot one only.

Returns:

  • (Array, nil)

    a list of Otu ids, matches one ot one only



34
35
36
# File 'lib/queries/collection_object/filter.rb', line 34

def otu_ids
  @otu_ids
end

#preparation_typeTrue, ...

Returns true - has preparation_type false - does not have preparation_type nil - not applied.

Returns:

  • (True, False, nil)

    true - has preparation_type false - does not have preparation_type nil - not applied



139
140
141
# File 'lib/queries/collection_object/filter.rb', line 139

def preparation_type
  @preparation_type
end

#preparation_type_idArray

Returns:

  • (Array)


142
143
144
# File 'lib/queries/collection_object/filter.rb', line 142

def preparation_type_id
  @preparation_type_id
end

#recentBoolen?

Parameters:

  • 'true' (String, nil)
    • order by updated_at

    'false', nil - do not apply ordering

Returns:

  • (Boolen, nil)


119
120
121
# File 'lib/queries/collection_object/filter.rb', line 119

def recent
  @recent
end

#repositoryTrue, ...

Returns true - has repository_id false - does not have repository_id nil - not applied.

Returns:

  • (True, False, nil)

    true - has repository_id false - does not have repository_id nil - not applied



127
128
129
# File 'lib/queries/collection_object/filter.rb', line 127

def repository
  @repository
end

#repository_idRepository#id?

Returns:



84
85
86
# File 'lib/queries/collection_object/filter.rb', line 84

def repository_id
  @repository_id
end

#sled_image_idSledImage#id?

Returns:



95
96
97
# File 'lib/queries/collection_object/filter.rb', line 95

def sled_image_id
  @sled_image_id
end

#taxon_determinationsTrue, ...

Returns true - has one ore more taxon_determinations false - does not have any taxon_determinations nil - not applied.

Returns:

  • (True, False, nil)

    true - has one ore more taxon_determinations false - does not have any taxon_determinations nil - not applied



107
108
109
# File 'lib/queries/collection_object/filter.rb', line 107

def taxon_determinations
  @taxon_determinations
end

#type_materialTrue, ...

Returns true - has collecting event that has geographic_area false - does not have collecting event that has geographic area nil - not applied.

Returns:

  • (True, False, nil)

    true - has collecting event that has geographic_area false - does not have collecting event that has geographic area nil - not applied



194
195
196
# File 'lib/queries/collection_object/filter.rb', line 194

def type_material
  @type_material
end

#type_specimen_taxon_name_idProtonym#id?

Returns:



81
82
83
# File 'lib/queries/collection_object/filter.rb', line 81

def type_specimen_taxon_name_id
  @type_specimen_taxon_name_id
end

#validityBoolean?

Returns nil = Match against all ancestors, valid or invalid true = Match against only valid ancestors false = Match against only invalid ancestors.

Returns:

  • (Boolean, nil)

    nil = Match against all ancestors, valid or invalid true = Match against only valid ancestors false = Match against only invalid ancestors



45
46
47
# File 'lib/queries/collection_object/filter.rb', line 45

def validity
  @validity
end

#with_buffered_collecting_eventObject

See with_buffered_determinations



203
204
205
# File 'lib/queries/collection_object/filter.rb', line 203

def with_buffered_collecting_event
  @with_buffered_collecting_event
end

#with_buffered_determinationsBoolean?

Returns Boolean, nil.

Parameters:

  • with_buffered_determinations (String, nil)

    `false`, nil - without buffered determination field value 'true' - with buffered_determinations field value

Returns:

  • (Boolean, nil)

    Boolean, nil



200
201
202
# File 'lib/queries/collection_object/filter.rb', line 200

def with_buffered_determinations
  @with_buffered_determinations
end

#with_buffered_other_labelsObject

See with_buffered_determinations



206
207
208
# File 'lib/queries/collection_object/filter.rb', line 206

def with_buffered_other_labels
  @with_buffered_other_labels
end

Instance Method Details

#allActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
# File 'lib/queries/collection_object/filter.rb', line 665

def all
  a = and_clauses
  b = merge_clauses
  # q = nil
  if a && b
    q = b.where(a).distinct
  elsif a
    q = ::CollectionObject.where(a).distinct
  elsif b
    q = b.distinct
  else
    q = ::CollectionObject.all
  end

  # TODO: needs to go, orders mess with chaining.
  q = q.order(updated_at: :desc) if recent
  q
end

#ancestors_facetObject



737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
# File 'lib/queries/collection_object/filter.rb', line 737

def ancestors_facet
  return nil if ancestor_id.nil?
  h = Arel::Table.new(:taxon_name_hierarchies)
  t = ::TaxonName.arel_table

  q = table.join(taxon_determination_table, Arel::Nodes::InnerJoin).on(
    table[:id].eq(taxon_determination_table[:biological_collection_object_id])
  ).join(otu_table, Arel::Nodes::InnerJoin).on(
    taxon_determination_table[:otu_id].eq(otu_table[:id])
  ).join(t, Arel::Nodes::InnerJoin).on(
    otu_table[:taxon_name_id].eq(t[:id])
  ).join(h, Arel::Nodes::InnerJoin).on(
    t[:id].eq(h[:descendant_id])
  )

  z = h[:ancestor_id].eq(ancestor_id)

  if validity == true
    z = z.and(t[:cached_valid_taxon_name_id].eq(t[:id]))
  elsif validity == false
    z = z.and(t[:cached_valid_taxon_name_id].not_eq(t[:id]))
  end

  if current_determinations == true
    z = z.and(taxon_determination_table[:position].eq(1))
  elsif current_determinations == false
    z = z.and(taxon_determination_table[:position].gt(1))
  end

  ::CollectionObject.joins(q.join_sources).where(z)
end

#and_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


574
575
576
577
578
579
580
581
582
583
584
# File 'lib/queries/collection_object/filter.rb', line 574

def and_clauses
  clauses = base_and_clauses

  return nil if clauses.empty?

  a = clauses.shift
  clauses.each do |b|
    a = a.and(b)
  end
  a
end

#base_and_clausesArray

Returns:

  • (Array)


587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'lib/queries/collection_object/filter.rb', line 587

def base_and_clauses
  clauses = []

  clauses += [
    attribute_exact_facet(:buffered_determinations),
    attribute_exact_facet(:buffered_collecting_event),
    attribute_exact_facet(:buffered_other_labels),
    collecting_event_ids_facet,
    preparation_type_id_facet,
    type_facet,
    repository_id_facet,
    current_repository_id_facet,
    object_global_id_facet
  ]
  clauses.compact!
  clauses
end

#base_merge_clausesObject



605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
# File 'lib/queries/collection_object/filter.rb', line 605

def base_merge_clauses
  clauses = []
  clauses += collecting_event_merge_clauses + collecting_event_and_clauses

  clauses += [
    ancestors_facet,
    biocuration_facet,
    biological_relationship_ids_facet,
    collecting_event_facet,
    created_updated_facet,  # See Queries::Concerns::Users
    current_repository_facet,
    data_attribute_predicate_facet,
    data_attribute_value_facet,
    data_attributes_facet,
    depictions_facet,
    determiner_facet,
    determiner_name_regex_facet,
    dwc_indexed_facet,
    geographic_area_facet,
    georeferences_facet,
    identifier_between_facet,
    identifier_facet,       # See Queries::Concerns::Identifiers
    identifier_namespace_facet,
    identifiers_facet,
    keyword_id_facet,       # See Queries::Concerns::Tags
    loan_facet,
    loaned_facet,
    never_loaned_facet,
    note_text_facet,        # See Queries::Concerns::Notes
    notes_facet,
    on_loan_facet,
    otus_facet,
    preparation_type_facet,
    repository_facet,
    sled_image_facet,
    taxon_determinations_facet,
    type_by_taxon_name_facet,
    type_material_facet,
    type_material_type_facet,
    with_buffered_collecting_event_facet,
    with_buffered_determinations_facet,
    with_buffered_other_labels_facet,
  ]

  clauses.compact!
  clauses
end

#base_queryObject



282
283
284
# File 'lib/queries/collection_object/filter.rb', line 282

def base_query
  ::CollectionObject.select('collection_objects.*')
end

#biocuration_facetObject



473
474
475
476
# File 'lib/queries/collection_object/filter.rb', line 473

def biocuration_facet
  return nil if biocuration_class_ids.empty?
  ::CollectionObject::BiologicalCollectionObject.joins(:biocuration_classifications).where(biocuration_classifications: {biocuration_class_id: biocuration_class_ids})
end

#biological_relationship_ids_facetObject



505
506
507
508
# File 'lib/queries/collection_object/filter.rb', line 505

def biological_relationship_ids_facet
  return nil if biological_relationship_ids.empty?
  ::CollectionObject.with_biological_relationship_ids(biological_relationship_ids)
end

#collecting_event_and_clausesObject



563
564
565
566
567
568
569
570
571
# File 'lib/queries/collection_object/filter.rb', line 563

def collecting_event_and_clauses
  c = []

  # Convert base and clauses to merge clauses
  collecting_event_query.base_and_clauses.each do |i|
    c.push ::CollectionObject.joins(:collecting_event).where( i )
  end
  c
end

#collecting_event_facetObject



424
425
426
427
428
429
430
431
# File 'lib/queries/collection_object/filter.rb', line 424

def collecting_event_facet
  return nil if collecting_event.nil?
  if collecting_event
    ::CollectionObject.where.not(collecting_event_id: nil)
  else
    ::CollectionObject.where(collecting_event_id: nil)
  end
end

#collecting_event_ids_facetObject

Returns Scope.

Returns:

  • Scope



533
534
535
536
# File 'lib/queries/collection_object/filter.rb', line 533

def collecting_event_ids_facet
  return nil if collecting_event_ids.empty?
  table[:collecting_event_id].eq_any(collecting_event_ids)
end

#collecting_event_merge_clausesObject



553
554
555
556
557
558
559
560
561
# File 'lib/queries/collection_object/filter.rb', line 553

def collecting_event_merge_clauses
  c = []

  # Convert base and clauses to merge clauses
  collecting_event_query.base_merge_clauses.each do |i|
    c.push ::CollectionObject.joins(:collecting_event).merge( i )
  end
  c
end

#collecting_event_tableArel::Table

Returns:

  • (Arel::Table)


287
288
289
# File 'lib/queries/collection_object/filter.rb', line 287

def collecting_event_table
  ::CollectingEvent.arel_table
end

#current_repository_facetObject



406
407
408
409
410
411
412
413
# File 'lib/queries/collection_object/filter.rb', line 406

def current_repository_facet
  return nil if current_repository.nil?
  if current_repository
    ::CollectionObject.where.not(current_repository_id: nil)
  else
    ::CollectionObject.where(current_repository_id: nil)
  end
end

#current_repository_id_facetObject



548
549
550
551
# File 'lib/queries/collection_object/filter.rb', line 548

def current_repository_id_facet
  return nil if current_repository_id.blank?
  table[:current_repository_id].eq(current_repository_id)
end

#depiction_tableArel::Table

Returns:

  • (Arel::Table)


302
303
304
# File 'lib/queries/collection_object/filter.rb', line 302

def depiction_table
  ::Depiction.arel_table
end

#depictions_facetObject



488
489
490
491
492
493
494
495
496
497
498
# File 'lib/queries/collection_object/filter.rb', line 488

def depictions_facet
  return nil if depictions.nil?

  if depictions
    ::CollectionObject.joins(:depictions).distinct
  else
    ::CollectionObject.left_outer_joins(:depictions)
      .where(depictions: {id: nil})
      .distinct
  end
end

#determiner_facetObject

TODO: DRY with Source (author), TaxonName, etc. See Queries::ColletingEvent::Filter for other use



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/queries/collection_object/filter.rb', line 337

def determiner_facet
  return nil if determiner_id.empty?
  tt = table

  o = ::TaxonDetermination.arel_table
  r = ::Role.arel_table

  a = o.alias("a_det__")
  b = o.project(a[Arel.star]).from(a)

  c = r.alias('det_r1')

  b = b.join(c, Arel::Nodes::OuterJoin)
    .on(
      a[:id].eq(c[:role_object_id])
    .and(c[:role_object_type].eq('TaxonDetermination'))
    .and(c[:type].eq('Determiner'))
    )

  e = c[:id].not_eq(nil)
  f = c[:person_id].eq_any(determiner_id)

  b = b.where(e.and(f))
  b = b.group(a['id'])
  b = b.having(a['id'].count.eq(determiner_id.length)) unless determiner_id_or

  b = b.as('det_z1_')

  ::CollectionObject.joins(Arel::Nodes::InnerJoin.new(b, Arel::Nodes::On.new(b['biological_collection_object_id'].eq(tt['id']))))
end

#determiner_name_regex_facetObject



368
369
370
371
# File 'lib/queries/collection_object/filter.rb', line 368

def determiner_name_regex_facet
  return nil if determiner_name_regex.nil?
  ::CollectionObject.joins(:determiners).where('people.cached ~* ?',  determiner_name_regex)
end

#dwc_indexed_facetObject



525
526
527
528
529
530
# File 'lib/queries/collection_object/filter.rb', line 525

def dwc_indexed_facet
  return nil if dwc_indexed.nil?
  dwc_indexed ?
    ::CollectionObject.dwc_indexed :
    ::CollectionObject.dwc_not_indexed
end

#geographic_area_facetObject



461
462
463
464
465
466
467
468
469
470
471
# File 'lib/queries/collection_object/filter.rb', line 461

def geographic_area_facet
  return nil if geographic_area.nil?

  if geographic_area
    ::CollectionObject.joins(:collecting_event).where.not(collecting_events: {geographic_area_id: nil}).distinct
  else
    ::CollectionObject.left_outer_joins(:collecting_event)
      .where(collecting_events: {geographic_area_id: nil})
      .distinct
  end
end

#georeferences_facetObject



373
374
375
376
377
378
379
380
381
382
# File 'lib/queries/collection_object/filter.rb', line 373

def georeferences_facet
  return nil if georeferences.nil?
  if georeferences
    ::CollectionObject.joins(:georeferences).distinct
  else
    ::CollectionObject.left_outer_joins(:georeferences)
      .where(georeferences: {id: nil})
      .distinct
  end
end

#loan_facetObject



478
479
480
481
# File 'lib/queries/collection_object/filter.rb', line 478

def loan_facet
  return nil if loan_id.empty?
  ::CollectionObject::BiologicalCollectionObject.joins(:loans).where(loans: {id: loan_id})
end

#loaned_facetObject



510
511
512
513
# File 'lib/queries/collection_object/filter.rb', line 510

def loaned_facet
  return nil unless loaned
  ::CollectionObject.loaned
end

#merge_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


654
655
656
657
658
659
660
661
662
# File 'lib/queries/collection_object/filter.rb', line 654

def merge_clauses
  clauses = base_merge_clauses
  return nil if clauses.empty?
  a = clauses.shift
  clauses.each do |b|
    a = a.merge(b)
  end
  a
end

#never_loaned_facetObject



515
516
517
518
# File 'lib/queries/collection_object/filter.rb', line 515

def never_loaned_facet
  return nil unless never_loaned
  ::CollectionObject.never_loaned
end

#object_global_id_facetObject



384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/queries/collection_object/filter.rb', line 384

def object_global_id_facet
  return nil if object_global_id.nil?

  if o = GlobalID::Locator.locate(object_global_id)
    k = o.class.name
    id = o.id

    table[:id].eq(id).and(table[:type].eq(k))
  else
    nil
  end
end

#on_loan_facetObject



520
521
522
523
# File 'lib/queries/collection_object/filter.rb', line 520

def on_loan_facet
  return nil unless on_loan
  ::CollectionObject.on_loan
end

#otu_tableArel::Table

Returns:

  • (Arel::Table)


292
293
294
# File 'lib/queries/collection_object/filter.rb', line 292

def otu_table
  ::Otu.arel_table
end

#otus_facetScope

Returns:

  • (Scope)


720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
# File 'lib/queries/collection_object/filter.rb', line 720

def otus_facet
  return nil if otu_ids.empty?

  w = taxon_determination_table[:biological_collection_object_id].eq(table[:id])
    .and( taxon_determination_table[:otu_id].eq_any(otu_ids) )

  if current_determinations
    w = w.and(taxon_determination_table[:position].eq(1))
  elsif current_determinations == false
    w = w.and(taxon_determination_table[:position].gt(1))
  end

  ::CollectionObject.where(
    ::TaxonDetermination.where(w).arel.exists
  )
end

#preparation_type_facetObject



415
416
417
418
419
420
421
422
# File 'lib/queries/collection_object/filter.rb', line 415

def preparation_type_facet
  return nil if preparation_type.nil?
  if preparation_type
    ::CollectionObject.where.not(preparation_type_id: nil)
  else
    ::CollectionObject.where(preparation_type_id: nil)
  end
end

#preparation_type_id_facetObject



538
539
540
541
# File 'lib/queries/collection_object/filter.rb', line 538

def preparation_type_id_facet
  return nil if preparation_type_id.empty?
  table[:preparation_type_id].eq_any(preparation_type_id)
end

#repository_facetObject



397
398
399
400
401
402
403
404
# File 'lib/queries/collection_object/filter.rb', line 397

def repository_facet
  return nil if repository.nil?
  if repository
    ::CollectionObject.where.not(repository_id: nil)
  else
    ::CollectionObject.where(repository_id: nil)
  end
end

#repository_id_facetObject



543
544
545
546
# File 'lib/queries/collection_object/filter.rb', line 543

def repository_id_facet
  return nil if repository_id.blank?
  table[:repository_id].eq(repository_id)
end

#sled_image_facetObject



500
501
502
503
# File 'lib/queries/collection_object/filter.rb', line 500

def sled_image_facet
  return nil if sled_image_id.nil?
  ::CollectionObject::BiologicalCollectionObject.joins(:depictions).where("depictions.sled_image_id = ?", sled_image_id)
end

#tableArel::Table

Returns:

  • (Arel::Table)


278
279
280
# File 'lib/queries/collection_object/filter.rb', line 278

def table
  ::CollectionObject.arel_table
end

#taxon_determination_tableArel::Table

Returns:

  • (Arel::Table)


307
308
309
# File 'lib/queries/collection_object/filter.rb', line 307

def taxon_determination_table
  ::TaxonDetermination.arel_table
end

#taxon_determinations_facetObject



323
324
325
326
327
328
329
330
331
332
333
# File 'lib/queries/collection_object/filter.rb', line 323

def taxon_determinations_facet
  return nil if taxon_determinations.nil?

  if taxon_determinations
    ::CollectionObject.joins(:taxon_determinations).distinct
  else
    ::CollectionObject.left_outer_joins(:taxon_determinations)
      .where(taxon_determinations: {id: nil})
      .distinct
  end
end

#type_by_taxon_name_facetScope

Returns:

  • (Scope)


685
686
687
688
689
690
691
692
693
694
# File 'lib/queries/collection_object/filter.rb', line 685

def type_by_taxon_name_facet
  return nil if type_specimen_taxon_name_id.nil?

  w = type_materials_table[:collection_object_id].eq(table[:id])
    .and( type_materials_table[:protonym_id].eq(type_specimen_taxon_name_id) )

  ::CollectionObject.where(
    ::TypeMaterial.where(w).arel.exists
  )
end

#type_facetObject



483
484
485
486
# File 'lib/queries/collection_object/filter.rb', line 483

def type_facet
  return nil if collection_object_type.nil?
  table[:type].eq(collection_object_type)
end

#type_material_facetObject



708
709
710
711
712
713
714
715
716
717
# File 'lib/queries/collection_object/filter.rb', line 708

def type_material_facet
  return nil if type_material.nil?
  if type_material
    ::CollectionObject.joins(:type_materials).distinct
  else
    ::CollectionObject.left_outer_joins(:type_materials)
      .where(type_materials: {id: nil})
      .distinct
  end
end

#type_material_type_facetScope

Returns:

  • (Scope)


697
698
699
700
701
702
703
704
705
706
# File 'lib/queries/collection_object/filter.rb', line 697

def type_material_type_facet
  return nil if is_type.empty?

  w = type_materials_table[:collection_object_id].eq(table[:id])
    .and( type_materials_table[:type_type].eq_any(is_type) )

  ::CollectionObject.where(
    ::TypeMaterial.where(w).arel.exists
  )
end

#type_materials_tableArel::Table

Returns:

  • (Arel::Table)


297
298
299
# File 'lib/queries/collection_object/filter.rb', line 297

def type_materials_table
  ::TypeMaterial.arel_table
end

#with_buffered_collecting_event_facetObject



434
435
436
437
438
439
440
441
# File 'lib/queries/collection_object/filter.rb', line 434

def with_buffered_collecting_event_facet
  return nil if with_buffered_collecting_event.nil?
  if with_buffered_collecting_event
    ::CollectionObject.where.not(buffered_collecting_event: nil)
  else
    ::CollectionObject.where(buffered_collecting_event: nil)
  end
end

#with_buffered_determinations_facetObject



452
453
454
455
456
457
458
459
# File 'lib/queries/collection_object/filter.rb', line 452

def with_buffered_determinations_facet
  return nil if with_buffered_determinations.nil?
  if with_buffered_determinations
    ::CollectionObject.where.not(buffered_determinations: nil)
  else
    ::CollectionObject.where(buffered_determinations: nil)
  end
end

#with_buffered_other_labels_facetObject



443
444
445
446
447
448
449
450
# File 'lib/queries/collection_object/filter.rb', line 443

def with_buffered_other_labels_facet
  return nil if with_buffered_other_labels.nil?
  if with_buffered_other_labels
    ::CollectionObject.where.not(buffered_other_labels: nil)
  else
    ::CollectionObject.where(buffered_other_labels: nil)
  end
end