Skip to content

Commit

Permalink
Merge pull request #315 from sul-dlss/fix-cql-queries
Browse files Browse the repository at this point in the history
Allow cql queries to take multiple arguments and limits
  • Loading branch information
jgreben authored Nov 11, 2024
2 parents 100a127 + b552a95 commit c7785dd
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 27 deletions.
18 changes: 16 additions & 2 deletions bin/folio_cql_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,19 @@
require 'json'
folio = FolioRequest.new
path = folio.make_path(ARGV[0])
query = ARGV[1]
folio.get_cql_json(path, query)

def usage
puts 'USAGE: folio_cql_json.rb {folio API path} {limit (optional, default 10)} {cql query string}'
exit(0)
end

usage if ARGV.length < 2

if ARGV.length == 2
query = ARGV[1..]
else
limit = ARGV[1]
query = ARGV[2..]
end

folio.get_cql_json(path, limit || 10, query.join(' '))
4 changes: 2 additions & 2 deletions lib/folio_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def get_cql(path, query)
parse(authenticated_request(path))
end

def get_cql_json(path, query)
path += "?query=#{CGI.escape(query)}"
def get_cql_json(path, limit, query)
path += "?limit=#{limit}&query=#{CGI.escape(query)}"
puts JSON.pretty_generate(JSON.parse(authenticated_request(path)))
end

Expand Down
6 changes: 2 additions & 4 deletions tasks/helpers/configurations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ def config_entry_json(file)
end

def config_entry_ids(hash)
ids = []
hash['configs'].each do |obj|
ids.push(obj['id'])
hash['configs'].map do |obj|
obj['id']
end
ids
end

def config_entry_get(module_code)
Expand Down
6 changes: 2 additions & 4 deletions tasks/helpers/okapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ def enable_timer(id)
end

def all_timers
all_timers = []
timers_get.each do |obj|
all_timers.push(timer_id(obj))
timers_get.map do |obj|
timer_id(obj)
end
all_timers
end

def circulation_timers
Expand Down
6 changes: 2 additions & 4 deletions tasks/helpers/orders/po_lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ def add_eresource_cost(cost, list_price)
end

def add_fund_data(fund_data, hldg_code, funds)
fund_dist = []
fund_data.each do |distribution|
fund_dist.push(distribution_hash(distribution, hldg_code, funds))
fund_data.map do |distribution|
distribution_hash(distribution, hldg_code, funds)
end
fund_dist
end

def distribution_hash(distribution, hldg_code, funds)
Expand Down
5 changes: 2 additions & 3 deletions tasks/helpers/organizations/org_notes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ def org_note_type_id
end

def org_notes_from_xml(xml_obj, org_id, note_type_id)
notes = []
xml_obj.xpath('vendorExtendedInfo/entry').each do |note|
notes.push(note_hash(note_type_id, note&.text, org_id))
notes = xml_obj.xpath('vendorExtendedInfo/entry').map do |note|
note_hash(note_type_id, note&.text, org_id)
end
notes.compact
end
Expand Down
6 changes: 2 additions & 4 deletions tasks/helpers/uuids/uuids.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,11 @@ def config_entries
end

def profile_associations_ids
uuids = []
associations = JSON.parse(pull_profile_associations)

associations['profileAssociations'].each do |obj|
uuids.push(obj['id'])
associations['profileAssociations'].map do |obj|
obj['id']
end
uuids
end

def user_ids(username)
Expand Down
13 changes: 9 additions & 4 deletions tasks/inventory/elasticsearch_indexing.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ namespace :inventory do
task :recreate_search_index, [:resource_name] do |_, args|
FolioRequest.new.post('/search/index/inventory/reindex',
'{ "recreateIndex": "true",
"resourceName": "'"#{args[:resource_name]}"'",
"resourceName": "' + (args[:resource_name]).to_s + '",
"indexSettings": { "numberOfShards": 4, "numberOfReplicas": 2, "refreshInterval": 1 }
}')
end

desc 'reindex search index for [instance, authority]'
task :reindex_search, [:resource_name] do |_, args|
FolioRequest.new.post('/search/index/inventory/reindex',
'{ "resourceName": "'"#{args[:resource_name]}"'" }')
"{ \"resourceName\": \"#{args[:resource_name]}\" }")
end

desc 'monitor instances published to Kafka for reindex with given job id'
Expand All @@ -24,7 +24,12 @@ namespace :inventory do
desc 'update index dynamic settings to defaults (2 replicas) for [instance, authority]'
task :default_search_index_settings, [:resource_name] do |_, args|
FolioRequest.new.put('/search/index/settings',
'{ "resourceName": "'"#{args[:resource_name]}"'",
"indexSettings": { "numberOfShards": 4, "numberOfReplicas": 2, "refreshInterval": 1 } }')
"{ \"resourceName\": \" #{args[:resource_name]} \",
\"indexSettings\": {
\"numberOfShards\": 4,
\"numberOfReplicas\": 2,
\"refreshInterval\": 1
}
}")
end
end

0 comments on commit c7785dd

Please sign in to comment.