Skip to content

Commit

Permalink
Fix wildcard collecting event param matches
Browse files Browse the repository at this point in the history
Add determiner_name_regexp in prep for #3026.
  • Loading branch information
mjy committed Jun 15, 2022
1 parent 70b45d0 commit 16be82d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This project <em>does not yet</em> adheres to [Semantic Versioning](https://semv

### Added


- Add `determiner_name_regex` to collection object filter [#3026]
- API interactive key engine endpoint `/api/v1/observation_matrices/123/key.json`
- API depictions endpoint `api/v1/depictions/123.json?extend[]=image&extend[]=sqed_depiction&extend[]=figures`
- Taxon determinations stats in stats API
Expand All @@ -16,9 +18,11 @@ This project <em>does not yet</em> adheres to [Semantic Versioning](https://semv
- Change column order in Observation matrices dashboard task

### Fixed
- Wildcard matches on collecting event attributes failing
- Select row in Observation matrices dashboard assigns incorrect ID
- Last week citations stats in API showing values for images. [#3020]

[#3026]: https://github.com/SpeciesFileGroup/taxonworks/issues/3026
[#3020]: https://github.com/SpeciesFileGroup/taxonworks/issues/3020

## [0.26.2] - 2022-06-05
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/collection_objects/filter_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def collection_object_filter_params
:current_repository_id,
:depictions,
:determiner_id_or,
:determiner_name_regex,
:dwc_indexed,
:end_date,
:exact_buffered_collecting_event,
Expand Down Expand Up @@ -84,7 +85,9 @@ def collection_object_filter_params
keyword_id_or: [],
loan_id: [],
otu_ids: [],
preparation_type_id: []
preparation_type_id: [],

collecting_event_wildcards: [] # !! TODO, factor into CONSTANT
# user_id: []
# collecting_event: {
# :recent,
Expand Down
4 changes: 3 additions & 1 deletion lib/queries/collecting_event/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Filter
class_eval { attr_accessor a.to_sym }
end

PARAMS = %w{collector_id
PARAMS = %w{
collector_id
collector_ids_or
spatial_geographic_areas
wkt
Expand All @@ -28,6 +29,7 @@ class Filter
in_verbatim_locality
in_labels
geo_json
collecting_event_wildcards
}

# Wildcard wrapped matching any label
Expand Down
13 changes: 13 additions & 0 deletions lib/queries/collection_object/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ class Filter < Queries::Query
# See with_buffered_determinations
attr_accessor :with_buffered_other_labels

# @return String
# A PostgreSQL valid regular expression. Note that
# simple strings evaluate as wildcard matches.
# !! Probably shouldn't expose to external API.
attr_accessor :determiner_name_regex

# @param [Hash] args are permitted params
def initialize(params)
params.reject!{ |_k, v| v.blank? } # dump all entries with empty values
Expand Down Expand Up @@ -231,6 +237,7 @@ def initialize(params)
@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)
Expand Down Expand Up @@ -356,6 +363,11 @@ def determiner_facet
::CollectionObject.joins(Arel::Nodes::InnerJoin.new(b, Arel::Nodes::On.new(b['biological_collection_object_id'].eq(tt['id']))))
end

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

def georeferences_facet
return nil if georeferences.nil?
if georeferences
Expand Down Expand Up @@ -593,6 +605,7 @@ def base_merge_clauses
clauses += collecting_event_merge_clauses + collecting_event_and_clauses

clauses += [
determiner_name_regex_facet,
with_buffered_collecting_event_facet,
with_buffered_other_labels_facet,
with_buffered_determinations_facet,
Expand Down
17 changes: 14 additions & 3 deletions spec/lib/queries/collection_object/filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@

let(:query) { Queries::CollectionObject::Filter.new({}) }


specify '#determiner_name_regex' do
s = Specimen.create!
a = FactoryBot.create(:valid_taxon_determination, biological_collection_object: s, determiners: [ FactoryBot.create(:valid_person, last_name: 'Smith') ] )

s1 = Specimen.create! # not this one
b = FactoryBot.create(:valid_taxon_determination, biological_collection_object: s1, determiners: [ FactoryBot.create(:valid_person, last_name: 'htims') ] )

query.determiner_name_regex = 'i.*h'
expect(query.all.pluck(:id)).to contain_exactly(s.id)
end

context 'lib/queries/concerns/notes.rb' do
specify '#notes present' do
s = Specimen.create!
Expand Down Expand Up @@ -44,7 +56,6 @@
end
end


specify '#loan_id' do
t1 = Specimen.create!
l = FactoryBot.create(:valid_loan)
Expand Down Expand Up @@ -241,9 +252,9 @@
specify '#taxon_determinations #buffered_determinations' do
s = FactoryBot.create(:valid_specimen, buffered_determinations: 'Foo')
d = FactoryBot.create(:valid_taxon_determination, biological_collection_object: s)

a = Specimen.create!(buffered_determinations: 'Foo') # this one

query.taxon_determinations = false
query.exact_buffered_determinations = true
query.buffered_determinations = 'Foo'
Expand Down

0 comments on commit 16be82d

Please sign in to comment.