Skip to content

Commit db97241

Browse files
authored
Merge pull request #2313 from broadinstitute/jb-azul-entity-update
Switching back to GET for Azul entity queries (SCP-6059)
2 parents e61c731 + e91e03e commit db97241

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

app/controllers/api/v1/bulk_download_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ def summary
162162
end
163163

164164
@study_file_info = ::BulkDownloadService.get_download_info(valid_accessions)
165-
hca_file_info = ::AzulSearchService.get_file_summary_info(hca_accessions)
166-
@study_file_info += hca_file_info if hca_file_info.any?
165+
if hca_accessions.present?
166+
hca_file_info = ::AzulSearchService.get_file_summary_info(hca_accessions)
167+
@study_file_info += hca_file_info if hca_file_info.any?
168+
end
167169

168170
render json: @study_file_info
169171
end

app/models/hca_azul_client.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class HcaAzulClient
1515
MANIFEST_FORMATS = %w[compact full terra.bdbag terra.pfb curl].freeze
1616

1717
# maximum number of results to return
18-
MAX_RESULTS = 80
18+
MAX_RESULTS = 75
1919

2020
# maximum length of query string (in characters) for requests
2121
MAX_QUERY_LENGTH = 8192
@@ -184,8 +184,9 @@ def catalogs
184184
# - (ArgumentError) => if catalog is not in self.all_catalogs
185185
def projects(catalog: nil, query: {}, size: MAX_RESULTS)
186186
base_path = "#{api_root}/index/projects?size=#{size}"
187+
base_path += "&filters=#{format_hash_as_query_string(query)}"
187188
path = append_catalog(base_path, catalog)
188-
process_api_request(:post, path, payload: create_query_filters(query))
189+
process_api_request(:get, path)
189190
end
190191

191192
# simulate OR logic by splitting project queries on facet and joining results
@@ -280,10 +281,10 @@ def project_manifest_link(project_id, catalog: nil, format: 'compact')
280281
# - (Hash) => List of files matching query
281282
def files(catalog: nil, query: {}, size: MAX_RESULTS)
282283
base_path = "#{api_root}/index/files?size=#{size}"
283-
payload = create_query_filters(query)
284+
base_path += "&filters=#{format_hash_as_query_string(query)}"
284285
path = append_catalog(base_path, catalog)
285286
# make API request, but fold in project information to each result so that this is preserved for later use
286-
raw_results = process_api_request(:post, path, payload:)['hits']
287+
raw_results = process_api_request(:get, path)['hits']
287288
results = []
288289
raw_results.each do |result|
289290
files = result['files']
@@ -404,6 +405,19 @@ def merge_query_objects(*query_objects)
404405
merged_query
405406
end
406407

408+
# take a Hash/JSON object and format as a query string parameter
409+
#
410+
# * *params*
411+
# - +query_params+ (Hash) => Hash of query parameters
412+
#
413+
# * *returns*
414+
# - (String) => URL-encoded string version of query parameters
415+
def format_hash_as_query_string(query_params)
416+
# replace Ruby => assignment operators with JSON standard colons (:)
417+
sanitized_params = query_params.to_s.gsub(/=>/, ':')
418+
CGI.escape(sanitized_params)
419+
end
420+
407421
# create a query filter object to use in a request body
408422
#
409423
# * *params*

test/integration/external/hca_azul_client_test.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,16 @@ def get_entries_from_response(response, key)
163163
assert_equal keys, file.keys.sort & keys
164164
end
165165

166-
# TODO: SCP-5564
167-
# - Fix "Global bulk download breaks in default use"
168-
# - Re-enable this test
166+
test 'should format object for query string' do
167+
query_object = { 'foo' => { 'bar' => 'baz' } }
168+
expected_response = '%7B%22foo%22+%3A+%7B%22bar%22+%3A+%22baz%22%7D%7D'
169+
formatted_query = @hca_azul_client.format_hash_as_query_string(query_object)
170+
assert_equal expected_response, formatted_query
171+
# assert we can get back to original object, but as JSON (removing whitespace that breaks comparison)
172+
query_as_json = CGI.unescape(formatted_query).gsub(/\s/, '')
173+
assert_equal query_object.to_json, query_as_json
174+
end
175+
169176
test 'should get HCA metadata tsv link' do
170177
skip_if_api_down
171178
manifest_info = @hca_azul_client.project_manifest_link(@project_id)

0 commit comments

Comments
 (0)